flexible-styled-components-modifiers

0.0.3 • Public • Published

Modifiers for styled components

Example

import applyStyleModifiers from 'flexible-styled-components-modifiers';
import styled from 'styled-components';
 
/* 
    globalModifiers - modifiers that will be applied for all components,
    which uses applyStyleModifiersWithGlobal
 */
 
const globalModifiers = {
  m: {
      prop: 'margin',
      values: {
          '': 'margin',
          t: 'margin-top',
          b: 'margin-bottom',
          r: 'margin-right',
          l: 'margin-left'
      }
  },
  p: 'padding: ',
  flex: 'flex: ',
  w: 'width: ',
  h: 'height: ',
  color: (props, value) => `background-color: ${props.theme[value] || value};`,
  fontColor: (props, value) => `color: ${props.theme[value] || value};`
}
 
const applyStyleModifiersWithGlobal = applyStyleModifiers(globalModifiers)
 
/*
    Pay attention to the package flexible-styled-flex
*/
 
const flexModifiers = {
    jc: {
        prop: 'justify-content',
        values: {
            c: 'center',
            sb: 'space-between',
            sa: 'space-around',
            fe: 'flex-end',
            fs: 'flex-start',
        },
    },
    ai: {
        prop: 'align-items',
        values: {
            s: 'stretch',
            c: 'center',
            b: 'baseline',
            fs: 'flex-start',
            fe: 'flex-end',
        },
    },
    fd: {
        prop: 'flex-direction',
        values: {
            c: 'column',
            r: 'row',
            rr: 'row-reverse',
            cr: 'column-reverse',
        },
    },
    fww: 'flex-wrap: wrap;'
}
 
const applyFlexModifiers = applyStyleModifiersWithGlobal(flexModifiers);
 
const Flex = styled.div`
    display: flex;
    ${applyFlexModifiers}
`
 
const MyComponent = <Flex jcc aic w="100px">;
 
/*
    MyComponent = styled.div`
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100px;
    `
 */

Readme

Keywords

none

Package Sidebar

Install

npm i flexible-styled-components-modifiers

Weekly Downloads

0

Version

0.0.3

License

ISC

Unpacked Size

3.25 kB

Total Files

3

Last publish

Collaborators

  • kaprisa57