@eluan/core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -1
- package/dist/{action-popover-D6K9aVFk.cjs → action-popover-DrHKPGqw.cjs} +1 -1
- package/dist/{action-popover-BVJQBuky.js → action-popover-NkXDAHJT.js} +1 -1
- package/dist/action-popover.cjs +1 -1
- package/dist/action-popover.js +1 -1
- package/dist/{avatar-Co-k8KqV.cjs → avatar-B-t3ctR4.cjs} +1 -1
- package/dist/{avatar-CS5f1irF.js → avatar-kDEa0rjF.js} +1 -1
- package/dist/avatar.cjs +1 -1
- package/dist/avatar.js +1 -1
- package/dist/{badge-D9NYZFWH.js → badge-BLZ8V-KC.js} +10 -10
- package/dist/{badge-DXKWztL-.cjs → badge-D1A0Tc79.cjs} +1 -1
- package/dist/badge.cjs +1 -1
- package/dist/badge.js +1 -1
- package/dist/{banner-COlEFRuK.cjs → banner-CNdwDPqA.cjs} +1 -1
- package/dist/{banner-CyYFLZXw.js → banner-DzSp5WfQ.js} +9 -9
- package/dist/banner.cjs +1 -1
- package/dist/banner.js +1 -1
- package/dist/box-DG-tkaYi.cjs +1 -0
- package/dist/box-DKbNgGGG.js +17 -0
- package/dist/box.cjs +1 -0
- package/dist/box.d.ts +1 -0
- package/dist/box.js +5 -0
- package/dist/{breadcrumb-NWXeCH5q.cjs → breadcrumb-BuxXkm6O.cjs} +1 -1
- package/dist/{breadcrumb-Cm1nb9Xj.js → breadcrumb-C6qj-tDx.js} +1 -1
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.js +1 -1
- package/dist/button--_WI-fM6.cjs +1 -0
- package/dist/{button-ANAPDrvs.js → button-DNSNShUc.js} +28 -26
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/{calendar-BpBsomy5.js → calendar-BA2tSwZD.js} +6 -6
- package/dist/{calendar-7LX5YGGT.cjs → calendar-DS5821-k.cjs} +3 -3
- package/dist/calendar.cjs +1 -1
- package/dist/calendar.js +1 -1
- package/dist/{card-C88--zB4.cjs → card-BNdR5aDa.cjs} +1 -1
- package/dist/{card-BC_4C3ns.js → card-BSgN7WSe.js} +1 -1
- package/dist/card.cjs +1 -1
- package/dist/card.js +1 -1
- package/dist/{carousel-BfL7oy_q.cjs → carousel-4AERgboz.cjs} +1 -1
- package/dist/{carousel-DuP0hvF-.js → carousel-Bb7jpzep.js} +1 -1
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.js +1 -1
- package/dist/{checkbox-Bi0Kmuut.js → checkbox-CGUTGery.js} +1 -1
- package/dist/{checkbox-M8DmWKiC.cjs → checkbox-Cq9sHU_S.cjs} +1 -1
- package/dist/{checkbox-group-KBwPhjmW.cjs → checkbox-group-DGXZ4o2-.cjs} +1 -1
- package/dist/{checkbox-group-CQMEJnhD.js → checkbox-group-Tkio3IhK.js} +1 -1
- package/dist/checkbox-group.cjs +1 -1
- package/dist/checkbox-group.js +1 -1
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.js +1 -1
- package/dist/{command-BCl0seLL.cjs → command-D02vvta9.cjs} +1 -1
- package/dist/{command-Chs5VlBL.js → command-sUMAxm8S.js} +1 -1
- package/dist/command.cjs +1 -1
- package/dist/command.js +1 -1
- package/dist/components/box.d.ts +12 -0
- package/dist/components/grid.d.ts +35 -0
- package/dist/components/hover-card.d.ts +14 -2
- package/dist/components/icon.d.ts +26 -0
- package/dist/components/layout-shared.d.ts +307 -0
- package/dist/components/multi-select.d.ts +1 -1
- package/dist/components/navigation-drawer.d.ts +25 -5
- package/dist/components/row.d.ts +18 -0
- package/dist/components/stack.d.ts +14 -0
- package/dist/components/tone-shared.d.ts +39 -0
- package/dist/components/tooltip.d.ts +14 -2
- package/dist/components/typography.d.ts +22 -2
- package/dist/components/visually-hidden.d.ts +11 -0
- package/dist/{credit-card-input-DN-8vaFj.js → credit-card-input-9VPlzvDm.js} +1 -1
- package/dist/{credit-card-input-CUqA9CX3.cjs → credit-card-input-DppPJBne.cjs} +1 -1
- package/dist/credit-card-input.cjs +1 -1
- package/dist/credit-card-input.js +1 -1
- package/dist/{date-picker-ni8td8Ru.js → date-picker-M5hLx_1s.js} +2 -2
- package/dist/{date-picker-DGBsfZXx.cjs → date-picker-hE7cDg2B.cjs} +1 -1
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.js +1 -1
- package/dist/{datetime-picker-C1d63MaA.cjs → datetime-picker-BeRUPJ7s.cjs} +1 -1
- package/dist/{datetime-picker-DsnHYRK-.js → datetime-picker-CIqBZYMH.js} +3 -3
- package/dist/datetime-picker.cjs +1 -1
- package/dist/datetime-picker.js +1 -1
- package/dist/{decimal-input-yTk35W_5.js → decimal-input-Bg2BPKIr.js} +38 -38
- package/dist/decimal-input-CkTEjo2J.cjs +1 -0
- package/dist/decimal-input.cjs +1 -1
- package/dist/decimal-input.js +1 -1
- package/dist/{dialog-B8eWKqzS.js → dialog-Bsfviqvy.js} +2 -2
- package/dist/dialog-DRAoumvB.cjs +1 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.js +1 -1
- package/dist/{email-input-DFI4h_KN.cjs → email-input-CehmtNUq.cjs} +1 -1
- package/dist/{email-input-pX0hlYV3.js → email-input-DIiY9Q3S.js} +1 -1
- package/dist/email-input.cjs +1 -1
- package/dist/email-input.js +1 -1
- package/dist/{footer-DB0_-IwN.cjs → footer-fovIsy-0.cjs} +1 -1
- package/dist/{footer-B3KUIwXW.js → footer-jWaFq3qk.js} +9 -9
- package/dist/footer.cjs +1 -1
- package/dist/footer.js +1 -1
- package/dist/grid-BDz4Xs6M.cjs +1 -0
- package/dist/grid-BX5vZjDo.js +612 -0
- package/dist/grid.cjs +1 -0
- package/dist/grid.d.ts +1 -0
- package/dist/grid.js +5 -0
- package/dist/{header-CDOWlOAR.js → header-Dnf8AnIx.js} +2 -2
- package/dist/{header-CiZQY_7S.cjs → header-DzItWqW4.cjs} +1 -1
- package/dist/header.cjs +1 -1
- package/dist/header.js +1 -1
- package/dist/hover-card-C5KsTSZR.cjs +1 -0
- package/dist/hover-card-C_FCzE41.js +21 -0
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.js +1 -1
- package/dist/icon-BmLOodCQ.cjs +1 -0
- package/dist/icon-BwDfkIdR.js +153 -0
- package/dist/icon.cjs +1 -0
- package/dist/icon.d.ts +1 -0
- package/dist/icon.js +5 -0
- package/dist/index.cjs +10 -5
- package/dist/index.d.ts +6 -0
- package/dist/index.js +612 -541
- package/dist/{input-BrGJn-D9.cjs → input-BcjL2oxv.cjs} +1 -1
- package/dist/{input-Cccufiqn.js → input-CPb9yVU5.js} +8 -8
- package/dist/input-otp-BhJ3ERrY.cjs +1 -0
- package/dist/{input-otp-DmEGB1nu.js → input-otp-CTvJztkH.js} +32 -32
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.js +1 -1
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/layout-shared-B_1iX4Hj.js +319 -0
- package/dist/layout-shared-CsBZcT4V.cjs +1 -0
- package/dist/multi-select-CVxkWW29.js +85 -0
- package/dist/multi-select-DBFINH3F.cjs +1 -0
- package/dist/multi-select.cjs +1 -1
- package/dist/multi-select.js +1 -1
- package/dist/navigation-drawer-BCBFtLEq.cjs +1 -0
- package/dist/navigation-drawer-BMyHXhhX.js +198 -0
- package/dist/navigation-drawer.cjs +1 -1
- package/dist/navigation-drawer.js +1 -1
- package/dist/{number-input-vICbRc2y.js → number-input-Cm9YPBOX.js} +1 -1
- package/dist/{number-input-Bc7jUsu-.cjs → number-input-Dr9MbuRV.cjs} +1 -1
- package/dist/number-input.cjs +1 -1
- package/dist/number-input.js +1 -1
- package/dist/{pagination-DTWRjiOm.js → pagination-D2tjMpVU.js} +2 -2
- package/dist/{pagination-4IuE_APs.cjs → pagination-yKmFlFMR.cjs} +1 -1
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.js +1 -1
- package/dist/{password-input-BwnlHPbX.cjs → password-input-CmHubHuU.cjs} +1 -1
- package/dist/{password-input-B9V45d3Q.js → password-input-ljwdGCO6.js} +2 -2
- package/dist/password-input.cjs +1 -1
- package/dist/password-input.js +1 -1
- package/dist/{phone-input-BQjZj5jI.cjs → phone-input-B8VksCer.cjs} +1 -1
- package/dist/{phone-input-CSBpGHvI.js → phone-input-qTL6K8rT.js} +2 -2
- package/dist/phone-input.cjs +1 -1
- package/dist/phone-input.js +1 -1
- package/dist/progress-BpdmBGaX.cjs +1 -0
- package/dist/{progress-Dz_it5I-.js → progress-ChFf9bIq.js} +1 -1
- package/dist/progress.cjs +1 -1
- package/dist/progress.js +1 -1
- package/dist/providers/create-theme.d.ts +10 -1
- package/dist/providers/eluan-provider.d.ts +2 -1
- package/dist/providers/portal-container.d.ts +1 -1
- package/dist/{radio-group-C--1neiq.cjs → radio-group-9gozRouT.cjs} +1 -1
- package/dist/{radio-group-CNMPZx_2.js → radio-group-Bs9933bk.js} +6 -6
- package/dist/radio-group.cjs +1 -1
- package/dist/radio-group.js +1 -1
- package/dist/{rich-text-BZSyuYSo.js → rich-text-DImwK9hN.js} +1 -1
- package/dist/{rich-text-DerWxzdn.cjs → rich-text-DzHLeG7W.cjs} +1 -1
- package/dist/rich-text.cjs +1 -1
- package/dist/rich-text.js +1 -1
- package/dist/row-BYAk7G5d.js +37 -0
- package/dist/row-Bjn-GQAC.cjs +1 -0
- package/dist/row.cjs +1 -0
- package/dist/row.d.ts +1 -0
- package/dist/row.js +5 -0
- package/dist/{search-input-Dmmo-BEL.cjs → search-input-BKTjebg7.cjs} +1 -1
- package/dist/{search-input-bFNW6oiE.js → search-input-Dgr9kT1a.js} +1 -1
- package/dist/search-input.cjs +1 -1
- package/dist/search-input.js +1 -1
- package/dist/select-Cdh991T-.cjs +1 -0
- package/dist/{select-DDSYjKtj.js → select-Dp5AJ6I-.js} +15 -15
- package/dist/select.cjs +1 -1
- package/dist/select.js +1 -1
- package/dist/sheet-CkXjinUG.cjs +1 -0
- package/dist/{sheet-D5HWF66e.js → sheet-uiyHNKEw.js} +6 -6
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.js +1 -1
- package/dist/{slider-CZQBAXup.js → slider-BQmbh0Nl.js} +1 -1
- package/dist/{slider-DdEOapYP.cjs → slider-DK2yk-YK.cjs} +1 -1
- package/dist/slider.cjs +1 -1
- package/dist/slider.js +1 -1
- package/dist/stack-Ck1w2iJu.cjs +1 -0
- package/dist/stack-D2btWM1t.js +27 -0
- package/dist/stack.cjs +1 -0
- package/dist/stack.d.ts +1 -0
- package/dist/stack.js +5 -0
- package/dist/{stepper-D5nDwJUz.cjs → stepper-ByYKX7qw.cjs} +1 -1
- package/dist/{stepper-BtlKiHtd.js → stepper-Copsj87A.js} +4 -4
- package/dist/stepper.cjs +1 -1
- package/dist/stepper.js +1 -1
- package/dist/styles.css +935 -59
- package/dist/{switch-KzBijHMJ.cjs → switch-C2OPCq5Z.cjs} +1 -1
- package/dist/{switch-C7EBLT5H.js → switch-CXBWUZcq.js} +3 -3
- package/dist/switch.cjs +1 -1
- package/dist/switch.js +1 -1
- package/dist/{tabs-DztJ2iVc.cjs → tabs-D8p6Tr5i.cjs} +1 -1
- package/dist/{tabs-C9NKBmH0.js → tabs-TV4_2wi1.js} +9 -9
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.js +1 -1
- package/dist/{textarea-Dl-daLHR.cjs → textarea-BnpQmE74.cjs} +1 -1
- package/dist/{textarea-DXUk1b_-.js → textarea-CJRmnazN.js} +1 -1
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.js +1 -1
- package/dist/{time-input-BPoFvoeM.js → time-input-A603mEFQ.js} +38 -38
- package/dist/time-input-qxljhdEb.cjs +1 -0
- package/dist/time-input.cjs +1 -1
- package/dist/time-input.js +1 -1
- package/dist/{toggle-Dv1VZ5Le.js → toggle-Bx3q15Pu.js} +6 -6
- package/dist/{toggle-Bvh1v32T.cjs → toggle-Z3t4jPdv.cjs} +1 -1
- package/dist/{toggle-group-SyHMwO90.cjs → toggle-group-BZIW4wJp.cjs} +1 -1
- package/dist/{toggle-group-DE8BPZih.js → toggle-group-LaZmOMx_.js} +7 -7
- package/dist/toggle-group.cjs +1 -1
- package/dist/toggle-group.js +1 -1
- package/dist/toggle.cjs +1 -1
- package/dist/toggle.js +1 -1
- package/dist/tooltip-DZqn4wKl.js +23 -0
- package/dist/tooltip-faf1dIXp.cjs +1 -0
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.js +1 -1
- package/dist/{tree-view-CyeJR7cW.js → tree-view-DRmm6oL6.js} +23 -23
- package/dist/tree-view-DVQyRQDg.cjs +1 -0
- package/dist/tree-view.cjs +1 -1
- package/dist/tree-view.js +1 -1
- package/dist/visually-hidden-BQMRYGxP.js +14 -0
- package/dist/visually-hidden-DzxxOswl.cjs +1 -0
- package/dist/visually-hidden.cjs +1 -0
- package/dist/visually-hidden.d.ts +1 -0
- package/dist/visually-hidden.js +5 -0
- package/package.json +8 -8
- package/skills/eluan/DESIGN.md +409 -0
- package/skills/eluan/SKILL.md +166 -0
- package/skills/eluan/components/accordion.md +212 -0
- package/skills/eluan/components/action-popover.md +266 -0
- package/skills/eluan/components/aspect-ratio.md +169 -0
- package/skills/eluan/components/avatar.md +277 -0
- package/skills/eluan/components/badge.md +190 -0
- package/skills/eluan/components/banner.md +247 -0
- package/skills/eluan/components/box.md +166 -0
- package/skills/eluan/components/breadcrumb.md +240 -0
- package/skills/eluan/components/button.md +214 -0
- package/skills/eluan/components/calendar.md +192 -0
- package/skills/eluan/components/card.md +270 -0
- package/skills/eluan/components/carousel.md +274 -0
- package/skills/eluan/components/checkbox-group.md +228 -0
- package/skills/eluan/components/checkbox.md +226 -0
- package/skills/eluan/components/code-block.md +193 -0
- package/skills/eluan/components/collapsible.md +240 -0
- package/skills/eluan/components/command.md +359 -0
- package/skills/eluan/components/context-menu.md +296 -0
- package/skills/eluan/components/credit-card-input.md +217 -0
- package/skills/eluan/components/date-picker.md +255 -0
- package/skills/eluan/components/date-time-picker.md +196 -0
- package/skills/eluan/components/decimal-input.md +232 -0
- package/skills/eluan/components/dialog.md +322 -0
- package/skills/eluan/components/drawer.md +292 -0
- package/skills/eluan/components/dropdown-menu.md +450 -0
- package/skills/eluan/components/email-input.md +200 -0
- package/skills/eluan/components/fieldset.md +219 -0
- package/skills/eluan/components/file-input.md +249 -0
- package/skills/eluan/components/footer.md +290 -0
- package/skills/eluan/components/form-label.md +254 -0
- package/skills/eluan/components/grid.md +192 -0
- package/skills/eluan/components/header.md +242 -0
- package/skills/eluan/components/hover-card.md +215 -0
- package/skills/eluan/components/icon.md +161 -0
- package/skills/eluan/components/input-otp.md +227 -0
- package/skills/eluan/components/input.md +249 -0
- package/skills/eluan/components/kbd.md +216 -0
- package/skills/eluan/components/media.md +244 -0
- package/skills/eluan/components/menubar.md +300 -0
- package/skills/eluan/components/multi-select.md +221 -0
- package/skills/eluan/components/navigation-drawer.md +297 -0
- package/skills/eluan/components/navigation-menu.md +291 -0
- package/skills/eluan/components/number-input.md +190 -0
- package/skills/eluan/components/pagination.md +262 -0
- package/skills/eluan/components/password-input.md +218 -0
- package/skills/eluan/components/phone-input.md +205 -0
- package/skills/eluan/components/popover.md +250 -0
- package/skills/eluan/components/progress.md +185 -0
- package/skills/eluan/components/radio-group.md +232 -0
- package/skills/eluan/components/rich-text.md +195 -0
- package/skills/eluan/components/row.md +174 -0
- package/skills/eluan/components/scroll-area.md +203 -0
- package/skills/eluan/components/search-input.md +281 -0
- package/skills/eluan/components/segmented-control.md +201 -0
- package/skills/eluan/components/select.md +296 -0
- package/skills/eluan/components/separator.md +179 -0
- package/skills/eluan/components/sheet.md +326 -0
- package/skills/eluan/components/skeleton.md +202 -0
- package/skills/eluan/components/slider.md +195 -0
- package/skills/eluan/components/spinner.md +187 -0
- package/skills/eluan/components/stack.md +158 -0
- package/skills/eluan/components/stepper.md +236 -0
- package/skills/eluan/components/switch.md +218 -0
- package/skills/eluan/components/table.md +348 -0
- package/skills/eluan/components/tabs.md +277 -0
- package/skills/eluan/components/textarea.md +202 -0
- package/skills/eluan/components/time-input.md +181 -0
- package/skills/eluan/components/toast.md +251 -0
- package/skills/eluan/components/toggle-group.md +241 -0
- package/skills/eluan/components/toggle.md +198 -0
- package/skills/eluan/components/tooltip.md +222 -0
- package/skills/eluan/components/tree-view.md +213 -0
- package/skills/eluan/components/typography.md +207 -0
- package/skills/eluan/components/visually-hidden.md +132 -0
- package/skills/eluan/foundations/colour.md +252 -0
- package/skills/eluan/foundations/elevation.md +57 -0
- package/skills/eluan/foundations/iconography.md +70 -0
- package/skills/eluan/foundations/motion.md +60 -0
- package/skills/eluan/foundations/radius.md +61 -0
- package/skills/eluan/foundations/spacing.md +98 -0
- package/skills/eluan/foundations/theming.md +197 -0
- package/skills/eluan/foundations/typography.md +163 -0
- package/skills/eluan/patterns/empty-states.md +84 -0
- package/skills/eluan/patterns/feedback.md +95 -0
- package/skills/eluan/patterns/forms.md +138 -0
- package/skills/eluan/patterns/navigation.md +95 -0
- package/skills/eluan/patterns/page-layout.md +101 -0
- package/dist/button-Ny6OF8Un.cjs +0 -1
- package/dist/decimal-input-BLmifKF2.cjs +0 -1
- package/dist/dialog-DWYtFhZl.cjs +0 -1
- package/dist/hover-card-BN7Ew2Y1.js +0 -16
- package/dist/hover-card-Dft-08Ha.cjs +0 -1
- package/dist/input-otp-DcZ7wyjs.cjs +0 -1
- package/dist/multi-select-DPoOHWSC.js +0 -74
- package/dist/multi-select-fX5FXYEY.cjs +0 -1
- package/dist/navigation-drawer-BbeDYPhu.js +0 -171
- package/dist/navigation-drawer-DOOHfbY3.cjs +0 -1
- package/dist/progress-DpQjGEyn.cjs +0 -1
- package/dist/select-1Eb3NSrR.cjs +0 -1
- package/dist/sheet-7NP1LuHy.cjs +0 -1
- package/dist/time-input-DR2snTgB.cjs +0 -1
- package/dist/tooltip-BlCQKhUE.js +0 -18
- package/dist/tooltip-Cyu7fWYZ.cjs +0 -1
- package/dist/tree-view-CNvEc1TT.cjs +0 -1
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ToggleGroup
|
|
3
|
+
use_when: A row of related pressable tool options in a toolbar, pressing one (text alignment) or several (bold, italic, underline).
|
|
4
|
+
instead_of: SegmentedControl for a mode or filter of the same view; RadioGroup or CheckboxGroup for a form value; Toggle for a single on/off; Tabs to switch panels.
|
|
5
|
+
source: packages/core/src/components/toggle-group.tsx
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# ToggleGroup
|
|
9
|
+
|
|
10
|
+
## 1. Overview
|
|
11
|
+
|
|
12
|
+
ToggleGroup is a row of Toggle-style buttons that act as one control. With `type="single"` at most one item is pressed, like radio buttons; with `type="multiple"` any set of items can be pressed. It wraps Radix ToggleGroup, and items take their size from the group.
|
|
13
|
+
|
|
14
|
+
## 2. When to use
|
|
15
|
+
|
|
16
|
+
- Editor and canvas toolbars: Bold, Italic, Underline (`multiple`); Align left, Center, Right (`single`).
|
|
17
|
+
- Icon-only tool options that sit together, such as drawing tools or list and grid density.
|
|
18
|
+
- A few related on/off filters shown as pressable buttons (`multiple`).
|
|
19
|
+
|
|
20
|
+
### When not to use
|
|
21
|
+
|
|
22
|
+
- Exactly one of two to five text options that sets the mode or filter of a view (Day, Week, Month; List, Board) → use [SegmentedControl](./segmented-control.md). It always keeps one option selected and draws the options as one recessed track.
|
|
23
|
+
- One value in a form → use [RadioGroup](./radio-group.md) for a few options or [Select](./select.md) for many. ToggleGroup submits nothing.
|
|
24
|
+
- Several values in a form → use [CheckboxGroup](./checkbox-group.md) or [MultiSelect](./multi-select.md).
|
|
25
|
+
- A single on/off button → use [Toggle](./toggle.md).
|
|
26
|
+
- Switching between content panels → use [Tabs](./tabs.md).
|
|
27
|
+
|
|
28
|
+
## 3. Anatomy
|
|
29
|
+
|
|
30
|
+
1. **Group** (`ToggleGroup`): a flex row with a `--spacing-xs` gap between items. Carries `role="group"` and the shared `type`, `size` and `disabled`.
|
|
31
|
+
2. **Item** (`ToggleGroupItem`): a Toggle-style button with its own `value`. Transparent at rest; filled while pressed. Holds a short label, a Lucide icon, or both.
|
|
32
|
+
|
|
33
|
+
## 4. Variants
|
|
34
|
+
|
|
35
|
+
ToggleGroup has one look. Its `variant` prop accepts only `"default"`; the standalone Toggle's `outline` variant is deliberately not supported in a group.
|
|
36
|
+
|
|
37
|
+
## 5. Sizes
|
|
38
|
+
|
|
39
|
+
Set `size` on the group; every item inherits it. An item's own `size` overrides the group's.
|
|
40
|
+
|
|
41
|
+
| Size | Use in |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `default` | Toolbars next to default-size controls (`--size-lg` tall). |
|
|
44
|
+
| `sm` | Dense toolbars and filter rows (`--size-sm` tall, `--font-size-xs`). |
|
|
45
|
+
| `iconSm` | Icon-only items in compact toolbars (`--size-md` square). |
|
|
46
|
+
|
|
47
|
+
## 6. States
|
|
48
|
+
|
|
49
|
+
| State | Looks like | Notes |
|
|
50
|
+
| --- | --- | --- |
|
|
51
|
+
| Default | Transparent items; text and icons inherit the surrounding colour | |
|
|
52
|
+
| Hover | `--interactive-bg-hover` fill, `--interactive-fg` text | |
|
|
53
|
+
| Focus | 1px outline in `--focus-ring`, 1px offset | Never remove or restyle the focus ring. |
|
|
54
|
+
| Pressed | `--interactive-bg-selected` fill, `--interactive-fg-selected` text | `data-state="on"`. |
|
|
55
|
+
| Disabled | `--interactive-fg-disabled` text on a transparent background, no pointer events | Set `disabled` on the group for all items or on one item. A standalone Toggle fills its disabled background with `--interactive-bg-disabled`, so the two won't match side by side. |
|
|
56
|
+
|
|
57
|
+
## 7. Content guidelines
|
|
58
|
+
|
|
59
|
+
- Name the group by what it sets: "Text alignment", "Text formatting".
|
|
60
|
+
- Name each item by its feature, not an action: "Bold", "Align left". The pressed state is announced for you.
|
|
61
|
+
- Keep item labels to one word, or use icons with an `aria-label` per item. Don't mix icon-only and text items in one group.
|
|
62
|
+
|
|
63
|
+
| Do | Don't |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| Align left | L |
|
|
66
|
+
| Bold | Toggle bold |
|
|
67
|
+
|
|
68
|
+
## 8. Rules
|
|
69
|
+
|
|
70
|
+
1. Always set `type`: `"single"` or `"multiple"`. Radix requires it, and it decides whether `value` is a `string` or a `string[]`.
|
|
71
|
+
2. Give the group an `aria-label` naming the set, and every icon-only item its own `aria-label`.
|
|
72
|
+
3. In `type="single"` the user can unpress the pressed item, which sends `""`. When one option must always stay selected, ignore the empty value: `onValueChange={(next) => next && setAlign(next)}`.
|
|
73
|
+
4. Set `size` once on the group, not on every item.
|
|
74
|
+
5. Don't pass `variant="outline"`; groups only support `"default"`.
|
|
75
|
+
6. Put the group in a flex row you own (see Behaviour) to control its alignment.
|
|
76
|
+
7. Never pass `className` or `style`; they're dropped.
|
|
77
|
+
|
|
78
|
+
## 9. Dos and don'ts
|
|
79
|
+
|
|
80
|
+
**Do:** name the group and keep one alignment selected.
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
<ToggleGroup
|
|
84
|
+
type="single"
|
|
85
|
+
aria-label="Text alignment"
|
|
86
|
+
value={align}
|
|
87
|
+
onValueChange={(next: string) => next && setAlign(next)}
|
|
88
|
+
>
|
|
89
|
+
<ToggleGroupItem value="left" aria-label="Align left">
|
|
90
|
+
<AlignLeft aria-hidden="true" style={{ width: "var(--size-xxs)", height: "var(--size-xxs)" }} />
|
|
91
|
+
</ToggleGroupItem>
|
|
92
|
+
<ToggleGroupItem value="center" aria-label="Align center">
|
|
93
|
+
<AlignCenter aria-hidden="true" style={{ width: "var(--size-xxs)", height: "var(--size-xxs)" }} />
|
|
94
|
+
</ToggleGroupItem>
|
|
95
|
+
</ToggleGroup>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Don't:** leave out `type`, labels, or the empty-value guard.
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
<ToggleGroup value={align} onValueChange={setAlign}>
|
|
102
|
+
<ToggleGroupItem value="left"><AlignLeft size={16} /></ToggleGroupItem>
|
|
103
|
+
<ToggleGroupItem value="center"><AlignCenter size={16} /></ToggleGroupItem>
|
|
104
|
+
</ToggleGroup>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Do:** use SegmentedControl for the mode of a view.
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
<SegmentedControl value={range} onValueChange={setRange}>
|
|
111
|
+
<SegmentedControlItem value="day">Day</SegmentedControlItem>
|
|
112
|
+
<SegmentedControlItem value="week">Week</SegmentedControlItem>
|
|
113
|
+
<SegmentedControlItem value="month">Month</SegmentedControlItem>
|
|
114
|
+
</SegmentedControl>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Don't:** build a calendar range switcher from a ToggleGroup.
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
<ToggleGroup type="single" value={range} onValueChange={setRange}>
|
|
121
|
+
<ToggleGroupItem value="day">Day</ToggleGroupItem>
|
|
122
|
+
<ToggleGroupItem value="week">Week</ToggleGroupItem>
|
|
123
|
+
<ToggleGroupItem value="month">Month</ToggleGroupItem>
|
|
124
|
+
</ToggleGroup>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 10. Accessibility
|
|
128
|
+
|
|
129
|
+
- Role: the group is a `group`. With `type="single"`, items are `radio`s with `aria-checked`; with `type="multiple"`, items are `button`s with `aria-pressed`.
|
|
130
|
+
- Label: `aria-label` (or `aria-labelledby`) on the group; text content or `aria-label` on each item.
|
|
131
|
+
- Keyboard: Tab moves into the group, onto the pressed item if there is one, and Tab again leaves it. Arrow keys move focus between items and wrap at the ends. Enter and Space press the focused item. Unlike RadioGroup, arrows only move focus; they don't change the value.
|
|
132
|
+
- Focus: visible outline on the focused item. Disabled items use the native `disabled` attribute and are skipped.
|
|
133
|
+
- Contrast: handled by the theme. Don't override colours.
|
|
134
|
+
|
|
135
|
+
## 11. Behaviour
|
|
136
|
+
|
|
137
|
+
- Layout: the group is a block-level flex row that centres its items. On its own line it stretches to the container's width with the items in the middle. Place it inside a flex row you own to keep it at its content width.
|
|
138
|
+
- Orientation: items always lay out in a row. Leave `orientation` unset.
|
|
139
|
+
- Overflow and truncation: items don't wrap or truncate. Keep groups to a handful of short items.
|
|
140
|
+
- Forms: ToggleGroup submits nothing. Keep its value in your own state.
|
|
141
|
+
- Motion: colour transitions over 150ms. Don't add your own.
|
|
142
|
+
|
|
143
|
+
## 12. API
|
|
144
|
+
|
|
145
|
+
<!-- api:start -->
|
|
146
|
+
### ToggleGroup
|
|
147
|
+
|
|
148
|
+
| Prop | Type | Default | Description |
|
|
149
|
+
| --- | --- | --- | --- |
|
|
150
|
+
| `type` | `"single" \| "multiple"` | | Required. One pressed item at most, or any set. |
|
|
151
|
+
| `value` | `string` (single) \| `string[]` (multiple) | | Controlled value. `""` or `[]` means nothing pressed. |
|
|
152
|
+
| `defaultValue` | `string` (single) \| `string[]` (multiple) | | Initial value when uncontrolled. |
|
|
153
|
+
| `onValueChange` | `(value: string) => void` (single) \| `(value: string[]) => void` (multiple) | | Called with the new value. |
|
|
154
|
+
| `size` | `"default" \| "sm" \| "iconSm"` | `"default"` | Size inherited by every item. |
|
|
155
|
+
| `variant` | `"default"` | `"default"` | The only supported value. |
|
|
156
|
+
| `disabled` | `boolean` | `false` | Disables every item. |
|
|
157
|
+
| `loop` | `boolean` | `true` | Arrow keys wrap from the last item to the first. |
|
|
158
|
+
| `rovingFocus` | `boolean` | `true` | Arrow-key focus movement; `false` puts every item in the Tab order. |
|
|
159
|
+
| `...props` | Radix `ToggleGroup.Root` props without `className`, `style` | | `aria-label`, `aria-labelledby`, `dir`. |
|
|
160
|
+
|
|
161
|
+
### ToggleGroupItem
|
|
162
|
+
|
|
163
|
+
| Prop | Type | Default | Description |
|
|
164
|
+
| --- | --- | --- | --- |
|
|
165
|
+
| `value` | `string` | | Required. The value this item adds to the group's value. |
|
|
166
|
+
| `size` | `"default" \| "sm" \| "iconSm"` | the group's `size` | Per-item override. |
|
|
167
|
+
| `variant` | `"default"` | the group's `variant` | The only supported value. |
|
|
168
|
+
| `disabled` | `boolean` | | Disables this item. |
|
|
169
|
+
| `...props` | Radix `ToggleGroup.Item` props without `className`, `style` | | `aria-label`, `id`. |
|
|
170
|
+
<!-- api:end -->
|
|
171
|
+
|
|
172
|
+
`className` and `style` are omitted from both parts; Eluan components are styling-closed.
|
|
173
|
+
|
|
174
|
+
## 13. Examples
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
import { useState } from "react";
|
|
178
|
+
import { ToggleGroup, ToggleGroupItem } from "@eluan/core";
|
|
179
|
+
import { AlignCenter, AlignLeft, AlignRight, Bold, Italic, Underline } from "lucide-react";
|
|
180
|
+
|
|
181
|
+
const iconStyle = { width: "var(--size-xxs)", height: "var(--size-xxs)" };
|
|
182
|
+
|
|
183
|
+
export function EditorToolbar() {
|
|
184
|
+
const [marks, setMarks] = useState<string[]>(["bold"]);
|
|
185
|
+
const [align, setAlign] = useState("left");
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div
|
|
189
|
+
style={{
|
|
190
|
+
display: "flex",
|
|
191
|
+
alignItems: "center",
|
|
192
|
+
gap: "var(--spacing-md)",
|
|
193
|
+
padding: "var(--spacing-xs)",
|
|
194
|
+
backgroundColor: "var(--container-bg-alt)",
|
|
195
|
+
}}
|
|
196
|
+
>
|
|
197
|
+
<ToggleGroup type="multiple" size="iconSm" aria-label="Text formatting" value={marks} onValueChange={setMarks}>
|
|
198
|
+
<ToggleGroupItem value="bold" aria-label="Bold">
|
|
199
|
+
<Bold aria-hidden="true" style={iconStyle} />
|
|
200
|
+
</ToggleGroupItem>
|
|
201
|
+
<ToggleGroupItem value="italic" aria-label="Italic">
|
|
202
|
+
<Italic aria-hidden="true" style={iconStyle} />
|
|
203
|
+
</ToggleGroupItem>
|
|
204
|
+
<ToggleGroupItem value="underline" aria-label="Underline">
|
|
205
|
+
<Underline aria-hidden="true" style={iconStyle} />
|
|
206
|
+
</ToggleGroupItem>
|
|
207
|
+
</ToggleGroup>
|
|
208
|
+
<ToggleGroup
|
|
209
|
+
type="single"
|
|
210
|
+
size="iconSm"
|
|
211
|
+
aria-label="Text alignment"
|
|
212
|
+
value={align}
|
|
213
|
+
onValueChange={(next: string) => next && setAlign(next)}
|
|
214
|
+
>
|
|
215
|
+
<ToggleGroupItem value="left" aria-label="Align left">
|
|
216
|
+
<AlignLeft aria-hidden="true" style={iconStyle} />
|
|
217
|
+
</ToggleGroupItem>
|
|
218
|
+
<ToggleGroupItem value="center" aria-label="Align center">
|
|
219
|
+
<AlignCenter aria-hidden="true" style={iconStyle} />
|
|
220
|
+
</ToggleGroupItem>
|
|
221
|
+
<ToggleGroupItem value="right" aria-label="Align right">
|
|
222
|
+
<AlignRight aria-hidden="true" style={iconStyle} />
|
|
223
|
+
</ToggleGroupItem>
|
|
224
|
+
</ToggleGroup>
|
|
225
|
+
</div>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## 14. Related components
|
|
231
|
+
|
|
232
|
+
- [Toggle](./toggle.md): one pressable on/off button.
|
|
233
|
+
- [SegmentedControl](./segmented-control.md): exactly one mode or filter of a view, always selected.
|
|
234
|
+
- [RadioGroup](./radio-group.md): one value in a form, with labels.
|
|
235
|
+
- [CheckboxGroup](./checkbox-group.md): several values in a form, with labels.
|
|
236
|
+
- [Tabs](./tabs.md): switches content panels.
|
|
237
|
+
- [Button](./button.md): a one-off action in the same toolbar.
|
|
238
|
+
|
|
239
|
+
## 15. Common agent mistakes
|
|
240
|
+
|
|
241
|
+
_Filled from evals._
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Toggle
|
|
3
|
+
use_when: A single button that stays pressed to show a state of the content or view, such as Bold, Mute or Show grid.
|
|
4
|
+
instead_of: Switch for an on/off setting; Button for a one-off action; ToggleGroup for a set of related toggles; Checkbox for a yes/no submitted with a form.
|
|
5
|
+
source: packages/core/src/components/toggle.tsx
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Toggle
|
|
9
|
+
|
|
10
|
+
## 1. Overview
|
|
11
|
+
|
|
12
|
+
Toggle is a two-state button: pressed or not pressed. It wraps Radix Toggle, renders a native `<button type="button">` with `aria-pressed`, and fills with the selected colours while pressed. It comes in two variants and three sizes, including a square icon-only size.
|
|
13
|
+
|
|
14
|
+
## 2. When to use
|
|
15
|
+
|
|
16
|
+
- Turning a formatting or view state on and off from a toolbar: Bold, Show grid, Mute, Pin.
|
|
17
|
+
- An icon-only on/off control that sits among other toolbar buttons.
|
|
18
|
+
- A single on/off filter chip above a list ("Only mine").
|
|
19
|
+
|
|
20
|
+
### When not to use
|
|
21
|
+
|
|
22
|
+
- A setting that applies immediately and reads as a preference (Email notifications, Dark mode) → use [Switch](./switch.md). It renders a `switch` role with a sliding thumb and pairs with a label.
|
|
23
|
+
- A one-off action that doesn't stay pressed (Save, Refresh, Export) → use [Button](./button.md).
|
|
24
|
+
- Several related toggles (Bold, Italic, Underline; Left, Center, Right) → use [ToggleGroup](./toggle-group.md). It adds a `group` role, arrow-key navigation and single or multiple selection.
|
|
25
|
+
- One choice from a few modes or filters → use [SegmentedControl](./segmented-control.md).
|
|
26
|
+
- A yes/no answer submitted with a form (Accept terms) → use [Checkbox](./checkbox.md). Toggle has no form value.
|
|
27
|
+
|
|
28
|
+
## 3. Anatomy
|
|
29
|
+
|
|
30
|
+
1. **Container**: the `<button>`. Transparent at rest, `--curves-md` corners, carries the pressed fill and focus outline.
|
|
31
|
+
2. **Content**: a text label, a Lucide icon, or both. Content sits in a row with a `--spacing-sm` gap.
|
|
32
|
+
|
|
33
|
+
## 4. Variants
|
|
34
|
+
|
|
35
|
+
| Variant | Use for |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `default` | Toggles in a toolbar, where the surrounding bar gives them an edge. Transparent at rest. |
|
|
38
|
+
| `outline` | A toggle that stands alone and needs a visible edge at rest. Adds a 1px `--interactive-border-alt` border. |
|
|
39
|
+
|
|
40
|
+
## 5. Sizes
|
|
41
|
+
|
|
42
|
+
| Size | Use in |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `default` | Toolbars next to default-size controls (`--size-lg` tall, at least as wide as it is tall). |
|
|
45
|
+
| `sm` | Dense toolbars and inline filter chips (`--size-sm` tall, `--font-size-xs`). |
|
|
46
|
+
| `iconSm` | Icon-only toggles in compact toolbars (`--size-md` square, no padding). |
|
|
47
|
+
|
|
48
|
+
For an icon-only toggle at default height, use `default`: its minimum width equals its height, so a lone icon renders square.
|
|
49
|
+
|
|
50
|
+
## 6. States
|
|
51
|
+
|
|
52
|
+
| State | Looks like | Notes |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| Default | Transparent; text and icon inherit the surrounding colour | |
|
|
55
|
+
| Hover | `--interactive-bg-hover` fill, `--interactive-fg` text | |
|
|
56
|
+
| Focus | 1px outline in `--focus-ring`, 1px offset | Never remove or restyle the focus ring. |
|
|
57
|
+
| Pressed | `--interactive-bg-selected` fill, `--interactive-fg-selected` text | `data-state="on"` and `aria-pressed="true"`. |
|
|
58
|
+
| Disabled | `--interactive-bg-disabled` fill, `--interactive-fg-disabled` text, no pointer events | A disabled ToggleGroupItem keeps a transparent background and only dims its text, so a disabled Toggle next to a disabled ToggleGroupItem won't match. |
|
|
59
|
+
|
|
60
|
+
## 7. Content guidelines
|
|
61
|
+
|
|
62
|
+
- Name the feature, not the action: "Bold", "Show grid", "Mute". The pressed state is announced from `aria-pressed`, so "Toggle bold" or "Make bold" repeats it.
|
|
63
|
+
- Keep the label and icon the same in both states. Don't swap "Mute" for "Unmute" on press.
|
|
64
|
+
- Use one or two words, in sentence case.
|
|
65
|
+
|
|
66
|
+
| Do | Don't |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| Bold | Toggle bold |
|
|
69
|
+
| Show grid | Grid on/off |
|
|
70
|
+
| Mute | Click to mute |
|
|
71
|
+
|
|
72
|
+
## 8. Rules
|
|
73
|
+
|
|
74
|
+
1. Give icon-only toggles an `aria-label`. Mark the icon `aria-hidden="true"`.
|
|
75
|
+
2. Keep the label constant across pressed and unpressed. State comes from `aria-pressed`.
|
|
76
|
+
3. Control the state with `pressed` and `onPressedChange`, or set `defaultPressed` for uncontrolled use. Don't track it with `onClick`.
|
|
77
|
+
4. Put two or more related toggles in a [ToggleGroup](./toggle-group.md), not a row of separate Toggles.
|
|
78
|
+
5. Size icons with `--size-xxs` on the icon's own style. Never use Lucide's `size` prop.
|
|
79
|
+
6. Never pass `className` or `style`; they're dropped. Put layout on a wrapper.
|
|
80
|
+
|
|
81
|
+
## 9. Dos and don'ts
|
|
82
|
+
|
|
83
|
+
**Do:** name an icon-only toggle and control it with `pressed`.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<Toggle aria-label="Show grid" pressed={showGrid} onPressedChange={setShowGrid}>
|
|
87
|
+
<Grid3x3 aria-hidden="true" style={{ width: "var(--size-xxs)", height: "var(--size-xxs)" }} />
|
|
88
|
+
</Toggle>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Don't:** leave it unnamed, size the icon in px, or track state with `onClick`.
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
<Toggle onClick={() => setShowGrid(!showGrid)}>
|
|
95
|
+
<Grid3x3 size={16} />
|
|
96
|
+
</Toggle>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Do:** use a Switch for a setting.
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
<div style={{ display: "flex", alignItems: "center", gap: "var(--spacing-sm)" }}>
|
|
103
|
+
<Switch id="digest" checked={digest} onCheckedChange={setDigest} />
|
|
104
|
+
<Label htmlFor="digest">Weekly digest email</Label>
|
|
105
|
+
</div>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Don't:** use a Toggle as a settings switch.
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<Toggle variant="outline" pressed={digest} onPressedChange={setDigest}>
|
|
112
|
+
Weekly digest email
|
|
113
|
+
</Toggle>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## 10. Accessibility
|
|
117
|
+
|
|
118
|
+
- Role: `button` (native `<button type="button">`) with `aria-pressed="true"` or `"false"`.
|
|
119
|
+
- Label: the text content; `aria-label` for icon-only toggles.
|
|
120
|
+
- Keyboard: Enter and Space toggle. Tab moves focus in DOM order.
|
|
121
|
+
- Focus: visible outline on `:focus-visible`. Disabled toggles use the native `disabled` attribute, so Tab skips them.
|
|
122
|
+
- Contrast: handled by the theme. Don't override colours.
|
|
123
|
+
|
|
124
|
+
## 11. Behaviour
|
|
125
|
+
|
|
126
|
+
- Responsive: Toggle sizes to its content. Wrap it in your own layout for toolbars.
|
|
127
|
+
- Overflow and truncation: Toggle doesn't truncate. Keep labels to one or two words.
|
|
128
|
+
- Forms: Toggle submits nothing. Keep its state in your own state and send it yourself.
|
|
129
|
+
- Motion: colour transitions over 150ms. Don't add your own.
|
|
130
|
+
|
|
131
|
+
## 12. API
|
|
132
|
+
|
|
133
|
+
<!-- api:start -->
|
|
134
|
+
| Prop | Type | Default | Description |
|
|
135
|
+
| --- | --- | --- | --- |
|
|
136
|
+
| `variant` | `"default" \| "outline"` | `"default"` | Visual style. |
|
|
137
|
+
| `size` | `"default" \| "sm" \| "iconSm"` | `"default"` | Height and padding; `iconSm` is square for icon-only toggles. |
|
|
138
|
+
| `pressed` | `boolean` | | Controlled pressed state. |
|
|
139
|
+
| `defaultPressed` | `boolean` | `false` | Initial pressed state when uncontrolled. |
|
|
140
|
+
| `onPressedChange` | `(pressed: boolean) => void` | | Called with the new state. |
|
|
141
|
+
| `disabled` | `boolean` | `false` | Disables the button. |
|
|
142
|
+
| `...props` | Radix `Toggle.Root` props without `className`, `style` | | Native button attributes: `aria-label`, `id`, `onFocus`. |
|
|
143
|
+
<!-- api:end -->
|
|
144
|
+
|
|
145
|
+
`className` and `style` are omitted; Eluan components are styling-closed.
|
|
146
|
+
|
|
147
|
+
## 13. Examples
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import { useState } from "react";
|
|
151
|
+
import { Toggle } from "@eluan/core";
|
|
152
|
+
import { Grid3x3, Magnet } from "lucide-react";
|
|
153
|
+
|
|
154
|
+
const iconStyle = { width: "var(--size-xxs)", height: "var(--size-xxs)" };
|
|
155
|
+
|
|
156
|
+
export function CanvasViewOptions() {
|
|
157
|
+
const [showGrid, setShowGrid] = useState(true);
|
|
158
|
+
const [snapToGrid, setSnapToGrid] = useState(false);
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<div
|
|
162
|
+
style={{
|
|
163
|
+
display: "flex",
|
|
164
|
+
alignItems: "center",
|
|
165
|
+
gap: "var(--spacing-xs)",
|
|
166
|
+
padding: "var(--spacing-xs)",
|
|
167
|
+
backgroundColor: "var(--container-bg-alt)",
|
|
168
|
+
}}
|
|
169
|
+
>
|
|
170
|
+
<Toggle size="sm" pressed={showGrid} onPressedChange={setShowGrid}>
|
|
171
|
+
<Grid3x3 aria-hidden="true" style={iconStyle} />
|
|
172
|
+
Show grid
|
|
173
|
+
</Toggle>
|
|
174
|
+
<Toggle
|
|
175
|
+
size="iconSm"
|
|
176
|
+
aria-label="Snap to grid"
|
|
177
|
+
pressed={snapToGrid}
|
|
178
|
+
onPressedChange={setSnapToGrid}
|
|
179
|
+
disabled={!showGrid}
|
|
180
|
+
>
|
|
181
|
+
<Magnet aria-hidden="true" style={iconStyle} />
|
|
182
|
+
</Toggle>
|
|
183
|
+
</div>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## 14. Related components
|
|
189
|
+
|
|
190
|
+
- [ToggleGroup](./toggle-group.md): a set of related toggles with group semantics.
|
|
191
|
+
- [Switch](./switch.md): an on/off setting that applies immediately.
|
|
192
|
+
- [Button](./button.md): a one-off action that doesn't stay pressed.
|
|
193
|
+
- [SegmentedControl](./segmented-control.md): one mode from a few options.
|
|
194
|
+
- [Checkbox](./checkbox.md): a yes/no that submits with a form.
|
|
195
|
+
|
|
196
|
+
## 15. Common agent mistakes
|
|
197
|
+
|
|
198
|
+
_Filled from evals._
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Tooltip
|
|
3
|
+
use_when: A short text hint appears when the user hovers or focuses a control, such as the label and shortcut of an icon-only button.
|
|
4
|
+
instead_of: aria-label for naming a control (a tooltip only describes); Popover or HoverCard for rich or interactive content; inline helper text or FormMessage for anything essential.
|
|
5
|
+
source: packages/core/src/components/tooltip.tsx
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Tooltip
|
|
9
|
+
|
|
10
|
+
## 1. Overview
|
|
11
|
+
|
|
12
|
+
Tooltip shows a short text hint next to a control on pointer hover or keyboard focus. It's built on Radix Tooltip and portals a small panel. Every Tooltip needs a `TooltipProvider` above it; EluanProvider doesn't include one.
|
|
13
|
+
|
|
14
|
+
## 2. When to use
|
|
15
|
+
|
|
16
|
+
- Showing the visible label of an icon-only Button in a toolbar (the Button still needs its own `aria-label`).
|
|
17
|
+
- Showing a keyboard shortcut for a control: "Bold ⌘B".
|
|
18
|
+
- Expanding an abbreviation or a truncated label on a focusable element.
|
|
19
|
+
|
|
20
|
+
### When not to use
|
|
21
|
+
|
|
22
|
+
- Naming an icon-only control → set `aria-label` on the [Button](./button.md); add a tooltip on top if you want a visible label.
|
|
23
|
+
- Content with links, buttons or formatting → use [Popover](./popover.md).
|
|
24
|
+
- A preview of a linked item → use [HoverCard](./hover-card.md).
|
|
25
|
+
- Instructions, errors or anything the user must read → show it inline with FormDescription or FormMessage from [Label](./form-label.md). See `../patterns/forms.md`.
|
|
26
|
+
- Telling the user something happened → use [Toast](./toast.md).
|
|
27
|
+
|
|
28
|
+
## 3. Anatomy
|
|
29
|
+
|
|
30
|
+
1. **TooltipProvider**: wraps your app once. Sets the shared open delay (200ms in Eluan) and lets the user move between tooltips without waiting again.
|
|
31
|
+
2. **Tooltip**: the root for one tooltip. Holds its open state.
|
|
32
|
+
3. **TooltipTrigger**: the element the tooltip describes. Wrap a focusable element, usually a Button, with `asChild`.
|
|
33
|
+
4. **TooltipContent**: the floating label. Renders in a portal with `--tooltip-bg`, a `--container-border` border, `--curves-md` corners, `--container-fg` text in `--font-size-sm`, and `--spacing-xs` by `--spacing-sm` padding.
|
|
34
|
+
|
|
35
|
+
## 4. Variants
|
|
36
|
+
|
|
37
|
+
No variants. The tooltip's look is fixed by the theme.
|
|
38
|
+
|
|
39
|
+
## 5. Sizes
|
|
40
|
+
|
|
41
|
+
No size prop. The panel fits its text.
|
|
42
|
+
|
|
43
|
+
## 6. States
|
|
44
|
+
|
|
45
|
+
| State | Looks like | Notes |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| Closed | Only the trigger renders | |
|
|
48
|
+
| Open | Label floats beside the trigger | Opens after the provider's delay on hover, or at once on keyboard focus. Closes when the pointer leaves, focus moves away, the trigger is clicked or Escape is pressed. |
|
|
49
|
+
| Focus | The trigger's own focus style | Never remove or restyle the focus ring. |
|
|
50
|
+
|
|
51
|
+
## 7. Content guidelines
|
|
52
|
+
|
|
53
|
+
- A few words. No full sentences, no trailing period.
|
|
54
|
+
- For an icon button, use the same words as its `aria-label`, and add the shortcut with [Kbd](./kbd.md).
|
|
55
|
+
- Plain text only. No links or buttons.
|
|
56
|
+
- Sentence case.
|
|
57
|
+
|
|
58
|
+
| Do | Don't |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| Bold | This button makes your selected text bold. |
|
|
61
|
+
| Archive conversation | Click here to archive |
|
|
62
|
+
| Copy link | Copy |
|
|
63
|
+
|
|
64
|
+
## 8. Rules
|
|
65
|
+
|
|
66
|
+
1. Wrap your app (or the region using tooltips) in one `TooltipProvider`. A Tooltip outside a provider throws.
|
|
67
|
+
2. Use `TooltipTrigger asChild` around a focusable element. A `span` or `div` trigger can't be reached by keyboard.
|
|
68
|
+
3. A tooltip describes; it doesn't name. Icon-only Buttons still need an `aria-label`.
|
|
69
|
+
4. Never put essential information in a tooltip. It never opens on touch, and screen readers treat it as a description.
|
|
70
|
+
5. Don't attach a tooltip to a disabled Button. Disabled Buttons take no pointer events or focus, so the tooltip never opens. Explain why the action is unavailable in visible text instead.
|
|
71
|
+
6. Never pass `className` or `style` to TooltipContent; they're dropped.
|
|
72
|
+
|
|
73
|
+
## 9. Dos and don'ts
|
|
74
|
+
|
|
75
|
+
**Do:** name the button and add the tooltip as a visible hint.
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
<Tooltip>
|
|
79
|
+
<TooltipTrigger asChild>
|
|
80
|
+
<Button type="button" variant="ghost" size="icon" aria-label="Archive conversation">
|
|
81
|
+
<Archive aria-hidden="true" style={{ width: "var(--size-xxs)", height: "var(--size-xxs)" }} />
|
|
82
|
+
</Button>
|
|
83
|
+
</TooltipTrigger>
|
|
84
|
+
<TooltipContent>Archive conversation</TooltipContent>
|
|
85
|
+
</Tooltip>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Don't:** rely on the tooltip to name an icon-only button.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
<Tooltip>
|
|
92
|
+
<TooltipTrigger asChild>
|
|
93
|
+
<Button size="icon">
|
|
94
|
+
<Archive />
|
|
95
|
+
</Button>
|
|
96
|
+
</TooltipTrigger>
|
|
97
|
+
<TooltipContent>Archive conversation</TooltipContent>
|
|
98
|
+
</Tooltip>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Do:** put instructions where everyone can read them.
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
<Label htmlFor="api-key-name">Key name</Label>
|
|
105
|
+
<Input id="api-key-name" aria-describedby="api-key-name-hint" />
|
|
106
|
+
<FormDescription id="api-key-name-hint">Only you can see this name.</FormDescription>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Don't:** hide field instructions or interactive content in a tooltip.
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
<TooltipContent>
|
|
113
|
+
Only you can see this name. <a href="/docs/keys">Learn more</a>
|
|
114
|
+
</TooltipContent>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 10. Accessibility
|
|
118
|
+
|
|
119
|
+
- Role: `tooltip`, on a visually hidden copy of the content. While open, the trigger gets `aria-describedby` pointing at it.
|
|
120
|
+
- Label: the tooltip adds a description, not a name. Name the trigger with its text or `aria-label`.
|
|
121
|
+
- Keyboard: focusing the trigger opens the tooltip; moving focus away or pressing Escape closes it.
|
|
122
|
+
- Focus: stays on the trigger; the tooltip can't be focused.
|
|
123
|
+
- Touch: touch input never opens a tooltip.
|
|
124
|
+
- Contrast: handled by the theme. Don't override colours.
|
|
125
|
+
|
|
126
|
+
## 11. Behaviour
|
|
127
|
+
|
|
128
|
+
- Placement: above the trigger by default (`side="top"`), 4px away. It flips and shifts to stay inside the viewport.
|
|
129
|
+
- Timing: the provider's `delayDuration` is 200ms in Eluan. After one tooltip closes, the next opens without delay for 300ms (`skipDelayDuration`). The pointer can move onto the tooltip without it closing, unless `disableHoverableContent` is set.
|
|
130
|
+
- Overflow and truncation: the panel clips overflow. Keep the text short.
|
|
131
|
+
- Motion: appears and disappears without animation. Don't add your own.
|
|
132
|
+
- Portal: TooltipContent mounts in `document.body`. In a scoped theme, pass `portalContainer` to the scoped EluanProvider or wrap the region in `PortalContainerProvider`; `container` overrides it for one tooltip. See `../foundations/theming.md`.
|
|
133
|
+
|
|
134
|
+
## 12. API
|
|
135
|
+
|
|
136
|
+
<!-- api:start -->
|
|
137
|
+
### TooltipProvider
|
|
138
|
+
|
|
139
|
+
| Prop | Type | Default | Description |
|
|
140
|
+
| --- | --- | --- | --- |
|
|
141
|
+
| `delayDuration` | `number` | `200` | Milliseconds of hover before a tooltip opens. |
|
|
142
|
+
| `skipDelayDuration` | `number` | `300` | Window after a tooltip closes in which the next one opens at once. |
|
|
143
|
+
| `disableHoverableContent` | `boolean` | `false` | Closes the tooltip as soon as the pointer leaves the trigger. |
|
|
144
|
+
| `children` | `ReactNode` | | Your app or region. |
|
|
145
|
+
|
|
146
|
+
### Tooltip
|
|
147
|
+
|
|
148
|
+
| Prop | Type | Default | Description |
|
|
149
|
+
| --- | --- | --- | --- |
|
|
150
|
+
| `open` | `boolean` | | Controlled open state. |
|
|
151
|
+
| `defaultOpen` | `boolean` | `false` | Initial state when uncontrolled. |
|
|
152
|
+
| `onOpenChange` | `(open: boolean) => void` | | Called on every open and close. |
|
|
153
|
+
| `delayDuration` | `number` | the provider's | Overrides the provider's delay for this tooltip. |
|
|
154
|
+
|
|
155
|
+
### TooltipTrigger
|
|
156
|
+
|
|
157
|
+
| Prop | Type | Default | Description |
|
|
158
|
+
| --- | --- | --- | --- |
|
|
159
|
+
| `asChild` | `boolean` | `false` | Renders the child (a Button) instead of a bare `<button>`. |
|
|
160
|
+
| `...props` | Radix `Tooltip.Trigger` props | | Native button attributes. |
|
|
161
|
+
|
|
162
|
+
### TooltipContent
|
|
163
|
+
|
|
164
|
+
| Prop | Type | Default | Description |
|
|
165
|
+
| --- | --- | --- | --- |
|
|
166
|
+
| `side` | `"top" \| "right" \| "bottom" \| "left"` | `"top"` | Preferred side of the trigger. |
|
|
167
|
+
| `align` | `"start" \| "center" \| "end"` | `"center"` | Alignment along that side. |
|
|
168
|
+
| `sideOffset` | `number` | `4` | Distance from the trigger in px. |
|
|
169
|
+
| `container` | `HTMLElement \| null` | nearest `PortalContainerProvider`, then `document.body` | Element to portal into. |
|
|
170
|
+
| `aria-label` | `string` | | Replaces the announced text when the visible content isn't plain text. |
|
|
171
|
+
| `...props` | Radix `Tooltip.Content` props without `className`, `style` | | |
|
|
172
|
+
<!-- api:end -->
|
|
173
|
+
|
|
174
|
+
## 13. Examples
|
|
175
|
+
|
|
176
|
+
A text-formatting toolbar. TooltipProvider normally sits once at the app root; it's shown here for completeness.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import { Button, Kbd, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@eluan/core";
|
|
180
|
+
import { Bold, Italic, Link } from "lucide-react";
|
|
181
|
+
|
|
182
|
+
const tools = [
|
|
183
|
+
{ label: "Bold", keys: "cmd+b", Icon: Bold },
|
|
184
|
+
{ label: "Italic", keys: "cmd+i", Icon: Italic },
|
|
185
|
+
{ label: "Insert link", keys: "cmd+k", Icon: Link },
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
export function FormattingToolbar({ onTool }: { onTool: (label: string) => void }) {
|
|
189
|
+
return (
|
|
190
|
+
<TooltipProvider>
|
|
191
|
+
<div role="group" aria-label="Text formatting" style={{ display: "flex", gap: "var(--spacing-xs)" }}>
|
|
192
|
+
{tools.map(({ label, keys, Icon }) => (
|
|
193
|
+
<Tooltip key={label}>
|
|
194
|
+
<TooltipTrigger asChild>
|
|
195
|
+
<Button type="button" variant="ghost" size="icon" aria-label={label} onClick={() => onTool(label)}>
|
|
196
|
+
<Icon aria-hidden="true" style={{ width: "var(--size-xxs)", height: "var(--size-xxs)" }} />
|
|
197
|
+
</Button>
|
|
198
|
+
</TooltipTrigger>
|
|
199
|
+
<TooltipContent side="bottom">
|
|
200
|
+
<span style={{ display: "flex", alignItems: "center", gap: "var(--spacing-xs)" }}>
|
|
201
|
+
{label}
|
|
202
|
+
<Kbd size="sm" keys={keys} />
|
|
203
|
+
</span>
|
|
204
|
+
</TooltipContent>
|
|
205
|
+
</Tooltip>
|
|
206
|
+
))}
|
|
207
|
+
</div>
|
|
208
|
+
</TooltipProvider>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## 14. Related components
|
|
214
|
+
|
|
215
|
+
- [Button](./button.md): the usual trigger; icon-only sizes need an `aria-label`.
|
|
216
|
+
- [Kbd](./kbd.md): shortcuts inside a tooltip.
|
|
217
|
+
- [HoverCard](./hover-card.md): a richer read-only preview on hover.
|
|
218
|
+
- [Popover](./popover.md): interactive content on click.
|
|
219
|
+
|
|
220
|
+
## 15. Common agent mistakes
|
|
221
|
+
|
|
222
|
+
_Filled from evals._
|