@radix-ng/primitives 0.11.0 → 0.12.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/.compodocrc.json +12 -0
- package/CHANGELOG.md +182 -0
- package/LICENSE +21 -0
- package/accordion/__tests__/accordion-content.directive.spec.ts +8 -0
- package/accordion/__tests__/accordion-header.directive.spec.ts +8 -0
- package/accordion/__tests__/accordion-item.directive.spec.ts +8 -0
- package/accordion/__tests__/accordion-root.directive.spec.ts +8 -0
- package/accordion/__tests__/accordion-trigger.directive.spec.ts +8 -0
- package/accordion/ng-package.json +5 -0
- package/accordion/src/accordion-content.directive.ts +46 -0
- package/accordion/src/accordion-header.directive.ts +15 -0
- package/accordion/src/accordion-item.directive.ts +216 -0
- package/accordion/src/accordion-root.directive.ts +205 -0
- package/accordion/src/accordion-trigger.directive.ts +37 -0
- package/accordion/stories/accordion.docs.mdx +77 -0
- package/accordion/stories/accordion.stories.ts +340 -0
- package/alert-dialog/{index.d.ts → index.ts} +1 -0
- package/alert-dialog/ng-package.json +5 -0
- package/alert-dialog/src/alert-dialog-cancel.directive.ts +17 -0
- package/alert-dialog/src/alert-dialog-content.directive.ts +24 -0
- package/alert-dialog/src/alert-dialog-root.directive.ts +15 -0
- package/alert-dialog/src/alert-dialog-title.directive.ts +7 -0
- package/alert-dialog/src/alert-dialog-trigger.directive.ts +17 -0
- package/alert-dialog/src/alert-dialog.service.ts +51 -0
- package/alert-dialog/stories/alert-dialog.stories.ts +139 -0
- package/avatar/__tests__/avatar-fallback.directive.spec.ts +31 -0
- package/avatar/__tests__/avatar-image.directive.spec.ts +36 -0
- package/avatar/ng-package.json +5 -0
- package/avatar/src/avatar-fallback.directive.ts +62 -0
- package/avatar/src/avatar-image.directive.ts +55 -0
- package/avatar/src/avatar-root.directive.ts +35 -0
- package/avatar/src/avatar.config.ts +29 -0
- package/avatar/stories/avatar.docs.mdx +37 -0
- package/avatar/stories/avatar.stories.ts +87 -0
- package/button/__tests__/.gitkeep +0 -0
- package/button/src/button-abstract.directive.ts +46 -0
- package/checkbox/ng-package.json +5 -0
- package/checkbox/src/checkbox-button.directive.ts +26 -0
- package/checkbox/src/checkbox-indicator.directive.ts +16 -0
- package/checkbox/src/checkbox-input.directive.ts +36 -0
- package/checkbox/src/checkbox.directive.ts +146 -0
- package/checkbox/src/checkbox.token.ts +8 -0
- package/checkbox/stories/checkbox-group.component.ts +87 -0
- package/checkbox/stories/checkbox-group.styles.scss +49 -0
- package/checkbox/stories/checkbox-indeterminate.component.ts +52 -0
- package/checkbox/stories/checkbox.docs.mdx +58 -0
- package/checkbox/stories/checkbox.stories.ts +105 -0
- package/collapsible/__tests__/collapsible-content.directive.spec.ts +30 -0
- package/collapsible/__tests__/collapsible-root.directive.spec.ts +27 -0
- package/collapsible/__tests__/collapsible-trigger.directive.spec.ts +30 -0
- package/collapsible/ng-package.json +5 -0
- package/collapsible/src/collapsible-content.directive.ts +34 -0
- package/collapsible/src/collapsible-content.token.ts +6 -0
- package/collapsible/src/collapsible-root.directive.ts +120 -0
- package/collapsible/src/collapsible-trigger.directive.ts +44 -0
- package/collapsible/stories/collapsible-animation.component.ts +116 -0
- package/collapsible/stories/collapsible-external-triggering.component.ts +86 -0
- package/collapsible/stories/collapsible.docs.mdx +53 -0
- package/collapsible/stories/collapsible.stories.ts +151 -0
- package/context-menu/README.md +1 -0
- package/context-menu/index.ts +10 -0
- package/context-menu/ng-package.json +5 -0
- package/context-menu/src/context-menu-content.directive.ts +47 -0
- package/context-menu/src/context-menu-item-checkbox.directive.ts +30 -0
- package/context-menu/src/context-menu-item-indicator.directive.ts +14 -0
- package/context-menu/src/context-menu-item-radio-group.directive.ts +31 -0
- package/context-menu/src/context-menu-item-radio.directive.ts +69 -0
- package/context-menu/src/context-menu-item-selectable.ts +18 -0
- package/context-menu/src/context-menu-item.directive.ts +65 -0
- package/context-menu/src/context-menu-label.directive.ts +7 -0
- package/context-menu/src/context-menu-separator.directive.ts +13 -0
- package/context-menu/src/context-menu-trigger.directive.ts +82 -0
- package/context-menu/stories/context-menu.docs.mdx +23 -0
- package/context-menu/stories/context-menu.stories.ts +253 -0
- package/core/index.ts +3 -0
- package/core/src/accessor/provide-value-accessor.ts +20 -0
- package/core/src/auto-focus.directive.ts +81 -0
- package/core/src/inject-ng-control.ts +28 -0
- package/core/src/mount.ts +27 -0
- package/dialog/README.md +1 -0
- package/dialog/__tests__/dialog-content.directive.spec.ts +77 -0
- package/dialog/__tests__/dialog-trigger.directive.spec.ts +85 -0
- package/dialog/index.ts +31 -0
- package/dialog/ng-package.json +5 -0
- package/dialog/src/dialog-close.directive.ts +18 -0
- package/dialog/src/dialog-content.directive.ts +45 -0
- package/dialog/src/dialog-description.directive.ts +7 -0
- package/dialog/src/dialog-dismiss.directive.ts +18 -0
- package/dialog/src/dialog-ref.ts +70 -0
- package/dialog/src/dialog-title.directive.ts +7 -0
- package/dialog/src/dialog-trigger.directive.ts +52 -0
- package/dialog/src/dialog.config.ts +55 -0
- package/dialog/src/dialog.injectors.ts +12 -0
- package/dialog/src/dialog.providers.ts +27 -0
- package/dialog/src/dialog.service.ts +94 -0
- package/dialog/stories/dialog.docs.mdx +32 -0
- package/dialog/stories/dialog.stories.ts +233 -0
- package/dropdown-menu/ng-package.json +5 -0
- package/dropdown-menu/src/dropdown-menu-content.directive.ts +47 -0
- package/dropdown-menu/src/dropdown-menu-item-checkbox.directive.ts +30 -0
- package/dropdown-menu/src/dropdown-menu-item-indicator.directive.ts +14 -0
- package/dropdown-menu/src/dropdown-menu-item-radio-group.directive.ts +31 -0
- package/dropdown-menu/src/dropdown-menu-item-radio.directive.ts +72 -0
- package/dropdown-menu/src/dropdown-menu-item-selectable.ts +18 -0
- package/dropdown-menu/src/dropdown-menu-item.directive.ts +66 -0
- package/dropdown-menu/src/dropdown-menu-label.directive.ts +7 -0
- package/dropdown-menu/src/dropdown-menu-separator.directive.ts +13 -0
- package/dropdown-menu/src/dropdown-menu-trigger.directive.ts +185 -0
- package/dropdown-menu/stories/dropdown-menu-item-checkbox.component.ts +104 -0
- package/dropdown-menu/stories/dropdown-menu-item-checkbox.styles.scss +106 -0
- package/dropdown-menu/stories/dropdown-menu-item-radio.component.ts +95 -0
- package/dropdown-menu/stories/dropdown-menu-item-radio.styles.scss +106 -0
- package/dropdown-menu/stories/dropdown.docs.mdx +27 -0
- package/dropdown-menu/stories/dropdown.stories.ts +212 -0
- package/form-field/index.ts +1 -0
- package/form-field/src/.gitkeep +0 -0
- package/jest.config.ts +21 -0
- package/label/__tests__/label-root.directive.spec.ts +99 -0
- package/label/ng-package.json +5 -0
- package/label/src/label.directive.ts +58 -0
- package/label/stories/label.docs.mdx +40 -0
- package/label/stories/label.stories.ts +76 -0
- package/menu/index.ts +29 -0
- package/menu/ng-package.json +5 -0
- package/menu/src/menu-content.directive.ts +9 -0
- package/menu/src/menu-directive.ts +10 -0
- package/menu/src/menu-group.directive.ts +12 -0
- package/menu/src/menu-item.directive.ts +44 -0
- package/menu/src/menu-label.directive.ts +7 -0
- package/menu/src/menu-separator.directive.ts +13 -0
- package/menubar/index.ts +38 -0
- package/menubar/ng-package.json +5 -0
- package/menubar/src/menubar-content.directive.ts +9 -0
- package/menubar/src/menubar-item-checkbox.directive.ts +32 -0
- package/menubar/src/menubar-item-indicator.directive.ts +10 -0
- package/menubar/src/menubar-item-radio.directive.ts +33 -0
- package/menubar/src/menubar-item.directive.ts +12 -0
- package/menubar/src/menubar-radio-group.directive.ts +9 -0
- package/menubar/src/menubar-root.directive.ts +15 -0
- package/menubar/src/menubar-separator.directive.ts +9 -0
- package/menubar/src/menubar-trigger.directive.ts +40 -0
- package/menubar/stories/menubar.stories.ts +229 -0
- package/ng-package.json +8 -0
- package/package.json +4 -112
- package/portal/stories/portal.docs.mdx +85 -0
- package/presence/__test__/presence-test.component.ts +51 -0
- package/presence/__test__/presence.spec.ts +50 -0
- package/presence/index.ts +4 -0
- package/presence/src/presence.ts +119 -0
- package/presence/src/transitions/transition.collapse.ts +99 -0
- package/presence/src/transitions/transition.toast.ts +27 -0
- package/presence/src/types.ts +20 -0
- package/presence/src/utils.ts +63 -0
- package/presence/stories/presence-story.componen.ts +69 -0
- package/presence/stories/presence.docs.mdx +40 -0
- package/presence/stories/presence.stories.ts +29 -0
- package/progress/__test__/progress.spec.ts +55 -0
- package/progress/{index.d.ts → index.ts} +1 -0
- package/progress/ng-package.json +5 -0
- package/progress/src/progress-indicator.directive.ts +26 -0
- package/progress/src/progress-root.directive.ts +134 -0
- package/progress/stories/progress.docs.mdx +65 -0
- package/progress/stories/progress.stories.ts +66 -0
- package/project.json +39 -0
- package/radio/{index.d.ts → index.ts} +1 -0
- package/radio/ng-package.json +5 -0
- package/radio/src/radio-indicator.directive.ts +17 -0
- package/radio/src/radio-item.directive.ts +68 -0
- package/radio/src/radio-root.directive.ts +207 -0
- package/radio/src/{radio-tokens.d.ts → radio-tokens.ts} +5 -1
- package/radio/stories/radio-group.component.ts +39 -0
- package/radio/stories/radio-group.styles.scss +70 -0
- package/radio/stories/radio.docs.mdx +68 -0
- package/radio/stories/radio.stories.ts +155 -0
- package/separator/__tests__/separator.directive.spec.ts +58 -0
- package/separator/ng-package.json +5 -0
- package/separator/src/separator.directive.ts +35 -0
- package/separator/stories/separator.docs.mdx +37 -0
- package/separator/stories/separator.stories.ts +82 -0
- package/slider/src/slider-input.directive.ts +0 -0
- package/slider/src/slider-thumb.directives.ts +60 -0
- package/slider/src/slider-track.directive.ts +11 -0
- package/slider/src/slider.directive.ts +59 -0
- package/slider/src/slider.types.ts +4 -0
- package/switch/index.ts +22 -0
- package/switch/ng-package.json +5 -0
- package/switch/src/switch-input.directive.ts +24 -0
- package/switch/src/switch-root.directive.ts +127 -0
- package/switch/src/switch-thumb.directive.ts +15 -0
- package/switch/stories/switch.docs.mdx +83 -0
- package/switch/stories/switch.stories.ts +149 -0
- package/tabs/__tests__/tabs-context.service.spec.ts +35 -0
- package/tabs/index.ts +26 -0
- package/tabs/ng-package.json +5 -0
- package/tabs/src/tabs-content.directive.ts +23 -0
- package/tabs/src/tabs-context.service.ts +43 -0
- package/tabs/src/tabs-list.directive.ts +21 -0
- package/tabs/src/tabs-root.directive.ts +70 -0
- package/tabs/src/tabs-trigger.directive.ts +55 -0
- package/tabs/stories/tabs.stories.ts +213 -0
- package/test-setup.ts +1 -0
- package/toggle/__tests__/toggle.directive.spec.ts +87 -0
- package/toggle/ng-package.json +5 -0
- package/toggle/src/toggle.directive.ts +49 -0
- package/toggle/stories/toggle.docs.mdx +60 -0
- package/toggle/stories/toggle.stories.ts +84 -0
- package/toggle-group/ng-package.json +5 -0
- package/toggle-group/src/toggle-group-button.directive.ts +73 -0
- package/toggle-group/src/toggle-group-button.token.ts +8 -0
- package/toggle-group/src/toggle-group-multi.directive.ts +158 -0
- package/toggle-group/src/toggle-group.directive.ts +148 -0
- package/toggle-group/src/toggle-group.token.ts +11 -0
- package/toggle-group/stories/toggle-group.docs.mdx +87 -0
- package/toggle-group/stories/toggle-group.stories.ts +95 -0
- package/tsconfig.doc.json +11 -0
- package/tsconfig.json +29 -0
- package/tsconfig.lib.json +19 -0
- package/tsconfig.lib.prod.json +12 -0
- package/tsconfig.spec.json +11 -0
- package/visually-hidden/README.md +3 -0
- package/visually-hidden/stories/visually-hidden.docs.mdx +36 -0
- package/accordion/src/accordion-content.directive.d.ts +0 -16
- package/accordion/src/accordion-header.directive.d.ts +0 -7
- package/accordion/src/accordion-item.directive.d.ts +0 -62
- package/accordion/src/accordion-root.directive.d.ts +0 -78
- package/accordion/src/accordion-trigger.directive.d.ts +0 -15
- package/alert-dialog/src/alert-dialog-cancel.directive.d.ts +0 -7
- package/alert-dialog/src/alert-dialog-content.directive.d.ts +0 -9
- package/alert-dialog/src/alert-dialog-root.directive.d.ts +0 -9
- package/alert-dialog/src/alert-dialog-title.directive.d.ts +0 -5
- package/alert-dialog/src/alert-dialog-trigger.directive.d.ts +0 -7
- package/alert-dialog/src/alert-dialog.service.d.ts +0 -14
- package/avatar/src/avatar-fallback.directive.d.ts +0 -27
- package/avatar/src/avatar-image.directive.d.ts +0 -16
- package/avatar/src/avatar-root.directive.d.ts +0 -21
- package/avatar/src/avatar.config.d.ts +0 -13
- package/checkbox/src/checkbox-button.directive.d.ts +0 -8
- package/checkbox/src/checkbox-indicator.directive.d.ts +0 -6
- package/checkbox/src/checkbox-input.directive.d.ts +0 -9
- package/checkbox/src/checkbox.directive.d.ts +0 -75
- package/checkbox/src/checkbox.token.d.ts +0 -4
- package/collapsible/src/collapsible-content.directive.d.ts +0 -17
- package/collapsible/src/collapsible-content.token.d.ts +0 -3
- package/collapsible/src/collapsible-root.directive.d.ts +0 -55
- package/collapsible/src/collapsible-trigger.directive.d.ts +0 -26
- package/compodoc/documentation.json +0 -11395
- package/dropdown-menu/src/dropdown-menu-content.directive.d.ts +0 -15
- package/dropdown-menu/src/dropdown-menu-item-checkbox.directive.d.ts +0 -9
- package/dropdown-menu/src/dropdown-menu-item-indicator.directive.d.ts +0 -7
- package/dropdown-menu/src/dropdown-menu-item-radio-group.directive.d.ts +0 -12
- package/dropdown-menu/src/dropdown-menu-item-radio.directive.d.ts +0 -19
- package/dropdown-menu/src/dropdown-menu-item-selectable.d.ts +0 -12
- package/dropdown-menu/src/dropdown-menu-item.directive.d.ts +0 -17
- package/dropdown-menu/src/dropdown-menu-label.directive.d.ts +0 -5
- package/dropdown-menu/src/dropdown-menu-separator.directive.d.ts +0 -6
- package/dropdown-menu/src/dropdown-menu-trigger.directive.d.ts +0 -43
- package/esm2022/accordion/index.mjs +0 -6
- package/esm2022/accordion/radix-ng-primitives-accordion.mjs +0 -5
- package/esm2022/accordion/src/accordion-content.directive.mjs +0 -36
- package/esm2022/accordion/src/accordion-header.directive.mjs +0 -23
- package/esm2022/accordion/src/accordion-item.directive.mjs +0 -170
- package/esm2022/accordion/src/accordion-root.directive.mjs +0 -157
- package/esm2022/accordion/src/accordion-trigger.directive.mjs +0 -42
- package/esm2022/alert-dialog/index.mjs +0 -7
- package/esm2022/alert-dialog/radix-ng-primitives-alert-dialog.mjs +0 -5
- package/esm2022/alert-dialog/src/alert-dialog-cancel.directive.mjs +0 -24
- package/esm2022/alert-dialog/src/alert-dialog-content.directive.mjs +0 -34
- package/esm2022/alert-dialog/src/alert-dialog-root.directive.mjs +0 -25
- package/esm2022/alert-dialog/src/alert-dialog-title.directive.mjs +0 -14
- package/esm2022/alert-dialog/src/alert-dialog-trigger.directive.mjs +0 -24
- package/esm2022/alert-dialog/src/alert-dialog.service.mjs +0 -47
- package/esm2022/avatar/index.mjs +0 -5
- package/esm2022/avatar/radix-ng-primitives-avatar.mjs +0 -5
- package/esm2022/avatar/src/avatar-fallback.directive.mjs +0 -54
- package/esm2022/avatar/src/avatar-image.directive.mjs +0 -48
- package/esm2022/avatar/src/avatar-root.directive.mjs +0 -38
- package/esm2022/avatar/src/avatar.config.mjs +0 -17
- package/esm2022/checkbox/index.mjs +0 -6
- package/esm2022/checkbox/radix-ng-primitives-checkbox.mjs +0 -5
- package/esm2022/checkbox/src/checkbox-button.directive.mjs +0 -33
- package/esm2022/checkbox/src/checkbox-indicator.directive.mjs +0 -24
- package/esm2022/checkbox/src/checkbox-input.directive.mjs +0 -41
- package/esm2022/checkbox/src/checkbox.directive.mjs +0 -141
- package/esm2022/checkbox/src/checkbox.token.mjs +0 -6
- package/esm2022/collapsible/index.mjs +0 -4
- package/esm2022/collapsible/radix-ng-primitives-collapsible.mjs +0 -5
- package/esm2022/collapsible/src/collapsible-content.directive.mjs +0 -45
- package/esm2022/collapsible/src/collapsible-content.token.mjs +0 -3
- package/esm2022/collapsible/src/collapsible-root.directive.mjs +0 -118
- package/esm2022/collapsible/src/collapsible-trigger.directive.mjs +0 -49
- package/esm2022/dropdown-menu/index.mjs +0 -11
- package/esm2022/dropdown-menu/radix-ng-primitives-dropdown-menu.mjs +0 -5
- package/esm2022/dropdown-menu/src/dropdown-menu-content.directive.mjs +0 -56
- package/esm2022/dropdown-menu/src/dropdown-menu-item-checkbox.directive.mjs +0 -36
- package/esm2022/dropdown-menu/src/dropdown-menu-item-indicator.directive.mjs +0 -22
- package/esm2022/dropdown-menu/src/dropdown-menu-item-radio-group.directive.mjs +0 -37
- package/esm2022/dropdown-menu/src/dropdown-menu-item-radio.directive.mjs +0 -64
- package/esm2022/dropdown-menu/src/dropdown-menu-item-selectable.mjs +0 -31
- package/esm2022/dropdown-menu/src/dropdown-menu-item.directive.mjs +0 -71
- package/esm2022/dropdown-menu/src/dropdown-menu-label.directive.mjs +0 -14
- package/esm2022/dropdown-menu/src/dropdown-menu-separator.directive.mjs +0 -21
- package/esm2022/dropdown-menu/src/dropdown-menu-trigger.directive.mjs +0 -176
- package/esm2022/index.mjs +0 -2
- package/esm2022/label/index.mjs +0 -2
- package/esm2022/label/radix-ng-primitives-label.mjs +0 -5
- package/esm2022/label/src/label.directive.mjs +0 -59
- package/esm2022/menu/index.mjs +0 -45
- package/esm2022/menu/radix-ng-primitives-menu.mjs +0 -5
- package/esm2022/menu/src/menu-content.directive.mjs +0 -17
- package/esm2022/menu/src/menu-directive.mjs +0 -18
- package/esm2022/menu/src/menu-group.directive.mjs +0 -20
- package/esm2022/menu/src/menu-item.directive.mjs +0 -46
- package/esm2022/menu/src/menu-label.directive.mjs +0 -14
- package/esm2022/menu/src/menu-separator.directive.mjs +0 -21
- package/esm2022/menubar/index.mjs +0 -60
- package/esm2022/menubar/radix-ng-primitives-menubar.mjs +0 -5
- package/esm2022/menubar/src/menubar-content.directive.mjs +0 -17
- package/esm2022/menubar/src/menubar-item-checkbox.directive.mjs +0 -34
- package/esm2022/menubar/src/menubar-item-indicator.directive.mjs +0 -17
- package/esm2022/menubar/src/menubar-item-radio.directive.mjs +0 -35
- package/esm2022/menubar/src/menubar-item.directive.mjs +0 -20
- package/esm2022/menubar/src/menubar-radio-group.directive.mjs +0 -17
- package/esm2022/menubar/src/menubar-root.directive.mjs +0 -24
- package/esm2022/menubar/src/menubar-separator.directive.mjs +0 -17
- package/esm2022/menubar/src/menubar-trigger.directive.mjs +0 -45
- package/esm2022/progress/index.mjs +0 -3
- package/esm2022/progress/radix-ng-primitives-progress.mjs +0 -5
- package/esm2022/progress/src/progress-indicator.directive.mjs +0 -34
- package/esm2022/progress/src/progress-root.directive.mjs +0 -127
- package/esm2022/radio/index.mjs +0 -4
- package/esm2022/radio/radix-ng-primitives-radio.mjs +0 -5
- package/esm2022/radio/src/radio-indicator.directive.mjs +0 -25
- package/esm2022/radio/src/radio-item.directive.mjs +0 -70
- package/esm2022/radio/src/radio-root.directive.mjs +0 -194
- package/esm2022/radio/src/radio-tokens.mjs +0 -3
- package/esm2022/radix-ng-primitives.mjs +0 -5
- package/esm2022/separator/index.mjs +0 -2
- package/esm2022/separator/radix-ng-primitives-separator.mjs +0 -5
- package/esm2022/separator/src/separator.directive.mjs +0 -31
- package/esm2022/switch/index.mjs +0 -30
- package/esm2022/switch/radix-ng-primitives-switch.mjs +0 -5
- package/esm2022/switch/src/switch-input.directive.mjs +0 -32
- package/esm2022/switch/src/switch-root.directive.mjs +0 -95
- package/esm2022/switch/src/switch-thumb.directive.mjs +0 -23
- package/esm2022/tabs/index.mjs +0 -38
- package/esm2022/tabs/radix-ng-primitives-tabs.mjs +0 -5
- package/esm2022/tabs/src/tabs-content.directive.mjs +0 -29
- package/esm2022/tabs/src/tabs-context.service.mjs +0 -43
- package/esm2022/tabs/src/tabs-list.directive.mjs +0 -23
- package/esm2022/tabs/src/tabs-root.directive.mjs +0 -54
- package/esm2022/tabs/src/tabs-trigger.directive.mjs +0 -52
- package/esm2022/toggle/index.mjs +0 -2
- package/esm2022/toggle/radix-ng-primitives-toggle.mjs +0 -5
- package/esm2022/toggle/src/toggle.directive.mjs +0 -39
- package/esm2022/toggle-group/index.mjs +0 -6
- package/esm2022/toggle-group/radix-ng-primitives-toggle-group.mjs +0 -5
- package/esm2022/toggle-group/src/toggle-group-button.directive.mjs +0 -75
- package/esm2022/toggle-group/src/toggle-group-button.token.mjs +0 -6
- package/esm2022/toggle-group/src/toggle-group-multi.directive.mjs +0 -143
- package/esm2022/toggle-group/src/toggle-group.directive.mjs +0 -134
- package/esm2022/toggle-group/src/toggle-group.token.mjs +0 -6
- package/fesm2022/radix-ng-primitives-accordion.mjs +0 -418
- package/fesm2022/radix-ng-primitives-accordion.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-alert-dialog.mjs +0 -161
- package/fesm2022/radix-ng-primitives-alert-dialog.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-avatar.mjs +0 -156
- package/fesm2022/radix-ng-primitives-avatar.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-checkbox.mjs +0 -241
- package/fesm2022/radix-ng-primitives-checkbox.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-collapsible.mjs +0 -213
- package/fesm2022/radix-ng-primitives-collapsible.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-dropdown-menu.mjs +0 -502
- package/fesm2022/radix-ng-primitives-dropdown-menu.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-label.mjs +0 -66
- package/fesm2022/radix-ng-primitives-label.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-menu.mjs +0 -158
- package/fesm2022/radix-ng-primitives-menu.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-menubar.mjs +0 -245
- package/fesm2022/radix-ng-primitives-menubar.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-progress.mjs +0 -165
- package/fesm2022/radix-ng-primitives-progress.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-radio.mjs +0 -289
- package/fesm2022/radix-ng-primitives-radio.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-separator.mjs +0 -38
- package/fesm2022/radix-ng-primitives-separator.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-switch.mjs +0 -173
- package/fesm2022/radix-ng-primitives-switch.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-tabs.mjs +0 -222
- package/fesm2022/radix-ng-primitives-tabs.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-toggle-group.mjs +0 -358
- package/fesm2022/radix-ng-primitives-toggle-group.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives-toggle.mjs +0 -46
- package/fesm2022/radix-ng-primitives-toggle.mjs.map +0 -1
- package/fesm2022/radix-ng-primitives.mjs +0 -4
- package/fesm2022/radix-ng-primitives.mjs.map +0 -1
- package/label/src/label.directive.d.ts +0 -29
- package/menu/index.d.ts +0 -18
- package/menu/src/menu-content.directive.d.ts +0 -6
- package/menu/src/menu-directive.d.ts +0 -6
- package/menu/src/menu-group.directive.d.ts +0 -6
- package/menu/src/menu-item.directive.d.ts +0 -12
- package/menu/src/menu-label.directive.d.ts +0 -5
- package/menu/src/menu-separator.directive.d.ts +0 -6
- package/menubar/index.d.ts +0 -24
- package/menubar/src/menubar-content.directive.d.ts +0 -6
- package/menubar/src/menubar-item-checkbox.directive.d.ts +0 -14
- package/menubar/src/menubar-item-indicator.directive.d.ts +0 -5
- package/menubar/src/menubar-item-radio.directive.d.ts +0 -14
- package/menubar/src/menubar-item.directive.d.ts +0 -8
- package/menubar/src/menubar-radio-group.directive.d.ts +0 -6
- package/menubar/src/menubar-root.directive.d.ts +0 -7
- package/menubar/src/menubar-separator.directive.d.ts +0 -6
- package/menubar/src/menubar-trigger.directive.d.ts +0 -11
- package/progress/src/progress-indicator.directive.d.ts +0 -16
- package/progress/src/progress-root.directive.d.ts +0 -63
- package/radio/src/radio-indicator.directive.d.ts +0 -9
- package/radio/src/radio-item.directive.d.ts +0 -21
- package/radio/src/radio-root.directive.d.ts +0 -72
- package/separator/src/separator.directive.d.ts +0 -22
- package/switch/index.d.ts +0 -13
- package/switch/src/switch-input.directive.d.ts +0 -6
- package/switch/src/switch-root.directive.d.ts +0 -51
- package/switch/src/switch-thumb.directive.d.ts +0 -6
- package/tabs/index.d.ts +0 -15
- package/tabs/src/tabs-content.directive.d.ts +0 -8
- package/tabs/src/tabs-context.service.d.ts +0 -22
- package/tabs/src/tabs-list.directive.d.ts +0 -6
- package/tabs/src/tabs-root.directive.d.ts +0 -37
- package/tabs/src/tabs-trigger.directive.d.ts +0 -19
- package/toggle/src/toggle.directive.d.ts +0 -30
- package/toggle-group/src/toggle-group-button.directive.d.ts +0 -39
- package/toggle-group/src/toggle-group-button.token.d.ts +0 -4
- package/toggle-group/src/toggle-group-multi.directive.d.ts +0 -93
- package/toggle-group/src/toggle-group.directive.d.ts +0 -84
- package/toggle-group/src/toggle-group.token.d.ts +0 -5
- /package/accordion/{index.d.ts → index.ts} +0 -0
- /package/avatar/{index.d.ts → index.ts} +0 -0
- /package/checkbox/{index.d.ts → index.ts} +0 -0
- /package/collapsible/{index.d.ts → index.ts} +0 -0
- /package/dropdown-menu/{index.d.ts → index.ts} +0 -0
- /package/{index.d.ts → index.ts} +0 -0
- /package/label/{index.d.ts → index.ts} +0 -0
- /package/separator/{index.d.ts → index.ts} +0 -0
- /package/toggle/{index.d.ts → index.ts} +0 -0
- /package/toggle-group/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
import { Directive } from '@angular/core';
|
2
|
+
import { injectSwitch } from './switch-root.directive';
|
3
|
+
|
4
|
+
@Directive({
|
5
|
+
selector: 'input[rdxSwitchInput]',
|
6
|
+
exportAs: 'rdxSwitchInput',
|
7
|
+
standalone: true,
|
8
|
+
host: {
|
9
|
+
type: 'checkbox',
|
10
|
+
tabindex: '-1',
|
11
|
+
'[attr.defaultChecked]': 'switchRoot.checked()',
|
12
|
+
'[attr.aria-checked]': 'switchRoot.checked()',
|
13
|
+
'[attr.aria-hidden]': 'true',
|
14
|
+
'[attr.aria-required]': 'switchRoot.required()',
|
15
|
+
'[attr.data-state]': 'switchRoot.checked() ? "checked" : "unchecked"',
|
16
|
+
'[attr.data-disabled]': 'switchRoot.disabledState() ? "true" : null',
|
17
|
+
'[attr.disabled]': 'switchRoot.disabledState() ? switchRoot.disabledState() : null',
|
18
|
+
'[attr.value]': 'switchRoot.checked() ? "on" : "off"',
|
19
|
+
style: 'transform: translateX(-100%); position: absolute; overflow: hidden; pointerEvents: none; opacity: 0; margin: 0;'
|
20
|
+
}
|
21
|
+
})
|
22
|
+
export class RdxSwitchInputDirective {
|
23
|
+
protected readonly switchRoot = injectSwitch();
|
24
|
+
}
|
@@ -0,0 +1,127 @@
|
|
1
|
+
import { BooleanInput } from '@angular/cdk/coercion';
|
2
|
+
import {
|
3
|
+
booleanAttribute,
|
4
|
+
computed,
|
5
|
+
Directive,
|
6
|
+
EventEmitter,
|
7
|
+
inject,
|
8
|
+
InjectionToken,
|
9
|
+
input,
|
10
|
+
InputSignalWithTransform,
|
11
|
+
model,
|
12
|
+
ModelSignal,
|
13
|
+
Output
|
14
|
+
} from '@angular/core';
|
15
|
+
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
16
|
+
|
17
|
+
export const RdxSwitchToken = new InjectionToken<RdxSwitchRootDirective>('RdxSwitchToken');
|
18
|
+
|
19
|
+
export function injectSwitch(): RdxSwitchRootDirective {
|
20
|
+
return inject(RdxSwitchToken);
|
21
|
+
}
|
22
|
+
|
23
|
+
export interface SwitchProps {
|
24
|
+
checked?: ModelSignal<boolean>;
|
25
|
+
defaultChecked?: boolean;
|
26
|
+
required?: InputSignalWithTransform<boolean, BooleanInput>;
|
27
|
+
onCheckedChange?: EventEmitter<boolean>;
|
28
|
+
}
|
29
|
+
|
30
|
+
let idIterator = 0;
|
31
|
+
|
32
|
+
@Directive({
|
33
|
+
selector: 'button[rdxSwitchRoot]',
|
34
|
+
exportAs: 'rdxSwitchRoot',
|
35
|
+
standalone: true,
|
36
|
+
providers: [
|
37
|
+
{ provide: RdxSwitchToken, useExisting: RdxSwitchRootDirective },
|
38
|
+
{ provide: NG_VALUE_ACCESSOR, useExisting: RdxSwitchRootDirective, multi: true }
|
39
|
+
],
|
40
|
+
host: {
|
41
|
+
role: 'switch',
|
42
|
+
type: 'button',
|
43
|
+
'[id]': 'elementId()',
|
44
|
+
'[attr.aria-checked]': 'checked()',
|
45
|
+
'[attr.aria-required]': 'required',
|
46
|
+
'[attr.data-state]': 'checked() ? "checked" : "unchecked"',
|
47
|
+
'[attr.data-disabled]': 'disabledState() ? "true" : null',
|
48
|
+
'[attr.disabled]': 'disabledState() ? disabledState() : null',
|
49
|
+
|
50
|
+
'(focus)': '_onTouched?.()',
|
51
|
+
'(click)': 'toggle()'
|
52
|
+
}
|
53
|
+
})
|
54
|
+
export class RdxSwitchRootDirective implements SwitchProps, ControlValueAccessor {
|
55
|
+
readonly id = input<string>(`rdx-switch-${idIterator++}`);
|
56
|
+
protected readonly elementId = computed(() => (this.id() ? this.id() : null));
|
57
|
+
|
58
|
+
// When true, indicates that the user must check
|
59
|
+
// the switch before the owning form can be submitted.
|
60
|
+
readonly required = input<boolean, BooleanInput>(false, {
|
61
|
+
transform: booleanAttribute
|
62
|
+
});
|
63
|
+
|
64
|
+
// The controlled state of the switch
|
65
|
+
readonly checked = model<boolean>(false);
|
66
|
+
|
67
|
+
// When true, prevents the user from interacting with the switch.
|
68
|
+
readonly disabled = input<boolean, BooleanInput>(false, {
|
69
|
+
transform: booleanAttribute
|
70
|
+
});
|
71
|
+
|
72
|
+
/*
|
73
|
+
* @ignore
|
74
|
+
*/
|
75
|
+
readonly disabledState = computed(() => this.disabled());
|
76
|
+
|
77
|
+
@Output() onCheckedChange = new EventEmitter<boolean>();
|
78
|
+
|
79
|
+
/**
|
80
|
+
* The method to be called in order to update ngModel.
|
81
|
+
*/
|
82
|
+
_onChange?: (checked: boolean) => void;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* onTouch function registered via registerOnTouch (ControlValueAccessor).
|
86
|
+
*/
|
87
|
+
_onTouched?: () => void;
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Registers a function to call when the checked state changes.
|
91
|
+
* @param fn Function to call on change.
|
92
|
+
*/
|
93
|
+
registerOnChange(fn: (checked: boolean) => void): void {
|
94
|
+
this._onChange = fn;
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Registers a function to call when the component is touched.
|
99
|
+
* @param fn Function to call on touch.
|
100
|
+
*/
|
101
|
+
registerOnTouched(fn: () => void): void {
|
102
|
+
this._onTouched = fn;
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Writes a new value to the model.
|
107
|
+
* @param checked The new checked value.
|
108
|
+
*/
|
109
|
+
writeValue(checked: boolean): void {
|
110
|
+
this.checked.set(checked);
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Toggles the checked state of the switch.
|
115
|
+
* If the switch is disabled, the function returns early.
|
116
|
+
*/
|
117
|
+
protected toggle(): void {
|
118
|
+
if (this.disabledState()) {
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
|
122
|
+
this.checked.set(!this.checked());
|
123
|
+
this._onChange?.(this.checked());
|
124
|
+
|
125
|
+
this.onCheckedChange.emit(this.checked());
|
126
|
+
}
|
127
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Directive } from '@angular/core';
|
2
|
+
import { injectSwitch } from './switch-root.directive';
|
3
|
+
|
4
|
+
@Directive({
|
5
|
+
selector: 'span[rdxSwitchThumb]',
|
6
|
+
exportAs: 'rdxSwitchThumb',
|
7
|
+
standalone: true,
|
8
|
+
host: {
|
9
|
+
'[attr.data-disabled]': 'switchRoot.disabledState() ? "true" : null',
|
10
|
+
'[attr.data-state]': 'switchRoot.checked() ? "checked" : "unchecked"'
|
11
|
+
}
|
12
|
+
})
|
13
|
+
export class RdxSwitchThumbDirective {
|
14
|
+
protected readonly switchRoot = injectSwitch();
|
15
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import { ArgTypes, Canvas, Markdown, Meta } from '@storybook/blocks';
|
2
|
+
import { switchExclude } from '../../../../apps/storybook-radix/docs/utils/storybook';
|
3
|
+
import { RdxSwitchRootDirective } from '../src/switch-root.directive';
|
4
|
+
import * as SwitchDirectiveStories from './switch.stories';
|
5
|
+
|
6
|
+
<Meta title="Primitives/Switch" />
|
7
|
+
|
8
|
+
# Switch
|
9
|
+
|
10
|
+
#### A control that allows the user to toggle between checked and not checked.
|
11
|
+
|
12
|
+
<Canvas sourceState="hidden" of={SwitchDirectiveStories.Default} />
|
13
|
+
|
14
|
+
## Features
|
15
|
+
|
16
|
+
- ✅ Full keyboard navigation.
|
17
|
+
- ✅ Can be controlled or uncontrolled.
|
18
|
+
|
19
|
+
## Import
|
20
|
+
|
21
|
+
Get started with importing the directives:
|
22
|
+
|
23
|
+
```typescript
|
24
|
+
import { RdxSwitchRootDirective, RdxSwitchThumbDirective, RdxSwitchInputDirective } from '@radix-ng/primitives/switch';
|
25
|
+
```
|
26
|
+
|
27
|
+
## Examples
|
28
|
+
|
29
|
+
```html
|
30
|
+
<label rdxLabel htmlFor="airplane-mode">Airplane mode</label>
|
31
|
+
<button id="airplane-mode" rdxSwitchRoot [(checked)]="checked">
|
32
|
+
<span rdxSwitchThumb></span>
|
33
|
+
</button>
|
34
|
+
```
|
35
|
+
|
36
|
+
```html
|
37
|
+
<label rdxLabel htmlFor="airplane-mode">Airplane mode</label>
|
38
|
+
<button id="airplane-mode" rdxSwitchRoot [(checked)]="checked">
|
39
|
+
<input rdxSwitchInput />
|
40
|
+
<span rdxSwitchThumb></span>
|
41
|
+
</button>
|
42
|
+
```
|
43
|
+
|
44
|
+
## API Reference
|
45
|
+
|
46
|
+
### RdxSwitchRootDirective
|
47
|
+
|
48
|
+
<ArgTypes exclude={switchExclude} of={RdxSwitchRootDirective} />
|
49
|
+
|
50
|
+
<Markdown>
|
51
|
+
{`
|
52
|
+
| Data Attribute | Value |
|
53
|
+
| ----------- | --------- |
|
54
|
+
| [data-state] | "checked" or "unchecked" |
|
55
|
+
| [data-disabled] | Present when disabled |
|
56
|
+
`}
|
57
|
+
</Markdown>
|
58
|
+
|
59
|
+
### ThumbDirective
|
60
|
+
|
61
|
+
<Markdown>
|
62
|
+
{`
|
63
|
+
| Data Attribute | Value |
|
64
|
+
| ----------- | --------- |
|
65
|
+
| [data-state] | "checked" or "unchecked" |
|
66
|
+
| [data-disabled] | Present when disabled |
|
67
|
+
`}
|
68
|
+
</Markdown>
|
69
|
+
|
70
|
+
## Accessibility
|
71
|
+
|
72
|
+
Adheres to the [`switch` role requirements](https://www.w3.org/WAI/ARIA/apg/patterns/switch).
|
73
|
+
|
74
|
+
### Keyboard Interactions
|
75
|
+
|
76
|
+
<Markdown>
|
77
|
+
{`
|
78
|
+
| Key | Description |
|
79
|
+
| ----------- | --------- |
|
80
|
+
| Space | Toggles the component's state. |
|
81
|
+
| Enter | Toggles the component's state. |
|
82
|
+
`}
|
83
|
+
</Markdown>
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import { componentWrapperDecorator, Meta, moduleMetadata, StoryObj } from '@storybook/angular';
|
2
|
+
import { RdxLabelDirective } from '../../label';
|
3
|
+
import { RdxSwitchInputDirective } from '../src/switch-input.directive';
|
4
|
+
import { RdxSwitchRootDirective } from '../src/switch-root.directive';
|
5
|
+
import { RdxSwitchThumbDirective } from '../src/switch-thumb.directive';
|
6
|
+
|
7
|
+
export default {
|
8
|
+
title: 'Primitives/Switch',
|
9
|
+
decorators: [
|
10
|
+
moduleMetadata({
|
11
|
+
imports: [
|
12
|
+
RdxLabelDirective,
|
13
|
+
RdxSwitchRootDirective,
|
14
|
+
RdxSwitchInputDirective,
|
15
|
+
RdxSwitchThumbDirective
|
16
|
+
]
|
17
|
+
}),
|
18
|
+
componentWrapperDecorator(
|
19
|
+
(story) =>
|
20
|
+
`<div class="radix-themes light light-theme"
|
21
|
+
data-radius="medium"
|
22
|
+
data-scaling="100%">${story}</div>`
|
23
|
+
)
|
24
|
+
]
|
25
|
+
} as Meta;
|
26
|
+
|
27
|
+
type Story = StoryObj;
|
28
|
+
|
29
|
+
export const Default: Story = {
|
30
|
+
render: () => ({
|
31
|
+
template: `
|
32
|
+
<style>
|
33
|
+
button {
|
34
|
+
all: unset;
|
35
|
+
}
|
36
|
+
|
37
|
+
.SwitchRoot {
|
38
|
+
width: 42px;
|
39
|
+
height: 25px;
|
40
|
+
background-color: var(--black-a9);
|
41
|
+
border-radius: 9999px;
|
42
|
+
margin-left: 15px;
|
43
|
+
position: relative;
|
44
|
+
box-shadow: 0 2px 10px var(--black-a7);
|
45
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
46
|
+
}
|
47
|
+
.SwitchRoot:focus {
|
48
|
+
box-shadow: 0 0 0 2px black;
|
49
|
+
}
|
50
|
+
.SwitchRoot[data-state='checked'] {
|
51
|
+
background-color: black;
|
52
|
+
}
|
53
|
+
|
54
|
+
.SwitchThumb {
|
55
|
+
display: block;
|
56
|
+
width: 21px;
|
57
|
+
height: 21px;
|
58
|
+
background-color: white;
|
59
|
+
border-radius: 9999px;
|
60
|
+
box-shadow: 0 2px 2px var(--black-a7);
|
61
|
+
transition: transform 100ms;
|
62
|
+
transform: translateX(2px);
|
63
|
+
will-change: transform;
|
64
|
+
}
|
65
|
+
.SwitchThumb[data-state='checked'] {
|
66
|
+
transform: translateX(19px);
|
67
|
+
}
|
68
|
+
|
69
|
+
.Label {
|
70
|
+
color: white;
|
71
|
+
font-size: 15px;
|
72
|
+
line-height: 1;
|
73
|
+
display: flex;
|
74
|
+
align-items: center;
|
75
|
+
}
|
76
|
+
|
77
|
+
</style>
|
78
|
+
|
79
|
+
<label rdxLabel htmlFor="airplane-mode" class="Label">
|
80
|
+
Airplane mode
|
81
|
+
<button rdxSwitchRoot [(checked)]="checked" id="airplane-mode" class="SwitchRoot">
|
82
|
+
<span rdxSwitchThumb class="SwitchThumb"></span>
|
83
|
+
</button>
|
84
|
+
</label>
|
85
|
+
`
|
86
|
+
})
|
87
|
+
};
|
88
|
+
|
89
|
+
export const DefaultInput: Story = {
|
90
|
+
name: 'With Input',
|
91
|
+
render: () => ({
|
92
|
+
template: `
|
93
|
+
<style>
|
94
|
+
button {
|
95
|
+
all: unset;
|
96
|
+
}
|
97
|
+
|
98
|
+
.SwitchRoot {
|
99
|
+
width: 42px;
|
100
|
+
height: 25px;
|
101
|
+
background-color: var(--black-a9);
|
102
|
+
border-radius: 9999px;
|
103
|
+
margin-left: 15px;
|
104
|
+
position: relative;
|
105
|
+
box-shadow: 0 2px 10px var(--black-a7);
|
106
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
107
|
+
}
|
108
|
+
.SwitchRoot:focus {
|
109
|
+
box-shadow: 0 0 0 2px black;
|
110
|
+
}
|
111
|
+
.SwitchRoot[data-state='checked'] {
|
112
|
+
background-color: black;
|
113
|
+
}
|
114
|
+
|
115
|
+
.SwitchThumb {
|
116
|
+
display: block;
|
117
|
+
width: 21px;
|
118
|
+
height: 21px;
|
119
|
+
background-color: white;
|
120
|
+
border-radius: 9999px;
|
121
|
+
box-shadow: 0 2px 2px var(--black-a7);
|
122
|
+
transition: transform 100ms;
|
123
|
+
transform: translateX(2px);
|
124
|
+
will-change: transform;
|
125
|
+
}
|
126
|
+
.SwitchThumb[data-state='checked'] {
|
127
|
+
transform: translateX(19px);
|
128
|
+
}
|
129
|
+
|
130
|
+
.Label {
|
131
|
+
color: white;
|
132
|
+
font-size: 15px;
|
133
|
+
line-height: 1;
|
134
|
+
display: flex;
|
135
|
+
align-items: center;
|
136
|
+
}
|
137
|
+
|
138
|
+
</style>
|
139
|
+
|
140
|
+
<label rdxLabel htmlFor="airplane-mode" class="Label">
|
141
|
+
Airplane mode
|
142
|
+
<button rdxSwitchRoot [(checked)]="checked" id="airplane-mode" class="SwitchRoot">
|
143
|
+
<input rdxSwitchInput />
|
144
|
+
<span rdxSwitchThumb class="SwitchThumb"></span>
|
145
|
+
</button>
|
146
|
+
</label>
|
147
|
+
`
|
148
|
+
})
|
149
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
2
|
+
import { RdxTabsContextService } from '../src/tabs-context.service';
|
3
|
+
|
4
|
+
describe('TabsContextService', () => {
|
5
|
+
let service: RdxTabsContextService;
|
6
|
+
|
7
|
+
beforeEach(() => {
|
8
|
+
TestBed.configureTestingModule({});
|
9
|
+
service = TestBed.inject(RdxTabsContextService);
|
10
|
+
});
|
11
|
+
|
12
|
+
it('should be created', () => {
|
13
|
+
expect(service).toBeTruthy();
|
14
|
+
});
|
15
|
+
|
16
|
+
it('should generate a base ID', () => {
|
17
|
+
const baseId = service.getBaseId();
|
18
|
+
expect(baseId).toMatch(/^tabs-/);
|
19
|
+
});
|
20
|
+
|
21
|
+
it('should set and get the value correctly', () => {
|
22
|
+
service.setValue('test');
|
23
|
+
expect(service.value$()).toBe('test');
|
24
|
+
});
|
25
|
+
|
26
|
+
it('should set and get the orientation correctly', () => {
|
27
|
+
service.setOrientation('vertical');
|
28
|
+
expect(service.orientation$()).toBe('vertical');
|
29
|
+
});
|
30
|
+
|
31
|
+
it('should set and get the direction correctly', () => {
|
32
|
+
service.setDir('rtl');
|
33
|
+
expect(service.dir$()).toBe('rtl');
|
34
|
+
});
|
35
|
+
});
|
package/tabs/index.ts
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
import { NgModule } from '@angular/core';
|
2
|
+
import { RdxTabsContentDirective } from './src/tabs-content.directive';
|
3
|
+
import { RdxTabsContextService } from './src/tabs-context.service';
|
4
|
+
import { RdxTabsListDirective } from './src/tabs-list.directive';
|
5
|
+
import { RdxTabsRootDirective } from './src/tabs-root.directive';
|
6
|
+
import { RdxTabsTriggerDirective } from './src/tabs-trigger.directive';
|
7
|
+
|
8
|
+
export * from './src/tabs-content.directive';
|
9
|
+
export * from './src/tabs-context.service';
|
10
|
+
export * from './src/tabs-list.directive';
|
11
|
+
export * from './src/tabs-root.directive';
|
12
|
+
export * from './src/tabs-trigger.directive';
|
13
|
+
|
14
|
+
const tabsImports = [
|
15
|
+
RdxTabsRootDirective,
|
16
|
+
RdxTabsContentDirective,
|
17
|
+
RdxTabsListDirective,
|
18
|
+
RdxTabsTriggerDirective
|
19
|
+
];
|
20
|
+
|
21
|
+
@NgModule({
|
22
|
+
imports: [...tabsImports],
|
23
|
+
exports: [...tabsImports],
|
24
|
+
providers: [RdxTabsContextService]
|
25
|
+
})
|
26
|
+
export class RdxTabsModule {}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { computed, Directive, inject, input } from '@angular/core';
|
2
|
+
import { TABS_CONTEXT_TOKEN } from './tabs-context.service';
|
3
|
+
|
4
|
+
@Directive({
|
5
|
+
selector: '[rdxTabsContent]',
|
6
|
+
standalone: true,
|
7
|
+
host: {
|
8
|
+
role: 'tabpanel',
|
9
|
+
tabindex: '0',
|
10
|
+
'[id]': 'tabsContext.getBaseId()',
|
11
|
+
'[attr.aria-labelledby]': 'tabsContext.getBaseId()',
|
12
|
+
'[attr.data-state]': 'selected() ? "active" : "inactive"',
|
13
|
+
'[attr.data-orientation]': 'tabsContext.orientation$()',
|
14
|
+
'[hidden]': '!selected()'
|
15
|
+
}
|
16
|
+
})
|
17
|
+
export class RdxTabsContentDirective {
|
18
|
+
protected readonly tabsContext = inject(TABS_CONTEXT_TOKEN);
|
19
|
+
|
20
|
+
readonly value = input.required<string>();
|
21
|
+
|
22
|
+
protected readonly selected = computed(() => this.tabsContext.value$() === this.value());
|
23
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { computed, Injectable, InjectionToken, signal } from '@angular/core';
|
2
|
+
|
3
|
+
export const TABS_CONTEXT_TOKEN = new InjectionToken<RdxTabsContextService>('TabsContext');
|
4
|
+
|
5
|
+
@Injectable({
|
6
|
+
providedIn: 'root'
|
7
|
+
})
|
8
|
+
export class RdxTabsContextService {
|
9
|
+
private baseId = this.generateId();
|
10
|
+
private value = signal<string | undefined>(undefined);
|
11
|
+
private orientation = signal<string>('horizontal');
|
12
|
+
private dir = signal<string | undefined>(undefined);
|
13
|
+
private activationMode = signal<string>('automatic');
|
14
|
+
|
15
|
+
readonly value$ = computed(() => this.value());
|
16
|
+
readonly orientation$ = computed(() => this.orientation());
|
17
|
+
readonly dir$ = computed(() => this.dir());
|
18
|
+
readonly activationMode$ = computed(() => this.activationMode());
|
19
|
+
|
20
|
+
setValue(value: string) {
|
21
|
+
this.value.set(value);
|
22
|
+
}
|
23
|
+
|
24
|
+
setOrientation(orientation: string) {
|
25
|
+
this.orientation.set(orientation);
|
26
|
+
}
|
27
|
+
|
28
|
+
setDir(dir: string) {
|
29
|
+
this.dir.set(dir);
|
30
|
+
}
|
31
|
+
|
32
|
+
setActivationMode(mode: string) {
|
33
|
+
this.activationMode.set(mode);
|
34
|
+
}
|
35
|
+
|
36
|
+
getBaseId() {
|
37
|
+
return this.baseId;
|
38
|
+
}
|
39
|
+
|
40
|
+
private generateId() {
|
41
|
+
return `tabs-${Math.random().toString(36).substr(2, 9)}`;
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Directive, inject } from '@angular/core';
|
2
|
+
import { TABS_CONTEXT_TOKEN } from './tabs-context.service';
|
3
|
+
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
5
|
+
interface TabsListProps {
|
6
|
+
// When true, keyboard navigation will loop from last tab to first, and vice versa.
|
7
|
+
loop?: boolean;
|
8
|
+
}
|
9
|
+
|
10
|
+
@Directive({
|
11
|
+
selector: '[rdxTabsList]',
|
12
|
+
standalone: true,
|
13
|
+
host: {
|
14
|
+
role: 'tablist',
|
15
|
+
'[attr.aria-orientation]': 'tabsContext.orientation$()',
|
16
|
+
'[attr.data-orientation]': 'tabsContext.orientation$()'
|
17
|
+
}
|
18
|
+
})
|
19
|
+
export class RdxTabsListDirective {
|
20
|
+
protected readonly tabsContext = inject(TABS_CONTEXT_TOKEN);
|
21
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { Directive, effect, EventEmitter, inject, Input, OnInit, Output } from '@angular/core';
|
2
|
+
import { RdxTabsContextService, TABS_CONTEXT_TOKEN } from './tabs-context.service';
|
3
|
+
|
4
|
+
export interface TabsProps {
|
5
|
+
/** The value for the selected tab, if controlled */
|
6
|
+
value?: string;
|
7
|
+
/** The value of the tab to select by default, if uncontrolled */
|
8
|
+
defaultValue?: string;
|
9
|
+
/** A function called when a new tab is selected */
|
10
|
+
onValueChange?: (value: string) => void;
|
11
|
+
/**
|
12
|
+
* The orientation the tabs are layed out.
|
13
|
+
* Mainly so arrow navigation is done accordingly (left & right vs. up & down)
|
14
|
+
* @defaultValue horizontal
|
15
|
+
*/
|
16
|
+
orientation?: string;
|
17
|
+
/**
|
18
|
+
* The direction of navigation between toolbar items.
|
19
|
+
*/
|
20
|
+
dir?: string;
|
21
|
+
/**
|
22
|
+
* Whether a tab is activated automatically or manually.
|
23
|
+
* @defaultValue automatic
|
24
|
+
* */
|
25
|
+
activationMode?: 'automatic' | 'manual';
|
26
|
+
}
|
27
|
+
|
28
|
+
@Directive({
|
29
|
+
selector: '[rdxTabsRoot]',
|
30
|
+
standalone: true,
|
31
|
+
providers: [{ provide: TABS_CONTEXT_TOKEN, useExisting: RdxTabsContextService }],
|
32
|
+
host: {
|
33
|
+
'[attr.data-orientation]': 'orientation',
|
34
|
+
'[attr.dir]': 'dir'
|
35
|
+
}
|
36
|
+
})
|
37
|
+
export class RdxTabsRootDirective implements OnInit {
|
38
|
+
private readonly tabsContext = inject(TABS_CONTEXT_TOKEN);
|
39
|
+
|
40
|
+
@Input() value?: string;
|
41
|
+
@Input() defaultValue?: string;
|
42
|
+
@Input() orientation = 'horizontal';
|
43
|
+
@Input() dir?: string;
|
44
|
+
|
45
|
+
// Event handler called when the value changes.
|
46
|
+
@Output() onValueChange = new EventEmitter<string>();
|
47
|
+
|
48
|
+
constructor() {
|
49
|
+
effect(() => {
|
50
|
+
const value = this.tabsContext.value$();
|
51
|
+
if (value !== undefined) {
|
52
|
+
this.onValueChange.emit(value);
|
53
|
+
}
|
54
|
+
});
|
55
|
+
}
|
56
|
+
|
57
|
+
ngOnInit() {
|
58
|
+
this.tabsContext.setOrientation(this.orientation);
|
59
|
+
|
60
|
+
if (this.dir) {
|
61
|
+
this.tabsContext.setDir(this.dir);
|
62
|
+
}
|
63
|
+
|
64
|
+
if (this.value) {
|
65
|
+
this.tabsContext.setValue(this.value);
|
66
|
+
} else if (this.defaultValue) {
|
67
|
+
this.tabsContext.setValue(this.defaultValue);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { BooleanInput } from '@angular/cdk/coercion';
|
2
|
+
import { booleanAttribute, computed, Directive, inject, input, InputSignalWithTransform } from '@angular/core';
|
3
|
+
import { TABS_CONTEXT_TOKEN } from './tabs-context.service';
|
4
|
+
|
5
|
+
interface TabsTriggerProps {
|
6
|
+
// When true, prevents the user from interacting with the tab.
|
7
|
+
disabled: InputSignalWithTransform<boolean, BooleanInput>;
|
8
|
+
}
|
9
|
+
|
10
|
+
@Directive({
|
11
|
+
selector: '[rdxTabsTrigger]',
|
12
|
+
standalone: true,
|
13
|
+
host: {
|
14
|
+
type: 'button',
|
15
|
+
role: 'tab',
|
16
|
+
'[id]': 'triggerId',
|
17
|
+
'[attr.aria-selected]': 'selected()',
|
18
|
+
'[attr.aria-controls]': 'contentId()',
|
19
|
+
'[attr.data-disabled]': "disabled() ? '' : undefined",
|
20
|
+
'[attr.data-state]': "selected() ? 'active' : 'inactive'",
|
21
|
+
'(mousedown)': 'onMouseDown($event)',
|
22
|
+
'(keydown)': 'onKeyDown($event)'
|
23
|
+
}
|
24
|
+
})
|
25
|
+
export class RdxTabsTriggerDirective implements TabsTriggerProps {
|
26
|
+
protected readonly tabsContext = inject(TABS_CONTEXT_TOKEN);
|
27
|
+
|
28
|
+
// A unique value that associates the trigger with a content.
|
29
|
+
readonly value = input.required<string>();
|
30
|
+
|
31
|
+
// When true, prevents the user from interacting with the tab.
|
32
|
+
readonly disabled = input<boolean, BooleanInput>(false, {
|
33
|
+
transform: booleanAttribute
|
34
|
+
});
|
35
|
+
|
36
|
+
protected readonly contentId = computed(() => `${this.tabsContext.getBaseId()}-content-${this.value()}`);
|
37
|
+
protected readonly triggerId = computed(() => `${this.tabsContext.getBaseId()}-trigger-${this.value}`);
|
38
|
+
|
39
|
+
protected readonly selected = computed(() => this.tabsContext.value$() === this.value());
|
40
|
+
|
41
|
+
protected onMouseDown(event: MouseEvent) {
|
42
|
+
if (!this.disabled() && event.button === 0 && !event.ctrlKey) {
|
43
|
+
this.tabsContext?.setValue(this.value());
|
44
|
+
} else {
|
45
|
+
// prevent focus to avoid accidental activation
|
46
|
+
event.preventDefault();
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
protected onKeyDown(event: KeyboardEvent) {
|
51
|
+
if ([' ', 'Enter'].includes(event.key)) {
|
52
|
+
this.tabsContext?.setValue(this.value());
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|