@zyro-sec/ui 1.0.1 → 1.0.3
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 -29
- package/LICENSE +21 -21
- package/bunfig.toml +2 -2
- package/package.json +76 -2
- package/perf/motion.bench.ts +14 -14
- package/perf/motion.ts +16 -16
- package/script/build-oc2-v2-overrides.ts +38 -38
- package/script/colors.txt +288 -288
- package/script/generate-spinner.ts +121 -121
- package/script/pack.ts +5 -5
- package/script/tailwind.ts +24 -24
- package/src/actions/button/button.css +346 -346
- package/src/actions/button/button.stories.tsx +158 -158
- package/src/actions/button/button.tsx +56 -56
- package/src/actions/icon-button/icon-button.css +128 -128
- package/src/actions/icon-button/icon-button.stories.tsx +122 -122
- package/src/actions/icon-button/icon-button.tsx +46 -46
- package/src/actions/split-button/split-button.css +99 -99
- package/src/actions/split-button/split-button.stories.tsx +59 -59
- package/src/actions/split-button/split-button.tsx +51 -51
- package/src/actions/submit.css +81 -81
- package/src/assets/favicon/favicon-v3.svg +6 -6
- package/src/assets/favicon/favicon.svg +6 -6
- package/src/assets/favicon/site.webmanifest +24 -24
- package/src/assets/icons/app/android-studio.svg +369 -369
- package/src/assets/icons/app/antigravity.svg +97 -97
- package/src/assets/icons/app/cursor.svg +16 -16
- package/src/assets/icons/app/file-explorer.svg +20 -20
- package/src/assets/icons/app/ghostty.svg +13 -13
- package/src/assets/icons/app/iterm2.svg +13 -13
- package/src/assets/icons/app/powershell.svg +14 -14
- package/src/assets/icons/app/sublimetext.svg +17 -17
- package/src/assets/icons/app/vscode.svg +39 -39
- package/src/assets/icons/app/windows-terminal.svg +6 -6
- package/src/assets/icons/app/zed-dark.svg +15 -15
- package/src/assets/icons/app/zed.svg +15 -15
- package/src/assets/icons/file-types/auto_light.svg +12 -12
- package/src/assets/icons/file-types/cursor.svg +1 -1
- package/src/assets/icons/file-types/cursor_light.svg +1 -1
- package/src/assets/icons/file-types/drone_light.svg +4 -4
- package/src/assets/icons/file-types/folder-admin-open.svg +6 -6
- package/src/assets/icons/file-types/folder-admin.svg +6 -6
- package/src/assets/icons/file-types/folder-circleci-open.svg +7 -7
- package/src/assets/icons/file-types/folder-circleci.svg +7 -7
- package/src/assets/icons/file-types/folder-flow-open.svg +6 -6
- package/src/assets/icons/file-types/folder-flow.svg +6 -6
- package/src/assets/icons/file-types/folder-gh-workflows-open.svg +6 -6
- package/src/assets/icons/file-types/folder-gh-workflows.svg +6 -6
- package/src/assets/icons/file-types/folder-github-open.svg +6 -6
- package/src/assets/icons/file-types/folder-github.svg +6 -6
- package/src/assets/icons/file-types/folder-intellij-open.svg +39 -39
- package/src/assets/icons/file-types/folder-intellij.svg +39 -39
- package/src/assets/icons/file-types/folder-macos-open.svg +6 -6
- package/src/assets/icons/file-types/folder-macos.svg +6 -6
- package/src/assets/icons/file-types/folder-next-open.svg +6 -6
- package/src/assets/icons/file-types/folder-next.svg +6 -6
- package/src/assets/icons/file-types/folder-nuxt-open.svg +6 -6
- package/src/assets/icons/file-types/folder-nuxt.svg +6 -6
- package/src/assets/icons/file-types/folder-open.svg +5 -5
- package/src/assets/icons/file-types/folder-scripts-open.svg +6 -6
- package/src/assets/icons/file-types/folder-scripts.svg +6 -6
- package/src/assets/icons/file-types/folder-target-open.svg +10 -10
- package/src/assets/icons/file-types/folder-target.svg +10 -10
- package/src/assets/icons/file-types/folder-turborepo-open.svg +15 -15
- package/src/assets/icons/file-types/folder-turborepo.svg +15 -15
- package/src/assets/icons/file-types/folder-vercel-open.svg +5 -5
- package/src/assets/icons/file-types/folder-vercel.svg +5 -5
- package/src/assets/icons/file-types/folder.svg +5 -5
- package/src/assets/icons/file-types/go_gopher.svg +35 -35
- package/src/assets/icons/file-types/nano-staged_light.svg +4 -4
- package/src/assets/icons/file-types/opa.svg +9 -9
- package/src/assets/icons/file-types/quarto.svg +5 -5
- package/src/assets/icons/file-types/rome.svg +6 -6
- package/src/assets/icons/file-types/stitches_light.svg +10 -10
- package/src/assets/icons/file-types/stylelint_light.svg +13 -13
- package/src/assets/icons/file-types/unocss.svg +5 -5
- package/src/assets/icons/file-types/vlang.svg +6 -6
- package/src/assets/icons/provider/302ai.svg +6 -6
- package/src/assets/icons/provider/abacus.svg +14 -14
- package/src/assets/icons/provider/aihubmix.svg +3 -3
- package/src/assets/icons/provider/alibaba-cn.svg +3 -3
- package/src/assets/icons/provider/alibaba-coding-plan-cn.svg +3 -3
- package/src/assets/icons/provider/alibaba-coding-plan.svg +3 -3
- package/src/assets/icons/provider/alibaba.svg +3 -3
- package/src/assets/icons/provider/amazon-bedrock.svg +3 -3
- package/src/assets/icons/provider/anthropic.svg +2 -2
- package/src/assets/icons/provider/azure-cognitive-services.svg +24 -24
- package/src/assets/icons/provider/azure.svg +3 -3
- package/src/assets/icons/provider/bailing.svg +3 -3
- package/src/assets/icons/provider/baseten.svg +3 -3
- package/src/assets/icons/provider/berget.svg +2 -2
- package/src/assets/icons/provider/cerebras.svg +4 -4
- package/src/assets/icons/provider/chutes.svg +24 -24
- package/src/assets/icons/provider/clarifai.svg +24 -24
- package/src/assets/icons/provider/claude-agent.svg +3 -3
- package/src/assets/icons/provider/cloudferro-sherlock.svg +4 -4
- package/src/assets/icons/provider/cloudflare-ai-gateway.svg +4 -4
- package/src/assets/icons/provider/cloudflare-workers-ai.svg +4 -4
- package/src/assets/icons/provider/cohere.svg +5 -5
- package/src/assets/icons/provider/cortecs.svg +24 -24
- package/src/assets/icons/provider/deepinfra.svg +4 -4
- package/src/assets/icons/provider/deepseek.svg +3 -3
- package/src/assets/icons/provider/digitalocean.svg +6 -6
- package/src/assets/icons/provider/dinference.svg +1 -1
- package/src/assets/icons/provider/drun.svg +8 -8
- package/src/assets/icons/provider/evroc.svg +2 -2
- package/src/assets/icons/provider/fastrouter.svg +3 -3
- package/src/assets/icons/provider/fireworks-ai.svg +3 -3
- package/src/assets/icons/provider/firmware.svg +18 -18
- package/src/assets/icons/provider/friendli.svg +3 -3
- package/src/assets/icons/provider/github-copilot.svg +3 -3
- package/src/assets/icons/provider/github-models.svg +3 -3
- package/src/assets/icons/provider/gitlab.svg +3 -3
- package/src/assets/icons/provider/google-vertex-anthropic.svg +24 -24
- package/src/assets/icons/provider/google-vertex.svg +10 -10
- package/src/assets/icons/provider/google.svg +3 -3
- package/src/assets/icons/provider/groq.svg +3 -3
- package/src/assets/icons/provider/helicone.svg +6 -6
- package/src/assets/icons/provider/huggingface.svg +3 -3
- package/src/assets/icons/provider/iflowcn.svg +3 -3
- package/src/assets/icons/provider/inception.svg +4 -4
- package/src/assets/icons/provider/inference.svg +3 -3
- package/src/assets/icons/provider/io-net.svg +5 -5
- package/src/assets/icons/provider/jiekou.svg +4 -4
- package/src/assets/icons/provider/kilo.svg +4 -4
- package/src/assets/icons/provider/kimi-for-coding.svg +3 -3
- package/src/assets/icons/provider/kuae-cloud-coding-plan.svg +3 -3
- package/src/assets/icons/provider/llama.svg +3 -3
- package/src/assets/icons/provider/lmstudio.svg +24 -24
- package/src/assets/icons/provider/lucidquery.svg +3 -3
- package/src/assets/icons/provider/meganova.svg +3 -3
- package/src/assets/icons/provider/meituan.svg +6 -6
- package/src/assets/icons/provider/meta.svg +3 -3
- package/src/assets/icons/provider/minimax-cn-coding-plan.svg +24 -24
- package/src/assets/icons/provider/minimax-cn.svg +3 -3
- package/src/assets/icons/provider/minimax-coding-plan.svg +24 -24
- package/src/assets/icons/provider/minimax.svg +3 -3
- package/src/assets/icons/provider/mistral.svg +3 -3
- package/src/assets/icons/provider/moark.svg +3 -3
- package/src/assets/icons/provider/modelscope.svg +5 -5
- package/src/assets/icons/provider/moonshotai-cn.svg +3 -3
- package/src/assets/icons/provider/moonshotai.svg +3 -3
- package/src/assets/icons/provider/morph.svg +24 -24
- package/src/assets/icons/provider/nano-gpt.svg +2 -2
- package/src/assets/icons/provider/nebius.svg +4 -4
- package/src/assets/icons/provider/nova.svg +3 -3
- package/src/assets/icons/provider/novita-ai.svg +10 -10
- package/src/assets/icons/provider/nvidia.svg +3 -3
- package/src/assets/icons/provider/ollama-cloud.svg +7 -7
- package/src/assets/icons/provider/openai.svg +3 -3
- package/src/assets/icons/provider/opencode-go.svg +3 -3
- package/src/assets/icons/provider/opencode.svg +3 -3
- package/src/assets/icons/provider/openrouter.svg +3 -3
- package/src/assets/icons/provider/ovhcloud.svg +3 -3
- package/src/assets/icons/provider/perplexity-agent.svg +3 -3
- package/src/assets/icons/provider/perplexity.svg +3 -3
- package/src/assets/icons/provider/poe.svg +7 -7
- package/src/assets/icons/provider/privatemode-ai.svg +4 -4
- package/src/assets/icons/provider/qihang-ai.svg +8 -8
- package/src/assets/icons/provider/qiniu-ai.svg +7 -7
- package/src/assets/icons/provider/reflection.svg +3 -3
- package/src/assets/icons/provider/requesty.svg +24 -24
- package/src/assets/icons/provider/sap-ai-core.svg +24 -24
- package/src/assets/icons/provider/scaleway.svg +5 -5
- package/src/assets/icons/provider/siliconflow-cn.svg +3 -3
- package/src/assets/icons/provider/siliconflow.svg +3 -3
- package/src/assets/icons/provider/stackit.svg +4 -4
- package/src/assets/icons/provider/stepfun.svg +16 -16
- package/src/assets/icons/provider/submodel.svg +3 -3
- package/src/assets/icons/provider/synthetic.svg +24 -24
- package/src/assets/icons/provider/tencent-coding-plan.svg +5 -5
- package/src/assets/icons/provider/tencent.svg +3 -3
- package/src/assets/icons/provider/thinkingmachines.svg +3 -3
- package/src/assets/icons/provider/togetherai.svg +4 -4
- package/src/assets/icons/provider/upstage.svg +24 -24
- package/src/assets/icons/provider/v0.svg +3 -3
- package/src/assets/icons/provider/venice.svg +4 -4
- package/src/assets/icons/provider/vercel.svg +3 -3
- package/src/assets/icons/provider/vivgrid.svg +4 -4
- package/src/assets/icons/provider/vultr.svg +6 -6
- package/src/assets/icons/provider/wandb.svg +24 -24
- package/src/assets/icons/provider/xai.svg +3 -3
- package/src/assets/icons/provider/xiaomi.svg +3 -3
- package/src/assets/icons/provider/zai-coding-plan.svg +3 -3
- package/src/assets/icons/provider/zai.svg +3 -3
- package/src/assets/icons/provider/zenmux.svg +4 -4
- package/src/assets/icons/provider/zhipuai-coding-plan.svg +3 -3
- package/src/assets/icons/provider/zhipuai.svg +3 -3
- package/src/components/animated-number-machine.ts +214 -214
- package/src/components/animated-number.css +110 -110
- package/src/components/animated-number.stories.tsx +35 -35
- package/src/components/animated-number.tsx +202 -202
- package/src/components/app-icon.css +5 -5
- package/src/components/app-icon.stories.tsx +73 -73
- package/src/components/app-icon.tsx +89 -89
- package/src/components/app-icons/sprite.svg +114 -114
- package/src/components/app-icons/types.ts +22 -22
- package/src/components/card.css +94 -94
- package/src/components/card.stories.tsx +101 -101
- package/src/components/card.tsx +145 -145
- package/src/components/collapsible.css +139 -139
- package/src/components/collapsible.stories.tsx +76 -76
- package/src/components/collapsible.tsx +62 -62
- package/src/components/context-menu.css +134 -134
- package/src/components/context-menu.stories.tsx +150 -150
- package/src/components/context-menu.tsx +342 -342
- package/src/components/diagram-preview.css +95 -95
- package/src/components/diagram-preview.stories.tsx +62 -62
- package/src/components/diagram-preview.tsx +332 -332
- package/src/components/dock-surface.css +30 -30
- package/src/components/dock-surface.stories.tsx +26 -26
- package/src/components/dock-surface.tsx +40 -40
- package/src/components/document-surface.css +37 -37
- package/src/components/document-surface.stories.tsx +42 -42
- package/src/components/document-surface.tsx +6 -6
- package/src/components/error-details.css +41 -41
- package/src/components/error-details.stories.tsx +72 -72
- package/src/components/error-details.tsx +13 -13
- package/src/components/favicon.stories.tsx +49 -49
- package/src/components/favicon.tsx +13 -13
- package/src/components/file-icon-machine.ts +78 -78
- package/src/components/file-icon.css +6 -6
- package/src/components/file-icon.stories.tsx +93 -93
- package/src/components/file-icon.tsx +186 -186
- package/src/components/file-icons/choose-icon-name.ts +574 -574
- package/src/components/file-icons/sprite.svg +11707 -11707
- package/src/components/file-icons/types.ts +1095 -1095
- package/src/components/font.stories.tsx +48 -48
- package/src/components/font.tsx +1 -1
- package/src/components/hover-card.css +61 -61
- package/src/components/hover-card.stories.tsx +79 -79
- package/src/components/hover-card.tsx +32 -32
- package/src/components/image-flight-machine.ts +247 -247
- package/src/components/image-flight.ts +161 -161
- package/src/components/image-preview.css +202 -202
- package/src/components/image-preview.stories.tsx +392 -392
- package/src/components/image-preview.tsx +908 -908
- package/src/components/image-zoom-machine.ts +191 -191
- package/src/components/image-zoom.ts +124 -124
- package/src/components/list.css +331 -331
- package/src/components/list.stories.tsx +221 -221
- package/src/components/list.tsx +322 -322
- package/src/components/logo.css +4 -4
- package/src/components/logo.stories.tsx +62 -62
- package/src/components/logo.tsx +62 -62
- package/src/components/menu-scroll.css +70 -70
- package/src/components/menu-scroll.stories.tsx +73 -73
- package/src/components/menu-scroll.tsx +202 -202
- package/src/components/motion-spring.tsx +65 -65
- package/src/components/popover-machine.ts +198 -198
- package/src/components/popover.css +66 -66
- package/src/components/popover.stories.tsx +84 -84
- package/src/components/popover.tsx +234 -234
- package/src/components/preview-controls.css +28 -28
- package/src/components/preview-controls.stories.tsx +40 -40
- package/src/components/preview-controls.tsx +53 -53
- package/src/components/progress.css +63 -63
- package/src/components/progress.stories.tsx +69 -69
- package/src/components/progress.tsx +39 -39
- package/src/components/provider-icon.css +5 -5
- package/src/components/provider-icon.stories.tsx +75 -75
- package/src/components/provider-icon.tsx +31 -31
- package/src/components/provider-icons/sprite.svg +1131 -1131
- package/src/components/provider-icons/types.ts +111 -111
- package/src/components/resize-handle-machine.ts +174 -174
- package/src/components/resize-handle.css +81 -81
- package/src/components/resize-handle.stories.tsx +81 -81
- package/src/components/resize-handle.tsx +164 -164
- package/src/components/rolling-number.css +24 -24
- package/src/components/rolling-number.stories.tsx +23 -23
- package/src/components/rolling-number.tsx +135 -135
- package/src/components/scroll-view-machine.ts +244 -244
- package/src/components/scroll-view.css +99 -99
- package/src/components/scroll-view.stories.tsx +68 -68
- package/src/components/scroll-view.tsx +653 -653
- package/src/components/spinner-frames.css +6 -6
- package/src/components/spinner-radar.ts +150 -150
- package/src/components/spinner.css +38 -38
- package/src/components/spinner.stories.tsx +40 -40
- package/src/components/spinner.tsx +43 -43
- package/src/components/sticky-accordion-header.css +11 -11
- package/src/components/sticky-accordion-header.stories.tsx +64 -64
- package/src/components/sticky-accordion-header.tsx +18 -18
- package/src/components/text-field-machine.ts +102 -102
- package/src/components/text-field.css +134 -134
- package/src/components/text-field.stories.tsx +132 -132
- package/src/components/text-field.tsx +196 -196
- package/src/components/text-reveal-machine.ts +184 -184
- package/src/components/text-reveal.css +150 -150
- package/src/components/text-reveal.stories.tsx +363 -363
- package/src/components/text-reveal.tsx +165 -165
- package/src/components/text-strikethrough.css +27 -27
- package/src/components/text-strikethrough.stories.tsx +296 -296
- package/src/components/text-strikethrough.tsx +92 -92
- package/src/components/thinking-heading.stories.tsx +900 -900
- package/src/components/truncated-text.css +25 -25
- package/src/components/truncated-text.stories.tsx +37 -37
- package/src/components/truncated-text.tsx +30 -30
- package/src/components/typewriter-machine.ts +134 -134
- package/src/components/typewriter.css +14 -14
- package/src/components/typewriter.stories.tsx +51 -51
- package/src/components/typewriter.tsx +70 -70
- package/src/context/dialog-machine.ts +281 -281
- package/src/context/dialog.tsx +376 -376
- package/src/context/file.tsx +11 -11
- package/src/context/focus-rescue.tsx +230 -230
- package/src/context/helper.tsx +43 -43
- package/src/context/highlight-theme.tsx +66 -66
- package/src/context/i18n.tsx +144 -144
- package/src/context/index.ts +7 -7
- package/src/context/marked-base.tsx +67 -67
- package/src/context/marked-parser.tsx +154 -154
- package/src/context/overlay-focus.tsx +90 -90
- package/src/custom-elements.d.ts +17 -17
- package/src/data-display/accordion/accordion.css +130 -130
- package/src/data-display/accordion/accordion.stories.tsx +76 -76
- package/src/data-display/accordion/accordion.tsx +106 -106
- package/src/data-display/avatar/avatar.css +70 -70
- package/src/data-display/avatar/avatar.stories.tsx +48 -48
- package/src/data-display/avatar/avatar.tsx +63 -63
- package/src/data-display/badge/badge.css +63 -63
- package/src/data-display/badge/badge.stories.tsx +75 -75
- package/src/data-display/badge/badge.tsx +26 -26
- package/src/data-display/diff-changes/diff-changes.css +47 -47
- package/src/data-display/diff-changes/diff-changes.stories.tsx +63 -63
- package/src/data-display/diff-changes/diff-changes.tsx +43 -43
- package/src/data-display/keybind/keybind.css +84 -84
- package/src/data-display/keybind/keybind.stories.tsx +77 -77
- package/src/data-display/keybind/keybind.tsx +31 -31
- package/src/data-display/line-comment/line-comment.css +341 -341
- package/src/data-display/line-comment/line-comment.stories.tsx +288 -288
- package/src/data-display/line-comment/line-comment.tsx +554 -554
- package/src/data-display/line-comment/machine.ts +400 -400
- package/src/data-display/line-comment/quote-check.svg +3 -3
- package/src/data-display/project-avatar/animation-machine.ts +182 -182
- package/src/data-display/project-avatar/animation.ts +133 -133
- package/src/data-display/project-avatar/generated.ts +225 -225
- package/src/data-display/project-avatar/procedural-craft.ts +1079 -1079
- package/src/data-display/project-avatar/procedural-kit.ts +244 -244
- package/src/data-display/project-avatar/procedural-machine.ts +924 -924
- package/src/data-display/project-avatar/procedural-world.ts +1542 -1542
- package/src/data-display/project-avatar/procedural.ts +1563 -1563
- package/src/data-display/project-avatar/project-avatar.css +189 -189
- package/src/data-display/project-avatar/project-avatar.stories.tsx +102 -102
- package/src/data-display/project-avatar/project-avatar.tsx +246 -246
- package/src/data-display/project-avatar/project-icon-styles.stories.tsx +772 -772
- package/src/feedback/activity-ring/activity-ring.css +5 -5
- package/src/feedback/activity-ring/activity-ring.stories.tsx +20 -20
- package/src/feedback/activity-ring/activity-ring.tsx +15 -15
- package/src/feedback/loader/loader.css +32 -32
- package/src/feedback/loader/loader.stories.tsx +44 -44
- package/src/feedback/loader/loader.tsx +34 -34
- package/src/feedback/progress-circle/progress-circle.css +28 -28
- package/src/feedback/progress-circle/progress-circle.stories.tsx +56 -56
- package/src/feedback/progress-circle/progress-circle.tsx +64 -64
- package/src/feedback/toast/description.ts +10 -10
- package/src/feedback/toast/machine.ts +115 -115
- package/src/feedback/toast/toast.css +234 -234
- package/src/feedback/toast/toast.stories.tsx +186 -186
- package/src/feedback/toast/toast.tsx +317 -317
- package/src/forms/checkbox/checkbox-compact.css +170 -170
- package/src/forms/checkbox/checkbox.css +125 -125
- package/src/forms/checkbox/checkbox.stories.tsx +104 -104
- package/src/forms/checkbox/checkbox.tsx +119 -119
- package/src/forms/field/field.css +94 -94
- package/src/forms/field/field.stories.tsx +129 -129
- package/src/forms/field/field.tsx +271 -271
- package/src/forms/inline-input/inline-input.css +16 -16
- package/src/forms/inline-input/inline-input.stories.tsx +37 -37
- package/src/forms/inline-input/inline-input.tsx +26 -26
- package/src/forms/radio/radio.css +218 -218
- package/src/forms/radio/radio.stories.tsx +145 -145
- package/src/forms/radio/radio.tsx +95 -95
- package/src/forms/redirect-paste/redirect-paste.stories.tsx +101 -101
- package/src/forms/redirect-paste/redirect-paste.tsx +92 -92
- package/src/forms/search-list/navigation.ts +54 -54
- package/src/forms/search-list/search-list.css +249 -249
- package/src/forms/search-list/search-list.stories.tsx +108 -108
- package/src/forms/search-list/search-list.tsx +463 -463
- package/src/forms/select/machine.ts +81 -81
- package/src/forms/select/select.css +312 -312
- package/src/forms/select/select.stories.tsx +208 -208
- package/src/forms/select/select.tsx +281 -281
- package/src/forms/switch/switch.css +281 -281
- package/src/forms/switch/switch.stories.tsx +97 -97
- package/src/forms/switch/switch.tsx +35 -35
- package/src/forms/text-input/text-input.css +229 -229
- package/src/forms/text-input/text-input.stories.tsx +220 -220
- package/src/forms/text-input/text-input.tsx +115 -115
- package/src/forms/textarea/textarea.css +103 -103
- package/src/forms/textarea/textarea.stories.tsx +137 -137
- package/src/forms/textarea/textarea.tsx +33 -33
- package/src/forms/typeahead/controller.ts +59 -59
- package/src/forms/typeahead/machine.ts +253 -253
- package/src/forms/typeahead/typeahead.stories.tsx +113 -113
- package/src/forms/typeahead/typeahead.tsx +239 -239
- package/src/hooks/auto-scroll-machine.ts +261 -261
- package/src/hooks/create-auto-scroll.tsx +196 -196
- package/src/hooks/index.ts +5 -5
- package/src/hooks/list-machine.ts +359 -359
- package/src/hooks/spin-phase.ts +116 -116
- package/src/hooks/use-filtered-list.tsx +132 -132
- package/src/i18n/am.ts +384 -384
- package/src/i18n/ar.ts +547 -547
- package/src/i18n/az.ts +386 -386
- package/src/i18n/bg.ts +386 -386
- package/src/i18n/bn.ts +393 -393
- package/src/i18n/br.ts +444 -444
- package/src/i18n/bs.ts +445 -445
- package/src/i18n/ca.ts +423 -423
- package/src/i18n/cs.ts +457 -457
- package/src/i18n/da.ts +407 -407
- package/src/i18n/de.ts +414 -414
- package/src/i18n/dv.ts +395 -395
- package/src/i18n/dz.ts +393 -393
- package/src/i18n/el.ts +388 -388
- package/src/i18n/en.ts +433 -433
- package/src/i18n/es.ts +443 -443
- package/src/i18n/et.ts +386 -386
- package/src/i18n/fa.ts +388 -388
- package/src/i18n/fi.ts +388 -388
- package/src/i18n/fo.ts +388 -388
- package/src/i18n/fr.ts +447 -447
- package/src/i18n/he.ts +422 -422
- package/src/i18n/hi.ts +392 -392
- package/src/i18n/hr.ts +422 -422
- package/src/i18n/hu.ts +388 -388
- package/src/i18n/hy.ts +389 -389
- package/src/i18n/id.ts +411 -411
- package/src/i18n/is.ts +388 -388
- package/src/i18n/it.ts +425 -425
- package/src/i18n/ja.ts +406 -406
- package/src/i18n/ka.ts +388 -388
- package/src/i18n/km.ts +389 -389
- package/src/i18n/ko.ts +408 -408
- package/src/i18n/lo.ts +387 -387
- package/src/i18n/lt.ts +457 -457
- package/src/i18n/lv.ts +421 -421
- package/src/i18n/mk.ts +387 -387
- package/src/i18n/mn.ts +386 -386
- package/src/i18n/ms.ts +389 -389
- package/src/i18n/my.ts +389 -389
- package/src/i18n/ne.ts +393 -393
- package/src/i18n/nl.ts +388 -388
- package/src/i18n/no.ts +413 -413
- package/src/i18n/pa.ts +394 -394
- package/src/i18n/pl.ts +476 -476
- package/src/i18n/ro.ts +423 -423
- package/src/i18n/ru.ts +475 -475
- package/src/i18n/si.ts +390 -390
- package/src/i18n/sk.ts +457 -457
- package/src/i18n/sl.ts +457 -457
- package/src/i18n/sq.ts +387 -387
- package/src/i18n/sr.ts +422 -422
- package/src/i18n/sv.ts +388 -388
- package/src/i18n/tg.ts +390 -390
- package/src/i18n/th.ts +407 -407
- package/src/i18n/tk.ts +386 -386
- package/src/i18n/tr.ts +412 -412
- package/src/i18n/uk.ts +480 -480
- package/src/i18n/ur.ts +394 -394
- package/src/i18n/uz.ts +390 -390
- package/src/i18n/vi.ts +387 -387
- package/src/i18n/zh.ts +408 -408
- package/src/i18n/zht.ts +408 -408
- package/src/icons/catalog.ts +638 -638
- package/src/icons/icon/icon.css +3 -3
- package/src/icons/icon/icon.stories.tsx +131 -131
- package/src/icons/icon/icon.tsx +106 -106
- package/src/icons/registry.ts +217 -217
- package/src/layout/divider/divider.css +11 -11
- package/src/layout/divider/divider.stories.tsx +38 -38
- package/src/layout/divider/divider.tsx +21 -21
- package/src/motion/README.md +113 -113
- package/src/motion/index.ts +13 -13
- package/src/motion/loop.ts +139 -139
- package/src/motion/reduced.ts +66 -66
- package/src/motion/slider.ts +45 -45
- package/src/motion/solid.ts +309 -309
- package/src/motion/spring.ts +125 -125
- package/src/motion/velocity.ts +46 -46
- package/src/motion/waapi.ts +89 -89
- package/src/motion-tuning-features.ts +161 -161
- package/src/motion-tuning-fields.ts +42 -42
- package/src/motion-tuning.ts +323 -323
- package/src/navigation/menu/machine.ts +109 -109
- package/src/navigation/menu/menu.css +313 -313
- package/src/navigation/menu/menu.stories.tsx +328 -328
- package/src/navigation/menu/menu.tsx +600 -600
- package/src/navigation/menu/submenu-machine.ts +67 -67
- package/src/navigation/segmented-control/machine.ts +72 -72
- package/src/navigation/segmented-control/segmented-control.css +113 -113
- package/src/navigation/segmented-control/segmented-control.stories.tsx +115 -115
- package/src/navigation/segmented-control/segmented-control.tsx +396 -396
- package/src/navigation/tab-state-indicator.stories.tsx +24 -24
- package/src/navigation/tab-state-indicator.tsx +38 -38
- package/src/navigation/tabs/tabs-current.css +244 -244
- package/src/navigation/tabs/tabs.css +676 -676
- package/src/navigation/tabs/tabs.stories.tsx +193 -193
- package/src/navigation/tabs/tabs.tsx +212 -212
- package/src/overlays/dialog/dialog.css +194 -194
- package/src/overlays/dialog/dialog.stories.tsx +365 -365
- package/src/overlays/dialog/dialog.tsx +192 -192
- package/src/overlays/mcp-sign-in/machine.ts +343 -343
- package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -159
- package/src/overlays/tooltip/machine.ts +312 -312
- package/src/overlays/tooltip/tooltip.css +102 -102
- package/src/overlays/tooltip/tooltip.stories.tsx +155 -155
- package/src/overlays/tooltip/tooltip.tsx +290 -290
- package/src/storybook/fixtures.ts +51 -51
- package/src/storybook/scaffold.tsx +65 -65
- package/src/styles/animations.css +13 -13
- package/src/styles/base.css +441 -441
- package/src/styles/blue-tokens.stories.tsx +215 -215
- package/src/styles/colors.css +772 -772
- package/src/styles/file-tree.css +285 -285
- package/src/styles/index.css +42 -42
- package/src/styles/scrollbar.css +79 -79
- package/src/styles/tailwind/colors.css +288 -288
- package/src/styles/tailwind/index.css +113 -113
- package/src/styles/tailwind/utilities.css +17 -17
- package/src/styles/theme.css +640 -640
- package/src/styles/tokens/colors.css +172 -172
- package/src/styles/tokens/index.css +2 -2
- package/src/styles/tokens/theme.css +522 -522
- package/src/styles/utilities.css +93 -93
- package/src/theme/color.ts +290 -290
- package/src/theme/context.tsx +361 -361
- package/src/theme/desktop-theme.schema.json +168 -168
- package/src/theme/index.ts +35 -35
- package/src/theme/machine.ts +508 -508
- package/src/theme/resolve.ts +561 -561
- package/src/theme/themes/amoled.json +49 -49
- package/src/theme/themes/aura.json +51 -51
- package/src/theme/themes/ayu.json +51 -51
- package/src/theme/themes/carbonfox.json +53 -53
- package/src/theme/themes/catppuccin-frappe.json +65 -65
- package/src/theme/themes/catppuccin-macchiato.json +65 -65
- package/src/theme/themes/catppuccin.json +45 -45
- package/src/theme/themes/cobalt2.json +87 -87
- package/src/theme/themes/cursor.json +91 -91
- package/src/theme/themes/dracula.json +49 -49
- package/src/theme/themes/everforest.json +89 -89
- package/src/theme/themes/flexoki.json +86 -86
- package/src/theme/themes/github.json +85 -85
- package/src/theme/themes/gruvbox.json +45 -45
- package/src/theme/themes/kanagawa.json +89 -89
- package/src/theme/themes/lucent-orng.json +87 -87
- package/src/theme/themes/material.json +87 -87
- package/src/theme/themes/matrix.json +113 -113
- package/src/theme/themes/mercury.json +86 -86
- package/src/theme/themes/monokai.json +49 -49
- package/src/theme/themes/nightowl.json +46 -46
- package/src/theme/themes/nord.json +46 -46
- package/src/theme/themes/oc-2.json +509 -509
- package/src/theme/themes/one-dark.json +89 -89
- package/src/theme/themes/onedarkpro.json +45 -45
- package/src/theme/themes/orng.json +87 -87
- package/src/theme/themes/osaka-jade.json +88 -88
- package/src/theme/themes/palenight.json +85 -85
- package/src/theme/themes/rosepine.json +85 -85
- package/src/theme/themes/shadesofpurple.json +51 -51
- package/src/theme/themes/solarized.json +49 -49
- package/src/theme/themes/synthwave84.json +87 -87
- package/src/theme/themes/tokyonight.json +47 -47
- package/src/theme/themes/vercel.json +90 -90
- package/src/theme/themes/vesper.json +51 -51
- package/src/theme/themes/zenburn.json +87 -87
- package/src/theme/types.ts +75 -75
- package/src/theme/v2/avatar.ts +48 -48
- package/src/theme/v2/default-primitives.ts +114 -114
- package/src/theme/v2/foreground.ts +69 -69
- package/src/theme/v2/mapping.ts +180 -180
- package/src/theme/v2/resolve.ts +163 -163
- package/src/typography/slash/slash.css +14 -14
- package/src/typography/slash/slash.stories.tsx +26 -26
- package/src/typography/slash/slash.tsx +16 -16
- package/src/typography/text-shimmer/machine.ts +90 -90
- package/src/typography/text-shimmer/text-shimmer.css +152 -152
- package/src/typography/text-shimmer/text-shimmer.stories.tsx +64 -64
- package/src/typography/text-shimmer/text-shimmer.tsx +81 -81
- package/src/typography/wordmark/wordmark.stories.tsx +19 -19
- package/src/typography/wordmark/wordmark.tsx +73 -73
- package/test/solid-jsx.ts +20 -20
- package/tsconfig.build.json +14 -14
- package/tsconfig.json +23 -23
- package/vite.config.ts +61 -61
- package/src/components/animated-number-machine.test.ts +0 -140
- package/src/components/file-icon-machine.test.ts +0 -52
- package/src/components/image-flight-machine.test.ts +0 -184
- package/src/components/image-flight.test.ts +0 -173
- package/src/components/image-zoom-machine.test.ts +0 -154
- package/src/components/image-zoom.test.ts +0 -96
- package/src/components/popover-machine.test.ts +0 -150
- package/src/components/resize-handle-machine.test.ts +0 -164
- package/src/components/scroll-view-machine.test.ts +0 -141
- package/src/components/scroll-view.test.ts +0 -114
- package/src/components/spinner-radar.test.ts +0 -61
- package/src/components/text-field-machine.test.ts +0 -99
- package/src/components/text-reveal-machine.test.ts +0 -157
- package/src/components/typewriter-machine.test.ts +0 -177
- package/src/context/dialog-machine.test.ts +0 -295
- package/src/context/i18n.test.ts +0 -89
- package/src/context/marked-base.test.ts +0 -75
- package/src/context/marked-parser.test.ts +0 -167
- package/src/context/marked-regression.test.ts +0 -12
- package/src/data-display/line-comment/machine.test.ts +0 -385
- package/src/data-display/project-avatar/animation-machine.test.ts +0 -134
- package/src/data-display/project-avatar/generated.test.ts +0 -50
- package/src/data-display/project-avatar/procedural.test.ts +0 -16
- package/src/data-display/project-avatar/project-avatar.test.ts +0 -21
- package/src/feedback/toast/description.test.ts +0 -20
- package/src/feedback/toast/machine.test.ts +0 -106
- package/src/forms/search-list/navigation.test.ts +0 -40
- package/src/forms/select/machine.test.ts +0 -105
- package/src/forms/typeahead/machine.test.ts +0 -143
- package/src/hooks/auto-scroll-machine.test.ts +0 -212
- package/src/hooks/list-machine.test.ts +0 -263
- package/src/hooks/spin-phase.test.ts +0 -32
- package/src/hooks/use-filtered-list.test.ts +0 -41
- package/src/motion/core.test.ts +0 -328
- package/src/motion-tuning-features.test.ts +0 -129
- package/src/motion-tuning.test.ts +0 -68
- package/src/navigation/menu/machine.test.ts +0 -85
- package/src/navigation/menu/submenu-machine.test.ts +0 -71
- package/src/navigation/segmented-control/segmented-control.test.ts +0 -123
- package/src/overlays/mcp-sign-in/machine.test.ts +0 -215
- package/src/overlays/tooltip/machine.test.ts +0 -214
- package/src/theme/machine.test.ts +0 -498
- package/src/theme/v2/resolve.test.ts +0 -120
- package/src/typography/text-shimmer/machine.test.ts +0 -117
|
@@ -1,600 +1,600 @@
|
|
|
1
|
-
import { DropdownMenu, type DropdownMenuTriggerProps } from "@kobalte/core/dropdown-menu"
|
|
2
|
-
import { ContextMenu } from "@kobalte/core/context-menu"
|
|
3
|
-
import type { PolymorphicProps } from "@kobalte/core/polymorphic"
|
|
4
|
-
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
5
|
-
import {
|
|
6
|
-
createComputed,
|
|
7
|
-
createContext,
|
|
8
|
-
createEffect,
|
|
9
|
-
createMemo,
|
|
10
|
-
createSignal,
|
|
11
|
-
createUniqueId,
|
|
12
|
-
on,
|
|
13
|
-
onCleanup,
|
|
14
|
-
Show,
|
|
15
|
-
splitProps,
|
|
16
|
-
useContext,
|
|
17
|
-
type Accessor,
|
|
18
|
-
type Component,
|
|
19
|
-
type ComponentProps,
|
|
20
|
-
type JSX,
|
|
21
|
-
type ParentProps,
|
|
22
|
-
type ValidComponent,
|
|
23
|
-
} from "solid-js"
|
|
24
|
-
import {
|
|
25
|
-
createMenuState,
|
|
26
|
-
MENU_CLOSE_AUTOFOCUS,
|
|
27
|
-
MENU_DISPOSED,
|
|
28
|
-
MENU_OUTSIDE_INTERACTED,
|
|
29
|
-
openChangedEvent,
|
|
30
|
-
selectMenuRestoreTriggerWithoutRing,
|
|
31
|
-
transitionMenu,
|
|
32
|
-
type MenuEvent,
|
|
33
|
-
type MenuState,
|
|
34
|
-
} from "./machine"
|
|
35
|
-
import {
|
|
36
|
-
selectSubmenuOpen,
|
|
37
|
-
SUBMENU_CLOSED,
|
|
38
|
-
SUBMENU_DISPOSED,
|
|
39
|
-
SUBMENU_FOCUS_LEFT,
|
|
40
|
-
SUBMENU_FOCUS_RETURNED,
|
|
41
|
-
submenuLeaveElapsed,
|
|
42
|
-
submenuRequested,
|
|
43
|
-
transitionSubmenu,
|
|
44
|
-
type SubmenuEvent,
|
|
45
|
-
type SubmenuState,
|
|
46
|
-
} from "./submenu-machine"
|
|
47
|
-
import { createOverlayFocus, openGesture, releaseOpenGesture, retainOpenGesture } from "../../context/overlay-focus"
|
|
48
|
-
import "./menu.css"
|
|
49
|
-
|
|
50
|
-
const ChevronRight: Component = () => (
|
|
51
|
-
<svg
|
|
52
|
-
data-slot="menu-v2-item-chevron"
|
|
53
|
-
width="16"
|
|
54
|
-
height="16"
|
|
55
|
-
viewBox="0 0 16 16"
|
|
56
|
-
fill="none"
|
|
57
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
58
|
-
aria-hidden="true"
|
|
59
|
-
>
|
|
60
|
-
<path d="M6 4L10 8L6 12V4Z" fill="currentColor" />
|
|
61
|
-
</svg>
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
const CheckMark: Component = () => (
|
|
65
|
-
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
66
|
-
<path
|
|
67
|
-
d="M3.53564 8.17857L6.39279 11.75L12.4642 4.25"
|
|
68
|
-
stroke="currentColor"
|
|
69
|
-
stroke-width="1"
|
|
70
|
-
stroke-linecap="round"
|
|
71
|
-
stroke-linejoin="round"
|
|
72
|
-
/>
|
|
73
|
-
</svg>
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
export type MenuAppearance = "standard" | "compact"
|
|
77
|
-
|
|
78
|
-
type MenuContextValue = {
|
|
79
|
-
appearance: Accessor<MenuAppearance>
|
|
80
|
-
state: Accessor<MenuState>
|
|
81
|
-
modal: Accessor<boolean>
|
|
82
|
-
onOutsideInteract: () => void
|
|
83
|
-
onCloseAutoFocus: () => void
|
|
84
|
-
restoreFocus?: (event: Event) => void
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Context menus restore focus through `restoreFocus`, so they never run the dropdown machine.
|
|
88
|
-
const UNTRACKED_MENU: MenuContextValue = {
|
|
89
|
-
appearance: () => "compact",
|
|
90
|
-
state: () => createMenuState(false),
|
|
91
|
-
modal: () => true,
|
|
92
|
-
onOutsideInteract: () => {},
|
|
93
|
-
onCloseAutoFocus: () => {},
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const MenuAppearanceContext = createContext<MenuContextValue>(UNTRACKED_MENU)
|
|
97
|
-
|
|
98
|
-
function useMenuContext() {
|
|
99
|
-
const ctx = useContext(MenuAppearanceContext)
|
|
100
|
-
|
|
101
|
-
if (!ctx) throw new Error("Menu components must be used inside Menu or Menu.Context")
|
|
102
|
-
|
|
103
|
-
return ctx
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function ItemBody(
|
|
107
|
-
props: ParentProps<{
|
|
108
|
-
shortcut?: JSX.Element | string
|
|
109
|
-
badge?: JSX.Element | string
|
|
110
|
-
trailing?: JSX.Element
|
|
111
|
-
}>,
|
|
112
|
-
) {
|
|
113
|
-
return (
|
|
114
|
-
<>
|
|
115
|
-
<span data-slot="menu-v2-item-content">{props.children}</span>
|
|
116
|
-
<Show when={props.shortcut}>{(shortcut) => <span data-slot="menu-v2-item-shortcut">{shortcut()}</span>}</Show>
|
|
117
|
-
<Show when={props.badge}>{(badge) => <span data-slot="menu-v2-item-badge">{badge()}</span>}</Show>
|
|
118
|
-
{props.trailing}
|
|
119
|
-
</>
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export interface MenuItemProps extends ComponentProps<typeof DropdownMenu.Item> {
|
|
124
|
-
shortcut?: JSX.Element | string
|
|
125
|
-
badge?: JSX.Element | string
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function MenuItem(props: ParentProps<MenuItemProps>) {
|
|
129
|
-
const ctx = useMenuContext()
|
|
130
|
-
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
|
|
131
|
-
|
|
132
|
-
return (
|
|
133
|
-
<DropdownMenu.Item
|
|
134
|
-
{...r}
|
|
135
|
-
data-component="menu-v2-item"
|
|
136
|
-
data-appearance={ctx.appearance()}
|
|
137
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
138
|
-
>
|
|
139
|
-
<ItemBody shortcut={s.shortcut} badge={s.badge}>
|
|
140
|
-
{s.children}
|
|
141
|
-
</ItemBody>
|
|
142
|
-
</DropdownMenu.Item>
|
|
143
|
-
)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export interface MenuItemRowProps extends ComponentProps<typeof DropdownMenu.Group> {
|
|
147
|
-
/** The row's name, set where an item's label is. It names the group for assistive technology. */
|
|
148
|
-
label: JSX.Element
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// A row that is not an action itself: its name where an item's label is, and small items of its own where an item's
|
|
152
|
-
// shortcut or chevron is. It is laid out as an item, so its name and the edge of its last item cannot drift from the
|
|
153
|
-
// rows around it. Up and Down walk its items in order, as they walk every item; Left and Right move between them.
|
|
154
|
-
function MenuItemRow(props: ParentProps<MenuItemRowProps>) {
|
|
155
|
-
const ctx = useMenuContext()
|
|
156
|
-
const [s, r] = splitProps(props, ["class", "classList", "children", "label"])
|
|
157
|
-
|
|
158
|
-
const onKeyDown: JSX.EventHandler<HTMLSpanElement, KeyboardEvent> = (event) => {
|
|
159
|
-
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return
|
|
160
|
-
|
|
161
|
-
const items = [...event.currentTarget.querySelectorAll<HTMLElement>('[data-component="menu-v2-item"]:not([data-disabled])')]
|
|
162
|
-
const forward = (event.key === "ArrowRight") !== event.currentTarget.matches(":dir(rtl)")
|
|
163
|
-
const next = items[items.findIndex((item) => item === document.activeElement) + (forward ? 1 : -1)]
|
|
164
|
-
|
|
165
|
-
// Past either end the key keeps its meaning for the menu, such as closing a submenu.
|
|
166
|
-
if (!next) return
|
|
167
|
-
event.preventDefault()
|
|
168
|
-
event.stopPropagation()
|
|
169
|
-
next.focus()
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return (
|
|
173
|
-
<DropdownMenu.Group
|
|
174
|
-
{...r}
|
|
175
|
-
data-component="menu-v2-item"
|
|
176
|
-
data-row=""
|
|
177
|
-
data-appearance={ctx.appearance()}
|
|
178
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
179
|
-
>
|
|
180
|
-
<DropdownMenu.GroupLabel data-slot="menu-v2-item-content">{s.label}</DropdownMenu.GroupLabel>
|
|
181
|
-
<span data-slot="menu-v2-item-actions" onKeyDown={onKeyDown}>
|
|
182
|
-
{s.children}
|
|
183
|
-
</span>
|
|
184
|
-
</DropdownMenu.Group>
|
|
185
|
-
)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export interface MenuCheckboxItemProps extends ComponentProps<typeof DropdownMenu.CheckboxItem> {
|
|
189
|
-
shortcut?: JSX.Element | string
|
|
190
|
-
badge?: JSX.Element | string
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function MenuCheckboxItem(props: ParentProps<MenuCheckboxItemProps>) {
|
|
194
|
-
const ctx = useMenuContext()
|
|
195
|
-
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
|
|
196
|
-
|
|
197
|
-
return (
|
|
198
|
-
<DropdownMenu.CheckboxItem
|
|
199
|
-
{...r}
|
|
200
|
-
data-component="menu-v2-item"
|
|
201
|
-
data-appearance={ctx.appearance()}
|
|
202
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
203
|
-
>
|
|
204
|
-
<ItemBody
|
|
205
|
-
shortcut={s.shortcut}
|
|
206
|
-
badge={s.badge}
|
|
207
|
-
trailing={
|
|
208
|
-
<DropdownMenu.ItemIndicator data-slot="menu-v2-item-indicator" forceMount>
|
|
209
|
-
<CheckMark />
|
|
210
|
-
</DropdownMenu.ItemIndicator>
|
|
211
|
-
}
|
|
212
|
-
>
|
|
213
|
-
{s.children}
|
|
214
|
-
</ItemBody>
|
|
215
|
-
</DropdownMenu.CheckboxItem>
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export interface MenuRadioItemProps extends ComponentProps<typeof DropdownMenu.RadioItem> {
|
|
220
|
-
shortcut?: JSX.Element | string
|
|
221
|
-
badge?: JSX.Element | string
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function MenuRadioItem(props: ParentProps<MenuRadioItemProps>) {
|
|
225
|
-
const ctx = useMenuContext()
|
|
226
|
-
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
|
|
227
|
-
|
|
228
|
-
return (
|
|
229
|
-
<DropdownMenu.RadioItem
|
|
230
|
-
{...r}
|
|
231
|
-
data-component="menu-v2-item"
|
|
232
|
-
data-appearance={ctx.appearance()}
|
|
233
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
234
|
-
>
|
|
235
|
-
<ItemBody
|
|
236
|
-
shortcut={s.shortcut}
|
|
237
|
-
badge={s.badge}
|
|
238
|
-
trailing={
|
|
239
|
-
<DropdownMenu.ItemIndicator data-slot="menu-v2-item-indicator" forceMount>
|
|
240
|
-
<CheckMark />
|
|
241
|
-
</DropdownMenu.ItemIndicator>
|
|
242
|
-
}
|
|
243
|
-
>
|
|
244
|
-
{s.children}
|
|
245
|
-
</ItemBody>
|
|
246
|
-
</DropdownMenu.RadioItem>
|
|
247
|
-
)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export interface MenuSubTriggerProps extends ComponentProps<typeof DropdownMenu.SubTrigger> {
|
|
251
|
-
shortcut?: JSX.Element | string
|
|
252
|
-
badge?: JSX.Element | string
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export interface MenuSubProps extends ComponentProps<typeof DropdownMenu.Sub> {
|
|
256
|
-
placement?:
|
|
257
|
-
| "top"
|
|
258
|
-
| "top-start"
|
|
259
|
-
| "top-end"
|
|
260
|
-
| "bottom"
|
|
261
|
-
| "bottom-start"
|
|
262
|
-
| "bottom-end"
|
|
263
|
-
| "left"
|
|
264
|
-
| "left-start"
|
|
265
|
-
| "left-end"
|
|
266
|
-
| "right"
|
|
267
|
-
| "right-start"
|
|
268
|
-
| "right-end"
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Longer than Kobalte's 100ms hover delay, so a submenu the pointer rests on replaces the leaving one in the same frame.
|
|
272
|
-
const SUBMENU_LEAVE_DELAY = 150
|
|
273
|
-
|
|
274
|
-
type SubmenuGroup = { state: Accessor<SubmenuState>; dispatch: (event: SubmenuEvent) => void }
|
|
275
|
-
|
|
276
|
-
const SubmenuGroupContext = createContext<SubmenuGroup>()
|
|
277
|
-
|
|
278
|
-
const SubmenuTriggerContext = createContext<(element: HTMLElement) => void>()
|
|
279
|
-
|
|
280
|
-
function createSubmenuGroup(): SubmenuGroup {
|
|
281
|
-
const [state, setState] = createSignal(SUBMENU_CLOSED)
|
|
282
|
-
let leave: ReturnType<typeof setTimeout> | undefined
|
|
283
|
-
|
|
284
|
-
const dispatch = (event: SubmenuEvent) => {
|
|
285
|
-
const next = transitionSubmenu(state(), event)
|
|
286
|
-
|
|
287
|
-
if (next === state()) return
|
|
288
|
-
clearTimeout(leave)
|
|
289
|
-
|
|
290
|
-
if (next.status === "leaving") leave = setTimeout(() => dispatch(submenuLeaveElapsed(next)), SUBMENU_LEAVE_DELAY)
|
|
291
|
-
setState(next)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
onCleanup(() => {
|
|
295
|
-
clearTimeout(leave)
|
|
296
|
-
dispatch(SUBMENU_DISPOSED)
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
return { state, dispatch }
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Each menu surface owns the submenus it lists, and mounts this with its items so every open starts with none open.
|
|
303
|
-
function SubmenuGroupProvider(props: ParentProps) {
|
|
304
|
-
const group = createSubmenuGroup()
|
|
305
|
-
|
|
306
|
-
return <SubmenuGroupContext.Provider value={group}>{props.children}</SubmenuGroupContext.Provider>
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// The menu surface decides which of its submenus is open. A controlled submenu stays with its owner instead.
|
|
310
|
-
function MenuSub(props: MenuSubProps) {
|
|
311
|
-
const [local, rest] = splitProps(props, ["open", "defaultOpen", "onOpenChange"])
|
|
312
|
-
const group = useContext(SubmenuGroupContext) ?? createSubmenuGroup()
|
|
313
|
-
const id = createUniqueId()
|
|
314
|
-
const open = createMemo(() => selectSubmenuOpen(group.state(), id))
|
|
315
|
-
let trigger: HTMLElement | undefined
|
|
316
|
-
|
|
317
|
-
if (local.defaultOpen) group.dispatch(submenuRequested(id, true))
|
|
318
|
-
onCleanup(() => group.dispatch(submenuRequested(id, false)))
|
|
319
|
-
|
|
320
|
-
createEffect(
|
|
321
|
-
on(
|
|
322
|
-
open,
|
|
323
|
-
(value) => {
|
|
324
|
-
if (local.open === undefined) local.onOpenChange?.(value)
|
|
325
|
-
},
|
|
326
|
-
{ defer: true },
|
|
327
|
-
),
|
|
328
|
-
)
|
|
329
|
-
|
|
330
|
-
// Kobalte closes a submenu when focus leaves it, but ignores focus inside a top layer, and every menu is one so a modal
|
|
331
|
-
// dialog keeps it reachable. Focus moves go to the group instead, which waits for the next submenu or the pointer.
|
|
332
|
-
createEffect(() => {
|
|
333
|
-
if (!open()) return
|
|
334
|
-
makeEventListener(
|
|
335
|
-
document,
|
|
336
|
-
"focusin",
|
|
337
|
-
(event) => {
|
|
338
|
-
if (!(event.target instanceof Node) || !trigger) return
|
|
339
|
-
|
|
340
|
-
const left = !trigger.contains(event.target) && !!trigger.closest('[role="menu"]')?.contains(event.target)
|
|
341
|
-
group.dispatch(left ? SUBMENU_FOCUS_LEFT : SUBMENU_FOCUS_RETURNED)
|
|
342
|
-
},
|
|
343
|
-
{ capture: true },
|
|
344
|
-
)
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
return (
|
|
348
|
-
<SubmenuTriggerContext.Provider value={(element) => (trigger = element)}>
|
|
349
|
-
<DropdownMenu.Sub
|
|
350
|
-
{...rest}
|
|
351
|
-
open={local.open ?? open()}
|
|
352
|
-
onOpenChange={(next) => {
|
|
353
|
-
if (local.open !== undefined) return local.onOpenChange?.(next)
|
|
354
|
-
group.dispatch(submenuRequested(id, next))
|
|
355
|
-
}}
|
|
356
|
-
/>
|
|
357
|
-
</SubmenuTriggerContext.Provider>
|
|
358
|
-
)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function MenuSubTrigger(props: ParentProps<MenuSubTriggerProps>) {
|
|
362
|
-
const ctx = useMenuContext()
|
|
363
|
-
const registerTrigger = useContext(SubmenuTriggerContext)
|
|
364
|
-
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge", "ref"])
|
|
365
|
-
|
|
366
|
-
const assignRef = (element: HTMLElement) => {
|
|
367
|
-
registerTrigger?.(element)
|
|
368
|
-
const ref = s.ref
|
|
369
|
-
|
|
370
|
-
if (ref instanceof Function) ref(element)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return (
|
|
374
|
-
<DropdownMenu.SubTrigger
|
|
375
|
-
{...r}
|
|
376
|
-
ref={assignRef}
|
|
377
|
-
data-component="menu-v2-item"
|
|
378
|
-
data-appearance={ctx.appearance()}
|
|
379
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
380
|
-
>
|
|
381
|
-
<ItemBody shortcut={s.shortcut} badge={s.badge} trailing={<ChevronRight />}>
|
|
382
|
-
{s.children}
|
|
383
|
-
</ItemBody>
|
|
384
|
-
</DropdownMenu.SubTrigger>
|
|
385
|
-
)
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function MenuSubContent(props: ComponentProps<typeof DropdownMenu.SubContent>) {
|
|
389
|
-
const ctx = useMenuContext()
|
|
390
|
-
const [s, r] = splitProps(props, ["class", "classList", "children"])
|
|
391
|
-
|
|
392
|
-
return (
|
|
393
|
-
<DropdownMenu.SubContent
|
|
394
|
-
{...r}
|
|
395
|
-
data-kb-top-layer=""
|
|
396
|
-
data-component="menu-v2-content"
|
|
397
|
-
data-appearance={ctx.appearance()}
|
|
398
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
399
|
-
>
|
|
400
|
-
<SubmenuGroupProvider>{s.children}</SubmenuGroupProvider>
|
|
401
|
-
</DropdownMenu.SubContent>
|
|
402
|
-
)
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
function MenuGroupLabel(props: ComponentProps<typeof DropdownMenu.GroupLabel>) {
|
|
406
|
-
const ctx = useMenuContext()
|
|
407
|
-
const [s, r] = splitProps(props, ["class", "classList"])
|
|
408
|
-
|
|
409
|
-
return (
|
|
410
|
-
<DropdownMenu.GroupLabel
|
|
411
|
-
{...r}
|
|
412
|
-
data-slot="menu-v2-group-label"
|
|
413
|
-
data-appearance={ctx.appearance()}
|
|
414
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
415
|
-
/>
|
|
416
|
-
)
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function MenuSeparator(props: ComponentProps<typeof DropdownMenu.Separator>) {
|
|
420
|
-
const ctx = useMenuContext()
|
|
421
|
-
const [s, r] = splitProps(props, ["class", "classList"])
|
|
422
|
-
|
|
423
|
-
return (
|
|
424
|
-
<DropdownMenu.Separator
|
|
425
|
-
{...r}
|
|
426
|
-
data-slot="menu-v2-separator"
|
|
427
|
-
data-appearance={ctx.appearance()}
|
|
428
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
429
|
-
/>
|
|
430
|
-
)
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// Kobalte drops `data-expanded` as the menu closes but returns focus to the trigger a task later, so for a frame the
|
|
434
|
-
// trigger is neither expanded nor focused. `data-closing` covers that gap for UI revealed by either.
|
|
435
|
-
function MenuTrigger<T extends ValidComponent = "button">(props: PolymorphicProps<T, DropdownMenuTriggerProps<T>>) {
|
|
436
|
-
const ctx = useMenuContext()
|
|
437
|
-
|
|
438
|
-
return <DropdownMenu.Trigger {...props} data-closing={ctx.state().status === "closing" ? "" : undefined} />
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function MenuContent(props: ComponentProps<typeof DropdownMenu.Content>) {
|
|
442
|
-
const ctx = useMenuContext()
|
|
443
|
-
const [s, r] = splitProps(props, ["class", "classList", "children", "onCloseAutoFocus", "onInteractOutside"])
|
|
444
|
-
|
|
445
|
-
// Kobalte's own rule for when an outside press keeps focus where it landed.
|
|
446
|
-
const onInteractOutside: NonNullable<typeof s.onInteractOutside> = (event) => {
|
|
447
|
-
s.onInteractOutside?.(event)
|
|
448
|
-
|
|
449
|
-
if (!event.defaultPrevented && (!ctx.modal() || event.detail.isContextMenu)) ctx.onOutsideInteract()
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// A menu returns focus to its trigger when it closes. Restore it without the ring after a pointer open and keep the
|
|
453
|
-
// ring for keyboard and programmatic opens.
|
|
454
|
-
const onCloseAutoFocus = (event: Event) => {
|
|
455
|
-
const restore = selectMenuRestoreTriggerWithoutRing(ctx.state())
|
|
456
|
-
ctx.onCloseAutoFocus()
|
|
457
|
-
s.onCloseAutoFocus?.(event)
|
|
458
|
-
|
|
459
|
-
if (event.defaultPrevented || !restore) return
|
|
460
|
-
event.preventDefault()
|
|
461
|
-
const active = document.activeElement
|
|
462
|
-
|
|
463
|
-
// An outside press already moved focus where it belongs.
|
|
464
|
-
if (active && active !== document.body && !active.closest('[role="menu"]')) return
|
|
465
|
-
const labelledby = event.target instanceof Element ? event.target.getAttribute("aria-labelledby") : null
|
|
466
|
-
const trigger = labelledby ? document.getElementById(labelledby) : null
|
|
467
|
-
trigger?.focus({ preventScroll: true, focusVisible: false })
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return (
|
|
471
|
-
<DropdownMenu.Content
|
|
472
|
-
{...r}
|
|
473
|
-
onCloseAutoFocus={onCloseAutoFocus}
|
|
474
|
-
onInteractOutside={onInteractOutside}
|
|
475
|
-
// A modal dialog hides what's outside it from assistive tech, and a non-modal menu is portaled outside it.
|
|
476
|
-
data-kb-top-layer=""
|
|
477
|
-
data-component="menu-v2-content"
|
|
478
|
-
data-appearance={ctx.appearance()}
|
|
479
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
480
|
-
>
|
|
481
|
-
<SubmenuGroupProvider>{s.children}</SubmenuGroupProvider>
|
|
482
|
-
</DropdownMenu.Content>
|
|
483
|
-
)
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
export interface MenuProps extends ComponentProps<typeof DropdownMenu> {
|
|
487
|
-
appearance?: MenuAppearance
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
function MenuRoot(props: MenuProps) {
|
|
491
|
-
const [local, rest] = splitProps(props, ["appearance", "children", "onOpenChange"])
|
|
492
|
-
const appearance = () => local.appearance ?? "compact"
|
|
493
|
-
const initialOpen = !!props.open || (props.open === undefined && !!props.defaultOpen)
|
|
494
|
-
const [menuState, setMenuState] = createSignal(createMenuState(initialOpen))
|
|
495
|
-
const dispatch = (event: MenuEvent) => setMenuState((state) => transitionMenu(state, event))
|
|
496
|
-
|
|
497
|
-
retainOpenGesture()
|
|
498
|
-
onCleanup(() => {
|
|
499
|
-
releaseOpenGesture()
|
|
500
|
-
dispatch(MENU_DISPOSED)
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
// Kobalte does not report a controlled open it did not ask for, so a controlled menu follows `open` itself.
|
|
504
|
-
createComputed(() => {
|
|
505
|
-
if (props.open === undefined) return
|
|
506
|
-
dispatch(openChangedEvent(props.open, openGesture()))
|
|
507
|
-
})
|
|
508
|
-
|
|
509
|
-
const context = {
|
|
510
|
-
appearance,
|
|
511
|
-
state: menuState,
|
|
512
|
-
modal: () => props.modal ?? true,
|
|
513
|
-
onOutsideInteract: () => dispatch(MENU_OUTSIDE_INTERACTED),
|
|
514
|
-
onCloseAutoFocus: () => dispatch(MENU_CLOSE_AUTOFOCUS),
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
return (
|
|
518
|
-
<MenuAppearanceContext.Provider value={context}>
|
|
519
|
-
<DropdownMenu
|
|
520
|
-
{...rest}
|
|
521
|
-
onOpenChange={(open) => {
|
|
522
|
-
if (props.open === undefined) dispatch(openChangedEvent(open, openGesture()))
|
|
523
|
-
local.onOpenChange?.(open)
|
|
524
|
-
}}
|
|
525
|
-
>
|
|
526
|
-
{local.children}
|
|
527
|
-
</DropdownMenu>
|
|
528
|
-
</MenuAppearanceContext.Provider>
|
|
529
|
-
)
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
export interface MenuContextProps extends ComponentProps<typeof ContextMenu> {
|
|
533
|
-
appearance?: MenuAppearance
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
function MenuContextRoot(props: MenuContextProps) {
|
|
537
|
-
const [local, rest] = splitProps(props, ["appearance", "children", "onOpenChange"])
|
|
538
|
-
const appearance = () => local.appearance ?? "compact"
|
|
539
|
-
const overlayFocus = createOverlayFocus()
|
|
540
|
-
|
|
541
|
-
return (
|
|
542
|
-
<MenuAppearanceContext.Provider
|
|
543
|
-
value={{ ...UNTRACKED_MENU, appearance, restoreFocus: (event) => overlayFocus.restore(event) }}
|
|
544
|
-
>
|
|
545
|
-
<ContextMenu
|
|
546
|
-
{...rest}
|
|
547
|
-
onOpenChange={(open) => {
|
|
548
|
-
overlayFocus.openChanged(open)
|
|
549
|
-
local.onOpenChange?.(open)
|
|
550
|
-
}}
|
|
551
|
-
>
|
|
552
|
-
{local.children}
|
|
553
|
-
</ContextMenu>
|
|
554
|
-
</MenuAppearanceContext.Provider>
|
|
555
|
-
)
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function MenuContextContent(props: ComponentProps<typeof ContextMenu.Content>) {
|
|
559
|
-
const ctx = useMenuContext()
|
|
560
|
-
const [s, r] = splitProps(props, ["class", "classList", "children", "onCloseAutoFocus"])
|
|
561
|
-
|
|
562
|
-
return (
|
|
563
|
-
<ContextMenu.Content
|
|
564
|
-
{...r}
|
|
565
|
-
onCloseAutoFocus={(event) => {
|
|
566
|
-
s.onCloseAutoFocus?.(event)
|
|
567
|
-
ctx.restoreFocus?.(event)
|
|
568
|
-
}}
|
|
569
|
-
data-component="menu-v2-content"
|
|
570
|
-
data-appearance={ctx.appearance()}
|
|
571
|
-
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
572
|
-
>
|
|
573
|
-
<SubmenuGroupProvider>{s.children}</SubmenuGroupProvider>
|
|
574
|
-
</ContextMenu.Content>
|
|
575
|
-
)
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const MenuContext = Object.assign(MenuContextRoot, {
|
|
579
|
-
Trigger: ContextMenu.Trigger,
|
|
580
|
-
Portal: ContextMenu.Portal,
|
|
581
|
-
Content: MenuContextContent,
|
|
582
|
-
})
|
|
583
|
-
|
|
584
|
-
export const Menu = Object.assign(MenuRoot, {
|
|
585
|
-
Trigger: MenuTrigger,
|
|
586
|
-
Portal: DropdownMenu.Portal,
|
|
587
|
-
Content: MenuContent,
|
|
588
|
-
Item: MenuItem,
|
|
589
|
-
ItemRow: MenuItemRow,
|
|
590
|
-
CheckboxItem: MenuCheckboxItem,
|
|
591
|
-
RadioGroup: DropdownMenu.RadioGroup,
|
|
592
|
-
RadioItem: MenuRadioItem,
|
|
593
|
-
Group: DropdownMenu.Group,
|
|
594
|
-
GroupLabel: MenuGroupLabel,
|
|
595
|
-
Separator: MenuSeparator,
|
|
596
|
-
Sub: MenuSub,
|
|
597
|
-
SubTrigger: MenuSubTrigger,
|
|
598
|
-
SubContent: MenuSubContent,
|
|
599
|
-
Context: MenuContext,
|
|
600
|
-
})
|
|
1
|
+
import { DropdownMenu, type DropdownMenuTriggerProps } from "@kobalte/core/dropdown-menu"
|
|
2
|
+
import { ContextMenu } from "@kobalte/core/context-menu"
|
|
3
|
+
import type { PolymorphicProps } from "@kobalte/core/polymorphic"
|
|
4
|
+
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
5
|
+
import {
|
|
6
|
+
createComputed,
|
|
7
|
+
createContext,
|
|
8
|
+
createEffect,
|
|
9
|
+
createMemo,
|
|
10
|
+
createSignal,
|
|
11
|
+
createUniqueId,
|
|
12
|
+
on,
|
|
13
|
+
onCleanup,
|
|
14
|
+
Show,
|
|
15
|
+
splitProps,
|
|
16
|
+
useContext,
|
|
17
|
+
type Accessor,
|
|
18
|
+
type Component,
|
|
19
|
+
type ComponentProps,
|
|
20
|
+
type JSX,
|
|
21
|
+
type ParentProps,
|
|
22
|
+
type ValidComponent,
|
|
23
|
+
} from "solid-js"
|
|
24
|
+
import {
|
|
25
|
+
createMenuState,
|
|
26
|
+
MENU_CLOSE_AUTOFOCUS,
|
|
27
|
+
MENU_DISPOSED,
|
|
28
|
+
MENU_OUTSIDE_INTERACTED,
|
|
29
|
+
openChangedEvent,
|
|
30
|
+
selectMenuRestoreTriggerWithoutRing,
|
|
31
|
+
transitionMenu,
|
|
32
|
+
type MenuEvent,
|
|
33
|
+
type MenuState,
|
|
34
|
+
} from "./machine"
|
|
35
|
+
import {
|
|
36
|
+
selectSubmenuOpen,
|
|
37
|
+
SUBMENU_CLOSED,
|
|
38
|
+
SUBMENU_DISPOSED,
|
|
39
|
+
SUBMENU_FOCUS_LEFT,
|
|
40
|
+
SUBMENU_FOCUS_RETURNED,
|
|
41
|
+
submenuLeaveElapsed,
|
|
42
|
+
submenuRequested,
|
|
43
|
+
transitionSubmenu,
|
|
44
|
+
type SubmenuEvent,
|
|
45
|
+
type SubmenuState,
|
|
46
|
+
} from "./submenu-machine"
|
|
47
|
+
import { createOverlayFocus, openGesture, releaseOpenGesture, retainOpenGesture } from "../../context/overlay-focus"
|
|
48
|
+
import "./menu.css"
|
|
49
|
+
|
|
50
|
+
const ChevronRight: Component = () => (
|
|
51
|
+
<svg
|
|
52
|
+
data-slot="menu-v2-item-chevron"
|
|
53
|
+
width="16"
|
|
54
|
+
height="16"
|
|
55
|
+
viewBox="0 0 16 16"
|
|
56
|
+
fill="none"
|
|
57
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
58
|
+
aria-hidden="true"
|
|
59
|
+
>
|
|
60
|
+
<path d="M6 4L10 8L6 12V4Z" fill="currentColor" />
|
|
61
|
+
</svg>
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const CheckMark: Component = () => (
|
|
65
|
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
66
|
+
<path
|
|
67
|
+
d="M3.53564 8.17857L6.39279 11.75L12.4642 4.25"
|
|
68
|
+
stroke="currentColor"
|
|
69
|
+
stroke-width="1"
|
|
70
|
+
stroke-linecap="round"
|
|
71
|
+
stroke-linejoin="round"
|
|
72
|
+
/>
|
|
73
|
+
</svg>
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
export type MenuAppearance = "standard" | "compact"
|
|
77
|
+
|
|
78
|
+
type MenuContextValue = {
|
|
79
|
+
appearance: Accessor<MenuAppearance>
|
|
80
|
+
state: Accessor<MenuState>
|
|
81
|
+
modal: Accessor<boolean>
|
|
82
|
+
onOutsideInteract: () => void
|
|
83
|
+
onCloseAutoFocus: () => void
|
|
84
|
+
restoreFocus?: (event: Event) => void
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Context menus restore focus through `restoreFocus`, so they never run the dropdown machine.
|
|
88
|
+
const UNTRACKED_MENU: MenuContextValue = {
|
|
89
|
+
appearance: () => "compact",
|
|
90
|
+
state: () => createMenuState(false),
|
|
91
|
+
modal: () => true,
|
|
92
|
+
onOutsideInteract: () => {},
|
|
93
|
+
onCloseAutoFocus: () => {},
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const MenuAppearanceContext = createContext<MenuContextValue>(UNTRACKED_MENU)
|
|
97
|
+
|
|
98
|
+
function useMenuContext() {
|
|
99
|
+
const ctx = useContext(MenuAppearanceContext)
|
|
100
|
+
|
|
101
|
+
if (!ctx) throw new Error("Menu components must be used inside Menu or Menu.Context")
|
|
102
|
+
|
|
103
|
+
return ctx
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function ItemBody(
|
|
107
|
+
props: ParentProps<{
|
|
108
|
+
shortcut?: JSX.Element | string
|
|
109
|
+
badge?: JSX.Element | string
|
|
110
|
+
trailing?: JSX.Element
|
|
111
|
+
}>,
|
|
112
|
+
) {
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
<span data-slot="menu-v2-item-content">{props.children}</span>
|
|
116
|
+
<Show when={props.shortcut}>{(shortcut) => <span data-slot="menu-v2-item-shortcut">{shortcut()}</span>}</Show>
|
|
117
|
+
<Show when={props.badge}>{(badge) => <span data-slot="menu-v2-item-badge">{badge()}</span>}</Show>
|
|
118
|
+
{props.trailing}
|
|
119
|
+
</>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface MenuItemProps extends ComponentProps<typeof DropdownMenu.Item> {
|
|
124
|
+
shortcut?: JSX.Element | string
|
|
125
|
+
badge?: JSX.Element | string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function MenuItem(props: ParentProps<MenuItemProps>) {
|
|
129
|
+
const ctx = useMenuContext()
|
|
130
|
+
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<DropdownMenu.Item
|
|
134
|
+
{...r}
|
|
135
|
+
data-component="menu-v2-item"
|
|
136
|
+
data-appearance={ctx.appearance()}
|
|
137
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
138
|
+
>
|
|
139
|
+
<ItemBody shortcut={s.shortcut} badge={s.badge}>
|
|
140
|
+
{s.children}
|
|
141
|
+
</ItemBody>
|
|
142
|
+
</DropdownMenu.Item>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface MenuItemRowProps extends ComponentProps<typeof DropdownMenu.Group> {
|
|
147
|
+
/** The row's name, set where an item's label is. It names the group for assistive technology. */
|
|
148
|
+
label: JSX.Element
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// A row that is not an action itself: its name where an item's label is, and small items of its own where an item's
|
|
152
|
+
// shortcut or chevron is. It is laid out as an item, so its name and the edge of its last item cannot drift from the
|
|
153
|
+
// rows around it. Up and Down walk its items in order, as they walk every item; Left and Right move between them.
|
|
154
|
+
function MenuItemRow(props: ParentProps<MenuItemRowProps>) {
|
|
155
|
+
const ctx = useMenuContext()
|
|
156
|
+
const [s, r] = splitProps(props, ["class", "classList", "children", "label"])
|
|
157
|
+
|
|
158
|
+
const onKeyDown: JSX.EventHandler<HTMLSpanElement, KeyboardEvent> = (event) => {
|
|
159
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return
|
|
160
|
+
|
|
161
|
+
const items = [...event.currentTarget.querySelectorAll<HTMLElement>('[data-component="menu-v2-item"]:not([data-disabled])')]
|
|
162
|
+
const forward = (event.key === "ArrowRight") !== event.currentTarget.matches(":dir(rtl)")
|
|
163
|
+
const next = items[items.findIndex((item) => item === document.activeElement) + (forward ? 1 : -1)]
|
|
164
|
+
|
|
165
|
+
// Past either end the key keeps its meaning for the menu, such as closing a submenu.
|
|
166
|
+
if (!next) return
|
|
167
|
+
event.preventDefault()
|
|
168
|
+
event.stopPropagation()
|
|
169
|
+
next.focus()
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<DropdownMenu.Group
|
|
174
|
+
{...r}
|
|
175
|
+
data-component="menu-v2-item"
|
|
176
|
+
data-row=""
|
|
177
|
+
data-appearance={ctx.appearance()}
|
|
178
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
179
|
+
>
|
|
180
|
+
<DropdownMenu.GroupLabel data-slot="menu-v2-item-content">{s.label}</DropdownMenu.GroupLabel>
|
|
181
|
+
<span data-slot="menu-v2-item-actions" onKeyDown={onKeyDown}>
|
|
182
|
+
{s.children}
|
|
183
|
+
</span>
|
|
184
|
+
</DropdownMenu.Group>
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface MenuCheckboxItemProps extends ComponentProps<typeof DropdownMenu.CheckboxItem> {
|
|
189
|
+
shortcut?: JSX.Element | string
|
|
190
|
+
badge?: JSX.Element | string
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function MenuCheckboxItem(props: ParentProps<MenuCheckboxItemProps>) {
|
|
194
|
+
const ctx = useMenuContext()
|
|
195
|
+
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<DropdownMenu.CheckboxItem
|
|
199
|
+
{...r}
|
|
200
|
+
data-component="menu-v2-item"
|
|
201
|
+
data-appearance={ctx.appearance()}
|
|
202
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
203
|
+
>
|
|
204
|
+
<ItemBody
|
|
205
|
+
shortcut={s.shortcut}
|
|
206
|
+
badge={s.badge}
|
|
207
|
+
trailing={
|
|
208
|
+
<DropdownMenu.ItemIndicator data-slot="menu-v2-item-indicator" forceMount>
|
|
209
|
+
<CheckMark />
|
|
210
|
+
</DropdownMenu.ItemIndicator>
|
|
211
|
+
}
|
|
212
|
+
>
|
|
213
|
+
{s.children}
|
|
214
|
+
</ItemBody>
|
|
215
|
+
</DropdownMenu.CheckboxItem>
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface MenuRadioItemProps extends ComponentProps<typeof DropdownMenu.RadioItem> {
|
|
220
|
+
shortcut?: JSX.Element | string
|
|
221
|
+
badge?: JSX.Element | string
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function MenuRadioItem(props: ParentProps<MenuRadioItemProps>) {
|
|
225
|
+
const ctx = useMenuContext()
|
|
226
|
+
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge"])
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<DropdownMenu.RadioItem
|
|
230
|
+
{...r}
|
|
231
|
+
data-component="menu-v2-item"
|
|
232
|
+
data-appearance={ctx.appearance()}
|
|
233
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
234
|
+
>
|
|
235
|
+
<ItemBody
|
|
236
|
+
shortcut={s.shortcut}
|
|
237
|
+
badge={s.badge}
|
|
238
|
+
trailing={
|
|
239
|
+
<DropdownMenu.ItemIndicator data-slot="menu-v2-item-indicator" forceMount>
|
|
240
|
+
<CheckMark />
|
|
241
|
+
</DropdownMenu.ItemIndicator>
|
|
242
|
+
}
|
|
243
|
+
>
|
|
244
|
+
{s.children}
|
|
245
|
+
</ItemBody>
|
|
246
|
+
</DropdownMenu.RadioItem>
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface MenuSubTriggerProps extends ComponentProps<typeof DropdownMenu.SubTrigger> {
|
|
251
|
+
shortcut?: JSX.Element | string
|
|
252
|
+
badge?: JSX.Element | string
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface MenuSubProps extends ComponentProps<typeof DropdownMenu.Sub> {
|
|
256
|
+
placement?:
|
|
257
|
+
| "top"
|
|
258
|
+
| "top-start"
|
|
259
|
+
| "top-end"
|
|
260
|
+
| "bottom"
|
|
261
|
+
| "bottom-start"
|
|
262
|
+
| "bottom-end"
|
|
263
|
+
| "left"
|
|
264
|
+
| "left-start"
|
|
265
|
+
| "left-end"
|
|
266
|
+
| "right"
|
|
267
|
+
| "right-start"
|
|
268
|
+
| "right-end"
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Longer than Kobalte's 100ms hover delay, so a submenu the pointer rests on replaces the leaving one in the same frame.
|
|
272
|
+
const SUBMENU_LEAVE_DELAY = 150
|
|
273
|
+
|
|
274
|
+
type SubmenuGroup = { state: Accessor<SubmenuState>; dispatch: (event: SubmenuEvent) => void }
|
|
275
|
+
|
|
276
|
+
const SubmenuGroupContext = createContext<SubmenuGroup>()
|
|
277
|
+
|
|
278
|
+
const SubmenuTriggerContext = createContext<(element: HTMLElement) => void>()
|
|
279
|
+
|
|
280
|
+
function createSubmenuGroup(): SubmenuGroup {
|
|
281
|
+
const [state, setState] = createSignal(SUBMENU_CLOSED)
|
|
282
|
+
let leave: ReturnType<typeof setTimeout> | undefined
|
|
283
|
+
|
|
284
|
+
const dispatch = (event: SubmenuEvent) => {
|
|
285
|
+
const next = transitionSubmenu(state(), event)
|
|
286
|
+
|
|
287
|
+
if (next === state()) return
|
|
288
|
+
clearTimeout(leave)
|
|
289
|
+
|
|
290
|
+
if (next.status === "leaving") leave = setTimeout(() => dispatch(submenuLeaveElapsed(next)), SUBMENU_LEAVE_DELAY)
|
|
291
|
+
setState(next)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
onCleanup(() => {
|
|
295
|
+
clearTimeout(leave)
|
|
296
|
+
dispatch(SUBMENU_DISPOSED)
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
return { state, dispatch }
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Each menu surface owns the submenus it lists, and mounts this with its items so every open starts with none open.
|
|
303
|
+
function SubmenuGroupProvider(props: ParentProps) {
|
|
304
|
+
const group = createSubmenuGroup()
|
|
305
|
+
|
|
306
|
+
return <SubmenuGroupContext.Provider value={group}>{props.children}</SubmenuGroupContext.Provider>
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// The menu surface decides which of its submenus is open. A controlled submenu stays with its owner instead.
|
|
310
|
+
function MenuSub(props: MenuSubProps) {
|
|
311
|
+
const [local, rest] = splitProps(props, ["open", "defaultOpen", "onOpenChange"])
|
|
312
|
+
const group = useContext(SubmenuGroupContext) ?? createSubmenuGroup()
|
|
313
|
+
const id = createUniqueId()
|
|
314
|
+
const open = createMemo(() => selectSubmenuOpen(group.state(), id))
|
|
315
|
+
let trigger: HTMLElement | undefined
|
|
316
|
+
|
|
317
|
+
if (local.defaultOpen) group.dispatch(submenuRequested(id, true))
|
|
318
|
+
onCleanup(() => group.dispatch(submenuRequested(id, false)))
|
|
319
|
+
|
|
320
|
+
createEffect(
|
|
321
|
+
on(
|
|
322
|
+
open,
|
|
323
|
+
(value) => {
|
|
324
|
+
if (local.open === undefined) local.onOpenChange?.(value)
|
|
325
|
+
},
|
|
326
|
+
{ defer: true },
|
|
327
|
+
),
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
// Kobalte closes a submenu when focus leaves it, but ignores focus inside a top layer, and every menu is one so a modal
|
|
331
|
+
// dialog keeps it reachable. Focus moves go to the group instead, which waits for the next submenu or the pointer.
|
|
332
|
+
createEffect(() => {
|
|
333
|
+
if (!open()) return
|
|
334
|
+
makeEventListener(
|
|
335
|
+
document,
|
|
336
|
+
"focusin",
|
|
337
|
+
(event) => {
|
|
338
|
+
if (!(event.target instanceof Node) || !trigger) return
|
|
339
|
+
|
|
340
|
+
const left = !trigger.contains(event.target) && !!trigger.closest('[role="menu"]')?.contains(event.target)
|
|
341
|
+
group.dispatch(left ? SUBMENU_FOCUS_LEFT : SUBMENU_FOCUS_RETURNED)
|
|
342
|
+
},
|
|
343
|
+
{ capture: true },
|
|
344
|
+
)
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<SubmenuTriggerContext.Provider value={(element) => (trigger = element)}>
|
|
349
|
+
<DropdownMenu.Sub
|
|
350
|
+
{...rest}
|
|
351
|
+
open={local.open ?? open()}
|
|
352
|
+
onOpenChange={(next) => {
|
|
353
|
+
if (local.open !== undefined) return local.onOpenChange?.(next)
|
|
354
|
+
group.dispatch(submenuRequested(id, next))
|
|
355
|
+
}}
|
|
356
|
+
/>
|
|
357
|
+
</SubmenuTriggerContext.Provider>
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function MenuSubTrigger(props: ParentProps<MenuSubTriggerProps>) {
|
|
362
|
+
const ctx = useMenuContext()
|
|
363
|
+
const registerTrigger = useContext(SubmenuTriggerContext)
|
|
364
|
+
const [s, r] = splitProps(props, ["class", "classList", "children", "shortcut", "badge", "ref"])
|
|
365
|
+
|
|
366
|
+
const assignRef = (element: HTMLElement) => {
|
|
367
|
+
registerTrigger?.(element)
|
|
368
|
+
const ref = s.ref
|
|
369
|
+
|
|
370
|
+
if (ref instanceof Function) ref(element)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return (
|
|
374
|
+
<DropdownMenu.SubTrigger
|
|
375
|
+
{...r}
|
|
376
|
+
ref={assignRef}
|
|
377
|
+
data-component="menu-v2-item"
|
|
378
|
+
data-appearance={ctx.appearance()}
|
|
379
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
380
|
+
>
|
|
381
|
+
<ItemBody shortcut={s.shortcut} badge={s.badge} trailing={<ChevronRight />}>
|
|
382
|
+
{s.children}
|
|
383
|
+
</ItemBody>
|
|
384
|
+
</DropdownMenu.SubTrigger>
|
|
385
|
+
)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function MenuSubContent(props: ComponentProps<typeof DropdownMenu.SubContent>) {
|
|
389
|
+
const ctx = useMenuContext()
|
|
390
|
+
const [s, r] = splitProps(props, ["class", "classList", "children"])
|
|
391
|
+
|
|
392
|
+
return (
|
|
393
|
+
<DropdownMenu.SubContent
|
|
394
|
+
{...r}
|
|
395
|
+
data-kb-top-layer=""
|
|
396
|
+
data-component="menu-v2-content"
|
|
397
|
+
data-appearance={ctx.appearance()}
|
|
398
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
399
|
+
>
|
|
400
|
+
<SubmenuGroupProvider>{s.children}</SubmenuGroupProvider>
|
|
401
|
+
</DropdownMenu.SubContent>
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function MenuGroupLabel(props: ComponentProps<typeof DropdownMenu.GroupLabel>) {
|
|
406
|
+
const ctx = useMenuContext()
|
|
407
|
+
const [s, r] = splitProps(props, ["class", "classList"])
|
|
408
|
+
|
|
409
|
+
return (
|
|
410
|
+
<DropdownMenu.GroupLabel
|
|
411
|
+
{...r}
|
|
412
|
+
data-slot="menu-v2-group-label"
|
|
413
|
+
data-appearance={ctx.appearance()}
|
|
414
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
415
|
+
/>
|
|
416
|
+
)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function MenuSeparator(props: ComponentProps<typeof DropdownMenu.Separator>) {
|
|
420
|
+
const ctx = useMenuContext()
|
|
421
|
+
const [s, r] = splitProps(props, ["class", "classList"])
|
|
422
|
+
|
|
423
|
+
return (
|
|
424
|
+
<DropdownMenu.Separator
|
|
425
|
+
{...r}
|
|
426
|
+
data-slot="menu-v2-separator"
|
|
427
|
+
data-appearance={ctx.appearance()}
|
|
428
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
429
|
+
/>
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Kobalte drops `data-expanded` as the menu closes but returns focus to the trigger a task later, so for a frame the
|
|
434
|
+
// trigger is neither expanded nor focused. `data-closing` covers that gap for UI revealed by either.
|
|
435
|
+
function MenuTrigger<T extends ValidComponent = "button">(props: PolymorphicProps<T, DropdownMenuTriggerProps<T>>) {
|
|
436
|
+
const ctx = useMenuContext()
|
|
437
|
+
|
|
438
|
+
return <DropdownMenu.Trigger {...props} data-closing={ctx.state().status === "closing" ? "" : undefined} />
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function MenuContent(props: ComponentProps<typeof DropdownMenu.Content>) {
|
|
442
|
+
const ctx = useMenuContext()
|
|
443
|
+
const [s, r] = splitProps(props, ["class", "classList", "children", "onCloseAutoFocus", "onInteractOutside"])
|
|
444
|
+
|
|
445
|
+
// Kobalte's own rule for when an outside press keeps focus where it landed.
|
|
446
|
+
const onInteractOutside: NonNullable<typeof s.onInteractOutside> = (event) => {
|
|
447
|
+
s.onInteractOutside?.(event)
|
|
448
|
+
|
|
449
|
+
if (!event.defaultPrevented && (!ctx.modal() || event.detail.isContextMenu)) ctx.onOutsideInteract()
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// A menu returns focus to its trigger when it closes. Restore it without the ring after a pointer open and keep the
|
|
453
|
+
// ring for keyboard and programmatic opens.
|
|
454
|
+
const onCloseAutoFocus = (event: Event) => {
|
|
455
|
+
const restore = selectMenuRestoreTriggerWithoutRing(ctx.state())
|
|
456
|
+
ctx.onCloseAutoFocus()
|
|
457
|
+
s.onCloseAutoFocus?.(event)
|
|
458
|
+
|
|
459
|
+
if (event.defaultPrevented || !restore) return
|
|
460
|
+
event.preventDefault()
|
|
461
|
+
const active = document.activeElement
|
|
462
|
+
|
|
463
|
+
// An outside press already moved focus where it belongs.
|
|
464
|
+
if (active && active !== document.body && !active.closest('[role="menu"]')) return
|
|
465
|
+
const labelledby = event.target instanceof Element ? event.target.getAttribute("aria-labelledby") : null
|
|
466
|
+
const trigger = labelledby ? document.getElementById(labelledby) : null
|
|
467
|
+
trigger?.focus({ preventScroll: true, focusVisible: false })
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return (
|
|
471
|
+
<DropdownMenu.Content
|
|
472
|
+
{...r}
|
|
473
|
+
onCloseAutoFocus={onCloseAutoFocus}
|
|
474
|
+
onInteractOutside={onInteractOutside}
|
|
475
|
+
// A modal dialog hides what's outside it from assistive tech, and a non-modal menu is portaled outside it.
|
|
476
|
+
data-kb-top-layer=""
|
|
477
|
+
data-component="menu-v2-content"
|
|
478
|
+
data-appearance={ctx.appearance()}
|
|
479
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
480
|
+
>
|
|
481
|
+
<SubmenuGroupProvider>{s.children}</SubmenuGroupProvider>
|
|
482
|
+
</DropdownMenu.Content>
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export interface MenuProps extends ComponentProps<typeof DropdownMenu> {
|
|
487
|
+
appearance?: MenuAppearance
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function MenuRoot(props: MenuProps) {
|
|
491
|
+
const [local, rest] = splitProps(props, ["appearance", "children", "onOpenChange"])
|
|
492
|
+
const appearance = () => local.appearance ?? "compact"
|
|
493
|
+
const initialOpen = !!props.open || (props.open === undefined && !!props.defaultOpen)
|
|
494
|
+
const [menuState, setMenuState] = createSignal(createMenuState(initialOpen))
|
|
495
|
+
const dispatch = (event: MenuEvent) => setMenuState((state) => transitionMenu(state, event))
|
|
496
|
+
|
|
497
|
+
retainOpenGesture()
|
|
498
|
+
onCleanup(() => {
|
|
499
|
+
releaseOpenGesture()
|
|
500
|
+
dispatch(MENU_DISPOSED)
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
// Kobalte does not report a controlled open it did not ask for, so a controlled menu follows `open` itself.
|
|
504
|
+
createComputed(() => {
|
|
505
|
+
if (props.open === undefined) return
|
|
506
|
+
dispatch(openChangedEvent(props.open, openGesture()))
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
const context = {
|
|
510
|
+
appearance,
|
|
511
|
+
state: menuState,
|
|
512
|
+
modal: () => props.modal ?? true,
|
|
513
|
+
onOutsideInteract: () => dispatch(MENU_OUTSIDE_INTERACTED),
|
|
514
|
+
onCloseAutoFocus: () => dispatch(MENU_CLOSE_AUTOFOCUS),
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return (
|
|
518
|
+
<MenuAppearanceContext.Provider value={context}>
|
|
519
|
+
<DropdownMenu
|
|
520
|
+
{...rest}
|
|
521
|
+
onOpenChange={(open) => {
|
|
522
|
+
if (props.open === undefined) dispatch(openChangedEvent(open, openGesture()))
|
|
523
|
+
local.onOpenChange?.(open)
|
|
524
|
+
}}
|
|
525
|
+
>
|
|
526
|
+
{local.children}
|
|
527
|
+
</DropdownMenu>
|
|
528
|
+
</MenuAppearanceContext.Provider>
|
|
529
|
+
)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export interface MenuContextProps extends ComponentProps<typeof ContextMenu> {
|
|
533
|
+
appearance?: MenuAppearance
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function MenuContextRoot(props: MenuContextProps) {
|
|
537
|
+
const [local, rest] = splitProps(props, ["appearance", "children", "onOpenChange"])
|
|
538
|
+
const appearance = () => local.appearance ?? "compact"
|
|
539
|
+
const overlayFocus = createOverlayFocus()
|
|
540
|
+
|
|
541
|
+
return (
|
|
542
|
+
<MenuAppearanceContext.Provider
|
|
543
|
+
value={{ ...UNTRACKED_MENU, appearance, restoreFocus: (event) => overlayFocus.restore(event) }}
|
|
544
|
+
>
|
|
545
|
+
<ContextMenu
|
|
546
|
+
{...rest}
|
|
547
|
+
onOpenChange={(open) => {
|
|
548
|
+
overlayFocus.openChanged(open)
|
|
549
|
+
local.onOpenChange?.(open)
|
|
550
|
+
}}
|
|
551
|
+
>
|
|
552
|
+
{local.children}
|
|
553
|
+
</ContextMenu>
|
|
554
|
+
</MenuAppearanceContext.Provider>
|
|
555
|
+
)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function MenuContextContent(props: ComponentProps<typeof ContextMenu.Content>) {
|
|
559
|
+
const ctx = useMenuContext()
|
|
560
|
+
const [s, r] = splitProps(props, ["class", "classList", "children", "onCloseAutoFocus"])
|
|
561
|
+
|
|
562
|
+
return (
|
|
563
|
+
<ContextMenu.Content
|
|
564
|
+
{...r}
|
|
565
|
+
onCloseAutoFocus={(event) => {
|
|
566
|
+
s.onCloseAutoFocus?.(event)
|
|
567
|
+
ctx.restoreFocus?.(event)
|
|
568
|
+
}}
|
|
569
|
+
data-component="menu-v2-content"
|
|
570
|
+
data-appearance={ctx.appearance()}
|
|
571
|
+
classList={{ ...s.classList, [s.class ?? ""]: !!s.class }}
|
|
572
|
+
>
|
|
573
|
+
<SubmenuGroupProvider>{s.children}</SubmenuGroupProvider>
|
|
574
|
+
</ContextMenu.Content>
|
|
575
|
+
)
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const MenuContext = Object.assign(MenuContextRoot, {
|
|
579
|
+
Trigger: ContextMenu.Trigger,
|
|
580
|
+
Portal: ContextMenu.Portal,
|
|
581
|
+
Content: MenuContextContent,
|
|
582
|
+
})
|
|
583
|
+
|
|
584
|
+
export const Menu = Object.assign(MenuRoot, {
|
|
585
|
+
Trigger: MenuTrigger,
|
|
586
|
+
Portal: DropdownMenu.Portal,
|
|
587
|
+
Content: MenuContent,
|
|
588
|
+
Item: MenuItem,
|
|
589
|
+
ItemRow: MenuItemRow,
|
|
590
|
+
CheckboxItem: MenuCheckboxItem,
|
|
591
|
+
RadioGroup: DropdownMenu.RadioGroup,
|
|
592
|
+
RadioItem: MenuRadioItem,
|
|
593
|
+
Group: DropdownMenu.Group,
|
|
594
|
+
GroupLabel: MenuGroupLabel,
|
|
595
|
+
Separator: MenuSeparator,
|
|
596
|
+
Sub: MenuSub,
|
|
597
|
+
SubTrigger: MenuSubTrigger,
|
|
598
|
+
SubContent: MenuSubContent,
|
|
599
|
+
Context: MenuContext,
|
|
600
|
+
})
|