{"id":13727446,"url":"https://github.com/egoist/style-module","last_synced_at":"2025-04-30T16:43:39.550Z","repository":{"id":45275256,"uuid":"164121379","full_name":"egoist/style-module","owner":"egoist","description":"CSS modules in JS.","archived":false,"fork":false,"pushed_at":"2021-12-25T14:13:20.000Z","size":139,"stargazers_count":36,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-23T22:34:47.349Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/egoist.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":"2019-01-04T15:06:53.000Z","updated_at":"2024-07-25T18:11:51.000Z","dependencies_parsed_at":"2022-09-06T12:10:19.285Z","dependency_job_id":null,"html_url":"https://github.com/egoist/style-module","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/egoist%2Fstyle-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fstyle-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fstyle-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fstyle-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egoist","download_url":"https://codeload.github.com/egoist/style-module/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242679489,"owners_count":20168158,"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":[],"created_at":"2024-08-03T01:03:56.849Z","updated_at":"2025-03-09T10:30:43.741Z","avatar_url":"https://github.com/egoist.png","language":"TypeScript","readme":"# style-module \u003csup\u003e\u003cimg src=\"https://version-badge.egoist.sh/text?text=less%20than%201kb\"\u003e\u003c/sup\u003e\n\n[![NPM version](https://badgen.net/npm/v/style-module)](https://npmjs.com/package/style-module) [![NPM downloads](https://badgen.net/npm/dm/style-module)](https://npmjs.com/package/style-module) [![CircleCI](https://badgen.net/circleci/github/egoist/style-module/master)](https://circleci.com/gh/egoist/style-module/tree/master) [![donate](https://badgen.net/badge/support%20me/donate/ff69b4)](https://patreon.com/egoist) [![chat](https://badgen.net/badge/chat%20on/discord/7289DA)](https://chat.egoist.moe)\n\n**Please consider [donating](https://www.patreon.com/egoist) to this project's author, [EGOIST](https://egoist.sh), to show your ❤️ and support.**\n\n## Install\n\n```bash\nnpm i style-module\n```\n\n\u003cdetails\u003e\u003csummary\u003eUse UMD bundle from CDN\u003c/summary\u003e\n\n```html\n\u003cscript src=\"https://unpkg.com/style-module/dist/style-module.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const { styleModule } = styleModule\n\n  const styles = styleModule({\n    button: {\n      color: 'red'\n    }\n  })\n\u003c/script\u003e\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eUse ESM bundle from CDN\u003c/summary\u003e\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { styleModule } from 'https://unpkg.com/style-module?module'\n\n  const styles = styleModule({\n    button: {\n      color: 'red'\n    }\n  })\n\u003c/script\u003e\n```\n\n\u003c/details\u003e\n\n## Usage\n\nCheck out the live demo on [CodePan](https://codepan.net/gist/bfcdf733f6099fff24080d039569c9aa).\n\n```js\nimport { styleModule } from 'style-module'\n\nconst buttonStyles = styleModule({\n  button: {\n    color: 'red',\n    ':hover': {\n      color: 'blue'\n    }\n  }\n})\n\nconst styles = styleModule({\n  main: {\n    font: '14px/1.4 helvetica',\n    backgroundColor: 'red'\n  },\n  button: {\n    // Composes (i.e. inherits) all the styles from buttonStyles.button\n    composes: buttonStyles.button,\n    color: 'pink'\n  }\n})\n\n// Generated class names\nconsole.log(styles)\n//=\u003e\n{\n  main: 'sm_2',\n  button: 'sm_0 sm_3'\n}\n```\n\n### Composes\n\nComposes (i.e. inherits) all styles from an existing class name which is usually generated by `css` or `styleModule` function:\n\n```js\nimport { css } from 'styleModule'\n\nconst defaultButton = css({\n  border: '1px solid #ccc'\n})\n\nconst primaryButton = css({\n  composes: defaultButton,\n  color: 'red',\n  ':hover': {\n    color: 'pink'\n  }\n})\n```\n\nNotes:\n\n- `composes` currently only works at the top level.\n- It's possible to compose multiple classes with \u003ccode\u003ecomposes: \u0026#x60;${classNameA} ${classNameB}\u0026#x60;\u003c/code\u003e\n\n### Keyframes\n\nCheck out the live demo on [CodePan](https://codepan.net/gist/3d965f020974fdbbc3aaaacf8c7cefda).\n\n```js\nimport { css, keyframes } from 'style-module'\n\nconst zoom = keyframes({\n  from: {\n    transform: 'scale(0.5)'\n  },\n  to: {\n    transform: 'scale(2)'\n  }\n})\n\nconst className = css({\n  animation: `${zoom} 300ms infinite`\n})\n```\n\n## API\n\n### css\n\nGenerate class name for a style record:\n\n```js\nimport { css } from 'styleModule'\n\nconst className = css({\n  color: 'red',\n  ':hover': {\n    color: 'black'\n  }\n})\n\nclassName //=\u003e sm_0\n```\n\n### styleModule\n\nGenerate class names for _multiple style records (a module)_:\n\n```js\nimport { styleModule } from 'styleModule'\n\nconst styles = styleModule({\n  button: {\n    color: 'red',\n    ':hover': {\n      color: 'black'\n    }\n  }\n})\n\nstyles.button //=\u003e .sm_0\n```\n\n`styleModule` is just a short-hand for generating multiple class names at once, internally it calls `css` function too.\n\n### keyframes\n\nCreate a `@keyframes` rule, you should pass in the definition of the rule and it returns the name.\n\n## TODO\n\n- [ ] Atomic CSS\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## Author\n\n**style-module** © EGOIST, Released under the [MIT](./LICENSE) License.\u003cbr\u003e\nAuthored and maintained by EGOIST with help from contributors ([list](https://github.com/egoist/style-module/contributors)).\n\n\u003e [Website](https://egoist.sh) · GitHub [@EGOIST](https://github.com/egoist) · Twitter [@\\_egoistlily](https://twitter.com/_egoistlily)\n","funding_links":["https://patreon.com/egoist","https://www.patreon.com/egoist"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fstyle-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegoist%2Fstyle-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fstyle-module/lists"}