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.9
  • npm
  • Socket score

Version published
Maintainers
1
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, formatReturn } from '@prop-styles/core'

const style = createPropStyles({ color: 'red', width: 100 }, {
  color: (value) => value ? ['--color-primary', value] : null
  // or use formatReturn to make null judgment
  // color: (value) => formatReturn('--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 PropMappingHandlerReturn key or customize key
valueVyesThe props[prop]'s value
strValuestringnoCustomize 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) // ['width', '100']
formatReturn('width', '100px') // ['width', '100px']
formatReturn('width', 100, '100%') // ['width', '100%']

formatReturn('key', false) // null
formatReturn('key', '') // null
formatReturn('key', undefined) // null
formatReturn('key', null) // null
formatReturn('key', null, 'stringValue') // null
formatReturn('key', true, 'stringValue') // ['key', 'stringValue']
ParamTypesRequiredDescription
keyKyesThe PropMappingHandlerReturn key or customize key
valueVyesThe props[prop]'s value
strValuestringnoCustomize the value of PropMappingHandlerReturn

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
inlineFlexbooleanno-
inlineBlockbooleanno-
inlinebooleanno-
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/stringno-
pbnumber/stringnopadding-bottom
paddingLeftnumber/stringno-
plnumber/stringnopadding-left
paddingRightnumber/stringno-
prnumber/stringnopadding-right
paddingInlinenumber/stringno-
pxnumber/stringnopadding-inline
paddingBlocknumber/stringno-
pynumber/stringnopadding-block
marginnumber/stringnomargin
mnumber/stringnomargin
marginTopnumber/stringno-
mtnumber/stringnomargin-top
marginBottomnumber/stringno-
mbnumber/stringnomargin-bottom
marginLeftnumber/stringno-
mlnumber/stringnomargin-left
marginRightnumber/stringno-
mrnumber/stringnomargin-right
marginInlinenumber/stringno-
mxnumber/stringnomargin-inline
marginBlocknumber/stringno-
mynumber/stringnomargin-block
radiusstring/numbernoborder-radius
fontSizestring/numbernofont-size
fsstring/numbernofont-size
lineHeightstring/numberno-
lhstring/numbernoline-height
colorstringnocolor
backgroundProperty.Backgroundno-
bgProperty.Backgroundnobackground
scrollboolean/'x'/'y'noscroll direction
breakWordbooleannotext
boldbooleannofont-weight: bold
thinbooleannofont-weight: 500
fontWeightProperty.FontWeightno-
fwProperty.FontWeightnofontWeight
borderstring/numbernoborder, border-width, border-color
tempColumnsstringnogrid-template-columns
gtcstringnogrid-template-columns
tempRowsstringnogrid-template-rows
gtrstringnogrid-template-rows
textAlignProperty.TextAlignnotext-align
taProperty.TextAlignnotext-align
positionProperty.Positionnoposition
topstring/numberno-
tstring/numbernotop
rightstring/numberno-
rstring/numbernoright
bottomstring/numberno-
bstring/numbernobottom
leftstring/numberno-
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
  inlineFlex?: boolean
  inlineBlock?: boolean
  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
  paddingBottom?: number | string
  // padding-bottom
  pb?: number | string
  paddingLeft?: number | string
  // padding-left
  pl?: number | string
  paddingRight?: number | string
  // padding-right
  pr?: number | string
  paddingInline?: number | string
  // padding-inline
  px?: number | string
  paddingBlock?: number | string
  // padding-block
  py?: number | string
  // margin
  margin?: number | string
  // margin
  m?: number | string
  marginTop?: number | string
  // margin-top
  mt?: number | string
  marginBottom?: number | string
  // margin-bottom
  mb?: number | string
  marginLeft?: number | string
  // margin-left
  ml?: number | string
  marginRight?: number | string
  // margin-right
  mr?: number | string
  marginInline?: number | string
  // margin-inline
  mx?: number | string
  marginBlock?: number | string
  // margin-block
  my?: number | string
  // border-radius
  radius?: string | number
  // font-size
  fontSize?: string | number
  // font-size
  fs?: string | number
  lineHeight?: string | number
  // line-height
  lh?: string | number
  // color
  color?: string
  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
  fontWeight?: Property.FontWeight
  // fontWeight
  fw?: Property.FontWeight
  // border, border-width, border-color
  border?: string | number
  // grid-template-columns
  tempColumns?: string
  // grid-template-columns
  gtc?: string
  // grid-template-rows
  tempRows?: string
  // grid-template-rows
  gtr?: string
  // text-align
  textAlign?: Property.TextAlign
  // text-align
  ta?: Property.TextAlign
  // position
  position?: Property.Position
  top?: string | number
  // top
  t?: string | number
  right?: string | number
  // right
  r?: string | number
  bottom?: string | number
  // bottom
  b?: string | number
  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 29 Apr 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