diff --git a/README.md b/README.md index f9932cc..d3773f0 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ All of these CSS properties are supported. You can pass either a string or a num - `content` - `cursor` - `display` +- `fill` - `flex` - `flexBasis` - `flexDirection` @@ -221,6 +222,12 @@ All of these CSS properties are supported. You can pass either a string or a num - `resize` - `right` - `rowGap` +- `stroke` +- `strokeDasharray` +- `strokeDashoffset` +- `strokeLinecap` +- `strokeMiterlimit` +- `strokeWidth` - `textAlign` - `textDecoration` - `textOverflow` @@ -342,6 +349,7 @@ These enhancer groups are also exported. They're all objects with `{ propTypes, - `overflow` - `position` - `spacing` +- `svg` - `text` - `transform` - `transition` diff --git a/src/enhancers/index.ts b/src/enhancers/index.ts index 78a5855..9b6c62f 100644 --- a/src/enhancers/index.ts +++ b/src/enhancers/index.ts @@ -16,6 +16,7 @@ import * as position from './position' import * as resize from './resize' import * as selectors from './selectors' import * as spacing from './spacing' +import * as svg from './svg' import * as text from './text' import * as transform from './transform' import * as transition from './transition' @@ -40,6 +41,7 @@ export { resize, selectors, spacing, + svg, text, transform, transition @@ -64,6 +66,7 @@ export const propTypes: PropTypesMapping = { ...resize.propTypes, ...selectors.propTypes, ...spacing.propTypes, + ...svg.propTypes, ...text.propTypes, ...transform.propTypes, ...transition.propTypes @@ -90,6 +93,7 @@ export const propAliases: PropAliases = { ...resize.propAliases, ...selectors.propAliases, ...spacing.propAliases, + ...svg.propAliases, ...text.propAliases, ...transform.propAliases, ...transition.propAliases @@ -114,6 +118,7 @@ export const propValidators: PropValidators = { ...resize.propValidators, ...selectors.propValidators, ...spacing.propValidators, + ...svg.propValidators, ...text.propValidators, ...transform.propValidators, ...transition.propValidators @@ -138,6 +143,7 @@ export const propEnhancers: PropEnhancers = { ...resize.propEnhancers, ...selectors.propEnhancers, ...spacing.propEnhancers, + ...svg.propEnhancers, ...text.propEnhancers, ...transform.propEnhancers, ...transition.propEnhancers diff --git a/src/enhancers/svg.ts b/src/enhancers/svg.ts new file mode 100644 index 0000000..8aaab65 --- /dev/null +++ b/src/enhancers/svg.ts @@ -0,0 +1,59 @@ +import PropTypes from 'prop-types' +import getCss from '../get-css' +import { PropEnhancerValueType, PropValidators, PropEnhancers, PropTypesMapping, PropAliases } from '../types/enhancers' + +export const propTypes: PropTypesMapping = { + fill: PropTypes.string, + stroke: PropTypes.string, + strokeDasharray: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + strokeDashoffset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + strokeLinecap: PropTypes.string, + strokeMiterlimit: PropTypes.number, + strokeWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) +} + +export const propAliases: PropAliases = {} +export const propValidators: PropValidators = {} + +const fill = { + className: 'fill', + cssName: 'fill', + jsName: 'fill' +} + +const stroke = { className: 'strk', cssName: 'stroke', jsName: 'stroke' } + +const strokeDasharray = { + className: 'strk-dshary', + cssName: 'stroke-dasharray', + jsName: 'strokeDasharray', + defaultUnit: '' +} + +const strokeDashoffset = { + className: 'strk-dshofst', + cssName: 'stroke-dashoffset', + jsName: 'strokeDashoffset', + defaultUnit: '' +} + +const strokeLinecap = { className: 'strk-lncp', cssName: 'stroke-linecap', jsName: 'strokeLinecap', safeValue: true } + +const strokeMiterlimit = { + className: 'strk-mtrlmt', + cssName: 'stroke-miterlimit', + jsName: 'strokeMiterlimit', + defaultUnit: '' +} + +const strokeWidth = { className: 'strk-w', cssName: 'stroke-width', jsName: 'strokeWidth', defaultUnit: '' } + +export const propEnhancers: PropEnhancers = { + fill: (value: PropEnhancerValueType, selector: string) => getCss(fill, value, selector), + stroke: (value: PropEnhancerValueType, selector: string) => getCss(stroke, value, selector), + strokeDasharray: (value: PropEnhancerValueType, selector: string) => getCss(strokeDasharray, value, selector), + strokeDashoffset: (value: PropEnhancerValueType, selector: string) => getCss(strokeDashoffset, value, selector), + strokeLinecap: (value: PropEnhancerValueType, selector: string) => getCss(strokeLinecap, value, selector), + strokeMiterlimit: (value: PropEnhancerValueType, selector: string) => getCss(strokeMiterlimit, value, selector), + strokeWidth: (value: PropEnhancerValueType, selector: string) => getCss(strokeWidth, value, selector) +} diff --git a/src/types/enhancers.ts b/src/types/enhancers.ts index 143c526..57431cd 100644 --- a/src/types/enhancers.ts +++ b/src/types/enhancers.ts @@ -150,7 +150,11 @@ export type CssProps = Pick< | 'wordWrap' | 'zIndex' > & - Pick + Pick & + Pick< + CSS.SvgProperties, + 'fill' | 'stroke' | 'strokeDasharray' | 'strokeDashoffset' | 'strokeLinecap' | 'strokeMiterlimit' | 'strokeWidth' + > export type BoxCssProps = { // Enhance the CSS props with the ui-box supported values. diff --git a/test/snapshots/box.tsx.md b/test/snapshots/box.tsx.md index 96b665b..16e131f 100644 --- a/test/snapshots/box.tsx.md +++ b/test/snapshots/box.tsx.md @@ -9,7 +9,7 @@ Generated by [AVA](https://ava.li). > DOM
@@ -179,6 +179,9 @@ Generated by [AVA](https://ava.li). display: -webkit-flex;␊ display: flex;␊ }␊ + .ub-fill_black {␊ + fill: black;␊ + }␊ .ub-flx_1 {␊ flex: 1;␊ }␊ @@ -395,6 +398,24 @@ Generated by [AVA](https://ava.li). .ub-bg-clr_nfznl2:hover {␊ background-color: blue;␊ }␊ + .ub-strk_black {␊ + stroke: black;␊ + }␊ + .ub-strk-dshary_10 {␊ + stroke-dasharray: 10;␊ + }␊ + .ub-strk-dshofst_10 {␊ + stroke-dashoffset: 10;␊ + }␊ + .ub-strk-lncp_round {␊ + stroke-linecap: round;␊ + }␊ + .ub-strk-mtrlmt_10 {␊ + stroke-miterlimit: 10;␊ + }␊ + .ub-strk-w_10 {␊ + stroke-width: 10;␊ + }␊ .ub-txt-algn_right {␊ text-align: right;␊ }␊ @@ -818,6 +839,27 @@ Generated by [AVA](https://ava.li). .ub-pt_inherit {␊ padding-top: inherit;␊ }␊ + .ub-fill_inherit {␊ + fill: inherit;␊ + }␊ + .ub-strk_inherit {␊ + stroke: inherit;␊ + }␊ + .ub-strk-dshary_inherit {␊ + stroke-dasharray: inherit;␊ + }␊ + .ub-strk-dshofst_inherit {␊ + stroke-dashoffset: inherit;␊ + }␊ + .ub-strk-lncp_inherit {␊ + stroke-linecap: inherit;␊ + }␊ + .ub-strk-mtrlmt_inherit {␊ + stroke-miterlimit: inherit;␊ + }␊ + .ub-strk-w_inherit {␊ + stroke-width: inherit;␊ + }␊ .ub-color_inherit {␊ color: inherit;␊ }␊ @@ -1253,6 +1295,27 @@ Generated by [AVA](https://ava.li). .ub-pt_initial {␊ padding-top: initial;␊ }␊ + .ub-fill_initial {␊ + fill: initial;␊ + }␊ + .ub-strk_initial {␊ + stroke: initial;␊ + }␊ + .ub-strk-dshary_initial {␊ + stroke-dasharray: initial;␊ + }␊ + .ub-strk-dshofst_initial {␊ + stroke-dashoffset: initial;␊ + }␊ + .ub-strk-lncp_initial {␊ + stroke-linecap: initial;␊ + }␊ + .ub-strk-mtrlmt_initial {␊ + stroke-miterlimit: initial;␊ + }␊ + .ub-strk-w_initial {␊ + stroke-width: initial;␊ + }␊ .ub-color_initial {␊ color: initial;␊ }␊ diff --git a/test/snapshots/box.tsx.snap b/test/snapshots/box.tsx.snap index b47c556..8f85448 100644 Binary files a/test/snapshots/box.tsx.snap and b/test/snapshots/box.tsx.snap differ diff --git a/tools/all-properties-component.tsx b/tools/all-properties-component.tsx index fa5fa4d..f39c944 100644 --- a/tools/all-properties-component.tsx +++ b/tools/all-properties-component.tsx @@ -71,6 +71,7 @@ export default () => { content={`""`} cursor="pointer" display="flex" + fill="black" flex={1} flexBasis="10px" flexDirection="column" @@ -152,6 +153,12 @@ export default () => { backgroundColor: 'blue' } }} + stroke="black" + strokeDasharray={10} + strokeDashoffset={10} + strokeLinecap="round" + strokeMiterlimit={10} + strokeWidth={10} textAlign="right" textDecoration="underline dotted" textOverflow="ellipsis"