PXD
v0.2.1-dev

Effort Slider

Input to pick one level out of a configurable list, e.g. the reasoning effort of a model. Drag the thumb freely, it snaps to the closest level once the pointer is released.

Default

Medium

medium

<script setup>
import { ref } from 'vue'

const options = [
  { label: 'Low', value: 'low' },
  { label: 'Medium', value: 'medium' },
  { label: 'High', value: 'high' },
  { label: 'Max', value: 'max' },
]

const value = ref('medium')
</script>

<template>
  <PStack direction="vertical" gap="3">
    <PEffortSlider v-model="value" :options="options" style="width: 240px;" />
    <PText secondary>{{ value }}</PText>
  </PStack>
</template>

Plain strings

medium
<script setup>
import { ref } from 'vue'

const value = ref('medium')
</script>

<template>
  <PEffortSlider v-model="value" :options="['low', 'medium', 'high', 'max']" style="width: 240px;" />
</template>

Uncontrolled

Without v-model the slider keeps its own state, and default-value picks the starting level.

medium
<template>
  <PEffortSlider
    :options="['low', 'medium', 'high', 'max']"
    default-value="medium"
    style="width: 240px;"
  />
</template>

Colors

High
<script setup>
import { ref } from 'vue'

const options = [
  { label: 'Low', value: 'low' },
  { label: 'Medium', value: 'medium' },
  { label: 'High', value: 'high' },
  { label: 'Max', value: 'max' },
]

const colors = {
  0: 'var(--color-gray-700)',
  1: 'var(--color-blue-700)',
  2: 'var(--color-amber-700)',
  3: 'var(--color-red-700)',
}

const value = ref('high')
</script>

<template>
  <PEffortSlider v-model="value" :options="options" :colors="colors" style="width: 240px;" />
</template>

Gradient

A gradient colour is painted as the fill’s background image across the whole track, so dragging reveals the gradient instead of stretching it.

Max
<script setup>
import { ref } from 'vue'

const options = [
  { label: 'Low', value: 'low' },
  { label: 'Medium', value: 'medium' },
  { label: 'High', value: 'high' },
  { label: 'Max', value: 'max' },
]

const colors = {
  0: 'var(--color-blue-600)',
  1: 'var(--color-amber-700)',
  2: 'var(--color-red-800)',
  3: 'linear-gradient(90deg, var(--color-blue-600), var(--color-amber-700), var(--color-red-800))',
}

const value = ref('max')
</script>

<template>
  <PEffortSlider v-model="value" :options="options" :colors="colors" style="width: 240px;" />
</template>

Particles

particles flows small dots through the fill. The dots are clipped to the filled part of the track and hidden under prefers-reduced-motion.

high
<script setup>
import { ref } from 'vue'

const options = ['low', 'medium', 'high', 'max']
const value = ref('high')
</script>

<template>
  <PEffortSlider v-model="value" :options="options" particles style="width: 240px;" />
</template>

Sizes

low
low
low
<script setup>
import { ref } from 'vue'

const options = ['low', 'medium', 'high', 'max']
const value = ref('low')
</script>

<template>
  <PStack direction="vertical" gap="6">
    <PEffortSlider v-model="value" :options="options" size="sm" style="width: 240px;" />
    <PEffortSlider v-model="value" :options="options" style="width: 240px;" />
    <PEffortSlider v-model="value" :options="options" size="lg" style="width: 240px;" />
  </PStack>
</template>

Disabled

low
<script setup>
import { ref } from 'vue'

const options = ['low', 'medium', 'high', 'max']
const value = ref('low')
</script>

<template>
  <PEffortSlider v-model="value" :options="options" disabled style="width: 240px;" />
</template>

Props

NameTypeDefaultDescription
optionsArray<EffortOption | string>-Levels from low to high, a string is used as both label and value, value falls back to the option index
colorsRecord<string, string>-Fill colour keyed by level index, the fill takes the colour of the highest key at or below the current level, levels below the lowest key fall back to primary, a gradient value is applied as the fill’s background image across the whole track
particlesboolean-Flow small dots along the fill, hidden under prefers-reduced-motion
disabledboolean-Disable clicking, dragging and keyboard interaction
size'sm' | 'md' | 'lg'-Track and thumb size, falls back to the config provider
default-valuestring | number | null-Level an uncontrolled slider starts from
model-valuestring | number | null-Value of the selected level, snapped to the first option when it matches none, bound value wins over default-value

Events

NameTypeDescription
change(value: string | number, details: ChangeDetails) => voidEmitted when a drag or an arrow key settles on a new level.
update:model-value(value: string | number) => voidEmitted whenever the level changes, including when the initial value is snapped to the first option on mount.

Source

Source