Skip to content

Color Theme Disclosure

Expand color palette choices within the page layout.

Preview

This preview runs in an iframe. The theme transition stays in the preview frame. In your app, the transition covers the full page.

Examples

Theme transition

A slide transition declared on this control. Duration is 500 milliseconds. Other controls keep their own settings.

This preview runs in an iframe. The theme transition stays in the preview frame. In your app, the transition covers the full page.

Opens upward

Place the choices above the trigger and the label below it. Reserved space keeps the preview and trigger in place.

This preview runs in an iframe. The theme transition stays in the preview frame. In your app, the transition covers the full page.

When to use

  • Show color palette choices in a settings panel with space in the expansion direction.
  • Keep the choices open while people compare their selection.
  • Use a bounded scroll area for a longer list.

When not to use

  • Expansion would cover or move content in a compact toolbar. Use Color Theme Selector.
  • You need a general content disclosure. This control selects a theme preference.

Installation

Set up uitheme-web in an existing Tailwind app. Then install this control. The floating selector is a separate component.

Tailwind version
Source language
npx uitheme-cli add color-theme-disclosure --base ui-sdk --tailwind 4 --language ts
  • This control uses the UI SDK Collapsible from @ui-sdk/vue/collapsible and RadioGroup from @ui-sdk/vue/radio.
  • UI SDK adds styles to the ui-sdk cascade layer. Declare @layer ui-sdk; at the top of your global stylesheet, before other layers. The CLI adds this line for you.

Usage

Place the control inside your theme provider. Expansion moves the content below it. The panel stays open after a selection. Its scroll area defaults to 240px and never exceeds 60% of the viewport height.

example.vue
<script setup lang="ts">
import { UIThemeProvider } from 'uitheme-web/vue';
import ColorThemeDisclosure from '@/components/ui/color-theme-disclosure.vue';
</script>

<template>
  <UIThemeProvider :color-themes="['default', 'caffeine']">
    <div class="flex h-96 flex-col justify-start">
      <ColorThemeDisclosure />
    </div>
  </UIThemeProvider>
</template>

Set direction="up" to place the choices above the trigger. Leave space above for the expanded panel. Anchor the control at the bottom of its container if the trigger must stay in place. The Examples section shows this layout. The default is direction="down".

Keep the label below the trigger when the panel opens upward. The component places the label there automatically. Keep the label above a downward-opening trigger. Preserve this order when you customize the layout.

Reserve enough height for the expanded panel, trigger, label, and frame padding. Align downward controls to the top and upward controls to the bottom. The examples reserve h-96 with the default maxHeight={240}. Adjust the space if you change the scroll limit. Opening a panel must not shift its trigger or the surrounding preview.

API reference

Use open with the change callback to control expansion. Use defaultOpen for an initial expanded state. Use maxHeight to set the scroll limit.

PropTypeBehavior
labelstringOverride the readable accessible label.
classstringExtend the root styles. Your classes replace default classes through the local merge helper.
classesobjectStyle root, trigger, content, item, and label parts.
disabledbooleanDisable interaction. Preference controls also wait for the provider to mount.
animationTypeThemeAnimationTypeOverride the UI theme transition for this control. Defaults to the provider setting.
durationnumberUI theme transition duration in milliseconds. Defaults to the provider setting.
slideDirectionSlideDirectionValid only with animationType set to ThemeAnimationType.SLIDE. Other animation types do not accept this prop.
options{ value, label }[]Change palette labels. Values must already exist in the providerโ€™s colorThemes.
openbooleanControl whether the inline panel is expanded.
defaultOpenbooleanStart with the panel expanded. Defaults to false.
update:openeventReceive the next expanded state when the trigger is pressed.
direction'down' | 'up'Place choices below or above the trigger. Defaults to down. Use a bottom-anchored layout to keep an upward trigger in place.
maxHeightnumberLimit the scroll area in pixels. Defaults to 240 and never exceeds 60% of the viewport height.

Keyboard

KeyAction
Enter / SpaceExpand or collapse the focused trigger.
TabMove from the trigger into the expanded panel and its radio choices.
Arrow keysChange the selected radio within the group.
SpaceSelect the focused radio.

The panel stays open until you collapse it. Escape does not close an inline panel.

Accessibility

  • Keep the visible label, trigger name, and radio group name.
  • The trigger reports the expanded state. Hidden choices leave the tab order.
  • The disabled state prevents expansion and selection.
  • Keyboard controls use buttons and radio controls.
  • The choices form a radiogroup named by the visible label. Each choice is a button with the radio role, not a native radio input.

Theme behavior

The checked radio follows colorTheme. Choices come from colorThemes. Appearance does not change.

The selected radio sets the transition origin. The library performs the page transition. Omitted transition props keep the provider settings.

AI Agent notes

  • Import the local control. Use uitheme-web/react or uitheme-web/vue for the runtime.
  • Read the configured provider choices. Do not invent theme values.
  • Preserve the label, focus styles, selected state, disabled state, and scroll limit.
  • Keep the label below an upward trigger and above a downward trigger.
  • Reserve room for the full bounded panel, trigger, label, and frame padding.
  • Anchor upward controls at the bottom and downward controls at the top. Opening the panel must not shift the preview.
  • Use the separate floating selector in compact layouts.
  • Keep page transitions in the library. Do not add a local transition helper.
  • Check keyboard selection, preference persistence, and reduced motion in the running app.

Source

The CLI reuses the shared cn utility. It repairs a missing utility and checks an existing utility before offering a replacement. This control installs one main component file. It does not install the floating selector.

<script setup lang="ts">
import { computed, useId, useTemplateRef } from 'vue';
import { useUITheme, type ThemeControlTransitionProps } from 'uitheme-web/vue';
import { ChevronDownIcon } from '@lucide/vue';
import { cn } from '@/lib/utils';
import {
  Collapsible,
  CollapsiblePanel,
  CollapsibleTrigger,
} from '@ui-sdk/vue/collapsible';
import { Radio, RadioGroup, RadioIndicator } from '@ui-sdk/vue/radio';

const props = withDefaults(
  defineProps<
    ThemeControlTransitionProps & {
      label?: string;
      disabled?: boolean;
      open?: boolean;
      defaultOpen?: boolean;
      maxHeight?: number;
      direction?: 'up' | 'down';

      options?: readonly { value: string; label: string }[];
      class?: string;
      classes?: Partial<
        Record<'root' | 'trigger' | 'content' | 'item' | 'label', string>
      >;
    }
  >(),
  {
    label: 'Color theme',
    disabled: false,
    open: undefined,
    defaultOpen: false,
    maxHeight: 240,
    direction: 'down',
    duration: undefined,
    slideDirection: undefined,
    options: undefined,
    class: undefined,
    classes: undefined,
  }
);

const emit = defineEmits<{ 'update:open': [open: boolean] }>();

const state = useUITheme(() => ({
  animationType: props.animationType,
  duration: props.duration,
  slideDirection: props.slideDirection,
}));

const group = useTemplateRef<{ $el: HTMLElement }>('group');

const id = useId();

const options = computed(
  () =>
    props.options?.filter((option) =>
      state.colorThemes.includes(option.value)
    ) ??
    state.colorThemes.map((value) => ({
      value,
      label: value
        .replaceAll('-', ' ')
        .replace(/\b\w/g, (letter) => letter.toUpperCase()),
    }))
);

const selected = computed(() =>
  options.value.find((option) => option.value === state.colorTheme.value)
);

function select(value: string | null) {
  const next = state.colorThemes.find((option) => option === value);

  if (next)
    void state.switchColorTheme(next, {
      element:
        group.value?.$el
          .querySelectorAll('[data-slot="radio"]')
          .item(options.value.findIndex((option) => option.value === next))
          ?.closest('label') ?? null,
    });
}
</script>

<template>
  <div
    :data-direction="direction"
    :class="
      cn(
        'flex min-w-0 flex-col gap-2 data-[direction=up]:flex-col-reverse',
        props.classes?.root,
        props.class
      )
    "
  >
    <span
      :id="id"
      :class="cn('text-sm font-medium text-foreground', props.classes?.label)"
      >{{ label }}</span
    >
    <Collapsible
      :open="props.open"
      :default-open="defaultOpen"
      :disabled="disabled || !state.mounted.value"
      :data-direction="direction"
      class="flex flex-col data-[direction=up]:flex-col-reverse min-w-0 [--disclosure-padding:var(--spacing,0.25rem)] rounded-[calc(var(--radius)+var(--disclosure-padding))] bg-muted p-[var(--disclosure-padding)] ring-1 ring-inset ring-border"
      @update:open="emit('update:open', $event)"
    >
      <CollapsibleTrigger
        :id="`${id}-trigger`"
        :disabled="disabled || !state.mounted.value"
        :class="
          cn(
            'group flex min-h-10 w-full items-center justify-between gap-3 rounded-[var(--radius)] border border-border bg-card px-3 py-2 text-left text-sm font-medium text-card-foreground outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50',
            props.classes?.trigger
          )
        "
      >
        <span class="flex min-w-0 items-center gap-2"
          ><span class="sr-only">{{ label }}: </span>

          <slot name="value" :value="state.colorTheme.value"
            ><span class="truncate">{{
              selected?.label ?? state.colorTheme.value
            }}</span></slot
          >
        </span>
        <ChevronDownIcon
          aria-hidden="true"
          :class="
            cn(
              'size-4 shrink-0',
              direction === 'up'
                ? 'rotate-180 group-data-[open]:rotate-0'
                : 'group-data-[open]:rotate-180'
            )
          "
        />
      </CollapsibleTrigger>
      <CollapsiblePanel
        keep-mounted
        :data-direction="direction"
        role="region"
        :aria-labelledby="`${id}-trigger`"
        tabindex="0"
        :style="{ '--disclosure-max-height': `${maxHeight}px` }"
        :class="
          cn(
            'max-h-[min(var(--disclosure-max-height),60svh)] overflow-auto overscroll-contain rounded-b-[var(--radius)] data-[direction=up]:rounded-t-[var(--radius)] data-[direction=up]:rounded-b-none p-1 text-sm text-foreground outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring [scrollbar-width:thin] [scrollbar-color:var(--muted-foreground)_transparent]',
            props.classes?.content
          )
        "
      >
        <RadioGroup
          ref="group"
          :aria-labelledby="id"
          :value="state.colorTheme.value"
          :disabled="disabled || !state.mounted.value"
          @value-change="select"
        >
          <label
            v-for="option in options"
            :key="option.value"
            :class="
              cn(
                'flex cursor-pointer items-center gap-3 rounded-[max(0px,calc(var(--radius)-2px))] px-3 py-2 text-sm focus-within:ring-2 focus-within:ring-inset focus-within:ring-ring has-[[data-checked]]:bg-accent has-[[data-checked]]:text-accent-foreground has-[[data-disabled]]:cursor-not-allowed has-[[data-disabled]]:opacity-50',
                props.classes?.item
              )
            "
          >
            <Radio
              :value="option.value"
              class="flex size-3.5 shrink-0 items-center justify-center rounded-full border border-muted-foreground bg-background outline-none data-[checked]:border-primary data-[checked]:bg-primary"
            >
              <RadioIndicator
                class="size-1.5 rounded-full bg-primary-foreground"
              />
            </Radio>
            <slot name="option" :option="option">{{ option.label }}</slot>
          </label>
        </RadioGroup>
      </CollapsiblePanel>
    </Collapsible>
  </div>
</template>

Dependencies: @ui-sdk/vue, @ui-sdk/core, @lucide/vue

Customization

Use the classes prop to style the root, label, trigger, content, and items. The frame uses theme tokens. Its outer radius equals the trigger radius plus the frame padding. This control uses solid borders.

Set animationType and duration for the page transition. Set slideDirection only with animationType="slide". Keep enough space in the expansion direction.