Breadcrumb
Where a page sits, and the way back up.
Previews are drawn in the theme you made.
Edit itBasic #
import { Breadcrumb, BreadcrumbSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// The current page is text, marked `aria-current`; every other step is a link.
export default example({
title: 'Basic',
slots: BreadcrumbSlots,
recipe: Recipes.Breadcrumb,
view: ({ style, h }) =>
Breadcrumb.view(
{
steps: [
{ label: 'Home', href: '#' },
{ label: 'Components', href: '#' },
{ label: 'Breadcrumb', current: true },
],
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Icons #
import { Breadcrumb, BreadcrumbSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { outline } from '../../snippets/icon.js'
// An icon before a step's words, hidden from assistive technology.
export default example({
title: 'Icons',
slots: BreadcrumbSlots,
recipe: Recipes.Breadcrumb,
view: ({ style, h }) =>
Breadcrumb.view(
{
steps: [
{ label: 'Home', href: '#', icon: outline(h, 'M2 7l6-5 6 5v7H2zM6 14v-4h4v4') },
{ label: 'Projects', href: '#', icon: outline(h, 'M1 3h5l2 2h7v8H1z') },
{ label: 'Roadmap.md', current: true, icon: outline(h, 'M3 1h7l3 3v11H3zM10 1v3h3') },
],
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
A separator of your own #
import { Breadcrumb, BreadcrumbSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// A separator of the view's own stands in for the recipe's.
export default example({
title: 'A separator of your own',
slots: BreadcrumbSlots,
recipe: Recipes.Breadcrumb,
view: ({ style, h }) =>
Breadcrumb.view(
{
steps: [
{ label: 'Settings', href: '#' },
{ label: 'Billing', href: '#' },
{ label: 'Invoices', current: true },
],
separator: h.span([], ['→']),
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Icon only, and a count #
import { Breadcrumb, BreadcrumbSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { outline } from '../../snippets/icon.js'
// `labelHidden` draws the icon alone and keeps the label as the step's name;
// `trailing` draws a count or a badge after the words.
export default example({
title: 'Icon only, and a count',
slots: BreadcrumbSlots,
recipe: Recipes.Breadcrumb,
view: ({ style, h }) =>
Breadcrumb.view(
{
steps: [
{
label: 'Home',
href: '#',
icon: outline(h, 'M2 7l6-5 6 5v7H2zM6 14v-4h4v4'),
labelHidden: true,
},
{ label: 'Inbox', href: '#', trailing: h.span([], ['12']) },
{ label: 'Invoices', current: true, trailing: h.span([], ['3']) },
],
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Collapsed #
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Breadcrumb, BreadcrumbSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Message = defineMessageUnion({ Expanded: {} })
const steps = [
{ label: 'Home', href: '#' },
{ label: 'Docs', href: '#' },
{ label: 'Packages', href: '#' },
{ label: 'Mixins', href: '#' },
{ label: 'Recipes', href: '#' },
{ label: 'Breadcrumb', current: true },
]
// A long trail folds its middle into an ellipsis. A press sends `onExpand`;
// whether the trail is folded is the application's own state, so it answers
// by drawing the trail without `collapse`.
export default example({
title: 'Collapsed',
slots: BreadcrumbSlots,
recipe: Recipes.Breadcrumb,
state: {
Model: Schema.Boolean,
Message,
init: () => ({ model: false }),
update: () => ({ model: true }),
},
view: ({ style, model: expanded, onMessage, h }) =>
Breadcrumb.view(
{
steps,
...(expanded ? {} : { collapse: { max: 3, onExpand: onMessage(Message.Expanded()) } }),
style,
},
h,
),
})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.
The hidden steps in a menu #
import { mapMessages } from 'foldkit/command'
import { defineMessageUnion } from 'foldkit/message'
import { Breadcrumb, BreadcrumbMenu, BreadcrumbSlots, Menu, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const steps = [
{ label: 'Home', href: '#' },
{ label: 'Docs', href: '#' },
{ label: 'Packages', href: '#' },
{ label: 'Mixins', href: '#' },
{ label: 'Recipes', href: '#' },
{ label: 'Breadcrumb', current: true },
]
const MAX = 3
const MenuStyle = Recipes.Menu.style({})
const Message = defineMessageUnion({ GotMenu: { message: Menu.Message } })
const got = (message: Menu.Message) => Message.GotMenu({ message })
// `BreadcrumbMenu.make` is a value the application passes, so a trail that
// never opens a Menu never loads one. The Menu's Model is the application's:
// `Menu.update` folds it, and a row chosen comes out as `Selected`, which
// `Breadcrumb.chosen` turns back into the step it stands for.
export default example({
title: 'The hidden steps in a menu',
slots: BreadcrumbSlots,
recipe: Recipes.Breadcrumb,
state: {
Model: Menu.Model,
Message,
init: () => ({ model: Menu.init('trail-menu', Breadcrumb.menuRows(steps, MAX)) }),
update: (model, { message }) => {
const next = Menu.update(model, message)
return { model: next.model, commands: mapMessages(next.commands, got) }
},
},
view: ({ style, model, onMessage, h }) =>
Breadcrumb.view(
{
steps,
collapse: BreadcrumbMenu.make({
max: MAX,
menu: {
model,
onMessage: message => onMessage(got(message)),
mixins: [MenuStyle.mixin],
},
}),
style,
},
h,
),
})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.
In another language #
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Breadcrumb, BreadcrumbSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Message = defineMessageUnion({ Expanded: {} })
const steps = [
{ label: 'Accueil', href: '#' },
{ label: 'Guides', href: '#' },
{ label: 'Composants', href: '#' },
{ label: 'Recettes', href: '#' },
{ label: 'Fil d’Ariane', current: true },
]
// The landmark's name, the ellipsis's name (`{count}` fills the steps it
// hides) and its mark are words: text with blanks, in the reader's language.
export default example({
title: 'In another language',
slots: BreadcrumbSlots,
recipe: Recipes.Breadcrumb,
state: {
Model: Schema.Boolean,
Message,
init: () => ({ model: false }),
update: () => ({ model: true }),
},
view: ({ style, model: expanded, onMessage, h }) =>
Breadcrumb.view(
{
words: { label: 'Fil d’Ariane', more: 'Afficher {count} de plus', ellipsis: '···' },
steps,
...(expanded ? {} : { collapse: { max: 3, onExpand: onMessage(Message.Expanded()) } }),
style,
},
h,
),
})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.
A fold of your own #
import { Breadcrumb, BreadcrumbSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
// A fold of the application's own: `collapse` takes any value with a `max` and
// a `draw`, here an ellipsis that is a link to a page of the whole trail.
export default example({
title: 'A fold of your own',
slots: BreadcrumbSlots,
recipe: Recipes.Breadcrumb,
view: ({ style, h }) =>
Breadcrumb.view(
{
steps: [
{ label: 'Home', href: '#' },
{ label: 'Docs', href: '#' },
{ label: 'Packages', href: '#' },
{ label: 'Mixins', href: '#' },
{ label: 'Breadcrumb', current: true },
],
collapse: {
max: 3,
draw: ({ label, ellipsis, builders }, builder) =>
builder.a(builders.ellipsis.attrs([builder.Href('#'), builder.AriaLabel(label)]), [
ellipsis,
]),
},
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.
Related
- Right to left The direction switch above turns the preview over; this is what each widget reads.