Progress
How far work has gone, as a bar or a ring, sliding or turning while the end is unknown.
Previews are drawn in the theme you made.
Edit itBasic #
import { Option } from 'effect'
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
// A value and a `max` make a bar that fills; `Option.none()` is a bar that
// does not know yet, which says "busy" to a screen reader and slides to the
// eye. `valueText` is what is announced beside the percentage.
export default example({
title: 'Basic',
slots: ProgressSlots,
recipe: Recipes.Progress,
view: ({ style, h }) =>
row(h, [
Progress.view(
{
id: 'upload',
label: 'Uploading',
value: Option.some(120),
max: 200,
valueText: (value, max) => `${value} of ${max} MB`,
style,
},
h,
),
Progress.view({ id: 'prepare', label: 'Preparing', value: Option.none(), style }, h),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
With its value #
import { Option } from 'effect'
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { stack } from '../../snippets/layout.js'
// `showValue` draws the value beside the label: the percentage, or the
// `valueText` when there is one.
export default example({
title: 'With its value',
slots: ProgressSlots,
recipe: Recipes.Progress,
view: ({ style, h }) =>
stack(h, [
Progress.view(
{ id: 'copy', label: 'Copying files', value: Option.some(64), showValue: true, style },
h,
),
Progress.view(
{
id: 'upload',
label: 'Uploading',
value: Option.some(120),
max: 200,
valueText: (value, max) => `${value} of ${max} MB`,
showValue: true,
style,
},
h,
),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Stacked #
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// A list of sections in place of one value: each part takes its tone, and
// the bar draws them end to end.
export default example({
title: 'Stacked',
slots: ProgressSlots,
recipe: Recipes.Progress,
pins: { shape: 'bar' },
view: ({ style, h }) =>
Progress.view(
{
id: 'storage',
label: 'Storage',
value: [
{ label: 'Photos', value: 38, tone: 'accent' },
{ label: 'Mail', value: 21, tone: 'success' },
{ label: 'Backups', value: 14, tone: 'warning' },
],
showValue: true,
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Buffered #
import { Option } from 'effect'
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// What has loaded ahead of what has played: `buffer` draws a fainter fill
// under the value.
export default example({
title: 'Buffered',
slots: ProgressSlots,
recipe: Recipes.Progress,
pins: { shape: 'bar' },
view: ({ style, h }) =>
Progress.view(
{
id: 'video',
label: 'Played',
value: Option.some(35),
buffer: 70,
valueText: '1:45 of 5:00, loaded to 3:30',
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Striped and moving #
import { Option } from 'effect'
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// `stripes: 'moving'` is a recipe value, so this page pins it; the bands
// hold still under reduced motion.
export default example({
title: 'Striped and moving',
slots: ProgressSlots,
recipe: Recipes.Progress,
pins: { shape: 'bar', stripes: 'moving', size: 'lg' },
view: ({ style, h }) =>
Progress.view(
{ id: 'sync', label: 'Syncing', value: Option.some(55), showValue: true, style },
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
A ring with its value #
import { Option } from 'effect'
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
// The same options draw a ring: the arc is the value, shown inside it, and a
// value not known yet turns a quarter arc.
export default example({
title: 'A ring with its value',
slots: ProgressSlots,
recipe: Recipes.Progress,
pins: { shape: 'ring', size: 'lg' },
view: ({ style, h }) =>
row(h, [
Progress.view(
{ id: 'done', label: 'Done', value: Option.some(72), showValue: true, style },
h,
),
Progress.view({ id: 'waiting', label: 'Waiting', value: Option.none(), style }, h),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Steps as progress #
import { Option } from 'effect'
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// The steps done of the steps there are, the track cut into one segment each.
export default example({
title: 'Steps as progress',
slots: ProgressSlots,
recipe: Recipes.Progress,
pins: { shape: 'bar' },
view: ({ style, h }) =>
Progress.view(
{
id: 'setup',
label: 'Setting up',
value: Option.some(2),
max: 4,
segments: 4,
valueText: (value, max) => `Step ${value} of ${max}`,
showValue: true,
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Tones #
import { Option } from 'effect'
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { stack } from '../../snippets/layout.js'
// A tone colours the fill by what the work means: `success` for done,
// `warning` for slow, `danger` for failed. The tone is a recipe selection,
// so each bar is a style of its own.
const Success = Recipes.Progress.style({ tone: 'success' })
const Warning = Recipes.Progress.style({ tone: 'warning' })
const Danger = Recipes.Progress.style({ tone: 'danger' })
export default example({
title: 'Tones',
slots: ProgressSlots,
recipe: Recipes.Progress,
pins: { shape: 'bar' },
view: ({ h }) =>
stack(h, [
Progress.view(
{ id: 'built', label: 'Built', value: Option.some(100), showValue: true, style: Success },
h,
),
Progress.view(
{ id: 'tested', label: 'Tests', value: Option.some(40), showValue: true, style: Warning },
h,
),
Progress.view(
{
id: 'deployed',
label: 'Deploy failed',
value: Option.some(72),
showValue: true,
style: Danger,
},
h,
),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
A size of your own #
import { Style } from 'foldkit-mixins'
import { Option } from 'effect'
import { Progress, ProgressSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// The shipped sizes stop at `lg`. `add` gives the recipe one more: the track
// reads its thickness from the custom property the sizes set.
const Progresses = Recipes.Progress.add({
size: { xl: { root: Style.self({ '--_fk-progress-thick': '1.25rem' }) } },
})
export default example({
title: 'A size of your own',
slots: ProgressSlots,
recipe: Progresses,
pins: { shape: 'bar', size: 'xl' },
view: ({ style, h }) =>
Progress.view(
{ id: 'import', label: 'Importing', value: Option.some(35), showValue: true, style },
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Usage
Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.