@krizaka/ui 3.4.0 → 3.6.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 +1 -0
- package/dist/app-shell.d.ts +24 -22
- package/dist/app-shell.js +9 -3
- package/dist/app-shell.js.map +1 -1
- package/dist/argument-card.js +3 -3
- package/dist/chat.d.ts +187 -0
- package/dist/chat.js +132 -0
- package/dist/chat.js.map +1 -0
- package/dist/chunk-3GODX3D6.js +25 -0
- package/dist/chunk-3GODX3D6.js.map +1 -0
- package/dist/chunk-ECSCA3CN.js +128 -0
- package/dist/chunk-ECSCA3CN.js.map +1 -0
- package/dist/chunk-F2GKFIYK.js +47 -0
- package/dist/chunk-F2GKFIYK.js.map +1 -0
- package/dist/{chunk-R6SDS7JM.js → chunk-ND3L5VHT.js} +25 -2
- package/dist/chunk-ND3L5VHT.js.map +1 -0
- package/dist/command.js +1 -1
- package/dist/data-table.js +20 -134
- package/dist/data-table.js.map +1 -1
- package/dist/dialog.js +7 -3
- package/dist/dialog.js.map +1 -1
- package/dist/loader.d.ts +21 -1
- package/dist/loader.js +7 -3
- package/dist/loader.js.map +1 -1
- package/dist/map.js +7 -1
- package/dist/map.js.map +1 -1
- package/dist/marketing-layout.d.ts +3 -9
- package/dist/marketing-layout.js +24 -7
- package/dist/marketing-layout.js.map +1 -1
- package/dist/match-dialog.d.ts +32 -0
- package/dist/match-dialog.js +168 -0
- package/dist/match-dialog.js.map +1 -0
- package/dist/native.d.ts +484 -106
- package/dist/native.js +1967 -1323
- package/dist/native.js.map +1 -1
- package/dist/page-hero.js +3 -3
- package/dist/photo-grid.d.ts +122 -0
- package/dist/photo-grid.js +94 -0
- package/dist/photo-grid.js.map +1 -0
- package/dist/skip-link.d.ts +15 -0
- package/dist/skip-link.js +10 -0
- package/dist/skip-link.js.map +1 -0
- package/dist/step-progress.d.ts +20 -0
- package/dist/step-progress.js +17 -0
- package/dist/step-progress.js.map +1 -0
- package/dist/swipe-deck.d.ts +183 -0
- package/dist/swipe-deck.js +144 -0
- package/dist/swipe-deck.js.map +1 -0
- package/dist/tag-selector.d.ts +26 -0
- package/dist/tag-selector.js +21 -0
- package/dist/tag-selector.js.map +1 -0
- package/dist/tree-view.d.ts +2 -0
- package/dist/tree-view.js.map +1 -1
- package/dist/verified-badge.d.ts +16 -0
- package/dist/verified-badge.js +23 -0
- package/dist/verified-badge.js.map +1 -0
- package/package.json +120 -8
- package/registry/achievement.json +2 -1
- package/registry/action-bar.json +2 -1
- package/registry/action-sheet.json +1 -0
- package/registry/activity-feed.json +2 -1
- package/registry/alert.json +2 -1
- package/registry/app-shell.json +27 -5
- package/registry/argument-card.json +2 -1
- package/registry/audio-player.json +2 -1
- package/registry/auth-layout.json +7 -2
- package/registry/avatar.json +2 -1
- package/registry/badge.json +2 -1
- package/registry/button.json +2 -1
- package/registry/card-grid.json +2 -1
- package/registry/card.json +2 -1
- package/registry/catalogue-page.json +5 -2
- package/registry/changelog-page.json +5 -2
- package/registry/chat.json +918 -0
- package/registry/checkbox.json +2 -1
- package/registry/chip-link.json +2 -1
- package/registry/chip.json +2 -1
- package/registry/choice-grid.json +2 -1
- package/registry/cn.json +1 -0
- package/registry/code-block.json +2 -1
- package/registry/combobox.json +2 -1
- package/registry/command.json +2 -1
- package/registry/component-page.json +5 -2
- package/registry/confirm-button.json +2 -1
- package/registry/contact-page.json +5 -2
- package/registry/continue-prompt.json +2 -1
- package/registry/countdown.json +2 -1
- package/registry/cta-panel.json +2 -1
- package/registry/dashboard-layout.json +5 -2
- package/registry/data-table.json +2 -1
- package/registry/date-picker.json +3 -2
- package/registry/decision-list.json +2 -1
- package/registry/description-list.json +2 -1
- package/registry/detail-layout.json +16 -2
- package/registry/dialog.json +10 -4
- package/registry/docs-article-page.json +16 -2
- package/registry/docs-hub-page.json +5 -2
- package/registry/docs-layout.json +2 -1
- package/registry/dropdown-menu.json +2 -1
- package/registry/empty-state.json +14 -2
- package/registry/error-page.json +5 -2
- package/registry/examples/chat/conversation.d.ts +4 -0
- package/registry/examples/chat/conversation.js +22 -0
- package/registry/examples/chat/conversation.tsx +21 -0
- package/registry/examples/chat/inbox.d.ts +4 -0
- package/registry/examples/chat/inbox.js +15 -0
- package/registry/examples/chat/inbox.tsx +12 -0
- package/registry/examples/chat/native/conversation.d.ts +4 -0
- package/registry/examples/chat/native/conversation.dark.png +0 -0
- package/registry/examples/chat/native/conversation.js +23 -0
- package/registry/examples/chat/native/conversation.light.png +0 -0
- package/registry/examples/chat/native/conversation.tsx +20 -0
- package/registry/examples/chat/native/inbox.d.ts +4 -0
- package/registry/examples/chat/native/inbox.dark.png +0 -0
- package/registry/examples/chat/native/inbox.js +16 -0
- package/registry/examples/chat/native/inbox.light.png +0 -0
- package/registry/examples/chat/native/inbox.tsx +13 -0
- package/registry/examples/detail-layout/checkout.d.ts +4 -0
- package/registry/examples/detail-layout/checkout.js +37 -0
- package/registry/examples/detail-layout/checkout.tsx +44 -0
- package/registry/examples/docs-article-page/faq.d.ts +4 -0
- package/registry/examples/docs-article-page/faq.js +31 -0
- package/registry/examples/docs-article-page/faq.tsx +40 -0
- package/registry/examples/empty-state/library.d.ts +4 -0
- package/registry/examples/empty-state/library.js +25 -0
- package/registry/examples/empty-state/library.tsx +20 -0
- package/registry/examples/loader/branded.d.ts +4 -0
- package/registry/examples/loader/branded.js +12 -0
- package/registry/examples/loader/branded.tsx +7 -0
- package/registry/examples/loader/native/branded.d.ts +4 -0
- package/registry/examples/loader/native/branded.dark.png +0 -0
- package/registry/examples/loader/native/branded.js +12 -0
- package/registry/examples/loader/native/branded.light.png +0 -0
- package/registry/examples/loader/native/branded.tsx +11 -0
- package/registry/examples/longform-page/case-study.d.ts +4 -0
- package/registry/examples/longform-page/case-study.js +41 -0
- package/registry/examples/longform-page/case-study.tsx +40 -0
- package/registry/examples/match-dialog/its-a-match.d.ts +4 -0
- package/registry/examples/match-dialog/its-a-match.js +29 -0
- package/registry/examples/match-dialog/its-a-match.tsx +25 -0
- package/registry/examples/match-dialog/native/its-a-match.d.ts +4 -0
- package/registry/examples/match-dialog/native/its-a-match.dark.png +0 -0
- package/registry/examples/match-dialog/native/its-a-match.js +28 -0
- package/registry/examples/match-dialog/native/its-a-match.light.png +0 -0
- package/registry/examples/match-dialog/native/its-a-match.tsx +22 -0
- package/registry/examples/photo-grid/native/profile-photos.d.ts +4 -0
- package/registry/examples/photo-grid/native/profile-photos.dark.png +0 -0
- package/registry/examples/photo-grid/native/profile-photos.js +27 -0
- package/registry/examples/photo-grid/native/profile-photos.light.png +0 -0
- package/registry/examples/photo-grid/native/profile-photos.tsx +24 -0
- package/registry/examples/photo-grid/profile-photos.d.ts +4 -0
- package/registry/examples/photo-grid/profile-photos.js +28 -0
- package/registry/examples/photo-grid/profile-photos.tsx +25 -0
- package/registry/examples/pull-to-refresh/native/branded.d.ts +4 -0
- package/registry/examples/pull-to-refresh/native/branded.dark.png +0 -0
- package/registry/examples/pull-to-refresh/native/branded.js +14 -0
- package/registry/examples/pull-to-refresh/native/branded.light.png +0 -0
- package/registry/examples/pull-to-refresh/native/branded.tsx +23 -0
- package/registry/examples/screen/native/app-shell.d.ts +4 -0
- package/registry/examples/screen/native/app-shell.dark.png +0 -0
- package/registry/examples/screen/native/app-shell.js +25 -0
- package/registry/examples/screen/native/app-shell.light.png +0 -0
- package/registry/examples/screen/native/app-shell.tsx +33 -0
- package/registry/examples/screen/native/auth.d.ts +4 -0
- package/registry/examples/screen/native/auth.dark.png +0 -0
- package/registry/examples/screen/native/auth.js +24 -0
- package/registry/examples/screen/native/auth.light.png +0 -0
- package/registry/examples/screen/native/auth.tsx +20 -0
- package/registry/examples/screen/native/chat.d.ts +4 -0
- package/registry/examples/screen/native/chat.dark.png +0 -0
- package/registry/examples/screen/native/chat.js +27 -0
- package/registry/examples/screen/native/chat.light.png +0 -0
- package/registry/examples/screen/native/chat.tsx +22 -0
- package/registry/examples/screen/native/feed.d.ts +4 -0
- package/registry/examples/screen/native/feed.dark.png +0 -0
- package/registry/examples/screen/native/feed.js +24 -0
- package/registry/examples/screen/native/feed.light.png +0 -0
- package/registry/examples/screen/native/feed.tsx +34 -0
- package/registry/examples/screen/native/map.d.ts +4 -0
- package/registry/examples/screen/native/map.dark.png +0 -0
- package/registry/examples/screen/native/map.js +26 -0
- package/registry/examples/screen/native/map.light.png +0 -0
- package/registry/examples/screen/native/map.tsx +31 -0
- package/registry/examples/screen/native/notifications.d.ts +4 -0
- package/registry/examples/screen/native/notifications.dark.png +0 -0
- package/registry/examples/screen/native/notifications.js +21 -0
- package/registry/examples/screen/native/notifications.light.png +0 -0
- package/registry/examples/screen/native/notifications.tsx +21 -0
- package/registry/examples/screen/native/profile.d.ts +4 -0
- package/registry/examples/screen/native/profile.dark.png +0 -0
- package/registry/examples/screen/native/profile.js +29 -0
- package/registry/examples/screen/native/profile.light.png +0 -0
- package/registry/examples/screen/native/profile.tsx +27 -0
- package/registry/examples/screen/native/settings.d.ts +4 -0
- package/registry/examples/screen/native/settings.dark.png +0 -0
- package/registry/examples/screen/native/settings.js +20 -0
- package/registry/examples/screen/native/settings.light.png +0 -0
- package/registry/examples/screen/native/settings.tsx +19 -0
- package/registry/examples/skip-link/default.d.ts +4 -0
- package/registry/examples/skip-link/default.js +19 -0
- package/registry/examples/skip-link/default.tsx +12 -0
- package/registry/examples/splash-handoff/native/default.d.ts +4 -0
- package/registry/examples/splash-handoff/native/default.dark.png +0 -0
- package/registry/examples/splash-handoff/native/default.js +12 -0
- package/registry/examples/splash-handoff/native/default.light.png +0 -0
- package/registry/examples/splash-handoff/native/default.tsx +11 -0
- package/registry/examples/split-view/nearby.d.ts +4 -0
- package/registry/examples/split-view/nearby.js +33 -0
- package/registry/examples/split-view/nearby.tsx +45 -0
- package/registry/examples/split-view/notifications.d.ts +4 -0
- package/registry/examples/split-view/notifications.js +33 -0
- package/registry/examples/split-view/notifications.tsx +31 -0
- package/registry/examples/status-page/maintenance.d.ts +4 -0
- package/registry/examples/status-page/maintenance.js +29 -0
- package/registry/examples/status-page/maintenance.tsx +24 -0
- package/registry/examples/step-progress/native/sign-up.d.ts +4 -0
- package/registry/examples/step-progress/native/sign-up.dark.png +0 -0
- package/registry/examples/step-progress/native/sign-up.js +12 -0
- package/registry/examples/step-progress/native/sign-up.light.png +0 -0
- package/registry/examples/step-progress/native/sign-up.tsx +11 -0
- package/registry/examples/step-progress/sign-up.d.ts +4 -0
- package/registry/examples/step-progress/sign-up.js +22 -0
- package/registry/examples/step-progress/sign-up.tsx +16 -0
- package/registry/examples/swipe-deck/discover.d.ts +4 -0
- package/registry/examples/swipe-deck/discover.js +41 -0
- package/registry/examples/swipe-deck/discover.tsx +37 -0
- package/registry/examples/swipe-deck/native/discover.d.ts +4 -0
- package/registry/examples/swipe-deck/native/discover.dark.png +0 -0
- package/registry/examples/swipe-deck/native/discover.js +39 -0
- package/registry/examples/swipe-deck/native/discover.light.png +0 -0
- package/registry/examples/swipe-deck/native/discover.tsx +35 -0
- package/registry/examples/tag-selector/interests.d.ts +4 -0
- package/registry/examples/tag-selector/interests.js +14 -0
- package/registry/examples/tag-selector/interests.tsx +12 -0
- package/registry/examples/tag-selector/native/interests.d.ts +4 -0
- package/registry/examples/tag-selector/native/interests.dark.png +0 -0
- package/registry/examples/tag-selector/native/interests.js +15 -0
- package/registry/examples/tag-selector/native/interests.light.png +0 -0
- package/registry/examples/tag-selector/native/interests.tsx +15 -0
- package/registry/examples/verified-badge/native/verified.d.ts +4 -0
- package/registry/examples/verified-badge/native/verified.dark.png +0 -0
- package/registry/examples/verified-badge/native/verified.js +18 -0
- package/registry/examples/verified-badge/native/verified.light.png +0 -0
- package/registry/examples/verified-badge/native/verified.tsx +15 -0
- package/registry/examples/verified-badge/verified.d.ts +4 -0
- package/registry/examples/verified-badge/verified.js +17 -0
- package/registry/examples/verified-badge/verified.tsx +13 -0
- package/registry/fab.json +1 -0
- package/registry/field.json +2 -1
- package/registry/file-upload.json +3 -2
- package/registry/filter-bar.json +2 -1
- package/registry/form.json +3 -2
- package/registry/gallery-page.json +5 -2
- package/registry/glow-card.json +2 -1
- package/registry/goal-gauge.json +2 -1
- package/registry/header.json +1 -0
- package/registry/how-it-works-page.json +5 -2
- package/registry/image-cropper.json +2 -1
- package/registry/image-viewer.json +1 -0
- package/registry/index.json +608 -19
- package/registry/iso.json +2 -1
- package/registry/kanban.json +2 -1
- package/registry/kbd.json +2 -1
- package/registry/landing-page.json +5 -2
- package/registry/landscape.json +2 -1
- package/registry/legal-page.json +5 -2
- package/registry/link-card.json +2 -1
- package/registry/list.json +2 -1
- package/registry/loader.json +47 -3
- package/registry/longform-page.json +16 -2
- package/registry/map.json +4 -3
- package/registry/marketing-layout.json +13 -4
- package/registry/marquee.json +2 -1
- package/registry/mascot-quote.json +2 -1
- package/registry/mascot-state.json +2 -1
- package/registry/mascots.json +2 -1
- package/registry/match-dialog.json +315 -0
- package/registry/media-capture.json +2 -1
- package/registry/media-picker.json +1 -0
- package/registry/meter.json +2 -1
- package/registry/nav-bar.json +2 -1
- package/registry/number-ticker.json +2 -1
- package/registry/onboarding.json +1 -0
- package/registry/otp-input.json +1 -0
- package/registry/page-header.json +2 -1
- package/registry/page-hero.json +2 -1
- package/registry/page.json +2 -1
- package/registry/pagination.json +2 -1
- package/registry/permission-prompt.json +1 -0
- package/registry/photo-grid.json +303 -0
- package/registry/pointer-light.json +2 -1
- package/registry/popover.json +2 -1
- package/registry/pricing-page.json +5 -2
- package/registry/product-page.json +5 -2
- package/registry/profile-card.json +2 -1
- package/registry/progress.json +2 -1
- package/registry/promise-card.json +2 -1
- package/registry/pull-to-refresh.json +68 -4
- package/registry/radio-group.json +2 -1
- package/registry/screen.json +233 -0
- package/registry/scroll-stage.json +2 -1
- package/registry/search-field.json +2 -1
- package/registry/section-backdrop.json +2 -1
- package/registry/segmented.json +1 -0
- package/registry/separator.json +2 -1
- package/registry/settings-layout.json +5 -2
- package/registry/skeleton.json +2 -1
- package/registry/skip-link.json +122 -0
- package/registry/slider.json +2 -1
- package/registry/slot.json +2 -1
- package/registry/spinner.json +2 -1
- package/registry/splash-handoff.json +138 -0
- package/registry/split-view.json +27 -2
- package/registry/stage-banner.json +2 -1
- package/registry/stat.json +2 -1
- package/registry/status-page.json +18 -2
- package/registry/step-progress.json +256 -0
- package/registry/stepper.json +2 -1
- package/registry/swipe-deck.json +513 -0
- package/registry/swipeable-row.json +1 -0
- package/registry/switch.json +2 -1
- package/registry/tab-bar.json +1 -0
- package/registry/tabs.json +2 -1
- package/registry/tag-input.json +2 -1
- package/registry/tag-selector.json +277 -0
- package/registry/terminal-replay.json +2 -1
- package/registry/theme.json +2 -1
- package/registry/toast.json +2 -1
- package/registry/toc.json +2 -1
- package/registry/tooltip.json +2 -1
- package/registry/tree-view.json +10 -4
- package/registry/txt.json +1 -0
- package/registry/verified-badge.json +203 -0
- package/registry/video-player.json +2 -1
- package/registry/video-trimmer.json +2 -1
- package/registry/virtual.json +2 -1
- package/dist/chunk-R6SDS7JM.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
usePrefersReducedMotion
|
|
4
|
+
} from "./chunk-BRKMQ6JV.js";
|
|
5
|
+
|
|
6
|
+
// src/swipe-deck/swipe-deck.tsx
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { tv } from "tailwind-variants";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var swipeDeck = tv({
|
|
11
|
+
slots: {
|
|
12
|
+
root: "flex w-full flex-col items-center gap-5",
|
|
13
|
+
stack: "relative aspect-[3/4] w-full max-w-sm outline-hidden focus-visible:rounded-2xl focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-4 focus-visible:ring-offset-surface-0",
|
|
14
|
+
layer: "absolute inset-0 touch-pan-y select-none",
|
|
15
|
+
stamp: "pointer-events-none absolute top-8 rounded-lg border-[3px] px-2.5 py-0.5 font-display text-2xl font-black uppercase tracking-wide",
|
|
16
|
+
buttons: "flex items-center gap-7",
|
|
17
|
+
button: "inline-flex h-16 w-16 items-center justify-center rounded-full border-2 bg-surface-1 shadow-md transition-transform active:scale-90 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40 motion-reduce:transition-none [&>svg]:h-7 [&>svg]:w-7",
|
|
18
|
+
card: "relative h-full w-full overflow-hidden rounded-2xl bg-surface-3 shadow-lg",
|
|
19
|
+
photo: "absolute inset-0 h-full w-full object-cover",
|
|
20
|
+
bars: "absolute inset-x-2 top-2 flex gap-1",
|
|
21
|
+
bar: "h-[3px] flex-1 rounded-full bg-fg-on-media opacity-40 data-[on]:opacity-100",
|
|
22
|
+
half: "absolute top-0 bottom-2/5 w-2/5 cursor-pointer outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
|
|
23
|
+
info: "absolute inset-x-0 bottom-0 flex flex-col gap-1.5 bg-gradient-to-t from-scrim-strong via-scrim-strong/80 to-transparent p-4 pt-24 text-fg-on-media",
|
|
24
|
+
name: "flex items-center gap-2 font-display text-3xl font-black",
|
|
25
|
+
age: "font-sans text-2xl font-normal",
|
|
26
|
+
bio: "line-clamp-2 text-sm",
|
|
27
|
+
footer: "mt-1 flex flex-wrap gap-1.5"
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
function PersonCard({ photos, name, age, badge, meta, bio, footer, photoLabels = { previous: "Previous photo", next: "Next photo" }, className }) {
|
|
31
|
+
const s = swipeDeck();
|
|
32
|
+
const [index, setIndex] = React.useState(0);
|
|
33
|
+
const photo = photos[index];
|
|
34
|
+
return /* @__PURE__ */ jsxs("article", { "aria-label": age !== void 0 ? `${name}, ${age}` : name, className: s.card({ className }), children: [
|
|
35
|
+
photo ? /* @__PURE__ */ jsx("img", { src: photo.src, alt: photo.alt ?? "", className: s.photo(), draggable: false }) : null,
|
|
36
|
+
photos.length > 1 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
37
|
+
/* @__PURE__ */ jsx("div", { className: s.bars(), "aria-hidden": true, children: photos.map((_, i) => /* @__PURE__ */ jsx("span", { className: s.bar(), "data-on": i === index || void 0 }, i)) }),
|
|
38
|
+
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": photoLabels.previous, disabled: index === 0, className: s.half({ className: "left-0" }), onClick: () => setIndex((i) => Math.max(0, i - 1)) }),
|
|
39
|
+
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": photoLabels.next, disabled: index === photos.length - 1, className: s.half({ className: "right-0" }), onClick: () => setIndex((i) => Math.min(photos.length - 1, i + 1)) })
|
|
40
|
+
] }) : null,
|
|
41
|
+
/* @__PURE__ */ jsxs("div", { className: s.info(), children: [
|
|
42
|
+
/* @__PURE__ */ jsxs("h3", { className: s.name(), children: [
|
|
43
|
+
/* @__PURE__ */ jsxs("span", { className: "truncate", children: [
|
|
44
|
+
name,
|
|
45
|
+
age !== void 0 ? /* @__PURE__ */ jsx("span", { className: s.age(), children: ` ${age}` }) : null
|
|
46
|
+
] }),
|
|
47
|
+
badge
|
|
48
|
+
] }),
|
|
49
|
+
meta,
|
|
50
|
+
bio ? /* @__PURE__ */ jsx("p", { className: s.bio(), children: bio }) : null,
|
|
51
|
+
footer ? /* @__PURE__ */ jsx("div", { className: s.footer(), children: footer }) : null
|
|
52
|
+
] })
|
|
53
|
+
] });
|
|
54
|
+
}
|
|
55
|
+
function SwipeDeck({ items, getId, getName, renderCard, onSwipe, empty, labels, className }) {
|
|
56
|
+
const s = swipeDeck();
|
|
57
|
+
const reduce = usePrefersReducedMotion();
|
|
58
|
+
const [dx, setDx] = React.useState(0);
|
|
59
|
+
const [leaving, setLeaving] = React.useState(null);
|
|
60
|
+
const [message, setMessage] = React.useState("");
|
|
61
|
+
const start = React.useRef(null);
|
|
62
|
+
const [dragging, setDragging] = React.useState(false);
|
|
63
|
+
const top = items[0];
|
|
64
|
+
const decide = (direction) => {
|
|
65
|
+
if (!top || leaving) return;
|
|
66
|
+
const finish = () => {
|
|
67
|
+
setLeaving(null);
|
|
68
|
+
setDx(0);
|
|
69
|
+
setMessage(labels.decided ? labels.decided(getName(top), direction) : `${getName(top)}: ${direction === "like" ? labels.like : labels.pass}`);
|
|
70
|
+
onSwipe(top, direction);
|
|
71
|
+
};
|
|
72
|
+
if (reduce) return finish();
|
|
73
|
+
setLeaving(direction);
|
|
74
|
+
setTimeout(finish, 220);
|
|
75
|
+
};
|
|
76
|
+
const offset = leaving ? (leaving === "like" ? 1 : -1) * 900 : dx;
|
|
77
|
+
const stampOpacity = (dir) => Math.max(0, Math.min(1, dir * offset / 120));
|
|
78
|
+
return /* @__PURE__ */ jsxs("div", { className: s.root({ className }), children: [
|
|
79
|
+
/* @__PURE__ */ jsx("p", { className: "sr-only", "aria-live": "polite", children: message }),
|
|
80
|
+
/* @__PURE__ */ jsxs(
|
|
81
|
+
"div",
|
|
82
|
+
{
|
|
83
|
+
role: "group",
|
|
84
|
+
"aria-label": labels.deck,
|
|
85
|
+
tabIndex: top ? 0 : -1,
|
|
86
|
+
className: s.stack(),
|
|
87
|
+
onKeyDown: (e) => {
|
|
88
|
+
if (e.key === "ArrowRight") decide("like");
|
|
89
|
+
if (e.key === "ArrowLeft") decide("pass");
|
|
90
|
+
},
|
|
91
|
+
children: [
|
|
92
|
+
!top ? empty : null,
|
|
93
|
+
items.slice(0, 2).reverse().map((item) => {
|
|
94
|
+
const isTop = item === top;
|
|
95
|
+
return /* @__PURE__ */ jsxs(
|
|
96
|
+
"div",
|
|
97
|
+
{
|
|
98
|
+
"aria-hidden": !isTop || void 0,
|
|
99
|
+
inert: !isTop || void 0,
|
|
100
|
+
className: s.layer(),
|
|
101
|
+
style: isTop ? { transform: `translateX(${offset}px) rotate(${offset / 22}deg)`, transition: dragging && !leaving ? "none" : reduce ? "none" : "transform 220ms var(--kz-ease, ease-out)" } : { transform: "scale(0.96)", opacity: 0.9 },
|
|
102
|
+
onPointerDown: (e) => {
|
|
103
|
+
if (!isTop || e.target.closest("button")) return;
|
|
104
|
+
start.current = { x: e.clientX, width: e.currentTarget.offsetWidth };
|
|
105
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
106
|
+
setDragging(true);
|
|
107
|
+
},
|
|
108
|
+
onPointerMove: (e) => {
|
|
109
|
+
if (start.current) setDx(e.clientX - start.current.x);
|
|
110
|
+
},
|
|
111
|
+
onPointerUp: () => {
|
|
112
|
+
const width = start.current?.width ?? 300;
|
|
113
|
+
start.current = null;
|
|
114
|
+
setDragging(false);
|
|
115
|
+
if (dx > width / 3) decide("like");
|
|
116
|
+
else if (dx < -width / 3) decide("pass");
|
|
117
|
+
else setDx(0);
|
|
118
|
+
},
|
|
119
|
+
children: [
|
|
120
|
+
renderCard(item),
|
|
121
|
+
isTop ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
122
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": true, className: s.stamp({ className: "left-6 -rotate-12 border-success text-fg-success" }), style: { opacity: stampOpacity(1) }, children: labels.likeStamp ?? labels.like }),
|
|
123
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": true, className: s.stamp({ className: "right-6 rotate-12 border-danger text-fg-danger" }), style: { opacity: stampOpacity(-1) }, children: labels.passStamp ?? labels.pass })
|
|
124
|
+
] }) : null
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
getId(item)
|
|
128
|
+
);
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
/* @__PURE__ */ jsxs("div", { className: s.buttons(), children: [
|
|
134
|
+
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": labels.pass, disabled: !top, onClick: () => decide("pass"), className: s.button({ className: "border-danger text-fg-danger" }), children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M6 6l12 12M18 6 6 18" }) }) }),
|
|
135
|
+
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": labels.like, disabled: !top, onClick: () => decide("like"), className: s.button({ className: "border-success text-fg-success" }), children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z" }) }) })
|
|
136
|
+
] })
|
|
137
|
+
] });
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
PersonCard,
|
|
141
|
+
SwipeDeck,
|
|
142
|
+
swipeDeck
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=swipe-deck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/swipe-deck/swipe-deck.tsx"],"sourcesContent":["// Client (the drag, the decision). A deck of cards decided one by one — drag right to like, left to pass, or the\n// buttons, or ← → on the focused deck — and `PersonCard`, a person on a card. Reduced motion: the card leaves without\n// flying.\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { usePrefersReducedMotion } from \"../media\";\n\nexport const swipeDeck = tv({\n slots: {\n root: \"flex w-full flex-col items-center gap-5\",\n stack: \"relative aspect-[3/4] w-full max-w-sm outline-hidden focus-visible:rounded-2xl focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-4 focus-visible:ring-offset-surface-0\",\n layer: \"absolute inset-0 touch-pan-y select-none\",\n stamp: \"pointer-events-none absolute top-8 rounded-lg border-[3px] px-2.5 py-0.5 font-display text-2xl font-black uppercase tracking-wide\",\n buttons: \"flex items-center gap-7\",\n button:\n \"inline-flex h-16 w-16 items-center justify-center rounded-full border-2 bg-surface-1 shadow-md transition-transform active:scale-90 \" +\n \"focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40 motion-reduce:transition-none [&>svg]:h-7 [&>svg]:w-7\",\n card: \"relative h-full w-full overflow-hidden rounded-2xl bg-surface-3 shadow-lg\",\n photo: \"absolute inset-0 h-full w-full object-cover\",\n bars: \"absolute inset-x-2 top-2 flex gap-1\",\n bar: \"h-[3px] flex-1 rounded-full bg-fg-on-media opacity-40 data-[on]:opacity-100\",\n half: \"absolute top-0 bottom-2/5 w-2/5 cursor-pointer outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring\",\n info: \"absolute inset-x-0 bottom-0 flex flex-col gap-1.5 bg-gradient-to-t from-scrim-strong via-scrim-strong/80 to-transparent p-4 pt-24 text-fg-on-media\",\n name: \"flex items-center gap-2 font-display text-3xl font-black\",\n age: \"font-sans text-2xl font-normal\",\n bio: \"line-clamp-2 text-sm\",\n footer: \"mt-1 flex flex-wrap gap-1.5\",\n },\n});\n\nexport type PersonCardProps = {\n /** The person's photos (URLs), the first shown first; click a side, or its buttons, to move between them. */\n photos: readonly { src: string; alt?: string }[];\n /** The name. */\n name: string;\n /** The age, written after the name. */\n age?: number;\n /** Beside the name: a `VerifiedBadge`. */\n badge?: React.ReactNode;\n /** A line under the name: a distance, a job. */\n meta?: React.ReactNode;\n /** A sentence about the person. */\n bio?: string;\n /** At the bottom: the interests as chips. */\n footer?: React.ReactNode;\n /** The photo buttons' words: `{ previous: \"Previous photo\", next: \"Next photo\" }` — passed translated. */\n photoLabels?: { previous: string; next: string };\n /** Classes merged on the card. */\n className?: string;\n};\n\n/** A person on a card: photos full bleed (a side to change), name and age over a scrim, a line, a bio, chips. */\nexport function PersonCard({ photos, name, age, badge, meta, bio, footer, photoLabels = { previous: \"Previous photo\", next: \"Next photo\" }, className }: PersonCardProps) {\n const s = swipeDeck();\n const [index, setIndex] = React.useState(0);\n const photo = photos[index];\n return (\n <article aria-label={age !== undefined ? `${name}, ${age}` : name} className={s.card({ className })}>\n {photo ? <img src={photo.src} alt={photo.alt ?? \"\"} className={s.photo()} draggable={false} /> : null}\n {photos.length > 1 ? (\n <>\n <div className={s.bars()} aria-hidden>\n {photos.map((_, i) => (\n <span key={i} className={s.bar()} data-on={i === index || undefined} />\n ))}\n </div>\n <button type=\"button\" aria-label={photoLabels.previous} disabled={index === 0} className={s.half({ className: \"left-0\" })} onClick={() => setIndex((i) => Math.max(0, i - 1))} />\n <button type=\"button\" aria-label={photoLabels.next} disabled={index === photos.length - 1} className={s.half({ className: \"right-0\" })} onClick={() => setIndex((i) => Math.min(photos.length - 1, i + 1))} />\n </>\n ) : null}\n <div className={s.info()}>\n <h3 className={s.name()}>\n <span className=\"truncate\">\n {name}\n {age !== undefined ? <span className={s.age()}>{` ${age}`}</span> : null}\n </span>\n {badge}\n </h3>\n {meta}\n {bio ? <p className={s.bio()}>{bio}</p> : null}\n {footer ? <div className={s.footer()}>{footer}</div> : null}\n </div>\n </article>\n );\n}\n\nexport type SwipeDirection = \"like\" | \"pass\";\n\nexport type SwipeDeckLabels = {\n /** The like button (“Like”). */\n like: string;\n /** The pass button (“Pass”). */\n pass: string;\n /** The deck's name and its keyboard hint (“Profiles. Right arrow to like, left arrow to pass.”). */\n deck: string;\n /** The stamp while dragging right (“LIKE”). */\n likeStamp?: string;\n /** The stamp while dragging left (“NOPE”). */\n passStamp?: string;\n /** Announced after a decision: `(name, direction) => …`. */\n decided?: (name: string, direction: SwipeDirection) => string;\n};\n\nexport type SwipeDeckProps<T> = {\n /** The cards still to decide, the first on top. */\n items: readonly T[];\n /** A card's id. */\n getId: (item: T) => string;\n /** A card's name, for the announcements. */\n getName: (item: T) => string;\n /** A card (usually a `PersonCard`). */\n renderCard: (item: T) => React.ReactNode;\n /** Called with the card decided and the decision; remove it from `items`. */\n onSwipe: (item: T, direction: SwipeDirection) => void;\n /** Shown when there is no card left (an `EmptyState`). */\n empty?: React.ReactNode;\n /** The words, passed translated. */\n labels: SwipeDeckLabels;\n /** Classes merged on the root. */\n className?: string;\n};\n\n/** A deck of cards decided one by one: drag, the buttons, or ← → — each decision announced. */\nexport function SwipeDeck<T>({ items, getId, getName, renderCard, onSwipe, empty, labels, className }: SwipeDeckProps<T>) {\n const s = swipeDeck();\n const reduce = usePrefersReducedMotion();\n const [dx, setDx] = React.useState(0);\n const [leaving, setLeaving] = React.useState<SwipeDirection | null>(null);\n const [message, setMessage] = React.useState(\"\");\n const start = React.useRef<{ x: number; width: number } | null>(null);\n const [dragging, setDragging] = React.useState(false);\n const top = items[0];\n const decide = (direction: SwipeDirection) => {\n if (!top || leaving) return;\n const finish = () => {\n setLeaving(null);\n setDx(0);\n setMessage(labels.decided ? labels.decided(getName(top), direction) : `${getName(top)}: ${direction === \"like\" ? labels.like : labels.pass}`);\n onSwipe(top, direction);\n };\n if (reduce) return finish();\n setLeaving(direction);\n setTimeout(finish, 220);\n };\n const offset = leaving ? (leaving === \"like\" ? 1 : -1) * 900 : dx;\n const stampOpacity = (dir: 1 | -1) => Math.max(0, Math.min(1, (dir * offset) / 120));\n return (\n <div className={s.root({ className })}>\n <p className=\"sr-only\" aria-live=\"polite\">\n {message}\n </p>\n <div\n role=\"group\"\n aria-label={labels.deck}\n tabIndex={top ? 0 : -1}\n className={s.stack()}\n onKeyDown={(e) => {\n if (e.key === \"ArrowRight\") decide(\"like\");\n if (e.key === \"ArrowLeft\") decide(\"pass\");\n }}\n >\n {!top ? empty : null}\n {items\n .slice(0, 2)\n .reverse()\n .map((item) => {\n const isTop = item === top;\n return (\n <div\n key={getId(item)}\n aria-hidden={!isTop || undefined}\n inert={!isTop || undefined}\n className={s.layer()}\n style={\n isTop\n ? { transform: `translateX(${offset}px) rotate(${offset / 22}deg)`, transition: dragging && !leaving ? \"none\" : reduce ? \"none\" : \"transform 220ms var(--kz-ease, ease-out)\" }\n : { transform: \"scale(0.96)\", opacity: 0.9 }\n }\n onPointerDown={(e) => {\n if (!isTop || (e.target as HTMLElement).closest(\"button\")) return;\n start.current = { x: e.clientX, width: e.currentTarget.offsetWidth };\n e.currentTarget.setPointerCapture(e.pointerId);\n setDragging(true);\n }}\n onPointerMove={(e) => {\n if (start.current) setDx(e.clientX - start.current.x);\n }}\n onPointerUp={() => {\n const width = start.current?.width ?? 300;\n start.current = null;\n setDragging(false);\n if (dx > width / 3) decide(\"like\");\n else if (dx < -width / 3) decide(\"pass\");\n else setDx(0);\n }}\n >\n {renderCard(item)}\n {isTop ? (\n <>\n <span aria-hidden className={s.stamp({ className: \"left-6 -rotate-12 border-success text-fg-success\" })} style={{ opacity: stampOpacity(1) }}>\n {labels.likeStamp ?? labels.like}\n </span>\n <span aria-hidden className={s.stamp({ className: \"right-6 rotate-12 border-danger text-fg-danger\" })} style={{ opacity: stampOpacity(-1) }}>\n {labels.passStamp ?? labels.pass}\n </span>\n </>\n ) : null}\n </div>\n );\n })}\n </div>\n <div className={s.buttons()}>\n <button type=\"button\" aria-label={labels.pass} disabled={!top} onClick={() => decide(\"pass\")} className={s.button({ className: \"border-danger text-fg-danger\" })}>\n <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"3\" strokeLinecap=\"round\" aria-hidden>\n <path d=\"M6 6l12 12M18 6 6 18\" />\n </svg>\n </button>\n <button type=\"button\" aria-label={labels.like} disabled={!top} onClick={() => decide(\"like\")} className={s.button({ className: \"border-success text-fg-success\" })}>\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden>\n <path d=\"M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z\" />\n </svg>\n </button>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;AAGA,YAAY,WAAW;AACvB,SAAS,UAAU;AAuDJ,SAEP,UAFO,KAEP,YAFO;AAnDR,IAAM,YAAY,GAAG;AAAA,EAC1B,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,SAAS;AAAA,IACT,QACE;AAAA,IAEF,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,IACN,KAAK;AAAA,IACL,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,KAAK;AAAA,IACL,KAAK;AAA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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type TagOption = {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
};
|
|
7
|
+
type TagSelectorProps = {
|
|
8
|
+
/** The group's name (“Interests”) — passed translated. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** The tags offered. */
|
|
11
|
+
options: readonly TagOption[];
|
|
12
|
+
/** The tags chosen. */
|
|
13
|
+
value: readonly string[];
|
|
14
|
+
/** Called with the tags chosen. */
|
|
15
|
+
onValueChange: (value: string[]) => void;
|
|
16
|
+
/** The most that can be chosen. */
|
|
17
|
+
max?: number;
|
|
18
|
+
/** The count under the tags: `(n, max) => n + " of " + max`. */
|
|
19
|
+
countLabel?: (count: number, max: number) => string;
|
|
20
|
+
/** Classes merged on the root. */
|
|
21
|
+
className?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Toggle chips with a limit and a count — the others rest once the limit is reached. */
|
|
24
|
+
declare function TagSelector({ label, options, value, onValueChange, max, countLabel, className }: TagSelectorProps): React.JSX.Element;
|
|
25
|
+
|
|
26
|
+
export { type TagOption, TagSelector, type TagSelectorProps };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Chip
|
|
4
|
+
} from "./chunk-YH4LMWRU.js";
|
|
5
|
+
|
|
6
|
+
// src/tag-selector/tag-selector.tsx
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
function TagSelector({ label, options, value, onValueChange, max, countLabel, className }) {
|
|
9
|
+
const full = max !== void 0 && value.length >= max;
|
|
10
|
+
return /* @__PURE__ */ jsxs("div", { className: ["flex flex-col gap-2", className].filter(Boolean).join(" "), children: [
|
|
11
|
+
/* @__PURE__ */ jsx("div", { role: "group", "aria-label": label, className: "flex flex-wrap gap-2", children: options.map((option) => {
|
|
12
|
+
const on = value.includes(option.value);
|
|
13
|
+
return /* @__PURE__ */ jsx(Chip, { selected: on, disabled: !on && full, onSelectedChange: (next) => onValueChange(next ? [...value, option.value] : value.filter((v) => v !== option.value)), children: option.label }, option.value);
|
|
14
|
+
}) }),
|
|
15
|
+
max !== void 0 && countLabel ? /* @__PURE__ */ jsx("p", { className: ["m-0 text-xs", full ? "font-semibold text-fg-accent" : "text-fg-secondary"].join(" "), "aria-live": "polite", children: countLabel(value.length, max) }) : null
|
|
16
|
+
] });
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
TagSelector
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=tag-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tag-selector/tag-selector.tsx"],"sourcesContent":["// Client. Interests, languages, what one is looking for: toggle chips with a limit and a count; once it is reached the\n// others rest (disabled) and the count says so.\nimport { Chip } from \"../chip\";\n\nexport type TagOption = { value: string; label: string };\n\nexport type TagSelectorProps = {\n /** The group's name (“Interests”) — passed translated. */\n label: string;\n /** The tags offered. */\n options: readonly TagOption[];\n /** The tags chosen. */\n value: readonly string[];\n /** Called with the tags chosen. */\n onValueChange: (value: string[]) => void;\n /** The most that can be chosen. */\n max?: number;\n /** The count under the tags: `(n, max) => n + \" of \" + max`. */\n countLabel?: (count: number, max: number) => string;\n /** Classes merged on the root. */\n className?: string;\n};\n\n/** Toggle chips with a limit and a count — the others rest once the limit is reached. */\nexport function TagSelector({ label, options, value, onValueChange, max, countLabel, className }: TagSelectorProps) {\n const full = max !== undefined && value.length >= max;\n return (\n <div className={[\"flex flex-col gap-2\", className].filter(Boolean).join(\" \")}>\n <div role=\"group\" aria-label={label} className=\"flex flex-wrap gap-2\">\n {options.map((option) => {\n const on = value.includes(option.value);\n return (\n <Chip key={option.value} selected={on} disabled={!on && full} onSelectedChange={(next) => onValueChange(next ? [...value, option.value] : value.filter((v) => v !== option.value))}>\n {option.label}\n </Chip>\n );\n })}\n </div>\n {max !== undefined && countLabel ? (\n <p className={[\"m-0 text-xs\", full ? \"font-semibold text-fg-accent\" : \"text-fg-secondary\"].join(\" \")} aria-live=\"polite\">\n {countLabel(value.length, max)}\n </p>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;AA2BI,SAKQ,KALR;AAHG,SAAS,YAAY,EAAE,OAAO,SAAS,OAAO,eAAe,KAAK,YAAY,UAAU,GAAqB;AAClH,QAAM,OAAO,QAAQ,UAAa,MAAM,UAAU;AAClD,SACE,qBAAC,SAAI,WAAW,CAAC,uBAAuB,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GACzE;AAAA,wBAAC,SAAI,MAAK,SAAQ,cAAY,OAAO,WAAU,wBAC5C,kBAAQ,IAAI,CAAC,WAAW;AACvB,YAAM,KAAK,MAAM,SAAS,OAAO,KAAK;AACtC,aACE,oBAAC,QAAwB,UAAU,IAAI,UAAU,CAAC,MAAM,MAAM,kBAAkB,CAAC,SAAS,cAAc,OAAO,CAAC,GAAG,OAAO,OAAO,KAAK,IAAI,MAAM,OAAO,CAAC,MAAM,MAAM,OAAO,KAAK,CAAC,GAC9K,iBAAO,SADC,OAAO,KAElB;AAAA,IAEJ,CAAC,GACH;AAAA,IACC,QAAQ,UAAa,aACpB,oBAAC,OAAE,WAAW,CAAC,eAAe,OAAO,iCAAiC,mBAAmB,EAAE,KAAK,GAAG,GAAG,aAAU,UAC7G,qBAAW,MAAM,QAAQ,GAAG,GAC/B,IACE;AAAA,KACN;AAEJ;","names":[]}
|
package/dist/tree-view.d.ts
CHANGED
|
@@ -105,6 +105,8 @@ type TreeViewProps = {
|
|
|
105
105
|
/**
|
|
106
106
|
* A hierarchy to browse — documentation sections, a studio's datasets, folders: one tab stop, the arrows walk it (→
|
|
107
107
|
* opens, ← closes or goes up), Home/End, a letter jumps to the next name; branches can load their children on demand.
|
|
108
|
+
*
|
|
109
|
+
* @deprecated Since 3.6.0, removed in 4.0.0: no product uses it. Drill down with `List` instead.
|
|
108
110
|
*/
|
|
109
111
|
declare function TreeView({ nodes, "aria-label": label, expanded: expandedProp, defaultExpanded, onExpandedChange, selected: selectedProp, defaultSelected, onSelect, onLoadChildren, loadingLabel, className, }: TreeViewProps): React.JSX.Element;
|
|
110
112
|
|
package/dist/tree-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tree-view/tree-view.tsx"],"sourcesContent":["// Client (expansion, selection, the roving focus). A hierarchy the keyboard walks — the ARIA tree pattern: one tab\n// stop, the arrows move and open, Home/End, typing a letter jumps; children loaded on demand when a branch opens.\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { ChevronGlyph } from \"../glyphs\";\nimport { useControllable } from \"../media\";\n\nexport const treeView = tv({\n slots: {\n root: \"m-0 list-none p-0 text-sm\",\n group: \"m-0 list-none p-0\",\n row:\n \"flex min-h-8 cursor-pointer select-none items-center gap-1.5 rounded-md pr-2 text-fg outline-hidden \" +\n \"hover:bg-surface-2 data-[selected]:bg-accent-soft data-[selected]:font-semibold data-[disabled]:cursor-default data-[disabled]:opacity-50\",\n toggle: \"flex h-5 w-5 shrink-0 items-center justify-center text-fg-secondary [&>svg]:h-3.5 [&>svg]:w-3.5 [&>svg]:transition-transform motion-reduce:[&>svg]:transition-none\",\n icon: \"flex shrink-0 items-center text-fg-secondary [&>svg]:h-4 [&>svg]:w-4\",\n label: \"min-w-0 flex-1 truncate\",\n meta: \"shrink-0 text-xs tabular-nums text-fg-secondary\",\n },\n});\n\nexport type TreeNode = {\n /** A stable id. */\n id: string;\n /** Its name — passed translated. */\n label: string;\n /** A decorative icon before the name. */\n icon?: React.ReactNode;\n /** A detail after the name (a count, a size). */\n meta?: React.ReactNode;\n /** Its children; `undefined` for a leaf. With `hasChildren`, they load when it opens (`onLoadChildren`). */\n children?: readonly TreeNode[];\n /** A branch whose children are not loaded yet. */\n hasChildren?: boolean;\n /** Cannot be selected. */\n disabled?: boolean;\n};\n\nexport type TreeViewProps = {\n /** The roots. */\n nodes: readonly TreeNode[];\n /** The tree's accessible name (“Documentation”). */\n \"aria-label\": string;\n /** The ids of the open branches (controlled). */\n expanded?: readonly string[];\n /** The ids open at first, uncontrolled. */\n defaultExpanded?: readonly string[];\n /** Called with the open branches. */\n onExpandedChange?: (expanded: string[]) => void;\n /** The selected node (controlled). */\n selected?: string | null;\n /** The selected node at first, uncontrolled. */\n defaultSelected?: string | null;\n /** Called when a node is chosen (click, Enter or Space): navigate, open the file. */\n onSelect?: (node: TreeNode) => void;\n /** Called when a branch with `hasChildren` and no `children` opens: fetch them, then pass them in `nodes`. */\n onLoadChildren?: (node: TreeNode) => void;\n /** The words of a branch that is loading (“Loading”). */\n loadingLabel?: string;\n /** Classes merged on the tree. */\n className?: string;\n};\n\ntype Flat = { node: TreeNode; level: number; parent: string | null; posinset: number; setsize: number };\n\nconst isBranch = (node: TreeNode) => Boolean(node.children?.length || node.hasChildren);\n\nfunction flatten(nodes: readonly TreeNode[], open: Set<string>, level = 1, parent: string | null = null, out: Flat[] = []): Flat[] {\n nodes.forEach((node, i) => {\n out.push({ node, level, parent, posinset: i + 1, setsize: nodes.length });\n if (open.has(node.id) && node.children) flatten(node.children, open, level + 1, node.id, out);\n });\n return out;\n}\n\n/**\n * A hierarchy to browse — documentation sections, a studio's datasets, folders: one tab stop, the arrows walk it (→\n * opens, ← closes or goes up), Home/End, a letter jumps to the next name; branches can load their children on demand.\n */\nexport function TreeView({\n nodes,\n \"aria-label\": label,\n expanded: expandedProp,\n defaultExpanded = [],\n onExpandedChange,\n selected: selectedProp,\n defaultSelected = null,\n onSelect,\n onLoadChildren,\n loadingLabel = \"Loading\",\n className,\n}: TreeViewProps) {\n const s = treeView();\n const uid = React.useId();\n const [expanded, setExpanded] = useControllable<readonly string[]>(expandedProp, defaultExpanded, onExpandedChange as (next: readonly string[]) => void);\n const [selected, setSelected] = useControllable<string | null>(selectedProp, defaultSelected);\n const open = new Set(expanded);\n const rows = flatten(nodes, open);\n const [active, setActive] = React.useState<string | null>(null);\n const focusId = active && rows.some((r) => r.node.id === active) ? active : (selected ?? rows[0]?.node.id ?? null);\n const refs = React.useRef(new Map<string, HTMLDivElement>());\n const move = (id: string | undefined) => {\n if (!id) return;\n setActive(id);\n refs.current.get(id)?.focus();\n };\n const toggle = (node: TreeNode, to = !open.has(node.id)) => {\n if (!isBranch(node)) return;\n if (to && node.hasChildren && !node.children) onLoadChildren?.(node);\n setExpanded(to ? [...expanded, node.id] : expanded.filter((id) => id !== node.id));\n };\n const choose = (node: TreeNode) => {\n if (node.disabled) return;\n setSelected(node.id);\n onSelect?.(node);\n };\n const onKeyDown = (event: React.KeyboardEvent, i: number) => {\n const row = rows[i]!;\n const { node } = row;\n const keys: Record<string, () => void> = {\n ArrowDown: () => move(rows[i + 1]?.node.id),\n ArrowUp: () => move(rows[i - 1]?.node.id),\n Home: () => move(rows[0]?.node.id),\n End: () => move(rows[rows.length - 1]?.node.id),\n ArrowRight: () => (isBranch(node) && !open.has(node.id) ? toggle(node, true) : isBranch(node) ? move(rows[i + 1]?.node.id) : undefined),\n ArrowLeft: () => (open.has(node.id) ? toggle(node, false) : move(row.parent ?? undefined)),\n Enter: () => choose(node),\n \" \": () => choose(node),\n };\n const run = keys[event.key];\n if (run) {\n event.preventDefault();\n run();\n return;\n }\n if (event.key.length === 1 && /\\S/.test(event.key)) {\n const letter = event.key.toLowerCase();\n const next = [...rows.slice(i + 1), ...rows.slice(0, i)].find((r) => r.node.label.toLowerCase().startsWith(letter));\n move(next?.node.id);\n }\n };\n\n const render = (list: readonly TreeNode[], level: number): React.ReactNode =>\n list.map((node) => {\n const i = rows.findIndex((r) => r.node.id === node.id);\n const row = rows[i]!;\n const branch = isBranch(node);\n const isOpen = open.has(node.id);\n const loading = isOpen && node.hasChildren && !node.children;\n return (\n // The row is the treeitem (its name is its own words, never its children's); the group of children hangs\n // from it with aria-owns, in the `li` that holds both.\n <li key={node.id} role=\"none\">\n <div\n ref={(el) => {\n if (el) refs.current.set(node.id, el);\n else refs.current.delete(node.id);\n }}\n role=\"treeitem\"\n aria-level={level}\n aria-posinset={row.posinset}\n aria-setsize={row.setsize}\n aria-expanded={branch ? isOpen : undefined}\n aria-selected={selected === node.id}\n aria-disabled={node.disabled || undefined}\n aria-busy={loading || undefined}\n aria-owns={branch && isOpen ? `${uid}-${node.id}-group` : undefined}\n tabIndex={node.id === focusId ? 0 : -1}\n onKeyDown={(e) => {\n if (e.target === e.currentTarget) onKeyDown(e, i);\n }}\n onFocus={(e) => {\n if (e.target === e.currentTarget) setActive(node.id);\n }}\n className={s.row({ className: \"outline-hidden focus-visible:ring-2 focus-visible:ring-ring\" })}\n data-selected={selected === node.id || undefined}\n data-disabled={node.disabled || undefined}\n style={{ paddingLeft: `${(level - 1) * 1.25 + 0.25}rem` }}\n onClick={() => {\n if (branch) toggle(node);\n choose(node);\n move(node.id);\n }}\n >\n <span className={s.toggle()} aria-hidden>\n {branch ? <ChevronGlyph direction={isOpen ? \"down\" : \"right\"} /> : null}\n </span>\n {node.icon ? <span className={s.icon()} aria-hidden>{node.icon}</span> : null}\n <span className={s.label()}>{node.label}</span>\n {node.meta ? <span className={s.meta()}>{node.meta}</span> : null}\n </div>\n {branch && isOpen ? (\n <ul role=\"group\" id={`${uid}-${node.id}-group`} className={s.group()}>\n {loading ? (\n <li role=\"none\" className=\"py-1 text-xs text-fg-secondary\" style={{ paddingLeft: `${level * 1.25 + 1.75}rem` }}>\n {loadingLabel}\n </li>\n ) : (\n render(node.children ?? [], level + 1)\n )}\n </ul>\n ) : null}\n </li>\n );\n });\n\n return (\n <ul role=\"tree\" aria-label={label} className={s.root({ className })}>\n {render(nodes, 1)}\n </ul>\n );\n}\n"],"mappings":";;;;;;;;;AAEA,YAAY,WAAW;AACvB,SAAS,UAAU;AAuJT,SAgCc,KAhCd;AAlJH,IAAM,WAAW,GAAG;AAAA,EACzB,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KACE;AAAA,IAEF,QAAQ;AAAA,IACR,MAAM;AAAA,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UAAU,CAAC,GAC/D,iBAAO,OAAO,CAAC,GAClB;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/tree-view/tree-view.tsx"],"sourcesContent":["// Client (expansion, selection, the roving focus). A hierarchy the keyboard walks — the ARIA tree pattern: one tab\n// stop, the arrows move and open, Home/End, typing a letter jumps; children loaded on demand when a branch opens.\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { ChevronGlyph } from \"../glyphs\";\nimport { useControllable } from \"../media\";\n\nexport const treeView = tv({\n slots: {\n root: \"m-0 list-none p-0 text-sm\",\n group: \"m-0 list-none p-0\",\n row:\n \"flex min-h-8 cursor-pointer select-none items-center gap-1.5 rounded-md pr-2 text-fg outline-hidden \" +\n \"hover:bg-surface-2 data-[selected]:bg-accent-soft data-[selected]:font-semibold data-[disabled]:cursor-default data-[disabled]:opacity-50\",\n toggle: \"flex h-5 w-5 shrink-0 items-center justify-center text-fg-secondary [&>svg]:h-3.5 [&>svg]:w-3.5 [&>svg]:transition-transform motion-reduce:[&>svg]:transition-none\",\n icon: \"flex shrink-0 items-center text-fg-secondary [&>svg]:h-4 [&>svg]:w-4\",\n label: \"min-w-0 flex-1 truncate\",\n meta: \"shrink-0 text-xs tabular-nums text-fg-secondary\",\n },\n});\n\nexport type TreeNode = {\n /** A stable id. */\n id: string;\n /** Its name — passed translated. */\n label: string;\n /** A decorative icon before the name. */\n icon?: React.ReactNode;\n /** A detail after the name (a count, a size). */\n meta?: React.ReactNode;\n /** Its children; `undefined` for a leaf. With `hasChildren`, they load when it opens (`onLoadChildren`). */\n children?: readonly TreeNode[];\n /** A branch whose children are not loaded yet. */\n hasChildren?: boolean;\n /** Cannot be selected. */\n disabled?: boolean;\n};\n\nexport type TreeViewProps = {\n /** The roots. */\n nodes: readonly TreeNode[];\n /** The tree's accessible name (“Documentation”). */\n \"aria-label\": string;\n /** The ids of the open branches (controlled). */\n expanded?: readonly string[];\n /** The ids open at first, uncontrolled. */\n defaultExpanded?: readonly string[];\n /** Called with the open branches. */\n onExpandedChange?: (expanded: string[]) => void;\n /** The selected node (controlled). */\n selected?: string | null;\n /** The selected node at first, uncontrolled. */\n defaultSelected?: string | null;\n /** Called when a node is chosen (click, Enter or Space): navigate, open the file. */\n onSelect?: (node: TreeNode) => void;\n /** Called when a branch with `hasChildren` and no `children` opens: fetch them, then pass them in `nodes`. */\n onLoadChildren?: (node: TreeNode) => void;\n /** The words of a branch that is loading (“Loading”). */\n loadingLabel?: string;\n /** Classes merged on the tree. */\n className?: string;\n};\n\ntype Flat = { node: TreeNode; level: number; parent: string | null; posinset: number; setsize: number };\n\nconst isBranch = (node: TreeNode) => Boolean(node.children?.length || node.hasChildren);\n\nfunction flatten(nodes: readonly TreeNode[], open: Set<string>, level = 1, parent: string | null = null, out: Flat[] = []): Flat[] {\n nodes.forEach((node, i) => {\n out.push({ node, level, parent, posinset: i + 1, setsize: nodes.length });\n if (open.has(node.id) && node.children) flatten(node.children, open, level + 1, node.id, out);\n });\n return out;\n}\n\n/**\n * A hierarchy to browse — documentation sections, a studio's datasets, folders: one tab stop, the arrows walk it (→\n * opens, ← closes or goes up), Home/End, a letter jumps to the next name; branches can load their children on demand.\n *\n * @deprecated Since 3.6.0, removed in 4.0.0: no product uses it. Drill down with `List` instead.\n */\nexport function TreeView({\n nodes,\n \"aria-label\": label,\n expanded: expandedProp,\n defaultExpanded = [],\n onExpandedChange,\n selected: selectedProp,\n defaultSelected = null,\n onSelect,\n onLoadChildren,\n loadingLabel = \"Loading\",\n className,\n}: TreeViewProps) {\n const s = treeView();\n const uid = React.useId();\n const [expanded, setExpanded] = useControllable<readonly string[]>(expandedProp, defaultExpanded, onExpandedChange as (next: readonly string[]) => void);\n const [selected, setSelected] = useControllable<string | null>(selectedProp, defaultSelected);\n const open = new Set(expanded);\n const rows = flatten(nodes, open);\n const [active, setActive] = React.useState<string | null>(null);\n const focusId = active && rows.some((r) => r.node.id === active) ? active : (selected ?? rows[0]?.node.id ?? null);\n const refs = React.useRef(new Map<string, HTMLDivElement>());\n const move = (id: string | undefined) => {\n if (!id) return;\n setActive(id);\n refs.current.get(id)?.focus();\n };\n const toggle = (node: TreeNode, to = !open.has(node.id)) => {\n if (!isBranch(node)) return;\n if (to && node.hasChildren && !node.children) onLoadChildren?.(node);\n setExpanded(to ? [...expanded, node.id] : expanded.filter((id) => id !== node.id));\n };\n const choose = (node: TreeNode) => {\n if (node.disabled) return;\n setSelected(node.id);\n onSelect?.(node);\n };\n const onKeyDown = (event: React.KeyboardEvent, i: number) => {\n const row = rows[i]!;\n const { node } = row;\n const keys: Record<string, () => void> = {\n ArrowDown: () => move(rows[i + 1]?.node.id),\n ArrowUp: () => move(rows[i - 1]?.node.id),\n Home: () => move(rows[0]?.node.id),\n End: () => move(rows[rows.length - 1]?.node.id),\n ArrowRight: () => (isBranch(node) && !open.has(node.id) ? toggle(node, true) : isBranch(node) ? move(rows[i + 1]?.node.id) : undefined),\n ArrowLeft: () => (open.has(node.id) ? toggle(node, false) : move(row.parent ?? undefined)),\n Enter: () => choose(node),\n \" \": () => choose(node),\n };\n const run = keys[event.key];\n if (run) {\n event.preventDefault();\n run();\n return;\n }\n if (event.key.length === 1 && /\\S/.test(event.key)) {\n const letter = event.key.toLowerCase();\n const next = [...rows.slice(i + 1), ...rows.slice(0, i)].find((r) => r.node.label.toLowerCase().startsWith(letter));\n move(next?.node.id);\n }\n };\n\n const render = (list: readonly TreeNode[], level: number): React.ReactNode =>\n list.map((node) => {\n const i = rows.findIndex((r) => r.node.id === node.id);\n const row = rows[i]!;\n const branch = isBranch(node);\n const isOpen = open.has(node.id);\n const loading = isOpen && node.hasChildren && !node.children;\n return (\n // The row is the treeitem (its name is its own words, never its children's); the group of children hangs\n // from it with aria-owns, in the `li` that holds both.\n <li key={node.id} role=\"none\">\n <div\n ref={(el) => {\n if (el) refs.current.set(node.id, el);\n else refs.current.delete(node.id);\n }}\n role=\"treeitem\"\n aria-level={level}\n aria-posinset={row.posinset}\n aria-setsize={row.setsize}\n aria-expanded={branch ? isOpen : undefined}\n aria-selected={selected === node.id}\n aria-disabled={node.disabled || undefined}\n aria-busy={loading || undefined}\n aria-owns={branch && isOpen ? `${uid}-${node.id}-group` : undefined}\n tabIndex={node.id === focusId ? 0 : -1}\n onKeyDown={(e) => {\n if (e.target === e.currentTarget) onKeyDown(e, i);\n }}\n onFocus={(e) => {\n if (e.target === e.currentTarget) setActive(node.id);\n }}\n className={s.row({ className: \"outline-hidden focus-visible:ring-2 focus-visible:ring-ring\" })}\n data-selected={selected === node.id || undefined}\n data-disabled={node.disabled || undefined}\n style={{ paddingLeft: `${(level - 1) * 1.25 + 0.25}rem` }}\n onClick={() => {\n if (branch) toggle(node);\n choose(node);\n move(node.id);\n }}\n >\n <span className={s.toggle()} aria-hidden>\n {branch ? <ChevronGlyph direction={isOpen ? \"down\" : \"right\"} /> : null}\n </span>\n {node.icon ? <span className={s.icon()} aria-hidden>{node.icon}</span> : null}\n <span className={s.label()}>{node.label}</span>\n {node.meta ? <span className={s.meta()}>{node.meta}</span> : null}\n </div>\n {branch && isOpen ? (\n <ul role=\"group\" id={`${uid}-${node.id}-group`} className={s.group()}>\n {loading ? (\n <li role=\"none\" className=\"py-1 text-xs text-fg-secondary\" style={{ paddingLeft: `${level * 1.25 + 1.75}rem` }}>\n {loadingLabel}\n </li>\n ) : (\n render(node.children ?? [], level + 1)\n )}\n </ul>\n ) : null}\n </li>\n );\n });\n\n return (\n <ul role=\"tree\" aria-label={label} className={s.root({ className })}>\n {render(nodes, 1)}\n </ul>\n );\n}\n"],"mappings":";;;;;;;;;AAEA,YAAY,WAAW;AACvB,SAAS,UAAU;AAyJT,SAgCc,KAhCd;AApJH,IAAM,WAAW,GAAG;AAAA,EACzB,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KACE;AAAA,IAEF,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AACF,CAAC;AA8CD,IAAM,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|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type VerifiedBadgeProps = Omit<React.ComponentProps<"span">, "children"> & {
|
|
4
|
+
/** Its words (“Verified”), read — and shown with `showLabel` — passed translated. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Show the words beside the seal. Default false: the seal alone, named. */
|
|
7
|
+
showLabel?: boolean;
|
|
8
|
+
/** The seal's size: sm (14 px), md (16 px, default), lg (20 px). */
|
|
9
|
+
size?: "sm" | "md" | "lg";
|
|
10
|
+
/** On a photo: a ring of the media around the seal. */
|
|
11
|
+
onMedia?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** A seal that says the person or the account was verified (a selfie check, an ID), named in words. */
|
|
14
|
+
declare function VerifiedBadge({ label, showLabel, size, onMedia, className, ...props }: VerifiedBadgeProps): React.JSX.Element;
|
|
15
|
+
|
|
16
|
+
export { VerifiedBadge, type VerifiedBadgeProps };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/verified-badge/verified-badge.tsx
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
var SIZE = { sm: "h-3.5 w-3.5", md: "h-4 w-4", lg: "h-5 w-5" };
|
|
4
|
+
function VerifiedBadge({ label, showLabel, size = "md", onMedia, className, ...props }) {
|
|
5
|
+
return /* @__PURE__ */ jsxs("span", { role: "img", "aria-label": label, className: ["inline-flex items-center gap-1 text-xs font-bold", onMedia ? "text-fg-on-media" : "text-fg-accent", className].filter(Boolean).join(" "), ...props, children: [
|
|
6
|
+
/* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", className: [SIZE[size], "shrink-0"].join(" "), "aria-hidden": true, children: [
|
|
7
|
+
/* @__PURE__ */ jsx(
|
|
8
|
+
"path",
|
|
9
|
+
{
|
|
10
|
+
d: "M12 2.5l2.4 1.7 2.9-.1.9 2.8 2.3 1.8-.9 2.8.9 2.8-2.3 1.8-.9 2.8-2.9-.1L12 21.5l-2.4-1.7-2.9.1-.9-2.8-2.3-1.8.9-2.8-.9-2.8 2.3-1.8.9-2.8 2.9.1z",
|
|
11
|
+
className: onMedia ? "fill-accent stroke-fg-on-media" : "fill-accent",
|
|
12
|
+
strokeWidth: "1.2"
|
|
13
|
+
}
|
|
14
|
+
),
|
|
15
|
+
/* @__PURE__ */ jsx("path", { d: "M8.3 12.3l2.5 2.5 4.9-5.2", fill: "none", className: "stroke-on-accent", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round" })
|
|
16
|
+
] }),
|
|
17
|
+
showLabel ? /* @__PURE__ */ jsx("span", { "aria-hidden": true, children: label }) : null
|
|
18
|
+
] });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
VerifiedBadge
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=verified-badge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/verified-badge/verified-badge.tsx"],"sourcesContent":["// Server-safe. A seal that says the person or the account was verified: the accent, named in words.\nimport type * as React from \"react\";\n\nexport type VerifiedBadgeProps = Omit<React.ComponentProps<\"span\">, \"children\"> & {\n /** Its words (“Verified”), read — and shown with `showLabel` — passed translated. */\n label: string;\n /** Show the words beside the seal. Default false: the seal alone, named. */\n showLabel?: boolean;\n /** The seal's size: sm (14 px), md (16 px, default), lg (20 px). */\n size?: \"sm\" | \"md\" | \"lg\";\n /** On a photo: a ring of the media around the seal. */\n onMedia?: boolean;\n};\n\nconst SIZE = { sm: \"h-3.5 w-3.5\", md: \"h-4 w-4\", lg: \"h-5 w-5\" } as const;\n\n/** A seal that says the person or the account was verified (a selfie check, an ID), named in words. */\nexport function VerifiedBadge({ label, showLabel, size = \"md\", onMedia, className, ...props }: VerifiedBadgeProps) {\n return (\n <span role=\"img\" aria-label={label} className={[\"inline-flex items-center gap-1 text-xs font-bold\", onMedia ? \"text-fg-on-media\" : \"text-fg-accent\", className].filter(Boolean).join(\" \")} {...props}>\n <svg viewBox=\"0 0 24 24\" className={[SIZE[size], \"shrink-0\"].join(\" \")} aria-hidden>\n <path\n d=\"M12 2.5l2.4 1.7 2.9-.1.9 2.8 2.3 1.8-.9 2.8.9 2.8-2.3 1.8-.9 2.8-2.9-.1L12 21.5l-2.4-1.7-2.9.1-.9-2.8-2.3-1.8.9-2.8-.9-2.8 2.3-1.8.9-2.8 2.9.1z\"\n className={onMedia ? \"fill-accent stroke-fg-on-media\" : \"fill-accent\"}\n strokeWidth=\"1.2\"\n />\n <path d=\"M8.3 12.3l2.5 2.5 4.9-5.2\" fill=\"none\" className=\"stroke-on-accent\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n </svg>\n {showLabel ? <span aria-hidden>{label}</span> : null}\n </span>\n );\n}\n"],"mappings":";AAoBM,SACE,KADF;AANN,IAAM,OAAO,EAAE,IAAI,eAAe,IAAI,WAAW,IAAI,UAAU;AAGxD,SAAS,cAAc,EAAE,OAAO,WAAW,OAAO,MAAM,SAAS,WAAW,GAAG,MAAM,GAAuB;AACjH,SACE,qBAAC,UAAK,MAAK,OAAM,cAAY,OAAO,WAAW,CAAC,oDAAoD,UAAU,qBAAqB,kBAAkB,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GAAI,GAAG,OAC7L;AAAA,yBAAC,SAAI,SAAQ,aAAY,WAAW,CAAC,KAAK,IAAI,GAAG,UAAU,EAAE,KAAK,GAAG,GAAG,eAAW,MACjF;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,GAAE;AAAA,UACF,WAAW,UAAU,mCAAmC;AAAA,UACxD,aAAY;AAAA;AAAA,MACd;AAAA,MACA,oBAAC,UAAK,GAAE,6BAA4B,MAAK,QAAO,WAAU,oBAAmB,aAAY,OAAM,eAAc,SAAQ,gBAAe,SAAQ;AAAA,OAC9I;AAAA,IACC,YAAY,oBAAC,UAAK,eAAW,MAAE,iBAAM,IAAU;AAAA,KAClD;AAEJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krizaka/ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "The Krizaka front-end platform's components: the primitives (button, card, dialog, toast, menu, field, tabs, chip, switch, slider, command palette, theme, countdown…) on the semantic --kz-* tokens, the animated marks (Krizaka, Orazaka, Orochia, Yazakia, Yororis) and the motion signature — web and /native.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"krizaka",
|
|
@@ -134,6 +134,10 @@
|
|
|
134
134
|
"types": "./dist/separator.d.ts",
|
|
135
135
|
"import": "./dist/separator.js"
|
|
136
136
|
},
|
|
137
|
+
"./skip-link": {
|
|
138
|
+
"types": "./dist/skip-link.d.ts",
|
|
139
|
+
"import": "./dist/skip-link.js"
|
|
140
|
+
},
|
|
137
141
|
"./kbd": {
|
|
138
142
|
"types": "./dist/kbd.d.ts",
|
|
139
143
|
"import": "./dist/kbd.js"
|
|
@@ -494,6 +498,34 @@
|
|
|
494
498
|
"types": "./dist/pricing-page.d.ts",
|
|
495
499
|
"import": "./dist/pricing-page.js"
|
|
496
500
|
},
|
|
501
|
+
"./chat": {
|
|
502
|
+
"types": "./dist/chat.d.ts",
|
|
503
|
+
"import": "./dist/chat.js"
|
|
504
|
+
},
|
|
505
|
+
"./swipe-deck": {
|
|
506
|
+
"types": "./dist/swipe-deck.d.ts",
|
|
507
|
+
"import": "./dist/swipe-deck.js"
|
|
508
|
+
},
|
|
509
|
+
"./match-dialog": {
|
|
510
|
+
"types": "./dist/match-dialog.d.ts",
|
|
511
|
+
"import": "./dist/match-dialog.js"
|
|
512
|
+
},
|
|
513
|
+
"./tag-selector": {
|
|
514
|
+
"types": "./dist/tag-selector.d.ts",
|
|
515
|
+
"import": "./dist/tag-selector.js"
|
|
516
|
+
},
|
|
517
|
+
"./step-progress": {
|
|
518
|
+
"types": "./dist/step-progress.d.ts",
|
|
519
|
+
"import": "./dist/step-progress.js"
|
|
520
|
+
},
|
|
521
|
+
"./verified-badge": {
|
|
522
|
+
"types": "./dist/verified-badge.d.ts",
|
|
523
|
+
"import": "./dist/verified-badge.js"
|
|
524
|
+
},
|
|
525
|
+
"./photo-grid": {
|
|
526
|
+
"types": "./dist/photo-grid.d.ts",
|
|
527
|
+
"import": "./dist/photo-grid.js"
|
|
528
|
+
},
|
|
497
529
|
"./motion.css": "./dist/motion.css",
|
|
498
530
|
"./blocks.css": "./dist/blocks.css",
|
|
499
531
|
"./story.css": "./dist/story.css",
|
|
@@ -549,8 +581,8 @@
|
|
|
549
581
|
"*.css"
|
|
550
582
|
],
|
|
551
583
|
"peerDependencies": {
|
|
552
|
-
"@krizaka/query": ">=0.
|
|
553
|
-
"@krizaka/tailwind": ">=3.
|
|
584
|
+
"@krizaka/query": ">=0.2.0",
|
|
585
|
+
"@krizaka/tailwind": ">=3.6.0",
|
|
554
586
|
"@maplibre/maplibre-react-native": ">=11",
|
|
555
587
|
"@shopify/flash-list": ">=2",
|
|
556
588
|
"expo-camera": ">=16",
|
|
@@ -608,11 +640,11 @@
|
|
|
608
640
|
"typescript": "^5.9.0",
|
|
609
641
|
"vitest": "^4.1.11",
|
|
610
642
|
"zod": "^4.6.5",
|
|
611
|
-
"@krizaka/query": "0.
|
|
643
|
+
"@krizaka/query": "0.2.0",
|
|
612
644
|
"@krizaka/config": "0.3.1"
|
|
613
645
|
},
|
|
614
646
|
"engines": {
|
|
615
|
-
"node": ">=
|
|
647
|
+
"node": ">=22"
|
|
616
648
|
},
|
|
617
649
|
"publishConfig": {
|
|
618
650
|
"access": "public"
|
|
@@ -668,7 +700,7 @@
|
|
|
668
700
|
{
|
|
669
701
|
"name": "./native (bundled into the app by Metro, never downloaded: a regression guard, not a budget)",
|
|
670
702
|
"path": "dist/native.js",
|
|
671
|
-
"limit": "
|
|
703
|
+
"limit": "47.5 kB",
|
|
672
704
|
"gzip": true
|
|
673
705
|
},
|
|
674
706
|
{
|
|
@@ -877,6 +909,16 @@
|
|
|
877
909
|
"clsx"
|
|
878
910
|
]
|
|
879
911
|
},
|
|
912
|
+
{
|
|
913
|
+
"name": "./skip-link",
|
|
914
|
+
"path": "dist/skip-link.js",
|
|
915
|
+
"limit": "1 kB",
|
|
916
|
+
"gzip": true,
|
|
917
|
+
"ignore": [
|
|
918
|
+
"tailwind-variants",
|
|
919
|
+
"clsx"
|
|
920
|
+
]
|
|
921
|
+
},
|
|
880
922
|
{
|
|
881
923
|
"name": "./kbd",
|
|
882
924
|
"path": "dist/kbd.js",
|
|
@@ -1869,6 +1911,76 @@
|
|
|
1869
1911
|
"expo-image-picker",
|
|
1870
1912
|
"@krizaka/ui"
|
|
1871
1913
|
]
|
|
1914
|
+
},
|
|
1915
|
+
{
|
|
1916
|
+
"name": "./photo-grid",
|
|
1917
|
+
"path": "dist/photo-grid.js",
|
|
1918
|
+
"limit": "2.5 kB",
|
|
1919
|
+
"gzip": true,
|
|
1920
|
+
"ignore": [
|
|
1921
|
+
"tailwind-variants",
|
|
1922
|
+
"clsx"
|
|
1923
|
+
]
|
|
1924
|
+
},
|
|
1925
|
+
{
|
|
1926
|
+
"name": "./swipe-deck",
|
|
1927
|
+
"path": "dist/swipe-deck.js",
|
|
1928
|
+
"limit": "3 kB",
|
|
1929
|
+
"gzip": true,
|
|
1930
|
+
"ignore": [
|
|
1931
|
+
"tailwind-variants",
|
|
1932
|
+
"clsx"
|
|
1933
|
+
]
|
|
1934
|
+
},
|
|
1935
|
+
{
|
|
1936
|
+
"name": "./verified-badge",
|
|
1937
|
+
"path": "dist/verified-badge.js",
|
|
1938
|
+
"limit": "1 kB",
|
|
1939
|
+
"gzip": true,
|
|
1940
|
+
"ignore": [
|
|
1941
|
+
"tailwind-variants",
|
|
1942
|
+
"clsx"
|
|
1943
|
+
]
|
|
1944
|
+
},
|
|
1945
|
+
{
|
|
1946
|
+
"name": "./match-dialog",
|
|
1947
|
+
"path": "dist/match-dialog.js",
|
|
1948
|
+
"limit": "20 kB",
|
|
1949
|
+
"gzip": true,
|
|
1950
|
+
"ignore": [
|
|
1951
|
+
"tailwind-variants",
|
|
1952
|
+
"clsx"
|
|
1953
|
+
]
|
|
1954
|
+
},
|
|
1955
|
+
{
|
|
1956
|
+
"name": "./tag-selector",
|
|
1957
|
+
"path": "dist/tag-selector.js",
|
|
1958
|
+
"limit": "10 kB",
|
|
1959
|
+
"gzip": true,
|
|
1960
|
+
"ignore": [
|
|
1961
|
+
"tailwind-variants",
|
|
1962
|
+
"clsx"
|
|
1963
|
+
]
|
|
1964
|
+
},
|
|
1965
|
+
{
|
|
1966
|
+
"name": "./step-progress",
|
|
1967
|
+
"path": "dist/step-progress.js",
|
|
1968
|
+
"limit": "1 kB",
|
|
1969
|
+
"gzip": true,
|
|
1970
|
+
"ignore": [
|
|
1971
|
+
"tailwind-variants",
|
|
1972
|
+
"clsx"
|
|
1973
|
+
]
|
|
1974
|
+
},
|
|
1975
|
+
{
|
|
1976
|
+
"name": "./chat",
|
|
1977
|
+
"path": "dist/chat.js",
|
|
1978
|
+
"limit": "7 kB",
|
|
1979
|
+
"gzip": true,
|
|
1980
|
+
"ignore": [
|
|
1981
|
+
"tailwind-variants",
|
|
1982
|
+
"clsx"
|
|
1983
|
+
]
|
|
1872
1984
|
}
|
|
1873
1985
|
],
|
|
1874
1986
|
"dependencies": {
|
|
@@ -1883,8 +1995,8 @@
|
|
|
1883
1995
|
"radix-ui": "^1.7.0",
|
|
1884
1996
|
"sonner": "^2.0.8",
|
|
1885
1997
|
"tailwind-variants": "^3.3.1",
|
|
1886
|
-
"@krizaka/
|
|
1887
|
-
"@krizaka/
|
|
1998
|
+
"@krizaka/intl": "^0.2.0",
|
|
1999
|
+
"@krizaka/tokens": "^3.6.0"
|
|
1888
2000
|
},
|
|
1889
2001
|
"scripts": {
|
|
1890
2002
|
"build": "node -e \"const fs=require('node:fs');fs.rmSync('dist',{recursive:true,force:true});for(const f of fs.readdirSync('registry/examples',{recursive:true}))if(/\\.(js|d\\.ts)$/.test(f))fs.rmSync('registry/examples/'+f)\" && tsup && node -e \"require('node:fs').copyFileSync('src/motion.css','dist/motion.css');require('node:fs').copyFileSync('src/blocks.css','dist/blocks.css');require('node:fs').copyFileSync('src/story.css','dist/story.css')\" && node scripts/build-registry.mjs",
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"summary": "Something done, and what it replaced: a milestone reached, a dare completed, a problem out of the way — on one grid of hairlines in a list, their badges arriving one by one; with three line emblems.",
|
|
6
6
|
"description": "Something done, and what it replaced: a milestone reached, a dare completed, a problem out of the way — on one grid of hairlines in a list, their badges arriving one by one; with three line emblems.",
|
|
7
7
|
"status": "beta",
|
|
8
|
+
"deprecated": null,
|
|
8
9
|
"category": "data-display",
|
|
9
10
|
"platforms": "web",
|
|
10
11
|
"whenToUse": [
|
|
@@ -193,7 +194,7 @@
|
|
|
193
194
|
},
|
|
194
195
|
{
|
|
195
196
|
"path": "meta.ts",
|
|
196
|
-
"content": "// The documentation of a component, carried by its code: each primitive has a `meta.ts` beside its source\n// (`src/<name>/meta.ts`; a component that exists only in React Native: `src/native/meta/<name>.ts`). Never built into\n// the package: `scripts/build-registry.mjs` reads them into `registry/<name>.json`, which krizaka.com renders as\n// /docs/ui/<name>, and `scripts/registry.test.mjs` fails when one is missing or incomplete.\n//\n// Why a typed module and not JSDoc tags: the fields are lists and links (`related`, `whenNotToUse[].use`, examples),\n// which a type checks and a comment does not; the file is plain data (erasable TypeScript), so Node reads it without a\n// compiler, and an editor completes it.\n\n/** Every documented component: the web primitives (one entry of the package each) and the native-only ones. */\nexport type ComponentName =\n | \"achievement\"\n | \"action-bar\"\n | \"activity-feed\"\n | \"action-sheet\"\n | \"alert\"\n | \"app-shell\"\n | \"argument-card\"\n | \"audio-player\"\n | \"auth-layout\"\n | \"avatar\"\n | \"badge\"\n | \"button\"\n | \"card\"\n | \"card-grid\"\n | \"catalogue-page\"\n | \"changelog-page\"\n | \"checkbox\"\n | \"chip\"\n | \"chip-link\"\n | \"choice-grid\"\n | \"cn\"\n | \"code-block\"\n | \"combobox\"\n | \"command\"\n | \"component-page\"\n | \"confirm-button\"\n | \"contact-page\"\n | \"continue-prompt\"\n | \"countdown\"\n | \"cta-panel\"\n | \"dashboard-layout\"\n | \"data-table\"\n | \"date-picker\"\n | \"decision-list\"\n | \"description-list\"\n | \"detail-layout\"\n | \"dialog\"\n | \"docs-article-page\"\n | \"docs-hub-page\"\n | \"docs-layout\"\n | \"dropdown-menu\"\n | \"empty-state\"\n | \"error-page\"\n | \"fab\"\n | \"field\"\n | \"file-upload\"\n | \"filter-bar\"\n | \"form\"\n | \"gallery-page\"\n | \"glow-card\"\n | \"goal-gauge\"\n | \"header\"\n | \"how-it-works-page\"\n | \"image-cropper\"\n | \"image-viewer\"\n | \"iso\"\n | \"kanban\"\n | \"kbd\"\n | \"landing-page\"\n | \"landscape\"\n | \"legal-page\"\n | \"link-card\"\n | \"list\"\n | \"loader\"\n | \"map\"\n | \"longform-page\"\n | \"marketing-layout\"\n | \"marquee\"\n | \"mascot-quote\"\n | \"mascot-state\"\n | \"mascots\"\n | \"media-capture\"\n | \"media-picker\"\n | \"meter\"\n | \"nav-bar\"\n | \"number-ticker\"\n | \"onboarding\"\n | \"otp-input\"\n | \"page\"\n | \"page-header\"\n | \"page-hero\"\n | \"pagination\"\n | \"permission-prompt\"\n | \"pointer-light\"\n | \"popover\"\n | \"pricing-page\"\n | \"product-page\"\n | \"profile-card\"\n | \"progress\"\n | \"promise-card\"\n | \"pull-to-refresh\"\n | \"radio-group\"\n | \"scroll-stage\"\n | \"search-field\"\n | \"section-backdrop\"\n | \"segmented\"\n | \"separator\"\n | \"settings-layout\"\n | \"skeleton\"\n | \"slider\"\n | \"slot\"\n | \"spinner\"\n | \"split-view\"\n | \"stage-banner\"\n | \"stat\"\n | \"status-page\"\n | \"stepper\"\n | \"swipeable-row\"\n | \"switch\"\n | \"tab-bar\"\n | \"tabs\"\n | \"tag-input\"\n | \"terminal-replay\"\n | \"theme\"\n | \"toast\"\n | \"toc\"\n | \"tooltip\"\n | \"tree-view\"\n | \"txt\"\n | \"video-player\"\n | \"video-trimmer\"\n | \"virtual\";\n\n/** Where a component exists: `@krizaka/ui/<name>` (web), `@krizaka/ui/native` (React Native), or both. */\nexport type Platform = \"web\" | \"native\" | \"both\";\n\n/** `stable`: its API only changes in a major. `beta`: it may still change in a minor. */\nexport type Status = \"stable\" | \"beta\";\n\n/**\n * The group of the catalogue. `media`: video, sound, camera, files, cropping. `blocks`: the page blocks — the frame,\n * the hero, sections, cards that lead or argue, decisions, code, calls to act — that every page of a site is made of.\n * `layouts`: the shells of whole screens — an application, a dashboard, settings, sign-in, an object, a list and its\n * item, a site's page, a documentation page — each with its screens. `templates`: the page templates — whole pages of a\n * site (a landing, a product, a docs hub, a long read, a changelog, pricing, status, an error…), each a distinct\n * composition of the blocks, words and content as props.\n */\nexport type Category = \"actions\" | \"forms\" | \"navigation\" | \"overlays\" | \"feedback\" | \"data-display\" | \"media\" | \"blocks\" | \"layouts\" | \"templates\" | \"layout\" | \"foundations\";\n\n/**\n * A named example: the file `registry/examples/<component>/<name>.tsx` (web) or\n * `registry/examples/<component>/native/<name>.tsx` (React Native) — at most 40 lines, imported by the stories and\n * shown (live, with its code) by the documentation.\n */\nexport interface Example {\n /** The file name, kebab-case (`primary`, `icon-button`). */\n readonly name: string;\n /** A short title (`Primary`, `Icon button`). */\n readonly title: string;\n /** One or two sentences: when this variant is the right one. */\n readonly description: string;\n /**\n * A template: a whole screen of a product composed from the platform (a layout and its blocks, real words, its phone\n * version thought out), copied as a starting point — at most 160 lines, listed on krizaka.com/docs/ui/templates.\n */\n readonly template?: boolean;\n}\n\n/** One platform's side of a component. */\nexport interface PlatformDocs {\n /** The names to import (`[\"Button\", \"IconButton\"]`): from `@krizaka/ui/<name>` on the web, `@krizaka/ui/native` in React Native. */\n readonly imports: readonly string[];\n /** The examples, in reading order; the first one is the component's preview. */\n readonly examples: readonly Example[];\n}\n\n/** The React Native side: the same concept, and what differs from the web API. */\nexport interface NativeDocs extends PlatformDocs {\n /**\n * The entry to import from when it is not `@krizaka/ui/native`: a component that needs an Expo module (an optional\n * peer) has its own, `@krizaka/ui/native/<name>`, so an app that does not use it never installs the module.\n */\n readonly entry?: string;\n /** What differs from the web API (`label` instead of children…); empty for a native-only component. */\n readonly differences: readonly string[];\n}\n\nexport interface KeyboardInteraction {\n /** The keys, as written on a keyboard: `Space`, `Enter`, `Arrow keys`, `Esc`, `Tab`. */\n readonly keys: string;\n /** What they do. */\n readonly action: string;\n}\n\nexport interface ComponentMeta {\n /** The display name: `Button`, `Dropdown menu`. */\n readonly title: string;\n /** One sentence: what it is. */\n readonly summary: string;\n readonly status: Status;\n readonly category: Category;\n /** Must match the sides below: `both` ⇔ `web` and `native`. */\n readonly platforms: Platform;\n /** When to reach for it: concrete situations, one per item. */\n readonly whenToUse: readonly string[];\n /** When not to — and what to use instead (`use`), when another component is the answer. */\n readonly whenNotToUse: readonly { readonly when: string; readonly use?: ComponentName }[];\n /** How to use it well: wording, placement, composition. */\n readonly bestPractices: readonly string[];\n readonly accessibility: {\n /** The keyboard, when it does more than Tab and Enter. */\n readonly keyboard: readonly KeyboardInteraction[];\n /** Roles, names and announcements: what the component does, what the app must provide. */\n readonly notes: readonly string[];\n };\n /** The components a reader of this page should know about. */\n readonly related: readonly ComponentName[];\n readonly web?: PlatformDocs;\n readonly native?: NativeDocs;\n}\n"
|
|
197
|
+
"content": "// The documentation of a component, carried by its code: each primitive has a `meta.ts` beside its source\n// (`src/<name>/meta.ts`; a component that exists only in React Native: `src/native/meta/<name>.ts`). Never built into\n// the package: `scripts/build-registry.mjs` reads them into `registry/<name>.json`, which krizaka.com renders as\n// /docs/ui/<name>, and `scripts/registry.test.mjs` fails when one is missing or incomplete.\n//\n// Why a typed module and not JSDoc tags: the fields are lists and links (`related`, `whenNotToUse[].use`, examples),\n// which a type checks and a comment does not; the file is plain data (erasable TypeScript), so Node reads it without a\n// compiler, and an editor completes it.\n\n/** Every documented component: the web primitives (one entry of the package each) and the native-only ones. */\nexport type ComponentName =\n | \"achievement\"\n | \"action-bar\"\n | \"activity-feed\"\n | \"action-sheet\"\n | \"alert\"\n | \"app-shell\"\n | \"argument-card\"\n | \"audio-player\"\n | \"auth-layout\"\n | \"avatar\"\n | \"badge\"\n | \"button\"\n | \"card\"\n | \"card-grid\"\n | \"catalogue-page\"\n | \"changelog-page\"\n | \"chat\"\n | \"checkbox\"\n | \"chip\"\n | \"chip-link\"\n | \"choice-grid\"\n | \"cn\"\n | \"code-block\"\n | \"combobox\"\n | \"command\"\n | \"component-page\"\n | \"confirm-button\"\n | \"contact-page\"\n | \"continue-prompt\"\n | \"countdown\"\n | \"cta-panel\"\n | \"dashboard-layout\"\n | \"data-table\"\n | \"date-picker\"\n | \"decision-list\"\n | \"description-list\"\n | \"detail-layout\"\n | \"dialog\"\n | \"docs-article-page\"\n | \"docs-hub-page\"\n | \"docs-layout\"\n | \"dropdown-menu\"\n | \"empty-state\"\n | \"error-page\"\n | \"fab\"\n | \"field\"\n | \"file-upload\"\n | \"filter-bar\"\n | \"form\"\n | \"gallery-page\"\n | \"glow-card\"\n | \"goal-gauge\"\n | \"header\"\n | \"how-it-works-page\"\n | \"image-cropper\"\n | \"image-viewer\"\n | \"iso\"\n | \"kanban\"\n | \"kbd\"\n | \"landing-page\"\n | \"landscape\"\n | \"legal-page\"\n | \"link-card\"\n | \"list\"\n | \"loader\"\n | \"map\"\n | \"longform-page\"\n | \"marketing-layout\"\n | \"marquee\"\n | \"mascot-quote\"\n | \"mascot-state\"\n | \"mascots\"\n | \"match-dialog\"\n | \"media-capture\"\n | \"media-picker\"\n | \"meter\"\n | \"nav-bar\"\n | \"number-ticker\"\n | \"onboarding\"\n | \"otp-input\"\n | \"page\"\n | \"page-header\"\n | \"page-hero\"\n | \"pagination\"\n | \"permission-prompt\"\n | \"photo-grid\"\n | \"pointer-light\"\n | \"popover\"\n | \"pricing-page\"\n | \"product-page\"\n | \"profile-card\"\n | \"progress\"\n | \"promise-card\"\n | \"pull-to-refresh\"\n | \"radio-group\"\n | \"screen\"\n | \"scroll-stage\"\n | \"search-field\"\n | \"section-backdrop\"\n | \"segmented\"\n | \"separator\"\n | \"settings-layout\"\n | \"skeleton\"\n | \"skip-link\"\n | \"slider\"\n | \"slot\"\n | \"spinner\"\n | \"split-view\"\n | \"splash-handoff\"\n | \"stage-banner\"\n | \"stat\"\n | \"status-page\"\n | \"step-progress\"\n | \"stepper\"\n | \"swipe-deck\"\n | \"swipeable-row\"\n | \"switch\"\n | \"tab-bar\"\n | \"tabs\"\n | \"tag-input\"\n | \"tag-selector\"\n | \"terminal-replay\"\n | \"theme\"\n | \"toast\"\n | \"toc\"\n | \"tooltip\"\n | \"tree-view\"\n | \"txt\"\n | \"verified-badge\"\n | \"video-player\"\n | \"video-trimmer\"\n | \"virtual\";\n\n/** Where a component exists: `@krizaka/ui/<name>` (web), `@krizaka/ui/native` (React Native), or both. */\nexport type Platform = \"web\" | \"native\" | \"both\";\n\n/**\n * `stable`: its API only changes in a major. `beta`: it may still change in a minor. `deprecated`: no product uses it and\n * no work plans to — it still works, says what replaces it, and goes in the major named by `deprecated.removedIn`.\n */\nexport type Status = \"stable\" | \"beta\" | \"deprecated\";\n\n/** What a deprecated component says (required when `status` is `deprecated`, absent otherwise). */\nexport interface Deprecation {\n /** The version that deprecated it (`3.6.0`). */\n readonly since: string;\n /** The major that removes it (`4.0.0`). */\n readonly removedIn: string;\n /** What replaces it, when a component does. */\n readonly use?: ComponentName;\n /** Why it goes: no product uses it, no planned work needs it. */\n readonly reason: string;\n}\n\n/**\n * The group of the catalogue. `media`: video, sound, camera, files, cropping. `blocks`: the page blocks — the frame,\n * the hero, sections, cards that lead or argue, decisions, code, calls to act — that every page of a site is made of.\n * `layouts`: the shells of whole screens — an application, a dashboard, settings, sign-in, an object, a list and its\n * item, a site's page, a documentation page — each with its screens. `templates`: the page templates — whole pages of a\n * site (a landing, a product, a docs hub, a long read, a changelog, pricing, status, an error…), each a distinct\n * composition of the blocks, words and content as props.\n */\nexport type Category = \"actions\" | \"forms\" | \"navigation\" | \"overlays\" | \"feedback\" | \"data-display\" | \"media\" | \"blocks\" | \"layouts\" | \"templates\" | \"layout\" | \"foundations\";\n\n/** Why a reader needs a template: the seven intents the templates are grouped by (sidebar sub-headings, catalogue filter). */\nexport type TemplatePurpose = \"convince\" | \"explain\" | \"show\" | \"act\" | \"operate\" | \"converse\" | \"recover\";\n\n/** The groups of templates, in reading order: the title, and the one line that says when to come to that group. */\nexport const templatePurposes = {\n convince: { title: \"Convince\", useWhen: \"You come here when a visitor must decide: a landing, a product, a price, a comparison, a proof.\" },\n explain: { title: \"Explain\", useWhen: \"You come here when a reader must understand: how it works, a documentation hub or article, a changelog, a FAQ, a policy.\" },\n show: { title: \"Show\", useWhen: \"You come here when the work itself is the argument: a gallery, a story, a case study, an object and its details.\" },\n act: { title: \"Act\", useWhen: \"You come here when a person must do something once: reach the team, sign in or up, set up, pay.\" },\n operate: { title: \"Operate\", useWhen: \"You come here when a person works every day: a dashboard, a console with a table, settings, an app shell.\" },\n converse: { title: \"Converse\", useWhen: \"You come here when people talk: an inbox, a chat, comments, a notifications centre.\" },\n recover: { title: \"Recover\", useWhen: \"You come here when the way is blocked: an empty list, an error, a missing page, maintenance, a product still being built.\" },\n} as const satisfies Record<TemplatePurpose, { readonly title: string; readonly useWhen: string }>;\n\n/**\n * A named example: the file `registry/examples/<component>/<name>.tsx` (web) or\n * `registry/examples/<component>/native/<name>.tsx` (React Native) — at most 40 lines, imported by the stories and\n * shown (live, with its code) by the documentation.\n */\ninterface ExampleBase {\n /** The file name, kebab-case (`primary`, `icon-button`). */\n readonly name: string;\n /** A short title (`Primary`, `Icon button`). */\n readonly title: string;\n /** One or two sentences: when this variant is the right one. */\n readonly description: string;\n}\n\n/** A plain example, or a template: a whole screen with its intent (`purpose`) and the user goal its layout serves (`why`). */\nexport type Example =\n | (ExampleBase & { readonly template?: false; readonly purpose?: undefined; readonly why?: undefined })\n | (ExampleBase & {\n /**\n * A template: a whole screen of a product composed from the platform (a layout and its blocks, real words, its\n * phone version thought out), copied as a starting point — at most 160 lines, listed on krizaka.com/docs/ui/templates.\n */\n readonly template: true;\n /** The intent that groups it: why you need this block. */\n readonly purpose: TemplatePurpose;\n /** Why this layout: the user goal it serves, in one sentence. */\n readonly why: string;\n });\n\n/** One platform's side of a component. */\nexport interface PlatformDocs {\n /** The names to import (`[\"Button\", \"IconButton\"]`): from `@krizaka/ui/<name>` on the web, `@krizaka/ui/native` in React Native. */\n readonly imports: readonly string[];\n /** The examples, in reading order; the first one is the component's preview. */\n readonly examples: readonly Example[];\n}\n\n/** The React Native side: the same concept, and what differs from the web API. */\nexport interface NativeDocs extends PlatformDocs {\n /**\n * The entry to import from when it is not `@krizaka/ui/native`: a component that needs an Expo module (an optional\n * peer) has its own, `@krizaka/ui/native/<name>`, so an app that does not use it never installs the module.\n */\n readonly entry?: string;\n /** What differs from the web API (`label` instead of children…); empty for a native-only component. */\n readonly differences: readonly string[];\n}\n\nexport interface KeyboardInteraction {\n /** The keys, as written on a keyboard: `Space`, `Enter`, `Arrow keys`, `Esc`, `Tab`. */\n readonly keys: string;\n /** What they do. */\n readonly action: string;\n}\n\nexport interface ComponentMeta {\n /** The display name: `Button`, `Dropdown menu`. */\n readonly title: string;\n /** One sentence: what it is. */\n readonly summary: string;\n readonly status: Status;\n /** Required for, and only for, a `deprecated` component. */\n readonly deprecated?: Deprecation;\n readonly category: Category;\n /** Must match the sides below: `both` ⇔ `web` and `native`. */\n readonly platforms: Platform;\n /** When to reach for it: concrete situations, one per item. */\n readonly whenToUse: readonly string[];\n /** When not to — and what to use instead (`use`), when another component is the answer. */\n readonly whenNotToUse: readonly { readonly when: string; readonly use?: ComponentName }[];\n /** How to use it well: wording, placement, composition. */\n readonly bestPractices: readonly string[];\n readonly accessibility: {\n /** The keyboard, when it does more than Tab and Enter. */\n readonly keyboard: readonly KeyboardInteraction[];\n /** Roles, names and announcements: what the component does, what the app must provide. */\n readonly notes: readonly string[];\n };\n /** The components a reader of this page should know about. */\n readonly related: readonly ComponentName[];\n readonly web?: PlatformDocs;\n readonly native?: NativeDocs;\n}\n"
|
|
197
198
|
},
|
|
198
199
|
{
|
|
199
200
|
"path": "story-variant.ts",
|