{"id":13778643,"url":"https://github.com/svnm/deku-css-modules","last_synced_at":"2026-02-26T01:15:21.370Z","repository":{"id":77944452,"uuid":"46855225","full_name":"svnm/deku-css-modules","owner":"svnm","description":"mapping of class names to CSS modules inside Deku components","archived":false,"fork":false,"pushed_at":"2016-11-03T03:45:38.000Z","size":81,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-18T21:42:39.608Z","etag":null,"topics":[],"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/svnm.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}},"created_at":"2015-11-25T10:40:41.000Z","updated_at":"2019-08-15T09:25:53.000Z","dependencies_parsed_at":"2023-03-08T14:17:55.088Z","dependency_job_id":null,"html_url":"https://github.com/svnm/deku-css-modules","commit_stats":null,"previous_names":["steveniseki/deku-css-modules"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svnm%2Fdeku-css-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svnm%2Fdeku-css-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svnm%2Fdeku-css-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svnm%2Fdeku-css-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svnm","download_url":"https://codeload.github.com/svnm/deku-css-modules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244058221,"owners_count":20391056,"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-03T18:00:55.646Z","updated_at":"2026-02-26T01:15:21.311Z","avatar_url":"https://github.com/svnm.png","language":"JavaScript","funding_links":[],"categories":["Components"],"sub_categories":[],"readme":"# deku-css-modules\n\n[![npm version](https://badge.fury.io/js/deku-css-modules.svg)](https://badge.fury.io/js/deku-css-modules)\n\nMapping of class names to CSS modules in Deku components\n\n## CSS Modules\n\n[CSS Modules](https://github.com/css-modules/css-modules) uses a module bundler such as [webpack](http://webpack.github.io/docs/) to load CSS scoped to a particular document. \n\nCSS module loader will generate a unique name for a each CSS class at the time of loading the CSS document\n\nCSS Modules with Deku looks like this:\n\n```js\n/** @jsx element */\nimport { element } from 'deku';\nimport styles from './table.css';\n\nlet Table = {\n    render () {\n        return \u003cdiv class={styles.table}\u003e\n            \u003cdiv class={styles.row}\u003e\n                \u003cdiv class={styles.cell}\u003eA0\u003c/div\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e;\n    }\n}\n```\n\nRendering the component will produce a markup similar to:\n\n```js\n\u003cdiv class=\"table__table___32osj\"\u003e\n    \u003cdiv class=\"table__row___2w27N\"\u003e\n        \u003cdiv class=\"table__cell___2w27N\"\u003eA0\u003c/div\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\nand a corresponding CSS file that matches those CSS classes... Awesome!\n\n### deku-css-modules\n\nSimilar to [React CSS Modules](https://github.com/gajus/react-css-modules), Deku CSS Modules automates loading of CSS Modules using the `styleName` property. \n\nCheck out the [deku-webpack-example](https://github.com/StevenIseki/deku-webpack-example)\n\n```js\n/** @jsx element */\n\nimport { element } from 'deku';\nimport CSSModules from 'deku-css-modules.js';\nimport styles from './table.css';\n\nconst Table = function () {\n    return (\n        \u003cdiv styleName='table'\u003e\n            \u003cdiv styleName='row'\u003e\n                \u003cdiv styleName='cell'\u003eA0\u003c/div\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    )\n}\n\nexport default CSSModules(Table, styles);\n\n```\n\nBenefits of using `deku-css-modules`:\n\n* You are not forced to use `camelCase` naming convention.\n* You do not need to refer to the `styles` object every time you use a CSS Module.\n* There is clear distinction between global CSS `class` and CSS Modules `styleName`\n\n## Implementation\n\n`deku-css-modules` extends the `render` method of the target component. It uses the value of `styleName` to look for CSS Modules in the associated styles object and appends the matching unique CSS class names to each `Element`s `className` property value.\n\n## Usage\n\n* Set up a [module bundler](#modulebundler) to load the [Interoperable CSS](https://github.com/css-modules/icss).\n* Configure the render method of your component to use `deku-css-modules`\n\n### Bundlers\n\n#### webpack\n\n* Install [`style-loader`](https://www.npmjs.com/package/style-loader) and [`css-loader`](https://www.npmjs.com/package/css-loader)\n* Use [`extract-text-webpack-plugin`](https://www.npmjs.com/package/extract-text-webpack-plugin) to aggregate the CSS into a single file\n* Setup your `/\\.css$/` loader\n\nCheck out the example [deku-webpack-example](https://github.com/StevenIseki/deku-webpack-example)\n### Extending Component Styles\n\nUse `styles` property to overwrite the default component styles.\n\nExplanation using `Table` component:\n\n```js\n/** @jsx element */\nimport { element } from 'deku';\nimport CSSModules from 'deku-css-modules.js';\nimport styles from './table.css';\n\nconst Table = function () {\n    return (\n        \u003cdiv styleName='table'\u003e\n            \u003cdiv styleName='row'\u003e\n                \u003cdiv styleName='cell'\u003eA0\u003c/div\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    )\n}\n\nexport default CSSModules(Table, styles);\n```\n\nIn this example, `CSSModules` is used to decorate `Table` component using `./table.css` CSS Modules. When `Table` component is rendered, it will use the properties of the `styles` object to construct `className` values.\n\nUsing `styles` property you can overwrite the default component `styles` object, e.g.\n\n```js\nimport customStyles from './table-custom-styles.css';\n\n\u003cTable styles={customStyles} /\u003e;\n```\n[Interoperable CSS](https://github.com/css-modules/icss) can [extend other ICSS](https://github.com/css-modules/css-modules#dependencies). Use this feature to extend default styles, e.g.\n\n```css\n/* table-custom-styles.css */\n.table {\n    composes: table from './table.css';\n}\n\n.row {\n    composes: row from './table.css';\n}\n\n/* .cell {\n    composes: cell from './table.css';\n} */\n\n.table {\n    width: 400px;\n}\n\n.cell {\n    float: left; width: 154px; background: #eee; padding: 10px; margin: 10px 0 10px 10px;\n}\n```\n\nIn this example, `table-custom-styles.css` selectively extends `table.css` (the default styles of `Table` component).\n\nRefer to the [`UsingStylesProperty` example](https://github.com/gajus/react-css-modules-examples/tree/master/src/UsingStylesProperty) for an example of a working implementation.\n\n### `styles` Property\n\nDecorated components inherit `styles` property that describes the mapping between CSS modules and CSS classes.\n\n```js\nconst render = ({props}) =\u003e {\n    \u003cdiv\u003e\n        \u003cp styleName='foo'\u003e\u003c/p\u003e\n        \u003cp class={props.styles.foo}\u003e\u003c/p\u003e\n    \u003c/div\u003e;\n}\n```\n\nIn the above example, `styleName='foo'` and `class={this.props.styles.foo}` are equivalent.\n\n### Decorator\nYou need to decorate your component using `deku-css-modules`, e.g.\n\n```js\n/** @jsx element **/\nimport { element } from 'deku';\nimport CSSModules from 'deku-css-modules.js';\nimport styles from './table.css';\n\nconst Table = function () {\n    return (\n        \u003cdiv styleName='table'\u003e\n            \u003cdiv styleName='row'\u003e\n                \u003cdiv styleName='cell'\u003eA0\u003c/div\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    )\n}\n\nexport default CSSModules(Table, styles);\n```\n\nThats it!\n\nAs the name implies, `deku-css-modules` is compatible with the [ES7 decorators](https://github.com/wycats/javascript-decorators) syntax:\n\n```js\n/** @jsx element **/\nimport { element } from 'deku';\nimport CSSModules from 'deku-css-modules.js';\nimport styles from './table.css';\n\nexport default {\n  @CSSModules(styles)\n  render: () =\u003e {\n    return (\n        \u003cdiv styleName='table'\u003e\n            \u003cdiv styleName='row'\u003e\n                \u003cdiv styleName='cell'\u003eA0\u003c/div\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    )\n  },\n  onCreate: () =\u003e {\n    console.log('A MyComponent entity was created!')\n  }\n}\n```\n\n\n\n#### Browserify\n\nRefer to [`css-modulesify`](https://github.com/css-modules/css-modulesify).\n\n## Development\n    npm install\n    npm run build\n    npm test\n    npm start\n\n## License\n\n[MIT](http://isekivacenz.mit-license.org/)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvnm%2Fdeku-css-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvnm%2Fdeku-css-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvnm%2Fdeku-css-modules/lists"}