
Security News
Potemkin Understanding in LLMs: New Study Reveals Flaws in AI Benchmarks
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
react-suitcssify
Advanced tools
A React component utility to generate CSS class names that conform to SUIT CSS naming conventions.
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.
getClassName({
baseComponentName: string,
className: string,
componentName: string,
descendantName: string,
modifiers: string,
namespace: string,
states: string,
utilities: string
})
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
import React from 'react';
import ReactDOM from 'react-dom';
import SuitCssify from 'react-suitcssify';
@SuitCssify.decorator
class MyComponent extends React.Component {
render() {
return <div className={ this.getClassName() }></div>
}
}
ReactDOM.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.
import React from 'react';
import ReactDOM from 'react-dom';
import SuitCssify from 'react-suitcssify';
const MyComponent = ({ getClassName }) => <div className={ getClassName() }></div>;
const WrappedComponent = SuitCssify.higherOrder('optional_namespace')(MyComponent);
ReactDOM.render(<WrappedComponent/>, document.body);
Here's an example with an ES2015 class React component.
import React from 'react';
import ReactDOM from 'react-dom';
import SuitCssify from 'react-suitcssify';
class MyComponent extends React.Component {
static propTypes = {
getClassName: React.PropTypes.func.isRequired
};
render() {
return <div className={ this.props.getClassName() }></div>
}
}
const WrappedComponent = SuitCssify.higherOrder('optional_namespace')(MyComponent);
ReactDOM.render(<WrappedComponent/>, document.body);
import React from 'react';
import ReactDOM from 'react-dom';
import SuitCssify from 'react-suitcssify';
const MyComponent = React.createClass({
mixins: [SuitCssify.mixin],
render: function() {
return <div className={ this.getClassName() }></div>
}
});
ReactDOM.render(<MyComponent/>, document.body);
import React from 'react';
import ReactDOM from 'react-dom';
import SuitCssify from 'react-suitcssify';
const getClassName = SuitCssify.getClassName;
class MyComponent extends React.Component {
render() {
return <div className={ getClassName({ componentName: 'MyComponent', namespace: 'my' }) }></div>
}
}
ReactDOM.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:
<div class="MyComponent"></div>
<Component />
getClassName() -----> 'Component'
getClassName({ componentName: 'AwesomeComponent' }) -----> 'AwesomeComponent'
getClassName({ namespace: 'my' }) -----> 'my-Component'
getClassName({ modifiers: 'foo bar' }) -----> 'Component Component--foo Component--bar'
getClassName({ states: 'active' }) -----> 'Component is-active'
getClassName({ utilities: 'floatRight' }) -----> 'Component u-floatRight'
getClassName({ className: 'arbitrary' }) -----> 'Component arbitrary'
getClassName({ descendantName: 'title' }) -----> 'Component Component-title'
getClassName({
className: 'arbitrary',
componentName: 'AwesomeComponent',
modifiers: 'foo bar',
namespace: 'my',
states: 'active',
utilities: 'floatRight'
}) -----> 'my-AwesomeComponent my-AwesomeComponent--foo my-AwesomeComponent--bar is-active u-floatRight arbitrary'
getClassName({
componentName: 'AwesomeComponent',
namespace: 'my',
modifiers: 'foo bar',
states: 'active',
utilities: 'floatRight',
className: 'arbitrary',
descendantName: 'child'
}) -----> 'my-AwesomeComponent-child my-AwesomeComponent-child--foo my-AwesomeComponent-child--bar is-active u-floatRight arbitrary'
const baseComponentName = getBaseComponentName('Component', 'my');
getClassName({
baseComponentName
}) -----> '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.FAQs
A React component utility to generate CSS class names that conform to SUIT CSS naming conventions.
The npm package react-suitcssify receives a total of 189 weekly downloads. As such, react-suitcssify popularity was classified as not popular.
We found that react-suitcssify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.