Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react): add createTheme for theme customization #947

Merged
merged 18 commits into from
Nov 29, 2024
Merged

Conversation

cheton
Copy link
Member

@cheton cheton commented Nov 23, 2024

User description

Demo: https://trendmicro-frontend.github.io/tonic-ui-demo/react/pr-947

Theme Configuration:
https://mui.com/material-ui/customization/css-theme-variables/configuration/


Description

  • Introduced createTheme function to simplify theme customization across the application.
  • Updated various components and documentation to utilize createTheme for consistent theme management.
  • Enhanced TonicProvider by setting default values for colorMode and colorStyle props.
  • Simplified ThemeProvider by removing redundant CSS variable map logic.
  • Updated tests to include createTheme in expected exports.
  • Deprecated createTheme in the theme package, indicating a shift to a new implementation.

Changes walkthrough 📝

Relevant files
Enhancement
8 files
_app.page.js
Integrate `createTheme` for theme customization                   

packages/react-docs/pages/_app.page.js

  • Added createTheme import for theme customization.
  • Replaced manual theme customization with createTheme function.
  • +19/-22 
    create-react-app.js
    Use `createTheme` and `merge` for theme and color customization

    packages/react-docs/sandbox/create-react-app.js

  • Added createTheme import for theme customization.
  • Replaced manual theme customization with createTheme function.
  • Used merge utility for color style customization.
  • +20/-25 
    TonicProvider.js
    Set default values for TonicProvider props                             

    packages/react/src/provider/TonicProvider.js

    • Set default values for colorMode and colorStyle props.
    +2/-5     
    ThemeProvider.js
    Simplify ThemeProvider by removing CSS variable map logic

    packages/react/src/theme/ThemeProvider.js

    • Simplified ThemeProvider by removing CSS variable map creation.
    +3/-66   
    createTheme.js
    Introduce `createTheme` function for customizable themes 

    packages/react/src/theme/createTheme.js

  • Introduced createTheme function for theme customization.
  • Supports merging options and generating CSS variable map.
  • +57/-0   
    index.js
    Export `createTheme` from theme index                                       

    packages/react/src/theme/index.js

    • Added createTheme export.
    +3/-1     
    theme.js
    Use `createTheme` for default theme configuration               

    packages/react/src/theme/theme.js

    • Replaced manual theme configuration with createTheme.
    +3/-10   
    createCSSVariableMap.js
    Add utility for creating CSS variable map                               

    packages/react/src/theme/utils/createCSSVariableMap.js

    • Added utility to generate CSS variable map from theme.
    +40/-0   
    Tests
    1 files
    index.test.js
    Update tests to include `createTheme` export                         

    packages/react/tests/index.test.js

    • Added createTheme to the list of expected exports.
    +1/-0     
    Documentation
    3 files
    index.js
    Deprecate `createTheme` in theme package                                 

    packages/theme/src/index.js

    • Marked createTheme as deprecated.
    +1/-1     
    index.page.mdx
    Update usage documentation for `createTheme`                         

    packages/react-docs/pages/getting-started/usage/index.page.mdx

  • Updated documentation to use createTheme for theme customization.
  • +33/-40 
    index.page.mdx
    Update breakpoints documentation for `createTheme`             

    packages/react-docs/pages/theme/breakpoints/index.page.mdx

    • Updated breakpoints documentation to use createTheme.
    +3/-4     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information


    PR Type

    enhancement, tests, documentation


    Description

    • Introduced a new createTheme function to simplify theme customization, allowing for CSS variable generation with optional prefixes.
    • Updated various components and documentation to utilize createTheme, replacing deprecated theme configuration methods.
    • Added comprehensive tests for the createTheme function, ensuring correct theme merging and CSS variable handling.
    • Replaced CodeBlock with PreformattedText in documentation for better code display.
    • Updated package installation and usage documentation to reflect new theme customization methods.

    Changes walkthrough 📝

    Relevant files
    Enhancement
    4 files
    ThemeProvider.js
    Simplify ThemeProvider by removing redundant logic             

    packages/react/src/theme/ThemeProvider.js

  • Removed redundant CSS variable map logic.
  • Simplified theme computation by removing useMemo.
  • Directly used theme prop in StyledEngineThemeProvider.
  • +3/-66   
    css-vars.js
    Introduce utility functions for CSS variable generation   

    packages/react/src/theme/utils/css-vars.js

  • Introduced utility functions for CSS variable generation.
  • Added toCSSVariable and mapThemeToCSSVariables functions.
  • +63/-0   
    createTheme.js
    Implement createTheme function for theme customization     

    packages/react/src/theme/createTheme.js

  • Implemented createTheme function for theme customization.
  • Added support for CSS variables with optional prefix.
  • Merged additional arguments into the theme.
  • +61/-0   
    theme.js
    Simplify theme initialization with createTheme                     

    packages/react/src/theme/theme.js

  • Replaced direct theme export with createTheme.
  • Simplified theme initialization.
  • +2/-10   
    Tests
    2 files
    createTheme.test.js
    Add tests for createTheme function                                             

    packages/react/src/theme/tests/createTheme.test.js

  • Added tests for createTheme function.
  • Verified default theme creation and custom theme merging.
  • Tested CSS variable generation and custom prefix application.
  • +60/-0   
    InputControl.test.js
    Update InputControl tests to use CSS variables                     

    packages/react/src/input/tests/InputControl.test.js

  • Removed useCSSVariables option from render options.
  • Updated tests to use CSS variables directly.
  • +6/-8     
    Documentation
    4 files
    index.page.mdx
    Update usage examples with createTheme                                     

    packages/react-docs/pages/getting-started/usage/index.page.mdx

  • Updated examples to use createTheme for theme customization.
  • Replaced deprecated theme configuration with new implementation.
  • +55/-100
    index.page.mdx
    Update color style documentation with PreformattedText     

    packages/react-docs/pages/components/color-style/index.page.mdx

  • Replaced CodeBlock with PreformattedText for displaying code.
  • Updated color style customization examples.
  • +26/-28 
    index.page.mdx
    Update installation guide with dynamic descriptions           

    packages/react-docs/pages/getting-started/installation/index.page.mdx

  • Updated package installation commands.
  • Added dynamic package descriptions using imports.
  • +23/-10 
    usage.js
    Replace CodeBlock with PreformattedText in modal usage     

    packages/react-docs/pages/components/modal/usage.js

  • Replaced CodeBlock with PreformattedText for code display.
  • Simplified code example components.
  • +5/-22   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    codesandbox bot commented Nov 23, 2024

    Review or Edit in CodeSandbox

    Open the branch in Web EditorVS CodeInsiders

    Open Preview

    Copy link

    changeset-bot bot commented Nov 23, 2024

    🦋 Changeset detected

    Latest commit: db02958

    The changes in this PR will be included in the next version bump.

    This PR includes changesets to release 2 packages
    Name Type
    @tonic-ui/react Patch
    @tonic-ui/theme Minor

    Not sure what this means? Click here to learn what changesets are.

    Click here if you're a maintainer who wants to add another changeset to this PR

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Nov 23, 2024

    PR Reviewer Guide 🔍

    (Review updated until commit 83288bc)

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Code Complexity
    The createTheme function handles multiple configuration options and theme merging logic. Verify the merging behavior works correctly for all edge cases and theme customization scenarios.

    Performance
    The mapThemeToCSSVariables function flattens and processes the entire theme object. For large themes, this could impact performance. Consider optimizing or memoizing results.

    Code Deprecation
    The code contains deprecated theme config properties that will be removed in next major release. Verify the deprecation warnings and migration path are clear.

    @cheton cheton linked an issue Nov 23, 2024 that may be closed by this pull request
    Copy link

    codesandbox-ci bot commented Nov 23, 2024

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    @trendmicro-frontend-bot
    Copy link
    Contributor

    trendmicro-frontend-bot commented Nov 23, 2024

    Tonic UI Demo

    On 2024-11-29 14:04:23 +0000, PR #947 (db02958) was successfully deployed. You can view it at the following link:
    https://trendmicro-frontend.github.io/tonic-ui-demo/react/pr-947/

    Copy link

    codecov bot commented Nov 23, 2024

    Codecov Report

    Attention: Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.

    Project coverage is 78.45%. Comparing base (848cc51) to head (db02958).
    Report is 1 commits behind head on v2.

    Files with missing lines Patch % Lines
    packages/react/src/theme/CSSVariables.js 80.00% 1 Missing ⚠️
    packages/react/src/theme/createTheme.js 94.11% 1 Missing ⚠️
    packages/react/src/theme/utils/css-vars.js 92.85% 1 Missing ⚠️
    Additional details and impacted files
    @@            Coverage Diff             @@
    ##               v2     #947      +/-   ##
    ==========================================
    + Coverage   78.41%   78.45%   +0.03%     
    ==========================================
      Files         405      406       +1     
      Lines        6677     6692      +15     
    ==========================================
    + Hits         5236     5250      +14     
    - Misses       1441     1442       +1     

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    @cheton
    Copy link
    Member Author

    cheton commented Nov 26, 2024

    /ask Add test cases for the createTheme function

    Copy link
    Contributor

    Ask

    Add test cases for the createTheme function

    Answer:

    To add test cases for the createTheme function, you should consider the following scenarios:

    1. Default Theme Creation:

      • Test that createTheme() without any arguments returns a theme object that matches the default theme structure.
    2. Custom Theme Merging:

      • Test that createTheme({ colors: { primary: 'blue' } }) correctly merges the custom colors into the default theme.
    3. CSS Variables Configuration:

      • Test that setting useCSSVariables: true in the config results in the theme having CSS variables generated.
    4. Prefix Handling:

      • Test that a custom prefix is correctly applied to the CSS variables when specified in the config.
    5. Additional Arguments Merging:

      • Test that additional arguments passed to createTheme are correctly merged into the theme.
    6. CSS Variable Map Generation:

      • Test that the CSS variable map is correctly generated and included in the theme object.

    Here is an example of how you might write these tests using a testing framework like Jest:

    import createTheme from '../src/theme/createTheme';
    
    describe('createTheme', () => {
      it('should create a default theme', () => {
        const theme = createTheme();
        expect(theme).toHaveProperty('colors');
        expect(theme).toHaveProperty('config');
      });
    
      it('should merge custom theme options', () => {
        const customTheme = createTheme({ colors: { primary: 'blue' } });
        expect(customTheme.colors.primary).toBe('blue');
      });
    
      it('should enable CSS variables when specified', () => {
        const theme = createTheme({ config: { useCSSVariables: true } });
        expect(theme.config.useCSSVariables).toBe(true);
        expect(theme).toHaveProperty('__cssVariableMap');
      });
    
      it('should apply custom prefix to CSS variables', () => {
        const theme = createTheme({ config: { prefix: 'custom' } });
        const cssVariableMap = theme.__cssVariableMap;
        expect(Object.keys(cssVariableMap)[0]).toMatch(/^--custom-/);
      });
    
      it('should merge additional arguments into the theme', () => {
        const additionalConfig = { components: { Button: { defaultProps: { size: 'large' } } } };
        const theme = createTheme({}, additionalConfig);
        expect(theme.components.Button.defaultProps.size).toBe('large');
      });
    
      it('should generate a CSS variable map', () => {
        const theme = createTheme({ config: { useCSSVariables: true } });
        expect(theme.__cssVariableMap).toBeDefined();
        expect(Object.keys(theme.__cssVariableMap).length).toBeGreaterThan(0);
      });
    });

    These tests cover the basic functionality and expected behaviors of the createTheme function. Adjust the paths and imports according to your project's structure.

    @cheton
    Copy link
    Member Author

    cheton commented Nov 29, 2024

    /review

    @cheton
    Copy link
    Member Author

    cheton commented Nov 29, 2024

    /improve

    Copy link
    Contributor

    Persistent review updated to latest commit 6b4e3e8

    @cheton
    Copy link
    Member Author

    cheton commented Nov 29, 2024

    /describe

    Copy link
    Contributor

    PR Description updated to latest commit (782ad84)

    @cheton
    Copy link
    Member Author

    cheton commented Nov 29, 2024

    /ask Add a test case to createTheme.test.js that allows empty prefix for CSS variables

    Copy link
    Contributor

    Ask

    Add a test case to createTheme.test.js that allows empty prefix for CSS variables

    Answer:

    To add a test case in createTheme.test.js that allows an empty prefix for CSS variables, you can follow the structure of the existing tests. Here's how you can add this test case:

    import createTheme from '../createTheme';
    
    describe('createTheme', () => {
      // Existing test cases...
    
      it('should allow an empty prefix for CSS variables', () => {
        const theme = createTheme({ cssVariables: { prefix: '' } });
        expect(theme.vars).toBeDefined();
        expect(theme.vars.prefix).toBe('');
        // Check that CSS variables are generated without a prefix
        const cssVariableKeys = Object.keys(theme.vars).filter(x => x.startsWith('--'));
        expect(cssVariableKeys.length).toBeGreaterThan(0);
        cssVariableKeys.forEach(key => {
          expect(key).toMatch(/^--[a-zA-Z0-9-_]+$/); // Ensure no prefix is added
        });
      });
    });

    Explanation:

    • Test Description: The test is named to indicate that it checks for the ability to use an empty prefix for CSS variables.
    • Theme Creation: The createTheme function is called with cssVariables: { prefix: '' } to specify an empty prefix.
    • Assertions:
      • expect(theme.vars).toBeDefined(); ensures that the vars object is created.
      • expect(theme.vars.prefix).toBe(''); checks that the prefix is indeed set to an empty string.
      • The test then checks that CSS variables are generated and that they start with -- but do not have any additional prefix, using a regular expression to match the expected format.

    @cheton
    Copy link
    Member Author

    cheton commented Nov 29, 2024

    /review

    @cheton
    Copy link
    Member Author

    cheton commented Nov 29, 2024

    /improve

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Nov 29, 2024

    PR Code Suggestions ✨

    Latest suggestions up to 83288bc

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Fix incorrect empty object check that would cause CSS variables to never be applied

    Add a check for empty cssVariables using Object.keys(cssVariables).length instead of
    comparing to 0 with ===. The current comparison will always evaluate to false.

    packages/react/src/theme/CSSVariables.js [9-11]

    -if (!rootSelector || Object.keys(cssVariables) === 0) {
    +if (!rootSelector || Object.keys(cssVariables).length === 0) {
       return {};
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: The suggestion fixes a critical bug where CSS variables would never be applied due to an incorrect comparison. Using Object.keys(cssVariables) === 0 compares an array with 0, which always returns false.

    9
    General
    Update test configuration to use the new property name for CSS variables

    The property name has been changed from useCSSVariables to cssVariables in v2.5.0.
    Update the test configuration to use the new property name.

    packages/react-docs/pages/contributing/react-components-part-1.page.mdx [106-108]

     const renderOptions = {
    -  cssVariables: true, // Enable CSS variables replacement
    +  cssVariables: true, // Enable CSS variables replacement (introduced in v2.5.0)
     };
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion correctly identifies the property name change from 'useCSSVariables' to 'cssVariables' in v2.5.0 and suggests adding a clarifying comment. This improves code maintainability and documentation.

    7
    Improve type checking to handle null values in configuration validation

    The error handling for cssVariableConfig should check for null since it's a common
    JavaScript value that's neither boolean nor object.

    packages/react/src/theme/createTheme.js [32-34]

    -if (typeof cssVariableConfig !== 'boolean' && typeof cssVariableConfig !== 'object') {
    +if (cssVariableConfig !== null && typeof cssVariableConfig !== 'boolean' && typeof cssVariableConfig !== 'object') {
       throw new Error('The `cssVariables` config must be a boolean or an object');
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    Why: The suggestion adds a valid null check to the type validation, which could prevent potential runtime errors. However, the impact is minor since null is already handled implicitly by the existing type checks.

    3

    Previous suggestions

    ✅ Suggestions up to commit 6b4e3e8
    CategorySuggestion                                                                                                                                    Score
    Possible issue
    ✅ Add type validation for configuration parameter to prevent invalid inputs

    Add validation for the cssVariableConfig parameter to ensure it's either a boolean
    or an object with a valid prefix property.

    packages/react/src/theme/createTheme.js [28-29]

     if (cssVariableConfig) {
    +  if (typeof cssVariableConfig !== 'boolean' && typeof cssVariableConfig !== 'object') {
    +    throw new Error('cssVariables config must be either boolean or an object');
    +  }
       const cssVariablePrefix = cssVariableConfig?.prefix ?? defaultCSSVariablePrefix;

    [Suggestion has been applied]

    Suggestion importance[1-10]: 8

    Why: The suggestion adds crucial type validation for the cssVariableConfig parameter, which could prevent subtle bugs and provide clear error messages when invalid configuration is provided. This is important for API robustness.

    8
    Add validation to prevent runtime errors from undefined or null input parameters

    Add input validation to ensure name parameter is not undefined or null before using
    it in string operations. This will prevent potential runtime errors.

    packages/react/src/theme/utils/css-vars.js [19-22]

    +if (!name) {
    +  throw new Error('name parameter is required');
    +}
     const variableName = ([prefix, name].filter(Boolean).join(delimiter))
    -  .replace(/\s+/g, delimiter) // replace whitespace characters
    -  .replace(/[^a-zA-Z0-9-_]/g, delimiter) // replace non-alphanumeric, non-hyphen, non-underscore characters
    -  .replace(/^-+|-+$/g, ''); // trim hyphens from beginning and end of string
    +  .replace(/\s+/g, delimiter)
    +  .replace(/[^a-zA-Z0-9-_]/g, delimiter)
    +  .replace(/^-+|-+$/g, '');
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a critical input validation issue that could prevent runtime errors. Adding null/undefined checks for the 'name' parameter is important for function robustness and reliability.

    8
    Ensure consistent naming of configuration properties across the codebase to maintain backward compatibility

    The property name cssVariables is used inconsistently with the old property name
    useCSSVariables. This change should be coordinated with other configuration changes
    to ensure backward compatibility.

    packages/react-docs/pages/contributing/react-components-part-1.page.mdx [105-107]

     const renderOptions = {
    -  cssVariables: true, // Enable CSS variables replacement
    +  useCSSVariables: true, // Enable CSS variables replacement
     };
    Suggestion importance[1-10]: 8

    Why: The suggestion identifies an important inconsistency in configuration property naming that could cause compatibility issues and confusion for users migrating from older versions.

    8
    Add validation for required object prop to prevent runtime errors

    Add default value initialization for colorStyleProps to prevent potential undefined
    access issues, similar to how colorModeProps is handled.

    packages/react/src/provider/TonicProvider.js [7-13]

     const TonicProvider = ({
       children,
       colorMode: colorModeProps = {},
       colorStyle: colorStyleProps = {},
       theme,
       useCSSBaseline = false,
     }) => {
    +  if (typeof colorStyleProps !== 'object') {
    +    console.error(
    +      'TonicProvider: "colorStyle" prop must be an object if provided.\n'
    +    );
    +  }
    Suggestion importance[1-10]: 7

    Why: The suggestion adds important validation for the colorStyle prop, similar to existing colorMode validation, which helps prevent runtime errors and improves error handling. This is a meaningful defensive programming practice.

    7
    Add object type validation before iteration to prevent runtime errors

    Add validation to ensure tokens is an object before iterating over its entries to
    prevent potential runtime errors.

    packages/react/src/theme/utils/css-vars.js [48-51]

     const tokens = flatten(theme);
    +if (!tokens || typeof tokens !== 'object') {
    +  throw new Error('Invalid theme structure');
    +}
     const cssVariables = {};
     
     for (const [name, value] of Object.entries(tokens)) {
    Suggestion importance[1-10]: 7

    Why: The suggestion adds important type validation for the 'tokens' object before iteration, which would prevent potential runtime errors if the theme structure is invalid.

    7
    Ensure proper deep merging of nested configuration objects to prevent data loss

    The merge operation for color styles should be deep to properly handle nested
    objects and preserve existing color styles.

    packages/react-docs/pages/getting-started/usage/index.page.mdx [130-134]

    -const customColorStyle = merge(colorStyle, {
    +const customColorStyle = merge({}, colorStyle, {
       dark: {
         risk: {
           high: 'red:50',
           medium: 'yellow:50',
    Suggestion importance[1-10]: 7

    Why: The suggestion correctly points out a potential issue with object merging that could lead to incomplete or incorrect color style configurations.

    7
    ✅ Suggestions up to commit efb03a3
    CategorySuggestion                                                                                                                                    Score
    Possible issue
    ✅ Add input validation to prevent runtime errors from invalid parameters
    Suggestion Impact:The suggestion to set a default value for the options parameter was implemented in the commit, which helps prevent runtime errors when no options are provided.

    code diff:

    -const createTheme = (options, ...args) => {
    +const createTheme = (options = {}, ...args) => {

    Validate the input options parameter to ensure it's an object before merging with
    default configurations. Add type checking to prevent runtime errors.

    packages/react/src/theme/createTheme.js [24-31]

    -const createTheme = (options, ...args) => {
    +const createTheme = (options = {}, ...args) => {
    +  if (typeof options !== 'object' || options === null) {
    +    throw new Error('createTheme: options parameter must be an object');
    +  }
       // Merge provided options with default configurations
       let theme = merge(options, {
         config: {
           prefix: defaultCSSVariablePrefix,
           useCSSVariables: false,
         },
       });
    Suggestion importance[1-10]: 8

    Why: The suggestion adds crucial input validation to prevent potential runtime errors when invalid parameters are passed to createTheme. This is important for a core theme creation function.

    8
    Fix potential runtime error by validating props before default value assignment

    Move the error check for colorModeProps before the default value assignment to
    prevent potential undefined access.

    packages/react/src/provider/TonicProvider.js [7-17]

     const TonicProvider = ({
       children,
    -  colorMode: colorModeProps = {},
    -  colorStyle: colorStyleProps = {},
    +  colorMode: colorModeProps,
    +  colorStyle: colorStyleProps,
       theme,
       useCSSBaseline = false,
     }) => {
    -  if (typeof colorModeProps !== 'object') {
    +  if (typeof colorModeProps !== 'object' && colorModeProps !== undefined) {
    +    console.error(
    +      'TonicProvider: "colorMode" prop must be an object if provided.\n' +
    +      'See https://trendmicro-frontend.github.io/tonic-ui for more information.'
    +    );
    +  }
    +  colorModeProps = colorModeProps ?? {};
    +  colorStyleProps = colorStyleProps ?? {};
    Suggestion importance[1-10]: 7

    Why: The suggestion improves error handling by validating props before default assignment, preventing potential undefined access issues in a core provider component.

    7

    Copy link
    Contributor

    Persistent review updated to latest commit 83288bc

    @cheton
    Copy link
    Member Author

    cheton commented Nov 29, 2024

    /ask Add test case for custom rootSelector

    Copy link
    Contributor

    Ask

    Add test case for custom rootSelector

    Answer:

    To add a test case for a custom rootSelector in the createTheme function, you can follow these steps:

    1. Identify the Functionality: The createTheme function in the PR allows for a custom rootSelector to be specified when generating CSS variables. This is part of the cssVariables configuration.

    2. Create a Test Case: You need to create a test case that verifies if the rootSelector is correctly applied when specified.

    3. Write the Test: Here's an example of how you might write this test:

    import createTheme from '../createTheme';
    
    describe('createTheme with custom rootSelector', () => {
      it('should apply custom rootSelector for CSS variables', () => {
        const customRootSelector = '.custom-root';
        const theme = createTheme({
          cssVariables: {
            rootSelector: customRootSelector,
          },
        });
    
        expect(theme.rootSelector).toBe(customRootSelector);
        expect(theme.cssVariables).toBeDefined();
        // Additional checks can be added here to verify the CSS variables are applied to the custom rootSelector
      });
    });
    1. Explanation: This test case creates a theme with a custom rootSelector and checks if the rootSelector in the theme matches the custom value provided. You can expand this test by checking if the CSS variables are correctly applied to the specified rootSelector in a real DOM environment, if necessary.

    2. Run the Test: Ensure that the test runs successfully and that it correctly verifies the functionality of the rootSelector customization.

    By following these steps, you can ensure that the createTheme function correctly handles custom rootSelector values.

    @cheton cheton merged commit 86f88f1 into v2 Nov 29, 2024
    7 checks passed
    @cheton cheton deleted the tonic-ui-945 branch November 29, 2024 14:23
    cheton added a commit that referenced this pull request Nov 30, 2024
    cheton added a commit that referenced this pull request Nov 30, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Add createTheme to generate a theme based on the provided options
    3 participants