Skip to content

Commit d8b5629

Browse files
committed
add support for directional border shorthands
1 parent 6197c9a commit d8b5629

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

src/__tests__/border.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,35 @@ it('transforms border shorthand missing color & style', () => {
6363
borderStyle: 'solid',
6464
})
6565
})
66+
67+
it('transforms bottom direction border shorthand', () => {
68+
expect(transformCss([['border-bottom', '2px dashed #f00']])).toEqual({
69+
borderBottomWidth: 2,
70+
borderBottomColor: '#f00',
71+
borderBottomStyle: 'dashed',
72+
})
73+
})
74+
75+
it('transforms left direction border shorthand', () => {
76+
expect(transformCss([['border-left', '2px dashed #f00']])).toEqual({
77+
borderLeftWidth: 2,
78+
borderLeftColor: '#f00',
79+
borderLeftStyle: 'dashed',
80+
})
81+
})
82+
83+
it('transforms right direction border shorthand', () => {
84+
expect(transformCss([['border-right', '2px dashed #f00']])).toEqual({
85+
borderRightWidth: 2,
86+
borderRightColor: '#f00',
87+
borderRightStyle: 'dashed',
88+
})
89+
})
90+
91+
it('transforms top direction border shorthand', () => {
92+
expect(transformCss([['border-top', '2px dashed #f00']])).toEqual({
93+
borderTopWidth: 2,
94+
borderTopColor: '#f00',
95+
borderTopStyle: 'dashed',
96+
})
97+
})

src/transforms/index.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,29 @@ const {
2222
const background = tokenStream => ({
2323
$merge: { backgroundColor: tokenStream.expect(COLOR) },
2424
})
25-
const border = anyOrderFactory({
26-
borderWidth: {
27-
tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
28-
default: 1,
29-
},
30-
borderColor: {
31-
tokens: [COLOR],
32-
default: 'black',
33-
},
34-
borderStyle: {
35-
tokens: [regExpToken(/^(solid|dashed|dotted)$/)],
36-
default: 'solid',
37-
},
38-
})
25+
26+
const createBorderFactory = (direction = '') =>
27+
anyOrderFactory({
28+
[`border${direction}Width`]: {
29+
tokens: [LENGTH, UNSUPPORTED_LENGTH_UNIT],
30+
default: 1,
31+
},
32+
[`border${direction}Color`]: {
33+
tokens: [COLOR],
34+
default: 'black',
35+
},
36+
[`border${direction}Style`]: {
37+
tokens: [regExpToken(/^(solid|dashed|dotted)$/)],
38+
default: 'solid',
39+
},
40+
})
41+
42+
const border = createBorderFactory()
43+
const borderTop = createBorderFactory('Top')
44+
const borderBottom = createBorderFactory('Bottom')
45+
const borderLeft = createBorderFactory('Left')
46+
const borderRight = createBorderFactory('Right')
47+
3948
const borderColor = directionFactory({
4049
types: [WORD],
4150
prefix: 'border',
@@ -70,6 +79,10 @@ const textShadowOffset = shadowOffsetFactory()
7079
export default {
7180
background,
7281
border,
82+
borderTop,
83+
borderBottom,
84+
borderLeft,
85+
borderRight,
7386
borderColor,
7487
borderRadius,
7588
borderWidth,

0 commit comments

Comments
 (0)