@prop-styles/core
The library provides a static method createPropStyles to create Style objects.
npm i @prop-styles/core
Example
import { createPropStyles, formatReturn } from '@prop-styles/core'
const style = createPropStyles({ color: 'red', width: 100 }, {
color: (value) => value ? ['--color-primary', value] : null
})
Methods
createPropStyles(props, mappings)
Create Styles Object
Example
import { createPropStyles, f } from '@prop-styles/core'
const props = { width: 100, color: '#fff' }
createPropStyles(props)
createPropStyles(props, {
color: (v) => ['--color', v]
})
createPropStyles(props, {
color: (v) => f('--color', v)
})
f(key, value, strValue)
Alias and abbreviation of formatReturn.
Param | Types | Required | Description |
---|
key | K | yes | The PropMappingHandlerReturn key or customize key |
value | V | yes | The props[prop]'s value |
strValue | string | no | Customize the value of PropMappingHandlerReturn |
formatReturn(key, value, strValue)
Used for PropMappingHandler processing. When value
is null/undefined/''/false
, return null, otherwise return the specified value.
Example
formatReturn('width', 100)
formatReturn('width', '100px')
formatReturn('width', 100, '100%')
formatReturn('key', false)
formatReturn('key', '')
formatReturn('key', undefined)
formatReturn('key', null)
formatReturn('key', null, 'stringValue')
formatReturn('key', true, 'stringValue')
Param | Types | Required | Description |
---|
key | K | yes | The PropMappingHandlerReturn key or customize key |
value | V | yes | The props[prop]'s value |
strValue | string | no | Customize the value of PropMappingHandlerReturn |
Types
BaseProps
Commonly used CSS properties for components.
csstype Property
Prop | Types | Required | Description |
---|
style | any | no | style |
width | number /string | no | width |
minWidth | number /string | no | min-width |
maxWidth | number /string | no | max-width |
height | number /string | no | height |
minHeight | number /string | no | min-height |
maxHeight | number /string | no | max-height |
flex | boolean | no | display flex |
grid | boolean | no | display grid |
inlineFlex | boolean | no | - |
inlineBlock | boolean | no | - |
inline | boolean | no | - |
gap | number /string | no | flex/grid's gap |
column | boolean | no | flex-direction |
align | Property.AlignItems | no | align-items |
alignItems | Property.AlignItems | no | align-items |
ai | Property.AlignItems | no | align-items |
alignContent | Property.AlignContent | no | align-content |
ac | Property.AlignContent | no | align-content |
justify | Property.JustifyContent | no | justify-content |
justifyContent | Property.JustifyContent | no | justify-content |
jc | Property.JustifyContent | no | justify-content |
justifyItems | Property.JustifyItems | no | justify-items |
ji | Property.JustifyItems | no | justify-items |
wrap | boolean /Property.FlexWrap | no | flex-wrap |
nowrap | boolean | no | white-space: nowrap |
whiteSpace | Property.WhiteSpace | no | white-space |
padding | number /string | no | padding |
p | number /string | no | padding |
paddingTop | number /string | no | padding-top |
pt | number /string | no | padding-top |
paddingBottom | number /string | no | - |
pb | number /string | no | padding-bottom |
paddingLeft | number /string | no | - |
pl | number /string | no | padding-left |
paddingRight | number /string | no | - |
pr | number /string | no | padding-right |
paddingInline | number /string | no | - |
px | number /string | no | padding-inline |
paddingBlock | number /string | no | - |
py | number /string | no | padding-block |
margin | number /string | no | margin |
m | number /string | no | margin |
marginTop | number /string | no | - |
mt | number /string | no | margin-top |
marginBottom | number /string | no | - |
mb | number /string | no | margin-bottom |
marginLeft | number /string | no | - |
ml | number /string | no | margin-left |
marginRight | number /string | no | - |
mr | number /string | no | margin-right |
marginInline | number /string | no | - |
mx | number /string | no | margin-inline |
marginBlock | number /string | no | - |
my | number /string | no | margin-block |
radius | string /number | no | border-radius |
fontSize | string /number | no | font-size |
fs | string /number | no | font-size |
lineHeight | string /number | no | - |
lh | string /number | no | line-height |
color | string | no | color |
background | Property.Background | no | - |
bg | Property.Background | no | background |
scroll | boolean /'x' /'y' | no | scroll direction |
breakWord | boolean | no | text |
bold | boolean | no | font-weight: bold |
thin | boolean | no | font-weight: 500 |
fontWeight | Property.FontWeight | no | - |
fw | Property.FontWeight | no | fontWeight |
border | string /number | no | border, border-width, border-color |
tempColumns | string | no | grid-template-columns |
gtc | string | no | grid-template-columns |
tempRows | string | no | grid-template-rows |
gtr | string | no | grid-template-rows |
textAlign | Property.TextAlign | no | text-align |
ta | Property.TextAlign | no | text-align |
position | Property.Position | no | position |
top | string /number | no | - |
t | string /number | no | top |
right | string /number | no | - |
r | string /number | no | right |
bottom | string /number | no | - |
b | string /number | no | bottom |
left | string /number | no | - |
l | string /number | no | left |
zIndex | Property.ZIndex | no | z-index |
z | Property.ZIndex | no | z-index |
inset | string /number | no | inset |
transform | Property.Transform | no | transform |
tf | Property.Transform | no | transform |
Source Code
interface BaseProps {
style?: any
width?: number | string
minWidth?: number | string
maxWidth?: number | string
height?: number | string
minHeight?: number | string
maxHeight?: number | string
flex?: boolean
grid?: boolean
inlineFlex?: boolean
inlineBlock?: boolean
inline?: boolean
gap?: number | string
column?: boolean
align?: Property.AlignItems
alignItems?: Property.AlignItems
ai?: Property.AlignItems
alignContent?: Property.AlignContent
ac?: Property.AlignContent
justify?: Property.JustifyContent
justifyContent?: Property.JustifyContent
jc?: Property.JustifyContent
justifyItems?: Property.JustifyItems
ji?: Property.JustifyItems
wrap?: boolean | Property.FlexWrap
nowrap?: boolean
whiteSpace?: Property.WhiteSpace
padding?: number | string
p?: number | string
paddingTop?: number | string
pt?: number | string
paddingBottom?: number | string
pb?: number | string
paddingLeft?: number | string
pl?: number | string
paddingRight?: number | string
pr?: number | string
paddingInline?: number | string
px?: number | string
paddingBlock?: number | string
py?: number | string
margin?: number | string
m?: number | string
marginTop?: number | string
mt?: number | string
marginBottom?: number | string
mb?: number | string
marginLeft?: number | string
ml?: number | string
marginRight?: number | string
mr?: number | string
marginInline?: number | string
mx?: number | string
marginBlock?: number | string
my?: number | string
radius?: string | number
fontSize?: string | number
fs?: string | number
lineHeight?: string | number
lh?: string | number
color?: string
background?: Property.Background
bg?: Property.Background
scroll?: boolean | 'x' | 'y'
breakWord?: boolean
bold?: boolean
thin?: boolean
fontWeight?: Property.FontWeight
fw?: Property.FontWeight
border?: string | number
tempColumns?: string
gtc?: string
tempRows?: string
gtr?: string
textAlign?: Property.TextAlign
ta?: Property.TextAlign
position?: Property.Position
top?: string | number
t?: string | number
right?: string | number
r?: string | number
bottom?: string | number
b?: string | number
left?: string | number
l?: string | number
zIndex?: Property.ZIndex
z?: Property.ZIndex
inset?: string | number
transform?: Property.Transform
tf?: Property.Transform
}
PropMappingHandler
PropMappings processing function, returns [key: string, val: string] | null
Prop | Types | Required | Description |
---|
value | T[keyof T], | yes | - |
props | T | yes | - |
Source Code
type PropMappingHandler<T extends BaseProps> = (
value: T[keyof T],
props: T
) => PropMappingHandlerReturn
PropMappingHandlerReturn
PropMappingHandler's returns
Source Code
type PropMappingHandlerReturn = [key: string, val: string] | null
PropMappings
PropMappingHandler
Prop | Types | Required | Description |
---|
[key: keyof T] | PropMappingHandler<T> | yes | - |
Source Code
type PropMappings<T extends BaseProps> = {
[key: keyof T]: PropMappingHandler<T>
}
License
MIT License © 2024-Present Capricorncd.