@radix-ng/primitives 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/checkbox/src/checkbox-indicator.directive.d.ts +6 -0
- package/checkbox/src/checkbox.directive.d.ts +71 -0
- package/checkbox/src/checkbox.token.d.ts +4 -0
- package/esm2022/checkbox/index.mjs +4 -0
- package/esm2022/checkbox/radix-ng-primitives-checkbox.mjs +5 -0
- package/esm2022/checkbox/src/checkbox-indicator.directive.mjs +23 -0
- package/esm2022/checkbox/src/checkbox.directive.mjs +135 -0
- package/esm2022/checkbox/src/checkbox.token.mjs +6 -0
- package/esm2022/index.mjs +2 -0
- package/esm2022/label/index.mjs +2 -0
- package/esm2022/label/radix-ng-primitives-label.mjs +5 -0
- package/esm2022/label/src/label.directive.mjs +46 -0
- package/esm2022/progress/index.mjs +3 -0
- package/esm2022/progress/radix-ng-primitives-progress.mjs +5 -0
- package/esm2022/progress/src/progress-indicator.directive.mjs +23 -0
- package/esm2022/progress/src/progress.directive.mjs +62 -0
- package/esm2022/progress/src/progress.token.mjs +6 -0
- package/esm2022/radix-ng-primitives.mjs +5 -0
- package/esm2022/roving-focus/index.mjs +5 -0
- package/esm2022/roving-focus/radix-ng-primitives-roving-focus.mjs +5 -0
- package/esm2022/roving-focus/src/roving-focus-group.directive.mjs +115 -0
- package/esm2022/roving-focus/src/roving-focus-group.token.mjs +9 -0
- package/esm2022/roving-focus/src/roving-focus-item.directive.mjs +91 -0
- package/esm2022/roving-focus/src/roving-focus-item.token.mjs +6 -0
- package/esm2022/separator/index.mjs +2 -0
- package/esm2022/separator/radix-ng-primitives-separator.mjs +5 -0
- package/esm2022/separator/src/separator.directive.mjs +37 -0
- package/esm2022/switch/index.mjs +4 -0
- package/esm2022/switch/radix-ng-primitives-switch.mjs +5 -0
- package/esm2022/switch/src/switch-thumb.directive.mjs +25 -0
- package/esm2022/switch/src/switch.directive.mjs +125 -0
- package/esm2022/switch/src/switch.token.mjs +6 -0
- package/esm2022/visually-hidden/index.mjs +2 -0
- package/esm2022/visually-hidden/radix-ng-primitives-visually-hidden.mjs +5 -0
- package/esm2022/visually-hidden/src/visually-hidden.directive.mjs +42 -0
- package/fesm2022/radix-ng-primitives-checkbox.mjs +166 -0
- package/fesm2022/radix-ng-primitives-checkbox.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-label.mjs +53 -0
- package/fesm2022/radix-ng-primitives-label.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-progress.mjs +93 -0
- package/fesm2022/radix-ng-primitives-progress.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-roving-focus.mjs +220 -0
- package/fesm2022/radix-ng-primitives-roving-focus.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-separator.mjs +44 -0
- package/fesm2022/radix-ng-primitives-separator.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-switch.mjs +158 -0
- package/fesm2022/radix-ng-primitives-switch.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives-visually-hidden.mjs +49 -0
- package/fesm2022/radix-ng-primitives-visually-hidden.mjs.map +1 -0
- package/fesm2022/radix-ng-primitives.mjs +4 -0
- package/fesm2022/radix-ng-primitives.mjs.map +1 -0
- package/label/src/label.directive.d.ts +14 -0
- package/package.json +82 -24
- package/progress/src/progress-indicator.directive.d.ts +6 -0
- package/progress/src/progress.directive.d.ts +26 -0
- package/progress/src/progress.token.d.ts +4 -0
- package/roving-focus/src/roving-focus-group.directive.d.ts +55 -0
- package/roving-focus/src/roving-focus-group.token.d.ts +7 -0
- package/roving-focus/src/roving-focus-item.directive.d.ts +52 -0
- package/roving-focus/src/roving-focus-item.token.d.ts +4 -0
- package/separator/src/separator.directive.d.ts +16 -0
- package/switch/src/switch-thumb.directive.d.ts +9 -0
- package/switch/src/switch.directive.d.ts +73 -0
- package/switch/src/switch.token.d.ts +4 -0
- package/visually-hidden/src/visually-hidden.directive.d.ts +11 -0
- package/.docs/overview/accessibility.docs.mdx +0 -45
- package/.docs/overview/installation.docs.mdx +0 -15
- package/.docs/overview/introduction.docs.mdx +0 -59
- package/.docs/utils/storybook.ts +0 -30
- package/.eslintrc.json +0 -56
- package/.storybook/helpers/bages-config.ts +0 -43
- package/.storybook/main.ts +0 -24
- package/.storybook/manager-head.html +0 -76
- package/.storybook/manager.ts +0 -6
- package/.storybook/preview.ts +0 -58
- package/.storybook/rdxTheme.ts +0 -8
- package/.storybook/tsconfig.json +0 -20
- package/CHANGELOG.md +0 -6
- package/checkbox/ng-package.json +0 -5
- package/checkbox/src/checkbox-indicator.directive.ts +0 -15
- package/checkbox/src/checkbox.directive.ts +0 -138
- package/checkbox/src/checkbox.token.ts +0 -8
- package/checkbox/stories/checkbox.component.ts +0 -50
- package/checkbox/stories/checkbox.stories.ts +0 -29
- package/checkbox/stories/style.css +0 -265
- package/jest.config.ts +0 -22
- package/label/ng-package.json +0 -5
- package/label/src/label.directive.ts +0 -36
- package/label/stories/label.docs.mdx +0 -40
- package/label/stories/label.stories.ts +0 -63
- package/ng-package.json +0 -7
- package/progress/ng-package.json +0 -5
- package/progress/src/progress-indicator.directive.ts +0 -15
- package/progress/src/progress.directive.ts +0 -51
- package/progress/src/progress.token.ts +0 -8
- package/progress/stories/progress.docs.mdx +0 -66
- package/progress/stories/progress.stories.ts +0 -61
- package/project.json +0 -90
- package/roving-focus/ng-package.json +0 -5
- package/roving-focus/src/roving-focus-group.directive.ts +0 -135
- package/roving-focus/src/roving-focus-group.token.ts +0 -13
- package/roving-focus/src/roving-focus-item.directive.ts +0 -98
- package/roving-focus/src/roving-focus-item.token.ts +0 -10
- package/separator/ng-package.json +0 -5
- package/separator/src/separator.directive.spec.ts +0 -59
- package/separator/src/separator.directive.ts +0 -24
- package/separator/stories/separator.docs.mdx +0 -38
- package/separator/stories/separator.stories.ts +0 -91
- package/switch/ng-package.json +0 -5
- package/switch/src/switch-thumb.directive.ts +0 -17
- package/switch/src/switch.directive.ts +0 -132
- package/switch/src/switch.token.ts +0 -8
- package/switch/stories/switch.docs.mdx +0 -74
- package/switch/stories/switch.stories.ts +0 -76
- package/test-setup.ts +0 -8
- package/tsconfig.json +0 -32
- package/tsconfig.lib.json +0 -19
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -21
- package/visually-hidden/ng-package.json +0 -5
- package/visually-hidden/src/visually-hidden.directive.spec.ts +0 -48
- package/visually-hidden/src/visually-hidden.directive.ts +0 -35
- package/visually-hidden/stories/visually-hidden.docs.mdx +0 -35
- /package/checkbox/{index.ts → index.d.ts} +0 -0
- /package/{index.ts → index.d.ts} +0 -0
- /package/label/{index.ts → index.d.ts} +0 -0
- /package/progress/{index.ts → index.d.ts} +0 -0
- /package/roving-focus/{index.ts → index.d.ts} +0 -0
- /package/separator/{index.ts → index.d.ts} +0 -0
- /package/switch/{index.ts → index.d.ts} +0 -0
- /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
|
-
};
|
package/switch/ng-package.json
DELETED
@@ -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
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
@@ -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,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
|
/package/{index.ts → index.d.ts}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|