-
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.
- Loading branch information
Showing
4 changed files
with
97 additions
and
2 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
94 changes: 94 additions & 0 deletions
94
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,94 @@ | ||
# 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`. | ||
|
||
After rendering, you will see CSS variables in the `:root` stylesheet of your HTML document. By default, these variables are prefixed with `--tonic`: | ||
|
||
```jsx | ||
import { | ||
TonicProvider, | ||
createTheme, | ||
} from '@tonic-ui/react'; | ||
|
||
const theme = createTheme({ cssVariables: true }); | ||
|
||
function App() { | ||
return ( | ||
<TonicProvider theme={theme}> | ||
{/* Your app content */} | ||
</TonicProvider> | ||
); | ||
} | ||
``` | ||
|
||
The resulting CSS variables will look like this: | ||
|
||
```css | ||
:root { | ||
--tonic-borders-1: .0625rem solid; | ||
--tonic-borders-2: .125rem solid; | ||
/* More 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 */ | ||
} | ||
``` | ||
|
||
## Using 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 */ | ||
} | ||
``` |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ting-started/css-variables/index.page.mdx → ...tarted/css-theme-variables/index.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# CSS Variables | ||
# CSS Theme Variables | ||
|
||
## Overview | ||
|
||
|