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.2
  • 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: (value) => ['--color', value]
}) // { width: '100px', '--color', '#fff' }
ParamTypesRequiredDescription
propsTyesBaseProps
mappingsPropMappingsnoPropMappings
  • @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
keystringyesThe PropMappingHandlerReturn key or customize key
valueVyesThe props[prop]'s value
strValuestringnoCustomize the value of PropMappingHandlerReturn

Types

BaseProps

PropTypesRequiredDescription
styleanynostyle
widthnumber/stringnowidth
minWidthnumber/stringno-
maxWidthnumber/stringno-
heightnumber/stringnoheight
minHeightnumber/stringno-
maxHeightnumber/stringno-
flexbooleannodisplay
gridbooleanno-
inlineFlexbooleanno-
inlineBlockbooleanno-
inlinebooleanno-
gapnumber/stringnoflex/grid
columnbooleanno-
alignProperty.AlignItemsno-
justifyProperty.JustifyContentno-
wrapboolean/Property.FlexWrapno-
paddingnumber/stringnopadding
paddingTopnumber/stringno-
paddingBottomnumber/stringno-
paddingLeftnumber/stringno-
paddingRightnumber/stringno-
paddingInlinenumber/stringno-
paddingBlocknumber/stringno-
marginnumber/stringnomargin
marginTopnumber/stringno-
marginBottomnumber/stringno-
marginLeftnumber/stringno-
marginRightnumber/stringno-
marginInlinenumber/stringno-
marginBlocknumber/stringno-
radiusstring/numbernoborder-radius
fontSizestring/numbernofont
fsstring/numbernofontSize
lineHeightstring/numberno-
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
Source Code
interface BaseProps {
  // style
  style?: any
  // width
  width?: number | string
  minWidth?: number | string
  maxWidth?: number | string
  // height
  height?: number | string
  minHeight?: number | string
  maxHeight?: number | string
  // display
  flex?: boolean
  grid?: boolean
  inlineFlex?: boolean
  inlineBlock?: boolean
  inline?: boolean
  // flex/grid
  gap?: number | string
  column?: boolean
  align?: Property.AlignItems
  justify?: Property.JustifyContent
  wrap?: boolean | Property.FlexWrap
  // padding
  padding?: number | string
  paddingTop?: number | string
  paddingBottom?: number | string
  paddingLeft?: number | string
  paddingRight?: number | string
  paddingInline?: number | string
  paddingBlock?: number | string
  // margin
  margin?: number | string
  marginTop?: number | string
  marginBottom?: number | string
  marginLeft?: number | string
  marginRight?: number | string
  marginInline?: number | string
  marginBlock?: number | string
  // border-radius
  radius?: string | number
  // font
  fontSize?: string | number
  // fontSize
  fs?: string | number
  lineHeight?: 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
}

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

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