Card
A surface with media, a title, content and actions, pressable and dismissible.
Previews are drawn in the theme you made.
Edit itBasic #
Invite your team
Everyone you invite can edit every page.
Three seats left on the Starter plan.
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Badge, Button, Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { outline } from '../../snippets/icon.js'
const Action = Recipes.Button.style({})
const Tag = Recipes.Badge.style()
const Model = Schema.Struct({ dismissed: Schema.Boolean })
const Message = defineMessageUnion({ Dismissed: {}, Restored: {} })
// Every part is optional: media, a title and description, an action in the
// corner, content, a footer. `dismiss` draws a close button and sends the
// Message the application gives; the Model decides whether the card shows.
export default example({
title: 'Basic',
slots: CardSlots,
recipe: Recipes.Card,
state: {
Model,
Message,
init: () => ({ model: { dismissed: false } }),
update: (model, message) => {
const dismissed = Message.match(message, { Dismissed: () => true, Restored: () => false })
return { model: dismissed === model.dismissed ? model : { dismissed } }
},
},
view: ({ style, model, onMessage, h }) =>
model.dismissed
? Button.view(
{ label: 'Bring the card back', onClick: onMessage(Message.Restored()), style: Action },
h,
)
: Card.view(
{
media: outline(h, 'M8 1.5l1.8 4.7 4.7 1.8-4.7 1.8L8 14.5l-1.8-4.7L1.5 8l4.7-1.8z'),
title: 'Invite your team',
description: 'Everyone you invite can edit every page.',
action: Badge.view({ text: 'New', tone: 'live', style: Tag }, h),
content: h.p([], ['Three seats left on the Starter plan.']),
footer: Button.view({ label: 'Send invites', style: Action }, h),
dismiss: { onDismiss: onMessage(Message.Dismissed()) },
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 figure #
Monthly revenue
Up 12% on September
$48,210
import { Badge, Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Tag = Recipes.Badge.style()
// A number with what it counts and how it moved: the content is the figure.
export default example({
title: 'A figure',
slots: CardSlots,
recipe: Recipes.Card,
view: ({ style, h }) =>
Card.view(
{
title: 'Monthly revenue',
description: 'Up 12% on September',
action: Badge.view({ text: '+12%', tone: 'live', style: Tag }, h),
content: h.p([h.Style({ margin: '0', fontSize: '2rem', fontWeight: '600' })], ['$48,210']),
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Media #
Lisbon in spring
Six days of trams, tiles and long lunches.
import { Button, Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { portrait } from '../../snippets/portrait.js'
const Action = Recipes.Button.style({})
// A picture across the top, bled to the card's edges.
export default example({
title: 'Media',
slots: CardSlots,
recipe: Recipes.Card,
view: ({ style, h }) =>
Card.view(
{
image: h.img([h.Src(portrait(200)), h.Alt('')]),
title: 'Lisbon in spring',
description: 'Six days of trams, tiles and long lunches.',
footer: Button.view({ label: 'Read the guide', style: Action }, h),
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
A person #
Ada Lovelace
Analyst, Engine team
import { Avatar, Button, Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Face = Recipes.Avatar.style({ size: 'lg', color: 'name' })
const Action = Recipes.Button.style({})
// A person: their avatar leading in the media's place, a name and a role.
export default example({
title: 'A person',
slots: CardSlots,
recipe: Recipes.Card,
view: ({ style, h }) =>
Card.view(
{
media: Avatar.view({ name: 'Ada Lovelace', status: 'online', style: Face }, h),
title: 'Ada Lovelace',
description: 'Analyst, Engine team',
footer: Button.view({ label: 'Message', style: Action }, h),
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
A link #
import { Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { outline } from '../../snippets/icon.js'
// A whole card that goes somewhere: one link named by its title, drawn over
// the card, so the card lifts under the pointer and a footer's own controls
// stay pressable above it.
export default example({
title: 'A link',
slots: CardSlots,
recipe: Recipes.Card,
pins: { lift: 'hover' },
view: ({ style, h }) =>
Card.view(
{
media: outline(h, 'M8 1.5l1.8 4.7 4.7 1.8-4.7 1.8L8 14.5l-1.8-4.7L1.5 8l4.7-1.8z'),
title: 'Read the changelog',
description: 'Everything that shipped this month.',
press: { href: 'https://github.com/doeixd/foldkit-plus/blob/main/CHANGELOG.md' },
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Sections #
Billing
Your plan renews on 1 December.
Team plan, ten seats, $120 a month.
import { Button, Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Action = Recipes.Button.style({ size: 'sm' })
// `divide` draws a hairline under the header, or under it and over the
// footer, edge to edge, so the regions read as sections of one sheet.
export default example({
title: 'Sections',
slots: CardSlots,
recipe: Recipes.Card,
pins: { divide: 'sections' },
view: ({ style, h }) =>
Card.view(
{
title: 'Billing',
description: 'Your plan renews on 1 December.',
content: h.p([], ['Team plan, ten seats, $120 a month.']),
footer: Button.view({ label: 'Change plan', style: Action }, h),
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
A picture that grows #
import { Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { portrait } from '../../snippets/portrait.js'
// `lift: 'zoom'` grows the picture inside its frame under the pointer; the
// card stays put. The reader's reduced-motion setting stills it.
export default example({
title: 'A picture that grows',
slots: CardSlots,
recipe: Recipes.Card,
pins: { lift: 'zoom' },
view: ({ style, h }) =>
Card.view(
{
image: h.img([h.Src(portrait(40)), h.Alt('')]),
title: 'Porto in autumn',
description: 'Four days along the river.',
press: { href: '#' },
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Text over a picture #
Autumn collection
Wool, linen and the first cold mornings.
import { Button, Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { portrait } from '../../snippets/portrait.js'
const Action = Recipes.Button.style({ size: 'sm' })
// `orientation: 'overlay'` makes the picture the card's ground, with the
// text over its foot on a fade to the card's own surface.
export default example({
title: 'Text over a picture',
slots: CardSlots,
recipe: Recipes.Card,
pins: { orientation: 'overlay' },
view: ({ style, h }) =>
Card.view(
{
image: h.img([h.Src(portrait(300)), h.Alt('')]),
title: 'Autumn collection',
description: 'Wool, linen and the first cold mornings.',
footer: Button.view({ label: 'Shop now', style: Action }, h),
style,
},
h,
),
})In your application: recipe goes to forSlots, and the body of view is the call. example is this site’s harness.
Elevation #
Level 0
elevation: '0'
Level 1
elevation: '1'
Level 2
elevation: '2'
Level 3
elevation: '3'
import { Card, CardSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Levels = (['0', '1', '2', '3'] as const).map(elevation =>
Recipes.Card.style({ surface: 'elevated', elevation }),
)
// Each level one more step above what holds it: lighter on a dark page, a
// deeper contact and ambient shadow on a light one.
export default example({
title: 'Elevation',
slots: CardSlots,
recipe: Recipes.Card,
view: ({ h }) =>
h.div(
[
h.Style({
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(9rem, 1fr))',
gap: '1.5rem',
}),
],
Levels.map((style, level) =>
Card.view({ title: `Level ${level}`, description: `elevation: '${level}'`, 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
- Keeping focus when something is removed A control that leaves the page takes its focus with it: say where focus goes next, to a neighbour (
FocusRecovery), to the opener (focusReturn) or to a control (keepFocus).