source: imaps-frontend/node_modules/css-in-js-utils/README.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 6.3 KB
Line 
1# CSS-in-JS Utilities
2A library that provides useful utilities functions for CSS-in-JS solutions.<br>
3They are intended to be used by CSS-in-JS library authors rather used directly.
4<br>
5
6<img alt="TravisCI" src="https://travis-ci.org/rofrischmann/css-in-js-utils.svg?branch=master"> <img alt="Test Coverage" src="https://api.codeclimate.com/v1/badges/2964ee833f8d2104cac6/test_coverage" /> <img alt="npm downloads" src="https://img.shields.io/npm/dm/css-in-js-utils.svg"> <img alt="npm version" src="https://badge.fury.io/js/css-in-js-utils.svg"> <img alt="gzipped size" src="https://img.shields.io/bundlephobia/minzip/css-in-js-utils.svg?colorB=4c1&label=gzipped%20size">
7
8## Installation
9```sh
10yarn add css-in-js-utils
11```
12
13## Why?
14By now I have authored and collaborated on many different libraries and found I would rewrite the very same utility functions every time. That's why this repository is hosting small utilities especially built for CSS-in-JS solutions and tools. Even if there are tons of different libraries already, they all basically use the same mechanisms and utilities.
15
16## Utilities
17* [`assignStyle(base, ...extend)`](#assignstylebase-extend)
18* [`camelCaseProperty(property)`](#camelcasepropertyproperty)
19* [`cssifyDeclaration(property, value)`](#cssifydeclarationproperty-value)
20* [`cssifyObject(object)`](#cssifyobjectobject)
21* [`hyphenateProperty(property)`](#hyphenatepropertyproperty)
22* [`isPrefixedProperty(property)`](#isprefixedpropertyproperty)
23* [`isPrefixedValue(value)`](#isprefixedvaluevalue)
24* [`isUnitlessProperty(property)`](#isunitlesspropertyproperty)
25* [`normalizeProperty(property)`](#normalizepropertyproperty)
26* [`resolveArrayValue(property, value)`](#resolvearrayvalueproperty-value)
27* [`unprefixProperty(property)`](#unprefixpropertyproperty)
28* [`unprefixValue(value)`](#unprefixvaluevalue)
29
30------
31
32### `assignStyle(base, ...extend)`
33Merges deep style objects similar to `Object.assign`.<br>
34It also merges array values into a single array whithout creating duplicates. The last occurence of every item wins.
35
36```javascript
37import { assignStyle } from 'css-in-js-utils'
38
39assignStyle(
40 { color: 'red', backgroundColor: 'black' },
41 { color: 'blue' }
42)
43// => { color: 'blue', backgroundColor: 'black' }
44
45assignStyle(
46 {
47 color: 'red',
48 ':hover': {
49 backgroundColor: 'black'
50 }
51 },
52
53 ':hover': {
54 backgroundColor: 'blue'
55 }
56 }
57)
58// => { color: 'red', ':hover': { backgroundColor: 'blue' }}
59```
60
61------
62
63### `camelCaseProperty(property)`
64Converts the `property` to camelCase.
65
66```javascript
67import { camelCaseProperty } from 'css-in-js-utils'
68
69camelCaseProperty('padding-top')
70// => 'paddingTop'
71
72camelCaseProperty('-webkit-transition')
73// => 'WebkitTransition'
74```
75
76------
77
78### `cssifyDeclaration(property, value)`
79Generates a CSS declaration (`property`:`value`) string.
80
81```javascript
82import { cssifyDeclaration } from 'css-in-js-utils'
83
84cssifyDeclaration('paddingTop', '400px')
85// => 'padding-top:400px'
86
87cssifyDeclaration('WebkitFlex', 3)
88// => '-webkit-flex:3'
89```
90
91------
92
93### `cssifyObject(object)`
94Generates a CSS string using all key-property pairs in `object`.
95It automatically removes declarations with value types other than `number` and `string`.
96
97```javascript
98import { cssifyObject } from 'css-in-js-utils'
99
100cssifyObject({
101 paddingTop: '400px',
102 paddingBottom: undefined,
103 WebkitFlex: 3,
104 _anyKey: [1, 2, 4]
105})
106// => 'padding-top:400px;-webkit-flex:3'
107```
108
109------
110
111### `hyphenateProperty(property)`
112Converts the `property` to hyphen-case.
113> Directly mirrors [hyphenate-style-name](https://github.com/rexxars/hyphenate-style-name).
114
115```javascript
116import { hyphenateProperty } from 'css-in-js-utils'
117
118hyphenateProperty('paddingTop')
119// => 'padding-top'
120
121hyphenateProperty('WebkitTransition')
122// => '-webkit-transition'
123```
124
125------
126
127### `isPrefixedProperty(property)`
128Checks if a `property` includes a vendor prefix.
129
130```javascript
131import { isPrefixedProperty } from 'css-in-js-utils'
132
133isPrefixedProperty('paddingTop')
134// => false
135
136isPrefixedProperty('WebkitTransition')
137// => true
138```
139
140------
141### `isPrefixedValue(value)`
142Checks if a `value` includes vendor prefixes.
143
144```javascript
145import { isPrefixedValue } from 'css-in-js-utils'
146
147isPrefixedValue('200px')
148isPrefixedValue(200)
149// => false
150
151isPrefixedValue('-webkit-calc(100% - 50px)')
152// => true
153```
154
155------
156
157### `isUnitlessProperty(property)`
158Checks if a `property` accepts unitless values.
159
160```javascript
161import { isUnitlessProperty } from 'css-in-js-utils'
162
163isUnitlessProperty('width')
164// => false
165
166isUnitlessProperty('flexGrow')
167isUnitlessProperty('lineHeight')
168isUnitlessProperty('line-height')
169// => true
170```
171
172------
173
174### `normalizeProperty(property)`
175Normalizes the `property` by unprefixing **and** camelCasing it.
176> Uses the [`camelCaseProperty`](#camelcasepropertyproperty) and [`unprefixProperty`](#unprefixpropertyproperty)-methods.
177
178```javascript
179import { normalizeProperty } from 'css-in-js-utils'
180
181normalizeProperty('-webkit-transition-delay')
182// => 'transitionDelay'
183```
184
185------
186
187### `resolveArrayValue(property, value)`
188Concatenates array values to single CSS value.
189> Uses the [`hyphenateProperty`](#hyphenatepropertyproperty)-method.
190
191
192```javascript
193import { resolveArrayValue } from 'css-in-js-utils'
194
195resolveArrayValue('display', [ '-webkit-flex', 'flex' ])
196// => '-webkit-flex;display:flex'
197
198resolveArrayValue('paddingTop', [ 'calc(100% - 50px)', '100px' ])
199// => 'calc(100% - 50px);padding-top:100px'
200```
201
202------
203
204### `unprefixProperty(property)`
205Removes the vendor prefix (if set) from the `property`.
206
207```javascript
208import { unprefixProperty } from 'css-in-js-utils'
209
210unprefixProperty('WebkitTransition')
211// => 'transition'
212
213unprefixProperty('transitionDelay')
214// => 'transitionDelay'
215```
216
217------
218
219### `unprefixValue(value)`
220Removes all vendor prefixes (if any) from the `value`.
221
222```javascript
223import { unprefixValue } from 'css-in-js-utils'
224
225unprefixValue('-webkit-calc(-moz-calc(100% - 50px)/2)')
226// => 'calc(calc(100% - 50px)/2)'
227
228unprefixValue('100px')
229// => '100px'
230```
231
232## Direct Import
233Every utility function may be imported directly to save bundle size.
234
235```javascript
236import camelCaseProperty from 'css-in-js-utils/lib/camelCaseProperty'
237```
238
239## License
240css-in-js-utils is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br>
241Documentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).<br>
242Created with ♥ by [@rofrischmann](http://rofrischmann.de).
Note: See TracBrowser for help on using the repository browser.