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.7
  • 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, 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

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

createPropStyles(props, {
  // custom mapping handler
  color: (v) => ['--color', v]
}) // { width: '100px', '--color', '#fff' }
ParamTypesRequiredDescription
propsTyesBaseProps
mappingsPropMappings<T>noPropMappings
  • @generic T extends BaseProps

  • @returns Record<string, string>

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
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
alignContentProperty.AlignContentnoalign-content
justifyProperty.JustifyContentnojustify-content
justifyItemsProperty.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
boldbooleannobold of font
thinboolean/stringnothin of font
fontWeightProperty.FontWeightno-
fwProperty.FontWeightnofontWeight
borderstring/numbernoborder, border-width, border-color
tempColumnsstringnogrid-template-columns
tempRowsstringnogrid-template-rows
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-content
  alignContent?: Property.AlignContent
  // justify-content
  justify?: Property.JustifyContent
  // justify-items
  justifyItems?: 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
  // bold of font
  bold?: boolean
  // thin of font
  thin?: boolean | string
  fontWeight?: Property.FontWeight
  // fontWeight
  fw?: Property.FontWeight
  // border, border-width, border-color
  border?: string | number
  // grid-template-columns
  tempColumns?: string
  // grid-template-rows
  tempRows?: string
}

PropMappingHandler

PropMappings processing function, returns PropMappingHandlerReturn

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 25 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