Skip to content

Commit dcac6a8

Browse files
Add svg prop enhancers (#131)
Resolves #130
1 parent cb41318 commit dcac6a8

File tree

7 files changed

+149
-2
lines changed

7 files changed

+149
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ All of these CSS properties are supported. You can pass either a string or a num
145145
- `content`
146146
- `cursor`
147147
- `display`
148+
- `fill`
148149
- `flex`
149150
- `flexBasis`
150151
- `flexDirection`
@@ -221,6 +222,12 @@ All of these CSS properties are supported. You can pass either a string or a num
221222
- `resize`
222223
- `right`
223224
- `rowGap`
225+
- `stroke`
226+
- `strokeDasharray`
227+
- `strokeDashoffset`
228+
- `strokeLinecap`
229+
- `strokeMiterlimit`
230+
- `strokeWidth`
224231
- `textAlign`
225232
- `textDecoration`
226233
- `textOverflow`
@@ -342,6 +349,7 @@ These enhancer groups are also exported. They're all objects with `{ propTypes,
342349
- `overflow`
343350
- `position`
344351
- `spacing`
352+
- `svg`
345353
- `text`
346354
- `transform`
347355
- `transition`

src/enhancers/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as position from './position'
1616
import * as resize from './resize'
1717
import * as selectors from './selectors'
1818
import * as spacing from './spacing'
19+
import * as svg from './svg'
1920
import * as text from './text'
2021
import * as transform from './transform'
2122
import * as transition from './transition'
@@ -40,6 +41,7 @@ export {
4041
resize,
4142
selectors,
4243
spacing,
44+
svg,
4345
text,
4446
transform,
4547
transition
@@ -64,6 +66,7 @@ export const propTypes: PropTypesMapping = {
6466
...resize.propTypes,
6567
...selectors.propTypes,
6668
...spacing.propTypes,
69+
...svg.propTypes,
6770
...text.propTypes,
6871
...transform.propTypes,
6972
...transition.propTypes
@@ -90,6 +93,7 @@ export const propAliases: PropAliases = {
9093
...resize.propAliases,
9194
...selectors.propAliases,
9295
...spacing.propAliases,
96+
...svg.propAliases,
9397
...text.propAliases,
9498
...transform.propAliases,
9599
...transition.propAliases
@@ -114,6 +118,7 @@ export const propValidators: PropValidators = {
114118
...resize.propValidators,
115119
...selectors.propValidators,
116120
...spacing.propValidators,
121+
...svg.propValidators,
117122
...text.propValidators,
118123
...transform.propValidators,
119124
...transition.propValidators
@@ -138,6 +143,7 @@ export const propEnhancers: PropEnhancers = {
138143
...resize.propEnhancers,
139144
...selectors.propEnhancers,
140145
...spacing.propEnhancers,
146+
...svg.propEnhancers,
141147
...text.propEnhancers,
142148
...transform.propEnhancers,
143149
...transition.propEnhancers

src/enhancers/svg.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import PropTypes from 'prop-types'
2+
import getCss from '../get-css'
3+
import { PropEnhancerValueType, PropValidators, PropEnhancers, PropTypesMapping, PropAliases } from '../types/enhancers'
4+
5+
export const propTypes: PropTypesMapping = {
6+
fill: PropTypes.string,
7+
stroke: PropTypes.string,
8+
strokeDasharray: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
9+
strokeDashoffset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
10+
strokeLinecap: PropTypes.string,
11+
strokeMiterlimit: PropTypes.number,
12+
strokeWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
13+
}
14+
15+
export const propAliases: PropAliases = {}
16+
export const propValidators: PropValidators = {}
17+
18+
const fill = {
19+
className: 'fill',
20+
cssName: 'fill',
21+
jsName: 'fill'
22+
}
23+
24+
const stroke = { className: 'strk', cssName: 'stroke', jsName: 'stroke' }
25+
26+
const strokeDasharray = {
27+
className: 'strk-dshary',
28+
cssName: 'stroke-dasharray',
29+
jsName: 'strokeDasharray',
30+
defaultUnit: ''
31+
}
32+
33+
const strokeDashoffset = {
34+
className: 'strk-dshofst',
35+
cssName: 'stroke-dashoffset',
36+
jsName: 'strokeDashoffset',
37+
defaultUnit: ''
38+
}
39+
40+
const strokeLinecap = { className: 'strk-lncp', cssName: 'stroke-linecap', jsName: 'strokeLinecap', safeValue: true }
41+
42+
const strokeMiterlimit = {
43+
className: 'strk-mtrlmt',
44+
cssName: 'stroke-miterlimit',
45+
jsName: 'strokeMiterlimit',
46+
defaultUnit: ''
47+
}
48+
49+
const strokeWidth = { className: 'strk-w', cssName: 'stroke-width', jsName: 'strokeWidth', defaultUnit: '' }
50+
51+
export const propEnhancers: PropEnhancers = {
52+
fill: (value: PropEnhancerValueType, selector: string) => getCss(fill, value, selector),
53+
stroke: (value: PropEnhancerValueType, selector: string) => getCss(stroke, value, selector),
54+
strokeDasharray: (value: PropEnhancerValueType, selector: string) => getCss(strokeDasharray, value, selector),
55+
strokeDashoffset: (value: PropEnhancerValueType, selector: string) => getCss(strokeDashoffset, value, selector),
56+
strokeLinecap: (value: PropEnhancerValueType, selector: string) => getCss(strokeLinecap, value, selector),
57+
strokeMiterlimit: (value: PropEnhancerValueType, selector: string) => getCss(strokeMiterlimit, value, selector),
58+
strokeWidth: (value: PropEnhancerValueType, selector: string) => getCss(strokeWidth, value, selector)
59+
}

src/types/enhancers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ export type CssProps = Pick<
150150
| 'wordWrap'
151151
| 'zIndex'
152152
> &
153-
Pick<CSS.ObsoleteProperties, 'gridColumnGap' | 'gridGap' | 'gridRowGap'>
153+
Pick<CSS.ObsoleteProperties, 'gridColumnGap' | 'gridGap' | 'gridRowGap'> &
154+
Pick<
155+
CSS.SvgProperties,
156+
'fill' | 'stroke' | 'strokeDasharray' | 'strokeDashoffset' | 'strokeLinecap' | 'strokeMiterlimit' | 'strokeWidth'
157+
>
154158

155159
export type BoxCssProps<CP> = {
156160
// Enhance the CSS props with the ui-box supported values.

test/snapshots/box.tsx.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Generated by [AVA](https://ava.li).
99
> DOM
1010
1111
<div
12-
className="ub-a-nm_openAnimation_65p985 ub-a-dur_2-5s ub-a-itr-ct_infinite ub-a-tmng-fn_lvnx00 ub-a-dir_both ub-a-ply-ste_running ub-a-dly_0s ub-algn-cnt_center ub-algn-itms_center ub-algn-slf_center ub-bg_169mlyl ub-bg-blnd-md_multiply ub-bg-clp_padding-box ub-bg-clr_red ub-bg-img_181xl07 ub-bg-orgn_border-box ub-bg-pos_center ub-bg-rpt_no-repeat ub-bg-siz_cover ub-b-btm_1px-solid-black ub-b-lft_1px-solid-black ub-b-rgt_1px-solid-black ub-b-top_1px-solid-black ub-b-btm-clr_red ub-bblr_5px ub-bbrr_5px ub-b-btm-stl_dashed ub-b-btm-wdt_2px ub-b-lft-clr_red ub-b-rgt-clr_red ub-b-top-clr_red ub-b-lft-stl_dashed ub-b-lft-wdt_2px ub-btlr_5px ub-btrr_5px ub-b-rgt-stl_dashed ub-b-rgt-wdt_2px ub-b-top-stl_dashed ub-b-top-wdt_2px ub-btm_10px ub-bs_1yidkis ub-box-szg_border-box ub-clr_both ub-clearfix ub-color_blue ub-col-gap_3px ub-cnt_1qde24a ub-crsr_pointer ub-dspl_flex ub-flx_1 ub-flx-basis_10px ub-flx-drct_column ub-flx-flow_column-wrap ub-flx-grow_1 ub-flx-srnk_1 ub-flx-wrap_wrap ub-flt_left ub-fnt_foz7o3 ub-fnt-fam_1bil31i ub-fnt-sze_14px ub-fnt-stl_italic ub-f-vari_small-caps ub-f-wght_bold ub-gap_3px ub-grd_1lsuugy ub-grd-ara_15fp4eo ub-grd-ato-col_1mp9azz ub-grd-ato-flw_row-dense ub-grd-ato-row_1mp9azz ub-grd-col_1i1wt59 ub-grd-col-end_span-3 ub-grd-col-gap_3px ub-grd-col-str_span-3 ub-grd-gap_3px ub-grd-row_1i1wt59 ub-grd-row-end_span-3 ub-grd-row-gap_3px ub-grd-row-str_span-3 ub-grd-tmp_1b7k023 ub-grd-tmp-ara_1s7jr1l ub-grd-tmp-col_2czdni ub-grd-tmp-row_2czdni ub-h_100px ub-just-cnt_center ub-just-items_center ub-just-self_center ub-lft_10px ub-ltr-spc_0-4em ub-ln-ht_1-2 ub-ls_1j8swju ub-ls-img_iu2jf4 ub-ls-pos_inside ub-ls-typ_lower-greek ub-mb_10px ub-ml_10px ub-mr_10px ub-mt_10px ub-max-h_100prcnt ub-max-w_100prcnt ub-min-h_100px ub-min-w_100px ub-opct_1 ub-order_1 ub-otln_iu2jf4 ub-ovflw-x_auto ub-ovflw-y_auto ub-pb_10px ub-pl_10px ub-pr_10px ub-pt_10px ub-plc-cnt_center-center ub-plc-items_center-center ub-plc-self_center-center ub-ptr-evts_auto ub-pst_relative ub-rsz_none ub-rgt_10px ub-row-gap_3px ub-bg-clr_nfznl2 ub-txt-algn_right ub-txt-deco_underline-dotted ub-txt-ovrf_ellipsis ub-txt-shdw_1kcg6ht ub-txt-trns_capitalize ub-top_10px ub-tfrm_yf7huz ub-tfrm-orgn_tkeb9y ub-tstn_7vzx02 ub-tstn-dly_ru3mkq ub-tstn-drn_i11nm5 ub-tstn-pty_ayd6f0 ub-tstn-tf_r9onko ub-usr-slct_none ub-vsblt_visible ub-wht-spc_nowrap ub-w_10ae43h ub-wrd-brk_normal ub-wrd-wrp_break-word ub-z-idx_1"
12+
className="ub-a-nm_openAnimation_65p985 ub-a-dur_2-5s ub-a-itr-ct_infinite ub-a-tmng-fn_lvnx00 ub-a-dir_both ub-a-ply-ste_running ub-a-dly_0s ub-algn-cnt_center ub-algn-itms_center ub-algn-slf_center ub-bg_169mlyl ub-bg-blnd-md_multiply ub-bg-clp_padding-box ub-bg-clr_red ub-bg-img_181xl07 ub-bg-orgn_border-box ub-bg-pos_center ub-bg-rpt_no-repeat ub-bg-siz_cover ub-b-btm_1px-solid-black ub-b-lft_1px-solid-black ub-b-rgt_1px-solid-black ub-b-top_1px-solid-black ub-b-btm-clr_red ub-bblr_5px ub-bbrr_5px ub-b-btm-stl_dashed ub-b-btm-wdt_2px ub-b-lft-clr_red ub-b-rgt-clr_red ub-b-top-clr_red ub-b-lft-stl_dashed ub-b-lft-wdt_2px ub-btlr_5px ub-btrr_5px ub-b-rgt-stl_dashed ub-b-rgt-wdt_2px ub-b-top-stl_dashed ub-b-top-wdt_2px ub-btm_10px ub-bs_1yidkis ub-box-szg_border-box ub-clr_both ub-clearfix ub-color_blue ub-col-gap_3px ub-cnt_1qde24a ub-crsr_pointer ub-dspl_flex ub-fill_black ub-flx_1 ub-flx-basis_10px ub-flx-drct_column ub-flx-flow_column-wrap ub-flx-grow_1 ub-flx-srnk_1 ub-flx-wrap_wrap ub-flt_left ub-fnt_foz7o3 ub-fnt-fam_1bil31i ub-fnt-sze_14px ub-fnt-stl_italic ub-f-vari_small-caps ub-f-wght_bold ub-gap_3px ub-grd_1lsuugy ub-grd-ara_15fp4eo ub-grd-ato-col_1mp9azz ub-grd-ato-flw_row-dense ub-grd-ato-row_1mp9azz ub-grd-col_1i1wt59 ub-grd-col-end_span-3 ub-grd-col-gap_3px ub-grd-col-str_span-3 ub-grd-gap_3px ub-grd-row_1i1wt59 ub-grd-row-end_span-3 ub-grd-row-gap_3px ub-grd-row-str_span-3 ub-grd-tmp_1b7k023 ub-grd-tmp-ara_1s7jr1l ub-grd-tmp-col_2czdni ub-grd-tmp-row_2czdni ub-h_100px ub-just-cnt_center ub-just-items_center ub-just-self_center ub-lft_10px ub-ltr-spc_0-4em ub-ln-ht_1-2 ub-ls_1j8swju ub-ls-img_iu2jf4 ub-ls-pos_inside ub-ls-typ_lower-greek ub-mb_10px ub-ml_10px ub-mr_10px ub-mt_10px ub-max-h_100prcnt ub-max-w_100prcnt ub-min-h_100px ub-min-w_100px ub-opct_1 ub-order_1 ub-otln_iu2jf4 ub-ovflw-x_auto ub-ovflw-y_auto ub-pb_10px ub-pl_10px ub-pr_10px ub-pt_10px ub-plc-cnt_center-center ub-plc-items_center-center ub-plc-self_center-center ub-ptr-evts_auto ub-pst_relative ub-rsz_none ub-rgt_10px ub-row-gap_3px ub-bg-clr_nfznl2 ub-strk_black ub-strk-dshary_10 ub-strk-dshofst_10 ub-strk-lncp_round ub-strk-mtrlmt_10 ub-strk-w_10 ub-txt-algn_right ub-txt-deco_underline-dotted ub-txt-ovrf_ellipsis ub-txt-shdw_1kcg6ht ub-txt-trns_capitalize ub-top_10px ub-tfrm_yf7huz ub-tfrm-orgn_tkeb9y ub-tstn_7vzx02 ub-tstn-dly_ru3mkq ub-tstn-drn_i11nm5 ub-tstn-pty_ayd6f0 ub-tstn-tf_r9onko ub-usr-slct_none ub-vsblt_visible ub-wht-spc_nowrap ub-w_10ae43h ub-wrd-brk_normal ub-wrd-wrp_break-word ub-z-idx_1"
1313
contentEditable={true}
1414
/>
1515

@@ -179,6 +179,9 @@ Generated by [AVA](https://ava.li).
179179
display: -webkit-flex;␊
180180
display: flex;␊
181181
}␊
182+
.ub-fill_black {␊
183+
fill: black;␊
184+
}␊
182185
.ub-flx_1 {␊
183186
flex: 1;␊
184187
}␊
@@ -395,6 +398,24 @@ Generated by [AVA](https://ava.li).
395398
.ub-bg-clr_nfznl2:hover {␊
396399
background-color: blue;␊
397400
}␊
401+
.ub-strk_black {␊
402+
stroke: black;␊
403+
}␊
404+
.ub-strk-dshary_10 {␊
405+
stroke-dasharray: 10;␊
406+
}␊
407+
.ub-strk-dshofst_10 {␊
408+
stroke-dashoffset: 10;␊
409+
}␊
410+
.ub-strk-lncp_round {␊
411+
stroke-linecap: round;␊
412+
}␊
413+
.ub-strk-mtrlmt_10 {␊
414+
stroke-miterlimit: 10;␊
415+
}␊
416+
.ub-strk-w_10 {␊
417+
stroke-width: 10;␊
418+
}␊
398419
.ub-txt-algn_right {␊
399420
text-align: right;␊
400421
}␊
@@ -818,6 +839,27 @@ Generated by [AVA](https://ava.li).
818839
.ub-pt_inherit {␊
819840
padding-top: inherit;␊
820841
}␊
842+
.ub-fill_inherit {␊
843+
fill: inherit;␊
844+
}␊
845+
.ub-strk_inherit {␊
846+
stroke: inherit;␊
847+
}␊
848+
.ub-strk-dshary_inherit {␊
849+
stroke-dasharray: inherit;␊
850+
}␊
851+
.ub-strk-dshofst_inherit {␊
852+
stroke-dashoffset: inherit;␊
853+
}␊
854+
.ub-strk-lncp_inherit {␊
855+
stroke-linecap: inherit;␊
856+
}␊
857+
.ub-strk-mtrlmt_inherit {␊
858+
stroke-miterlimit: inherit;␊
859+
}␊
860+
.ub-strk-w_inherit {␊
861+
stroke-width: inherit;␊
862+
}␊
821863
.ub-color_inherit {␊
822864
color: inherit;␊
823865
}␊
@@ -1253,6 +1295,27 @@ Generated by [AVA](https://ava.li).
12531295
.ub-pt_initial {␊
12541296
padding-top: initial;␊
12551297
}␊
1298+
.ub-fill_initial {␊
1299+
fill: initial;␊
1300+
}␊
1301+
.ub-strk_initial {␊
1302+
stroke: initial;␊
1303+
}␊
1304+
.ub-strk-dshary_initial {␊
1305+
stroke-dasharray: initial;␊
1306+
}␊
1307+
.ub-strk-dshofst_initial {␊
1308+
stroke-dashoffset: initial;␊
1309+
}␊
1310+
.ub-strk-lncp_initial {␊
1311+
stroke-linecap: initial;␊
1312+
}␊
1313+
.ub-strk-mtrlmt_initial {␊
1314+
stroke-miterlimit: initial;␊
1315+
}␊
1316+
.ub-strk-w_initial {␊
1317+
stroke-width: initial;␊
1318+
}␊
12561319
.ub-color_initial {␊
12571320
color: initial;␊
12581321
}␊

test/snapshots/box.tsx.snap

222 Bytes
Binary file not shown.

tools/all-properties-component.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export default () => {
7171
content={`""`}
7272
cursor="pointer"
7373
display="flex"
74+
fill="black"
7475
flex={1}
7576
flexBasis="10px"
7677
flexDirection="column"
@@ -152,6 +153,12 @@ export default () => {
152153
backgroundColor: 'blue'
153154
}
154155
}}
156+
stroke="black"
157+
strokeDasharray={10}
158+
strokeDashoffset={10}
159+
strokeLinecap="round"
160+
strokeMiterlimit={10}
161+
strokeWidth={10}
155162
textAlign="right"
156163
textDecoration="underline dotted"
157164
textOverflow="ellipsis"

0 commit comments

Comments
 (0)