0.0.9 • Published 1 year ago

@chengsokdara/styled-props v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Styled Props for React Native

Styling React Native component like it is TailwindCSS.


Installation

npm install @chengsokdara/styled-props --save
yarn add @chengsokdara/styled-props

Getting Start

What styled-props can do?

1. inject styler into custom view

import {
  injectStyles,
  // import styles you want to inject
  backgroundStyle,
  flexStyle,
} from '@chengsokdara/styled-props'

// Create custom view by injecting styles
const CustomView = (props) => {
  const styles = injectStyles([backgroundStyle, flexStyle], props)

  return <View style={[props.style, styles]} />
}

2. use custom view with custom props

import { CustomView } from 'your-custom-view-path'

// Usage examples
const App = () => {
  const [bg, setBg] = useState('red')
  return (
    {/* When style value a static */}
    <CustomView bg-00DDFF flex-1>
      {/* When style value are dynamic*/}
      <CustomView bg={bg} />
    </CustonView>
  )
}

API

  • alignContent
    prop namestyle namevalue typeexample
    contentalignContentstringcontent={'between'}
    content-valuealignContentstringcontent-between

content-value: start | end | center | between | around | evenly

  • alignItems
    prop namestyle namevalue typeexample
    itemsalignItemsstringitems={'center'}
    items-valuealignItemsstringitems-center

items-value: start | end | center | baseline | stretch

  • alignSelf
    prop namestyle namevalue typeexample
    selfalignSelfstringself={'stretch'}
    self-valuealignSelfstringself-stretch

self-value: start | end | center | baseline | stretch

  • backgroundStyle
    prop namestyle namevalue typeexample
    bgbackgroundColorstringbg={'red'}
    bg-hexbackgroundColorstringbg-FF0000

bg-hex: bg-FF0000 will be converted to backgroundColor: "#FF0000"

  • borderStyle
    prop namestyle namevalue typeexample
    bcborderColorstringbc={'red'}
    bc-hexborderColorstringbc-FF0000
    bcbborderColorBottomstringbcb={'red'}
    bcb-hexborderColorBottomstringbcb-FF0000
    bclborderColorLeftstringbcl={'red'}
    bcl-hexborderColorLeftstringbcl-FF0000
    bcrborderColorRightstringbcr={'red'}
    bcr-hexborderColorRightstringbcr-FF0000
    bctborderColorTopstringbct={'red'}
    bct-hexborderColorTopstringbct-FF0000
    brborderRadiusnumberbr={4}
    br-valueborderRadiusnumberbr-4
    brbborderRadiusBottomnumberbrb={4}
    brb-valueborderRadiusBottomnumberbrb-4
    brblborderRadiusBottomLeftnumberbrbl={4}
    brbl-valueborderRadiusBottomLeftnumberbrbl-4
    brbrborderRadiusBottomRightnumberbrbr={4}
    brbr-valueborderRadiusBottomRightnumberbrbr-4
    brlborderRadiusLeftnumberbrl={4}
    brl-valueborderRadiusLeftnumberbrl-4
    brrborderRadiusRightnumberbrr={4}
    brr-valueborderRadiusRightnumberbrr-4
    brtborderRadiusTopnumberbrt={4}
    brt-valueborderRadiusTopnumberbrt-4
    brtlborderRadiusTopLeftnumberbrtl={4}
    brtl-valueborderRadiusTopLeftnumberbrtl-4
    brtrborderRadiusTopRightnumberbrtr={4}
    brtr-valueborderRadiusTopRightnumberbrtr-4
    bsborderStylestringbs={'solid'}
    bs-valueborderStylestringbs-solid
    bwborderWidthnumberbw={1}
    bw-valueborderWidthnumberbw-1
    bwbborderWidthBottomnumberbwb={1}
    bwb-valueborderWidthBottomnumberbwb-1
    bwlborderWidthLeftnumberbwl={1}
    bwl-valueborderWidthLeftnumberbwl-1
    bwrborderWidthRightnumberbwr={1}
    bwr-valueborderWidthRightnumberbwr-1
    bwtborderWidthTopnumberbwt={1}
    bwt-valueborderWidthTopnumberbwt-1

bs-value: solid | dotted | dashed

  • colorStyle
    prop namestyle namevalue typeexample
    colorcolorstringcolor={'blue'}
    color-valuecolorstringcolor-0000FF

color-hex: color-0000FF will be converted to color: "#0000FF"

  • flexAlignment
    prop namestyle namevalue typeexample
    centeralignItemsjustifyContentbooleancenter
    center-valuealignItemsjustifyContentbooleancenter
    itemsalignItemsstringitems={'center'}
    items-valuealignItemsstringitems-center
    justifyjustifyContentstringself={'stretch'}
    justify-valuejustifyContentstringself-stretch

items-value: start | end | center | baseline | stretch

justify-value: start | end | center | between | around | evenly

  • flexDirection
    prop namestyle namevalue typeexample
    colflexDirectionbooleancol
    rowflexDirectionbooleanrow
  • flexGrow
    prop namestyle namevalue typeexample
    growflexGrowbooleangrow
    grow-0flexGrowbooleangrow-o
    grow-valueflexGrownumbergrow-1
  • flexStyles
    prop namestyle namevalue typeexample
    basisflexBasisnumber,stringbasis={168}
    basis-valueflexBasisstringbasis-168
    flexflexnumberflex={1}
    flex-valueflexnumberflex-1
    flex-nowrapflexWrapbooleanflex-nowrap
    flex-reverseflexWrapbooleanflex-reverse
    flex-wrapflexWrapbooleanflex-wrap
    growflexGrowbooleangrow
    grow-0flexGrowbooleangrow-o
    grow-valueflexGrownumbergrow-1
    shrinkflexShrinkbooleanshrink
    shrink-0flexShrinkbooleanshrink-o
    shrink-valueflexShrinknumbershrink-1

basis-value: basis-100pct will be converted to flexBasis: "100%"

flex-nowrap will be converted to flexWrap: 'nowrap'

flex-reverse will be converted to flexWrap: 'reverse'

flex-wrap will be converted to flexWrap: 'wrap'

  • flexboxStyles

    prop namestyle namevalue typeexample
    basisflexBasisnumber,stringbasis={168}
    basis-valueflexBasisstringbasis-168
    centeralignItemsjustifyContentbooleancenter
    center-valuealignItemsjustifyContentbooleancenter
    colflexDirectionbooleancol
    contentalignContentstringcontent={'between'}
    content-valuealignContentstringcontent-between
    flexflexnumberflex={1}
    flex-valueflexnumberflex-1
    flex-nowrapflexWrapbooleanflex-nowrap
    flex-reverseflexWrapbooleanflex-reverse
    flex-wrapflexWrapbooleanflex-wrap
    growflexGrowbooleangrow
    grow-0flexGrowbooleangrow-o
    grow-valueflexGrownumbergrow-1
    itemsalignItemsstringitems={'center'}
    items-valuealignItemsstringitems-center
    justifyjustifyContentstringself={'stretch'}
    justify-valuejustifyContentstringself-stretch
    rowflexDirectionbooleanrow
    selfalignSelfstringself={'stretch'}
    self-valuealignSelfstringself-stretch
    shrinkflexShrinkbooleanshrink
    shrink-0flexShrinkbooleanshrink-o
    shrink-valueflexShrinknumbershrink-1

basis-value: basis-100pct will be converted to flexBasis: "100%"

content-value: start | end | center | between | around | evenly

flex-nowrap will be converted to flexWrap: 'nowrap'

items-value: start | end | center | baseline | stretch

justify-value: start | end | center | between | around | evenly

self-value: start | end | center | baseline | stretch

  • fontStyles

    prop namestyle namevalue typeexample
    boldfontWeightbooleanbold
    fontfontFamilystringfont={"Roboto"}
    italicfontStylebooleanitalic
    sizefontSizenumbersize={12}
    *size-valuefontSizsenumbersize-12
    weight-boldfontWeightbooleanweight-bold
    weight-lightfontWeightbooleanweight-light
    weight-mediumfontWeightbooleanweight-medium
    weight-regularfontWeightbooleanweight-regular
  • fontSizeStyles

    prop namestyle namevalue typeexample
    sizefontSizenumbersize={12}
    *size-valuefontSizsenumbersize-12
  • fontStyleStyles

    prop namestyle namevalue typeexample
    italicfontStylebooleanitalic
  • fontWeightStyles

    prop namestyle namevalue typeexample
    boldfontWeightbooleanbold
    weight-boldfontWeightbooleanweight-bold
    weight-lightfontWeightbooleanweight-light
    weight-mediumfontWeightbooleanweight-medium
    weight-regularfontWeightbooleanweight-regular
  • justifyContent

    prop namestyle namevalue typeexample
    justifyjustifyContentstringself={'stretch'}
    justify-valuejustifyContentstringself-stretch

justify-value: start | end | center | between | around | evenly

  • marginStyles

    prop namestyle namevalue typeexample
    mmarginnumberm={10}
    m-valuemarginnumberm-10
    mbmarginBottomnumbermb={10}
    mb-valuemarginBottomnumbermb-10
    mlmarginLeftnumberml={10}
    ml-valuemarginLeftnumberml-10
    mrmarginRightnumbermr={10}
    mr-valuemarginRightnumbermr-10
    mtmarginTopnumbermt={10}
    mt-valuemarginTopnumbermt-10
    mxmarginHorizontalnumbermx={10}
    mx-valuemarginHorizontalnumbermx-10
    mymarginVerticalnumbermy={10}
    my-valuemarginVerticalnumbermy-10
  • overflowSstyles

    prop namestyle namevalue typeexample
    ovfoverflowstringovf={"scroll"}
    ovf-valueoverflowstringovf-scroll

ovf-value: hidden | scroll | visible

  • paddingStyles

    prop namestyle namevalue typeexample
    ppaddingnumberp={10}
    p-valuepaddingnumberp-10
    pbpaddingBottomnumberpb={10}
    pb-valuepaddingBottomnumberpb-10
    plpaddingLeftnumberpl={10}
    pl-valuepaddingLeftnumberpl-10
    prpaddingRightnumberpr={10}
    pr-valuepaddingRightnumberpr-10
    ptpaddingTopnumberpt={10}
    pt-valuepaddingTopnumberpt-10
    pxpaddingHorizontalnumberpx={10}
    px-valuepaddingHorizontalnumberpx-10
    pypaddingVerticalnumberpy={10}
    py-valuepaddingVerticalnumberpy-10
  • positionStyles

    prop namestyle namevalue typeexample
    absolutepositionbooleanabsolute
    absolutepositionbottomleftrighttopnumberabsolute={0}
    absolute-0positionbottomleftrighttopbooleanabsolute-0
    bottom-valuebottomnumberbottom-10
    left-valueleftnumberleft-10
    relativepositionbooleanrelative
    *right-valuerightnumberright-10
    *top-valuetopnumbertop-10
    *z-valuezIndexnumberz-1
  • resizeModeStyles

    prop namestyle namevalue typeexample
    resize-coverresizeModebooleanresize-cover
    resize-containresizeModebooleanresize-contain
    resize-stretchresizeModebooleanresize-stretch
    resize-repeatresizeModebooleanresize-repeat
    resize-centerresizeModebooleanresize-center
  • sizingStyles

    prop namestyle namevalue typeexample
    hheightnumberh={10}
    hheightstringh={"100%"}
    *h-valueheightnumberh-10
    h-valueheightstringh-100pct
    maxhmaxHeightnumbermaxh={10}
    maxhmaxHeightstringmaxh={"100%"}
    maxh-valuemaxHeightnumbermaxh-10
    maxh-valuemaxHeightstringmaxh-100pct
    maxwmaxWidthnumbermaxw={10}
    maxwmaxWidthstringmaxw={"100%"}
    maxw-valuemaxWidthnumbermaxw-10
    maxw-valuemaxWidthstringmaxw-100pct
    minhminHeightnumberminh={10}
    minhminHeightstringminh={"100%"}
    minh-valueminHeightnumberminh-10
    minh-valueminHeightstringminh-100pct
    minwminWidthnumberminw={10}
    minwminWidthstringminw={"100%"}
    minw-valueminWidthnumberminw-10
    minw-valueminWidthstringminw-100pct
    wwidthnumberw={10}
    wwidthstringw={"100%"}
    *w-valuewidthnumberw-10
    w-valuewidthstringw-100pct
  • spacingStyles

    prop namestyle namevalue typeexample
    mmarginnumberm={10}
    m-valuemarginnumberm-10
    mbmarginBottomnumbermb={10}
    mb-valuemarginBottomnumbermb-10
    mlmarginLeftnumberml={10}
    ml-valuemarginLeftnumberml-10
    mrmarginRightnumbermr={10}
    mr-valuemarginRightnumbermr-10
    mtmarginTopnumbermt={10}
    mt-valuemarginTopnumbermt-10
    mxmarginHorizontalnumbermx={10}
    mx-valuemarginHorizontalnumbermx-10
    mymarginVerticalnumbermy={10}
    my-valuemarginVerticalnumbermy-10
    ppaddingnumberp={10}
    p-valuepaddingnumberp-10
    pbpaddingBottomnumberpb={10}
    pb-valuepaddingBottomnumberpb-10
    plpaddingLeftnumberpl={10}
    pl-valuepaddingLeftnumberpl-10
    prpaddingRightnumberpr={10}
    pr-valuepaddingRightnumberpr-10
    ptpaddingTopnumberpt={10}
    pt-valuepaddingTopnumberpt-10
    pxpaddingHorizontalnumberpx={10}
    px-valuepaddingHorizontalnumberpx-10
    pypaddingVerticalnumberpy={10}
    py-valuepaddingVerticalnumberpy-10
  • textAlignStyles

    prop namestyle namevalue typeexample
    aligntextAlignstringalign={"center"}
    align-valuetextAlignstringalign-center

align-value: auto | center | left | right | justify

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago