1.0.15 ā€¢ Published 7 years ago

create-classname v1.0.15

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

createClassName

šŸŽˆ - Create className based on an object's conditions.

NPM version

Npm Downloads

Installation

Install the dependencies.

$ npm i --save create-classname
ou
$ yarn add create-classname

Definition

    createClassName(defaultClassName, data | props, mapping);
  • defaultClassName: string
  • data | props: object
  • mapping: array
    • verifier: string | function
    • className: string | function

Example

//App.jsx
	ReactDOM.render(
		<MyButton 
			active
			color='blue'
			icon={<Icon name="facebook"/>}
			outline
			raised={false}
		>
			Click Me!
		</MyButton>,
		document.getElementById('root')
	);
//MyButton.jsx
import { createClassName } from 'create-classname';

export default class MyButton extends Component {
	constructor(props) {
		super();
		
		const mapping = [
			{ verifier: 'active', className: 'active' },
			{ verifier: 'color' , className: (p) => `color-${p.color}` },
			{ verifier: (p) =>  p.icon && p.outline, className: 'button-icon-outline' },
			{ verifier: (p) => p.raised, className: 'button-raised' },
			{ verifier: 'round', className: 'button-round' }
		];
		
		const className = createClassName('button', props, mapping);
		//className => "button active color-blue button-icon-outline"

		this.state = { className: className };
	}
	
	render() {
		return (<button className={this.state.className}></button>)
	}
}

License

ISC

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago