@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 { CdkTrapFocus } from '@angular/cdk/a11y';
|
2
|
+
import { Directive, ElementRef, inject, Input, Renderer2 } from '@angular/core';
|
3
|
+
|
4
|
+
@Directive({
|
5
|
+
selector: '[rdxAlertDialogContent]',
|
6
|
+
hostDirectives: [
|
7
|
+
{
|
8
|
+
directive: CdkTrapFocus
|
9
|
+
}
|
10
|
+
],
|
11
|
+
standalone: true,
|
12
|
+
host: {
|
13
|
+
'[attr.data-state]': 'open',
|
14
|
+
'[attr.cdkTrapFocusAutoCapture]': 'true'
|
15
|
+
}
|
16
|
+
})
|
17
|
+
export class AlertDialogContentDirective {
|
18
|
+
private readonly renderer = inject(Renderer2);
|
19
|
+
private readonly elementRef = inject(ElementRef);
|
20
|
+
|
21
|
+
@Input() set maxWidth(value: string) {
|
22
|
+
this.renderer.setStyle(this.elementRef.nativeElement, 'maxWidth', value);
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Directive, inject, Input, TemplateRef, ViewContainerRef } from '@angular/core';
|
2
|
+
import { AlertDialogService } from './alert-dialog.service';
|
3
|
+
|
4
|
+
@Directive({
|
5
|
+
selector: '[rdxAlertDialogRoot]',
|
6
|
+
standalone: true
|
7
|
+
})
|
8
|
+
export class AlertDialogRootDirective {
|
9
|
+
private readonly viewContainerRef = inject(ViewContainerRef);
|
10
|
+
private readonly alertDialogService = inject(AlertDialogService);
|
11
|
+
|
12
|
+
@Input() set content(template: TemplateRef<any>) {
|
13
|
+
this.alertDialogService.setDialogContent(this.viewContainerRef, template);
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Directive, inject } from '@angular/core';
|
2
|
+
import { AlertDialogService } from './alert-dialog.service';
|
3
|
+
|
4
|
+
@Directive({
|
5
|
+
selector: '[rdxAlertDialogTrigger]',
|
6
|
+
standalone: true,
|
7
|
+
host: {
|
8
|
+
'(click)': 'handleClick()'
|
9
|
+
}
|
10
|
+
})
|
11
|
+
export class AlertDialogTriggerDirective {
|
12
|
+
private readonly alertDialogService = inject(AlertDialogService);
|
13
|
+
|
14
|
+
handleClick() {
|
15
|
+
this.alertDialogService.open();
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { Overlay, OverlayRef } from '@angular/cdk/overlay';
|
2
|
+
import { TemplatePortal } from '@angular/cdk/portal';
|
3
|
+
import { Injectable, TemplateRef, ViewContainerRef } from '@angular/core';
|
4
|
+
|
5
|
+
@Injectable({
|
6
|
+
providedIn: 'root'
|
7
|
+
})
|
8
|
+
export class AlertDialogService {
|
9
|
+
private overlayRef: OverlayRef | null | undefined;
|
10
|
+
private dialogContent:
|
11
|
+
| {
|
12
|
+
viewContainerRef: ViewContainerRef;
|
13
|
+
template: TemplateRef<any>;
|
14
|
+
}
|
15
|
+
| undefined;
|
16
|
+
|
17
|
+
constructor(private overlay: Overlay) {}
|
18
|
+
|
19
|
+
setDialogContent(viewContainerRef: ViewContainerRef, template: TemplateRef<any>) {
|
20
|
+
this.dialogContent = { viewContainerRef, template };
|
21
|
+
}
|
22
|
+
|
23
|
+
open() {
|
24
|
+
if (!this.dialogContent) {
|
25
|
+
throw new Error('Dialog content is not set');
|
26
|
+
}
|
27
|
+
|
28
|
+
this.overlayRef = this.overlay.create({
|
29
|
+
hasBackdrop: true,
|
30
|
+
backdropClass: 'cdk-overlay-dark-backdrop',
|
31
|
+
positionStrategy: this.overlay.position().global().centerHorizontally().centerVertically()
|
32
|
+
});
|
33
|
+
|
34
|
+
const templatePortal = new TemplatePortal(this.dialogContent.template, this.dialogContent.viewContainerRef);
|
35
|
+
this.overlayRef.attach(templatePortal);
|
36
|
+
|
37
|
+
this.overlayRef.keydownEvents().subscribe((event) => {
|
38
|
+
if (event.key === 'Escape' || event.code === 'Escape') {
|
39
|
+
this.close();
|
40
|
+
}
|
41
|
+
});
|
42
|
+
this.overlayRef.backdropClick().subscribe(() => this.close());
|
43
|
+
}
|
44
|
+
|
45
|
+
close() {
|
46
|
+
if (this.overlayRef) {
|
47
|
+
this.overlayRef.dispose();
|
48
|
+
this.overlayRef = null;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,139 @@
|
|
1
|
+
import { OverlayModule } from '@angular/cdk/overlay';
|
2
|
+
import { PortalModule } from '@angular/cdk/portal';
|
3
|
+
import { componentWrapperDecorator, Meta, moduleMetadata, StoryObj } from '@storybook/angular';
|
4
|
+
import { AlertDialogCancelDirective } from '../src/alert-dialog-cancel.directive';
|
5
|
+
import { AlertDialogContentDirective } from '../src/alert-dialog-content.directive';
|
6
|
+
import { AlertDialogRootDirective } from '../src/alert-dialog-root.directive';
|
7
|
+
import { AlertDialogTitleDirective } from '../src/alert-dialog-title.directive';
|
8
|
+
import { AlertDialogTriggerDirective } from '../src/alert-dialog-trigger.directive';
|
9
|
+
import { AlertDialogService } from '../src/alert-dialog.service';
|
10
|
+
|
11
|
+
export default {
|
12
|
+
title: 'Primitives/Alert Dialog',
|
13
|
+
decorators: [
|
14
|
+
moduleMetadata({
|
15
|
+
imports: [
|
16
|
+
AlertDialogContentDirective,
|
17
|
+
AlertDialogRootDirective,
|
18
|
+
AlertDialogTitleDirective,
|
19
|
+
AlertDialogTriggerDirective,
|
20
|
+
AlertDialogCancelDirective,
|
21
|
+
OverlayModule,
|
22
|
+
PortalModule
|
23
|
+
],
|
24
|
+
providers: [AlertDialogService]
|
25
|
+
}),
|
26
|
+
componentWrapperDecorator(
|
27
|
+
(story) =>
|
28
|
+
`
|
29
|
+
<div class="radix-themes light light-theme"
|
30
|
+
data-radius="medium"
|
31
|
+
data-scaling="100%">${story}</div>`
|
32
|
+
)
|
33
|
+
]
|
34
|
+
} as Meta;
|
35
|
+
|
36
|
+
type Story = StoryObj;
|
37
|
+
|
38
|
+
export const Default: Story = {
|
39
|
+
render: (args) => ({
|
40
|
+
props: args,
|
41
|
+
template: `
|
42
|
+
|
43
|
+
<div rdxAlertDialogRoot [content]="alertDialogContent">
|
44
|
+
<button rdxAlertDialogTrigger class="Button violet">Delete account</button>
|
45
|
+
<ng-template #alertDialogContent>
|
46
|
+
<div rdxAlertDialogContent maxWidth="450" class="AlertDialogContent">
|
47
|
+
<h2 rdxAlertDialogTitle class="AlertDialogTitle">Are you absolutely sure?</h2>
|
48
|
+
<p class="AlertDialogDescription">
|
49
|
+
This action cannot be undone. This will permanently delete your account and remove your data from our servers.
|
50
|
+
</p>
|
51
|
+
<div style="display: flex; gap: 3px; margin-top: 4px; justify-content: flex-end;">
|
52
|
+
<button rdxAlertDialogCancel class="Button mauve">Cancel</button>
|
53
|
+
<button class="Button red">Revoke access</button>
|
54
|
+
</div>
|
55
|
+
</div>
|
56
|
+
</ng-template>
|
57
|
+
</div>
|
58
|
+
|
59
|
+
<style>
|
60
|
+
|
61
|
+
.AlertDialogContent {
|
62
|
+
background-color: white;
|
63
|
+
border-radius: 6px;
|
64
|
+
box-shadow: hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px;
|
65
|
+
position: fixed;
|
66
|
+
top: 50%;
|
67
|
+
left: 50%;
|
68
|
+
transform: translate(-50%, -50%);
|
69
|
+
width: 90vw;
|
70
|
+
max-width: 500px;
|
71
|
+
max-height: 85vh;
|
72
|
+
padding: 25px;
|
73
|
+
animation: contentShow 150ms cubic-bezier(0.16, 1, 0.3, 1);
|
74
|
+
}
|
75
|
+
|
76
|
+
.AlertDialogTitle {
|
77
|
+
margin: 0;
|
78
|
+
color: var(--mauve-12);
|
79
|
+
font-size: 17px;
|
80
|
+
font-weight: 500;
|
81
|
+
}
|
82
|
+
|
83
|
+
.AlertDialogDescription {
|
84
|
+
margin-bottom: 20px;
|
85
|
+
color: var(--mauve-11);
|
86
|
+
font-size: 15px;
|
87
|
+
line-height: 1.5;
|
88
|
+
}
|
89
|
+
|
90
|
+
button {
|
91
|
+
all: unset;
|
92
|
+
}
|
93
|
+
Button {
|
94
|
+
display: inline-flex;
|
95
|
+
align-items: center;
|
96
|
+
justify-content: center;
|
97
|
+
border-radius: 4px;
|
98
|
+
padding: 0 15px;
|
99
|
+
font-size: 15px;
|
100
|
+
line-height: 1;
|
101
|
+
font-weight: 500;
|
102
|
+
height: 35px;
|
103
|
+
}
|
104
|
+
.Button.violet {
|
105
|
+
background-color: white;
|
106
|
+
color: var(--violet-11);
|
107
|
+
box-shadow: 0 2px 10px var(--black-a7);
|
108
|
+
}
|
109
|
+
.Button.violet:hover {
|
110
|
+
background-color: var(--mauve-3);
|
111
|
+
}
|
112
|
+
.Button.violet:focus {
|
113
|
+
box-shadow: 0 0 0 2px black;
|
114
|
+
}
|
115
|
+
.Button.red {
|
116
|
+
background-color: var(--red-4);
|
117
|
+
color: var(--red-11);
|
118
|
+
}
|
119
|
+
.Button.red:hover {
|
120
|
+
background-color: var(--red-5);
|
121
|
+
}
|
122
|
+
.Button.red:focus {
|
123
|
+
box-shadow: 0 0 0 2px var(--red-7);
|
124
|
+
}
|
125
|
+
.Button.mauve {
|
126
|
+
background-color: var(--mauve-4);
|
127
|
+
color: var(--mauve-11);
|
128
|
+
}
|
129
|
+
.Button.mauve:hover {
|
130
|
+
background-color: var(--mauve-5);
|
131
|
+
}
|
132
|
+
.Button.mauve:focus {
|
133
|
+
box-shadow: 0 0 0 2px var(--mauve-7);
|
134
|
+
}
|
135
|
+
</style>
|
136
|
+
|
137
|
+
`
|
138
|
+
})
|
139
|
+
};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { Component, PLATFORM_ID } from '@angular/core';
|
2
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
3
|
+
import { RdxAvatarFallbackDirective } from '../src/avatar-fallback.directive';
|
4
|
+
import { RdxAvatarRootDirective } from '../src/avatar-root.directive';
|
5
|
+
|
6
|
+
@Component({
|
7
|
+
selector: 'rdx-mock-component',
|
8
|
+
standalone: true,
|
9
|
+
imports: [RdxAvatarFallbackDirective, RdxAvatarRootDirective],
|
10
|
+
template: `
|
11
|
+
<span rdxAvatarRoot>
|
12
|
+
<span rdxAvatarFallback>fallback</span>
|
13
|
+
<span rdxAvatarFallback>fallback2</span>
|
14
|
+
</span>
|
15
|
+
`
|
16
|
+
})
|
17
|
+
class RdxMockComponent {}
|
18
|
+
|
19
|
+
describe('RdxAvatarFallbackDirective', () => {
|
20
|
+
let component: RdxMockComponent;
|
21
|
+
let fixture: ComponentFixture<RdxMockComponent>;
|
22
|
+
|
23
|
+
beforeEach(() => {
|
24
|
+
fixture = TestBed.overrideProvider(PLATFORM_ID, { useValue: 'browser' }).createComponent(RdxMockComponent);
|
25
|
+
component = fixture.componentInstance;
|
26
|
+
});
|
27
|
+
|
28
|
+
it('should compile', () => {
|
29
|
+
expect(component).toBeTruthy();
|
30
|
+
});
|
31
|
+
});
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { Component } from '@angular/core';
|
2
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
3
|
+
import { RdxAvatarFallbackDirective } from '../src/avatar-fallback.directive';
|
4
|
+
import { RdxAvatarImageDirective } from '../src/avatar-image.directive';
|
5
|
+
import { RdxAvatarRootDirective } from '../src/avatar-root.directive';
|
6
|
+
|
7
|
+
@Component({
|
8
|
+
selector: 'rdx-mock-component',
|
9
|
+
standalone: true,
|
10
|
+
imports: [RdxAvatarImageDirective, RdxAvatarRootDirective, RdxAvatarFallbackDirective],
|
11
|
+
template: `
|
12
|
+
<span rdxAvatarRoot>
|
13
|
+
<img
|
14
|
+
rdxAvatarImage
|
15
|
+
alt="Angular Logo"
|
16
|
+
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg=="
|
17
|
+
/>
|
18
|
+
<span rdxAvatarFallback>Angular Logo</span>
|
19
|
+
</span>
|
20
|
+
`
|
21
|
+
})
|
22
|
+
class RdxMockComponent {}
|
23
|
+
|
24
|
+
describe('RdxAvatarImageDirective', () => {
|
25
|
+
let component: RdxMockComponent;
|
26
|
+
let fixture: ComponentFixture<RdxMockComponent>;
|
27
|
+
|
28
|
+
beforeEach(() => {
|
29
|
+
fixture = TestBed.createComponent(RdxMockComponent);
|
30
|
+
component = fixture.componentInstance;
|
31
|
+
});
|
32
|
+
|
33
|
+
it('should compile', () => {
|
34
|
+
expect(component).toBeTruthy();
|
35
|
+
});
|
36
|
+
});
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { isPlatformBrowser } from '@angular/common';
|
2
|
+
import { Directive, inject, Input, NgZone, numberAttribute, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core';
|
3
|
+
import { injectAvatar } from './avatar-root.directive';
|
4
|
+
import { injectAvatarConfig } from './avatar.config';
|
5
|
+
|
6
|
+
export interface RdxAvatarFallbackProps {
|
7
|
+
delayMs?: number;
|
8
|
+
}
|
9
|
+
|
10
|
+
@Directive({
|
11
|
+
selector: 'span[rdxAvatarFallback]',
|
12
|
+
exportAs: 'rdxAvatarFallback',
|
13
|
+
standalone: true,
|
14
|
+
host: {
|
15
|
+
'[style.display]': 'visible ? null : "none"'
|
16
|
+
}
|
17
|
+
})
|
18
|
+
export class RdxAvatarFallbackDirective implements RdxAvatarFallbackProps, OnInit, OnDestroy {
|
19
|
+
private readonly avatar = injectAvatar();
|
20
|
+
|
21
|
+
private readonly config = injectAvatarConfig();
|
22
|
+
|
23
|
+
private readonly ngZone = inject(NgZone);
|
24
|
+
|
25
|
+
private readonly platformId = inject(PLATFORM_ID);
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Define a delay before the fallback is shown.
|
29
|
+
* This is useful to only show the fallback for those with slower connections.
|
30
|
+
* @default 0
|
31
|
+
*/
|
32
|
+
@Input({ alias: 'rdxDelayMs', transform: numberAttribute }) delayMs: number = this.config.delayMs;
|
33
|
+
|
34
|
+
protected get visible(): boolean {
|
35
|
+
return this.delayElapsed && this.avatar._state() !== 'loaded';
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Determine the delay has elapsed, and we can show the fallback.
|
40
|
+
*/
|
41
|
+
private delayElapsed = false;
|
42
|
+
|
43
|
+
private timeoutId: ReturnType<typeof setTimeout> | null = null;
|
44
|
+
|
45
|
+
ngOnInit(): void {
|
46
|
+
if (isPlatformBrowser(this.platformId)) {
|
47
|
+
this.ngZone.runOutsideAngular(() => {
|
48
|
+
this.timeoutId = globalThis.setTimeout(() => {
|
49
|
+
this.ngZone.run(() => {
|
50
|
+
this.delayElapsed = true;
|
51
|
+
});
|
52
|
+
}, this.delayMs);
|
53
|
+
});
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
ngOnDestroy(): void {
|
58
|
+
if (isPlatformBrowser(this.platformId) && this.timeoutId !== null) {
|
59
|
+
globalThis.clearTimeout(this.timeoutId);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { Directive, ElementRef, EventEmitter, inject, OnInit, Output } from '@angular/core';
|
2
|
+
import { injectAvatar, RdxImageLoadingStatus } from './avatar-root.directive';
|
3
|
+
|
4
|
+
export interface RdxAvatarImageProps {
|
5
|
+
onLoadingStatusChange?: EventEmitter<RdxImageLoadingStatus>;
|
6
|
+
}
|
7
|
+
|
8
|
+
@Directive({
|
9
|
+
selector: 'img[rdxAvatarImage]',
|
10
|
+
exportAs: 'rdxAvatarImage',
|
11
|
+
standalone: true,
|
12
|
+
host: {
|
13
|
+
'(load)': 'onLoad()',
|
14
|
+
'(error)': 'onError()'
|
15
|
+
}
|
16
|
+
})
|
17
|
+
export class RdxAvatarImageDirective implements RdxAvatarImageProps, OnInit {
|
18
|
+
private readonly avatar = injectAvatar();
|
19
|
+
|
20
|
+
private readonly elementRef = inject<ElementRef<HTMLImageElement>>(ElementRef);
|
21
|
+
|
22
|
+
/**
|
23
|
+
* By default, it will only render when it has loaded.
|
24
|
+
* You can use the `onLoadingStatusChange` handler if you need more control.
|
25
|
+
*/
|
26
|
+
@Output() onLoadingStatusChange = new EventEmitter<RdxImageLoadingStatus>();
|
27
|
+
|
28
|
+
ngOnInit(): void {
|
29
|
+
this.avatar._setState('loading');
|
30
|
+
|
31
|
+
if (!this.nativeElement.src) {
|
32
|
+
this.avatar._setState('error');
|
33
|
+
}
|
34
|
+
|
35
|
+
if (this.nativeElement.complete) {
|
36
|
+
this.avatar._setState('loaded');
|
37
|
+
}
|
38
|
+
|
39
|
+
this.onLoadingStatusChange.emit(this.avatar._state());
|
40
|
+
}
|
41
|
+
|
42
|
+
protected onLoad(): void {
|
43
|
+
this.avatar._setState('loaded');
|
44
|
+
this.onLoadingStatusChange.emit('loaded');
|
45
|
+
}
|
46
|
+
|
47
|
+
protected onError(): void {
|
48
|
+
this.avatar._setState('error');
|
49
|
+
this.onLoadingStatusChange.emit('error');
|
50
|
+
}
|
51
|
+
|
52
|
+
get nativeElement() {
|
53
|
+
return this.elementRef.nativeElement;
|
54
|
+
}
|
55
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { Directive, inject, InjectionToken, signal } from '@angular/core';
|
2
|
+
|
3
|
+
const RdxAvatarToken = new InjectionToken<RdxAvatarRootDirective>('RdxAvatarToken');
|
4
|
+
|
5
|
+
export function injectAvatar(): RdxAvatarRootDirective {
|
6
|
+
return inject(RdxAvatarToken);
|
7
|
+
}
|
8
|
+
|
9
|
+
export type RdxImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
10
|
+
|
11
|
+
@Directive({
|
12
|
+
selector: 'span[rdxAvatarRoot]',
|
13
|
+
exportAs: 'rdxAvatarRoot',
|
14
|
+
standalone: true,
|
15
|
+
providers: [{ provide: RdxAvatarToken, useExisting: RdxAvatarRootDirective }]
|
16
|
+
})
|
17
|
+
export class RdxAvatarRootDirective {
|
18
|
+
/**
|
19
|
+
* A readonly signal property that holds the current state of image loading.
|
20
|
+
* To set a new status, use the `setState` method of the component.
|
21
|
+
* @internal
|
22
|
+
*/
|
23
|
+
readonly _state = signal<RdxImageLoadingStatus>('idle');
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Set the avatar state.
|
27
|
+
* @param state The new image loading status to set. This value should be one of the predefined states
|
28
|
+
* in the `ImageLoadingStatus`
|
29
|
+
* @returns void This method does not return a value.
|
30
|
+
* @internal
|
31
|
+
*/
|
32
|
+
_setState(state: RdxImageLoadingStatus): void {
|
33
|
+
this._state.set(state);
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { inject, InjectionToken, Provider } from '@angular/core';
|
2
|
+
|
3
|
+
export interface RdxAvatarConfig {
|
4
|
+
/**
|
5
|
+
* Define a delay before the fallback is shown.
|
6
|
+
* This is useful to only show the fallback for those with slower connections.
|
7
|
+
* @default 0
|
8
|
+
*/
|
9
|
+
delayMs: number;
|
10
|
+
}
|
11
|
+
|
12
|
+
export const defaultAvatarConfig: RdxAvatarConfig = {
|
13
|
+
delayMs: 0
|
14
|
+
};
|
15
|
+
|
16
|
+
export const RdxAvatarConfigToken = new InjectionToken<RdxAvatarConfig>('RdxAvatarConfigToken');
|
17
|
+
|
18
|
+
export function provideRdxAvatarConfig(config: Partial<RdxAvatarConfig>): Provider[] {
|
19
|
+
return [
|
20
|
+
{
|
21
|
+
provide: RdxAvatarConfigToken,
|
22
|
+
useValue: { ...defaultAvatarConfig, ...config }
|
23
|
+
}
|
24
|
+
];
|
25
|
+
}
|
26
|
+
|
27
|
+
export function injectAvatarConfig(): RdxAvatarConfig {
|
28
|
+
return inject(RdxAvatarConfigToken, { optional: true }) ?? defaultAvatarConfig;
|
29
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { Canvas, Meta } from '@storybook/blocks';
|
2
|
+
import * as AvatarDirectiveStories from './avatar.stories';
|
3
|
+
|
4
|
+
<Meta title="Primitives/Avatar" />
|
5
|
+
|
6
|
+
# Avatar
|
7
|
+
|
8
|
+
#### An image element with a fallback for representing the user.
|
9
|
+
|
10
|
+
<Canvas sourceState="hidden" of={AvatarDirectiveStories.Default} />
|
11
|
+
|
12
|
+
## Features
|
13
|
+
|
14
|
+
- ✅ Automatic and manual control over when the image renders.
|
15
|
+
- ✅ Fallback part accepts any children.
|
16
|
+
- ✅ Optionally delayMs fallback rendering to avoid content flashing.
|
17
|
+
|
18
|
+
## Global Configuration
|
19
|
+
|
20
|
+
You can configure the default options for all avatars in your application by using the `provideRdxAvatarConfig` function in a providers array.
|
21
|
+
|
22
|
+
```ts
|
23
|
+
import { provideRdxAvatarConfig } from '@radix-ng/primitives/avatar';
|
24
|
+
|
25
|
+
bootstrapApplication(AppComponent, {
|
26
|
+
providers: [provideRdxAvatarConfig({ delayMs: 1000 })]
|
27
|
+
});
|
28
|
+
```
|
29
|
+
|
30
|
+
## Anatomy
|
31
|
+
|
32
|
+
```html
|
33
|
+
<span rdxAvatarRoot>
|
34
|
+
<img rdxAvatarImage src="..." alt="..." />
|
35
|
+
<span rdxAvatarFallback>Angular</span>
|
36
|
+
</span>
|
37
|
+
```
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import { componentWrapperDecorator, Meta, moduleMetadata, StoryObj } from '@storybook/angular';
|
2
|
+
import { RdxAvatarFallbackDirective } from '../src/avatar-fallback.directive';
|
3
|
+
import { RdxAvatarImageDirective } from '../src/avatar-image.directive';
|
4
|
+
import { RdxAvatarRootDirective } from '../src/avatar-root.directive';
|
5
|
+
|
6
|
+
export default {
|
7
|
+
title: 'Primitives/Avatar',
|
8
|
+
decorators: [
|
9
|
+
moduleMetadata({
|
10
|
+
imports: [RdxAvatarRootDirective, RdxAvatarImageDirective, RdxAvatarFallbackDirective]
|
11
|
+
}),
|
12
|
+
componentWrapperDecorator(
|
13
|
+
(story) =>
|
14
|
+
`<div class="radix-themes light light-theme radix-themes-default-fonts"
|
15
|
+
data-accent-color="indigo"
|
16
|
+
data-radius="medium"
|
17
|
+
data-scaling="100%">${story}</div>`
|
18
|
+
)
|
19
|
+
]
|
20
|
+
} as Meta;
|
21
|
+
|
22
|
+
type Story = StoryObj;
|
23
|
+
|
24
|
+
export const Default: Story = {
|
25
|
+
render: () => ({
|
26
|
+
template: `
|
27
|
+
<div style=" display: flex; gap: 20px">
|
28
|
+
<span rdxAvatarRoot class="AvatarRoot">
|
29
|
+
<img rdxAvatarImage
|
30
|
+
src="https://images.unsplash.com/photo-1492633423870-43d1cd2775eb?&w=128&h=128&dpr=2&q=80"
|
31
|
+
alt="Colm Tuite"
|
32
|
+
class="AvatarImage" />
|
33
|
+
<span rdxAvatarFallback class="AvatarFallback" rdxDelayMs="600">CT</span>
|
34
|
+
</span>
|
35
|
+
|
36
|
+
<span rdxAvatarRoot class="AvatarRoot">
|
37
|
+
<img rdxAvatarImage
|
38
|
+
class="AvatarImage"
|
39
|
+
src="https://images.unsplash.com/photo-1511485977113-f34c92461ad9?ixlib=rb-1.2.1&w=128&h=128&dpr=2&q=80"
|
40
|
+
alt="Pedro Duarte"
|
41
|
+
/>
|
42
|
+
<span rdxAvatarFallback class="AvatarFallback" rdxDelayMs="600">
|
43
|
+
JD
|
44
|
+
</span>
|
45
|
+
</span>
|
46
|
+
<span rdxAvatarRoot class="AvatarRoot">
|
47
|
+
<span rdxAvatarFallback class="AvatarFallback">PD</span>
|
48
|
+
</span>
|
49
|
+
</div>
|
50
|
+
<style>
|
51
|
+
.AvatarRoot {
|
52
|
+
display: inline-flex;
|
53
|
+
align-items: center;
|
54
|
+
justify-content: center;
|
55
|
+
vertical-align: middle;
|
56
|
+
overflow: hidden;
|
57
|
+
user-select: none;
|
58
|
+
width: 45px;
|
59
|
+
height: 45px;
|
60
|
+
border-radius: 100%;
|
61
|
+
background-color: var(--black-a3);
|
62
|
+
}
|
63
|
+
|
64
|
+
.AvatarImage {
|
65
|
+
width: 100%;
|
66
|
+
height: 100%;
|
67
|
+
object-fit: cover;
|
68
|
+
border-radius: inherit;
|
69
|
+
}
|
70
|
+
|
71
|
+
.AvatarFallback {
|
72
|
+
width: 100%;
|
73
|
+
height: 100%;
|
74
|
+
display: flex;
|
75
|
+
align-items: center;
|
76
|
+
justify-content: center;
|
77
|
+
background-color: white;
|
78
|
+
color: var(--violet-11);
|
79
|
+
font-size: 15px;
|
80
|
+
line-height: 1;
|
81
|
+
font-weight: 500;
|
82
|
+
}
|
83
|
+
|
84
|
+
</style>
|
85
|
+
`
|
86
|
+
})
|
87
|
+
};
|
File without changes
|