Badge
A status pill toned by the value it carries.
Previews are drawn in the theme you made.
Edit itTones #
import { Badge, BadgeSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
// A tone is a word the badge carries, not a recipe axis: one style serves
// every tone at once. A badge with none keeps the quiet base.
export default example({
title: 'Tones',
slots: BadgeSlots,
recipe: Recipes.Badge,
view: ({ style, h }) =>
row(h, [
Badge.view({ text: 'Draft', style }, h),
Badge.view({ text: 'Pro', tone: 'accent', style }, h),
Badge.view({ text: 'Neutral', tone: 'neutral', style }, h),
Badge.view({ text: 'Info', tone: 'info', style }, h),
Badge.view({ text: 'Live', tone: 'success', style }, h),
Badge.view({ text: 'Review', tone: 'warning', style }, h),
Badge.view({ text: 'Failed', tone: 'danger', style }, h),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Sizes #
import { Badge, BadgeSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
// `size` is a recipe axis, so each step is a style of its own; the same
// call draws all three.
const Small = Recipes.Badge.style({ size: 'sm' })
const Medium = Recipes.Badge.style({ size: 'md' })
const Large = Recipes.Badge.style({ size: 'lg' })
export default example({
title: 'Sizes',
slots: BadgeSlots,
recipe: Recipes.Badge,
pins: { appearance: 'tinted' },
view: ({ h }) =>
row(h, [
Badge.view({ text: 'Small', tone: 'info', style: Small }, h),
Badge.view({ text: 'Medium', tone: 'info', style: Medium }, h),
Badge.view({ text: 'Large', tone: 'info', style: Large }, h),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
With an icon #
import { Badge, BadgeSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { outline } from '../../snippets/icon.js'
import { row } from '../../snippets/layout.js'
// An `icon` stands before the text in a slot of its own, hidden from
// assistive technology: the text is the badge's name.
export default example({
title: 'With an icon',
slots: BadgeSlots,
recipe: Recipes.Badge,
view: ({ style, h }) =>
row(h, [
Badge.view(
{ text: 'Verified', tone: 'success', icon: outline(h, 'M3 8.5l3 3 7-7'), style },
h,
),
Badge.view(
{ text: 'Needs review', tone: 'warning', icon: outline(h, 'M8 3v6M8 12v.5'), style },
h,
),
Badge.view(
{
text: 'Starred',
tone: 'accent',
icon: outline(h, 'M8 2l1.8 4 4.2.4-3.2 2.8 1 4.3L8 11.4 4.2 13.5l1-4.3L2 6.4 6.2 6z'),
style,
},
h,
),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Dismissible #
3 filters on
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { modifyFields } from 'foldkit/struct'
import { Badge, BadgeSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { note, row, stack } from '../../snippets/layout.js'
const Model = Schema.Struct({ filters: Schema.Array(Schema.String) })
const Message = defineMessageUnion({ Dismissed: { filter: Schema.String } })
// `onDismiss` draws a button inside the pill, named by `words.dismiss` with
// the badge's text filled in. Whether the filter stays is the application's:
// the next draw leaves the badge out.
export default example({
title: 'Dismissible',
slots: BadgeSlots,
recipe: Recipes.Badge,
state: {
Model,
Message,
init: () => ({ model: { filters: ['Design', 'Open', 'Assigned to me'] } }),
update: (model, { filter }) => ({
model: modifyFields(model, { filters: filters => filters.filter(each => each !== filter) }),
}),
},
view: ({ style, model, onMessage, h }) =>
stack(h, [
row(
h,
model.filters.map(filter =>
Badge.view(
{ text: filter, onDismiss: onMessage(Message.Dismissed({ filter })), style },
h,
),
),
),
note(h, [`${model.filters.length} filters on`]),
]),
})In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.
As a link #
import { Badge, BadgeSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
// `href` draws the pill as a link, with the pointer, hover and focus ring of
// one. `external` opens a new tab and says so to a screen reader; a link
// holds no dismiss button.
export default example({
title: 'As a link',
slots: BadgeSlots,
recipe: Recipes.Badge,
view: ({ style, h }) =>
row(h, [
Badge.view({ text: 'Changelog', tone: 'accent', href: '#', style }, h),
Badge.view(
{ text: 'Docs', tone: 'info', href: 'https://example.com', external: true, style },
h,
),
]),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Your own states #
import { Badge, BadgeSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
// A badge whose words are the application's own (a deployment's state) maps
// them to tones with `badgeTones`, through `extend`. A word the map leaves
// out keeps the base.
const States = Recipes.Badge.extend({
base: {
badge: Recipes.badgeTones('data-tone', {
live: 'success',
deploying: 'warning',
down: 'danger',
queued: 'info',
}),
},
})
export default example({
title: 'Your own states',
slots: BadgeSlots,
recipe: States,
view: ({ style, h }) =>
row(h, [
Badge.view({ text: 'Live', tone: 'live', style }, h),
Badge.view({ text: 'Deploying', tone: 'deploying', style }, h),
Badge.view({ text: 'Down', tone: 'down', style }, h),
Badge.view({ text: 'Queued', tone: 'queued', style }, h),
Badge.view({ text: 'Archived', style }, 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 { Badge, BadgeSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { row } from '../../snippets/layout.js'
// The shipped sizes stop at `lg`. `add` gives the recipe one more, and its
// appearances and tones still apply; a value an axis already has is refused.
const Badges = Recipes.Badge.add({
size: { xl: { badge: Style.self({ fontSize: '1.25rem', paddingInline: '1rem' }) } },
})
export default example({
title: 'A size of your own',
slots: BadgeSlots,
recipe: Badges,
pins: { size: 'xl' },
view: ({ style, h }) =>
row(h, [
Badge.view({ text: '12', tone: 'danger', style }, h),
Badge.view({ text: 'Release candidate', tone: 'accent', 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.