From d940ede72f37f6e5c883e9f07bc8dff0880caeb4 Mon Sep 17 00:00:00 2001 From: cheton Date: Sat, 23 Nov 2024 20:13:14 +0800 Subject: [PATCH 01/18] feat(react): add `createTheme` for theme customization --- packages/react-docs/pages/_app.page.js | 41 +++++------ .../getting-started/usage/index.page.mdx | 73 +++++++++---------- .../pages/theme/breakpoints/index.page.mdx | 7 +- .../react-docs/sandbox/create-react-app.js | 45 +++++------- packages/react/__tests__/index.test.js | 1 + packages/react/src/provider/TonicProvider.js | 7 +- packages/react/src/theme/ThemeProvider.js | 69 +----------------- packages/react/src/theme/createTheme.js | 57 +++++++++++++++ packages/react/src/theme/index.js | 4 +- packages/react/src/theme/theme.js | 13 +--- .../src/theme/utils/createCSSVariableMap.js | 40 ++++++++++ packages/theme/src/index.js | 2 +- 12 files changed, 185 insertions(+), 174 deletions(-) create mode 100644 packages/react/src/theme/createTheme.js create mode 100644 packages/react/src/theme/utils/createCSSVariableMap.js diff --git a/packages/react-docs/pages/_app.page.js b/packages/react-docs/pages/_app.page.js index 20a615e877..212207afae 100644 --- a/packages/react-docs/pages/_app.page.js +++ b/packages/react-docs/pages/_app.page.js @@ -7,6 +7,7 @@ import { ToastManager, TonicProvider, colorStyle as defaultColorStyle, + createTheme, theme, useTheme, } from '@tonic-ui/react'; @@ -50,28 +51,24 @@ const EmotionCacheProvider = ({ }; const App = (props) => { - const customTheme = useConst(() => { - return { - ...theme, - components: { - // Set default props for components here. - // - // Example: - // ``` - // 'AccordionToggle': { - // defaultProps: { - // disabled: true, - // }, - // } - // ``` - }, - config: { - ...theme?.config, - // Enable CSS variables replacement - useCSSVariables: true, - }, - }; - }); + const customTheme = useConst(() => createTheme(theme, { + components: { + // Set default props for specific components + // + // Example: + // ``` + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', + // }, + // }, + // ``` + }, + config: { + // Enable CSS variables replacement + useCSSVariables: true, + }, + })); const [initialColorMode, setColorMode] = useState(null); const router = useRouter(); 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 118dce13b8..93406bc491 100644 --- a/packages/react-docs/pages/getting-started/usage/index.page.mdx +++ b/packages/react-docs/pages/getting-started/usage/index.page.mdx @@ -14,32 +14,30 @@ import { Box, TonicProvider, colorStyle, // [optional] Required only for customizing color styles + createTheme, theme, // [optional] Required only for customizing the theme } from '@tonic-ui/react'; +import { useConst } from '@tonic-ui/react-hooks'; function App(props) { - const customTheme = { - ...theme, + const customTheme = useConst(() => createTheme(theme, { + components: { // Set default props for specific components // // Example: - // ```js - // components: { - // 'ToastCloseButton': { - // defaultProps: { - // 'aria-label': 'Close toast', - // }, + // ``` + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', // }, - // } + // }, // ``` - components: {}, - // Enable CSS variables - config: { - ...theme?.config, - useCSSVariables: true, - }, - }; - }; + }, + config: { + // Enable CSS variables replacement + useCSSVariables: true, + }, + })); return ( createTheme(theme, { + components: { // Set default props for specific components // // Example: - // ```js - // components: { - // 'ToastCloseButton': { - // defaultProps: { - // 'aria-label': 'Close toast', - // }, + // ``` + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', // }, - // } + // }, // ``` - components: {}, - // Enable CSS variables - config: { - ...theme?.config, - useCSSVariables: true, - }, - }; - }; + }, + config: { + // Enable CSS variables replacement + useCSSVariables: true, + }, + })); return ( ` component. ```js -import { theme } from '@tonic-ui/react'; +import { createTheme, theme } from '@tonic-ui/react'; // Let's say you want to add more colors -const customTheme = { - ...theme, +const customTheme = createTheme(theme, { config: { - ...theme?.config, useCSSVariables: true, }, colors: { - ...theme?.colors, brand: { 90: "#1a365d", 80: "#153e75", 70: "#2a69ac", }, }, -}; +}); ``` #### 2. Setting up the provider diff --git a/packages/react-docs/pages/theme/breakpoints/index.page.mdx b/packages/react-docs/pages/theme/breakpoints/index.page.mdx index 1feb2a62da..1e37bbb031 100644 --- a/packages/react-docs/pages/theme/breakpoints/index.page.mdx +++ b/packages/react-docs/pages/theme/breakpoints/index.page.mdx @@ -42,7 +42,7 @@ To do this, add a `breakpoints` array with additional aliases (e.g. `sm`, `md`, ```jsx disabled // 1. Import the theme -import { ThemeProvider, theme } from '@tonic-ui/react'; +import { ThemeProvider, createTheme, theme } from '@tonic-ui/react'; // 2. Update the breakpoints const breakpoints = [ @@ -59,10 +59,9 @@ breakpoints.xl = breakpoints[3]; breakpoints['2xl'] = breakpoints[4]; // 3. Extend the theme -const customTheme = { - ...theme, +const customTheme = createTheme(theme, { breakpoints, -}; +}); // 4. Pass the custom theme to the theme provider function App() { diff --git a/packages/react-docs/sandbox/create-react-app.js b/packages/react-docs/sandbox/create-react-app.js index d139ac7a84..c55790be80 100644 --- a/packages/react-docs/sandbox/create-react-app.js +++ b/packages/react-docs/sandbox/create-react-app.js @@ -28,20 +28,20 @@ import { ToastManager, TonicProvider, colorStyle, + createTheme, theme, useColorMode, useColorStyle, useTheme, } from '@tonic-ui/react'; +import { useConst } from '@tonic-ui/react-hooks'; +import { merge } from '@tonic-ui/utils'; import * as React from 'react'; import ReactDOM from 'react-dom/client'; import App from './app'; -const customColorStyle = { - ...colorStyle, +const customColorStyle = merge(colorStyle, { dark: { - ...colorStyle.dark, - // Add custom colors here risk: { high: 'red:50', @@ -58,8 +58,6 @@ const customColorStyle = { }, }, light: { - ...colorStyle.light, - // Add custom colors here risk: { high: 'red:60', @@ -75,30 +73,27 @@ const customColorStyle = { info: 'gray:50', }, }, -}; +}); 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 + const customTheme = useConst(() => createTheme(theme, { + components: { + // Set default props for specific components + // + // Example: + // \`\`\` + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', + // }, + // }, + // \`\`\` + }, config: { - ...theme?.config, + // Enable CSS variables replacement useCSSVariables: true, }, - }; + })); return ( { // theme 'ThemeProvider', + 'createTheme', 'theme', 'useTheme', diff --git a/packages/react/src/provider/TonicProvider.js b/packages/react/src/provider/TonicProvider.js index ca81bcff32..3d682e3e85 100644 --- a/packages/react/src/provider/TonicProvider.js +++ b/packages/react/src/provider/TonicProvider.js @@ -6,14 +6,11 @@ import { CSSBaseline } from '../css-baseline'; const TonicProvider = ({ children, - colorMode: colorModeProps, - colorStyle: colorStyleProps, + colorMode: colorModeProps = {}, + colorStyle: colorStyleProps = {}, theme, useCSSBaseline = false, }) => { - colorModeProps = colorModeProps ?? {}; - colorStyleProps = colorStyleProps ?? {}; - if (typeof colorModeProps !== 'object') { console.error( 'TonicProvider: "colorMode" prop must be an object if provided.\n' + diff --git a/packages/react/src/theme/ThemeProvider.js b/packages/react/src/theme/ThemeProvider.js index 8bfbbefa80..4394c2dc69 100644 --- a/packages/react/src/theme/ThemeProvider.js +++ b/packages/react/src/theme/ThemeProvider.js @@ -1,83 +1,20 @@ import { ThemeProvider as StyledEngineThemeProvider, } from '@emotion/react'; -import originalTheme from '@tonic-ui/theme'; -import { ensurePlainObject, ensureString } from 'ensure-type'; -import React, { useMemo } from 'react'; +import React from 'react'; import { DefaultPropsProvider } from '../default-props'; import CSSVariables from './CSSVariables'; import defaultTheme from './theme'; -import flatten from './utils/flatten'; -import toCSSVariable from './utils/toCSSVariable'; - -const originalThemeScales = Object.keys(originalTheme); - -/** - * Generate CSS variable map for a given theme object. - * - * @param {object} theme - The object containing the theme values. - * @param {object} [options] - The options object. - * @param {string} [options.prefix] - A prefix to prepend to each generated CSS variable. - * - * @example - * ```js - * const theme = { - * colors: { - * 'blue:50': '#578aef', - * }, - * }; - * createCSSVariableMap(theme, { prefix: 'tonic' }); - * // => { - * // '--tonic-colors-blue-50': '#578aef' - * // } - * ``` - */ -const createCSSVariableMap = (theme, options) => { - const prefix = ensureString(options?.prefix); - const tokens = flatten(theme); - const cssVariableMap = {}; - - for (const [name, value] of Object.entries(tokens)) { - // name='colors.blue:50', prefix='tonic' - // => '--tonic-colors-blue-50' - const variable = toCSSVariable(name, { prefix }); - cssVariableMap[variable] = value; - } - - return cssVariableMap; -}; const ThemeProvider = ({ children, theme: themeProp, }) => { const theme = themeProp ?? defaultTheme; - const computedTheme = useMemo(() => { - const themeConfig = { - ...defaultTheme.config, - ...theme?.config, - }; - - // Filter only the theme scales that are supported by the original theme - const normalizedTheme = Object.fromEntries( - Object.entries(ensurePlainObject(theme)).filter( - ([key]) => originalThemeScales.includes(key) - ) - ); - - // Create CSS variable map for the theme - const cssVariableMap = createCSSVariableMap(normalizedTheme, { prefix: themeConfig.prefix }); - - return { - ...theme, - config: themeConfig, - __cssVariableMap: cssVariableMap, - }; - }, [theme]); return ( - - + + {children} diff --git a/packages/react/src/theme/createTheme.js b/packages/react/src/theme/createTheme.js new file mode 100644 index 0000000000..5e033c0e1d --- /dev/null +++ b/packages/react/src/theme/createTheme.js @@ -0,0 +1,57 @@ +import { merge } from '@tonic-ui/utils'; +import { ensurePlainObject } from 'ensure-type'; +import createCSSVariableMap from './utils/createCSSVariableMap'; + +const defaultCSSVariablePrefix = 'tonic'; + +const cssVariableScales = [ + 'borders', + 'breakpoints', + 'colors', + 'fonts', + 'fontSizes', + 'fontWeights', + 'letterSpacings', + 'lineHeights', + 'outlines', + 'radii', + 'shadows', + 'sizes', + 'space', + 'zIndices', +]; + +const createTheme = (options, ...args) => { + // Merge provided options with default configurations + let theme = merge(options, { + config: { + prefix: defaultCSSVariablePrefix, + useCSSVariables: false, + }, + }); + + // Ensure the components field is initialized + theme.components = theme.components ?? {}; + + // Merge additional arguments into the theme + theme = args.reduce((acc, arg) => merge(acc, arg), theme); + + // Generate a theme object filtered to include only scales supported by CSS variables + const cssVariableTheme = Object.fromEntries( + Object.entries(ensurePlainObject(theme)).filter( + ([key]) => cssVariableScales.includes(key) + ) + ); + + // Create a map of CSS variables with the appropriate prefix + const cssVariableMap = createCSSVariableMap(cssVariableTheme, { prefix: theme?.config?.prefix }); + + // Merge the CSS variable map into the theme + theme = merge(theme, { + __cssVariableMap: cssVariableMap, + }); + + return theme; +}; + +export default createTheme; diff --git a/packages/react/src/theme/index.js b/packages/react/src/theme/index.js index 2e19cb1818..bc7f208afc 100644 --- a/packages/react/src/theme/index.js +++ b/packages/react/src/theme/index.js @@ -1,9 +1,11 @@ import ThemeProvider from './ThemeProvider'; -import theme from './theme'; +import createTheme from './createTheme'; import useTheme from './useTheme'; +import theme from './theme'; export { ThemeProvider, + createTheme, theme, useTheme, }; diff --git a/packages/react/src/theme/theme.js b/packages/react/src/theme/theme.js index 21dd1e5e8a..7c89066a20 100644 --- a/packages/react/src/theme/theme.js +++ b/packages/react/src/theme/theme.js @@ -1,13 +1,6 @@ -import originalTheme from '@tonic-ui/theme'; +import tonicTheme from '@tonic-ui/theme'; +import createTheme from './createTheme'; -const theme = { - ...originalTheme, - config: { - prefix: 'tonic', - useCSSVariables: false, - }, - components: {}, - icons: [], -}; +const theme = createTheme(tonicTheme); export default theme; diff --git a/packages/react/src/theme/utils/createCSSVariableMap.js b/packages/react/src/theme/utils/createCSSVariableMap.js new file mode 100644 index 0000000000..8fcf409fe4 --- /dev/null +++ b/packages/react/src/theme/utils/createCSSVariableMap.js @@ -0,0 +1,40 @@ +import { ensureString } from 'ensure-type'; +import flatten from './flatten'; +import toCSSVariable from './toCSSVariable'; + +/** + * Generate CSS variable map for a given theme object. + * + * @param {object} theme - The object containing the theme values. + * @param {object} [options] - The options object. + * @param {string} [options.prefix] - A prefix to prepend to each generated CSS variable. + * + * @example + * ```js + * const theme = { + * colors: { + * 'blue:50': '#578aef', + * }, + * }; + * createCSSVariableMap(theme, { prefix: 'tonic' }); + * // => { + * // '--tonic-colors-blue-50': '#578aef' + * // } + * ``` + */ +const createCSSVariableMap = (theme, options) => { + const prefix = ensureString(options?.prefix); + const tokens = flatten(theme); + const cssVariableMap = {}; + + for (const [name, value] of Object.entries(tokens)) { + // name='colors.blue:50', prefix='tonic' + // => '--tonic-colors-blue-50' + const variable = toCSSVariable(name, { prefix }); + cssVariableMap[variable] = value; + } + + return cssVariableMap; +}; + +export default createCSSVariableMap; diff --git a/packages/theme/src/index.js b/packages/theme/src/index.js index f02767257e..d7c1833c03 100644 --- a/packages/theme/src/index.js +++ b/packages/theme/src/index.js @@ -1,4 +1,4 @@ -import createTheme from './createTheme'; +import createTheme from './createTheme'; // deprecated const theme = createTheme('rem'); From 44da0316bf192ae7760c4995372d74ba7fb2454c Mon Sep 17 00:00:00 2001 From: cheton Date: Sat, 23 Nov 2024 20:54:00 +0800 Subject: [PATCH 02/18] feat: add default value for the `options` parameter --- packages/react/src/theme/createTheme.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/src/theme/createTheme.js b/packages/react/src/theme/createTheme.js index 5e033c0e1d..bbee4058ed 100644 --- a/packages/react/src/theme/createTheme.js +++ b/packages/react/src/theme/createTheme.js @@ -21,7 +21,7 @@ const cssVariableScales = [ 'zIndices', ]; -const createTheme = (options, ...args) => { +const createTheme = (options = {}, ...args) => { // Merge provided options with default configurations let theme = merge(options, { config: { From bf1ac8004d8c5ea378e22fc893e88d49e69c263a Mon Sep 17 00:00:00 2001 From: cheton Date: Sat, 23 Nov 2024 21:58:23 +0800 Subject: [PATCH 03/18] docs: update examples --- .../components/color-style/index.page.mdx | 8 +- .../getting-started/usage/index.page.mdx | 111 +++++++++--------- .../migrating-from-v1-to-v2.page.mdx | 18 +-- .../react-docs/sandbox/create-react-app.js | 39 +++--- 4 files changed, 82 insertions(+), 94 deletions(-) diff --git a/packages/react-docs/pages/components/color-style/index.page.mdx b/packages/react-docs/pages/components/color-style/index.page.mdx index 3a2e628ef0..85829122ea 100644 --- a/packages/react-docs/pages/components/color-style/index.page.mdx +++ b/packages/react-docs/pages/components/color-style/index.page.mdx @@ -83,12 +83,11 @@ To override default color style, you can create a color style object in accordan ```jsx disabled import { Box, TonicProvider, colorStyle } from '@tonic-ui/react'; +import { merge } from '@tonic-ui/utils'; import React from 'react'; -const customColorStyle = { - ...colorStyle, +const customColorStyle = merge(colorStyle, { dark: { - ...colorStyle.dark, risk: { high: 'red:50', medium: 'yellow:50', @@ -104,7 +103,6 @@ const customColorStyle = { }, }, light: { - ...colorStyle.light, risk: { high: 'red:60', medium: 'yellow:50', @@ -119,7 +117,7 @@ const customColorStyle = { info: 'gray:50', }, }, -}; +}); const App = () => ( createTheme(theme, { - components: { - // Set default props for specific components - // - // Example: - // ``` - // 'ToastCloseButton': { - // defaultProps: { - // 'aria-label': 'Close toast', - // }, - // }, - // ``` - }, - config: { - // Enable CSS variables replacement - useCSSVariables: true, - }, - })); +const customTheme = createTheme(theme, { + config: { + // Enable CSS variables replacement + useCSSVariables: true, + }, + components: { + // Set default props for specific components + // + // Example: + // ``` + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', + // }, + // }, + // ``` + }, +}); +function App(props) { return ( @@ -72,37 +71,36 @@ import { useColorMode, useTheme, } from '@tonic-ui/react'; -import { useConst } from '@tonic-ui/react-hooks'; -function App(props) { - const customTheme = useConst(() => createTheme(theme, { - components: { - // Set default props for specific components - // - // Example: - // ``` - // 'ToastCloseButton': { - // defaultProps: { - // 'aria-label': 'Close toast', - // }, - // }, - // ``` - }, - config: { - // Enable CSS variables replacement - useCSSVariables: true, - }, - })); +const customTheme = createTheme(theme, { + config: { + // Enable CSS variables replacement + useCSSVariables: true, + }, + components: { + // Set default props for specific components + // + // Example: + // ``` + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', + // }, + // }, + // ``` + }, +}); +function App(props) { return ( ``` @@ -259,12 +255,11 @@ To override default color style, you can create a color style object according t ```js import { colorStyle } from '@tonic-ui/react'; +import { merge } from '@tonic-ui/utils'; // Let's say you want to define color style for your components -const customColorStyle = { - ...colorStyle, +const customColorStyle = merge(colorStyle, { dark: { - ...colorStyle.dark, risk: { high: 'red:50', medium: 'yellow:50', @@ -280,7 +275,6 @@ const customColorStyle = { }, }, light: { - ...colorStyle.light, risk: { high: 'red:60', medium: 'yellow:50', @@ -295,7 +289,7 @@ const customColorStyle = { info: 'gray:50', }, }, -}; +}); ``` #### 2. Setting up the provider @@ -332,7 +326,10 @@ Optionally, you can extend the theme object to override the defaults with custom Override the theme object and pass it to the `` component. ```js -import { createTheme, theme } from '@tonic-ui/react'; +import { + createTheme, + theme, +} from '@tonic-ui/react'; // Let's say you want to add more colors const customTheme = createTheme(theme, { diff --git a/packages/react-docs/pages/migrations/migrating-from-v1-to-v2.page.mdx b/packages/react-docs/pages/migrations/migrating-from-v1-to-v2.page.mdx index a934fb3e29..9f6994495b 100644 --- a/packages/react-docs/pages/migrations/migrating-from-v1-to-v2.page.mdx +++ b/packages/react-docs/pages/migrations/migrating-from-v1-to-v2.page.mdx @@ -40,12 +40,10 @@ To use previously defined `severity` and `chart` colors, you need to pass a cust ```jsx disabled import React from 'react'; import { Box, TonicProvider, colorStyle } from '@tonic-ui/react'; +import { merge } from '@tonic-ui/utils'; -const customColorStyle = { - ...colorStyle, +const customColorStyle = merge(colorStyle, { dark: { - ...colorStyle.dark, - // deprecated severity: { critical: 'magenta:60', @@ -77,8 +75,6 @@ const customColorStyle = { }, }, light: { - ...colorStyle.light, - // deprecated severity: { critical: 'magenta:60', @@ -109,7 +105,7 @@ const customColorStyle = { }, }, }, -}; +}); const App = (props) => ( { - const customTheme = useConst(() => createTheme(theme, { - components: { - // Set default props for specific components - // - // Example: - // \`\`\` - // 'ToastCloseButton': { - // defaultProps: { - // 'aria-label': 'Close toast', - // }, - // }, - // \`\`\` - }, - config: { - // Enable CSS variables replacement - useCSSVariables: true, - }, - })); +const customTheme = createTheme(theme, { + config: { + // Enable CSS variables replacement + useCSSVariables: true, + }, + components: { + // Set default props for specific components + // + // Example: + // \`\`\` + // 'ToastCloseButton': { + // defaultProps: { + // 'aria-label': 'Close toast', + // }, + // }, + // \`\`\` + }, +}); +const Root = (props) => { return ( Date: Sat, 23 Nov 2024 22:18:02 +0800 Subject: [PATCH 04/18] chore: add `tonic-ui-945.md` changeset --- .changeset/tonic-ui-945.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/tonic-ui-945.md diff --git a/.changeset/tonic-ui-945.md b/.changeset/tonic-ui-945.md new file mode 100644 index 0000000000..690a3d6553 --- /dev/null +++ b/.changeset/tonic-ui-945.md @@ -0,0 +1,6 @@ +--- +"@tonic-ui/react": patch +"@tonic-ui/theme": minor +--- + +feat(react): add `createTheme` for theme customization From 1f415b9ff8dc7a68bb501b8be9b36532ee814103 Mon Sep 17 00:00:00 2001 From: cheton Date: Sun, 24 Nov 2024 10:44:01 +0800 Subject: [PATCH 05/18] docs: update getting started usage guide --- .../getting-started/usage/index.page.mdx | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) 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 8c7e564996..dba000b734 100644 --- a/packages/react-docs/pages/getting-started/usage/index.page.mdx +++ b/packages/react-docs/pages/getting-started/usage/index.page.mdx @@ -12,10 +12,10 @@ Go to the root of your application and do the following: import React from 'react'; import { Box, - TonicProvider, - colorStyle, // The default color style object - createTheme, // The function for theme customization - theme, // The default theme configuration + TonicProvider, // Provides theme and context for Tonic UI components + colorStyle, // Default color style object + createTheme, // For theme customization (introduced in v2.5.0) + theme, // Default theme configuration } from '@tonic-ui/react'; const customTheme = createTheme(theme, { @@ -62,14 +62,15 @@ import { Global, css } from '@emotion/react'; import React from 'react'; import { Box, - PortalManager, // allows you to create and manage portals in the application - ToastManager, // allows you to create and manage toasts in the application - TonicProvider, - colorStyle, - createTheme, - theme, - useColorMode, - useTheme, + PortalManager, // Manages portals in the application + ToastManager, // Manages toasts in the application + TonicProvider, // Provides theme and context for Tonic UI components + colorStyle, // Default color style object + createTheme, // For theme customization (introduced in v2.5.0) + theme, // Default theme configuration + useColorMode, // Hook to manage color mode (e.g., light/dark) + useColorStyle, // Hook to manage color style + useTheme, // Hook to access the theme object } from '@tonic-ui/react'; const customTheme = createTheme(theme, { @@ -133,7 +134,7 @@ function App(props) { function Layout(props) { const [colorMode] = useColorMode(); - const [colorStyle] = useColorStyle({ colorMode }); + const [colorStyle] = useColorStyle(); const { colors, fontSizes, lineHeights } = useTheme(); const backgroundColor = colorStyle.background.primary; const color = colorStyle.color.primary; @@ -202,7 +203,9 @@ function Layout(props) { Sometimes you may need to apply base CSS styles to your application. Tonic UI provides an optional `CSSBaseline` component that fixes some inconsistencies across browsers and devices while providing slightly more opinionated resets to common HTML elements. `CSSBaseline` is recommended to add at the root to ensure all components work correctly. ```jsx disabled - + ``` @@ -296,14 +299,9 @@ const customColorStyle = merge(colorStyle, { ```jsx disabled {children} @@ -349,7 +347,9 @@ const customTheme = createTheme(theme, { #### 2. Setting up the provider ```jsx - + {children} ``` From 67fd9bdfaa26eab2e7a6868532cbf2aa9c09f4f3 Mon Sep 17 00:00:00 2001 From: cheton Date: Sun, 24 Nov 2024 11:03:51 +0800 Subject: [PATCH 06/18] docs: replace `\`\`\`jsx disabled` with `\`\`\`jsx` for the code block --- .../pages/components/alert/index.page.mdx | 4 ++-- .../pages/components/button/index.page.mdx | 4 ++-- .../pages/components/checkbox/index.page.mdx | 2 +- .../components/color-mode/index.page.mdx | 16 +++++++-------- .../color-mode/useColorMode.page.mdx | 2 +- .../components/color-style/index.page.mdx | 6 +++--- .../components/css-baseline/index.page.mdx | 2 +- .../date-pickers/date-picker/index.page.mdx | 4 ++-- .../pages/components/drawer/index.page.mdx | 4 ++-- .../pages/components/menu/index.page.mdx | 2 +- .../pages/components/modal/index.page.mdx | 4 ++-- .../pages/components/popover/index.page.mdx | 12 +++++------ .../components/portal-manager/index.page.mdx | 10 +++++----- .../pages/components/radio/index.page.mdx | 2 +- .../pages/components/scrollbar/index.page.mdx | 4 ++-- .../pages/components/skeleton/index.page.mdx | 2 +- .../pages/components/switch/index.page.mdx | 2 +- .../pages/components/table/index.page.mdx | 10 +++++----- .../pages/components/tag/index.page.mdx | 4 ++-- .../components/toast-manager/index.page.mdx | 8 ++++---- .../pages/components/toast/index.page.mdx | 4 ++-- .../pages/components/tooltip/index.page.mdx | 6 +++--- .../pages/components/tree/index.page.mdx | 6 +++--- .../getting-started/security/index.page.mdx | 4 ++-- .../the-sx-prop/index.page.mdx | 2 +- .../getting-started/usage/index.page.mdx | 20 +++++++++---------- 26 files changed, 73 insertions(+), 73 deletions(-) diff --git a/packages/react-docs/pages/components/alert/index.page.mdx b/packages/react-docs/pages/components/alert/index.page.mdx index 4f96319ddb..5765451185 100644 --- a/packages/react-docs/pages/components/alert/index.page.mdx +++ b/packages/react-docs/pages/components/alert/index.page.mdx @@ -52,7 +52,7 @@ If not specified, the default icon will be used based on the `severity` prop. The `isClosable` prop is used to make an alert closable by adding a close button to it. By default, the value of `isClosable` is false. To make an alert closable, set `isClosable` to true. -```jsx disabled +```jsx This is a success alert. @@ -66,7 +66,7 @@ The `AlertCloseButton` component provides an easy way to add a close button to a Besides the default functionality of the `AlertCloseButton`, you can also pass additional props, such as `data-test` or `data-tracking` attributes, to the `AlertCloseButton` component as needed. -```jsx disabled +```jsx This is a success alert. diff --git a/packages/react-docs/pages/components/button/index.page.mdx b/packages/react-docs/pages/components/button/index.page.mdx index f2988f9004..fc703d74ba 100644 --- a/packages/react-docs/pages/components/button/index.page.mdx +++ b/packages/react-docs/pages/components/button/index.page.mdx @@ -34,7 +34,7 @@ You can make buttons look inactive or active by adding the `disabled` or `select If the `disabled` prop is set (or set to `true`), the button will have a `disabled` attribute and not respond to user interactions. -```jsx disabled +```jsx ``` @@ -46,7 +46,7 @@ To customize the visual appearance of the disabled state, pass the `_disabled` s If the `selected` prop is set (or set to `true`), the button will have both `pointer-events: none` style and `tabindex="-1"` attribute. This will prevent the button from receiving pointer events and will not be reachable via sequential keyboard navigation. -```jsx disabled +```jsx ``` diff --git a/packages/react-docs/pages/components/checkbox/index.page.mdx b/packages/react-docs/pages/components/checkbox/index.page.mdx index a1c0ae4be9..220e6c9c6b 100644 --- a/packages/react-docs/pages/components/checkbox/index.page.mdx +++ b/packages/react-docs/pages/components/checkbox/index.page.mdx @@ -45,7 +45,7 @@ WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/ * All form controls should have labels, and this includes radio buttons, checkboxes, and switches. In most cases, this is done by using the `