@zyro-sec/ui 1.0.0 → 1.0.1
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/AGENTS.md +29 -0
- package/bunfig.toml +2 -0
- package/package.json +21 -114
- package/perf/motion.bench.ts +14 -0
- package/perf/motion.ts +16 -0
- package/script/build-oc2-v2-overrides.ts +38 -0
- package/script/colors.txt +288 -0
- package/script/generate-spinner.ts +121 -0
- package/script/pack.ts +5 -0
- package/script/tailwind.ts +24 -0
- package/src/actions/button/button.stories.tsx +158 -0
- package/src/actions/icon-button/icon-button.stories.tsx +122 -0
- package/src/actions/split-button/split-button.stories.tsx +59 -0
- package/src/assets/favicon/apple-touch-icon-v3.png +0 -0
- package/src/assets/favicon/apple-touch-icon.png +0 -0
- package/src/assets/favicon/favicon-96x96-v3.png +0 -0
- package/src/assets/favicon/favicon-96x96.png +0 -0
- package/src/assets/favicon/favicon-v3.ico +0 -0
- package/src/assets/favicon/favicon-v3.svg +7 -0
- package/src/assets/favicon/favicon.ico +0 -0
- package/src/assets/favicon/favicon.svg +7 -0
- package/src/assets/favicon/site.webmanifest +24 -0
- package/src/assets/favicon/web-app-manifest-192x192.png +0 -0
- package/src/assets/favicon/web-app-manifest-512x512.png +0 -0
- package/src/assets/icons/provider/302ai.svg +7 -0
- package/src/assets/icons/provider/abacus.svg +14 -0
- package/src/assets/icons/provider/aihubmix.svg +3 -0
- package/src/assets/icons/provider/alibaba-cn.svg +3 -0
- package/src/assets/icons/provider/alibaba-coding-plan-cn.svg +3 -0
- package/src/assets/icons/provider/alibaba-coding-plan.svg +3 -0
- package/src/assets/icons/provider/alibaba.svg +3 -0
- package/src/assets/icons/provider/amazon-bedrock.svg +3 -0
- package/src/assets/icons/provider/anthropic.svg +3 -0
- package/src/assets/icons/provider/azure-cognitive-services.svg +24 -0
- package/src/assets/icons/provider/azure.svg +3 -0
- package/src/assets/icons/provider/bailing.svg +3 -0
- package/src/assets/icons/provider/baseten.svg +3 -0
- package/src/assets/icons/provider/berget.svg +3 -0
- package/src/assets/icons/provider/cerebras.svg +4 -0
- package/src/assets/icons/provider/chutes.svg +24 -0
- package/src/assets/icons/provider/clarifai.svg +24 -0
- package/src/assets/icons/provider/claude-agent.svg +3 -0
- package/src/assets/icons/provider/cloudferro-sherlock.svg +5 -0
- package/src/assets/icons/provider/cloudflare-ai-gateway.svg +4 -0
- package/src/assets/icons/provider/cloudflare-workers-ai.svg +4 -0
- package/src/assets/icons/provider/cohere.svg +5 -0
- package/src/assets/icons/provider/cortecs.svg +24 -0
- package/src/assets/icons/provider/deepinfra.svg +4 -0
- package/src/assets/icons/provider/deepseek.svg +3 -0
- package/src/assets/icons/provider/digitalocean.svg +6 -0
- package/src/assets/icons/provider/dinference.svg +1 -0
- package/src/assets/icons/provider/drun.svg +8 -0
- package/src/assets/icons/provider/evroc.svg +3 -0
- package/src/assets/icons/provider/fastrouter.svg +3 -0
- package/src/assets/icons/provider/fireworks-ai.svg +3 -0
- package/src/assets/icons/provider/firmware.svg +18 -0
- package/src/assets/icons/provider/friendli.svg +3 -0
- package/src/assets/icons/provider/github-copilot.svg +3 -0
- package/src/assets/icons/provider/github-models.svg +3 -0
- package/src/assets/icons/provider/gitlab.svg +3 -0
- package/src/assets/icons/provider/google-vertex-anthropic.svg +24 -0
- package/src/assets/icons/provider/google-vertex.svg +10 -0
- package/src/assets/icons/provider/google.svg +3 -0
- package/src/assets/icons/provider/groq.svg +3 -0
- package/src/assets/icons/provider/helicone.svg +6 -0
- package/src/assets/icons/provider/huggingface.svg +3 -0
- package/src/assets/icons/provider/iflowcn.svg +3 -0
- package/src/assets/icons/provider/inception.svg +4 -0
- package/src/assets/icons/provider/inference.svg +3 -0
- package/src/assets/icons/provider/io-net.svg +5 -0
- package/src/assets/icons/provider/jiekou.svg +4 -0
- package/src/assets/icons/provider/kilo.svg +4 -0
- package/src/assets/icons/provider/kimi-for-coding.svg +3 -0
- package/src/assets/icons/provider/kuae-cloud-coding-plan.svg +3 -0
- package/src/assets/icons/provider/llama.svg +3 -0
- package/src/assets/icons/provider/lmstudio.svg +24 -0
- package/src/assets/icons/provider/lucidquery.svg +3 -0
- package/src/assets/icons/provider/meganova.svg +3 -0
- package/src/assets/icons/provider/meituan.svg +6 -0
- package/src/assets/icons/provider/meta.svg +3 -0
- package/src/assets/icons/provider/minimax-cn-coding-plan.svg +24 -0
- package/src/assets/icons/provider/minimax-cn.svg +3 -0
- package/src/assets/icons/provider/minimax-coding-plan.svg +24 -0
- package/src/assets/icons/provider/minimax.svg +3 -0
- package/src/assets/icons/provider/mistral.svg +3 -0
- package/src/assets/icons/provider/moark.svg +3 -0
- package/src/assets/icons/provider/modelscope.svg +5 -0
- package/src/assets/icons/provider/moonshotai-cn.svg +3 -0
- package/src/assets/icons/provider/moonshotai.svg +3 -0
- package/src/assets/icons/provider/morph.svg +24 -0
- package/src/assets/icons/provider/nano-gpt.svg +3 -0
- package/src/assets/icons/provider/nebius.svg +4 -0
- package/src/assets/icons/provider/nova.svg +3 -0
- package/src/assets/icons/provider/novita-ai.svg +10 -0
- package/src/assets/icons/provider/nvidia.svg +3 -0
- package/src/assets/icons/provider/ollama-cloud.svg +7 -0
- package/src/assets/icons/provider/openai.svg +3 -0
- package/src/assets/icons/provider/opencode-go.svg +3 -0
- package/src/assets/icons/provider/opencode.svg +3 -0
- package/src/assets/icons/provider/openrouter.svg +3 -0
- package/src/assets/icons/provider/ovhcloud.svg +3 -0
- package/src/assets/icons/provider/perplexity-agent.svg +3 -0
- package/src/assets/icons/provider/perplexity.svg +3 -0
- package/src/assets/icons/provider/poe.svg +7 -0
- package/src/assets/icons/provider/privatemode-ai.svg +5 -0
- package/src/assets/icons/provider/qihang-ai.svg +9 -0
- package/src/assets/icons/provider/qiniu-ai.svg +7 -0
- package/src/assets/icons/provider/reflection.svg +3 -0
- package/src/assets/icons/provider/requesty.svg +24 -0
- package/src/assets/icons/provider/sap-ai-core.svg +24 -0
- package/src/assets/icons/provider/scaleway.svg +5 -0
- package/src/assets/icons/provider/siliconflow-cn.svg +3 -0
- package/src/assets/icons/provider/siliconflow.svg +3 -0
- package/src/assets/icons/provider/stackit.svg +4 -0
- package/src/assets/icons/provider/stepfun.svg +16 -0
- package/src/assets/icons/provider/submodel.svg +3 -0
- package/src/assets/icons/provider/synthetic.svg +24 -0
- package/src/assets/icons/provider/tencent-coding-plan.svg +5 -0
- package/src/assets/icons/provider/tencent.svg +3 -0
- package/src/assets/icons/provider/thinkingmachines.svg +3 -0
- package/src/assets/icons/provider/togetherai.svg +4 -0
- package/src/assets/icons/provider/upstage.svg +24 -0
- package/src/assets/icons/provider/v0.svg +3 -0
- package/src/assets/icons/provider/venice.svg +4 -0
- package/src/assets/icons/provider/vercel.svg +3 -0
- package/src/assets/icons/provider/vivgrid.svg +4 -0
- package/src/assets/icons/provider/vultr.svg +6 -0
- package/src/assets/icons/provider/wandb.svg +24 -0
- package/src/assets/icons/provider/xai.svg +3 -0
- package/src/assets/icons/provider/xiaomi.svg +3 -0
- package/src/assets/icons/provider/zai-coding-plan.svg +3 -0
- package/src/assets/icons/provider/zai.svg +3 -0
- package/src/assets/icons/provider/zenmux.svg +4 -0
- package/src/assets/icons/provider/zhipuai-coding-plan.svg +3 -0
- package/src/assets/icons/provider/zhipuai.svg +3 -0
- package/src/assets/images/social-share-black.png +0 -0
- package/src/assets/images/social-share-zen.png +0 -0
- package/src/assets/images/social-share.png +0 -0
- package/src/components/animated-number-machine.test.ts +140 -0
- package/src/components/animated-number.stories.tsx +35 -0
- package/src/components/app-icon.stories.tsx +73 -0
- package/src/components/card.stories.tsx +101 -0
- package/src/components/collapsible.stories.tsx +76 -0
- package/src/components/context-menu.stories.tsx +150 -0
- package/src/components/diagram-preview.stories.tsx +62 -0
- package/src/components/dock-surface.stories.tsx +26 -0
- package/src/components/document-surface.stories.tsx +42 -0
- package/src/components/error-details.stories.tsx +72 -0
- package/src/components/favicon.stories.tsx +49 -0
- package/src/components/file-icon-machine.test.ts +52 -0
- package/src/components/file-icon.stories.tsx +93 -0
- package/src/components/file-icons/sprite.svg +11707 -0
- package/src/components/font.stories.tsx +48 -0
- package/src/components/hover-card.stories.tsx +79 -0
- package/src/components/image-flight-machine.test.ts +184 -0
- package/src/components/image-flight.test.ts +173 -0
- package/src/components/image-preview.stories.tsx +392 -0
- package/src/components/image-zoom-machine.test.ts +154 -0
- package/src/components/image-zoom.test.ts +96 -0
- package/src/components/list.stories.tsx +221 -0
- package/src/components/logo.stories.tsx +62 -0
- package/src/components/menu-scroll.stories.tsx +73 -0
- package/src/components/popover-machine.test.ts +150 -0
- package/src/components/popover.stories.tsx +84 -0
- package/src/components/preview-controls.stories.tsx +40 -0
- package/src/components/progress.stories.tsx +69 -0
- package/src/components/provider-icon.stories.tsx +75 -0
- package/src/components/resize-handle-machine.test.ts +164 -0
- package/src/components/resize-handle.stories.tsx +81 -0
- package/src/components/rolling-number.stories.tsx +23 -0
- package/src/components/scroll-view-machine.test.ts +141 -0
- package/src/components/scroll-view.stories.tsx +68 -0
- package/src/components/scroll-view.test.ts +114 -0
- package/src/components/spinner-radar.test.ts +61 -0
- package/src/components/spinner.stories.tsx +40 -0
- package/src/components/sticky-accordion-header.stories.tsx +64 -0
- package/src/components/text-field-machine.test.ts +99 -0
- package/src/components/text-field.stories.tsx +132 -0
- package/src/components/text-reveal-machine.test.ts +157 -0
- package/src/components/text-reveal.stories.tsx +363 -0
- package/src/components/text-strikethrough.stories.tsx +296 -0
- package/src/components/thinking-heading.stories.tsx +900 -0
- package/src/components/truncated-text.stories.tsx +37 -0
- package/src/components/typewriter-machine.test.ts +177 -0
- package/src/components/typewriter.stories.tsx +51 -0
- package/src/context/dialog-machine.test.ts +295 -0
- package/src/context/i18n.test.ts +89 -0
- package/src/context/marked-base.test.ts +75 -0
- package/src/context/marked-parser.test.ts +167 -0
- package/src/context/marked-regression.test.ts +12 -0
- package/src/data-display/accordion/accordion.stories.tsx +76 -0
- package/src/data-display/avatar/avatar.stories.tsx +48 -0
- package/src/data-display/badge/badge.stories.tsx +75 -0
- package/src/data-display/diff-changes/diff-changes.stories.tsx +63 -0
- package/src/data-display/keybind/keybind.stories.tsx +77 -0
- package/src/data-display/line-comment/line-comment.stories.tsx +288 -0
- package/src/data-display/line-comment/machine.test.ts +385 -0
- package/src/data-display/project-avatar/animation-machine.test.ts +134 -0
- package/src/data-display/project-avatar/generated.test.ts +50 -0
- package/src/data-display/project-avatar/procedural.test.ts +16 -0
- package/src/data-display/project-avatar/project-avatar.stories.tsx +102 -0
- package/src/data-display/project-avatar/project-avatar.test.ts +21 -0
- package/src/data-display/project-avatar/project-icon-styles.stories.tsx +772 -0
- package/src/feedback/activity-ring/activity-ring.stories.tsx +20 -0
- package/src/feedback/loader/loader.stories.tsx +44 -0
- package/src/feedback/progress-circle/progress-circle.stories.tsx +56 -0
- package/src/feedback/toast/description.test.ts +20 -0
- package/src/feedback/toast/machine.test.ts +106 -0
- package/src/feedback/toast/toast.stories.tsx +186 -0
- package/src/forms/checkbox/checkbox.stories.tsx +104 -0
- package/src/forms/field/field.stories.tsx +129 -0
- package/src/forms/inline-input/inline-input.stories.tsx +37 -0
- package/src/forms/radio/radio.stories.tsx +145 -0
- package/src/forms/redirect-paste/redirect-paste.stories.tsx +101 -0
- package/src/forms/search-list/navigation.test.ts +40 -0
- package/src/forms/search-list/search-list.stories.tsx +108 -0
- package/src/forms/select/machine.test.ts +105 -0
- package/src/forms/select/select.stories.tsx +208 -0
- package/src/forms/switch/switch.stories.tsx +97 -0
- package/src/forms/text-input/text-input.stories.tsx +220 -0
- package/src/forms/textarea/textarea.stories.tsx +137 -0
- package/src/forms/typeahead/machine.test.ts +143 -0
- package/src/forms/typeahead/typeahead.stories.tsx +113 -0
- package/src/hooks/auto-scroll-machine.test.ts +212 -0
- package/src/hooks/list-machine.test.ts +263 -0
- package/src/hooks/spin-phase.test.ts +32 -0
- package/src/hooks/use-filtered-list.test.ts +41 -0
- package/src/icons/icon/icon.stories.tsx +131 -0
- package/src/layout/divider/divider.stories.tsx +38 -0
- package/src/motion/README.md +113 -0
- package/src/motion/core.test.ts +328 -0
- package/src/motion-tuning-features.test.ts +129 -0
- package/src/motion-tuning.test.ts +68 -0
- package/src/navigation/menu/machine.test.ts +85 -0
- package/src/navigation/menu/menu.stories.tsx +328 -0
- package/src/navigation/menu/submenu-machine.test.ts +71 -0
- package/src/navigation/segmented-control/segmented-control.stories.tsx +115 -0
- package/src/navigation/segmented-control/segmented-control.test.ts +123 -0
- package/src/navigation/tab-state-indicator.stories.tsx +24 -0
- package/src/navigation/tabs/tabs.stories.tsx +193 -0
- package/src/overlays/dialog/dialog.stories.tsx +365 -0
- package/src/overlays/mcp-sign-in/machine.test.ts +215 -0
- package/src/overlays/tooltip/machine.test.ts +214 -0
- package/src/overlays/tooltip/tooltip.stories.tsx +155 -0
- package/src/styles/blue-tokens.stories.tsx +215 -0
- package/src/theme/desktop-theme.schema.json +168 -0
- package/src/theme/machine.test.ts +498 -0
- package/src/theme/v2/resolve.test.ts +120 -0
- package/src/typography/slash/slash.stories.tsx +26 -0
- package/src/typography/text-shimmer/machine.test.ts +117 -0
- package/src/typography/text-shimmer/text-shimmer.stories.tsx +64 -0
- package/src/typography/wordmark/wordmark.stories.tsx +19 -0
- package/test/solid-jsx.ts +20 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +23 -0
- package/vite.config.ts +61 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { spinnerCss } from "../../script/generate-spinner"
|
|
3
|
+
import { radarDots, radarOpacity } from "./spinner-radar"
|
|
4
|
+
|
|
5
|
+
test("the radar's dots fit the viewBox and light within one loop", () => {
|
|
6
|
+
const dots = radarDots()
|
|
7
|
+
|
|
8
|
+
expect(dots).toHaveLength(25)
|
|
9
|
+
dots.forEach((dot) => {
|
|
10
|
+
expect(dot.x).toBeGreaterThanOrEqual(0)
|
|
11
|
+
expect(dot.x + dot.size).toBeLessThanOrEqual(16)
|
|
12
|
+
expect(dot.at).toBeGreaterThanOrEqual(0)
|
|
13
|
+
expect(dot.at).toBeLessThan(1)
|
|
14
|
+
expect(dot.still).toBeGreaterThanOrEqual(0.2)
|
|
15
|
+
expect(dot.still).toBeLessThanOrEqual(1)
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test("the radar's brightest dot is never more than half a dot from its head", () => {
|
|
20
|
+
const dots = radarDots()
|
|
21
|
+
const centre = dots.find((dot) => dot.steady)!
|
|
22
|
+
|
|
23
|
+
const ring = dots
|
|
24
|
+
.filter((dot) => !dot.steady)
|
|
25
|
+
.map((dot) => ({
|
|
26
|
+
...dot,
|
|
27
|
+
ring: Math.round(Math.max(Math.abs(dot.x + dot.size / 2 - 8), Math.abs(dot.y + dot.size / 2 - 8))),
|
|
28
|
+
}))
|
|
29
|
+
|
|
30
|
+
const wrap = (turns: number) => turns - Math.round(turns)
|
|
31
|
+
|
|
32
|
+
Array.from({ length: 360 }, (_, step) => step / 360).forEach((head) => {
|
|
33
|
+
const lit = ring.map((dot) => radarOpacity(dot, head))
|
|
34
|
+
const top = Math.max(...lit)
|
|
35
|
+
const brightest = ring.filter((_, index) => lit[index]! > top - 1e-9)
|
|
36
|
+
|
|
37
|
+
expect(top).toBeGreaterThan(centre.still)
|
|
38
|
+
brightest.forEach((dot) => {
|
|
39
|
+
const offset = wrap(dot.at - head)
|
|
40
|
+
|
|
41
|
+
// The gap to the neighbour on the head's side, on the dot's own ring.
|
|
42
|
+
const gap = Math.min(
|
|
43
|
+
...ring
|
|
44
|
+
.filter(
|
|
45
|
+
(other) =>
|
|
46
|
+
other.ring === dot.ring && other !== dot && Math.sign(wrap(other.at - dot.at)) === -Math.sign(offset),
|
|
47
|
+
)
|
|
48
|
+
.map((other) => Math.abs(wrap(other.at - dot.at))),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
expect(Math.abs(offset)).toBeLessThanOrEqual(gap / 2 + 0.003)
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// The committed frames must be the radar's: run `bun run generate:spinner` after changing spinner-radar.ts.
|
|
57
|
+
test("spinner-frames.css is what generate-spinner.ts writes", async () => {
|
|
58
|
+
const committed = await Bun.file(new URL("./spinner-frames.css", import.meta.url)).text()
|
|
59
|
+
|
|
60
|
+
expect(committed.replaceAll("\r\n", "\n")).toBe(spinnerCss())
|
|
61
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Spinner } from "./spinner"
|
|
2
|
+
|
|
3
|
+
const docs = `### Overview
|
|
4
|
+
Dot-matrix indicator for AI activity: a running session, turn, subagent or tool. Busy session tabs, \`ActivityRing\`
|
|
5
|
+
and the session progress indicator render it. Other loading states use \`Loader\`.
|
|
6
|
+
|
|
7
|
+
### Variants and states
|
|
8
|
+
- Soft Radar: a lit head sweeps each ring of a 5×5 grid, leaving a fading trail, around a steady centre.
|
|
9
|
+
|
|
10
|
+
### Behavior
|
|
11
|
+
- One element painted through a CSS mask whose frames are a pre-rendered 90 fps APNG, so it runs no CSS animation and
|
|
12
|
+
every spinner on screen shares one loop and stays in phase.
|
|
13
|
+
- Reduced motion freezes it on a still pose.
|
|
14
|
+
|
|
15
|
+
### Accessibility
|
|
16
|
+
- Use alongside text or aria-live regions to convey loading state.
|
|
17
|
+
`
|
|
18
|
+
|
|
19
|
+
type Args = { size: number }
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
title: "UI/Spinner",
|
|
23
|
+
id: "components-spinner",
|
|
24
|
+
component: Spinner,
|
|
25
|
+
tags: ["autodocs"],
|
|
26
|
+
args: { size: 16 },
|
|
27
|
+
argTypes: {
|
|
28
|
+
size: { control: { type: "range", min: 12, max: 48, step: 1 } },
|
|
29
|
+
},
|
|
30
|
+
render: (args: Args) => <Spinner style={{ width: `${args.size}px`, height: `${args.size}px` }} />,
|
|
31
|
+
parameters: {
|
|
32
|
+
docs: {
|
|
33
|
+
description: {
|
|
34
|
+
component: docs,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const SoftRadar = {}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createEffect, createSignal } from "solid-js"
|
|
2
|
+
import { Accordion } from "@zyro-sec/ui/accordion"
|
|
3
|
+
import { StickyAccordionHeader } from "./sticky-accordion-header"
|
|
4
|
+
|
|
5
|
+
const docs = `### Overview
|
|
6
|
+
Sticky accordion header wrapper for persistent section labels.
|
|
7
|
+
|
|
8
|
+
Use only inside \`Accordion.Item\` with \`Accordion.Trigger\`.
|
|
9
|
+
|
|
10
|
+
### API
|
|
11
|
+
- Accepts standard header props and children.
|
|
12
|
+
|
|
13
|
+
### Variants and states
|
|
14
|
+
- Inherits accordion states.
|
|
15
|
+
|
|
16
|
+
### Behavior
|
|
17
|
+
- Renders inside an Accordion item header.
|
|
18
|
+
|
|
19
|
+
### Accessibility
|
|
20
|
+
- TODO: confirm semantics from Accordion.Header usage.
|
|
21
|
+
|
|
22
|
+
### Theming/tokens
|
|
23
|
+
- Uses \`data-component="sticky-accordion-header"\`.
|
|
24
|
+
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
title: "UI/StickyAccordionHeader",
|
|
29
|
+
id: "components-sticky-accordion-header",
|
|
30
|
+
component: StickyAccordionHeader,
|
|
31
|
+
tags: ["autodocs"],
|
|
32
|
+
parameters: {
|
|
33
|
+
docs: {
|
|
34
|
+
description: {
|
|
35
|
+
component: docs,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const Basic = {
|
|
42
|
+
args: { expanded: false, disabled: false },
|
|
43
|
+
render: (props: { expanded: boolean; disabled: boolean }) => {
|
|
44
|
+
const [expanded, setExpanded] = createSignal(props.expanded)
|
|
45
|
+
createEffect(() => setExpanded(props.expanded))
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Accordion
|
|
49
|
+
collapsible
|
|
50
|
+
value={expanded() ? ["first"] : []}
|
|
51
|
+
onChange={(items: string[]) => setExpanded(items.includes("first"))}
|
|
52
|
+
>
|
|
53
|
+
<Accordion.Item value="first" disabled={props.disabled}>
|
|
54
|
+
<StickyAccordionHeader>
|
|
55
|
+
<Accordion.Trigger>Sticky header</Accordion.Trigger>
|
|
56
|
+
</StickyAccordionHeader>
|
|
57
|
+
<Accordion.Content>
|
|
58
|
+
<div style={{ color: "var(--text-weak)", padding: "8px 0" }}>Accordion content.</div>
|
|
59
|
+
</Accordion.Content>
|
|
60
|
+
</Accordion.Item>
|
|
61
|
+
</Accordion>
|
|
62
|
+
)
|
|
63
|
+
},
|
|
64
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import {
|
|
3
|
+
INITIAL_TEXT_FIELD_COPY_STATE,
|
|
4
|
+
selectTextFieldCopied,
|
|
5
|
+
selectTextFieldCopyIcon,
|
|
6
|
+
selectTextFieldCopyLabelKey,
|
|
7
|
+
TEXT_FIELD_COPIED_MS,
|
|
8
|
+
TEXT_FIELD_COPY_TIMEOUT_MS,
|
|
9
|
+
transitionTextFieldCopy,
|
|
10
|
+
type TextFieldCopyEvent,
|
|
11
|
+
type TextFieldCopyState,
|
|
12
|
+
type TextFieldCopyTransition,
|
|
13
|
+
} from "./text-field-machine"
|
|
14
|
+
|
|
15
|
+
function run(state: TextFieldCopyState, ...events: TextFieldCopyEvent[]) {
|
|
16
|
+
return events.reduce<TextFieldCopyTransition>((result, event) => transitionTextFieldCopy(result.state, event), {
|
|
17
|
+
state,
|
|
18
|
+
effects: [],
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const request: TextFieldCopyEvent = { type: "copy.requested", value: "sk-123", enabled: true }
|
|
23
|
+
|
|
24
|
+
describe("transitionTextFieldCopy", () => {
|
|
25
|
+
test("claims the copy before the write starts, so a second click waits for it", () => {
|
|
26
|
+
const first = transitionTextFieldCopy(INITIAL_TEXT_FIELD_COPY_STATE, request)
|
|
27
|
+
|
|
28
|
+
expect(first.state).toEqual({ status: "copying", attempt: 1, keepCopied: false })
|
|
29
|
+
expect(first.effects).toEqual([
|
|
30
|
+
{ type: "clipboard.write", attempt: 1, value: "sk-123", timeoutMs: TEXT_FIELD_COPY_TIMEOUT_MS },
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
const second = transitionTextFieldCopy(first.state, request)
|
|
34
|
+
|
|
35
|
+
expect(second.state).toBe(first.state)
|
|
36
|
+
expect(second.effects).toEqual([])
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test("a repeat copy restarts the feedback window instead of ending it early", () => {
|
|
40
|
+
const copied = run(INITIAL_TEXT_FIELD_COPY_STATE, request, { type: "copy.succeeded", attempt: 1 })
|
|
41
|
+
|
|
42
|
+
expect(copied.effects).toEqual([
|
|
43
|
+
{ type: "timer.clear" },
|
|
44
|
+
{ type: "reset.schedule", attempt: 1, delayMs: TEXT_FIELD_COPIED_MS },
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
const again = transitionTextFieldCopy(copied.state, request)
|
|
48
|
+
|
|
49
|
+
expect(again.effects[0]).toEqual({ type: "timer.clear" })
|
|
50
|
+
expect(selectTextFieldCopied(again.state)).toBe(true)
|
|
51
|
+
// The first copy's reset timer fires late: the checkmark stays.
|
|
52
|
+
expect(run(again.state, { type: "reset.elapsed", attempt: 1 }).state).toBe(again.state)
|
|
53
|
+
|
|
54
|
+
const second = run(again.state, { type: "copy.succeeded", attempt: 2 })
|
|
55
|
+
|
|
56
|
+
expect(second.effects).toContainEqual({ type: "reset.schedule", attempt: 2, delayMs: TEXT_FIELD_COPIED_MS })
|
|
57
|
+
expect(run(second.state, { type: "reset.elapsed", attempt: 2 }).state).toEqual({ status: "idle", issued: 2 })
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test.each(["copy.failed", "copy.timed-out"] as const)("%s returns to idle and ignores the late result", (type) => {
|
|
61
|
+
const failed = run(INITIAL_TEXT_FIELD_COPY_STATE, request, { type, attempt: 1 })
|
|
62
|
+
|
|
63
|
+
expect(failed.state).toEqual({ status: "idle", issued: 1 })
|
|
64
|
+
expect(failed.effects).toEqual([{ type: "timer.clear" }])
|
|
65
|
+
expect(run(failed.state, { type: "copy.succeeded", attempt: 1 }).state).toBe(failed.state)
|
|
66
|
+
|
|
67
|
+
const repeat = run(INITIAL_TEXT_FIELD_COPY_STATE, request, { type: "copy.succeeded", attempt: 1 }, request, {
|
|
68
|
+
type,
|
|
69
|
+
attempt: 2,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
expect(selectTextFieldCopied(repeat.state)).toBe(false)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test("a disabled field does not copy", () => {
|
|
76
|
+
const result = transitionTextFieldCopy(INITIAL_TEXT_FIELD_COPY_STATE, { ...request, enabled: false })
|
|
77
|
+
|
|
78
|
+
expect(result.state).toBe(INITIAL_TEXT_FIELD_COPY_STATE)
|
|
79
|
+
expect(result.effects).toEqual([])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test("disposing clears the timer and ignores later results", () => {
|
|
83
|
+
const copying = run(INITIAL_TEXT_FIELD_COPY_STATE, request, { type: "disposed" })
|
|
84
|
+
|
|
85
|
+
expect(copying.state).toEqual({ status: "disposed" })
|
|
86
|
+
expect(copying.effects).toEqual([{ type: "timer.clear" }])
|
|
87
|
+
expect(run(copying.state, { type: "copy.succeeded", attempt: 1 }, request).state).toBe(copying.state)
|
|
88
|
+
expect(run(INITIAL_TEXT_FIELD_COPY_STATE, { type: "disposed" }).effects).toEqual([])
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test("labels and icons follow the copied state", () => {
|
|
92
|
+
const copied = run(INITIAL_TEXT_FIELD_COPY_STATE, request, { type: "copy.succeeded", attempt: 1 }).state
|
|
93
|
+
|
|
94
|
+
expect(selectTextFieldCopyLabelKey(copied, "link")).toBe("ui.textField.copied")
|
|
95
|
+
expect(selectTextFieldCopyIcon(copied, "link")).toBe("check")
|
|
96
|
+
expect(selectTextFieldCopyLabelKey(INITIAL_TEXT_FIELD_COPY_STATE, "link")).toBe("ui.textField.copyLink")
|
|
97
|
+
expect(selectTextFieldCopyIcon(INITIAL_TEXT_FIELD_COPY_STATE, undefined)).toBe("copy")
|
|
98
|
+
})
|
|
99
|
+
})
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createEffect, createSignal } from "solid-js"
|
|
2
|
+
import { TextField, type TextFieldProps } from "./text-field"
|
|
3
|
+
|
|
4
|
+
const docs = `### Overview
|
|
5
|
+
Text input with label, description, and optional copy-to-clipboard action.
|
|
6
|
+
|
|
7
|
+
Pair with \`Tooltip\` and \`IconButton\` for copy affordance (built in).
|
|
8
|
+
|
|
9
|
+
### API
|
|
10
|
+
- Supports Kobalte TextField props: \`value\`, \`defaultValue\`, \`onChange\`, \`disabled\`, \`readOnly\`.
|
|
11
|
+
- Optional: \`label\`, \`description\`, \`error\`, \`variant\`, \`copyable\`, \`multiline\`.
|
|
12
|
+
|
|
13
|
+
### Variants and states
|
|
14
|
+
- Normal and ghost variants.
|
|
15
|
+
- Supports multiline textarea.
|
|
16
|
+
|
|
17
|
+
### Behavior
|
|
18
|
+
- When \`copyable\` is true, clicking copies the current value.
|
|
19
|
+
|
|
20
|
+
### Accessibility
|
|
21
|
+
- Label is hidden when \`hideLabel\` is true (sr-only).
|
|
22
|
+
|
|
23
|
+
### Theming/tokens
|
|
24
|
+
- Uses \`data-component="input"\` with slot attributes for styling.
|
|
25
|
+
|
|
26
|
+
`
|
|
27
|
+
|
|
28
|
+
function Sample(props: TextFieldProps) {
|
|
29
|
+
const [value, setValue] = createSignal("")
|
|
30
|
+
|
|
31
|
+
createEffect(() => setValue(props.defaultValue ?? ""))
|
|
32
|
+
|
|
33
|
+
return <TextField {...props} value={value()} onChange={setValue} />
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default {
|
|
37
|
+
title: "UI/TextField",
|
|
38
|
+
id: "components-text-field",
|
|
39
|
+
component: TextField,
|
|
40
|
+
render: Sample,
|
|
41
|
+
args: {
|
|
42
|
+
label: "Label",
|
|
43
|
+
description: "",
|
|
44
|
+
error: "",
|
|
45
|
+
placeholder: "",
|
|
46
|
+
defaultValue: "",
|
|
47
|
+
variant: "normal",
|
|
48
|
+
hideLabel: false,
|
|
49
|
+
multiline: false,
|
|
50
|
+
copyable: false,
|
|
51
|
+
copyKind: "clipboard",
|
|
52
|
+
validationState: "valid",
|
|
53
|
+
required: false,
|
|
54
|
+
disabled: false,
|
|
55
|
+
readOnly: false,
|
|
56
|
+
} satisfies TextFieldProps,
|
|
57
|
+
argTypes: {
|
|
58
|
+
variant: { options: ["normal", "ghost"] },
|
|
59
|
+
copyKind: { options: ["clipboard", "link"] },
|
|
60
|
+
validationState: { options: ["valid", "invalid"] },
|
|
61
|
+
},
|
|
62
|
+
tags: ["autodocs"],
|
|
63
|
+
parameters: {
|
|
64
|
+
docs: {
|
|
65
|
+
description: {
|
|
66
|
+
component: docs,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const Basic = { args: { placeholder: "Type here...", defaultValue: "Hello" } }
|
|
73
|
+
|
|
74
|
+
export const Variants = {
|
|
75
|
+
args: { label: "Normal", placeholder: "Type here...", defaultValue: "Value" },
|
|
76
|
+
render: (args: TextFieldProps) => (
|
|
77
|
+
<div style={{ display: "grid", gap: "12px", width: "320px" }}>
|
|
78
|
+
<Sample {...args} />
|
|
79
|
+
<TextField label="Ghost" variant="ghost" placeholder="Type here..." defaultValue="Value" />
|
|
80
|
+
</div>
|
|
81
|
+
),
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const Multiline = {
|
|
85
|
+
args: {
|
|
86
|
+
label: "Description",
|
|
87
|
+
multiline: true,
|
|
88
|
+
defaultValue: "Line one\nLine two",
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const Copyable = {
|
|
93
|
+
args: {
|
|
94
|
+
label: "Invite link",
|
|
95
|
+
defaultValue: "https://example.com/invite/abc",
|
|
96
|
+
copyable: true,
|
|
97
|
+
copyKind: "link",
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const Error = {
|
|
102
|
+
args: {
|
|
103
|
+
label: "Email",
|
|
104
|
+
defaultValue: "invalid@",
|
|
105
|
+
error: "Enter a valid email address",
|
|
106
|
+
validationState: "invalid",
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const Disabled = {
|
|
111
|
+
args: {
|
|
112
|
+
label: "Disabled",
|
|
113
|
+
defaultValue: "Readonly",
|
|
114
|
+
disabled: true,
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const ReadOnly = {
|
|
119
|
+
args: {
|
|
120
|
+
label: "Read only",
|
|
121
|
+
defaultValue: "Read only value",
|
|
122
|
+
readOnly: true,
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const HiddenLabel = {
|
|
127
|
+
args: {
|
|
128
|
+
label: "Hidden label",
|
|
129
|
+
hideLabel: true,
|
|
130
|
+
placeholder: "Hidden label",
|
|
131
|
+
},
|
|
132
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import {
|
|
3
|
+
createTextRevealState,
|
|
4
|
+
selectTextRevealEntering,
|
|
5
|
+
selectTextRevealLeaving,
|
|
6
|
+
selectTextRevealReady,
|
|
7
|
+
selectTextRevealSwapping,
|
|
8
|
+
selectTextRevealTrackWidth,
|
|
9
|
+
transitionTextReveal,
|
|
10
|
+
type TextRevealEvent,
|
|
11
|
+
type TextRevealState,
|
|
12
|
+
type TextRevealTransition,
|
|
13
|
+
} from "./text-reveal-machine"
|
|
14
|
+
|
|
15
|
+
function run(state: TextRevealState, ...events: TextRevealEvent[]) {
|
|
16
|
+
return events.reduce<TextRevealTransition>((result, event) => transitionTextReveal(result.state, event), {
|
|
17
|
+
state,
|
|
18
|
+
effects: [],
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const measured = (widthPx: number, growOnly = true) => ({ widthPx, growOnly })
|
|
23
|
+
|
|
24
|
+
const settled = (text: string) =>
|
|
25
|
+
run(
|
|
26
|
+
createTextRevealState(text),
|
|
27
|
+
{ type: "fonts.settled", ...measured(40) },
|
|
28
|
+
{ type: "ready.settled", ...measured(40) },
|
|
29
|
+
).state
|
|
30
|
+
|
|
31
|
+
describe("transitionTextReveal", () => {
|
|
32
|
+
test("mounting with text does not swap", () => {
|
|
33
|
+
const state = createTextRevealState("Thinking")
|
|
34
|
+
const result = transitionTextReveal(state, { type: "text.changed", text: "Thinking" })
|
|
35
|
+
|
|
36
|
+
expect(result.state).toBe(state)
|
|
37
|
+
expect(result.effects).toEqual([])
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test("waits for fonts and one frame before turning transitions on", () => {
|
|
41
|
+
const fonts = run(createTextRevealState("Thinking"), { type: "fonts.settled", ...measured(40) })
|
|
42
|
+
|
|
43
|
+
expect(selectTextRevealReady(fonts.state)).toBe(false)
|
|
44
|
+
expect(fonts.effects).toEqual([{ type: "ready.frame" }])
|
|
45
|
+
|
|
46
|
+
const ready = transitionTextReveal(fonts.state, { type: "ready.settled", ...measured(42) })
|
|
47
|
+
|
|
48
|
+
expect(ready.state).toMatchObject({ status: "idle", current: "Thinking", widthPx: 42 })
|
|
49
|
+
expect(selectTextRevealReady(ready.state)).toBe(true)
|
|
50
|
+
expect(ready.effects).toEqual([{ type: "cancel.frame" }, { type: "cancel.ready-timer" }])
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test("a change before the first paint replaces the text without a swap", () => {
|
|
54
|
+
const result = transitionTextReveal(createTextRevealState("A"), { type: "text.changed", text: "B" })
|
|
55
|
+
|
|
56
|
+
expect(result.state).toMatchObject({ status: "measuring", current: "B" })
|
|
57
|
+
expect(selectTextRevealSwapping(result.state)).toBe(false)
|
|
58
|
+
expect(selectTextRevealLeaving(result.state)).toBe("\u00A0")
|
|
59
|
+
expect(result.effects).toEqual([{ type: "measure.entering" }])
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test("fonts that never settle time out into ready and ignore the late results", () => {
|
|
63
|
+
const timedOut = run(createTextRevealState("A"), { type: "ready.timed-out", ...measured(30) })
|
|
64
|
+
|
|
65
|
+
expect(timedOut.state).toMatchObject({ status: "idle", widthPx: 30 })
|
|
66
|
+
expect(run(timedOut.state, { type: "ready.settled", ...measured(50) }).state).toBe(timedOut.state)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test("fonts that settle after the timeout re-measure the width without a frame", () => {
|
|
70
|
+
const timedOut = run(createTextRevealState("A"), { type: "ready.timed-out", ...measured(30) }).state
|
|
71
|
+
const late = transitionTextReveal(timedOut, { type: "fonts.settled", ...measured(50) })
|
|
72
|
+
|
|
73
|
+
expect(late.state).toMatchObject({ status: "idle", widthPx: 50 })
|
|
74
|
+
expect(late.effects).toEqual([])
|
|
75
|
+
expect(transitionTextReveal(late.state, { type: "fonts.settled", ...measured(50) }).state).toBe(late.state)
|
|
76
|
+
|
|
77
|
+
const swapping = transitionTextReveal(timedOut, { type: "text.changed", text: "B" }).state
|
|
78
|
+
|
|
79
|
+
expect(transitionTextReveal(swapping, { type: "fonts.settled", ...measured(60) }).state).toMatchObject({
|
|
80
|
+
status: "swapping",
|
|
81
|
+
widthPx: 60,
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test("swaps a replaced text and wipes it out after one frame", () => {
|
|
86
|
+
const swap = transitionTextReveal(settled("Alpha"), { type: "text.changed", text: "Beta" })
|
|
87
|
+
|
|
88
|
+
expect(swap.state).toMatchObject({ status: "swapping", attempt: 1, current: "Beta", leaving: "Alpha" })
|
|
89
|
+
expect(swap.effects).toEqual([{ type: "swap.frame", attempt: 1 }])
|
|
90
|
+
|
|
91
|
+
const done = transitionTextReveal(swap.state, { type: "swap.settled", attempt: 1, ...measured(60) })
|
|
92
|
+
|
|
93
|
+
expect(done.state).toMatchObject({ status: "idle", current: "Beta", leaving: "Alpha", widthPx: 60 })
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test("two changes in one frame wipe out the text that was on screen", () => {
|
|
97
|
+
const result = run(
|
|
98
|
+
settled("Alpha"),
|
|
99
|
+
{ type: "text.changed", text: "Beta" },
|
|
100
|
+
{ type: "text.changed", text: "Gamma" },
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
expect(result.state).toMatchObject({ status: "swapping", attempt: 2, current: "Gamma", leaving: "Alpha" })
|
|
104
|
+
expect(result.effects).toEqual([{ type: "cancel.frame" }, { type: "swap.frame", attempt: 2 }])
|
|
105
|
+
expect(run(result.state, { type: "swap.settled", attempt: 1, ...measured(80) }).state).toBe(result.state)
|
|
106
|
+
expect(selectTextRevealLeaving(result.state)).toBe("Alpha")
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test("changing back within one frame cancels the swap", () => {
|
|
110
|
+
const result = run(
|
|
111
|
+
settled("Alpha"),
|
|
112
|
+
{ type: "text.changed", text: "Beta" },
|
|
113
|
+
{ type: "text.changed", text: "Alpha" },
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
expect(result.state).toMatchObject({ status: "idle", current: "Alpha", leaving: undefined })
|
|
117
|
+
expect(result.effects).toEqual([{ type: "cancel.frame" }, { type: "measure.entering" }])
|
|
118
|
+
|
|
119
|
+
const next = transitionTextReveal(result.state, { type: "text.changed", text: "Gamma" })
|
|
120
|
+
|
|
121
|
+
expect(next.state).toMatchObject({ status: "swapping", attempt: 2, leaving: "Alpha" })
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test("extending the text grows it in place", () => {
|
|
125
|
+
const result = transitionTextReveal(settled("Plan"), { type: "text.changed", text: "Planning" })
|
|
126
|
+
|
|
127
|
+
expect(result.state).toMatchObject({ status: "idle", current: "Planning" })
|
|
128
|
+
expect(result.effects).toEqual([{ type: "measure.entering" }])
|
|
129
|
+
expect(selectTextRevealEntering(result.state)).toBe("Planning")
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test("grows only when asked, and ignores empty measurements", () => {
|
|
133
|
+
const state = settled("Alpha")
|
|
134
|
+
|
|
135
|
+
expect(transitionTextReveal(state, { type: "width.measured", ...measured(20) }).state).toBe(state)
|
|
136
|
+
expect(transitionTextReveal(state, { type: "width.measured", ...measured(0, false) }).state).toBe(state)
|
|
137
|
+
expect(transitionTextReveal(state, { type: "width.measured", ...measured(20, false) }).state).toMatchObject({
|
|
138
|
+
widthPx: 20,
|
|
139
|
+
})
|
|
140
|
+
expect(selectTextRevealTrackWidth(state, false)).toBe("40px")
|
|
141
|
+
expect(selectTextRevealTrackWidth(state, true)).toBe("100%")
|
|
142
|
+
expect(selectTextRevealTrackWidth(createTextRevealState("A"), false)).toBe("auto")
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
test("disposing cancels pending work and ignores late results", () => {
|
|
146
|
+
const measuring = transitionTextReveal(createTextRevealState("A"), { type: "disposed" })
|
|
147
|
+
|
|
148
|
+
expect(measuring.effects).toEqual([{ type: "cancel.frame" }, { type: "cancel.ready-timer" }])
|
|
149
|
+
expect(run(measuring.state, { type: "ready.timed-out", ...measured(10) }).state).toBe(measuring.state)
|
|
150
|
+
|
|
151
|
+
const swapping = run(settled("Alpha"), { type: "text.changed", text: "Beta" }, { type: "disposed" })
|
|
152
|
+
|
|
153
|
+
expect(swapping.state).toEqual({ status: "disposed" })
|
|
154
|
+
expect(swapping.effects).toEqual([{ type: "cancel.frame" }])
|
|
155
|
+
expect(run(swapping.state, { type: "swap.settled", attempt: 1, ...measured(10) }).state).toBe(swapping.state)
|
|
156
|
+
})
|
|
157
|
+
})
|