Skip to content

Commit ce1264c

Browse files
authored
Merge pull request #176 from styled-components/allow-multiple-font-variants
Allow multiple font variant values to be used, fixes #175
2 parents 3701eee + 22d3223 commit ce1264c

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/__tests__/fontVariant.js

+8
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ it('transforms font variant as an array', () => {
55
fontVariant: ['tabular-nums'],
66
})
77
})
8+
9+
it('transforms multiple font variant as an array', () => {
10+
expect(
11+
transformCss([['font-variant', 'tabular-nums oldstyle-nums']])
12+
).toEqual({
13+
fontVariant: ['tabular-nums', 'oldstyle-nums'],
14+
})
15+
})

src/transforms/fontVariant.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { SPACE, IDENT } from '../tokenTypes'
2+
3+
export default tokenStream => {
4+
const values = [tokenStream.expect(IDENT)]
5+
6+
while (tokenStream.hasTokens()) {
7+
tokenStream.expect(SPACE)
8+
values.push(tokenStream.expect(IDENT))
9+
}
10+
11+
return {
12+
fontVariant: values,
13+
}
14+
}

src/transforms/index.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {
2-
IDENT,
3-
WORD,
2+
AUTO,
43
COLOR,
54
LENGTH,
6-
UNSUPPORTED_LENGTH_UNIT,
75
PERCENT,
8-
AUTO,
6+
UNSUPPORTED_LENGTH_UNIT,
7+
WORD,
98
} from '../tokenTypes'
109
import border from './border'
1110
import boxShadow from './boxShadow'
1211
import flex from './flex'
1312
import flexFlow from './flexFlow'
1413
import font from './font'
1514
import fontFamily from './fontFamily'
15+
import fontVariant from './fontVariant'
1616
import placeContent from './placeContent'
1717
import textDecoration from './textDecoration'
1818
import textDecorationLine from './textDecorationLine'
@@ -39,9 +39,7 @@ const margin = directionFactory({
3939
prefix: 'margin',
4040
})
4141
const padding = directionFactory({ prefix: 'padding' })
42-
const fontVariant = tokenStream => ({
43-
fontVariant: [tokenStream.expect(IDENT)],
44-
})
42+
4543
const fontWeight = tokenStream => ({
4644
fontWeight: tokenStream.expect(WORD), // Also match numbers as strings
4745
})

0 commit comments

Comments
 (0)