Skip to main content
GitHub

Material look

A Material-style settings screen, built from nxds parts with your own colors.

Built with nxds

Profile

Shown on your invoices.

3 of 5 details added

Enter a full email address.

Notifications

Choose what we email you.

Built with Material UI

The first screen is built with nxds parts. The second is the same screen built with Material UI, to compare.

Set your own colors

Create the colors file, with Roboto and the standard elevation:

npx nxds-cli@latest init --own-colors --font roboto --elevation standard

Replace its values with Material's palette:

/* app/nxds-colors.css */
@layer theme {
  :root {
    --nx-color-primary-background: #1976d2;
    --nx-color-primary-background-hover: #1565c0;
    --nx-color-primary-foreground: #fff;
    --nx-color-primary-disabled: rgb(0 0 0 / 0.12);
    --nx-color-secondary-background: #9c27b0;
    --nx-color-secondary-background-hover: #7b1fa2;
    --nx-color-secondary-border: rgb(156 39 176 / 0.5);
    --nx-color-error-background: #d32f2f;
    --nx-color-foreground: rgb(0 0 0 / 0.87);
    --nx-color-border-default: rgb(0 0 0 / 0.23);
    /* The other colors */
  }
}

The full palette has every color for light and dark. It sets them on a wrapper, so they reach only the preview on this page. Your app sets them on :root and .dark.

Your own colors covers the colors file.

Add Material's shadows

Material lifts a card and a button off the page. Redefine the standard elevation in the colors file:

/* app/nxds-colors.css */
@layer theme {
  [data-shadow='standard'],
  .dark[data-shadow='standard'],
  .dark [data-shadow='standard'] {
    --nx-shadow-xs:
      0 2px 1px -1px rgb(0 0 0 / 0.2), 0 1px 1px 0 rgb(0 0 0 / 0.14),
      0 1px 3px 0 rgb(0 0 0 / 0.12);
    --nx-shadow-sm:
      0 3px 1px -2px rgb(0 0 0 / 0.2), 0 2px 2px 0 rgb(0 0 0 / 0.14),
      0 1px 5px 0 rgb(0 0 0 / 0.12);
    --nx-shadow-base:
      0 2px 4px -1px rgb(0 0 0 / 0.2), 0 4px 5px 0 rgb(0 0 0 / 0.14),
      0 1px 10px 0 rgb(0 0 0 / 0.12);
    --nx-shadow-md:
      0 3px 5px -1px rgb(0 0 0 / 0.2), 0 6px 10px 0 rgb(0 0 0 / 0.14),
      0 1px 18px 0 rgb(0 0 0 / 0.12);
    --nx-shadow-lg:
      0 5px 5px -3px rgb(0 0 0 / 0.2), 0 8px 10px 1px rgb(0 0 0 / 0.14),
      0 3px 14px 2px rgb(0 0 0 / 0.12);
    --nx-shadow-xl:
      0 7px 8px -4px rgb(0 0 0 / 0.2), 0 12px 17px 2px rgb(0 0 0 / 0.14),
      0 5px 22px 4px rgb(0 0 0 / 0.12);
  }
}

The six shadows are Material's elevations 1, 2, 4, 6, 8 and 12.

Set Material's letter spacing

Material spaces its body text by 0.15px. Set the nxds letter spacing for body text in the colors file:

/* app/nxds-colors.css */
@layer theme {
  :root {
    --nx-typography-letterspacing-normal: 0.15px;
  }
}

Add the parts

npx nxds-cli@latest add card button progress switch checkbox label

Each part needs a different amount of work:

PartChange
LabelNone. It reads the colors you set
CardA shadow in place of the border, and Material's title sizes
ButtonThree restyled variants, a tone prop, round icon buttons
ProgressA thin, square bar on a tinted track
SwitchA new class recipe: a thin track, a raised thumb and a hover halo
CheckboxA new class recipe and check mark: a bold outline, and a hover halo
TextFieldA new part: the label sits inside the field

Edit the Card

A Material card has a shadow and no border, and a large title in regular weight. Change the Card's class strings:

components/nxds/components/card/card.tsx
import * as React from 'react';

import { Slot } from '@radix-ui/react-slot';

import { cn } from '../../lib/utils';

/**
 * CardProps
 *
 * Props for the Card component.
 */
type CardProps = React.ComponentProps<'div'>;

/**
 * Groups related content and actions in a section raised by a shadow.
 * Content is clipped to the rounded corners. Add `nx:overflow-visible` for content that overhangs the edge.
 */
function Card({ className, ...props }: CardProps) {
  return (
    <div
      data-slot="card"
      className={cn(
        'nx:overflow-hidden nx:rounded-md nx:bg-container nx:text-container-foreground nx:shadow-xs',
        className
      )}
      {...props}
    />
  );
}

/**
 * CardHeaderProps
 *
 * Props for the CardHeader component.
 */
type CardHeaderProps = React.ComponentProps<'div'>;

/**
 * Holds the title, description and `CardAction`.
 * `CardAction` sits in a right-hand column. Add `nx:col-start-1` to a custom child so it lines up with the title.
 */
function CardHeader({ className, ...props }: CardHeaderProps) {
  return (
    <div
      data-slot="card-header"
      className={cn(
        'nx:grid nx:grid-cols-[minmax(0,1fr)_auto] nx:items-start nx:p-4',
        className
      )}
      {...props}
    />
  );
}

/**
 * CardTitleProps
 *
 * Props for the CardTitle component.
 */
interface CardTitleProps extends React.ComponentProps<'h3'> {
  /**
   * Applies the title styles to the child element, such as a different heading level.
   */
  asChild?: boolean;
}

/**
 * Card heading. Renders an `h3`, or another heading level through `asChild`.
 */
function CardTitle({
  asChild = false,
  className,
  children,
  ...props
}: CardTitleProps) {
  const Comp = asChild ? Slot : 'h3';

  return (
    <Comp
      data-slot="card-title"
      className={cn(
        'nx:col-start-1 nx:m-0 nx:min-w-0 nx:typography-heading-medium nx:font-normal nx:tracking-normal',
        className
      )}
      {...props}
    >
      {children}
    </Comp>
  );
}

/**
 * CardDescriptionProps
 *
 * Props for the CardDescription component.
 */
type CardDescriptionProps = React.ComponentProps<'p'>;

/**
 * Supporting text under the title.
 */
function CardDescription({ className, ...props }: CardDescriptionProps) {
  return (
    <p
      data-slot="card-description"
      className={cn(
        'nx:col-start-1 nx:m-0 nx:min-w-0 nx:typography-body-default nx:text-[length:var(--nx-typography-size-base)] nx:leading-[var(--nx-typography-line-height-base)] nx:text-muted-foreground',
        className
      )}
      {...props}
    />
  );
}

/**
 * CardActionProps
 *
 * Props for the CardAction component.
 */
type CardActionProps = React.ComponentProps<'div'>;

/**
 * Holds header actions, such as buttons or badges, beside the title.
 */
function CardAction({ className, ...props }: CardActionProps) {
  return (
    <div
      data-slot="card-action"
      className={cn(
        'nx:col-start-2 nx:row-start-1 nx:row-span-2 nx:flex nx:items-center nx:gap-2 nx:self-start nx:justify-self-end nx:pl-4',
        className
      )}
      {...props}
    />
  );
}

/**
 * CardContentProps
 *
 * Props for the CardContent component.
 */
type CardContentProps = React.ComponentProps<'div'>;

/**
 * Main content area.
 */
function CardContent({ className, ...props }: CardContentProps) {
  return (
    <div
      data-slot="card-content"
      className={cn('nx:p-4 nx:pt-0', className)}
      {...props}
    />
  );
}

/**
 * CardFooterProps
 *
 * Props for the CardFooter component.
 */
type CardFooterProps = React.ComponentProps<'div'>;

/**
 * Holds actions and content at the bottom of the card.
 */
function CardFooter({ className, ...props }: CardFooterProps) {
  return (
    <div
      data-slot="card-footer"
      className={cn('nx:flex nx:items-center nx:gap-2 nx:p-2', className)}
      {...props}
    />
  );
}

export {
  Card,
  CardAction,
  type CardActionProps,
  CardContent,
  type CardContentProps,
  CardDescription,
  type CardDescriptionProps,
  CardFooter,
  type CardFooterProps,
  CardHeader,
  type CardHeaderProps,
  type CardProps,
  CardTitle,
  type CardTitleProps,
};
Material needsChange
A shadow, and no bordernx:shadow-xs in place of the border classes
4px cornersnx:rounded-md
Tighter paddingnx:p-4 on the header and the content, and no gap under the title
A 24px title in regular weightnx:typography-heading-medium nx:font-normal nx:tracking-normal
16px supporting textThe base size and line height on the description
An action row that fits text buttonsnx:p-2 on the footer

Edit the Button

Restyle three of the Button's variants, and add a tone beside variant:

components/nxds/components/button/button-variants.ts
import { cva, type VariantProps } from 'class-variance-authority';

export const buttonVariants = cva(
  'nx:inline-flex nx:box-border nx:cursor-pointer nx:items-center nx:justify-center nx:border-0 nx:bg-transparent nx:no-underline nx:whitespace-nowrap nx:uppercase nx:transition-[color,background-color,box-shadow] nx:focus-visible:outline-2 nx:focus-visible:outline-focus-default nx:focus-visible:outline-offset-2 nx:disabled:pointer-events-none nx:disabled:cursor-default nx:disabled:opacity-100 nx:disabled:text-disabled-foreground nx:aria-disabled:pointer-events-none nx:aria-disabled:cursor-default nx:aria-disabled:opacity-100 nx:aria-disabled:text-disabled-foreground nx:[&_svg]:pointer-events-none nx:[&_svg]:shrink-0 nx:icon-stroke',
  {
    variants: {
      variant: {
        default:
          'nx:shadow-sm nx:hover:shadow-base nx:active:shadow-lg nx:disabled:shadow-none nx:aria-disabled:shadow-none',
        error:
          'nx:text-error-subtle-foreground nx:hover:bg-error-subtle-hover nx:active:bg-error-subtle-active nx:disabled:text-disabled-foreground nx:aria-disabled:text-disabled-foreground',
        destructive:
          'nx:bg-error-background nx:text-error-foreground nx:hover:bg-error-background-hover nx:active:bg-error-background-active nx:disabled:bg-error-disabled nx:aria-disabled:bg-error-disabled',
        outline:
          'nx:inset-ring-[length:var(--nx-borderwidth-default)] nx:disabled:inset-ring-disabled nx:aria-disabled:inset-ring-disabled',
        dashed:
          'nx:border-default nx:border-dashed nx:border-border-default nx:bg-container nx:text-foreground nx:hover:bg-container-hover nx:active:bg-container-active nx:disabled:border-border-disabled nx:disabled:bg-disabled nx:disabled:text-disabled-foreground nx:aria-disabled:border-border-disabled nx:aria-disabled:bg-disabled nx:aria-disabled:text-disabled-foreground',
        secondary:
          'nx:bg-secondary-background nx:text-secondary-foreground nx:hover:bg-secondary-background-hover nx:active:bg-secondary-background-active nx:disabled:bg-secondary-disabled nx:disabled:text-disabled-foreground nx:aria-disabled:bg-secondary-disabled nx:aria-disabled:text-disabled-foreground',
        ghost: '',
        link: 'nx:border-0 nx:text-primary-subtle-foreground nx:underline-offset-4 nx:hover:underline nx:active:scale-100 nx:disabled:text-disabled-foreground nx:aria-disabled:text-disabled-foreground',
      },
      tone: {
        default: '',
        primary: '',
        secondary: '',
        error: '',
      },
      size: {
        sm: '',
        default: '',
        lg: '',
      },
      iconOnly: {
        false:
          'nx:min-w-16 nx:gap-2 nx:rounded-base nx:typography-label-default nx:leading-[1.75] nx:tracking-[var(--nx-typography-letterspacing-wide)] nx:[&_svg]:size-5',
        true: 'nx:rounded-full nx:p-0 nx:[&_svg]:size-6',
      },
    },
    compoundVariants: [
      {
        variant: 'default',
        tone: ['default', 'primary'],
        className:
          'nx:bg-primary-background nx:text-primary-foreground nx:hover:bg-primary-background-hover nx:active:bg-primary-background-active nx:disabled:bg-primary-disabled nx:aria-disabled:bg-primary-disabled',
      },
      {
        variant: 'default',
        tone: 'secondary',
        className:
          'nx:bg-secondary-background nx:text-secondary-foreground nx:hover:bg-secondary-background-hover nx:active:bg-secondary-background-active nx:disabled:bg-secondary-disabled nx:aria-disabled:bg-secondary-disabled',
      },
      {
        variant: 'default',
        tone: 'error',
        className:
          'nx:bg-error-background nx:text-error-foreground nx:hover:bg-error-background-hover nx:active:bg-error-background-active nx:disabled:bg-error-disabled nx:aria-disabled:bg-error-disabled',
      },
      {
        variant: 'outline',
        tone: 'default',
        className:
          'nx:inset-ring-border-default nx:bg-container nx:text-foreground nx:hover:bg-container-hover nx:active:bg-container-active nx:disabled:bg-secondary-disabled nx:aria-disabled:bg-secondary-disabled',
      },
      {
        variant: 'outline',
        tone: 'primary',
        className:
          'nx:inset-ring-primary-border nx:text-primary-subtle-foreground nx:hover:inset-ring-primary-border-active nx:hover:bg-primary-background/4 nx:active:bg-primary-subtle-active',
      },
      {
        variant: 'outline',
        tone: 'secondary',
        className:
          'nx:inset-ring-secondary-border nx:text-secondary-subtle-foreground nx:hover:inset-ring-secondary-border-active nx:hover:bg-secondary-background/4 nx:active:bg-secondary-subtle-active',
      },
      {
        variant: 'outline',
        tone: 'error',
        className:
          'nx:inset-ring-error-border nx:text-error-subtle-foreground nx:hover:inset-ring-border-error-active nx:hover:bg-error-background/4 nx:active:bg-error-subtle-active',
      },
      {
        variant: 'ghost',
        tone: 'default',
        className:
          'nx:text-foreground nx:hover:bg-container-hover nx:active:bg-container-active',
      },
      {
        variant: 'ghost',
        tone: 'primary',
        className:
          'nx:text-primary-subtle-foreground nx:hover:bg-primary-background/4 nx:active:bg-primary-subtle-active',
      },
      {
        variant: 'ghost',
        tone: 'secondary',
        className:
          'nx:text-secondary-subtle-foreground nx:hover:bg-secondary-background/4 nx:active:bg-secondary-subtle-active',
      },
      {
        variant: 'ghost',
        tone: 'error',
        className:
          'nx:text-error-subtle-foreground nx:hover:bg-error-background/4 nx:active:bg-error-subtle-active',
      },
      {
        iconOnly: false,
        size: 'sm',
        className:
          'nx:px-2.5 nx:py-1 nx:text-[length:calc(var(--nx-typography-size-sm)-1px)]',
      },
      { iconOnly: false, size: 'default', className: 'nx:px-4 nx:py-1.5' },
      {
        iconOnly: false,
        size: 'lg',
        className:
          'nx:px-[22px] nx:py-2 nx:text-[length:calc(var(--nx-typography-size-sm)+1px)]',
      },
      {
        variant: 'ghost',
        iconOnly: false,
        size: 'sm',
        className: 'nx:px-[5px]',
      },
      {
        variant: 'ghost',
        iconOnly: false,
        size: 'default',
        className: 'nx:px-2',
      },
      {
        variant: 'ghost',
        iconOnly: false,
        size: 'lg',
        className: 'nx:px-[11px]',
      },
      { iconOnly: true, size: 'sm', className: 'nx:size-10' },
      { iconOnly: true, size: 'default', className: 'nx:size-12' },
      { iconOnly: true, size: 'lg', className: 'nx:size-14' },
      {
        variant: 'default',
        iconOnly: true,
        className: 'nx:shadow-md nx:hover:shadow-md nx:active:shadow-xl',
      },
      {
        variant: 'link',
        iconOnly: false,
        className: 'nx:h-auto nx:min-h-0 nx:p-0!',
      },
    ],
    defaultVariants: {
      variant: 'default',
      tone: 'default',
      size: 'default',
      iconOnly: false,
    },
  }
);

export type ButtonVariants = VariantProps<typeof buttonVariants>;
Material needsChange in the recipe
Contained, outlined and text buttonsNew classes on default, outline and ghost
Each in three colorsA tone variant: primary, secondary or error
Uppercase labels with wider letter spacingnx:uppercase and a nx:tracking-* class
A shadow that grows on hover and pressnx:shadow-sm, nx:hover:shadow-base, nx:active:shadow-lg
A readable disabled buttonnx:disabled:text-disabled-foreground, and no shadow
36.5px tall with 16px side paddingnx:py-1.5, nx:px-4 and a line height of 1.75
8px side padding on a text buttonnx:px-2 on the ghost variant
An outline that takes no roomnx:inset-ring-* in place of a border
A faint wash on hoverThe button's color at 4%, such as nx:bg-primary-background/4
Round icon buttons, 48px widenx:rounded-full and nx:size-12 on the icon-only variant

The variant names stay, so parts that build on Button, such as Pagination, still compile. Without a tone, a button keeps its nxds colors, so those parts look as they did. The other variants keep their nxds classes.

The component takes the new tone prop and passes it to the recipe. color is already an HTML attribute, so the prop has another name:

components/nxds/components/button/button.tsx
'use client';

import * as React from 'react';

import { Slot } from '@radix-ui/react-slot';

import { ButtonGroupSizeContext } from '../button-group/button-group-context';
import { Spinner } from '../spinner/spinner';
import { cn } from '../../lib/utils';

import { type ButtonVariants, buttonVariants } from './button-variants';

/** Button's props without its label and icon props. */
interface ButtonBaseProps
  extends
    Omit<React.ComponentProps<'button'>, 'children'>,
    Omit<ButtonVariants, 'iconOnly'> {
  /**
   * Disables the button and shows a spinner in place of its content.
   */
  loading?: boolean;
}

interface ButtonWithTextProps extends ButtonBaseProps {
  /**
   * Shows only `startIcon` in a square button. The text stays as the name
   * screen readers read, visually hidden.
   */
  iconOnly?: false;

  /**
   * Renders the child, such as an `<a>`, with button styles.
   * The `loading` spinner and icon slots then don't render.
   */
  asChild?: boolean;

  /**
   * Decorative icon before the label. Use `startIcon` or `endIcon`, not both.
   */
  startIcon?: React.ReactNode;

  /**
   * Decorative icon after the label. Use `endIcon` or `startIcon`, not both.
   */
  endIcon?: React.ReactNode;

  children?: React.ReactNode;
}

interface ButtonIconOnlyProps extends ButtonBaseProps {
  /**
   * Shows only `startIcon` in a square button. The text stays as the name
   * screen readers read, visually hidden.
   */
  iconOnly: true;

  /**
   * Renders the child, such as an `<a>`, with button styles.
   * The `loading` spinner and icon slots then don't render.
   */
  asChild?: false;

  /**
   * The button's name. Screen readers read it, and it stays visually hidden.
   */
  children: string;

  /**
   * Decorative icon before the label. Use `startIcon` or `endIcon`, not both.
   */
  startIcon: React.ReactNode;

  endIcon?: never;
}

/**
 * With `iconOnly`, `children` must be a string and `startIcon` must be set,
 * and `asChild` is not allowed.
 */
type ButtonProps = ButtonWithTextProps | ButtonIconOnlyProps;

function hasIconSlot(icon: React.ReactNode) {
  return icon !== undefined && icon !== null && icon !== false;
}

function ButtonIcon({
  position,
  children,
}: {
  position: 'start' | 'end';
  children: React.ReactNode;
}) {
  if (!hasIconSlot(children)) return null;
  return (
    <span
      aria-hidden="true"
      data-slot={`button-${position}-icon`}
      className="nx:inline-flex nx:shrink-0"
    >
      {children}
    </span>
  );
}

/** Icon slots and label content; loading renders spinner-only visually. */
function ButtonContent({
  loading,
  iconOnly,
  startIcon,
  endIcon,
  children,
}: {
  loading: boolean;
  iconOnly: boolean;
  startIcon?: React.ReactNode;
  endIcon?: React.ReactNode;
  children: React.ReactNode;
}) {
  const label = iconOnly ? (
    <span className="nx:sr-only">{children}</span>
  ) : (
    children
  );

  if (loading)
    return (
      <span
        data-slot="button-loading-content"
        className="nx:relative nx:inline-flex nx:items-center nx:justify-center"
      >
        <span data-slot="button-loading-label" className="nx:opacity-0">
          {label}
        </span>
        <Spinner
          aria-hidden="true"
          className="nx:absolute nx:left-1/2 nx:top-1/2 nx:-translate-x-1/2 nx:-translate-y-1/2"
        />
      </span>
    );

  return (
    <>
      <ButtonIcon position="start">{startIcon}</ButtonIcon>
      {label}
      <ButtonIcon position="end">{endIcon}</ButtonIcon>
    </>
  );
}

/**
 * Triggers an action. Renders a native `<button>`, or the child element with `asChild`.
 * A non-button child ignores `disabled`, so Button sets `aria-disabled` and removes it from the tab order.
 */
function Button({
  asChild = false,
  className,
  variant = 'default',
  tone = 'default',
  size,
  iconOnly = false,
  loading = false,
  disabled,
  children,
  startIcon,
  endIcon,
  type = 'button',
  tabIndex,
  'aria-busy': ariaBusy,
  'aria-disabled': ariaDisabled,
  ...props
}: ButtonProps) {
  // Inherit the enclosing ButtonGroup's size when no explicit size is set, so a
  // Button nested inside a trigger wrapper (a split button) still picks it up.
  const groupSize = React.useContext(ButtonGroupSizeContext);
  const semanticSize = size ?? groupSize ?? 'default';
  const isDisabled = disabled || loading;

  const sharedProps = {
    'data-slot': 'button',
    'data-variant': variant,
    'data-tone': tone,
    'data-size': semanticSize,
    'data-icon-only': iconOnly || undefined,
    'data-loading': loading || undefined,
    className: cn(
      buttonVariants({
        variant,
        tone,
        size: semanticSize,
        iconOnly,
        className,
      })
    ),
    'aria-busy': loading || ariaBusy || undefined,
    'aria-disabled': isDisabled || ariaDisabled || undefined,
  };

  if (asChild && React.isValidElement(children))
    return (
      <Slot {...sharedProps} {...props} tabIndex={isDisabled ? -1 : tabIndex}>
        {children}
      </Slot>
    );

  return (
    <button
      {...sharedProps}
      {...props}
      type={type}
      disabled={isDisabled}
      tabIndex={tabIndex}
    >
      <ButtonContent
        loading={loading}
        iconOnly={iconOnly}
        startIcon={startIcon}
        endIcon={endIcon}
      >
        {children}
      </ButtonContent>
    </button>
  );
}

export { Button, type ButtonProps, buttonVariants };

Loading, the icon slots, asChild and the focus ring are unchanged.

Edit the Progress

A Material progress bar is thin and square, on a track in a lighter shade of its own color. Change one class string in the Progress:

components/nxds/components/progress/progress.tsx
import * as React from 'react';

import * as ProgressPrimitive from '@radix-ui/react-progress';

import { cn } from '../../lib/utils';

/**
 * Props for the Progress component.
 */
type ProgressProps = React.ComponentProps<typeof ProgressPrimitive.Root>;

/**
 * Bar that shows task progress from `value` 0 to 100, or an animated bar
 * without `value`. Always pass an `aria-label` or `aria-labelledby`.
 */
function Progress({ className, value, ...props }: ProgressProps) {
  return (
    <ProgressPrimitive.Root
      data-slot="progress"
      value={value}
      className={cn(
        'nx:relative nx:h-1 nx:w-full nx:overflow-hidden nx:bg-primary-background/38',
        className
      )}
      {...props}
    >
      <ProgressPrimitive.Indicator
        data-slot="progress-indicator"
        className="nx:h-full nx:w-full nx:bg-primary-background nx:transition-transform nx:duration-fast nx:data-[state=indeterminate]:w-1/3 nx:data-[state=indeterminate]:animate-progress-indeterminate"
        style={
          value == null
            ? undefined
            : { transform: `translateX(-${100 - value}%)` }
        }
      />
    </ProgressPrimitive.Root>
  );
}

export { Progress, type ProgressProps };
Material needsChange
A thin bar with square endsnx:h-1, and no corner class
A track in a lighter primarynx:bg-primary-background/38 in place of the rail

Rewrite the Switch

A Material thumb is larger than its track, and casts a shadow. Replace the Switch's two class recipes. The component under them stays as it is:

components/nxds/components/switch/switch.tsx
import * as React from 'react';

import * as SwitchPrimitive from '@radix-ui/react-switch';
import { cva, type VariantProps } from 'class-variance-authority';

import { cn } from '../../lib/utils';

// The root is the whole touch area. It draws the track inside its edges, and a
// round halo behind the thumb on hover. The thumb is larger than the track and
// lifts off the page with a shadow.
const switchVariants = cva(
  [
    'nx:group nx:peer nx:relative nx:isolate nx:inline-flex nx:shrink-0 nx:cursor-pointer nx:rounded-full nx:border-0 nx:bg-transparent nx:p-0',
    'nx:before:absolute nx:before:rounded-full nx:before:transition-colors',
    'nx:data-[state=unchecked]:before:bg-muted-foreground-subtle nx:data-[state=checked]:before:bg-primary-background/50',
    'nx:after:absolute nx:after:top-0 nx:after:left-0 nx:after:aspect-square nx:after:h-full nx:after:rounded-full nx:after:transition-[background-color,translate]',
    'nx:enabled:hover:after:bg-background-hover-alpha nx:enabled:hover:data-[state=checked]:after:bg-primary-background/4',
    'nx:focus-visible:outline-2 nx:focus-visible:outline-focus-default',
    'nx:disabled:cursor-not-allowed nx:disabled:data-[state=checked]:before:bg-disabled nx:disabled:data-[state=unchecked]:before:bg-disabled',
  ],
  {
    variants: {
      size: {
        default:
          'nx:h-[38px] nx:w-[58px] nx:before:inset-3 nx:data-[state=checked]:after:translate-x-5 nx:focus-visible:-outline-offset-8',
        sm: 'nx:h-6 nx:w-10 nx:before:inset-[7px] nx:data-[state=checked]:after:translate-x-4 nx:focus-visible:-outline-offset-4',
      },
    },
    defaultVariants: {
      size: 'default',
    },
  }
);

const switchThumbVariants = cva(
  [
    'nx:pointer-events-none nx:absolute nx:z-10 nx:block nx:rounded-full',
    'nx:bg-control-thumb nx:shadow-xs nx:transition-[background-color,translate]',
    'nx:data-[state=checked]:bg-primary-background',
    'nx:data-disabled:bg-muted',
  ],
  {
    variants: {
      size: {
        default:
          'nx:top-[9px] nx:left-[9px] nx:size-5 nx:data-[state=checked]:translate-x-5',
        sm: 'nx:top-1 nx:left-1 nx:size-4 nx:data-[state=checked]:translate-x-4',
      },
    },
    defaultVariants: {
      size: 'default',
    },
  }
);

type SwitchProps = React.ComponentProps<typeof SwitchPrimitive.Root> &
  VariantProps<typeof switchVariants>;

/**
 * Turns one setting on or off, and applies it at once. Give it a label, or an
 * `aria-label`.
 */
function Switch({ className, size, ...props }: SwitchProps) {
  return (
    <SwitchPrimitive.Root
      data-slot="switch"
      data-size={size ?? 'default'}
      className={cn(switchVariants({ size, className }))}
      {...props}
    >
      <SwitchPrimitive.Thumb
        data-slot="switch-thumb"
        className={switchThumbVariants({ size })}
      />
    </SwitchPrimitive.Root>
  );
}

export { Switch, type SwitchProps, switchVariants };
Material needsChange in the recipe
A 58 by 38px touch areaThe root's size. An nx:before: box draws the track inside it
A track thinner than the thumbA 14px track, with a 20px thumb placed over it
A raised thumbnx:shadow-xs on the thumb
The primary color at half strength on the tracknx:before:bg-primary-background/50
A darker track when the switch is offnx:before:bg-muted-foreground-subtle
A round halo behind the thumb on hoverAn nx:after: circle that moves with the thumb

Rewrite the Checkbox

A Material checkbox is a larger box with a bold outline, a bold check and a round halo on hover. Replace the Checkbox's class recipe and its two marks. The component under them stays as it is:

components/nxds/components/checkbox/checkbox.tsx
import * as React from 'react';

import * as CheckboxPrimitive from '@radix-ui/react-checkbox';

import { selectionIndicatorMotionClassName } from '../../lib/motion';
import { cn } from '../../lib/utils';

/**
 * CheckboxProps
 *
 * Props for the Checkbox component.
 */
type CheckboxProps = React.ComponentProps<typeof CheckboxPrimitive.Root>;

// Each mark is drawn on the whole 18px box, border included, so it keeps
// Material's proportions.
const markClassName = cn(
  'nx:absolute nx:inset-[calc(var(--nx-borderwidth-thick)*-1)]',
  selectionIndicatorMotionClassName
);

/**
 * Selects one or more options, or toggles one setting.
 * Set `checked="indeterminate"` to show a dash for a partly selected group, such as "select all".
 *
 * The box is 18px at the Default UI scale, inside a 42px touch area that shows
 * a round halo on hover. Pair it with a `Label`.
 */
function Checkbox({ className, ...props }: CheckboxProps) {
  return (
    <CheckboxPrimitive.Root
      data-slot="checkbox"
      className={cn(
        'nx:group nx:peer nx:relative nx:isolate nx:m-3 nx:inline-flex nx:size-[calc(var(--nx-icon-glyph-default)_+_2px)] nx:shrink-0 nx:cursor-pointer nx:items-center nx:justify-center nx:p-0',
        'nx:rounded-sm nx:border-thick nx:border-muted-foreground nx:bg-transparent nx:text-primary-foreground',
        'nx:transition-control',
        'nx:after:absolute nx:after:-inset-3.5 nx:after:-z-10 nx:after:rounded-full nx:after:transition-colors',
        'nx:enabled:hover:after:bg-background-hover-alpha nx:enabled:hover:data-[state=checked]:after:bg-primary-background/4 nx:enabled:hover:data-[state=indeterminate]:after:bg-primary-background/4',
        'nx:focus-visible:outline-2 nx:focus-visible:outline-offset-2 nx:focus-visible:outline-focus-default',
        'nx:aria-invalid:border-border-error-active nx:aria-invalid:focus-visible:outline-focus-error',
        'nx:disabled:cursor-not-allowed nx:disabled:border-border-disabled',
        'nx:data-[state=checked]:border-primary-background nx:data-[state=checked]:bg-primary-background',
        'nx:data-[state=indeterminate]:border-primary-background nx:data-[state=indeterminate]:bg-primary-background',
        'nx:aria-invalid:data-[state=checked]:border-error-background nx:aria-invalid:data-[state=checked]:bg-error-background nx:aria-invalid:data-[state=checked]:text-error-foreground',
        'nx:aria-invalid:data-[state=indeterminate]:border-error-background nx:aria-invalid:data-[state=indeterminate]:bg-error-background nx:aria-invalid:data-[state=indeterminate]:text-error-foreground',
        'nx:data-[state=checked]:disabled:border-transparent nx:data-[state=checked]:disabled:bg-border-disabled',
        'nx:data-[state=indeterminate]:disabled:border-transparent nx:data-[state=indeterminate]:disabled:bg-border-disabled',
        className
      )}
      {...props}
    >
      <CheckboxPrimitive.Indicator
        forceMount
        data-slot="checkbox-indicator"
        className="nx:relative nx:flex nx:size-full nx:items-center nx:justify-center nx:text-current"
      >
        <svg
          data-slot="checkbox-check"
          aria-hidden="true"
          viewBox="3 3 18 18"
          fill="none"
          stroke="currentColor"
          strokeWidth="2"
          className={cn(
            markClassName,
            'nx:group-data-[state=checked]:scale-100 nx:group-data-[state=checked]:opacity-100'
          )}
        >
          <path d="M5.7 11.3 10 15.6l8.3-8.3" />
        </svg>
        <svg
          data-slot="checkbox-minus"
          aria-hidden="true"
          viewBox="3 3 18 18"
          fill="none"
          stroke="currentColor"
          strokeWidth="2"
          className={cn(
            markClassName,
            'nx:group-data-[state=indeterminate]:scale-100 nx:group-data-[state=indeterminate]:opacity-100'
          )}
        >
          <path d="M7 12h10" />
        </svg>
      </CheckboxPrimitive.Indicator>
    </CheckboxPrimitive.Root>
  );
}

export { Checkbox, type CheckboxProps };
Material needsChange
An 18px boxThe icon size plus 2px
A bold outline, and no fillnx:border-thick nx:border-muted-foreground nx:bg-transparent
A bold check and dashTwo inline SVG marks with a 2px line, in place of the icons
A round halo on hoverAn nx:after: circle that takes nx:bg-background-hover-alpha
A 42px touch areanx:m-3 around the box
No color change on hoverNo hover or press fill classes

Add a TextField

Material's label sits inside the field and rises into its border. No color or class change gives the nxds Input that shape, so add a part of your own:

components/nxds/components/text-field/text-field.tsx
import * as React from 'react';

import { cva, type VariantProps } from 'class-variance-authority';

import { cn } from '../../lib/utils';

const controlVariants = cva('nx:relative nx:flex nx:w-full nx:items-center', {
  variants: {
    variant: {
      outlined: 'nx:rounded-md',
      filled:
        'nx:rounded-t-md nx:bg-control-background nx:transition-field nx:hover:bg-control-background-hover nx:has-[:disabled]:bg-disabled',
    },
  },
});

const inputVariants = cva(
  [
    'nx:peer nx:box-border nx:w-full nx:min-w-0 nx:border-0 nx:bg-transparent nx:outline-none',
    'nx:typography-body-default nx:text-[length:var(--nx-typography-size-base)] nx:leading-[1.4375] nx:text-foreground',
    'nx:autofill-bg-transparent nx:autofill-text-foreground',
    'nx:placeholder:text-muted-foreground-subtle',
    'nx:disabled:cursor-not-allowed nx:disabled:text-disabled-foreground nx:disabled:autofill-text-disabled-foreground',
  ],
  {
    variants: {
      variant: {
        outlined: 'nx:rounded-md nx:px-3.5 nx:py-0',
        filled: 'nx:rounded-t-md nx:px-3',
      },
      size: { default: '', sm: '' },
    },
    compoundVariants: [
      { variant: 'outlined', size: 'default', className: 'nx:min-h-14' },
      { variant: 'outlined', size: 'sm', className: 'nx:min-h-10' },
      {
        variant: 'filled',
        size: 'default',
        className: 'nx:min-h-14 nx:pt-[25px] nx:pb-2',
      },
      {
        variant: 'filled',
        size: 'sm',
        className: 'nx:min-h-12 nx:pt-5 nx:pb-1',
      },
    ],
  }
);

// The label rests on the input's text line. It moves up and shrinks while the
// input has focus or a value, which the blank placeholder lets CSS see.
const labelVariants = cva(
  [
    'nx:pointer-events-none nx:absolute nx:top-1/2 nx:-translate-y-1/2',
    'nx:typography-body-default nx:text-[length:var(--nx-typography-size-base)] nx:leading-[1.4375] nx:text-muted-foreground',
    'nx:transition-[top,translate,scale,color] nx:duration-200 nx:ease-out',
    'nx:peer-focus:text-primary-subtle-foreground',
    'nx:peer-aria-invalid:text-error-subtle-foreground nx:peer-focus:peer-aria-invalid:text-error-subtle-foreground',
    'nx:peer-disabled:text-disabled-foreground',
  ],
  {
    variants: {
      variant: {
        outlined: 'nx:left-3.5 nx:origin-left',
        filled: 'nx:left-3 nx:origin-top-left',
      },
      size: { default: '', sm: '' },
      raised: { true: 'nx:scale-75', false: '' },
    },
    compoundVariants: [
      { variant: 'outlined', raised: true, className: 'nx:top-0' },
      {
        variant: 'outlined',
        raised: false,
        className:
          'nx:peer-[:is(:focus,:not(:placeholder-shown))]:top-0 nx:peer-[:is(:focus,:not(:placeholder-shown))]:scale-75',
      },
      {
        variant: 'filled',
        size: 'default',
        raised: true,
        className: 'nx:top-[7px] nx:translate-y-0',
      },
      {
        variant: 'filled',
        size: 'sm',
        raised: true,
        className: 'nx:top-1 nx:translate-y-0',
      },
      {
        variant: 'filled',
        size: 'default',
        raised: false,
        className:
          'nx:peer-[:is(:focus,:not(:placeholder-shown))]:top-[7px] nx:peer-[:is(:focus,:not(:placeholder-shown))]:translate-y-0 nx:peer-[:is(:focus,:not(:placeholder-shown))]:scale-75',
      },
      {
        variant: 'filled',
        size: 'sm',
        raised: false,
        className:
          'nx:peer-[:is(:focus,:not(:placeholder-shown))]:top-1 nx:peer-[:is(:focus,:not(:placeholder-shown))]:translate-y-0 nx:peer-[:is(:focus,:not(:placeholder-shown))]:scale-75',
      },
    ],
  }
);

// The outline is a fieldset so its legend can open a gap in the top border,
// exactly as wide as the raised label.
const outlineVariants = cva(
  [
    'nx:pointer-events-none nx:absolute nx:inset-x-0 nx:-top-[5px] nx:bottom-0 nx:m-0 nx:min-w-0 nx:overflow-hidden nx:px-2 nx:py-0 nx:text-left',
    'nx:rounded-[inherit] nx:border-default nx:border-border-default nx:transition-[border-color] nx:duration-200',
    'nx:peer-hover:border-foreground',
    'nx:peer-focus:border-thick nx:peer-focus:border-focus-default',
    'nx:peer-aria-invalid:border-border-error-active nx:peer-focus:peer-aria-invalid:border-focus-error',
    'nx:peer-disabled:border-border-disabled',
    'nx:*:invisible nx:*:float-none nx:*:block nx:*:h-[11px] nx:*:w-auto nx:*:overflow-hidden nx:*:p-0 nx:*:whitespace-nowrap',
    'nx:*:text-[length:calc(var(--nx-typography-size-base)*0.75)] nx:*:transition-[max-width] nx:*:duration-100',
  ],
  {
    variants: {
      raised: {
        true: 'nx:*:max-w-full',
        false:
          'nx:*:max-w-[0.01px] nx:peer-[:is(:focus,:not(:placeholder-shown))]:*:max-w-full',
      },
    },
  }
);

// The resting line, and over it the focus line that grows from the middle.
const underlineClass = [
  'nx:pointer-events-none nx:absolute nx:inset-x-0 nx:bottom-0 nx:border-width-b-default nx:border-muted-foreground-subtle',
  'nx:peer-hover:border-foreground nx:peer-disabled:border-border-disabled',
  'nx:peer-aria-invalid:border-border-error-active',
  'nx:after:absolute nx:after:inset-x-0 nx:after:-bottom-px nx:after:scale-x-0 nx:after:border-width-b-thick nx:after:border-focus-default nx:after:transition-[scale] nx:after:duration-200 nx:after:ease-out',
  'nx:peer-focus:after:scale-x-100 nx:peer-aria-invalid:after:border-focus-error',
].join(' ');

const helperVariants = cva(
  'nx:m-0 nx:mt-[3px] nx:typography-body-small nx:leading-[1.66] nx:tracking-[var(--nx-typography-letterspacing-wide)]',
  {
    variants: {
      variant: { outlined: 'nx:mx-3.5', filled: 'nx:mx-3' },
      tone: {
        default: 'nx:text-muted-foreground',
        invalid: 'nx:text-error-subtle-foreground',
        disabled: 'nx:text-disabled-foreground',
      },
    },
  }
);

type TextFieldProps = Omit<React.ComponentProps<'input'>, 'size'> &
  VariantProps<typeof inputVariants> & {
    /**
     * The field's name. It sits inside the field, and moves to the top edge
     * while the field has focus or a value.
     */
    label?: React.ReactNode;

    /** A hint or an error message under the field. */
    helperText?: React.ReactNode;
  };

/**
 * A one-line text field with its label inside it. Accepts every native input
 * attribute.
 *
 * - `outlined` has a stroke, which opens around the raised label.
 * - `filled` has a tonal fill and a bottom line.
 *
 * With a `placeholder`, the label stays raised so the two never overlap.
 */
function TextField({
  className,
  label,
  helperText,
  variant: variantProp,
  size: sizeProp,
  id,
  placeholder,
  disabled,
  'aria-invalid': ariaInvalid,
  'aria-describedby': ariaDescribedBy,
  ...props
}: TextFieldProps) {
  const variant = variantProp ?? 'outlined';
  const size = sizeProp ?? 'default';
  const generatedId = React.useId();
  const inputId = id ?? generatedId;
  const helperId = `${inputId}-helper`;
  const raised = Boolean(placeholder);
  const invalid = ariaInvalid === true || ariaInvalid === 'true';

  let tone: 'default' | 'invalid' | 'disabled' = 'default';
  if (invalid) tone = 'invalid';
  if (disabled) tone = 'disabled';

  return (
    <div
      data-slot="text-field"
      data-variant={variant}
      data-size={size}
      className={cn('nx:inline-flex nx:w-full nx:flex-col', className)}
    >
      <div
        data-slot="text-field-control"
        className={controlVariants({ variant })}
      >
        <input
          id={inputId}
          data-slot="text-field-input"
          placeholder={placeholder ?? ' '}
          disabled={disabled}
          aria-invalid={ariaInvalid}
          aria-describedby={
            [ariaDescribedBy, helperText ? helperId : undefined]
              .filter(Boolean)
              .join(' ') || undefined
          }
          className={inputVariants({ variant, size })}
          {...props}
        />
        {label ? (
          <label
            htmlFor={inputId}
            data-slot="text-field-label"
            className={cn(labelVariants({ variant, size, raised }))}
          >
            {label}
          </label>
        ) : null}
        {variant === 'outlined' ? (
          <fieldset
            aria-hidden="true"
            data-slot="text-field-outline"
            className={outlineVariants({ raised })}
          >
            <legend>
              {label ? (
                <span className="nx:visible nx:inline-block nx:px-[5px] nx:opacity-0">
                  {label}
                </span>
              ) : null}
            </legend>
          </fieldset>
        ) : (
          <span
            aria-hidden="true"
            data-slot="text-field-underline"
            className={underlineClass}
          />
        )}
      </div>
      {helperText ? (
        <p
          id={helperId}
          data-slot="text-field-helper"
          className={helperVariants({ variant, tone })}
        >
          {helperText}
        </p>
      ) : null}
    </div>
  );
}

export { TextField, type TextFieldProps };
PartJob
<input>The native field. Its blank placeholder lets CSS tell an empty field from a full one
<label>Rests on the text line. Rises to the top edge on focus, or when the field has a value
<fieldset> and <legend>Draw the outline. The legend opens a gap as wide as the label
<p>Helper or error text, linked to the field with aria-describedby

The field keeps no state in JavaScript. Its classes read :focus and :placeholder-shown.

If you pass a placeholder, the label stays raised, so the two never overlap.

TextField is a new file. The nxds Input, and the parts that build on it, stay as they are.

Use the parts

// app/settings/notifications.tsx
import { Button } from '@/components/nxds/components/button/button';
import {
  Card,
  CardContent,
  CardFooter,
  CardHeader,
  CardTitle,
} from '@/components/nxds/components/card/card';
import { Label } from '@/components/nxds/components/label/label';
import { Switch } from '@/components/nxds/components/switch/switch';
import { TextField } from '@/components/nxds/components/text-field/text-field';

export function Notifications() {
  return (
    <Card>
      <CardHeader>
        <CardTitle>Notifications</CardTitle>
      </CardHeader>
      <CardContent className="nx:flex nx:flex-col nx:gap-6">
        <TextField label="Send to" type="email" />
        <div className="nx:flex nx:items-center nx:justify-between">
          <Label htmlFor="product-updates">Product updates</Label>
          <Switch id="product-updates" defaultChecked />
        </div>
      </CardContent>
      <CardFooter className="nx:justify-end">
        <Button variant="ghost" tone="primary">
          Cancel
        </Button>
        <Button>Save</Button>
      </CardFooter>
    </Card>
  );
}

What nxds provides

From nxdsIn this example
Light and dark modeThe provider switches .dark, and the colors file has a value for each
DensityPadding and gaps on the nxds scale read the nxds spacing tokens
Corners and strokeThe parts read the nxds radius and border width tokens
Color namesEvery class reads an nxds color, so one file recolors every part
BehaviorSwitch and Checkbox keep their keyboard and screen reader support

The nxds screen on this page follows the page's mode, density and corners. Its colors come from the palette file, so the brand color in the theme picker doesn't change it. The Material UI screen follows the page's mode only.

The example has no ripple. Material draws its ripple with JavaScript.

Next steps