Skip to content

Commit a063957

Browse files
committed
support for pseduo selectors
1 parent e24f004 commit a063957

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/babel/__tests__/__snapshots__/index.test.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ exports[`merging.jsx 1`] = `"export const Component = () => <div className={\\"x
3232

3333
exports[`merging.jsx 2`] = `.xp5623v {color:green}`;
3434

35+
exports[`pseudo.jsx 1`] = `"export const Component = () => <div className={\\"x1dqz7z3 x1jz5mb\\"} />;"`;
36+
37+
exports[`pseudo.jsx 2`] = `
38+
.x1dqz7z3 {color:red}
39+
.x1jz5mb:hover {color:green}
40+
`;
41+
3542
exports[`simple.jsx 1`] = `"export const Component = () => <div className={\\"x1e4w2a9\\"} />;"`;
3643

3744
exports[`simple.jsx 2`] = `.x1e4w2a9 {font-size:16px}`;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {css, styles} from 'css-zero';
2+
3+
const one = css`
4+
color: red;
5+
6+
&:hover {
7+
color: green;
8+
}
9+
`;
10+
11+
export const Component = () => <div className={styles(one)} />;

src/babel/utils/atomizer.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ const fnv1a = require('fnv1a');
33
const id = seed => 'x' + fnv1a(seed).toString(36);
44
const hyphenate = s => s.replace(/[A-Z]|^ms/g, '-$&').toLowerCase();
55

6-
const createRule = (key, value, media) => {
6+
const createRule = (className, key, value, children, media) => {
77
const hyphenated = hyphenate(key);
8-
const cssText = hyphenated + ':' + value;
8+
let cssText = hyphenated + ':' + value;
9+
910
return {
10-
key: hyphenated,
11-
value,
11+
key: children + hyphenated,
12+
selector: '.' + className + children,
1213
media,
1314
cssText: media ? media + '{' + cssText + '}' : cssText,
1415
};
@@ -35,7 +36,7 @@ const parse = (obj, children = '', media = '') => {
3536
case 'number':
3637
case 'string':
3738
const className = id(key + value + children + media);
38-
const rule = createRule(key, value, media);
39+
const rule = createRule(className, key, value, children, media);
3940
rules.push([className, rule]);
4041
}
4142
}

0 commit comments

Comments
 (0)