0.2.3 • Published 6 years ago

react-props-classnames v0.2.3

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

React Props Classnames

Travis Codecov npm

Easily transform component's props to classnames

  • Good usage with styled-components when you want to control styles by props.
  • Transform your boolean and string props to className.
  • Customized classNames prefix.

Install

yarn add react-props-classnames

Examples

Edit 5zzjpn94zn

Usage

import styled from 'styled-components';
import createPropsTransform from 'react-props-classnames';

const propsTransform = createPropsTransform({
  prefix: 'my-button',
  props: ['circle', 'size'],
});

const Button = styled.button`
  /* ... */

  &.my-button-circle {
    /* ... */
  }

  &.my-button-size-lg {
    /* ... */
  }
`;

export default propsTransform(Button);
<Button circle size="lg" type="button" disalbed>Button</Button>

// will trasnform to

<button class="{...styled} my-button-circle my-button-size-lg">Button</button>

API

createPropsTransform(options)

options (Object)

keyTypeDefaultDescription
prefixString'default-prefix'The prefix of every classNames.
propsArray[]The props which will be transformed. If this option is empty, propsTransform will transform any props
boolBooleantrueTransform boolean props to classNames or not.
stringBooleantrueTransform string props to classNames or not.

Returns

A higher-order component that transform props then pass into your components.

License

MIT © jigsawye

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago