Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prop-styles/core

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prop-styles/core

The library provides a static method createPropStyles to create Style objects.

  • 0.0.11
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

@prop-styles/core

Downloads Version License

The library provides a static method createPropStyles to create Style objects.

npm i @prop-styles/core

Example

import { createPropStyles, f } from '@prop-styles/core'

const style = createPropStyles({ color: 'red', width: 100 }, {
  color: (value) => value ? ['--color-primary', value] : null
  // or Use f function to remove null/undefined props
  // color: (value) => f('--color-primary', value)
})

// style
// { '--color-primary': 'red', width: '100px' }

Methods

createPropStyles(props, mappings)

Create Styles Object

Example

import { createPropStyles, f } from '@prop-styles/core'

const props = { width: 100, color: '#fff' }

createPropStyles(props) // { width: '100px', color, '#fff' }

// Use custom Mapping handler
createPropStyles(props, {
  // custom mapping handler
  color: (v) => ['--color', v]
}) // { width: '100px', '--color', '#fff' }

// Use f function to remove null/undefined props
createPropStyles(props, {
  color: (v) => f('--color', v)
}) // { width: '100px', '--color', '#fff' }
ParamTypesRequiredDescription
propsTyesBaseProps
mappingsPropMappings<T>noPropMappings
  • @generic T extends BaseProps

  • @returns Record<string, string>

f(key, value, strValue)

Alias and abbreviation of formatReturn.

ParamTypesRequiredDescription
keyKyesThe PropMappingHandler Return key or customize key
valueVyesThe props[prop]'s value
strValuestringnoCustomize the value of PropMappingHandler Return
  • @generic K extends string, V

  • @returns [key: string, val: string] | null

formatReturn(key, value, strValue)

Used for PropMappingHandler processing. When value is null/undefined/''/false, return null, otherwise return the specified value.

Example

f('width', 100) // ['width', '100']
f('width', '100px') // ['width', '100px']
f('width', 100, '100%') // ['width', '100%']

f('key', false) // null
f('key', '') // null
f('key', undefined) // null
f('key', null) // null
f('key', null, 'stringValue') // null
f('key', true, 'stringValue') // ['key', 'stringValue']
ParamTypesRequiredDescription
keyKyesThe PropMappingHandler Return key or customize key
valueVyesThe props[prop]'s value
strValuestringnoCustomize the value of PropMappingHandler Return
  • @generic K extends string, V

  • @returns [key: string, val: string] | null

Types

BaseProps

Commonly used CSS properties for components.

csstype Property

PropTypesRequiredDescription
styleanynostyle
widthnumber/stringnowidth
minWidthnumber/stringnomin-width
maxWidthnumber/stringnomax-width
heightnumber/stringnoheight
minHeightnumber/stringnomin-height
maxHeightnumber/stringnomax-height
flexbooleannodisplay: flex
gridbooleannodisplay: grid
inlineFlexbooleannodisplay: inline-flex
inlineBlockbooleannodisplay: inline-block
inlinebooleannodisplay: inline
gapnumber/stringnoflex/grid's gap
columnbooleannoflex-direction
alignProperty.AlignItemsnoalign-items
alignItemsProperty.AlignItemsnoalign-items
aiProperty.AlignItemsnoalign-items
alignContentProperty.AlignContentnoalign-content
acProperty.AlignContentnoalign-content
justifyProperty.JustifyContentnojustify-content
justifyContentProperty.JustifyContentnojustify-content
jcProperty.JustifyContentnojustify-content
justifyItemsProperty.JustifyItemsnojustify-items
jiProperty.JustifyItemsnojustify-items
wrapboolean/Property.FlexWrapnoflex-wrap
nowrapbooleannowhite-space: nowrap
whiteSpaceProperty.WhiteSpacenowhite-space
paddingnumber/stringnopadding
pnumber/stringnopadding
paddingTopnumber/stringnopadding-top
ptnumber/stringnopadding-top
paddingBottomnumber/stringnopadding-bottom
pbnumber/stringnopadding-bottom
paddingLeftnumber/stringnopadding-left
plnumber/stringnopadding-left
paddingRightnumber/stringnopadding-right
prnumber/stringnopadding-right
paddingInlinenumber/stringnopadding-inline
pxnumber/stringnopadding-inline
paddingBlocknumber/stringnopadding-block
pynumber/stringnopadding-block
marginnumber/stringnomargin
mnumber/stringnomargin
marginTopnumber/stringnomargin-top
mtnumber/stringnomargin-top
marginBottomnumber/stringnomargin-bottom
mbnumber/stringnomargin-bottom
marginLeftnumber/stringnomargin-left
mlnumber/stringnomargin-left
marginRightnumber/stringnomargin-right
mrnumber/stringnomargin-right
marginInlinenumber/stringnomargin-inline
mxnumber/stringnomargin-inline
marginBlocknumber/stringnomargin-block
mynumber/stringnomargin-block
radiusstring/numbernoborder-radius
fontSizestring/numbernofont-size
fsstring/numbernofont-size
lineHeightstring/numbernoline-height
lhstring/numbernoline-height
colorstringnocolor
backgroundProperty.Backgroundnobackground
bgProperty.Backgroundnobackground
scrollboolean/'x'/'y'noscroll direction
breakWordbooleannotext
boldbooleannofont-weight: bold
thinbooleannofont-weight: 500
fontWeightProperty.FontWeightnofont-weight
fwProperty.FontWeightnofont-weight
borderstring/numbernoborder, border-width, border-color
tempColumnsstring/numbernogrid-template-columns
gtcstring/numbernogrid-template-columns
tempRowsstring/numbernogrid-template-rows
gtrstring/numbernogrid-template-rows
textAlignProperty.TextAlignnotext-align
taProperty.TextAlignnotext-align
positionProperty.Positionnoposition
topstring/numberno-
tstring/numbernotop
rightstring/numbernoright
rstring/numbernoright
bottomstring/numbernobottom
bstring/numbernobottom
leftstring/numbernoleft
lstring/numbernoleft
zIndexProperty.ZIndexnoz-index
zProperty.ZIndexnoz-index
insetstring/numbernoinset
transformProperty.Transformnotransform
tfProperty.Transformnotransform
Source Code
interface BaseProps {
  // style
  style?: any
  // width
  width?: number | string
  // min-width
  minWidth?: number | string
  // max-width
  maxWidth?: number | string
  // height
  height?: number | string
  // min-height
  minHeight?: number | string
  // max-height
  maxHeight?: number | string
  // display: flex
  flex?: boolean
  // display: grid
  grid?: boolean
  // display: inline-flex
  inlineFlex?: boolean
  // display: inline-block
  inlineBlock?: boolean
  // display: inline
  inline?: boolean
  // flex/grid's gap
  gap?: number | string
  // flex-direction
  column?: boolean
  // align-items
  align?: Property.AlignItems
  // align-items
  alignItems?: Property.AlignItems
  // align-items
  ai?: Property.AlignItems
  // align-content
  alignContent?: Property.AlignContent
  // align-content
  ac?: Property.AlignContent
  // justify-content
  justify?: Property.JustifyContent
  // justify-content
  justifyContent?: Property.JustifyContent
  // justify-content
  jc?: Property.JustifyContent
  // justify-items
  justifyItems?: Property.JustifyItems
  // justify-items
  ji?: Property.JustifyItems
  // flex-wrap
  wrap?: boolean | Property.FlexWrap
  // white-space: nowrap
  nowrap?: boolean
  // white-space
  whiteSpace?: Property.WhiteSpace
  // padding
  padding?: number | string
  // padding
  p?: number | string
  // padding-top
  paddingTop?: number | string
  // padding-top
  pt?: number | string
  // padding-bottom
  paddingBottom?: number | string
  // padding-bottom
  pb?: number | string
  // padding-left
  paddingLeft?: number | string
  // padding-left
  pl?: number | string
  // padding-right
  paddingRight?: number | string
  // padding-right
  pr?: number | string
  // padding-inline
  paddingInline?: number | string
  // padding-inline
  px?: number | string
  // padding-block
  paddingBlock?: number | string
  // padding-block
  py?: number | string
  // margin
  margin?: number | string
  // margin
  m?: number | string
  // margin-top
  marginTop?: number | string
  // margin-top
  mt?: number | string
  // margin-bottom
  marginBottom?: number | string
  // margin-bottom
  mb?: number | string
  // margin-left
  marginLeft?: number | string
  // margin-left
  ml?: number | string
  // margin-right
  marginRight?: number | string
  // margin-right
  mr?: number | string
  // margin-inline
  marginInline?: number | string
  // margin-inline
  mx?: number | string
  // margin-block
  marginBlock?: number | string
  // margin-block
  my?: number | string
  // border-radius
  radius?: string | number
  // font-size
  fontSize?: string | number
  // font-size
  fs?: string | number
  // line-height
  lineHeight?: string | number
  // line-height
  lh?: string | number
  // color
  color?: string
  // background
  background?: Property.Background
  // background
  bg?: Property.Background
  // scroll direction
  scroll?: boolean | 'x' | 'y'
  // text
  breakWord?: boolean
  // font-weight: bold
  bold?: boolean
  // font-weight: 500
  thin?: boolean
  // font-weight
  fontWeight?: Property.FontWeight
  // font-weight
  fw?: Property.FontWeight
  // border, border-width, border-color
  border?: string | number
  // grid-template-columns
  tempColumns?: string | number
  // grid-template-columns
  gtc?: string | number
  // grid-template-rows
  tempRows?: string | number
  // grid-template-rows
  gtr?: string | number
  // text-align
  textAlign?: Property.TextAlign
  // text-align
  ta?: Property.TextAlign
  // position
  position?: Property.Position
  top?: string | number
  // top
  t?: string | number
  // right
  right?: string | number
  // right
  r?: string | number
  // bottom
  bottom?: string | number
  // bottom
  b?: string | number
  // left
  left?: string | number
  // left
  l?: string | number
  // z-index
  zIndex?: Property.ZIndex
  // z-index
  z?: Property.ZIndex
  // inset
  inset?: string | number
  // transform
  transform?: Property.Transform
  // transform
  tf?: Property.Transform
}

PropMappingHandler

PropMappings processing function, returns [key: string, val: string] | null

PropTypesRequiredDescription
valueT[keyof T],yes-
propsTyes-
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

PropTypesRequiredDescription
[key: keyof T]PropMappingHandler<T>yes-
Source Code
type PropMappings<T extends BaseProps> = {
  [key: keyof T]: PropMappingHandler<T>
}

License

MIT License © 2024-Present Capricorncd.

Keywords

FAQs

Package last updated on 08 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc