foldkit-mixins-ui 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/datePickerView.d.ts +6 -6
- package/dist/picker.d.ts.map +1 -1
- package/dist/picker.js +2 -1
- package/dist/picker.js.map +1 -1
- package/dist/recipes/tabs.d.ts +7 -0
- package/dist/recipes/tabs.d.ts.map +1 -1
- package/dist/recipes/tabs.js +78 -20
- package/dist/recipes/tabs.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -458,7 +458,7 @@ adapter.
|
|
|
458
458
|
| Popover | `button`, `panel`, `backdrop`, `arrow`, and this package's `layer`, drawn around the panel to show it in the top layer (see [The top layer](#the-top-layer)); `Popover.anchor(config?)` is the placement. Recipe `arrow`: `shown` (default), `none` |
|
|
459
459
|
| Tooltip | `trigger`, `panel`, `arrow`, and this package's `layer`. `Tooltip.toView(mixins, { h, id }, draw)` takes the Tooltip's id (`model.id`), whose trigger the arrow points at; `Tooltip.anchor(config?)` is the placement, above by default. Recipe `arrow`: `shown` (default), `none` |
|
|
460
460
|
| HoverIntent | `trigger`, `panel`, `arrow` (open and close delays with intent, for a hover card or a menu). `anchored: { id, anchor? }` in the context anchors the panel to the trigger in the top layer (`HoverIntent.anchor()` unless given), the trigger taking `HoverIntent.triggerId(id)` |
|
|
461
|
-
| Tabs | `tablist`, `tab`, `panel`, and this package's `indicator` and `highlight` (drawn first in the tablist, for `Tabs.fluid`). and this package's `item`, `label`, `icon` and `close`: a tab is a flex row, so draw its words in `label` (`h.span(label, [words])`) and an icon in `icon`, a Badge after them for a count. `TabsContext.close: { onClose }` makes tabs closable: each gets a close button (no tab stop, hidden from assistive technology) and Delete, named in `aria-keyshortcuts`; answer with `Tabs.closing(tabs, chosen, closed)`, which gives the tabs left, the tab chosen and the index to focus with `FocusTab`. `Tabs.readingKeys` beside the style reads the arrow keys by the tablist's direction (see [Right to left](#right-to-left)). Recipe axes `variant`: `line` (default), `pill`; `size`: `sm`, `md`, `lg`; `overflow: 'scroll'` (one line, its edges fading); upstream's `orientation: 'Vertical'` stands the rule at the tabs' inline end |
|
|
461
|
+
| Tabs | `tablist`, `tab`, `panel`, and this package's `indicator` and `highlight` (drawn first in the tablist, for `Tabs.fluid`). and this package's `item`, `label`, `icon` and `close`: a tab is a flex row, so draw its words in `label` (`h.span(label, [words])`) and an icon in `icon`, a Badge after them for a count. `TabsContext.close: { onClose }` makes tabs closable: each gets a close button (no tab stop, hidden from assistive technology) and Delete, named in `aria-keyshortcuts`; answer with `Tabs.closing(tabs, chosen, closed)`, which gives the tabs left, the tab chosen and the index to focus with `FocusTab`. `Tabs.readingKeys` beside the style reads the arrow keys by the tablist's direction (see [Right to left](#right-to-left)). Recipe axes `variant`: `line` (default), `pill`; `size`: `sm`, `md`, `lg`; `overflow: 'scroll'` (one line, its edges fading) or `'wrap'` (a grid of equal columns that fills the row and falls to fewer columns, no tab cut off; a column is no narrower than three control heights; `.extend` the tablist's `--_fk-tab-min` to change it); pill-only `selection`: `raised` (default) or `tint`; upstream's `orientation: 'Vertical'` stands the rule at the tabs' inline end |
|
|
462
462
|
| RadioGroup | `group`, `option`, `label`, `description`, `hiddenInput`, and this package's `card`. Upstream's `option` is a `button` and its `label` bundle only an id, so a bare `label` takes no press: draw each row as a `label` element around its `option`, carrying the option's `card` bundle (`h.label(option.card, [h.button(option.option, []), …])`), and the browser sends a press on the words to the radio. `card` is `data-checked` while its option is. The recipe stacks the group unless `aria-orientation` is `horizontal`, and a row wraps. `variant: 'card'` frames each card and fills the one whose radio is checked. `tone`: `accent` (default), `neutral`; `size`: `sm`, `md`, `lg`. `RadioGroup.readingKeys` as Tabs' |
|
|
463
463
|
| Anchor | a Mount and a Behavior over `@foldkit/ui/anchor`: `Anchor.behavior(Slots)({ floating, config })` positions a floating slot against a button by id; `Anchor.topLayer(mount)` shows an in-place panel in the top layer around it (see [The top layer](#the-top-layer)) |
|
|
464
464
|
| Calendar | `root`, `header` (the heading's row, this package's own), `grid`, `headerRow`, `previousMonthButton`, `nextMonthButton`, `headingButton`, `previousPageButton`, `nextPageButton`, `columnHeader`, `weekRow`, `dayCell`, `dayButton`, `monthCell`, `monthButton`, `yearCell`, `yearButton`. `Calendar.readingKeys` as Tabs' |
|
|
@@ -837,8 +837,10 @@ with more past it with a hairline (`Utilities.scrollDivider` on `root`,
|
|
|
837
837
|
`Utilities.scrollTimeline` on `viewport`), drawn where the browser lets a
|
|
838
838
|
parent read a child's scroll timeline (`timeline-scope`).
|
|
839
839
|
|
|
840
|
-
`Recipes.Tabs({ variant: 'pill' })`'s chosen tab is
|
|
841
|
-
|
|
840
|
+
`Recipes.Tabs({ variant: 'pill' })`'s chosen tab is a raised surface with a
|
|
841
|
+
hairline edge and shadow on the tray, in the default text colour;
|
|
842
|
+
`selection: 'tint'` is the accent's tint and ink instead, as a pressed Segmented
|
|
843
|
+
option is. To look at every recipe in every variant and
|
|
842
844
|
state at once, in both schemes, write the specimen page:
|
|
843
845
|
`pnpm --filter foldkit-mixins-ui specimen <out.html> [hue]`.
|
|
844
846
|
|
package/dist/datePickerView.d.ts
CHANGED
|
@@ -259,9 +259,9 @@ export declare const view: import("foldkit/submodel").View<{
|
|
|
259
259
|
readonly maybeLastButtonPointerType: Option.Option<string>;
|
|
260
260
|
};
|
|
261
261
|
}, {
|
|
262
|
-
readonly _tag: "Cleared";
|
|
263
|
-
} | {
|
|
264
262
|
readonly _tag: "Closed";
|
|
263
|
+
} | {
|
|
264
|
+
readonly _tag: "Cleared";
|
|
265
265
|
} | {
|
|
266
266
|
readonly _tag: "Opened";
|
|
267
267
|
} | {
|
|
@@ -309,10 +309,6 @@ export declare const view: import("foldkit/submodel").View<{
|
|
|
309
309
|
} | {
|
|
310
310
|
readonly _tag: "GotPopoverMessage";
|
|
311
311
|
readonly message: {
|
|
312
|
-
readonly _tag: "ClickedButton";
|
|
313
|
-
} | {
|
|
314
|
-
readonly _tag: "CompletedFocusButton";
|
|
315
|
-
} | {
|
|
316
312
|
readonly _tag: "CompletedInertOthers";
|
|
317
313
|
} | {
|
|
318
314
|
readonly _tag: "CompletedLockScroll";
|
|
@@ -320,6 +316,10 @@ export declare const view: import("foldkit/submodel").View<{
|
|
|
320
316
|
readonly _tag: "CompletedRestoreInert";
|
|
321
317
|
} | {
|
|
322
318
|
readonly _tag: "CompletedUnlockScroll";
|
|
319
|
+
} | {
|
|
320
|
+
readonly _tag: "ClickedButton";
|
|
321
|
+
} | {
|
|
322
|
+
readonly _tag: "CompletedFocusButton";
|
|
323
323
|
} | {
|
|
324
324
|
readonly _tag: "IgnoredMouseClick";
|
|
325
325
|
} | {
|
package/dist/picker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picker.d.ts","names":[],"sources":["../src/picker.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"picker.d.ts","names":[],"sources":["../src/picker.ts"],"mappings":";;;;;;;;qBA4Ca,aAAW,MAAA;;;;;;;;;;qBAmBX,OAAK,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAON,eAAe,MAAM;qBAEpB,mCAAO;;IACJ,mCAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IACT,mCAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH,OAAK,OAAA;;;;IAEV,IAAE,OAAA;;;;YAGH,iBAAiB,QAAQ;qBAExB,sCAAU;;;IAEZ,OAAK,OAAA;;;YAEJ,oBAAoB,WAAW;iBAE1B;;WAEN;;WAEA,QAAQ,KAAK,MAAM;;;qBAIjB,OAAI,QAAY,eAAa;;qBAO7B,WAAQ,YAAc;YAYvB,SAAS,qBAAqB,OAAO,SAAS;;qBAmB7C,SAAM,OAAW,OAAK,SAAW,YAAU;;iBA0BvC,aAAa,8BAA8B,QAAQ;WACzD,OAAO;;iBAGD,WAAW,sBAAsB;WACvC,OAAO;WACP,YAAY,SAAS,YAAY,QAAQ;;WAEzC;WACA,SAAS,cAAc,aAAa;;WAEpC,OAAO,OAAO,OAAO,QAAQ;;WAE7B;;WAEA,SAAS,UAAU;;WAEnB,QAAQ,kBAAkB;;WAE1B,SAAS,UAAU;;WAEnB,UAAU,UAAU;;WAEpB,QAAQ,UAAU;;;qBAahB,OAAQ,sBAAsB,OAAK,SACrC,WAAW,OAAO,QAAM,GAC9B,YAAY,WACd"}
|
package/dist/picker.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Effect, Option, Schema } from "effect";
|
|
|
3
3
|
import { defineMessageUnion } from "foldkit/message";
|
|
4
4
|
import { modifyFields } from "foldkit/struct";
|
|
5
5
|
import * as Command from "foldkit/command";
|
|
6
|
+
import { idSelector } from "./datePickerUtils.js";
|
|
6
7
|
import * as Listbox from "./listbox.js";
|
|
7
8
|
import * as Sheet from "./sheet.js";
|
|
8
9
|
import * as ListboxView from "./listboxView.js";
|
|
@@ -126,7 +127,7 @@ const update = (model, message) => Message.match(message, {
|
|
|
126
127
|
}),
|
|
127
128
|
Stepped: ({ to }) => ({
|
|
128
129
|
model,
|
|
129
|
-
commands: [Focus({ selector:
|
|
130
|
+
commands: [Focus({ selector: idSelector(optionId(model.id, to)) })]
|
|
130
131
|
}),
|
|
131
132
|
CompletedFocus: () => ({ model })
|
|
132
133
|
});
|
package/dist/picker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picker.js","names":[],"sources":["../src/picker.ts"],"sourcesContent":["/**\n * A picker that is a dropdown on a desktop and a bottom sheet on a phone:\n * one control, one Model and one set of Messages whatever the width. The\n * application owns the value, as with `@foldkit/ui`'s Listbox, and hears a\n * choice made either way as the same `Chose`.\n *\n * ```text\n * at or above the breakpoint: Listbox trigger -> Listbox panel -> Selected -> Chose\n * below it: opener -> Sheet -> an option pressed -> Chose\n * ```\n *\n * Both are drawn, and `Recipes.Picker` shows one: the `dropdown` (a Listbox,\n * its panel kept in place with `portal: false`) at or above its\n * `sheetBelow` breakpoint, the `opener` below it, so nothing reads the width\n * and a server render is right at every width. The one hidden is\n * `display: none`, out of the accessibility tree and the tab order. Opening\n * the Sheet closes the Listbox, so one left open behind a window narrowed\n * past the breakpoint does not stay open beside it; a Sheet open when the\n * window widens stays until chosen from or dismissed.\n *\n * The Sheet's list is a listbox of option buttons: the chosen one (or the\n * first) takes the Dialog's first focus and is the one in the tab order, the\n * arrows, Home and End move focus between them, and Enter, Space or a tap\n * chooses, which closes the Sheet and gives focus back to the opener. An\n * option's content and the trigger's are `Listbox.parts`', in the Listbox's\n * slots.\n */\nimport * as UiDialog from '@foldkit/ui/dialog'\nimport * as UiListbox from '@foldkit/ui/listbox'\nimport { Effect, Option, Schema } from 'effect'\nimport { Attr, Capability, Event, Slot, Slots, SlotView, type NamedStyle } from 'foldkit-mixins'\nimport * as Command from 'foldkit/command'\nimport * as Dom from 'foldkit/dom'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport { defineMessageUnion } from 'foldkit/message'\nimport { modifyFields } from 'foldkit/struct'\nimport type { ReturnWithOutMessage } from 'foldkit/update'\nimport type { ResolvedDialog } from './dialog.js'\nimport * as Listbox from './listbox.js'\nimport * as ListboxView from './listboxView.js'\nimport type { MixinList } from './resolve.js'\nimport * as Sheet from './sheet.js'\n\nexport const PickerSlots = Slots.define({\n root: Slot.make({ capability: Capability.Container }),\n /** The desktop's half: the Listbox, its trigger and its panel. */\n dropdown: Slot.make({ capability: Capability.Container }),\n /** The phone's half: the button that opens the Sheet. */\n opener: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click],\n attributes: [Attr.AriaExpanded, Attr.AriaLabel],\n }),\n /** The Sheet's options. */\n list: Slot.make({ capability: Capability.Container, attributes: [Attr.Role] }),\n option: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click, Event.KeyDown],\n attributes: [Attr.Role, Attr.AriaSelected],\n }),\n})\n\nexport const Model = Schema.Struct({\n id: Schema.String,\n /** The desktop's dropdown: which row is active, whether it is open. */\n listbox: UiListbox.Model,\n /** The phone's sheet. */\n sheet: Sheet.Model,\n})\nexport type Model = typeof Model.Type\n\nexport const Message = defineMessageUnion({\n GotListbox: { message: UiListbox.Message },\n GotSheet: { message: Sheet.Message },\n OpenedSheet: {},\n ChoseInSheet: { value: Schema.String },\n /** A key moved focus to the Sheet's option at `to`. */\n Stepped: { to: Schema.Number },\n CompletedFocus: {},\n})\nexport type Message = typeof Message.Type\n\nexport const OutMessage = defineMessageUnion({\n /** An option was chosen, in the dropdown or in the Sheet. */\n Chose: { value: Schema.String },\n})\nexport type OutMessage = typeof OutMessage.Type\n\nexport interface InitConfig {\n /** Prefixes the ids the picker draws, unique on the page. */\n readonly id: string\n /** The phone's Sheet, beside its id: points, swipe, animation. It comes from the bottom. */\n readonly sheet?: Omit<Sheet.InitConfig, 'id' | 'side'>\n}\n\n/** A closed picker. */\nexport const init = (config: InitConfig): Model => ({\n id: config.id,\n listbox: UiListbox.init({ id: `${config.id}-listbox` }),\n sheet: Sheet.init({ ...config.sheet, id: `${config.id}-sheet`, side: 'bottom' }),\n})\n\n/** The id of the Sheet's option at `index`. */\nexport const optionId = (id: string, index: number): string => `${id}-option-${index}`\n\n/** Upstream's Listbox `update` with this package's view, over the picker's options. */\nconst Dropdown = ListboxView.create<PickerOption<string>, string>()\n\nconst Focus = Command.define('FocusPickerOption', {\n args: { selector: Schema.String },\n messages: [Message.CompletedFocus],\n execute: ({ selector }) =>\n Dom.focus(selector).pipe(Effect.ignore, Effect.as(Message.CompletedFocus())),\n})\n\nexport type Return = ReturnWithOutMessage<Model, Message, OutMessage>\n\nconst listboxStep = (\n model: Model,\n next: ReturnWithOutMessage<UiListbox.Model, UiListbox.Message, UiListbox.OutMessage>,\n): Return => ({\n model: next.model === model.listbox ? model : modifyFields(model, { listbox: () => next.model }),\n commands: Command.mapMessages(next.commands ?? [], message => Message.GotListbox({ message })),\n ...(next.outMessage === undefined\n ? {}\n : { outMessage: OutMessage.Chose({ value: next.outMessage.value }) }),\n})\n\nconst sheetStep = (model: Model, next: Sheet.Return): Return => ({\n model: next.model === model.sheet ? model : modifyFields(model, { sheet: () => next.model }),\n commands: Command.mapMessages(next.commands ?? [], message => Message.GotSheet({ message })),\n})\n\n/** The picker after `message`; the same Model when nothing changes. */\nexport const update = (model: Model, message: Message): Return =>\n Message.match(message, {\n GotListbox: ({ message }) => listboxStep(model, Dropdown.update(model.listbox, message)),\n GotSheet: ({ message }) => sheetStep(model, Sheet.update(model.sheet, message)),\n OpenedSheet: () => {\n const closed = model.listbox.isOpen\n ? listboxStep(model, Dropdown.close(model.listbox))\n : { model, commands: [] }\n const opened = sheetStep(closed.model, Sheet.open(closed.model.sheet))\n return {\n model: opened.model,\n commands: [...(closed.commands ?? []), ...(opened.commands ?? [])],\n }\n },\n ChoseInSheet: ({ value }) => ({\n ...sheetStep(model, Sheet.close(model.sheet)),\n outMessage: OutMessage.Chose({ value }),\n }),\n Stepped: ({ to }) => ({ model, commands: [Focus({ selector: `#${optionId(model.id, to)}` })] }),\n CompletedFocus: () => ({ model }),\n })\n\n/** An option: its value, and what it shows in the list and on the trigger. */\nexport interface PickerOption<Value extends string> extends Listbox.OptionContent {\n readonly value: Value\n}\n\nexport interface PickerView<Value extends string, Outer> {\n readonly model: Model\n readonly onMessage: (message: Message) => NoInfer<Outer>\n /** Names the control, and titles the Sheet. */\n readonly label: string\n readonly options: ReadonlyArray<PickerOption<Value>>\n /** The chosen value, which the application keeps. */\n readonly value: Option.Option<NoInfer<Value>>\n /** Shown on the trigger while nothing is chosen. */\n readonly placeholder: string\n /** Where the dropdown's panel opens; default below the trigger's start, kept in place. */\n readonly anchor?: UiListbox.AnchorConfig\n /** A style of `PickerSlots` (`Recipes.Picker`). */\n readonly style?: NamedStyle<typeof PickerSlots> | undefined\n /** Mixins beside the style. */\n readonly mixins?: MixinList<Outer> | undefined\n /** The Listbox's style and mixins (`Recipes.Listbox`), which also draw the options' and the trigger's content. */\n readonly listbox?: MixinList<Outer> | undefined\n /** The Sheet's style and mixins (`Recipes.Sheet`), on `DialogSlots`. */\n readonly sheet?: MixinList<Outer> | undefined\n}\n\n/** Where a key moves focus from the option at `index` of `count`, if it is one that moves it. */\nconst stepped = (key: string, index: number, count: number): Option.Option<number> => {\n if (key === 'Home') return Option.some(0)\n if (key === 'End') return Option.some(count - 1)\n if (key === 'ArrowDown') return Option.some(Math.min(count - 1, index + 1))\n if (key === 'ArrowUp') return Option.some(Math.max(0, index - 1))\n return Option.none()\n}\n\n/** The picker: the dropdown and the opener, one shown by the style, and the Sheet. */\nexport const view = <Value extends string, Outer>(\n options: PickerView<Value, Outer>,\n h: HtmlBuilder<Outer>,\n): Html => {\n const { model, onMessage, value } = options\n const builders = SlotView.buildersFor(\n PickerSlots,\n [...(options.style === undefined ? [] : [options.style.mixin]), ...(options.mixins ?? [])],\n { input: undefined, h },\n )\n const listboxMixins = options.listbox ?? []\n const part = Listbox.parts(listboxMixins, { h })\n const chosen = Option.flatMap(value, current =>\n Option.fromNullishOr(options.options.find(option => option.value === current)),\n )\n const trigger = part.trigger(chosen, options.placeholder)\n const choices = options.options\n const focused = Math.max(\n 0,\n choices.findIndex(option => Option.contains(value, option.value)),\n )\n // Both triggers say what they choose and what is chosen.\n const named = `${options.label}: ${Option.match(chosen, {\n onNone: () => options.placeholder,\n onSome: option => option.label,\n })}`\n return h.div(builders.root.attrs(), [\n h.div(builders.dropdown.attrs(), [\n h.submodel({\n slotId: model.listbox.id,\n model: model.listbox,\n view: Dropdown.view,\n viewInputs: {\n anchor: options.anchor ?? {\n placement: 'bottom-start',\n gap: 4,\n padding: 8,\n portal: false,\n },\n items: choices,\n itemToValue: (option: PickerOption<string>) => option.value,\n maybeSelectedValue: value,\n ariaLabel: named,\n itemToConfig: (option: PickerOption<string>) => ({ content: part.option(option) }),\n buttonContent: trigger,\n toView: Listbox.toView(listboxMixins, { h }),\n },\n toParentMessage: message => onMessage(Message.GotListbox({ message })),\n }),\n ]),\n h.button(\n builders.opener.attrs([\n h.Type('button'),\n h.AriaHasPopup('dialog'),\n h.AriaExpanded(Sheet.isOpen(model.sheet)),\n h.AriaLabel(named),\n h.OnClick(onMessage(Message.OpenedSheet())),\n ]),\n [trigger],\n ),\n Sheet.view(\n {\n model: model.sheet,\n onMessage: message => onMessage(Message.GotSheet({ message })),\n mixins: options.sheet ?? [],\n draw: (dialog: ResolvedDialog<Outer>) =>\n h.dialog(\n dialog.dialog,\n dialog.isVisible\n ? [\n h.div(dialog.backdrop),\n h.div(dialog.panel, [\n h.div(dialog.handle),\n h.h2(dialog.title, [options.label]),\n h.div(\n builders.list.attrs([\n h.Role('listbox'),\n h.AriaLabelledBy(UiDialog.titleId(model.sheet.dialog)),\n ]),\n choices.map((option, index) =>\n h.keyed('button')(\n option.value,\n builders.option.attrs([\n h.Type('button'),\n h.Id(optionId(model.id, index)),\n h.Role('option'),\n h.AriaSelected(Option.contains(value, option.value)),\n h.Tabindex(index === focused ? 0 : -1),\n ...(index === focused ? dialog.initialFocus : []),\n h.OnClick(onMessage(Message.ChoseInSheet({ value: option.value }))),\n h.OnKeyDownPreventDefault(key =>\n Option.map(stepped(key, index, choices.length), to =>\n onMessage(Message.Stepped({ to })),\n ),\n ),\n ]),\n [part.option(option)],\n ),\n ),\n ),\n ]),\n ]\n : [],\n ),\n },\n h,\n ),\n ])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,cAAc,MAAM,OAAO;CACtC,MAAM,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;;CAEpD,UAAU,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;;CAExD,QAAQ,KAAK,KAAK;EAChB,YAAY,WAAW;EACvB,QAAQ,CAAC,MAAM,KAAK;EACpB,YAAY,CAAC,KAAK,cAAc,KAAK,SAAS;CAChD,CAAC;;CAED,MAAM,KAA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AK,QAAQ;KACf,EAAE,GAAG,SAAS,MAAM,IAAI,KAAK,CAAC;KAC9B,EAAE,KAAK,QAAQ;KACf,EAAE,aAAa,OAAO,SAAS,OAAO,OAAO,KAAK,CAAC;KACnD,EAAE,SAAS,UAAU,UAAU,IAAI,EAAE;KACrC,GAAI,UAAU,UAAU,OAAO,eAAe,CAAC;KAC/C,EAAE,QAAQ,UAAU,QAAQ,aAAa,EAAE,OAAO,OAAO,MAAM,CAAC,CAAC,CAAC;KAClE,EAAE,yBAAwB,QACxB,OAAO,IAAI,QAAQ,KAAK,OAAO,QAAQ,MAAM,IAAG,OAC9C,UAAU,QAAQ,QAAQ,EAAE,GAAG,CAAC,CAAC,CACnC,CACF;IACF,CAAC,GACD,CAAC,KAAK,OAAO,MAAM,CAAC,CACtB,CACF,CACF;GACF,CAAC,CACH,IACA,CAAC,CACP;EACJ,GACA,CACF;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"picker.js","names":[],"sources":["../src/picker.ts"],"sourcesContent":["/**\n * A picker that is a dropdown on a desktop and a bottom sheet on a phone:\n * one control, one Model and one set of Messages whatever the width. The\n * application owns the value, as with `@foldkit/ui`'s Listbox, and hears a\n * choice made either way as the same `Chose`.\n *\n * ```text\n * at or above the breakpoint: Listbox trigger -> Listbox panel -> Selected -> Chose\n * below it: opener -> Sheet -> an option pressed -> Chose\n * ```\n *\n * Both are drawn, and `Recipes.Picker` shows one: the `dropdown` (a Listbox,\n * its panel kept in place with `portal: false`) at or above its\n * `sheetBelow` breakpoint, the `opener` below it, so nothing reads the width\n * and a server render is right at every width. The one hidden is\n * `display: none`, out of the accessibility tree and the tab order. Opening\n * the Sheet closes the Listbox, so one left open behind a window narrowed\n * past the breakpoint does not stay open beside it; a Sheet open when the\n * window widens stays until chosen from or dismissed.\n *\n * The Sheet's list is a listbox of option buttons: the chosen one (or the\n * first) takes the Dialog's first focus and is the one in the tab order, the\n * arrows, Home and End move focus between them, and Enter, Space or a tap\n * chooses, which closes the Sheet and gives focus back to the opener. An\n * option's content and the trigger's are `Listbox.parts`', in the Listbox's\n * slots.\n */\nimport * as UiDialog from '@foldkit/ui/dialog'\nimport * as UiListbox from '@foldkit/ui/listbox'\nimport { Effect, Option, Schema } from 'effect'\nimport { Attr, Capability, Event, Slot, Slots, SlotView, type NamedStyle } from 'foldkit-mixins'\nimport * as Command from 'foldkit/command'\nimport * as Dom from 'foldkit/dom'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport { defineMessageUnion } from 'foldkit/message'\nimport { modifyFields } from 'foldkit/struct'\nimport type { ReturnWithOutMessage } from 'foldkit/update'\nimport type { ResolvedDialog } from './dialog.js'\nimport { idSelector } from './datePickerUtils.js'\nimport * as Listbox from './listbox.js'\nimport * as ListboxView from './listboxView.js'\nimport type { MixinList } from './resolve.js'\nimport * as Sheet from './sheet.js'\n\nexport const PickerSlots = Slots.define({\n root: Slot.make({ capability: Capability.Container }),\n /** The desktop's half: the Listbox, its trigger and its panel. */\n dropdown: Slot.make({ capability: Capability.Container }),\n /** The phone's half: the button that opens the Sheet. */\n opener: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click],\n attributes: [Attr.AriaExpanded, Attr.AriaLabel],\n }),\n /** The Sheet's options. */\n list: Slot.make({ capability: Capability.Container, attributes: [Attr.Role] }),\n option: Slot.make({\n capability: Capability.Interactive,\n events: [Event.Click, Event.KeyDown],\n attributes: [Attr.Role, Attr.AriaSelected],\n }),\n})\n\nexport const Model = Schema.Struct({\n id: Schema.String,\n /** The desktop's dropdown: which row is active, whether it is open. */\n listbox: UiListbox.Model,\n /** The phone's sheet. */\n sheet: Sheet.Model,\n})\nexport type Model = typeof Model.Type\n\nexport const Message = defineMessageUnion({\n GotListbox: { message: UiListbox.Message },\n GotSheet: { message: Sheet.Message },\n OpenedSheet: {},\n ChoseInSheet: { value: Schema.String },\n /** A key moved focus to the Sheet's option at `to`. */\n Stepped: { to: Schema.Number },\n CompletedFocus: {},\n})\nexport type Message = typeof Message.Type\n\nexport const OutMessage = defineMessageUnion({\n /** An option was chosen, in the dropdown or in the Sheet. */\n Chose: { value: Schema.String },\n})\nexport type OutMessage = typeof OutMessage.Type\n\nexport interface InitConfig {\n /** Prefixes the ids the picker draws, unique on the page. */\n readonly id: string\n /** The phone's Sheet, beside its id: points, swipe, animation. It comes from the bottom. */\n readonly sheet?: Omit<Sheet.InitConfig, 'id' | 'side'>\n}\n\n/** A closed picker. */\nexport const init = (config: InitConfig): Model => ({\n id: config.id,\n listbox: UiListbox.init({ id: `${config.id}-listbox` }),\n sheet: Sheet.init({ ...config.sheet, id: `${config.id}-sheet`, side: 'bottom' }),\n})\n\n/** The id of the Sheet's option at `index`. */\nexport const optionId = (id: string, index: number): string => `${id}-option-${index}`\n\n/** Upstream's Listbox `update` with this package's view, over the picker's options. */\nconst Dropdown = ListboxView.create<PickerOption<string>, string>()\n\nconst Focus = Command.define('FocusPickerOption', {\n args: { selector: Schema.String },\n messages: [Message.CompletedFocus],\n execute: ({ selector }) =>\n Dom.focus(selector).pipe(Effect.ignore, Effect.as(Message.CompletedFocus())),\n})\n\nexport type Return = ReturnWithOutMessage<Model, Message, OutMessage>\n\nconst listboxStep = (\n model: Model,\n next: ReturnWithOutMessage<UiListbox.Model, UiListbox.Message, UiListbox.OutMessage>,\n): Return => ({\n model: next.model === model.listbox ? model : modifyFields(model, { listbox: () => next.model }),\n commands: Command.mapMessages(next.commands ?? [], message => Message.GotListbox({ message })),\n ...(next.outMessage === undefined\n ? {}\n : { outMessage: OutMessage.Chose({ value: next.outMessage.value }) }),\n})\n\nconst sheetStep = (model: Model, next: Sheet.Return): Return => ({\n model: next.model === model.sheet ? model : modifyFields(model, { sheet: () => next.model }),\n commands: Command.mapMessages(next.commands ?? [], message => Message.GotSheet({ message })),\n})\n\n/** The picker after `message`; the same Model when nothing changes. */\nexport const update = (model: Model, message: Message): Return =>\n Message.match(message, {\n GotListbox: ({ message }) => listboxStep(model, Dropdown.update(model.listbox, message)),\n GotSheet: ({ message }) => sheetStep(model, Sheet.update(model.sheet, message)),\n OpenedSheet: () => {\n const closed = model.listbox.isOpen\n ? listboxStep(model, Dropdown.close(model.listbox))\n : { model, commands: [] }\n const opened = sheetStep(closed.model, Sheet.open(closed.model.sheet))\n return {\n model: opened.model,\n commands: [...(closed.commands ?? []), ...(opened.commands ?? [])],\n }\n },\n ChoseInSheet: ({ value }) => ({\n ...sheetStep(model, Sheet.close(model.sheet)),\n outMessage: OutMessage.Chose({ value }),\n }),\n Stepped: ({ to }) => ({\n model,\n commands: [Focus({ selector: idSelector(optionId(model.id, to)) })],\n }),\n CompletedFocus: () => ({ model }),\n })\n\n/** An option: its value, and what it shows in the list and on the trigger. */\nexport interface PickerOption<Value extends string> extends Listbox.OptionContent {\n readonly value: Value\n}\n\nexport interface PickerView<Value extends string, Outer> {\n readonly model: Model\n readonly onMessage: (message: Message) => NoInfer<Outer>\n /** Names the control, and titles the Sheet. */\n readonly label: string\n readonly options: ReadonlyArray<PickerOption<Value>>\n /** The chosen value, which the application keeps. */\n readonly value: Option.Option<NoInfer<Value>>\n /** Shown on the trigger while nothing is chosen. */\n readonly placeholder: string\n /** Where the dropdown's panel opens; default below the trigger's start, kept in place. */\n readonly anchor?: UiListbox.AnchorConfig\n /** A style of `PickerSlots` (`Recipes.Picker`). */\n readonly style?: NamedStyle<typeof PickerSlots> | undefined\n /** Mixins beside the style. */\n readonly mixins?: MixinList<Outer> | undefined\n /** The Listbox's style and mixins (`Recipes.Listbox`), which also draw the options' and the trigger's content. */\n readonly listbox?: MixinList<Outer> | undefined\n /** The Sheet's style and mixins (`Recipes.Sheet`), on `DialogSlots`. */\n readonly sheet?: MixinList<Outer> | undefined\n}\n\n/** Where a key moves focus from the option at `index` of `count`, if it is one that moves it. */\nconst stepped = (key: string, index: number, count: number): Option.Option<number> => {\n if (key === 'Home') return Option.some(0)\n if (key === 'End') return Option.some(count - 1)\n if (key === 'ArrowDown') return Option.some(Math.min(count - 1, index + 1))\n if (key === 'ArrowUp') return Option.some(Math.max(0, index - 1))\n return Option.none()\n}\n\n/** The picker: the dropdown and the opener, one shown by the style, and the Sheet. */\nexport const view = <Value extends string, Outer>(\n options: PickerView<Value, Outer>,\n h: HtmlBuilder<Outer>,\n): Html => {\n const { model, onMessage, value } = options\n const builders = SlotView.buildersFor(\n PickerSlots,\n [...(options.style === undefined ? [] : [options.style.mixin]), ...(options.mixins ?? [])],\n { input: undefined, h },\n )\n const listboxMixins = options.listbox ?? []\n const part = Listbox.parts(listboxMixins, { h })\n const chosen = Option.flatMap(value, current =>\n Option.fromNullishOr(options.options.find(option => option.value === current)),\n )\n const trigger = part.trigger(chosen, options.placeholder)\n const choices = options.options\n const focused = Math.max(\n 0,\n choices.findIndex(option => Option.contains(value, option.value)),\n )\n // Both triggers say what they choose and what is chosen.\n const named = `${options.label}: ${Option.match(chosen, {\n onNone: () => options.placeholder,\n onSome: option => option.label,\n })}`\n return h.div(builders.root.attrs(), [\n h.div(builders.dropdown.attrs(), [\n h.submodel({\n slotId: model.listbox.id,\n model: model.listbox,\n view: Dropdown.view,\n viewInputs: {\n anchor: options.anchor ?? {\n placement: 'bottom-start',\n gap: 4,\n padding: 8,\n portal: false,\n },\n items: choices,\n itemToValue: (option: PickerOption<string>) => option.value,\n maybeSelectedValue: value,\n ariaLabel: named,\n itemToConfig: (option: PickerOption<string>) => ({ content: part.option(option) }),\n buttonContent: trigger,\n toView: Listbox.toView(listboxMixins, { h }),\n },\n toParentMessage: message => onMessage(Message.GotListbox({ message })),\n }),\n ]),\n h.button(\n builders.opener.attrs([\n h.Type('button'),\n h.AriaHasPopup('dialog'),\n h.AriaExpanded(Sheet.isOpen(model.sheet)),\n h.AriaLabel(named),\n h.OnClick(onMessage(Message.OpenedSheet())),\n ]),\n [trigger],\n ),\n Sheet.view(\n {\n model: model.sheet,\n onMessage: message => onMessage(Message.GotSheet({ message })),\n mixins: options.sheet ?? [],\n draw: (dialog: ResolvedDialog<Outer>) =>\n h.dialog(\n dialog.dialog,\n dialog.isVisible\n ? [\n h.div(dialog.backdrop),\n h.div(dialog.panel, [\n h.div(dialog.handle),\n h.h2(dialog.title, [options.label]),\n h.div(\n builders.list.attrs([\n h.Role('listbox'),\n h.AriaLabelledBy(UiDialog.titleId(model.sheet.dialog)),\n ]),\n choices.map((option, index) =>\n h.keyed('button')(\n option.value,\n builders.option.attrs([\n h.Type('button'),\n h.Id(optionId(model.id, index)),\n h.Role('option'),\n h.AriaSelected(Option.contains(value, option.value)),\n h.Tabindex(index === focused ? 0 : -1),\n ...(index === focused ? dialog.initialFocus : []),\n h.OnClick(onMessage(Message.ChoseInSheet({ value: option.value }))),\n h.OnKeyDownPreventDefault(key =>\n Option.map(stepped(key, index, choices.length), to =>\n onMessage(Message.Stepped({ to })),\n ),\n ),\n ]),\n [part.option(option)],\n ),\n ),\n ),\n ]),\n ]\n : [],\n ),\n },\n h,\n ),\n ])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,cAAc,MAAM,OAAO;CACtC,MAAM,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;;CAEpD,UAAU,KAAK,KAAK,EAAE,YAAY,WAAW,UAAU,CAAC;;CAExD,QAAQ,KAAK,KAAK;EAChB,YAAY,WAAW;EACvB,QAAQ,CAAC,MAAM,KAAK;EACpB,YAAY,CAAC,KAAK,cAAc,KAAK,SAAS;CAChD,CAAC;;CAED,MAAM,KAAK,KAAK;EAAE,YAAY,WAAW;EAAW,YAAY,CAAC,KAAK,IAAI;CAAE,CAAC;CAC7E,QAAQ,KAAK,KAAK;EAChB,YAAY,WAAW;EACvB,QAAQ,CAAC,MAAM,OAAO,MAAM,OAAO;EACnC,YAAY,CAAC,KAAK,MAAM,KAAK,YAAY;CAC3C,CAAC;AACH,CAAC;AAED,MAAa,QAAQ,OAAO,OAAO;CACjC,IAAI,OAAO;;CAEX,SAAS,UAAU;;CAEnB,OAAO,MAAM;AACf,CAAC;AAGD,MAAa,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AAO,IAAI,QAAQ,KAAK,OAAO,QAAQ,MAAM,IAAG,OAC9C,UAAU,QAAQ,QAAQ,EAAE,GAAG,CAAC,CAAC,CACnC,CACF;IACF,CAAC,GACD,CAAC,KAAK,OAAO,MAAM,CAAC,CACtB,CACF,CACF;GACF,CAAC,CACH,IACA,CAAC,CACP;EACJ,GACA,CACF;CACF,CAAC;AACH"}
|
package/dist/recipes/tabs.d.ts
CHANGED
|
@@ -33,7 +33,14 @@ export declare const Tabs: import("foldkit-mixins").SlotRecipe<import("foldkit-m
|
|
|
33
33
|
tablist: import("foldkit-mixins").StyleValue;
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
+
selection: {
|
|
37
|
+
raised: {};
|
|
38
|
+
tint: {};
|
|
39
|
+
};
|
|
36
40
|
overflow: {
|
|
41
|
+
wrap: {
|
|
42
|
+
tablist: import("foldkit-mixins").StyleValue;
|
|
43
|
+
};
|
|
37
44
|
scroll: {
|
|
38
45
|
tablist: import("foldkit-mixins").StyleValue;
|
|
39
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.d.ts","names":[],"sources":["../../src/recipes/tabs.ts"],"mappings":"A,
|
|
1
|
+
{"version":3,"file":"tabs.d.ts","names":[],"sources":["../../src/recipes/tabs.ts"],"mappings":"A,qBAkFa,+BAAI,oCAAA;;;;;;;;;;;;IA6GX;MACE,kCAAO;MAmBP,8BAAG;MAYH,oCAAS;;IAgBX;MACE,kCAAO;MAYP,8BAAG;MAKH,oCAAS;MAYT,oCAAS;;;;IAYX;MAAM,kCAAO;;IACb;MAAM,kCAAO;;IACb;MAAM,kCAAO;;;;IAIb;IACA;;;IAKA;MACE,kCAAO;;IAST;MACE,kCAAO"}
|
package/dist/recipes/tabs.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Style } from "foldkit-mixins";
|
|
2
2
|
import { TabsSlots } from "../tabs.js";
|
|
3
|
-
import { ladder, nested, nests } from "foldkit-mixins/theme";
|
|
3
|
+
import { ladder, nested, nests, raise, raisedSurface } from "foldkit-mixins/theme";
|
|
4
4
|
import { Utilities } from "foldkit-mixins/utilities";
|
|
5
|
-
import { component, disabled, focusRing, glide, heldHighlight, hover, onLadder, ref, steps, transition, trimmed, unfilledHover, variant } from "./design.js";
|
|
5
|
+
import { component, controlHeight, disabled, focusRing, glide, heldHighlight, hover, onLadder, ref, steps, transition, trimmed, unfilledHover, variant } from "./design.js";
|
|
6
6
|
// src/recipes/tabs.ts
|
|
7
7
|
/**
|
|
8
8
|
* Tabs: the selected tab is `aria-selected`, which `@foldkit/ui` writes.
|
|
9
9
|
* `variant` is an underline under a rule or a pill in a tray; `size` the
|
|
10
|
-
* tabs' step on the size ladder;
|
|
11
|
-
*
|
|
10
|
+
* tabs' step on the size ladder; the pill's `selection` is a `raised` surface
|
|
11
|
+
* (default) or the accent's `tint`; `overflow: 'scroll'` keeps a long row on
|
|
12
|
+
* one line, scrolled, its edges fading where more lies past them, and `'wrap'`
|
|
13
|
+
* lets it fall to more rows so no tab is cut off. Drawn with
|
|
12
14
|
* its `indicator` and `highlight`, and given `Tabs.fluid`, the underline or
|
|
13
15
|
* pill glides to the chosen tab and a hover follows the pointer; until
|
|
14
16
|
* `Tabs.fluid` runs, the chosen tab marks itself. A vertical tablist
|
|
@@ -29,6 +31,23 @@ const upright = "[aria-orientation=\"vertical\"]";
|
|
|
29
31
|
const vertical = `:where(${upright})`;
|
|
30
32
|
/** A vertical tablist right to left, whose inline end is the left. */
|
|
31
33
|
const verticalRtl = `:where(${upright}:dir(rtl))`;
|
|
34
|
+
/**
|
|
35
|
+
* The chosen pill's lift: a contact shadow in black (mixed from the text it
|
|
36
|
+
* would glow in a dark scheme), which holds where `shadow-strength` is its
|
|
37
|
+
* default 0 and the theme's own `shadow.xs` draws nothing; that shadow on top;
|
|
38
|
+
* and a hairline ring, a step stronger in a dark scheme, where the chip's fill
|
|
39
|
+
* is only a little lighter than its tray.
|
|
40
|
+
*/
|
|
41
|
+
const raisedEdge = `0 1px 2px 0 color-mix(in oklch, black 14%, transparent), ${ref.shadow.xs}, 0 0 0 ${ref.border.thin} light-dark(${ref.outline.default}, ${ref.outline.overt})`;
|
|
42
|
+
/**
|
|
43
|
+
* The narrowest a wrapping row's tabs go before it falls to fewer columns,
|
|
44
|
+
* on the tabs' size step: a short label ("Themes") and its padding.
|
|
45
|
+
* A private property of the recipe, not a token: an app tunes one row with
|
|
46
|
+
* `Recipes.Tabs.extend({ base: { tablist: Style.self({ '--_fk-tab-min': '8rem' }) } })`.
|
|
47
|
+
*/
|
|
48
|
+
const TAB_MIN = "--_fk-tab-min";
|
|
49
|
+
const tabMin = `var(${TAB_MIN})`;
|
|
50
|
+
const trayPadding = `calc(${ref.space["2xs"]} * 0.75)`;
|
|
32
51
|
const hovered = (part) => `var(--fk-tabs-hover-${part})`;
|
|
33
52
|
const chosen = (part) => part === "display" ? "var(--fk-tabs-chosen-display, none)" : `var(--fk-tabs-chosen-${part})`;
|
|
34
53
|
const overlay = {
|
|
@@ -43,7 +62,8 @@ const Tabs = Style.recipeFor(TabsSlots)({
|
|
|
43
62
|
position: "relative",
|
|
44
63
|
display: "flex",
|
|
45
64
|
gap: ref.space["2xs"],
|
|
46
|
-
isolation: "isolate"
|
|
65
|
+
isolation: "isolate",
|
|
66
|
+
[TAB_MIN]: `calc(${controlHeight} * 3)`
|
|
47
67
|
}), Style.pseudo(upright, {
|
|
48
68
|
flexDirection: "column",
|
|
49
69
|
alignItems: "stretch",
|
|
@@ -145,18 +165,17 @@ const Tabs = Style.recipeFor(TabsSlots)({
|
|
|
145
165
|
pill: {
|
|
146
166
|
tablist: variant(Style.self({
|
|
147
167
|
inlineSize: "fit-content",
|
|
148
|
-
padding:
|
|
149
|
-
borderRadius: ref.radius.
|
|
168
|
+
padding: trayPadding,
|
|
169
|
+
borderRadius: ref.radius.xl,
|
|
150
170
|
background: ref.surface.muted,
|
|
151
|
-
...nests(ref.radius.
|
|
171
|
+
...nests(ref.radius.xl, trayPadding)
|
|
152
172
|
})),
|
|
153
|
-
tab: variant(Style.self({ borderRadius: nested() })
|
|
173
|
+
tab: variant(Style.self({ borderRadius: nested() })),
|
|
154
174
|
indicator: variant(Style.self({
|
|
155
175
|
inlineSize: chosen("w"),
|
|
156
176
|
blockSize: chosen("h"),
|
|
157
177
|
translate: `${chosen("x")} ${chosen("y")}`,
|
|
158
178
|
borderRadius: nested(),
|
|
159
|
-
background: ref.accent.subtle,
|
|
160
179
|
opacity: `calc(1 - 0.15 * ${hovered("shown")})`
|
|
161
180
|
})),
|
|
162
181
|
highlight: variant(Style.self({
|
|
@@ -171,17 +190,56 @@ const Tabs = Style.recipeFor(TabsSlots)({
|
|
|
171
190
|
md: { tablist: steps.md },
|
|
172
191
|
lg: { tablist: steps.lg }
|
|
173
192
|
},
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
193
|
+
selection: {
|
|
194
|
+
raised: {},
|
|
195
|
+
tint: {}
|
|
196
|
+
},
|
|
197
|
+
overflow: {
|
|
198
|
+
wrap: { tablist: variant(Style.self({
|
|
199
|
+
display: "grid",
|
|
200
|
+
gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${tabMin}), 1fr))`,
|
|
201
|
+
inlineSize: "100%"
|
|
202
|
+
})) },
|
|
203
|
+
scroll: { tablist: variant(Style.self({
|
|
204
|
+
maxInlineSize: "100%",
|
|
205
|
+
overflowX: "auto",
|
|
206
|
+
overscrollBehaviorInline: "contain",
|
|
207
|
+
scrollbarWidth: "none"
|
|
208
|
+
}), Style.at("@media (hover: hover) and (pointer: fine)", Style.compose(Style.self({
|
|
209
|
+
scrollbarWidth: "thin",
|
|
210
|
+
scrollbarColor: "transparent transparent"
|
|
211
|
+
}), Style.pseudo(":is(:hover, :focus-within)", { scrollbarColor: `${ref.outline.default} transparent` }))), Utilities.scrollFade("inline")) }
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
defaults: {
|
|
215
|
+
variant: "line",
|
|
216
|
+
selection: "raised"
|
|
183
217
|
},
|
|
184
|
-
|
|
218
|
+
compound: [{
|
|
219
|
+
when: {
|
|
220
|
+
variant: "pill",
|
|
221
|
+
selection: "raised"
|
|
222
|
+
},
|
|
223
|
+
style: {
|
|
224
|
+
tab: variant(raise(1), Style.nest(markedIn(unlit), {
|
|
225
|
+
background: raisedSurface(),
|
|
226
|
+
boxShadow: raisedEdge
|
|
227
|
+
})),
|
|
228
|
+
indicator: variant(raise(1), Style.self({
|
|
229
|
+
background: raisedSurface(),
|
|
230
|
+
boxShadow: raisedEdge
|
|
231
|
+
}))
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
when: {
|
|
235
|
+
variant: "pill",
|
|
236
|
+
selection: "tint"
|
|
237
|
+
},
|
|
238
|
+
style: {
|
|
239
|
+
tab: variant(Style.pseudo(selected, { color: ref.accent.ink }), Style.nest(markedIn(unlit), { background: ref.accent.subtle })),
|
|
240
|
+
indicator: variant(Style.self({ background: ref.accent.subtle }))
|
|
241
|
+
}
|
|
242
|
+
}]
|
|
185
243
|
});
|
|
186
244
|
export { Tabs };
|
|
187
245
|
|
package/dist/recipes/tabs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.js","names":[],"sources":["../../src/recipes/tabs.ts"],"sourcesContent":["/**\n * Tabs: the selected tab is `aria-selected`, which `@foldkit/ui` writes.\n * `variant` is an underline under a rule or a pill in a tray; `size` the\n * tabs' step on the size ladder; `overflow: 'scroll'` keeps a long row on\n * one line, scrolled, its edges fading where more lies past them. Drawn with\n * its `indicator` and `highlight`, and given `Tabs.fluid`, the underline or\n * pill glides to the chosen tab and a hover follows the pointer; until\n * `Tabs.fluid` runs, the chosen tab marks itself. A vertical tablist\n * (`aria-orientation`, upstream's `orientation: 'Vertical'`) stacks its tabs\n * and draws its rule and underline at the inline end.\n */\nimport { Style } from 'foldkit-mixins'\nimport { ladder, nested, nests } from 'foldkit-mixins/theme'\nimport { Utilities } from 'foldkit-mixins/utilities'\nimport { TabsSlots } from '../tabs.js'\nimport {\n component,\n disabled,\n focusRing,\n glide,\n heldHighlight,\n hover,\n onLadder,\n ref,\n steps,\n transition,\n trimmed,\n unfilledHover,\n variant,\n} from './design.js'\n\nconst selected = '[aria-selected=\"true\"]'\n/** Where `Tabs.fluid` runs; a tablist marks it while its highlight follows the pointer. */\nconst fluid = ':where([data-fluid-hover]) > &'\n/**\n * A chosen tab marks itself until `Tabs.fluid` moves the indicator: the\n * tablist's own child, or its `item`'s, so a closable tab's item does not\n * pass for a tablist without the Mount.\n */\nconst markedIn = (tablist: string) =>\n `:where(${tablist}) > &${selected}, :where(${tablist}) > * > &${selected}`\nconst unlit = '[role=\"tablist\"]:not([data-fluid-hover])'\nconst upright = '[aria-orientation=\"vertical\"]'\nconst vertical = `:where(${upright})`\n/** A vertical tablist right to left, whose inline end is the left. */\nconst verticalRtl = `:where(${upright}:dir(rtl))`\n\nconst hovered = (part: 'x' | 'y' | 'w' | 'h' | 'shown' | 'moving') => `var(--fk-tabs-hover-${part})`\nconst chosen = (part: 'x' | 'y' | 'w' | 'h' | 'display') =>\n part === 'display' ? 'var(--fk-tabs-chosen-display, none)' : `var(--fk-tabs-chosen-${part})`\n\nconst overlay = {\n position: 'absolute',\n // Physical: the Mounts measure from the left, in either direction.\n top: '0',\n left: '0',\n pointerEvents: 'none',\n} as const\n\nexport const Tabs = Style.recipeFor(TabsSlots)({\n base: {\n tablist: component(\n Style.self({\n position: 'relative',\n display: 'flex',\n gap: ref.space['2xs'],\n isolation: 'isolate',\n }),\n // As wide as its widest tab, so the rule at its end stays beside them.\n Style.pseudo(upright, {\n flexDirection: 'column',\n alignItems: 'stretch',\n inlineSize: 'fit-content',\n }),\n ),\n // A closable tab and its close button, the button over the tab's end; a grid, so the tab fills it.\n item: component(Style.self({ position: 'relative', display: 'grid', flexShrink: '0' })),\n indicator: component(\n Style.self({\n ...overlay,\n display: 'none',\n zIndex: '-1',\n ...glide('moderate', '1'),\n }),\n Style.nest(fluid, { display: chosen('display') }),\n ),\n highlight: component(\n Style.self({\n ...overlay,\n display: 'none',\n zIndex: '-1',\n inlineSize: hovered('w'),\n blockSize: hovered('h'),\n translate: `${hovered('x')} ${hovered('y')}`,\n opacity: hovered('shown'),\n borderRadius: ref.radius.md,\n background: unfilledHover,\n ...glide('fast', hovered('moving')),\n }),\n Style.nest(fluid, { display: 'block' }),\n heldHighlight,\n ),\n tab: component(\n Style.self({\n position: 'relative',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n flexShrink: '0',\n ...onLadder,\n whiteSpace: 'nowrap',\n border: '0',\n background: 'transparent',\n color: ref.text.muted,\n font: 'inherit',\n fontWeight: ref.weight.medium,\n cursor: 'pointer',\n ...transition('background-color, color, box-shadow'),\n }),\n hover({ color: ref.text.overt }),\n Style.pseudo(selected, { color: ref.text.overt }),\n // Room at its end for the close button laid over it, inside what the indicator marks.\n Style.pseudo('[data-closable]', {\n paddingInlineEnd: `calc(${ladder('pad')} + ${ladder('icon')} + ${ladder('gap')})`,\n }),\n Style.nest(`${vertical} > &, ${vertical} > * > &`, { justifyContent: 'flex-start' }),\n focusRing,\n disabled,\n ),\n // The words trimmed in a block of their own: the tab is a flex row, where a trim does nothing.\n label: component(Style.self({ display: 'block', ...trimmed })),\n icon: component(\n Style.self({\n display: 'inline-flex',\n flexShrink: '0',\n inlineSize: ladder('icon'),\n blockSize: ladder('icon'),\n }),\n ),\n // A cross drawn in CSS: two diagonal bars, so the button's own box and hover stay square.\n close: component(\n Style.self({\n position: 'absolute',\n insetBlock: '0',\n insetInlineEnd: `calc(${ladder('pad')} - ${ref.space['3xs']})`,\n marginBlock: 'auto',\n inlineSize: `calc(${ladder('icon')} + 2 * ${ref.space['3xs']})`,\n blockSize: `calc(${ladder('icon')} + 2 * ${ref.space['3xs']})`,\n padding: '0',\n border: '0',\n borderRadius: ref.radius.sm,\n background: [45, -45]\n .map(\n turn =>\n `linear-gradient(${turn}deg, transparent calc(50% - ${ref.border.thin}), currentColor 0 calc(50% + ${ref.border.thin}), transparent 0) center / 40% 40% no-repeat`,\n )\n .join(', '),\n color: ref.text.muted,\n cursor: 'pointer',\n ...transition('background-color, color'),\n }),\n hover({ backgroundColor: unfilledHover, color: ref.text.overt }),\n ),\n panel: component(Style.self({ paddingBlock: ref.space.md })),\n },\n variants: {\n variant: {\n line: {\n tablist: variant(\n // A background, not an inset shadow: it lies in the padding box,\n // so a scrolling row's bar sits under the rule, not between the\n // rule and the chosen tab's.\n Style.self({\n backgroundImage: `linear-gradient(${ref.outline.default}, ${ref.outline.default})`,\n backgroundSize: `100% ${ref.border.thin}`,\n backgroundPosition: 'bottom',\n backgroundRepeat: 'no-repeat',\n }),\n // Upright, the rule runs down the inline end.\n Style.pseudo(upright, {\n backgroundImage: 'none',\n boxShadow: `inset calc(-1 * ${ref.border.thin}) 0 0 ${ref.outline.default}`,\n }),\n Style.pseudo(`${upright}:dir(rtl)`, {\n boxShadow: `inset ${ref.border.thin} 0 0 ${ref.outline.default}`,\n }),\n ),\n tab: variant(\n Style.nest(markedIn(unlit), {\n boxShadow: `inset 0 calc(-1 * ${ref.border.thick}) 0 ${ref.accent.default}`,\n }),\n Style.nest(markedIn(`${unlit}${upright}`), {\n boxShadow: `inset calc(-1 * ${ref.border.thick}) 0 0 ${ref.accent.default}`,\n }),\n Style.nest(markedIn(`${unlit}${upright}:dir(rtl)`), {\n boxShadow: `inset ${ref.border.thick} 0 0 ${ref.accent.default}`,\n }),\n ),\n // A rule under the chosen tab, at its foot.\n indicator: variant(\n Style.self({\n inlineSize: chosen('w'),\n blockSize: ref.border.thick,\n translate: `${chosen('x')} calc(${chosen('y')} + ${chosen('h')} - ${ref.border.thick})`,\n background: ref.accent.default,\n }),\n // Upright, a rule beside the chosen tab, at its inline end.\n Style.nest(`${vertical} > &`, {\n inlineSize: ref.border.thick,\n blockSize: chosen('h'),\n translate: `calc(${chosen('x')} + ${chosen('w')} - ${ref.border.thick}) ${chosen('y')}`,\n }),\n Style.nest(`${verticalRtl} > &`, { translate: `${chosen('x')} ${chosen('y')}` }),\n ),\n },\n pill: {\n tablist: variant(\n Style.self({\n inlineSize: 'fit-content',\n padding: ref.space['3xs'],\n borderRadius: ref.radius.lg,\n background: ref.surface.muted,\n // The tabs, the chosen pill and the hover take their corners from these.\n ...nests(ref.radius.lg, ref.space['3xs']),\n }),\n ),\n tab: variant(\n // Concentric with the tray's corner, inside its padding.\n Style.self({ borderRadius: nested() }),\n // The accent's tint and ink, as a pressed Segmented option: the base\n // surface on the tray barely differed from it in a dark scheme.\n Style.pseudo(selected, { color: ref.accent.ink }),\n Style.nest(markedIn(unlit), { background: ref.accent.subtle }),\n ),\n // The chosen tab's pill, under it; it dims while another tab is hovered.\n indicator: variant(\n Style.self({\n inlineSize: chosen('w'),\n blockSize: chosen('h'),\n translate: `${chosen('x')} ${chosen('y')}`,\n // The tab's own corner, so the pill meets the tab it marks.\n borderRadius: nested(),\n background: ref.accent.subtle,\n opacity: `calc(1 - 0.15 * ${hovered('shown')})`,\n }),\n ),\n // The hover, in the pill's corner; `surface.hover` chooses its ink (the\n // accent's, for a hover that tries the chosen pill on).\n highlight: variant(\n Style.self({\n borderRadius: nested(),\n background: unfilledHover,\n opacity: hovered('shown'),\n }),\n // Beside the fill it deepens, since a variant's own rule beats the base's held one.\n heldHighlight,\n ),\n },\n },\n size: {\n sm: { tablist: steps.sm },\n md: { tablist: steps.md },\n lg: { tablist: steps.lg },\n },\n overflow: {\n // Past the row's width the tabs scroll, as a browser's tab strip; none shrinks or wraps.\n scroll: {\n tablist: variant(\n Style.self({\n maxInlineSize: '100%',\n overflowX: 'auto',\n overscrollBehaviorInline: 'contain',\n scrollbarWidth: 'none',\n }),\n // A mouse has no swipe to scroll by: a thin bar to drag, its room kept\n // so nothing moves, and its thumb shown only while the row is hovered or focused.\n Style.at(\n '@media (hover: hover) and (pointer: fine)',\n Style.compose(\n Style.self({ scrollbarWidth: 'thin', scrollbarColor: 'transparent transparent' }),\n Style.pseudo(':is(:hover, :focus-within)', {\n scrollbarColor: `${ref.outline.default} transparent`,\n }),\n ),\n ),\n Utilities.scrollFade('inline'),\n ),\n },\n },\n },\n defaults: { variant: 'line' },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,MAAM,WAAW;;AAEjB,MAAM,QAAQ;;;;;;AAMd,MAAM,YAAY,YAChB,UAAU,QAAQ,OAAO,SAAS,WAAW,QAAQ,WAAW;AAClE,MAAM,QAAQ;AACd,MAAM,UAAU;AAChB,MAAM,WAAW,UAAU,QAAQ;;AAEnC,MAAM,cAAc,UAAU,QAAQ;AAEtC,MAAM,WAAW,SAAqD,uBAAuB,KAAK;AAClG,MAAM,UAAU,SACd,SAAS,YAAY,wCAAwC,wBAAwB,KAAK;AAE5F,MAAM,UAAU;CACd,UAAU;CAEV,KAAK;CACL,MAAM;CACN,eAAe;AACjB;AAEA,MAAa,OAAO,MAAM,UAAU,SAAS,CAAC,CAAC;CAC7C,MAAM;EACJ,SAAS,UACP,MAAM,KAAK;GACT,UAAU;GACV,SAAS;GACT,KAAK,IAAI,MAAM;GACf,WAAW;EACb,CAAC,GAED,MAAM,OAAO,SAAS;GACpB,eAAe;GACf,YAAY;GACZ,YAAY;EACd,CAAC,CACH;EAEA,MAAM,UAAU,MAAM,KAAK;GAAE,UAAU;GAAY,SAAS;GAAQ,YAAY;EAAI,CAAC,CAAC;EACtF,WAAW,UACT,MAAM,KAAK;GACT,GAAG;GACH,SAAS;GACT,QAAQ;GACR,GAAG,MAAM,YAAY,GAAG;EAC1B,CAAC,GACD,MAAM,KAAK,OAAO,EAAE,SAAS,OAAO,SAAS,EAAE,CAAC,CAClD;EACA,WAAW,UACT,MAAM,KAAK;GACT,GAAG;GACH,SAAS;GACT,QAAQ;GACR,YAAY,QAAQ,GAAG;GACvB,WAAW,QAAQ,GAAG;GACtB,WAAW,GAAG,Q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F;EACF;EACA,MAAM;GACJ,IAAI,EAAE,SAAS,MAAM,GAAG;GACxB,IAAI,EAAE,SAAS,MAAM,GAAG;GACxB,IAAI,EAAE,SAAS,MAAM,GAAG;EAC1B;EACA,UAAU,EAER,QAAQ,EACN,SAAS,QACP,MAAM,KAAK;GACT,eAAe;GACf,WAAW;GACX,0BAA0B;GAC1B,gBAAgB;EAClB,CAAC,GAGD,MAAM,GACJ,6CACA,MAAM,QACJ,MAAM,KAAK;GAAE,gBAAgB;GAAQ,gBAAgB;EAA0B,CAAC,GAChF,MAAM,OAAO,8BAA8B,EACzC,gBAAgB,GAAG,IAAI,QAAQ,QAAQ,cACzC,CAAC,CACH,CACF,GACA,UAAU,WAAW,QAAQ,CAC/B,EACF,EACF;CACF;CACA,UAAU,EAAE,SAAS,OAAO;AAC9B,CAAC"}
|
|
1
|
+
{"version":3,"file":"tabs.js","names":[],"sources":["../../src/recipes/tabs.ts"],"sourcesContent":["/**\n * Tabs: the selected tab is `aria-selected`, which `@foldkit/ui` writes.\n * `variant` is an underline under a rule or a pill in a tray; `size` the\n * tabs' step on the size ladder; the pill's `selection` is a `raised` surface\n * (default) or the accent's `tint`; `overflow: 'scroll'` keeps a long row on\n * one line, scrolled, its edges fading where more lies past them, and `'wrap'`\n * lets it fall to more rows so no tab is cut off. Drawn with\n * its `indicator` and `highlight`, and given `Tabs.fluid`, the underline or\n * pill glides to the chosen tab and a hover follows the pointer; until\n * `Tabs.fluid` runs, the chosen tab marks itself. A vertical tablist\n * (`aria-orientation`, upstream's `orientation: 'Vertical'`) stacks its tabs\n * and draws its rule and underline at the inline end.\n */\nimport { Style } from 'foldkit-mixins'\nimport { ladder, nested, nests, raise, raisedSurface } from 'foldkit-mixins/theme'\nimport { Utilities } from 'foldkit-mixins/utilities'\nimport { TabsSlots } from '../tabs.js'\nimport {\n component,\n controlHeight,\n disabled,\n focusRing,\n glide,\n heldHighlight,\n hover,\n onLadder,\n ref,\n steps,\n transition,\n trimmed,\n unfilledHover,\n variant,\n} from './design.js'\n\nconst selected = '[aria-selected=\"true\"]'\n/** Where `Tabs.fluid` runs; a tablist marks it while its highlight follows the pointer. */\nconst fluid = ':where([data-fluid-hover]) > &'\n/**\n * A chosen tab marks itself until `Tabs.fluid` moves the indicator: the\n * tablist's own child, or its `item`'s, so a closable tab's item does not\n * pass for a tablist without the Mount.\n */\nconst markedIn = (tablist: string) =>\n `:where(${tablist}) > &${selected}, :where(${tablist}) > * > &${selected}`\nconst unlit = '[role=\"tablist\"]:not([data-fluid-hover])'\nconst upright = '[aria-orientation=\"vertical\"]'\nconst vertical = `:where(${upright})`\n/** A vertical tablist right to left, whose inline end is the left. */\nconst verticalRtl = `:where(${upright}:dir(rtl))`\n\n/**\n * The chosen pill's lift: a contact shadow in black (mixed from the text it\n * would glow in a dark scheme), which holds where `shadow-strength` is its\n * default 0 and the theme's own `shadow.xs` draws nothing; that shadow on top;\n * and a hairline ring, a step stronger in a dark scheme, where the chip's fill\n * is only a little lighter than its tray.\n */\nconst raisedEdge = `0 1px 2px 0 color-mix(in oklch, black 14%, transparent), ${ref.shadow.xs}, 0 0 0 ${ref.border.thin} light-dark(${ref.outline.default}, ${ref.outline.overt})`\n\n/**\n * The narrowest a wrapping row's tabs go before it falls to fewer columns,\n * on the tabs' size step: a short label (\"Themes\") and its padding.\n * A private property of the recipe, not a token: an app tunes one row with\n * `Recipes.Tabs.extend({ base: { tablist: Style.self({ '--_fk-tab-min': '8rem' }) } })`.\n */\nconst TAB_MIN = '--_fk-tab-min'\nconst tabMin = `var(${TAB_MIN})`\n\nconst trayPadding = `calc(${ref.space['2xs']} * 0.75)`\n\nconst hovered = (part: 'x' | 'y' | 'w' | 'h' | 'shown' | 'moving') => `var(--fk-tabs-hover-${part})`\nconst chosen = (part: 'x' | 'y' | 'w' | 'h' | 'display') =>\n part === 'display' ? 'var(--fk-tabs-chosen-display, none)' : `var(--fk-tabs-chosen-${part})`\n\nconst overlay = {\n position: 'absolute',\n // Physical: the Mounts measure from the left, in either direction.\n top: '0',\n left: '0',\n pointerEvents: 'none',\n} as const\n\nexport const Tabs = Style.recipeFor(TabsSlots)({\n base: {\n tablist: component(\n Style.self({\n position: 'relative',\n display: 'flex',\n gap: ref.space['2xs'],\n isolation: 'isolate',\n [TAB_MIN]: `calc(${controlHeight} * 3)`,\n }),\n // As wide as its widest tab, so the rule at its end stays beside them.\n Style.pseudo(upright, {\n flexDirection: 'column',\n alignItems: 'stretch',\n inlineSize: 'fit-content',\n }),\n ),\n // A closable tab and its close button, the button over the tab's end; a grid, so the tab fills it.\n item: component(Style.self({ position: 'relative', display: 'grid', flexShrink: '0' })),\n indicator: component(\n Style.self({\n ...overlay,\n display: 'none',\n zIndex: '-1',\n ...glide('moderate', '1'),\n }),\n Style.nest(fluid, { display: chosen('display') }),\n ),\n highlight: component(\n Style.self({\n ...overlay,\n display: 'none',\n zIndex: '-1',\n inlineSize: hovered('w'),\n blockSize: hovered('h'),\n translate: `${hovered('x')} ${hovered('y')}`,\n opacity: hovered('shown'),\n borderRadius: ref.radius.md,\n background: unfilledHover,\n ...glide('fast', hovered('moving')),\n }),\n Style.nest(fluid, { display: 'block' }),\n heldHighlight,\n ),\n tab: component(\n Style.self({\n position: 'relative',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n flexShrink: '0',\n ...onLadder,\n whiteSpace: 'nowrap',\n border: '0',\n background: 'transparent',\n color: ref.text.muted,\n font: 'inherit',\n fontWeight: ref.weight.medium,\n cursor: 'pointer',\n ...transition('background-color, color, box-shadow'),\n }),\n hover({ color: ref.text.overt }),\n Style.pseudo(selected, { color: ref.text.overt }),\n // Room at its end for the close button laid over it, inside what the indicator marks.\n Style.pseudo('[data-closable]', {\n paddingInlineEnd: `calc(${ladder('pad')} + ${ladder('icon')} + ${ladder('gap')})`,\n }),\n Style.nest(`${vertical} > &, ${vertical} > * > &`, { justifyContent: 'flex-start' }),\n focusRing,\n disabled,\n ),\n // The words trimmed in a block of their own: the tab is a flex row, where a trim does nothing.\n label: component(Style.self({ display: 'block', ...trimmed })),\n icon: component(\n Style.self({\n display: 'inline-flex',\n flexShrink: '0',\n inlineSize: ladder('icon'),\n blockSize: ladder('icon'),\n }),\n ),\n // A cross drawn in CSS: two diagonal bars, so the button's own box and hover stay square.\n close: component(\n Style.self({\n position: 'absolute',\n insetBlock: '0',\n insetInlineEnd: `calc(${ladder('pad')} - ${ref.space['3xs']})`,\n marginBlock: 'auto',\n inlineSize: `calc(${ladder('icon')} + 2 * ${ref.space['3xs']})`,\n blockSize: `calc(${ladder('icon')} + 2 * ${ref.space['3xs']})`,\n padding: '0',\n border: '0',\n borderRadius: ref.radius.sm,\n background: [45, -45]\n .map(\n turn =>\n `linear-gradient(${turn}deg, transparent calc(50% - ${ref.border.thin}), currentColor 0 calc(50% + ${ref.border.thin}), transparent 0) center / 40% 40% no-repeat`,\n )\n .join(', '),\n color: ref.text.muted,\n cursor: 'pointer',\n ...transition('background-color, color'),\n }),\n hover({ backgroundColor: unfilledHover, color: ref.text.overt }),\n ),\n panel: component(Style.self({ paddingBlock: ref.space.md })),\n },\n variants: {\n variant: {\n line: {\n tablist: variant(\n // A background, not an inset shadow: it lies in the padding box,\n // so a scrolling row's bar sits under the rule, not between the\n // rule and the chosen tab's.\n Style.self({\n backgroundImage: `linear-gradient(${ref.outline.default}, ${ref.outline.default})`,\n backgroundSize: `100% ${ref.border.thin}`,\n backgroundPosition: 'bottom',\n backgroundRepeat: 'no-repeat',\n }),\n // Upright, the rule runs down the inline end.\n Style.pseudo(upright, {\n backgroundImage: 'none',\n boxShadow: `inset calc(-1 * ${ref.border.thin}) 0 0 ${ref.outline.default}`,\n }),\n Style.pseudo(`${upright}:dir(rtl)`, {\n boxShadow: `inset ${ref.border.thin} 0 0 ${ref.outline.default}`,\n }),\n ),\n tab: variant(\n Style.nest(markedIn(unlit), {\n boxShadow: `inset 0 calc(-1 * ${ref.border.thick}) 0 ${ref.accent.default}`,\n }),\n Style.nest(markedIn(`${unlit}${upright}`), {\n boxShadow: `inset calc(-1 * ${ref.border.thick}) 0 0 ${ref.accent.default}`,\n }),\n Style.nest(markedIn(`${unlit}${upright}:dir(rtl)`), {\n boxShadow: `inset ${ref.border.thick} 0 0 ${ref.accent.default}`,\n }),\n ),\n // A rule under the chosen tab, at its foot.\n indicator: variant(\n Style.self({\n inlineSize: chosen('w'),\n blockSize: ref.border.thick,\n translate: `${chosen('x')} calc(${chosen('y')} + ${chosen('h')} - ${ref.border.thick})`,\n background: ref.accent.default,\n }),\n // Upright, a rule beside the chosen tab, at its inline end.\n Style.nest(`${vertical} > &`, {\n inlineSize: ref.border.thick,\n blockSize: chosen('h'),\n translate: `calc(${chosen('x')} + ${chosen('w')} - ${ref.border.thick}) ${chosen('y')}`,\n }),\n Style.nest(`${verticalRtl} > &`, { translate: `${chosen('x')} ${chosen('y')}` }),\n ),\n },\n pill: {\n tablist: variant(\n Style.self({\n inlineSize: 'fit-content',\n // Between the ladder's inset and the next space step: it reads as an inset, and\n // the chip keeps a corner in a theme with little radius.\n padding: trayPadding,\n borderRadius: ref.radius.xl,\n background: ref.surface.muted,\n // The tabs, the chosen pill and the hover take their corners from these.\n ...nests(ref.radius.xl, trayPadding),\n }),\n ),\n tab: variant(\n // Concentric with the tray's corner, inside its padding.\n Style.self({ borderRadius: nested() }),\n ),\n // The chosen tab's pill, under it; it dims while another tab is hovered.\n indicator: variant(\n Style.self({\n inlineSize: chosen('w'),\n blockSize: chosen('h'),\n translate: `${chosen('x')} ${chosen('y')}`,\n // The tab's own corner, so the pill meets the tab it marks.\n borderRadius: nested(),\n opacity: `calc(1 - 0.15 * ${hovered('shown')})`,\n }),\n ),\n // The hover, in the pill's corner; `surface.hover` chooses its ink (the\n // accent's, for a hover that tries the chosen pill on).\n highlight: variant(\n Style.self({\n borderRadius: nested(),\n background: unfilledHover,\n opacity: hovered('shown'),\n }),\n // Beside the fill it deepens, since a variant's own rule beats the base's held one.\n heldHighlight,\n ),\n },\n },\n size: {\n sm: { tablist: steps.sm },\n md: { tablist: steps.md },\n lg: { tablist: steps.lg },\n },\n // How the chosen pill is drawn; only the pill has one (see `compound`).\n selection: {\n raised: {},\n tint: {},\n },\n overflow: {\n // Every tab stays whole and the same width: a grid of equal columns that\n // fill the row, so six tabs are one row, then 3 + 3, then 2 x 3, never 5 + 1.\n wrap: {\n tablist: variant(\n Style.self({\n display: 'grid',\n gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${tabMin}), 1fr))`,\n inlineSize: '100%',\n }),\n ),\n },\n // Past the row's width the tabs scroll, as a browser's tab strip; none shrinks or wraps.\n scroll: {\n tablist: variant(\n Style.self({\n maxInlineSize: '100%',\n overflowX: 'auto',\n overscrollBehaviorInline: 'contain',\n scrollbarWidth: 'none',\n }),\n // A mouse has no swipe to scroll by: a thin bar to drag, its room kept\n // so nothing moves, and its thumb shown only while the row is hovered or focused.\n Style.at(\n '@media (hover: hover) and (pointer: fine)',\n Style.compose(\n Style.self({ scrollbarWidth: 'thin', scrollbarColor: 'transparent transparent' }),\n Style.pseudo(':is(:hover, :focus-within)', {\n scrollbarColor: `${ref.outline.default} transparent`,\n }),\n ),\n ),\n Utilities.scrollFade('inline'),\n ),\n },\n },\n },\n defaults: { variant: 'line', selection: 'raised' },\n compound: [\n {\n // A raised surface and its shadow, on the tray's muted one: the shadow and a\n // hairline keep it apart in a dark scheme, where the two surfaces are near.\n when: { variant: 'pill', selection: 'raised' },\n style: {\n tab: variant(\n raise(1),\n Style.nest(markedIn(unlit), { background: raisedSurface(), boxShadow: raisedEdge }),\n ),\n indicator: variant(\n raise(1),\n Style.self({ background: raisedSurface(), boxShadow: raisedEdge }),\n ),\n },\n },\n {\n // The accent's tint and ink, as a pressed Segmented option.\n when: { variant: 'pill', selection: 'tint' },\n style: {\n tab: variant(\n Style.pseudo(selected, { color: ref.accent.ink }),\n Style.nest(markedIn(unlit), { background: ref.accent.subtle }),\n ),\n indicator: variant(Style.self({ background: ref.accent.subtle })),\n },\n },\n ],\n})\n"],"mappings":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|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Published slot contracts and mixin adapters for @foldkit/ui, built on foldkit-mixins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foldkit",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"@foldkit/ui": "^0.170.0",
|
|
46
46
|
"effect": "^4.1.0",
|
|
47
47
|
"foldkit": "^0.170.0",
|
|
48
|
-
"foldkit-
|
|
49
|
-
"foldkit-
|
|
50
|
-
"foldkit-
|
|
48
|
+
"foldkit-mixins": "^0.23.0",
|
|
49
|
+
"foldkit-media": "^0.6.0",
|
|
50
|
+
"foldkit-primitives": "^0.18.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@effect/platform-browser": "^4.1.1",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"jsqr": "^1.4.0",
|
|
58
58
|
"tsdown": "^0.23.1",
|
|
59
59
|
"typescript": "7.0.2",
|
|
60
|
-
"foldkit-
|
|
61
|
-
"foldkit-
|
|
62
|
-
"foldkit-mixins": "0.
|
|
60
|
+
"foldkit-media": "0.6.0",
|
|
61
|
+
"foldkit-primitives": "0.18.0",
|
|
62
|
+
"foldkit-mixins": "0.23.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "node ../../scripts/declarations.mjs . && tsdown && node ../../scripts/declared-any.mjs .",
|