Gathering detailed insights and metrics for react-suitcssify
Gathering detailed insights and metrics for react-suitcssify
Gathering detailed insights and metrics for react-suitcssify
Gathering detailed insights and metrics for react-suitcssify
npm install react-suitcssify
Typescript
Module System
Node Version
NPM Version
75.5
Supply Chain
99.1
Quality
81.2
Maintenance
100
Vulnerability
100
License
Total Downloads
459,288
Last Day
29
Last Week
133
Last Month
521
Last Year
7,205
Minified
Minified + Gzipped
Latest Version
3.3.0
Package Id
react-suitcssify@3.3.0
Size
51.53 kB
NPM Version
3.8.3
Node Version
5.10.1
Cumulative downloads
Total Downloads
Last day
70.6%
29
Compared to previous day
Last week
-7%
133
Compared to previous week
Last month
8.3%
521
Compared to previous month
Last year
-83.1%
7,205
Compared to previous year
1
21
A React component utility to generate CSS class names that conform to SUIT CSS naming conventions.
This utility can be used as a higher-order component, decorator, mixin, or utility function. This means that you can use it with React components defined using createClass, ES2015 classes, or stateless-functional components.
Provides a general purpose getClassName(options)
method that accepts a variety of options for generating SUIT CSS conformant class names.
1getClassName({
2 baseComponentName: string,
3 className: string,
4 componentName: string,
5 descendantName: string,
6 modifiers: string,
7 namespace: string,
8 states: string,
9 utilities: string
10})
When using the decorator or mixin approach, the following defaults are provided.
Component.props.className
Note that Component.propTypes.className
is also added for convenience.Component.displayName || Component.name
Component.namespace
Component.props.utilities
Note that Component.propTypes.utilities
is also added for convenience.When using the higher-order approach, the following defaults are provided.
Component.props.className
Component.displayName || Component.name
Component.props.utilities
npm install react-suitcssify
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import SuitCssify from 'react-suitcssify'; 4 5@SuitCssify.decorator 6class MyComponent extends React.Component { 7 render() { 8 return <div className={ this.getClassName() }></div> 9 } 10} 11 12ReactDOM.render(<MyComponent/>, document.body);
This decorator approach does not work with stateless functional React components. This approach will pass in the getClassName
function as a prop to your component.
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import SuitCssify from 'react-suitcssify'; 4 5const MyComponent = ({ getClassName }) => <div className={ getClassName() }></div>; 6 7const WrappedComponent = SuitCssify.higherOrder('optional_namespace')(MyComponent); 8 9ReactDOM.render(<WrappedComponent/>, document.body);
Here's an example with an ES2015 class React component.
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import SuitCssify from 'react-suitcssify'; 4 5class MyComponent extends React.Component { 6 static propTypes = { 7 getClassName: React.PropTypes.func.isRequired 8 }; 9 10 render() { 11 return <div className={ this.props.getClassName() }></div> 12 } 13} 14 15const WrappedComponent = SuitCssify.higherOrder('optional_namespace')(MyComponent); 16 17ReactDOM.render(<WrappedComponent/>, document.body);
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import SuitCssify from 'react-suitcssify'; 4 5const MyComponent = React.createClass({ 6 mixins: [SuitCssify.mixin], 7 8 render: function() { 9 return <div className={ this.getClassName() }></div> 10 } 11}); 12 13ReactDOM.render(<MyComponent/>, document.body);
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import SuitCssify from 'react-suitcssify'; 4 5const getClassName = SuitCssify.getClassName; 6 7class MyComponent extends React.Component { 8 render() { 9 return <div className={ getClassName({ componentName: 'MyComponent', namespace: 'my' }) }></div> 10 } 11} 12 13ReactDOM.render(<MyComponent/>, document.body);
A more performant implementation of a component using the getClassName
function directly is to instead call getBaseComponentName which pre-calculates the baseComponentName one time given the componentName and namespace instead of calculating it on every call. While being slightly more verbose than the other options, it will provide better performance than all the other approaches. Here's what that looks like:
const displayName = 'MyComponent';
const namespace = 'my';
const baseComponentName = SuitCssify.getBaseComponentName(displayName, namespace);
const getClassName = SuitCssify.getClassName;
class MyComponent extends React.Component {
render() {
return <div className={ getClassName({ baseComponentName }) }></div>
}
}
ReactDOM.render(<MyComponent/>, document.body);
Each of the above render as:
1<div class="MyComponent"></div>
1<Component />
1getClassName() -----> 'Component' 2 3getClassName({ componentName: 'AwesomeComponent' }) -----> 'AwesomeComponent' 4 5getClassName({ namespace: 'my' }) -----> 'my-Component' 6 7getClassName({ modifiers: 'foo bar' }) -----> 'Component Component--foo Component--bar' 8 9getClassName({ states: 'active' }) -----> 'Component is-active' 10 11getClassName({ utilities: 'floatRight' }) -----> 'Component u-floatRight' 12 13getClassName({ className: 'arbitrary' }) -----> 'Component arbitrary' 14 15getClassName({ descendantName: 'title' }) -----> 'Component Component-title' 16 17getClassName({ 18 className: 'arbitrary', 19 componentName: 'AwesomeComponent', 20 modifiers: 'foo bar', 21 namespace: 'my', 22 states: 'active', 23 utilities: 'floatRight' 24}) -----> 'my-AwesomeComponent my-AwesomeComponent--foo my-AwesomeComponent--bar is-active u-floatRight arbitrary' 25 26getClassName({ 27 componentName: 'AwesomeComponent', 28 namespace: 'my', 29 modifiers: 'foo bar', 30 states: 'active', 31 utilities: 'floatRight', 32 className: 'arbitrary', 33 descendantName: 'child' 34}) -----> 'my-AwesomeComponent-child my-AwesomeComponent-child--foo my-AwesomeComponent-child--bar is-active u-floatRight arbitrary' 35 36const baseComponentName = getBaseComponentName('Component', 'my'); 37getClassName({ 38 baseComponentName 39}) -----> 'my-Component'
For more examples, browse the demo files or just run the demo.
npm run demo
npm run build
npm test
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
utility
as getClassName
-- utility will be removed in a future release as it would be a breaking change.No vulnerabilities found.
No security vulnerabilities found.