@radix-ng/primitives 0.1.0 → 0.2.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.
Files changed (148) hide show
  1. package/README.md +2 -4
  2. package/checkbox/src/checkbox-indicator.directive.d.ts +6 -0
  3. package/checkbox/src/checkbox.directive.d.ts +71 -0
  4. package/checkbox/src/checkbox.token.d.ts +4 -0
  5. package/esm2022/checkbox/index.mjs +4 -0
  6. package/esm2022/checkbox/radix-ng-primitives-checkbox.mjs +5 -0
  7. package/esm2022/checkbox/src/checkbox-indicator.directive.mjs +23 -0
  8. package/esm2022/checkbox/src/checkbox.directive.mjs +135 -0
  9. package/esm2022/checkbox/src/checkbox.token.mjs +6 -0
  10. package/esm2022/index.mjs +2 -0
  11. package/esm2022/label/index.mjs +2 -0
  12. package/esm2022/label/radix-ng-primitives-label.mjs +5 -0
  13. package/esm2022/label/src/label.directive.mjs +46 -0
  14. package/esm2022/progress/index.mjs +3 -0
  15. package/esm2022/progress/radix-ng-primitives-progress.mjs +5 -0
  16. package/esm2022/progress/src/progress-indicator.directive.mjs +23 -0
  17. package/esm2022/progress/src/progress.directive.mjs +62 -0
  18. package/esm2022/progress/src/progress.token.mjs +6 -0
  19. package/esm2022/radio/index.mjs +6 -0
  20. package/esm2022/radio/radix-ng-primitives-radio.mjs +5 -0
  21. package/esm2022/radio/src/radio-group.directive.mjs +108 -0
  22. package/esm2022/radio/src/radio-group.token.mjs +6 -0
  23. package/esm2022/radio/src/radio-indicator.directive.mjs +30 -0
  24. package/esm2022/radio/src/radio-item.directive.mjs +79 -0
  25. package/esm2022/radio/src/radio-item.token.mjs +6 -0
  26. package/esm2022/radix-ng-primitives.mjs +5 -0
  27. package/esm2022/roving-focus/index.mjs +5 -0
  28. package/esm2022/roving-focus/radix-ng-primitives-roving-focus.mjs +5 -0
  29. package/esm2022/roving-focus/src/roving-focus-group.directive.mjs +115 -0
  30. package/esm2022/roving-focus/src/roving-focus-group.token.mjs +9 -0
  31. package/esm2022/roving-focus/src/roving-focus-item.directive.mjs +91 -0
  32. package/esm2022/roving-focus/src/roving-focus-item.token.mjs +6 -0
  33. package/esm2022/separator/index.mjs +2 -0
  34. package/esm2022/separator/radix-ng-primitives-separator.mjs +5 -0
  35. package/esm2022/separator/src/separator.directive.mjs +37 -0
  36. package/esm2022/switch/index.mjs +4 -0
  37. package/esm2022/switch/radix-ng-primitives-switch.mjs +5 -0
  38. package/esm2022/switch/src/switch-thumb.directive.mjs +25 -0
  39. package/esm2022/switch/src/switch.directive.mjs +125 -0
  40. package/esm2022/switch/src/switch.token.mjs +6 -0
  41. package/esm2022/visually-hidden/index.mjs +2 -0
  42. package/esm2022/visually-hidden/radix-ng-primitives-visually-hidden.mjs +5 -0
  43. package/esm2022/visually-hidden/src/visually-hidden.directive.mjs +42 -0
  44. package/fesm2022/radix-ng-primitives-checkbox.mjs +166 -0
  45. package/fesm2022/radix-ng-primitives-checkbox.mjs.map +1 -0
  46. package/fesm2022/radix-ng-primitives-label.mjs +53 -0
  47. package/fesm2022/radix-ng-primitives-label.mjs.map +1 -0
  48. package/fesm2022/radix-ng-primitives-progress.mjs +93 -0
  49. package/fesm2022/radix-ng-primitives-progress.mjs.map +1 -0
  50. package/fesm2022/radix-ng-primitives-radio.mjs +221 -0
  51. package/fesm2022/radix-ng-primitives-radio.mjs.map +1 -0
  52. package/fesm2022/radix-ng-primitives-roving-focus.mjs +220 -0
  53. package/fesm2022/radix-ng-primitives-roving-focus.mjs.map +1 -0
  54. package/fesm2022/radix-ng-primitives-separator.mjs +44 -0
  55. package/fesm2022/radix-ng-primitives-separator.mjs.map +1 -0
  56. package/fesm2022/radix-ng-primitives-switch.mjs +158 -0
  57. package/fesm2022/radix-ng-primitives-switch.mjs.map +1 -0
  58. package/fesm2022/radix-ng-primitives-visually-hidden.mjs +49 -0
  59. package/fesm2022/radix-ng-primitives-visually-hidden.mjs.map +1 -0
  60. package/fesm2022/radix-ng-primitives.mjs +4 -0
  61. package/fesm2022/radix-ng-primitives.mjs.map +1 -0
  62. package/label/src/label.directive.d.ts +14 -0
  63. package/package.json +88 -24
  64. package/progress/src/progress-indicator.directive.d.ts +6 -0
  65. package/progress/src/progress.directive.d.ts +26 -0
  66. package/progress/src/progress.token.d.ts +4 -0
  67. package/radio/README.md +1 -0
  68. package/radio/index.d.ts +5 -0
  69. package/radio/src/radio-group.directive.d.ts +65 -0
  70. package/radio/src/radio-group.token.d.ts +4 -0
  71. package/radio/src/radio-indicator.directive.d.ts +13 -0
  72. package/radio/src/radio-item.directive.d.ts +36 -0
  73. package/radio/src/radio-item.token.d.ts +4 -0
  74. package/roving-focus/src/roving-focus-group.directive.d.ts +55 -0
  75. package/roving-focus/src/roving-focus-group.token.d.ts +7 -0
  76. package/roving-focus/src/roving-focus-item.directive.d.ts +52 -0
  77. package/roving-focus/src/roving-focus-item.token.d.ts +4 -0
  78. package/separator/src/separator.directive.d.ts +16 -0
  79. package/switch/src/switch-thumb.directive.d.ts +9 -0
  80. package/switch/src/switch.directive.d.ts +73 -0
  81. package/switch/src/switch.token.d.ts +4 -0
  82. package/visually-hidden/src/visually-hidden.directive.d.ts +11 -0
  83. package/.docs/overview/accessibility.docs.mdx +0 -45
  84. package/.docs/overview/installation.docs.mdx +0 -15
  85. package/.docs/overview/introduction.docs.mdx +0 -59
  86. package/.docs/utils/storybook.ts +0 -30
  87. package/.eslintrc.json +0 -56
  88. package/.storybook/helpers/bages-config.ts +0 -43
  89. package/.storybook/main.ts +0 -24
  90. package/.storybook/manager-head.html +0 -76
  91. package/.storybook/manager.ts +0 -6
  92. package/.storybook/preview.ts +0 -58
  93. package/.storybook/rdxTheme.ts +0 -8
  94. package/.storybook/tsconfig.json +0 -20
  95. package/CHANGELOG.md +0 -6
  96. package/checkbox/ng-package.json +0 -5
  97. package/checkbox/src/checkbox-indicator.directive.ts +0 -15
  98. package/checkbox/src/checkbox.directive.ts +0 -138
  99. package/checkbox/src/checkbox.token.ts +0 -8
  100. package/checkbox/stories/checkbox.component.ts +0 -50
  101. package/checkbox/stories/checkbox.stories.ts +0 -29
  102. package/checkbox/stories/style.css +0 -265
  103. package/jest.config.ts +0 -22
  104. package/label/ng-package.json +0 -5
  105. package/label/src/label.directive.ts +0 -36
  106. package/label/stories/label.docs.mdx +0 -40
  107. package/label/stories/label.stories.ts +0 -63
  108. package/ng-package.json +0 -7
  109. package/progress/ng-package.json +0 -5
  110. package/progress/src/progress-indicator.directive.ts +0 -15
  111. package/progress/src/progress.directive.ts +0 -51
  112. package/progress/src/progress.token.ts +0 -8
  113. package/progress/stories/progress.docs.mdx +0 -66
  114. package/progress/stories/progress.stories.ts +0 -61
  115. package/project.json +0 -90
  116. package/roving-focus/ng-package.json +0 -5
  117. package/roving-focus/src/roving-focus-group.directive.ts +0 -135
  118. package/roving-focus/src/roving-focus-group.token.ts +0 -13
  119. package/roving-focus/src/roving-focus-item.directive.ts +0 -98
  120. package/roving-focus/src/roving-focus-item.token.ts +0 -10
  121. package/separator/ng-package.json +0 -5
  122. package/separator/src/separator.directive.spec.ts +0 -59
  123. package/separator/src/separator.directive.ts +0 -24
  124. package/separator/stories/separator.docs.mdx +0 -38
  125. package/separator/stories/separator.stories.ts +0 -91
  126. package/switch/ng-package.json +0 -5
  127. package/switch/src/switch-thumb.directive.ts +0 -17
  128. package/switch/src/switch.directive.ts +0 -132
  129. package/switch/src/switch.token.ts +0 -8
  130. package/switch/stories/switch.docs.mdx +0 -74
  131. package/switch/stories/switch.stories.ts +0 -76
  132. package/test-setup.ts +0 -8
  133. package/tsconfig.json +0 -32
  134. package/tsconfig.lib.json +0 -19
  135. package/tsconfig.lib.prod.json +0 -9
  136. package/tsconfig.spec.json +0 -21
  137. package/visually-hidden/ng-package.json +0 -5
  138. package/visually-hidden/src/visually-hidden.directive.spec.ts +0 -48
  139. package/visually-hidden/src/visually-hidden.directive.ts +0 -35
  140. package/visually-hidden/stories/visually-hidden.docs.mdx +0 -35
  141. /package/checkbox/{index.ts → index.d.ts} +0 -0
  142. /package/{index.ts → index.d.ts} +0 -0
  143. /package/label/{index.ts → index.d.ts} +0 -0
  144. /package/progress/{index.ts → index.d.ts} +0 -0
  145. /package/roving-focus/{index.ts → index.d.ts} +0 -0
  146. /package/separator/{index.ts → index.d.ts} +0 -0
  147. /package/switch/{index.ts → index.d.ts} +0 -0
  148. /package/visually-hidden/{index.ts → index.d.ts} +0 -0
@@ -1,91 +0,0 @@
1
- import { LabelDirective } from '../../label';
2
- import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
3
- import { CommonModule } from '@angular/common';
4
- import { SeparatorDirective } from '../src/separator.directive';
5
-
6
- export default {
7
- component: SeparatorDirective,
8
- title: 'Primitives/Separator',
9
- decorators: [
10
- moduleMetadata({
11
- imports: [SeparatorDirective, CommonModule]
12
- })
13
- ]
14
- } as Meta<LabelDirective>;
15
-
16
- type Story = StoryObj<LabelDirective>;
17
-
18
- export const Default: Story = {
19
- parameters: {
20
- backgrounds: {
21
- default: 'black',
22
- values: [
23
- {
24
- name: 'black',
25
- value: 'linear-gradient(330deg,color(display-p3 0.523 0.318 0.751) 0,color(display-p3 0.276 0.384 0.837) 100%)'
26
- }
27
- ]
28
- }
29
- },
30
- render: () => ({
31
- template: `
32
- <style>
33
-
34
- .SeparatorRoot {
35
- background-color: white;
36
- }
37
- .SeparatorRoot[data-orientation='horizontal'] {
38
- height: 1px;
39
- width: 100%;
40
- }
41
- .SeparatorRoot[data-orientation='vertical'] {
42
- height: 100%;
43
- width: 1px;
44
- }
45
-
46
- .Text {
47
- color: white;
48
- font-size: 15px;
49
- line-height: 20px;
50
- }
51
-
52
- </style>
53
- <div style="width: 100%; max-width: 300px; margin: 0 15px;">
54
- <div class="Text">
55
- Radix Primitives
56
- </div>
57
- <div class="Text" style="font-weight: 500;">
58
- An open-source UI component library.
59
- </div>
60
- <div rdxSeparator
61
- class="SeparatorRoot"
62
- style="margin: 15px 0;"
63
- ></div>
64
- <div style="display: flex; height: 1.25rem; align-items: center;">
65
- <div class="Text">
66
- Blog
67
- </div>
68
- <div rdxSeparator
69
- class="SeparatorRoot"
70
- rdxSeparatorDecorative="decorative"
71
- rdxSeparatorOrientation="vertical"
72
- style="margin: 0 15px;"
73
- ></div>
74
- <div class="Text">
75
- Docs
76
- </div>
77
- <div rdxSeparator
78
- class="SeparatorRoot"
79
- rdxSeparatorDecorative="decorative"
80
- rdxSeparatorOrientation="vertical"
81
- style="margin: 0 15px;"
82
- ></div>
83
- <div class="Text">
84
- Source
85
- </div>
86
- </div>
87
- </div>
88
-
89
- `
90
- })
91
- };
@@ -1,5 +0,0 @@
1
- {
2
- "lib": {
3
- "entryFile": "index.ts"
4
- }
5
- }
@@ -1,17 +0,0 @@
1
- import { Directive } from '@angular/core';
2
- import { injectSwitch } from './switch.token';
3
-
4
- @Directive({
5
- selector: '[rdxSwitchThumb]',
6
- standalone: true,
7
- host: {
8
- '[attr.data-state]': 'switch.checked ? "checked" : "unchecked"',
9
- '[attr.data-disabled]': 'switch.disabled ? "true" : null'
10
- }
11
- })
12
- export class SwitchThumbDirective {
13
- /**
14
- * Access the switch directive.
15
- */
16
- protected readonly switch = injectSwitch();
17
- }
@@ -1,132 +0,0 @@
1
- import {
2
- Directive,
3
- ElementRef,
4
- EventEmitter,
5
- HostListener,
6
- Input,
7
- Output,
8
- booleanAttribute,
9
- inject
10
- } from '@angular/core';
11
- import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
12
- import { SwitchToken } from './switch.token';
13
-
14
- @Directive({
15
- selector: '[rdxSwitch]',
16
- standalone: true,
17
- providers: [
18
- { provide: SwitchToken, useExisting: SwitchDirective },
19
- { provide: NG_VALUE_ACCESSOR, useExisting: SwitchDirective, multi: true }
20
- ],
21
- host: {
22
- role: 'switch',
23
- '[attr.type]': 'isButton ? "button" : null',
24
- '[attr.aria-checked]': 'checked',
25
- '[attr.data-state]': 'checked ? "checked" : "unchecked"',
26
- '[attr.data-disabled]': 'disabled ? "true" : null',
27
- '[attr.disabled]': 'isButton && disabled ? disabled : null',
28
- '(focus)': 'onTouched?.()'
29
- }
30
- })
31
- export class SwitchDirective implements ControlValueAccessor {
32
- /**
33
- * Access the element ref.
34
- */
35
- private readonly elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
36
-
37
- /**
38
- * Determine if the switch is a button
39
- */
40
- protected isButton = this.elementRef.nativeElement.tagName === 'BUTTON';
41
-
42
- /**
43
- * Determine if the switch is checked.
44
- * The controlled state of the switch.
45
- * @default false
46
- */
47
- @Input({ transform: booleanAttribute }) checked = false;
48
-
49
- /**
50
- * Determine if the switch is disabled.
51
- * When true, prevents the user from interacting with the switch.
52
- * @default false
53
- */
54
- @Input({ transform: booleanAttribute }) disabled = false;
55
-
56
- /**
57
- * Event emitted when the checked state changes.
58
- */
59
- @Output() readonly checkedChange = new EventEmitter<boolean>();
60
-
61
- /**
62
- * Store the onChange callback.
63
- */
64
- private onChange?: (checked: boolean) => void;
65
-
66
- /**
67
- * Store the onTouched callback.
68
- */
69
- protected onTouched?: () => void;
70
-
71
- /**
72
- * Register the onChange callback.
73
- * @param fn The onChange callback.
74
- * @internal
75
- */
76
- registerOnChange(fn: (checked: boolean) => void): void {
77
- this.onChange = fn;
78
- }
79
-
80
- /**
81
- * Register the onTouched callback.
82
- * @param fn The onTouched callback.
83
- * @internal
84
- */
85
- registerOnTouched(fn: () => void): void {
86
- this.onTouched = fn;
87
- }
88
-
89
- /**
90
- * Write the value to the checked state.
91
- * @param checked The checked state.
92
- * @internal
93
- */
94
- writeValue(checked: boolean): void {
95
- this.checked = checked;
96
- }
97
-
98
- /**
99
- * Set the disabled state.
100
- * @param isDisabled The disabled state.
101
- * @internal
102
- */
103
- setDisabledState(isDisabled: boolean): void {
104
- this.disabled = isDisabled;
105
- }
106
-
107
- /**
108
- * Toggle the checked state.
109
- */
110
- @HostListener('click')
111
- toggle(): void {
112
- if (this.disabled) {
113
- return;
114
- }
115
-
116
- this.checked = !this.checked;
117
- this.checkedChange.emit(this.checked);
118
- this.onChange?.(this.checked);
119
- }
120
-
121
- /**
122
- * Handle the keydown event.
123
- */
124
- @HostListener('keydown.space')
125
- protected onKeyDown(): void {
126
- // If the switch is not a button then the space key will not toggle the checked state automatically,
127
- // so we need to do it manually.
128
- if (!this.isButton) {
129
- this.toggle();
130
- }
131
- }
132
- }
@@ -1,8 +0,0 @@
1
- import { InjectionToken, inject } from '@angular/core';
2
- import type { SwitchDirective } from './switch.directive';
3
-
4
- export const SwitchToken = new InjectionToken<SwitchDirective>('SwitchToken');
5
-
6
- export function injectSwitch(): SwitchDirective {
7
- return inject(SwitchToken);
8
- }
@@ -1,74 +0,0 @@
1
- import { ArgTypes, Canvas, Markdown, Meta } from '@storybook/addon-docs';
2
- import * as SwitchDirectiveStories from "./switch.stories";
3
- import { SwitchDirective } from '../src/switch.directive';
4
- import { switchExclude } from '../../.docs/utils/storybook';
5
-
6
- <Meta
7
- title="Primitives/Switch"
8
- />
9
-
10
- # Switch
11
- #### A control that allows the user to toggle between checked and not checked.
12
-
13
- <Canvas sourceState='hidden' of={SwitchDirectiveStories.Default}></Canvas>
14
-
15
- ## Features
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 { SwitchDirective, SwitchThumbDirective } from '@radix-ng/primitives/switch';
25
- ```
26
-
27
- ## Examples
28
-
29
- ```html
30
- <label rdxLabel htmlFor="airplane-mode">Airplane mode</label>
31
- <button rdxSwitch [(checked)]="checked" id="airplane-mode">
32
- <span rdxSwitchThumb></span>
33
- </button>
34
-
35
- ```
36
- ## API Reference
37
-
38
- ### SwitchDirective
39
- <ArgTypes exclude={switchExclude} of={SwitchDirective} />
40
-
41
- <Markdown>
42
- {`
43
- | Data Attribute | Value |
44
- | ----------- | --------- |
45
- | [data-state] | "checked" or "unchecked" |
46
- | [data-disabled] | Present when disabled |
47
- `}
48
- </Markdown>
49
-
50
- ### ThumbDirective
51
-
52
- <Markdown>
53
- {`
54
- | Data Attribute | Value |
55
- | ----------- | --------- |
56
- | [data-state] | "checked" or "unchecked" |
57
- | [data-disabled] | Present when disabled |
58
- `}
59
- </Markdown>
60
-
61
- ## Accessibility
62
-
63
- Adheres to the [`switch` role requirements](https://www.w3.org/WAI/ARIA/apg/patterns/switch).
64
-
65
- ### Keyboard Interactions
66
-
67
- <Markdown>
68
- {`
69
- | Key | Description |
70
- | ----------- | --------- |
71
- | Space | Toggles the component's state. |
72
- | Enter | Toggles the component's state. |
73
- `}
74
- </Markdown>
@@ -1,76 +0,0 @@
1
- import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
2
-
3
- import { LabelDirective } from '../../label';
4
- import { SwitchDirective } from '../src/switch.directive';
5
- import { SwitchThumbDirective } from '../src/switch-thumb.directive';
6
-
7
- export default {
8
- title: 'Primitives/Switch',
9
- decorators: [
10
- moduleMetadata({
11
- imports: [LabelDirective, SwitchDirective, SwitchThumbDirective]
12
- })
13
- ]
14
- } as Meta;
15
-
16
- type Story = StoryObj;
17
-
18
- export const Default: Story = {
19
- render: () => ({
20
- template: `
21
- <style>
22
- button {
23
- all: unset;
24
- }
25
-
26
- .SwitchRoot {
27
- width: 42px;
28
- height: 25px;
29
- background-color: color(display-p3 0 0 0/0.7);
30
- border-radius: 9999px;
31
- margin-left: 15px;
32
- position: relative;
33
- box-shadow: 0 2px 10px color(display-p3 0 0 0/0.5);
34
- -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
35
- }
36
- .SwitchRoot:focus {
37
- box-shadow: 0 0 0 2px black;
38
- }
39
- .SwitchRoot[data-state='checked'] {
40
- background-color: black;
41
- }
42
-
43
- .SwitchThumb {
44
- display: block;
45
- width: 21px;
46
- height: 21px;
47
- background-color: white;
48
- border-radius: 9999px;
49
- box-shadow: 0 2px 2px color(display-p3 0 0 0/0.5);
50
- transition: transform 100ms;
51
- transform: translateX(2px);
52
- will-change: transform;
53
- }
54
- .SwitchThumb[data-state='checked'] {
55
- transform: translateX(19px);
56
- }
57
-
58
- .Label {
59
- color: white;
60
- font-size: 15px;
61
- line-height: 1;
62
- display: flex;
63
- align-items: center;
64
- }
65
-
66
- </style>
67
-
68
- <label rdxLabel htmlFor="airplane-mode" class="Label">
69
- Airplane mode
70
- <button rdxSwitch [(checked)]="checked" id="airplane-mode" class="SwitchRoot">
71
- <span rdxSwitchThumb class="SwitchThumb"></span>
72
- </button>
73
- </label>
74
- `
75
- })
76
- };
package/test-setup.ts DELETED
@@ -1,8 +0,0 @@
1
- // @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
2
- globalThis.ngJest = {
3
- testEnvironmentOptions: {
4
- errorOnUnknownElements: true,
5
- errorOnUnknownProperties: true
6
- }
7
- };
8
- import 'jest-preset-angular/setup-jest';
package/tsconfig.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2022",
4
- "useDefineForClassFields": false,
5
- "forceConsistentCasingInFileNames": true,
6
- "strict": true,
7
- "noImplicitOverride": true,
8
- "noPropertyAccessFromIndexSignature": true,
9
- "noImplicitReturns": true,
10
- "noFallthroughCasesInSwitch": true
11
- },
12
- "files": [],
13
- "include": [],
14
- "references": [
15
- {
16
- "path": "./tsconfig.lib.json"
17
- },
18
- {
19
- "path": "./tsconfig.spec.json"
20
- },
21
- {
22
- "path": "./.storybook/tsconfig.json"
23
- }
24
- ],
25
- "extends": "../../tsconfig.base.json",
26
- "angularCompilerOptions": {
27
- "enableI18nLegacyMessageIdFormat": false,
28
- "strictInjectionParameters": true,
29
- "strictInputAccessModifiers": true,
30
- "strictTemplates": true
31
- }
32
- }
package/tsconfig.lib.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "declarationMap": true,
7
- "inlineSources": true,
8
- "types": []
9
- },
10
- "exclude": [
11
- "**/*.spec.ts",
12
- "test-setup.ts",
13
- "jest.config.ts",
14
- "**/*.test.ts",
15
- "**/*.stories.ts",
16
- "**/*.stories.js"
17
- ],
18
- "include": ["**/*.ts"]
19
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.lib.json",
3
- "compilerOptions": {
4
- "declarationMap": false
5
- },
6
- "angularCompilerOptions": {
7
- "compilationMode": "partial"
8
- }
9
- }
@@ -1,21 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "module": "commonjs",
6
- "target": "es2016",
7
- "types": [
8
- "jest",
9
- "node"
10
- ]
11
- },
12
- "files": [
13
- "src/test-setup.ts"
14
- ],
15
- "include": [
16
- "jest.config.ts",
17
- "src/**/*.test.ts",
18
- "src/**/*.spec.ts",
19
- "src/**/*.d.ts"
20
- ]
21
- }
@@ -1,5 +0,0 @@
1
- {
2
- "lib": {
3
- "entryFile": "index.ts"
4
- }
5
- }
@@ -1,48 +0,0 @@
1
- import { VisuallyHiddenDirective } from './visually-hidden.directive';
2
- import { ComponentFixture, TestBed } from '@angular/core/testing';
3
- import { Component, DebugElement } from '@angular/core';
4
- import { By } from '@angular/platform-browser';
5
-
6
- @Component({
7
- template: '<span rdxVisuallyHidden>Hidden content</span>'
8
- })
9
- class TestComponent {}
10
-
11
- describe('VisuallyHiddenDirective', () => {
12
- let component: TestComponent;
13
- let fixture: ComponentFixture<TestComponent>;
14
- let span: DebugElement;
15
-
16
- beforeEach(async () => {
17
- await TestBed.configureTestingModule({
18
- declarations: [TestComponent],
19
- imports: [VisuallyHiddenDirective]
20
- }).compileComponents();
21
- });
22
-
23
- beforeEach(() => {
24
- fixture = TestBed.createComponent(TestComponent);
25
- component = fixture.componentInstance;
26
- span = fixture.debugElement.query(By.css('span'));
27
- fixture.detectChanges();
28
- });
29
-
30
- it('should set the element style to visually hide the content', () => {
31
- const element = span.nativeElement as HTMLElement;
32
- const styles = element.style;
33
-
34
- expect(styles.position).toBe('absolute');
35
- expect(styles.border).toBe('0px');
36
- expect(styles.width).toBe('1px');
37
- expect(styles.height).toBe('1px');
38
- expect(styles.padding).toBe('0px');
39
- expect(styles.margin).toBe('-1px');
40
- expect(styles.overflow).toBe('hidden');
41
- expect(styles.clip).toBe('rect(0px, 0px, 0px, 0px)');
42
- expect(styles.whiteSpace).toBe('nowrap');
43
- expect(styles.wordWrap).toBe('normal');
44
- expect(styles.outline).toBe('none');
45
- expect(styles.appearance).toBe('none');
46
- expect(styles.left).toBe('0px');
47
- });
48
- });
@@ -1,35 +0,0 @@
1
- import { Directive, ElementRef, OnInit, inject } from '@angular/core';
2
-
3
- @Directive({
4
- selector: '[rdxVisuallyHidden]',
5
- standalone: true
6
- })
7
- export class VisuallyHiddenDirective implements OnInit {
8
- /**
9
- * Access the element.
10
- */
11
- private readonly element = inject<ElementRef<HTMLElement>>(ElementRef);
12
-
13
- ngOnInit(): void {
14
- // hide the element
15
- Object.assign(this.element.nativeElement.style, {
16
- position: 'absolute',
17
- border: 0,
18
- width: '1px',
19
- height: '1px',
20
- padding: 0,
21
- margin: '-1px',
22
- overflow: 'hidden',
23
- clip: 'rect(0, 0, 0, 0)',
24
- whiteSpace: 'nowrap',
25
- wordWrap: 'normal',
26
- // Avoid browsers rendering the focus ring in some cases.
27
- outline: 'none',
28
- appearance: 'none',
29
- // Avoid some cases where the browser will still render the native controls
30
- '-webkit-appearance': 'none',
31
- '-moz-appearance': 'none',
32
- left: 0
33
- });
34
- }
35
- }
@@ -1,35 +0,0 @@
1
- import { ArgTypes, Meta } from '@storybook/addon-docs';
2
-
3
- <Meta
4
- title="Utilities/Visually Hidden"
5
- />
6
-
7
- # Visually Hidden
8
- #### Hides content from the screen in an accessible way.
9
-
10
-
11
- ## Features
12
- - ✅ Visually hides content while preserving it for assistive technology.
13
-
14
-
15
- ## Import
16
-
17
- Get started with importing the directive:
18
-
19
- ```typescript
20
- import { VisuallyHiddenDirective } from '@radix-ng/primitives/visually-hidden';
21
- ```
22
-
23
- ## Examples
24
-
25
- ```html
26
- <button aria-label="Open menu">
27
- <span rdxVisuallyHidden>Open menu</span>
28
- <svg> <!-- Menu Icon --> </svg>
29
- </button>
30
-
31
- ```
32
-
33
- ## Accessibility
34
-
35
- This is useful in certain scenarios as an alternative to traditional labelling with aria-label or aria-labelledby.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes