Card group
Cards as one choice, with a highlight that follows the pointer between them.
Previews are drawn in the theme you made.
Edit itPlans #
Starter
One editor and three pages.
FreeTeam
Ten editors and every page.
$12Business
Sign-on and audit logs.
$40Enterprise
Talk to us first.
Soon
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Card, CardGroupSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Plan = Recipes.Card.style({ surface: 'plain', orientation: 'inline' })
const plans = [
{ key: 'starter', title: 'Starter', description: 'One editor and three pages.', price: 'Free' },
{ key: 'team', title: 'Team', description: 'Ten editors and every page.', price: '$12' },
{ key: 'business', title: 'Business', description: 'Sign-on and audit logs.', price: '$40' },
{ key: 'enterprise', title: 'Enterprise', description: 'Talk to us first.', price: 'Soon' },
]
const Model = Schema.Struct({ chosen: Schema.String })
const Message = defineMessageUnion({ Chose: { key: Schema.String } })
// Cards as one choice: the chosen one is `selected`, a card can be `disabled`,
// and `Card.fluid` is the highlight that follows the pointer. Without it the
// group draws no highlight and loads none of its code.
export default example({
title: 'Plans',
slots: CardGroupSlots,
recipe: Recipes.CardGroup,
state: {
Model,
Message,
init: () => ({ model: { chosen: 'team' } }),
update: (model, { key }) => ({ model: key === model.chosen ? model : { chosen: key } }),
},
view: ({ style, model, onMessage, h }) =>
Card.group(
{
fluid: Card.fluid,
label: 'Plans',
cards: plans.map(plan => ({
key: plan.key,
title: plan.title,
description: plan.description,
footer: h.span([], [plan.price]),
selected: plan.key === model.chosen,
disabled: plan.key === 'enterprise',
press: { onClick: onMessage(Message.Chose({ key: plan.key })) },
})),
style,
cardStyle: Plan,
},
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 grid #
Frankfurt
Under 40ms from most of the region
Virginia
Under 40ms from most of the region
Singapore
Under 40ms from most of the region
São Paulo
Under 40ms from most of the region
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Card, CardGroupSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Region = Recipes.Card.style({})
const Model = Schema.Struct({ chosen: Schema.String })
const Message = defineMessageUnion({ Chose: { region: Schema.String } })
// Cards in a grid, still one choice: the highlight follows the pointer both
// ways. Leave `fluid` out and each card shows its own hover.
export default example({
title: 'A grid',
slots: CardGroupSlots,
recipe: Recipes.CardGroup,
pins: { layout: 'separated' },
state: {
Model,
Message,
init: () => ({ model: { chosen: 'Frankfurt' } }),
update: (model, { region }) => ({
model: region === model.chosen ? model : { chosen: region },
}),
},
view: ({ style, model, onMessage, h }) =>
Card.group(
{
fluid: Card.fluid,
label: 'Regions',
columns: 2,
cards: ['Frankfurt', 'Virginia', 'Singapore', 'São Paulo'].map(title => ({
key: title,
title,
description: 'Under 40ms from most of the region',
selected: title === model.chosen,
press: { onClick: onMessage(Message.Chose({ region: title })) },
})),
style,
cardStyle: Region,
},
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.
Without the highlight #
import { Card, CardGroupSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
const Tile = Recipes.Card.style({ lift: 'hover' })
// No `fluid`: the group draws no highlight element and no Mount, and each
// card lifts by its own `lift`. A page that never passes `Card.fluid` ships
// none of it.
export default example({
title: 'Without the highlight',
slots: CardGroupSlots,
recipe: Recipes.CardGroup,
pins: { layout: 'separated' },
view: ({ style, h }) =>
Card.group(
{
label: 'Guides',
columns: 2,
cards: ['Tokens', 'Recipes', 'Bundles', 'Themes'].map(title => ({
key: title,
title,
description: 'Read the guide',
press: { href: '#' },
})),
style,
cardStyle: Tile,
},
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.