All components outlinesubtlexssmmdlgxl
Meter
Static gauges for a value within a known range, like storage or quota, with the progress bar look.
Storage
12345678910111213141516171819import { Meter } from "#components/ui/base-ui/meter.tsx";import { indigoPalette } from "@stylexblocks/ui/themes/palettes.ts";
export function Example() { return ( // Base UI's Meter parts wearing the progress recipe; Root carries // role="meter" and the aria values, variant/size/shape resolve once on // Root and Track/Range (Base UI's Indicator) inherit them via context <Meter.Root value={64} variant="outline" size="md" shape="full" palette={indigoPalette}> <Meter.Label>Storage</Meter.Label> <Meter.ValueText /> <Meter.Track> <Meter.Range /> </Meter.Track> </Meter.Root> );}
// units: <Meter.Root value={3.2} max={8} format={{ style: "unit", unit: "gigabyte" }}>Variants
Storage
Storage
Sizes
Storage
Storage
Storage
Storage
Storage
Custom range and format
Set min/max for real units and format the value text; it also becomes the root's aria-valuetext.
Storage
1234567891011121314151617import { Meter } from "#components/ui/base-ui/meter.tsx";
export function Example() { return ( <Meter.Root value={3.2} max={8} format={{ style: "unit", unit: "gigabyte", maximumFractionDigits: 1 }} > <Meter.Label>Storage</Meter.Label> <Meter.ValueText /> <Meter.Track> <Meter.Range /> </Meter.Track> </Meter.Root> );}Thresholds
Pick the palette from the value to flag levels: healthy, getting full, critical.
API quota
API quota
API quota
12345678910111213141516import { Meter } from "#components/ui/base-ui/meter.tsx";import { amberPalette, greenPalette, redPalette } from "@stylexblocks/ui/themes/palettes.ts";
const paletteFor = (v: number) => (v >= 90 ? redPalette : v >= 70 ? amberPalette : greenPalette);
export function Example({ value }: { value: number }) { return ( <Meter.Root value={value} variant="subtle" shape="full" palette={paletteFor(value)}> <Meter.Label>API quota</Meter.Label> <Meter.ValueText /> <Meter.Track> <Meter.Range /> </Meter.Track> </Meter.Root> );}Install
1npx stylexblocks add meterSource
components/ui/base-ui/meter.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189import { Meter as BaseMeter } from "@base-ui/react/meter";import { createSlotRecipeContext } from "#lib/base-ui/create-slot-recipe-context.tsx";import { defineSlotRecipe, type SlotRecipeVariants, type WithStyleOverrides,} from "#lib/recipe-props.ts";import * as stylex from "@stylexjs/stylex";import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'import { durations } from '@stylexblocks/ui/tokens/durations.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 { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
const progressRoot = stylex.create({ base: { fontSize: fontSizes.sm, lineHeight: lineHeights.sm, position: 'relative', },})
const progressTrack = stylex.create({ base: { overflow: 'hidden', position: 'relative', },})
const progressTrackSizes = stylex.create({ xs: { height: sizes._1_5, }, sm: { height: sizes._2, }, md: { height: sizes._2_5, }, lg: { height: sizes._3, }, xl: { height: sizes._4, },})
const progressTrackVariants = stylex.create({ outline: { boxShadow: semanticShadows.inset, backgroundColor: semanticColors.bgSubtle, }, subtle: { backgroundColor: colorPalette.muted, },})
const progressTrackShapes = stylex.create({ rounded: { borderRadius: semanticRadii.control, }, full: { borderRadius: radii.full, },})
const progressRange = stylex.create({ base: { display: 'flex', alignItems: 'center', justifyContent: 'center', transitionProperty: 'width, height', transitionDuration: durations.slow, height: '100%', backgroundColor: 'var(--track-color)', },})
const progressRangeVariants = stylex.create({ outline: { backgroundColor: colorPalette.solid, }, subtle: { backgroundColor: `color-mix(in oklch, ${colorPalette.solid} 72%, transparent)`, },})
const progressRangeStripeds = stylex.create({ true: { backgroundImage: 'linear-gradient(45deg, var(--stripe-color) 25%, transparent 25%, transparent 50%, var(--stripe-color) 50%, var(--stripe-color) 75%, transparent 75%, transparent)', backgroundSize: 'var(--stripe-size) var(--stripe-size)', '--stripe-size': '1rem', '--stripe-color': 'rgba(255, 255, 255, 0.3)', },})
const progressRangeAnimateds = stylex.create({ true: { '--animate-from': 'var(--stripe-size)', animationName: 'bg-position', animationDuration: '1s', animationTimingFunction: 'linear', animationIterationCount: 'infinite', },})
const progressLabel = stylex.create({ base: { display: 'inline-flex', fontWeight: fontWeights.medium, },})
const progressValueText = stylex.create({ base: { fontSize: fontSizes.xs, lineHeight: 1, fontWeight: fontWeights.medium, },})
export type ProgressVariant = keyof typeof progressTrackVariants
export type ProgressShape = keyof typeof progressTrackShapes
export type ProgressStriped = keyof typeof progressRangeStripeds
export type ProgressAnimated = keyof typeof progressRangeAnimateds
export type ProgressSize = keyof typeof progressTrackSizes
// A meter is a static gauge (disk usage, quota, strength), not a task in// flight, but it looks like a progress bar: reuse the progress recipe.const meterSlotRecipe = defineSlotRecipe({ slots: { root: { styles: progressRoot }, track: { styles: progressTrack, sizes: progressTrackSizes, variants: progressTrackVariants, shapes: progressTrackShapes, }, range: { styles: progressRange, variants: progressRangeVariants, }, label: { styles: progressLabel }, valueText: { styles: progressValueText }, }, defaultVariants: { variant: "outline", size: "md", shape: "rounded" },});
const { withProvider, withContext } = createSlotRecipeContext(meterSlotRecipe);
type MeterVariants = SlotRecipeVariants<typeof meterSlotRecipe>;
/** * Meter — Base UI's Meter parts wearing the progress recipe. Root renders * `role="meter"` with `aria-valuenow/min/max/text` and links the Label; * `variant`, `size` and `shape` resolve once on Root and Track/Range * inherit them via context. `format` / `locale` drive the ValueText (a * percentage by default). Every part composes via `render`. */export type MeterRootProps = WithStyleOverrides< React.ComponentProps<typeof BaseMeter.Root>> & Partial<MeterVariants>;
const MeterRoot = withProvider(BaseMeter.Root, "root", "MeterRoot");
function Root(props: MeterRootProps) { return <MeterRoot {...(props as React.ComponentProps<typeof MeterRoot>)} />;}Root.displayName = "MeterRoot";
export const Meter = { Root, Label: withContext(BaseMeter.Label, "label", "MeterLabel"), Track: withContext(BaseMeter.Track, "track", "MeterTrack"), Range: withContext(BaseMeter.Indicator, "range", "MeterRange"), ValueText: withContext(BaseMeter.Value, "valueText", "MeterValueText"),};