What is jss-plugin-global?
The jss-plugin-global npm package is a plugin for JSS (JavaScript Style Sheets) that allows you to define global CSS rules within your JSS styles. It enables you to write global selectors (like body, html, or any other global HTML element) inside a JSS object, which will then be applied to the whole document.
What are jss-plugin-global's main functionalities?
Defining global styles
This feature allows you to set global CSS properties for HTML elements. The code sample demonstrates how to set the font-size for the html element and reset the margin and padding for the body element.
{"@global": {"html": {"font-size": "16px"}, "body": {"margin": 0, "padding": 0}}}
Using global selectors
With this feature, you can define styles for global classes. The code sample shows how to change the text color to blue for elements with the class 'my-global-class'.
{"@global": {".my-global-class": {"color": "blue"}}}
Nesting global selectors
This feature allows for nesting within global selectors. The code sample demonstrates how to set a yellow background color for elements with the class 'my-class' that are children of the element with the id 'my-id'.
{"@global": {"#my-id": {"& .my-class": {"background-color": "yellow"}}}}
Other packages similar to jss-plugin-global
styled-components
Styled-components is a library for styling React components using tagged template literals. It allows for defining styles in a component-scoped manner, but also supports global styles via the 'createGlobalStyle' helper. Compared to jss-plugin-global, styled-components offers a more component-centric approach to styling with a different syntax.
emotion
Emotion is a performant and flexible CSS-in-JS library that allows you to style applications quickly with string or object styles. It has a similar feature to 'createGlobalStyle' in styled-components called 'Global', which can be used to define global styles. Emotion and jss-plugin-global both allow for global styling, but Emotion provides a more extensive set of features for composing and theming styles.
aphrodite
Aphrodite is another CSS-in-JS library that allows you to write styles in JavaScript and attach them to your components. It does not have a dedicated global styles feature like jss-plugin-global, but you can achieve global styles by defining a style object and then inserting it into the DOM using standard JavaScript. Aphrodite focuses more on inline styles and does not support JSS's plugin system.
jss-plugin-global
Global styles for JSS
See our website jss-plugin-global for more information.
Install
Using npm:
npm install jss-plugin-global
or using yarn:
yarn add jss-plugin-global