Skip to content

Commit 5d6e4fb

Browse files
author
Henri Beck
committed
Merge remote-tracking branch 'origin/feat/add-markdown-lint' into feat/add-markdown-lint
* origin/feat/add-markdown-lint: Scoped keyframes (#888)
2 parents 0396649 + a6f4ace commit 5d6e4fb

83 files changed

Lines changed: 1154 additions & 601 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

changelog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
## Next / 2018-09-16
22

33
- Fix multiple cases where linking CSS rules didn't work (#815, #710, #664)
4+
- Added support for Typed CSSOM values (#882)
5+
- Added scoped keyframes support (#346)
46
- Function values and function rules support now fallbacks, media queries, nesting, global styles (#682)
5-
- Added support for Typed CSSOM values
67

78
### Breaking changes
89

910
- Observables, function values and rules are now standalone packages, not part of the core. They are still part of the default preset though.
1011
- Function values, rules and observables apply plugins by default now, which means they can support all plugin defined syntaxes, but they are also slower by default. To speed them up use `sheet.update(data, {process: false})` for fn values/rules and `jss.use(pluginObservable({process: false}))` when setting up observables plugin. (#682)
12+
- Rule @keyframes has now scoped name by default, which means that you can access it using `$ref` from the same sheet and generate global one as before using `@global` rule ((#346).
13+
- Options `createGenerateClassName` and `generateClassName` are renamed to `createGenerateId` and `generateId` since th same function is now used to scope @keyframes rules. This affects both JSS and React-JSS.
1114

1215
## 9.8.7 / 2018-06-24
1316

docs/js-api.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default jss
3434

3535
Options:
3636

37-
- `createGenerateClassName` - a function which returns a function which generates unique class names.
37+
- `createGenerateId` - a function which returns a function which generates unique class names.
3838
- `plugins` - an array of functions, will be passed to `jss.use`.
3939
- `virtual` - if true, JSS will use VirtualRenderer.
4040
- `insertionPoint` - string value of a DOM comment node which marks the start of sheets or a rendered DOM node. Sheets rendered by this Jss instance are inserted after this point sequentially.
@@ -76,7 +76,7 @@ Options:
7676
- `link` - link jss `Rule` instances with DOM `CSSRule` instances so that styles, can be modified dynamically, false by default because it has some performance cost.
7777
- `element` - style element, will create one by default.
7878
- `index` - 0 by default - determines DOM rendering order, higher number = higher specificity (inserted after).
79-
- `generateClassName` - a function that generates a unique class name.
79+
- `generateId` - a function that generates a unique class name.
8080
- `classNamePrefix` - a string, which will be added at the beginning of the class name.
8181

8282
```javascript
@@ -386,22 +386,22 @@ console.log(sheet.toString())
386386

387387
## Generate your own class names
388388

389-
`createGenerateClassName`
389+
`createGenerateId`
390390

391-
Option `createGenerateClassName` allows you to specify a function which returns a class name generator function `generateClassName(rule, sheet)`. This pattern is used to allow JSS reset the counter upon factory invocation, when needed. For example, it is used in [React-JSS](https://github.com/cssinjs/react-jss) to reset the counter on each request for server-side rendering.
391+
Option `createGenerateId` allows you to specify a function which returns a class name generator function `generateId(rule, sheet)`. This pattern is used to allow JSS reset the counter upon factory invocation, when needed. For example, it is used in [React-JSS](https://github.com/cssinjs/react-jss) to reset the counter on each request for server-side rendering.
392392

393393
By default class names generator uses a simple counter to ensure uniqueness of the class names. It consists of `classNamePrefix` Style Sheet option + rule name + counter. **Note**: in production (`NODE_ENV=production`) it uses just the `c` + rules counter.
394394

395395
```javascript
396396
import jss from 'jss'
397397

398-
const createGenerateClassName = () => {
398+
const createGenerateId = () => {
399399
let counter = 0
400400

401401
return (rule, sheet) => `pizza--${rule.key}-${counter++}`
402402
}
403403

404-
jss.setup({createGenerateClassName})
404+
jss.setup({createGenerateId})
405405

406406
const sheet = jss.createStyleSheet({
407407
button: {

docs/json-api.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,41 +69,38 @@ Compiles to:
6969

7070
## Keyframes Animation
7171

72-
Note: keyframe id is still global and may conflict.
72+
Keyframes name will use the same id generator function as the class names. Animation name will be scoped by default. In order to access it within the same style sheet, you can use `$ref` syntax as a value of `animationName` or `animation` property.
7373

74-
```javascript
75-
const styles = {
76-
'@keyframes my-animation': {
77-
from: {opacity: 0},
78-
to: {opacity: 1}
79-
}
80-
}
81-
```
74+
Additionally generated name can be accessed through `sheet.keyframes.{name}` map.
8275

83-
### ES6 with generated keyframe id
76+
In order to generate a global animation name, you can use `@global` rule.
8477

8578
```javascript
86-
const animationId = Math.random()
87-
8879
const styles = {
89-
[`@keyframes ${animationId}`]: {
80+
'@keyframes slideRight': {
9081
from: {opacity: 0},
9182
to: {opacity: 1}
83+
},
84+
container: {
85+
animationName: '$slideRight'
9286
}
9387
}
9488
```
9589

9690
Compiles to:
9791

9892
```css
99-
@keyframes my-animation {
93+
@keyframes keyframes-slideRight-0-1-2 {
10094
from {
10195
opacity: 0;
10296
}
10397
to {
10498
opacity: 1;
10599
}
106100
}
101+
.container-0-1-3 {
102+
animation-name: keyframes-slideRight-0-1-2;
103+
}
107104
```
108105

109106
## Fallbacks

packages/jss-plugin-cache/.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"dist/jss-plugin-cache.js": {
3-
"bundled": 1058,
4-
"minified": 515,
5-
"gzipped": 330
3+
"bundled": 1066,
4+
"minified": 518,
5+
"gzipped": 331
66
},
77
"dist/jss-plugin-cache.min.js": {
8-
"bundled": 1058,
9-
"minified": 515,
10-
"gzipped": 330
8+
"bundled": 1066,
9+
"minified": 518,
10+
"gzipped": 331
1111
},
1212
"dist/jss-plugin-cache.cjs.js": {
13-
"bundled": 740,
14-
"minified": 368,
15-
"gzipped": 256
13+
"bundled": 748,
14+
"minified": 371,
15+
"gzipped": 258
1616
},
1717
"dist/jss-plugin-cache.esm.js": {
18-
"bundled": 658,
19-
"minified": 299,
20-
"gzipped": 213,
18+
"bundled": 666,
19+
"minified": 302,
20+
"gzipped": 215,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 0,

packages/jss-plugin-cache/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function cachePlugin(): Plugin {
55
const cache = new WeakMap()
66

77
function onCreateRule(name, decl, {parent}) {
8-
return parent ? cache.get(parent.rules.raw[name]) || null : null
8+
return parent && name ? cache.get(parent.rules.raw[name]) || null : null
99
}
1010

1111
function onProcessRule(rule) {

packages/jss-plugin-props-sort/src/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {create} from 'jss'
44
import propsSort from './index'
55

66
const settings = {
7-
createGenerateClassName: () => rule => `${rule.key}-id`
7+
createGenerateId: () => rule => `${rule.key}-id`
88
}
99

1010
describe('jss-plugin-props-sort', () => {

packages/jss-plugin-syntax-camel-case/src/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import functionPlugin from 'jss-plugin-syntax-rule-value-function'
66
import camelCase from './index'
77

88
const settings = {
9-
createGenerateClassName: () => rule => `${rule.key}-id`
9+
createGenerateId: () => rule => `${rule.key}-id`
1010
}
1111

1212
describe('jss-plugin-syntax-camel-case', () => {

packages/jss-plugin-syntax-compose/.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"dist/jss-plugin-syntax-compose.js": {
3-
"bundled": 3738,
4-
"minified": 1342,
5-
"gzipped": 756
3+
"bundled": 3745,
4+
"minified": 1345,
5+
"gzipped": 761
66
},
77
"dist/jss-plugin-syntax-compose.min.js": {
8-
"bundled": 2622,
9-
"minified": 822,
10-
"gzipped": 485
8+
"bundled": 2629,
9+
"minified": 825,
10+
"gzipped": 487
1111
},
1212
"dist/jss-plugin-syntax-compose.cjs.js": {
13-
"bundled": 2005,
14-
"minified": 840,
15-
"gzipped": 470
13+
"bundled": 2012,
14+
"minified": 843,
15+
"gzipped": 471
1616
},
1717
"dist/jss-plugin-syntax-compose.esm.js": {
18-
"bundled": 1787,
19-
"minified": 668,
20-
"gzipped": 381,
18+
"bundled": 1794,
19+
"minified": 671,
20+
"gzipped": 385,
2121
"treeshaked": {
2222
"rollup": {
2323
"code": 16,

packages/jss-plugin-syntax-compose/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function registerClass(rule, className) {
6262
*/
6363
export default function jssCompose(): Plugin {
6464
function onProcessStyle(style, rule) {
65-
if (!style.composes) return style
65+
if (!('composes' in style)) return style
6666
registerClass(rule, style.composes)
6767
// Remove composes property to prevent infinite loop.
6868
delete style.composes

packages/jss-plugin-syntax-compose/src/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import expect from 'expect.js'
44
import {create} from 'jss'
55
import compose from '.'
66

7-
const settings = {createGenerateClassName: () => rule => `${rule.key}-id`}
7+
const settings = {createGenerateId: () => rule => `${rule.key}-id`}
88

99
describe('jss-plugin-syntax-compose', () => {
1010
let jss

0 commit comments

Comments
 (0)