CSS Injection
DANGER
π¨ CSS Injection is a deprecated feature and will be removed in the next major release planned on Q1 of 2024.
WARNING
π¨ If you're using CSS Injection for theming purpose, consider review design tokens based theming.
If you need to change the style of a component in one specific case, then you should use local customization of styles.
Step one β
Install our component and our plugin @semcore/babel-plugin-styles to properly transpile the code.
npm i @semcore/ui @semcore/babel-plugin-stylesStep two β
Add a new rule to your webpack-config :
{
test: /\.js$/,
include: /\/node_modules\/@semcore\//,
enforce: 'pre',
use: [{
loader: 'babel-loader',
options: {
plugins: [
['@semcore/babel-plugin-styles']
],
},
}, ]
}Step three β
Write your own styles for our components using one of the following methods:
- CSS-in-JS
import { sstyled } from '@semcore/core';
const styles = sstyled.css`
SWhatever {
some-styles: 'Cool';
}
`;- good old CSS
import styles from './custom.shadow.css';WARNING
β οΈ The extension .shadow.css is required.
Step four β
Pass the new styles to the styles property of our component:
import Button from '@semcore/button';
export default (props) => <Button styles={styles} {...props} />;π―β Congratulations, you've changed the styles of the component!
Note β
Rules for writing styles
Look at the source of styles in GitHub, styles are written in the same format.
- By convention, all of our styled tags are capitalized
S + ComponentName. You donβt need to write styles with the.buttonclasses, just use the tag namesSButton. - If you need to access the properties of a component, then use
SButton[keybordFocus]or properties with the valueSButton[size="m"]. - If you need properties like
:hoverand others, then they're available as usualSButton:hover.
You can use variables as properties:
import { sstyled } from '@semcore/core';
import Button from '@semcore/button';
const styles = sstyled.css`
SButton {
background: var(--myCustomProp);
}
`;
const Demo = () => <Button styles={styles} myCustomProp="red" />;