Meter
A meter element for displaying a value within a range.
Storage Used
24%
View source
import * as Meter from "@danielfrg/solid-ui/meter"
import styles from "./index.module.css"
export function DemoMeterHero() {
return (
<Meter.Root class={styles.meter} value={24}>
<Meter.Label class={styles.label}>Storage Used</Meter.Label>
<Meter.ValueLabel class={styles.value} />
<Meter.Track class={styles.track}>
<Meter.Fill class={styles.fill} />
</Meter.Track>
</Meter.Root>
)
}.meter {
box-sizing: border-box;
display: grid;
grid-template-columns: 1fr 1fr;
width: 12rem;
}
.label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 500;
color: var(--color-gray-900);
}
.value {
grid-column-start: 2;
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--color-gray-900);
text-align: right;
}
.track {
grid-column: 1 / 3;
overflow: hidden;
background-color: var(--color-gray-100);
box-shadow: inset 0 0 0 1px var(--color-gray-200);
height: 0.5rem;
}
.fill {
height: 100%;
width: var(--kb-meter-fill-width);
background-color: var(--color-gray-500);
transition: width 500ms;
}:root {
--color-blue: oklch(45% 50% 264deg);
--color-red: oklch(50% 55% 31deg);
--color-gray-50: oklch(98% 0.25% 264deg);
--color-gray-100: oklch(12% 9.5% 264deg / 5%);
--color-gray-200: oklch(12% 9% 264deg / 7%);
--color-gray-300: oklch(12% 8.5% 264deg / 17%);
--color-gray-400: oklch(12% 8% 264deg / 38%);
--color-gray-500: oklch(12% 7.5% 264deg / 50%);
--color-gray-600: oklch(12% 7% 264deg / 67%);
--color-gray-700: oklch(12% 6% 264deg / 77%);
--color-gray-800: oklch(12% 5% 264deg / 85%);
--color-gray-900: oklch(12% 5% 264deg / 90%);
--color-gray-950: oklch(12% 5% 264deg / 95%);
}
@media (prefers-color-scheme: dark) {
:root {
--color-blue: oklch(69% 50% 264deg);
--color-red: oklch(80% 55% 31deg);
--color-gray-50: oklch(17% 0.25% 264deg);
--color-gray-100: oklch(28% 0.75% 264deg / 65%);
--color-gray-200: oklch(29% 0.75% 264deg / 80%);
--color-gray-300: oklch(35% 0.75% 264deg / 80%);
--color-gray-400: oklch(47% 0.875% 264deg / 80%);
--color-gray-500: oklch(64% 1% 264deg / 80%);
--color-gray-600: oklch(82% 1% 264deg / 80%);
--color-gray-700: oklch(92% 1.125% 264deg / 80%);
--color-gray-800: oklch(93% 0.875% 264deg / 85%);
--color-gray-900: oklch(95% 0.5% 264deg / 90%);
--color-gray-950: oklch(94% 0.375% 264deg / 95%);
}
}Examples
Custom value scale
Use minValue and maxValue to define a custom range for the meter.
Disk Space Usage
40%
View source
import * as Meter from "@danielfrg/solid-ui/meter"
import styles from "./index.module.css"
export function DemoMeterCustomValueScale() {
return (
<Meter.Root class={styles.meter} value={100} minValue={0} maxValue={250}>
<Meter.Label class={styles.label}>Disk Space Usage</Meter.Label>
<Meter.ValueLabel class={styles.value} />
<Meter.Track class={styles.track}>
<Meter.Fill class={styles.fill} />
</Meter.Track>
</Meter.Root>
)
}.meter {
box-sizing: border-box;
display: grid;
grid-template-columns: 1fr 1fr;
width: 12rem;
}
.label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 500;
color: var(--color-gray-900);
}
.value {
grid-column-start: 2;
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--color-gray-900);
text-align: right;
}
.track {
grid-column: 1 / 3;
overflow: hidden;
background-color: var(--color-gray-100);
box-shadow: inset 0 0 0 1px var(--color-gray-200);
height: 0.5rem;
}
.fill {
height: 100%;
width: var(--kb-meter-fill-width);
background-color: var(--color-gray-500);
transition: width 500ms;
}:root {
--color-blue: oklch(45% 50% 264deg);
--color-red: oklch(50% 55% 31deg);
--color-gray-50: oklch(98% 0.25% 264deg);
--color-gray-100: oklch(12% 9.5% 264deg / 5%);
--color-gray-200: oklch(12% 9% 264deg / 7%);
--color-gray-300: oklch(12% 8.5% 264deg / 17%);
--color-gray-400: oklch(12% 8% 264deg / 38%);
--color-gray-500: oklch(12% 7.5% 264deg / 50%);
--color-gray-600: oklch(12% 7% 264deg / 67%);
--color-gray-700: oklch(12% 6% 264deg / 77%);
--color-gray-800: oklch(12% 5% 264deg / 85%);
--color-gray-900: oklch(12% 5% 264deg / 90%);
--color-gray-950: oklch(12% 5% 264deg / 95%);
}
@media (prefers-color-scheme: dark) {
:root {
--color-blue: oklch(69% 50% 264deg);
--color-red: oklch(80% 55% 31deg);
--color-gray-50: oklch(17% 0.25% 264deg);
--color-gray-100: oklch(28% 0.75% 264deg / 65%);
--color-gray-200: oklch(29% 0.75% 264deg / 80%);
--color-gray-300: oklch(35% 0.75% 264deg / 80%);
--color-gray-400: oklch(47% 0.875% 264deg / 80%);
--color-gray-500: oklch(64% 1% 264deg / 80%);
--color-gray-600: oklch(82% 1% 264deg / 80%);
--color-gray-700: oklch(92% 1.125% 264deg / 80%);
--color-gray-800: oklch(93% 0.875% 264deg / 85%);
--color-gray-900: oklch(95% 0.5% 264deg / 90%);
--color-gray-950: oklch(94% 0.375% 264deg / 95%);
}
}Custom value label
Use getValueLabel to format the displayed value text.
Storage
3 of 10 GB used
View source
import * as Meter from "@danielfrg/solid-ui/meter"
import styles from "./index.module.css"
export function DemoMeterCustomValueLabel() {
return (
<Meter.Root
class={styles.meter}
value={3}
minValue={0}
maxValue={10}
getValueLabel={({ value, max }) => `${value} of ${max} GB used`}
>
<Meter.Label class={styles.label}>Storage</Meter.Label>
<Meter.ValueLabel class={styles.value} />
<Meter.Track class={styles.track}>
<Meter.Fill class={styles.fill} />
</Meter.Track>
</Meter.Root>
)
}.meter {
box-sizing: border-box;
display: grid;
grid-template-columns: 1fr 1fr;
width: 12rem;
}
.label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 500;
color: var(--color-gray-900);
}
.value {
grid-column-start: 2;
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--color-gray-900);
text-align: right;
}
.track {
grid-column: 1 / 3;
overflow: hidden;
background-color: var(--color-gray-100);
box-shadow: inset 0 0 0 1px var(--color-gray-200);
height: 0.5rem;
}
.fill {
height: 100%;
width: var(--kb-meter-fill-width);
background-color: var(--color-gray-500);
transition: width 500ms;
}:root {
--color-blue: oklch(45% 50% 264deg);
--color-red: oklch(50% 55% 31deg);
--color-gray-50: oklch(98% 0.25% 264deg);
--color-gray-100: oklch(12% 9.5% 264deg / 5%);
--color-gray-200: oklch(12% 9% 264deg / 7%);
--color-gray-300: oklch(12% 8.5% 264deg / 17%);
--color-gray-400: oklch(12% 8% 264deg / 38%);
--color-gray-500: oklch(12% 7.5% 264deg / 50%);
--color-gray-600: oklch(12% 7% 264deg / 67%);
--color-gray-700: oklch(12% 6% 264deg / 77%);
--color-gray-800: oklch(12% 5% 264deg / 85%);
--color-gray-900: oklch(12% 5% 264deg / 90%);
--color-gray-950: oklch(12% 5% 264deg / 95%);
}
@media (prefers-color-scheme: dark) {
:root {
--color-blue: oklch(69% 50% 264deg);
--color-red: oklch(80% 55% 31deg);
--color-gray-50: oklch(17% 0.25% 264deg);
--color-gray-100: oklch(28% 0.75% 264deg / 65%);
--color-gray-200: oklch(29% 0.75% 264deg / 80%);
--color-gray-300: oklch(35% 0.75% 264deg / 80%);
--color-gray-400: oklch(47% 0.875% 264deg / 80%);
--color-gray-500: oklch(64% 1% 264deg / 80%);
--color-gray-600: oklch(82% 1% 264deg / 80%);
--color-gray-700: oklch(92% 1.125% 264deg / 80%);
--color-gray-800: oklch(93% 0.875% 264deg / 85%);
--color-gray-900: oklch(95% 0.5% 264deg / 90%);
--color-gray-950: oklch(94% 0.375% 264deg / 95%);
}
}