├── .github
└── workflows
│ └── nodejs.yml
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── package.json
├── src
└── index.js
├── tests
├── example.html
└── stylenames.test.js
└── yarn.lock
/.github/workflows/nodejs.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | strategy:
11 | matrix:
12 | node-version: [10.x, 12.x]
13 |
14 | steps:
15 | - uses: actions/checkout@v1
16 | - name: Use Node.js ${{ matrix.node-version }}
17 | uses: actions/setup-node@v1
18 | with:
19 | node-version: ${{ matrix.node-version }}
20 | - name: yarn install, lint, and test
21 | run: |
22 | yarn
23 | yarn lint
24 | yarn test
25 | env:
26 | CI: true
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | node_modules
3 | lib
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | ### Node template
2 | # Logs
3 | logs
4 | *.log
5 | npm-debug.log*
6 |
7 | # Dependency directories
8 | node_modules
9 |
10 | .idea
11 | .babelrc
12 | .eslintrc
13 | .gitignore
14 | webpack.production.babel.js
15 |
16 | tests
17 | .dependabot
18 | .github
19 | src
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Kevin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | 
3 | 
4 |
5 | # @shat/stylenames
6 |
7 | A simple JavaScript utility for conditionally joining inline styles together.
8 |
9 | > This is a fork of the unmaintained [stylenames](https://github.com/kmathmann/stylenames) package
10 |
11 | ## What does stylenames do?
12 |
13 | In one short sentence: "stylenames converts an object to a css style string."
14 |
15 | Think [classNames](https://www.npmjs.com/package/classnames) but for inline styles.
16 |
17 | ## Install
18 |
19 | **From CDN:** Add the following script to the end of your `
` section.
20 | ```html
21 |
22 | ```
23 |
24 | That's it. It will initialize itself as `styleNames()`.
25 |
26 | **From NPM:** Install the package from NPM.
27 | ```js
28 | npm install @shat/stylenames
29 | ```
30 |
31 | Include it in your script.
32 |
33 | ```javascript
34 | import styleNames from '@shat/stylenames';
35 | ```
36 |
37 |
38 | ## Quick Start
39 |
40 | Standalone:
41 |
42 | ```js
43 | styleNames({
44 | backgroundColor: 'red',
45 | width: '120px',
46 |
47 | 'height':{
48 | // If the condition is false the style does not get used.
49 | '200px': false,
50 | // Only the first value with true condition is used.
51 | '300px': true,
52 | '400px': true
53 | },
54 | });
55 | ```
56 |
57 | With [Alpine.js](https://github.com/alpinejs/alpine):
58 |
59 | ```html
60 |
61 |
62 |