{"id":24518255,"url":"https://github.com/flasd/react-classlist-helper","last_synced_at":"2026-05-19T17:05:35.763Z","repository":{"id":96503867,"uuid":"96631426","full_name":"flasd/react-classlist-helper","owner":"flasd","description":"Helper to defining multiple classNames on a react component.","archived":false,"fork":false,"pushed_at":"2018-01-13T05:31:15.000Z","size":152,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-22T01:41:28.193Z","etag":null,"topics":["css-classes","helper","javascript","react"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flasd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-08T16:43:16.000Z","updated_at":"2017-07-09T03:54:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"f43cdc2e-9df0-4432-a899-9357ff427c88","html_url":"https://github.com/flasd/react-classlist-helper","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flasd%2Freact-classlist-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flasd%2Freact-classlist-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flasd%2Freact-classlist-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flasd%2Freact-classlist-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flasd","download_url":"https://codeload.github.com/flasd/react-classlist-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243719398,"owners_count":20336607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css-classes","helper","javascript","react"],"created_at":"2025-01-22T01:41:28.271Z","updated_at":"2026-05-19T17:05:30.719Z","avatar_url":"https://github.com/flasd.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React classList Helper\nHelper to defining multiple classes on a react component.\n\n[![Build Status](https://travis-ci.org/flasd/react-classlist-helper.svg?branch=master)](https://travis-ci.org/flasd/react-classlist-helper) [![Coverage Status](https://coveralls.io/repos/github/flasd/react-classlist-helper/badge.svg?branch=master)](https://coveralls.io/github/flasd/react-classlist-helper?branch=master) [![npm version](https://badge.fury.io/js/react-classlist-helper.svg)](https://www.npmjs.com/package/react-classlist-helper)\n\n## Getting it up and running\n\nAdd the latest version of react-classlist-helper to your package.json:\n```\nnpm install react-classlist-helper --save\n```\nAlso available in Yarn:\n```\nyarn add react-classlist-helper\n```\n\n## API\n\n### classList(class1: (string || array || object), class2, ...classN): string\nUsed to add multiple classes to an element:\n\n```javascript\nimport classList from 'react-classlist-helper';\n\n...\n\nconst Component = () =\u003e (\n    \u003cdiv className={ classList(myCssClass1, myCssClass2, myCssClass3) } /\u003e\n);\n\n// \u003cdiv class=\"myCssClass1 myCssClass2 myCssClass3\"\u003e\u003c/div\u003e\n```\n\nIt also works with Arrays `['className', 'className2', ...]` and Objects `{ ClassName: boolean, ... }`;\n\nThe Object form is usefull for creating conditional classes:\n\n```javascript\nconst mobileClass = 'myAwesomeMobileClass';\nconst desktopClass = 'myDesktopClass';\nconst isMobile = true;\n\nconst classMap = {\n    myAwesomeMobileClass: isMobile,\n    myDesktopClass: !isMobile,\n};\n// { myAwesomeMobileClass: true, myDesktopClass: false }\n\n...\n\nconst Component = () =\u003e (\n    \u003cdiv className={ classList(classMap) } /\u003e\n);\n\n// \u003cdiv class=\"myAwesomeMobileClass\"\u003e\u003c/div\u003e\n\n```\n\n### toggleClass(className: string, condition: boolean): string\n\nIf you have only one class to toggle based on a condition:\n```javascript\nimport { toggleClass } from 'react-classlist-helper';\n\n...\n\nconst isACOn = true;\nconst coolClass = 'cool';\n\nconst Component = () =\u003e (\n    \u003cdiv className={ toggleClass(coolClass, isACOn) } /\u003e\n);\n// \u003cdiv class=\"cool\"\u003e\u003c/div\u003e\n\nisACOn = false;\n// \u003cdiv class=\"\"\u003e\u003c/div\u003e\n\n```\n\n### classList (cL) and toggleClass (tC) aliases\nWanna save some space? Use the alias:\n```javascript\nimport { cL, tC } from 'react-classlist-helper';\n\n...\n\nconst myCond = true;\nconst myClass = 'dangerZone';\n\nconst someClasses = ['something', 'something'];\n\nconst Component = () =\u003e (\n    \u003cdiv className={ cl(someClasses, tC(myClass, myCond)) } /\u003e\n);\n\n// \u003cdiv class=\"something something dangerZone\"\u003e\u003c/div\u003e\n```\n\nHappy coding!\n\n## MIT Licence\nCopyright 2017 Marcel Coelho.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflasd%2Freact-classlist-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflasd%2Freact-classlist-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflasd%2Freact-classlist-helper/lists"}