Radix Themes

repository·main·Indexed 27 days ago

https://github.com/radix-ui/themes

An open-source component library optimized for fast development, easy maintenance, and accessibility. It provides a set of pre-styled, accessible components for building high-quality user interfaces, featuring layout components like Grid, Flex, and Box, as well as specialized components such as Dialog, TextField, and SegmentedControl.

Tokens
6.4K
Snippets
2
Records
70
Agent score
90%

What's inside Radix Themes

  1. Radix Themes Overview

    main
    Radix Themes is an open-source component library designed for fast development, easy maintenance, and accessibility. It provides a set of pre-styled, accessible components that can be used to build high-quality user interfaces.
  2. Update CSS specificity and Tailwind compatibility in v2.0.0

    main

    In version 2.0.0, CSS selector specificity was capped to improve compatibility with Tailwind CSS:

    • Styling HTML elements: specificity capped at 0,1,0.
    • Styling pseudo-elements: specificity capped at 0,1,1.

    [Upgrade guide] If you were relying on specific Radix Themes selector specificity quirks for your own styles, verify that your overrides still function correctly.

  3. Import Radix Themes styles

    main

    When using Radix Themes, you must import the CSS styles for the components to render correctly. Depending on your version, the import path has changed:

    • For version 0.0.39 and later: Import from @radix-ui/themes/styles.css.
    • For version 0.0.38 and earlier: Import from @radix-ui/themes/index.css.

    Note that older versions used @radix-ui/react-themes as the source, but this has been consolidated into the @radix-ui/themes package.

  4. Update width and height props (v3.0.0)

    main

    In version 3.0.0, the width and height props no longer map to the space scale. They now accept arbitrary CSS values (including responsive object syntax).

    Upgrade Guide: Replace space scale values with corresponding pixel values or CSS variables. For example, width="9" should be changed to width="64px" or width="var(--space-9)".

  5. Use standalone component entrypoints in @radix-ui/themes

    main

    Starting from version 3.2.0, you can import components from standalone entrypoints to potentially optimize your bundle. For single components, import them directly. For compound components, it is recommended to use namespaced imports.

    import { AlertDialog } from '@radix-ui/themes/components/alert-dialog';
    import { Box } from '@radix-ui/themes/components/box';
    // We recommend using namespaced imports for compound components
    import * as CheckboxGroup from '@radix-ui/themes/components/checkbox-group';
  6. Configure Theme appearance and hydration

    main

    When setting the appearance prop on the Theme component to dark or light, Radix Themes injects a script to set the theme class and color-scheme on the html element.

    To prevent hydration mismatch warnings in frameworks like Next.js, you must add suppressHydrationWarning to your <html> element. This change was introduced in version 0.0.38.

    Additionally, in version 0.0.44, the Theme component was updated to respect the theme class format on the html element when updating appearance.

  7. Migrate Checkbox, RadioGroup, and Switch sizes in v2.0.0

    main

    In version 2.0.0, the size scales for Checkbox, RadioGroup, and Switch were reworked.

    [Upgrade guide] If you were using explicit size props, update them as follows:

    • For Checkbox and RadioGroup:
      • Rename size="1" $\rightarrow$ size="2"
      • Rename size="2" $\rightarrow$ size="3"
    • For Switch:
      • Use size="3" to match the previous size="2" look.
  8. Import fine-grained CSS files (v3.0.0)

    main

    Radix Themes v3.0.0 exports individual CSS files to allow for fine-grained control over CSS precedence and bundle size:

    • tokens.css
    • components.css
    • utilities.css
    • layout.css (styles for Box, Flex, Grid, Container, Section)

    You can also customize color imports by using tokens/base.css and importing specific colors from tokens/colors/*.css (e.g., tokens/colors/blue.css).

  9. Migrate TextField usage (v3.0.0)

    main

    In version 3.0.0, the TextField.Input part was removed to simplify prop forwarding.

    Upgrade Guide:

    1. If using TextField.Input without TextField.Root: Rename it to TextField.Root.
    2. If using TextField.Input inside TextField.Root: Remove the Input part and move its props directly onto TextField.Root.
    3. If using TextField.Slot to the right of an input: Add the side="right" prop. (Note: If two slots are used within one TextField, they are automatically positioned on different sides).
  10. Migrate to dot notation for multi-part components (v3.0.0)

    main

    In version 3.0.0, Radix Themes dropped named exports for multi-part components. You must now use dot notation to access component parts. This change also ensures reliable behavior in React Server Components.

    Example: Instead of importing a specific part as a named export, use the parent component with dot notation, such as Dialog.Root.