diff --git a/packages/react-docs/pages/getting-started/usage/index.page.mdx b/packages/react-docs/pages/getting-started/usage/index.page.mdx index 3762570495..118dce13b8 100644 --- a/packages/react-docs/pages/getting-started/usage/index.page.mdx +++ b/packages/react-docs/pages/getting-started/usage/index.page.mdx @@ -17,10 +17,30 @@ import { theme, // [optional] Required only for customizing the theme } from '@tonic-ui/react'; -// Enable CSS variables -theme.config.useCSSVariables = true; - function App(props) { + const customTheme = { + ...theme, + // Set default props for specific components + // + // Example: + // ```js + // components: { + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', + // }, + // }, + // } + // ``` + components: {}, + // Enable CSS variables + config: { + ...theme?.config, + useCSSVariables: true, + }, + }; + }; + return ( @@ -54,10 +74,30 @@ import { useTheme, } from '@tonic-ui/react'; -// Enable CSS variables -theme.config.useCSSVariables = true; - function App(props) { + const customTheme = { + ...theme, + // Set default props for specific components + // + // Example: + // ```js + // components: { + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', + // }, + // }, + // } + // ``` + components: {}, + // Enable CSS variables + config: { + ...theme?.config, + useCSSVariables: true, + }, + }; + }; + return ( + ``` For example, consider a theme object that looks like this: -```js disabled -const theme = { +```js +{ colors: { 'gray:10': '#fafafa', 'gray:20': '#f7f7f7', }, -}; +} ``` When this theme is passed to `TonicProvider`, Tonic UI will generate CSS variables automatically, as shown below: @@ -270,7 +312,7 @@ const customColorStyle = { colorStyle={{ defaultValue: customColorStyle, }} - theme={theme} + theme={customTheme} useCSSBaseline={true} > {children} @@ -296,14 +338,15 @@ Override the theme object and pass it to the `` component. ```js import { theme } from '@tonic-ui/react'; -// Enable CSS variables -theme.config.useCSSVariables = true; - // Let's say you want to add more colors const customTheme = { ...theme, + config: { + ...theme?.config, + useCSSVariables: true, + }, colors: { - ...theme.colors, + ...theme?.colors, brand: { 90: "#1a365d", 80: "#153e75", @@ -315,7 +358,7 @@ const customTheme = { #### 2. Setting up the provider -```jsx disabled +```jsx {children} diff --git a/packages/react-docs/sandbox/create-react-app.js b/packages/react-docs/sandbox/create-react-app.js index 53e04add0c..d139ac7a84 100644 --- a/packages/react-docs/sandbox/create-react-app.js +++ b/packages/react-docs/sandbox/create-react-app.js @@ -77,29 +77,50 @@ const customColorStyle = { }, }; -// Enable CSS variables -theme.config.useCSSVariables = true; - -const Root = (props) => ( - - - - - - - - - -); +const Root = (props) => { + const customTheme = { + ...theme, + // Set default props for specific components + // + // Example: + // \`\`\`js + // components: { + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', + // }, + // }, + // } + // \`\`\` + components: {}, + // Enable CSS variables + config: { + ...theme?.config, + useCSSVariables: true, + }, + }; + + return ( + + + + + + + + + + ); +}; const Layout = (props) => { const [colorMode] = useColorMode();