{"id":17956838,"url":"https://github.com/morajabi/rc-classnames","last_synced_at":"2025-08-16T07:32:19.564Z","repository":{"id":58231445,"uuid":"64495299","full_name":"morajabi/rc-classnames","owner":"morajabi","description":"🍭 Manage classNames conditionally in React and JSX easily","archived":false,"fork":false,"pushed_at":"2017-07-04T12:30:34.000Z","size":19,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-08T18:18:05.320Z","etag":null,"topics":["classname","jsx","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/morajabi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-29T16:35:14.000Z","updated_at":"2023-02-07T11:14:59.000Z","dependencies_parsed_at":"2022-08-31T00:22:09.071Z","dependency_job_id":null,"html_url":"https://github.com/morajabi/rc-classnames","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morajabi%2Frc-classnames","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morajabi%2Frc-classnames/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morajabi%2Frc-classnames/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morajabi%2Frc-classnames/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morajabi","download_url":"https://codeload.github.com/morajabi/rc-classnames/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230022016,"owners_count":18160964,"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":["classname","jsx","react"],"created_at":"2024-10-29T10:43:11.966Z","updated_at":"2024-12-16T20:27:52.715Z","avatar_url":"https://github.com/morajabi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rc-classnames\n[![Version](http://img.shields.io/npm/v/rc-classnames.svg)](https://www.npmjs.org/package/rc-classnames)\n[![Build Status](https://travis-ci.org/morajabi/rc-classnames.svg?branch=master)](https://travis-ci.org/morajabi/rc-classnames)\n[![David](https://img.shields.io/david/morajabi/rc-classnames.svg?maxAge=2592000)]()\n[![GitHub issues](https://img.shields.io/github/issues/morajabi/rc-classnames.svg?maxAge=2592000?style=flat)]()\n[![Maintenance](https://img.shields.io/maintenance/yes/2017.svg?maxAge=2592000)]()\n\n[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n\nManage classNames conditionally in React and JSX easily in **any format**\n\n**There's also another classnames library which I didn't find when I was building this. It's more popular so take a look at it: [JedWatson / classnames](https://github.com/JedWatson/classnames)**\n\nInstall with npm:\n```\nnpm install rc-classnames --save\n```\nOr with bower:\n```\nbower install rc-classnames\n```\nYou can use CDN with minified version as well:\n```\n\u003cscript src=\"https://unpkg.com/rc-classnames/index.min.js\"\u003e\u003c/script\u003e\n```\nYou can use with UMD as well.\n\nWe use \t[SemVer](http://semver.org) for versioning.\n\n## Why react-classnames\nDo you remember when you wanted a button in JSX to have diffrent states conditionally? You might end up with something like this:\n```js\n\u003cbutton className={'button' + (isDisabled ? ' button--disabled' : '') + (hasRadius ? '' : 'button--no-radius'} /\u003e\n```\nOr in ES6 syntax:\n```js\n\u003cbutton className={`button${isDisabled \u0026\u0026 ' button--disabled'}${hasRadius || button--no-radius}`} /\u003e\n```\nOh, It's very hard to read. But with rc-classnames those days are gone! It's intelligent! You can give it classNames in **Any Format** you want and it will generate a neat classname for you. Let's see how can we implement our button with rc-classnames:\n```js\n// ES6\nimport c from 'rc-classnames';\n\n// CommonJS\nvar c = require('rc-classnames');\n\n\u003cbutton className={c('button', {\n  'button--disabled': isDisabled,\n  'button--no-radius': !hasRadius\n})} /\u003e\n```\nEven with Arrays and Nested Arrays:\n```js\n\u003cbutton className={c(\n  ['button', 'header__button', ['button--large']],\n  {\n    'button--disabled': isDisabled,\n    'button--no-radius': !hasRadius\n  }\n)} /\u003e\n```\nOr Arrays containing objects:\n```js\n\u003cbutton className={c(\n  'button',\n  [\n    'header__button',\n    {\n      'button--disabled': isDisabled,\n      'button--no-radius': !hasRadius\n    }\n  ]\n)} /\u003e\n```\nSee? Give your classNames in **Any Format** you wish!\n\n## Usage Without react\nWhile main purpose of this library is using with React, you **can** use it without react, just call the exported function.\n\nFirst import `index.js` file with script tag:\n```\n\u003cscript src=\"rc-classnames/index.js\"\u003e\u003c/script\u003e\n```\n`ReactClassNames` is available globally with Pure JS:\n```\nwindow.getElementById('someId').classList = ReactClassNames('hey', { 'foo': true, 'bar': false });\n```\nWe support UMD as well.\n\n## TODO\n- Add HoC for custom `classNames` prop in React\n- ...\nIf you want a feature or have an idea, fill an issue and tell me what you want.\n\n## Have problems?\nI hope you don't have any problem with the library, but if library have problems, fill an issue containing the case with a seperate Repo and me or other friends will answer ASAP. Please double check your code before sumbiting issues.\n\n## License\nCopyright (c) 2016 Mohammad Rajabifard\n\nThe MIT License (MIT)\n```\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorajabi%2Frc-classnames","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorajabi%2Frc-classnames","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorajabi%2Frc-classnames/lists"}