css-hooks-basic
v0.1.1
Published
A simplified CSS Hooks API for basic use cases
Maintainers
Readme
css-hooks-basic
This is a utility library for simplifying the usage of CSS Hooks, providing a basic API for styling components without advanced conditions.
Installation
npm install css-hooks-basicUsage
Option 1: Global css function
If you prefer to avoid using advanced conditions (the on field) entirely, you
can convert your global css function to use the basic API provided by this
library:
- Import the
basicfunction in your CSS module. - Apply it to the
cssfunction produced bycreateHooks. - Export the resulting function as
css.
// src/css.ts
import { createHooks } from "@css-hooks/react";
import { basic } from "css-hooks-basic";
const { styleSheet, css: cssAdvanced } = createHooks({
// ...configuration...
});
export { styleSheet };
export const css = basic(cssAdvanced);Now, you can use the basic version of the css function throughout your
project, providing an easier way to define styles.
Option 2: Case by case
Alternatively, you can use the basic API on a case-by-case basis. This allows you to mix basic and advanced styling conditions according to your needs.
In a component module, simply import css from your CSS module and the basic
function from css-hooks-basic; and then use them together to style your
component:
// src/easy-button.tsx
import { css } from "./css";
import { basic } from "css-hooks-basic";
export const EasyButton = () => (
<button
style={basic(css)({
color: "black",
"&:enabled": {
"&:hover": {
color: "blue",
},
"&:active": {
color: "red",
},
},
"&:disabled": {
color: "gray",
},
})}
>
Easy
</button>
);With this approach, you have the flexibility to choose between basic and advanced styling conditions for different components as needed.
Contributing
Contributions to css-hooks-basic are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
License
css-hooks-basic is licensed under the MIT License. See the LICENSE file for details.
