Skip to content

Commit 3a3aad6

Browse files
authored
Merge pull request styled-components#66 from styled-components/text-decoration-line
Add support for text-decoration-line
2 parents 1c0abd2 + e424f89 commit 3a3aad6

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

src/index.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,41 @@ it('transforms text-decoration with none as part of multiple terms', () =>
620620
textDecorationColor: 'yellow',
621621
}))
622622

623+
it('transforms text-decoration with none in capitals', () =>
624+
runTest([['text-decoration', 'yellow NONE']], {
625+
textDecorationLine: 'none',
626+
textDecorationStyle: 'solid',
627+
textDecorationColor: 'yellow',
628+
}))
629+
630+
it('transforms text-decoration with style in capitals', () =>
631+
runTest([['text-decoration', 'yellow UNDERLINE LINE-THROUGH']], {
632+
textDecorationLine: 'underline line-through',
633+
textDecorationStyle: 'solid',
634+
textDecorationColor: 'yellow',
635+
}))
636+
623637
it('does not transform text-decoration if multiple colors are used', () => {
624638
expect(() =>
625639
transformCss([['text-decoration', 'underline red yellow']])
626640
).toThrow()
627641
})
628642

643+
it('transforms text-decoration-line with underline line-through', () =>
644+
runTest([['text-decoration-line', 'underline line-through']], {
645+
textDecorationLine: 'underline line-through',
646+
}))
647+
648+
it('transforms text-decoration-line with line-through underline', () =>
649+
runTest([['text-decoration-line', 'line-through underline']], {
650+
textDecorationLine: 'underline line-through',
651+
}))
652+
653+
it('transforms text-decoration-line with none', () =>
654+
runTest([['text-decoration-line', 'none']], {
655+
textDecorationLine: 'none',
656+
}))
657+
629658
it('allows blacklisting shorthands', () => {
630659
const actualStyles = transformCss([['border-radius', '50']], ['borderRadius'])
631660
expect(actualStyles).toEqual({ borderRadius: 50 })

src/tokenTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ module.exports.tokens = {
6767
IDENT: regExpToken(identRe),
6868
STRING: matchString,
6969
COLOR: matchColor,
70+
LINE: regExpToken(/^(none|underline|line-through)$/i),
7071
}

src/transforms/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const flex = require('./flex')
44
const font = require('./font')
55
const fontFamily = require('./fontFamily')
66
const textDecoration = require('./textDecoration')
7+
const textDecorationLine = require('./textDecorationLine')
78
const transform = require('./transform')
89
const {
910
directionFactory,
@@ -76,5 +77,6 @@ module.exports = {
7677
shadowOffset,
7778
textShadowOffset,
7879
textDecoration,
80+
textDecorationLine,
7981
transform,
8082
}

src/transforms/textDecoration.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { regExpToken, tokens } from '../tokenTypes'
22

3-
const { SPACE, COLOR } = tokens
3+
const { SPACE, LINE, COLOR } = tokens
44

55
const STYLE = regExpToken(/^(solid|double|dotted|dashed)$/)
6-
const LINE = regExpToken(/^(none|underline|line-through)$/)
76

87
const defaultTextDecorationLine = 'none'
98
const defaultTextDecorationStyle = 'solid'
@@ -19,15 +18,15 @@ module.exports = tokenStream => {
1918
if (didParseFirst) tokenStream.expect(SPACE)
2019

2120
if (line === undefined && tokenStream.matches(LINE)) {
22-
const lines = [tokenStream.lastValue]
21+
const lines = [tokenStream.lastValue.toLowerCase()]
2322

2423
tokenStream.saveRewindPoint()
2524
if (
2625
lines[0] !== 'none' &&
2726
tokenStream.matches(SPACE) &&
2827
tokenStream.matches(LINE)
2928
) {
30-
lines.push(tokenStream.lastValue)
29+
lines.push(tokenStream.lastValue.toLowerCase())
3130
// Underline comes before line-through
3231
lines.sort().reverse()
3332
} else {

src/transforms/textDecorationLine.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { tokens } = require('../tokenTypes')
2+
3+
const { SPACE, LINE } = tokens
4+
5+
module.exports = tokenStream => {
6+
const lines = []
7+
8+
let didParseFirst = false
9+
while (tokenStream.hasTokens()) {
10+
if (didParseFirst) tokenStream.expect(SPACE)
11+
12+
lines.push(tokenStream.expect(LINE).toLowerCase())
13+
14+
didParseFirst = true
15+
}
16+
17+
lines.sort().reverse()
18+
19+
return lines.join(' ')
20+
}

0 commit comments

Comments
 (0)