All components outlinesolidsmmdlg
Angle Slider
Circular dial for picking an angle, with a value arc, draggable thumb and optional markers.
135°
12345678910111213141516171819202122232425import { AngleSlider } from "#components/ui/ark-ui/angle-slider.tsx";import { indigoPalette } from "@stylexblocks/ui/themes/palettes.ts";
export function Example() { return ( // variant/size resolve once on Root; Control renders Thumb + ValueText // by default — pass children to add markers <AngleSlider.Root defaultValue={45} variant="outline" size="md" palette={indigoPalette}> <AngleSlider.Label>Rotation</AngleSlider.Label> <AngleSlider.Control> <AngleSlider.MarkerGroup> {[0, 90, 180, 270].map((value) => ( <AngleSlider.Marker key={value} value={value} /> ))} </AngleSlider.MarkerGroup> <AngleSlider.Thumb /> <AngleSlider.ValueText /> </AngleSlider.Control> <AngleSlider.HiddenInput /> </AngleSlider.Root> );}
// controlled: <AngleSlider.Root value={angle} onValueChange={(d) => setAngle(d.value)}>// step: <AngleSlider.Root step={15}>Variants
135°
135°
Sizes
135°
135°
135°
Markers and steps
Markers tick the ring and light up once the value passes them; step={45} snaps drags and key presses to the markers. Drag anywhere on the dial, or focus the thumb and use the arrow keys (Shift for 10x steps), Home and End.
135°
Controlled
value and onValueChange drive anything that takes an angle, here a gradient direction.
120°
Disabled
The arc and thumb mute and the dial ignores pointer and keyboard input.
135°
Install
1npx stylexblocks add angle-sliderSource
components/ui/ark-ui/angle-slider.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302import { AngleSlider as ArkAngleSlider, useAngleSliderContext,} from "@ark-ui/react/angle-slider";import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";import { defineSlotRecipe } from "#lib/recipe-props.ts";import * as stylex from "@stylexjs/stylex";import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'import { radii } from '@stylexblocks/ui/tokens/radii.stylex.ts'import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
const angleSliderRoot = stylex.create({ base: { display: 'inline-flex', flexDirection: 'column', alignItems: 'center', gap: spacing._2, fontSize: fontSizes.sm, position: 'relative', isolation: 'isolate', touchAction: 'none', },})
const angleSliderRootSizes = stylex.create({ sm: { '--angle-slider-size': sizes._24, '--angle-slider-track-size': sizes._1_5, '--angle-slider-thumb-size': sizes._4, '--angle-slider-marker-size': sizes._1, '--angle-slider-value-font-size': fontSizes.md, }, md: { '--angle-slider-size': sizes._32, '--angle-slider-track-size': sizes._2, '--angle-slider-thumb-size': sizes._5, '--angle-slider-marker-size': sizes._1, '--angle-slider-value-font-size': fontSizes.xl, }, lg: { '--angle-slider-size': sizes._40, '--angle-slider-track-size': sizes._2_5, '--angle-slider-thumb-size': sizes._6, '--angle-slider-marker-size': sizes._1_5, '--angle-slider-value-font-size': fontSizes._2xl, },})
const angleSliderLabel = stylex.create({ base: { fontSize: fontSizes.sm, lineHeight: lineHeights.sm, fontWeight: fontWeights.medium, userSelect: 'none', opacity: { default: null, ':is([data-disabled])': 0.5, }, },})
/** * The dial. The ring track and the value arc are painted on `::before` * (a conic gradient up to `--angle`, masked to a ring), so the thumb and * the centered value text stay unmasked. */const angleSliderControl = stylex.create({ base: { position: 'relative', flexShrink: 0, width: 'var(--angle-slider-size)', height: 'var(--angle-slider-size)', borderRadius: radii.full, touchAction: 'none', userSelect: 'none', cursor: { default: 'pointer', ':is([data-disabled])': 'not-allowed', }, '--angle-slider-range': { default: colorPalette.solid, ':is([data-disabled])': semanticColors.borderEmphasized, }, '::before': { content: '""', position: 'absolute', inset: 0, borderRadius: 'inherit', backgroundImage: 'conic-gradient(var(--angle-slider-range) var(--angle, 0deg), var(--angle-slider-track) 0)', maskImage: 'radial-gradient(farthest-side, transparent calc(100% - var(--angle-slider-track-size) - 0.5px), #000 calc(100% - var(--angle-slider-track-size)))', pointerEvents: 'none', }, },})
const angleSliderControlVariants = stylex.create({ outline: { '--angle-slider-track': { default: `color-mix(in oklch, ${semanticColors.bgEmphasized} 72%, transparent)`, ':is([data-disabled])': semanticColors.bgMuted, }, }, solid: { '--angle-slider-track': { default: colorPalette.subtle, ':is([data-disabled])': semanticColors.bgMuted, }, },})
/** * A full-size layer the engine rotates by `--angle`; the knob is its * `::before`, sitting on the ring at 12 o'clock. Pointer input goes to the * control underneath. */const angleSliderThumb = stylex.create({ base: { position: 'absolute', inset: 0, borderRadius: radii.full, pointerEvents: 'none', outline: 'none', zIndex: 2, '--angle-slider-thumb-ring': { default: '0 0 0 0 transparent', ':focus-visible': `0 0 0 2px ${semanticColors.bg}, 0 0 0 4px ${colorPalette.focusRing}`, }, '::before': { content: '""', position: 'absolute', boxSizing: 'border-box', top: 'calc(var(--angle-slider-track-size) / 2)', left: '50%', width: 'var(--angle-slider-thumb-size)', height: 'var(--angle-slider-thumb-size)', translate: '-50% -50%', borderRadius: radii.full, backgroundColor: 'var(--angle-slider-thumb-bg)', borderStyle: 'solid', borderWidth: 'var(--angle-slider-thumb-border-width)', borderColor: 'var(--angle-slider-thumb-border)', boxShadow: `var(--angle-slider-thumb-ring), ${semanticShadows.xs}`, }, },})
const angleSliderThumbVariants = stylex.create({ outline: { '--angle-slider-thumb-border-width': '2px', '--angle-slider-thumb-border': { default: colorPalette.solid, ':is([data-disabled])': semanticColors.borderEmphasized, }, '--angle-slider-thumb-bg': { default: semanticColors.bg, ':is([data-disabled])': semanticColors.borderEmphasized, }, }, solid: { '--angle-slider-thumb-border-width': '2px', '--angle-slider-thumb-border': semanticColors.bg, '--angle-slider-thumb-bg': { default: colorPalette.solid, ':is([data-disabled])': semanticColors.borderEmphasized, }, },})
/** Centered inside the control. */const angleSliderValueText = stylex.create({ base: { position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', pointerEvents: 'none', fontSize: 'var(--angle-slider-value-font-size)', lineHeight: 1, fontWeight: fontWeights.semibold, fontVariantNumeric: 'tabular-nums', color: semanticColors.fg, },})
const angleSliderMarkerGroup = stylex.create({ base: { position: 'absolute', inset: 0, pointerEvents: 'none', zIndex: 1, },})
/** A full-size layer the engine rotates to the marker's angle; the tick is `::before`. */const angleSliderMarker = stylex.create({ base: { position: 'absolute', inset: 0, '--angle-slider-marker-color': { default: semanticColors.fgSubtle, ':is([data-state="under-value"], [data-state="at-value"]):not([data-disabled])': colorPalette.contrast, ':is([data-disabled])': semanticColors.fgMuted, }, '::before': { content: '""', position: 'absolute', top: 'calc(var(--angle-slider-track-size) / 2)', left: '50%', width: 'var(--angle-slider-marker-size)', height: 'var(--angle-slider-marker-size)', translate: '-50% -50%', borderRadius: radii.full, backgroundColor: 'var(--angle-slider-marker-color)', }, },})
export type AngleSliderSize = keyof typeof angleSliderRootSizes
export type AngleSliderVariant = keyof typeof angleSliderControlVariants
const angleSliderRecipe = defineSlotRecipe({ slots: { root: { styles: angleSliderRoot, sizes: angleSliderRootSizes }, label: { styles: angleSliderLabel }, control: { styles: angleSliderControl, variants: angleSliderControlVariants }, thumb: { styles: angleSliderThumb, variants: angleSliderThumbVariants }, valueText: { styles: angleSliderValueText }, markerGroup: { styles: angleSliderMarkerGroup }, marker: { styles: angleSliderMarker }, }, defaultVariants: { size: "md", variant: "outline" },});
const { withProvider, withContext } = createSlotRecipeContext(angleSliderRecipe);
const Thumb = withContext(ArkAngleSlider.Thumb, "thumb", "AngleSliderThumb");// The machine's `valueAsDegree` reads "45deg"; show a degree sign instead.function ValueTextNode({ children, ...props}: React.ComponentProps<typeof ArkAngleSlider.ValueText>) { const api = useAngleSliderContext(); return ( <ArkAngleSlider.ValueText {...props}>{children ?? `${api.value}°`}</ArkAngleSlider.ValueText> );}
const ValueText = withContext(ValueTextNode, "valueText", "AngleSliderValueText");
function ControlNode({ children, ...props}: React.ComponentProps<typeof ArkAngleSlider.Control>) { return ( <ArkAngleSlider.Control {...props}> {children ?? ( <> <Thumb /> <ValueText /> </> )} </ArkAngleSlider.Control> );}
/** * AngleSlider — Ark UI's angle-slider machine (0–359°) wearing the * angle-slider slot recipe. `<AngleSlider.Root variant size>` resolves the * recipe once; every part inherits it through context. The control paints a * ring track with a conic value arc up to the machine's `--angle`; the thumb * is a full-size layer the machine rotates, with its knob on the ring. * Control renders Thumb + ValueText by default; ValueText centers inside the * dial. Markers are ticks on the ring. */export const AngleSlider = { Root: withProvider(ArkAngleSlider.Root, "root", "AngleSliderRoot"), Label: withContext(ArkAngleSlider.Label, "label", "AngleSliderLabel"), Control: withContext(ControlNode, "control", "AngleSliderControl"), Thumb, ValueText, MarkerGroup: withContext(ArkAngleSlider.MarkerGroup, "markerGroup", "AngleSliderMarkerGroup"), Marker: withContext(ArkAngleSlider.Marker, "marker", "AngleSliderMarker"), HiddenInput: ArkAngleSlider.HiddenInput, Context: ArkAngleSlider.Context,};
export type AngleSliderRootProps = React.ComponentProps<typeof AngleSlider.Root>;export type AngleSliderControlProps = React.ComponentProps<typeof AngleSlider.Control>;export type AngleSliderThumbProps = React.ComponentProps<typeof AngleSlider.Thumb>;export type AngleSliderMarkerProps = React.ComponentProps<typeof AngleSlider.Marker>;