Socket
Book a DemoInstallSign in
Socket

@prop-styles/core

Package Overview
Dependencies
Maintainers
1
Versions
13
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.

npmnpm
Version
1.0.0-beta05112249
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, 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, format } 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 format function to remove null/undefined props
createPropStyles(props, {
  color: (v) => format('--color', v)
}) // { width: '100px', '--color', '#fff' }
ParamTypesRequiredDescription
propsTyesBaseProps
mappingsPropMappings<T>noPropMappings
  • @generic T extends BaseProps

  • @returns Record<string, string>

transform(key, value, strValue)

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

Example

transform('width', 100) // { key: 'width', value: '100' }
transform('width', '100px') // { key: 'width', value: '100px' }
transform('width', 100, '100%') // { key: 'width', value: '100%' }

transform('key', false) // null
transform('key', '') // null
transform('key', undefined) // null
transform('key', null) // null
transform('key', null, 'stringValue') // null
transform('key', true, 'stringValue') // { key: 'key', value: 'stringValue' }
ParamTypesRequiredDescription
keystringyesThe PropMappingHandler Return key or customize key
valueanyyesThe props[prop]'s value
strValuestringnoCustomize the value of PropMappingHandler Return
  • @returns { key: string, value: string } | null

Types

BaseProps

Commonly used CSS properties for components.

csstype Property

PropTypesRequiredDescription
displayProperty.Displaynodisplay
widthnumber/stringnowidth
minWidthnumber/stringnomin-width
maxWidthnumber/stringnomax-width
heightnumber/stringnoheight
minHeightnumber/stringnomin-height
maxHeightnumber/stringnomax-height
flexProperty.Flexnoflex
gapnumber/stringnoflex/grid's gap
columnbooleannoflex-direction
fdProperty.FlexDirectionnoflex-direction
aiProperty.AlignItemsnoalign-items
acProperty.AlignContentnoalign-content
jiProperty.JustifyItemsnojustify-items
jcProperty.JustifyContentnojustify-content
wrapboolean/Property.FlexWrapnoflex-wrap
wsProperty.WhiteSpacenowhite-space
pnumber/stringnopadding
ptnumber/stringnopadding-top
prnumber/stringnopadding-right
pbnumber/stringnopadding-bottom
plnumber/stringnopadding-left
pxnumber/stringnopadding-inline
pynumber/stringnopadding-block
mnumber/stringnomargin
mtnumber/stringnomargin-top
mrnumber/stringnomargin-right
mbnumber/stringnomargin-bottom
mlnumber/stringnomargin-left
mxnumber/stringnomargin-inline
mynumber/stringnomargin-block
radiusstring/numbernoborder-radius
fsstring/numbernofont-size
fwProperty.FontWeightnofont-weight
lhstring/numbernoline-height
colorstringnocolor
bgProperty.Backgroundnobackground
scrollboolean/'x'/'y'noscroll direction
breakWordbooleannotext
borderstring/numbernoborder, border-width, border-color
gtcstring/numbernogrid-template-columns
gtrstring/numbernogrid-template-rows
taProperty.TextAlignnotext-align
positionProperty.Positionnoposition
topstring/numbernotop
rightstring/numbernoright
bottomstring/numbernobottom
leftstring/numbernoleft
zIndexProperty.ZIndexnoz-index
insetstring/numbernoinset
transformProperty.Transformnotransform
Source Code
interface BaseProps {
  // display
  display?: Property.Display;
  // 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;
  // flex
  flex?: Property.Flex;
  // flex/grid's gap
  gap?: number | string;
  // flex-direction
  column?: boolean;
  // flex-direction
  fd?: Property.FlexDirection;
  // align-items
  ai?: Property.AlignItems;
  // align-content
  ac?: Property.AlignContent;
  // justify-items
  ji?: Property.JustifyItems;
  // justify-content
  jc?: Property.JustifyContent;
  // flex-wrap
  wrap?: boolean | Property.FlexWrap;
  // white-space
  ws?: Property.WhiteSpace;
  // padding
  p?: number | string;
  // padding-top
  pt?: number | string;
  // padding-right
  pr?: number | string;
  // padding-bottom
  pb?: number | string;
  // padding-left
  pl?: number | string;
  // padding-inline
  px?: number | string;
  // padding-block
  py?: number | string;
  // margin
  m?: number | string;
  // margin-top
  mt?: number | string;
  // margin-right
  mr?: number | string;
  // margin-bottom
  mb?: number | string;
  // margin-left
  ml?: number | string;
  // margin-inline
  mx?: number | string;
  // margin-block
  my?: number | string;
  // border-radius
  radius?: string | number;
  // font-size
  fs?: string | number;
  // font-weight
  fw?: Property.FontWeight;
  // line-height
  lh?: string | number;
  // color
  color?: string;
  // background
  bg?: Property.Background;
  // scroll direction
  scroll?: boolean | 'x' | 'y';
  // text
  breakWord?: boolean;
  // border, border-width, border-color
  border?: string | number;
  // grid-template-columns
  gtc?: string | number;
  // grid-template-rows
  gtr?: string | number;
  // text-align
  ta?: Property.TextAlign;
  // position
  position?: Property.Position;
  // top
  top?: string | number;
  // right
  right?: string | number;
  // bottom
  bottom?: string | number;
  // left
  left?: string | number;
  // z-index
  zIndex?: Property.ZIndex;
  // inset
  inset?: string | number;
  // transform
  transform?: Property.Transform;
}

PropMappingHandler

PropMappings processing function, returns { key: string, value: string } | null

PropTypesRequiredDescription
valueany,yes-
propsTyes-
Source Code
type PropMappingHandler<T extends BaseProps> = (
  value: any,
  props: T
) => PropMappingHandlerReturn | PropMappingHandlerReturn[];

PropMappingHandlerReturn

Source Code
type PropMappingHandlerReturn = { key: string; value: string } | null;

PropMappings

PropMappingHandler

Source Code
type PropMappings<T extends BaseProps> = Partial<
  Record<keyof T, PropMappingHandler<T>>
>;

License

MIT License © 2024-Present Capricorncd.

Keywords

libs

FAQs

Package last updated on 11 May 2025

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