-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add "CSS Theme Variables" page
- Loading branch information
Showing
4 changed files
with
104 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/react-docs/pages/customization/css-theme-variables.page.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# CSS Theme Variables | ||
|
||
Learn how to adopt CSS theme variables. | ||
|
||
## Getting Started | ||
|
||
To use CSS theme variables, create a theme with `cssVariables: true` and wrap your app with `TonicProvider`: | ||
|
||
```jsx | ||
import { | ||
TonicProvider, | ||
createTheme, | ||
} from '@tonic-ui/react'; | ||
|
||
// `createTheme` was introduced in v2.5.0 | ||
const theme = createTheme({ cssVariables: true }); | ||
|
||
function App() { | ||
return ( | ||
<TonicProvider theme={theme}> | ||
{/* Your app content */} | ||
</TonicProvider> | ||
); | ||
} | ||
``` | ||
|
||
After rendering, you will see all CSS theme variables in the `:root` stylesheet of the HTML document. By default, these variables are prefixed with `--tonic`. You can open the **Developer Tools** and go to the **Elements** tab to see all the CSS theme variables being used on the webpage. | ||
|
||
{render('./css-theme-variables')} | ||
|
||
## Customizing Variable Prefix | ||
|
||
You can customize the variable prefix by providing a string to the `prefix` property in the theme configuration. | ||
|
||
```js | ||
createTheme({ | ||
cssVariables: { | ||
prefix: 'custom', | ||
}, | ||
}); | ||
``` | ||
|
||
```css | ||
:root { | ||
--custom-borders-1: .0625rem solid; | ||
--custom-borders-2: .125rem solid; | ||
/* More variables */ | ||
} | ||
``` | ||
|
||
If you prefer not to use any prefix, set `prefix` to an empty string: | ||
|
||
```js | ||
createTheme({ | ||
cssVariables: { | ||
prefix: '', | ||
}, | ||
}); | ||
``` | ||
|
||
```css | ||
:root { | ||
--borders-1: .0625rem solid; | ||
--borders-2: .125rem solid; | ||
/* More variables */ | ||
} | ||
``` | ||
|
||
## Variables Inside Shadow DOM | ||
|
||
To apply CSS theme variables inside shadow DOM, specify a different root selector using the `rootSelector` option: | ||
|
||
```js | ||
createTheme({ | ||
cssVariables: { | ||
rootSelector: ':host', | ||
}, | ||
}); | ||
``` | ||
|
||
```css | ||
:host { | ||
--tonic-borders-1: .0625rem solid; | ||
--tonic-borders-2: .125rem solid; | ||
/* More variables */ | ||
} | ||
``` |
42 changes: 0 additions & 42 deletions
42
packages/react-docs/pages/getting-started/css-variables/index.page.mdx
This file was deleted.
Oops, something went wrong.