Meter
Display a numeric value within a known range.
Demos
Size
Storage used64
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Value changes animate the bar width over 200ms. Reduced motion applies the new value immediately. Use Options and states to change value, bounds, and thresholds.
Installation
Complete the shared installation. Copy Meter.vue and index.ts into app/components/ui/meter/.
app/components/ui/meter/Meter.vue
<script setup lang="ts">
import { Meter as Primitive } from 'akaza-ui'
import { computed, useAttrs } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import { meterVariants, resolveMeterVariants, type MeterProps, type MeterSlots } from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<MeterProps>(), {
min: undefined,
max: undefined,
low: undefined,
high: undefined,
optimum: undefined,
label: undefined,
ariaLabel: undefined,
ariaLabelledby: undefined,
ariaValueText: undefined,
locale: undefined,
formatOptions: undefined,
getAriaValueText: undefined,
getValueLabel: undefined,
ui: undefined,
})
defineSlots<MeterSlots>()
const attrs = useAttrs()
const styles = computed(() => meterVariants(resolveMeterVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, ...native } = props
return native
})
</script>
<template>
<component :is="Primitive" v-bind="{ ...primitiveProps, ...attrs }" :ui="mergedUi">
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof MeterSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | required | Current value. |
min | number | 0 | Minimum value. |
max | number | 100 | Maximum value. |
low | number | — | Low threshold. Values below set data-akaza-state="low". |
high | number | — | High threshold. Values above set data-akaza-state="high". |
optimum | number | — | Preferred range hint. |
label | string | — | Visible label. Also labels the meter. |
ariaLabel | string | — | Accessible label when no visible label exists. |
ariaLabelledby | string | label id | Accessible label id. |
ariaValueText | string | — | Custom aria-valuetext. |
locale | Intl.LocalesArgument | runtime locale | Locale for formatted value. |
formatOptions | Intl.NumberFormatOptions | — | Number formatting options. |
getAriaValueText | (value, max, min) => string | undefined | — | Base-style function for aria-valuetext. |
getValueLabel | (formattedValue, value) => string | undefined | — | Function for aria-valuetext. |
ui | MeterUi | — | Classes for structural parts. |
Slots
| Slot | Props | Description |
|---|---|---|
label | value, formattedValue, state | Custom label. |
value | value, formattedValue, percentage, state | Custom formatted value. |
indicator | value, percentage, state | Custom indicator content. |