Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 675d560
Showing
15 changed files
with
5,070 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.rpt2_cache | ||
dist | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"bracketSpacing": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) EGOIST <0x142857@gmail.com> (https://egoist.sh) | ||
|
||
Permission 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: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# style-module <sup><img src="https://version-badge.egoist.sh/text?text=beta"></sup> | ||
|
||
[![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) | ||
|
||
**Please consider [donating](https://www.patreon.com/egoist) to this project's author, [EGOIST](https://egoist.sh), to show your ❤️ and support.** | ||
|
||
## Install | ||
|
||
```bash | ||
npm i style-module | ||
``` | ||
|
||
<details><summary>Use UMD bundle from CDN</summary> | ||
|
||
```html | ||
<script src="https://unpkg.com/style-module/dist/style-module.min.js"></script> | ||
<script> | ||
const { styleModule } = styleModule | ||
const styles = styleModule({ | ||
button: { | ||
color: 'red' | ||
} | ||
}) | ||
</script> | ||
``` | ||
|
||
</details> | ||
|
||
<details><summary>Use ESM bundle from CDN</summary> | ||
|
||
```html | ||
<script module> | ||
import { styleModule } from 'https://unpkg.com/style-module?module' | ||
const styles = styleModule({ | ||
button: { | ||
color: 'red' | ||
} | ||
}) | ||
</script> | ||
``` | ||
|
||
</details> | ||
|
||
## Usage | ||
|
||
```js | ||
import { styleModule } from 'style-module' | ||
|
||
const buttonStyles = styleModule({ | ||
button: { | ||
color: 'red', | ||
':hover': { | ||
color: 'blue' | ||
} | ||
} | ||
}) | ||
|
||
const styles = styleModule({ | ||
main: { | ||
font: '14px/1.4 helvetica', | ||
backgroundColor: 'red' | ||
}, | ||
button: { | ||
// Composes (i.e. inherits) all the styles from buttonStyles.button | ||
composes: buttonStyles.button, | ||
color: 'pink' | ||
} | ||
}) | ||
|
||
// Generated class names | ||
console.log(styles) | ||
//=> | ||
{ | ||
main: 'sm_2', | ||
button: 'sm_0 sm_3' | ||
} | ||
``` | ||
|
||
## API | ||
|
||
### css | ||
|
||
Generate class name for a style record: | ||
|
||
```js | ||
const className = css({ | ||
color: 'red', | ||
':hover': { | ||
color: 'black' | ||
} | ||
}) | ||
|
||
className //=> sm_0 | ||
``` | ||
|
||
### styleModule | ||
|
||
Generate class names for _multiple style records (a module)_: | ||
|
||
```js | ||
const styles = styleModule({ | ||
button: { | ||
color: 'red', | ||
':hover': { | ||
color: 'black' | ||
} | ||
} | ||
}) | ||
|
||
styles.button //=> .sm_0 | ||
``` | ||
|
||
## TODO | ||
|
||
- [ ] Atomic CSS | ||
|
||
## Contributing | ||
|
||
1. Fork it! | ||
2. Create your feature branch: `git checkout -b my-new-feature` | ||
3. Commit your changes: `git commit -am 'Add some feature'` | ||
4. Push to the branch: `git push origin my-new-feature` | ||
5. Submit a pull request :D | ||
|
||
## Author | ||
|
||
**style-module** © EGOIST, Released under the [MIT](./LICENSE) License.<br> | ||
Authored and maintained by EGOIST with help from contributors ([list](https://github.com/egoist/style-module/contributors)). | ||
|
||
> [Website](https://egoist.sh) · GitHub [@EGOIST](https://github.com/egoist) · Twitter [@\_egoistlily](https://twitter.com/_egoistlily) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/node:latest | ||
branches: | ||
ignore: | ||
- gh-pages # list of branches to ignore | ||
- /release\/.*/ # or ignore regexes | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
key: dependency-cache-{{ checksum "yarn.lock" }} | ||
- run: | ||
name: install dependences | ||
command: yarn | ||
- save_cache: | ||
key: dependency-cache-{{ checksum "yarn.lock" }} | ||
paths: | ||
- ./node_modules | ||
- run: | ||
name: test | ||
command: yarn test | ||
- run: | ||
name: Release | ||
command: yarn semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
testEnvironment: 'jsdom', | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest' | ||
}, | ||
testRegex: '(/__test__/.*|(\\.|/)(test|spec))\\.tsx?$', | ||
testPathIgnorePatterns: ['/node_modules/', '/dist/', '/types/'], | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"name": "style-module", | ||
"version": "0.0.0", | ||
"description": "Like CSS modules but in JS.", | ||
"main": "dist/style-module.js", | ||
"module": "dist/style-module.mjs", | ||
"production:main": "dist/style-module.min.js", | ||
"production:module": "dist/style-module.min.mjs", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"test": "npm run test:unit", | ||
"test:unit": "jest -i", | ||
"build": "rollup -c", | ||
"prepublishOnly": "npm run build", | ||
"commit": "git-cz" | ||
}, | ||
"repository": { | ||
"url": "egoist/style-module", | ||
"type": "git" | ||
}, | ||
"author": "egoist<0x142857@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/jest": "^23.3.11", | ||
"commitizen": "^3.0.5", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"husky": "^1.0.0-rc.13", | ||
"jest": "^23.6.0", | ||
"lint-staged": "^7.2.0", | ||
"prettier": "^1.15.2", | ||
"rollup": "^1.0.1", | ||
"rollup-plugin-terser": "^4.0.1", | ||
"rollup-plugin-typescript2": "^0.18.1", | ||
"ts-jest": "^23.10.5", | ||
"typescript": "^3.2.2" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{ts,js,json,md}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"release": { | ||
"branch": "master" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const createConfig = ({ format, minify, types }) => { | ||
let ext = format === 'cjs' ? '.cjs.js' : format === 'es' ? '.mjs' : '.js' | ||
if (minify) { | ||
ext = ext.replace(/\.([a-z]+)$/, '.min.$1') | ||
} | ||
return { | ||
input: 'src/index.ts', | ||
output: { | ||
format: format, | ||
file: `dist/style-module${ext}`, | ||
name: 'styleModule' | ||
}, | ||
plugins: [ | ||
require('rollup-plugin-typescript2')({ | ||
tsconfigOverride: { | ||
compilerOptions: { | ||
declaration: types && true | ||
} | ||
} | ||
}), | ||
minify && require('rollup-plugin-terser').terser() | ||
].filter(Boolean) | ||
} | ||
} | ||
|
||
export default [ | ||
createConfig({ format: 'es', types: true }), | ||
createConfig({ format: 'cjs' }), | ||
createConfig({ format: 'umd' }), | ||
createConfig({ format: 'es', minify: true }), | ||
createConfig({ format: 'cjs', minify: true }), | ||
createConfig({ format: 'umd', minify: true }) | ||
] |
Oops, something went wrong.