@design-system-rte/angular 0.2.0-rc2 → 0.2.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.
Files changed (77) hide show
  1. package/ng-package.json +10 -0
  2. package/package.json +4 -17
  3. package/src/lib/components/button/button.component.html +10 -0
  4. package/src/lib/components/button/button.component.scss +156 -0
  5. package/src/lib/components/button/button.component.spec.ts +22 -0
  6. package/src/lib/components/button/button.component.stories.ts +99 -0
  7. package/src/lib/components/button/button.component.ts +27 -0
  8. package/src/lib/components/checkbox/checkbox.component.html +31 -0
  9. package/src/lib/components/checkbox/checkbox.component.scss +170 -0
  10. package/src/lib/components/checkbox/checkbox.component.stories.ts +126 -0
  11. package/src/lib/components/checkbox/checkbox.component.ts +34 -0
  12. package/src/lib/components/checkbox-group/checkbox-group.component.html +46 -0
  13. package/src/lib/components/checkbox-group/checkbox-group.component.scss +82 -0
  14. package/src/lib/components/checkbox-group/checkbox-group.component.stories.ts +121 -0
  15. package/src/lib/components/checkbox-group/checkbox-group.component.ts +28 -0
  16. package/src/lib/components/grid/col/col.directive.ts +35 -0
  17. package/src/lib/components/grid/grid.directive.stories.ts +150 -0
  18. package/src/lib/components/grid/grid.directive.ts +22 -0
  19. package/src/lib/components/icon/icon-map.ts +301 -0
  20. package/src/lib/components/icon/icon.component.html +1 -0
  21. package/src/lib/components/icon/icon.component.scss +3 -0
  22. package/src/lib/components/icon/icon.component.ts +58 -0
  23. package/src/lib/components/icon/icon.service.ts +33 -0
  24. package/src/lib/components/icon/icon.stories.ts +84 -0
  25. package/src/lib/components/link/link.component.html +6 -0
  26. package/src/lib/components/link/link.component.scss +108 -0
  27. package/src/lib/components/link/link.component.stories.ts +61 -0
  28. package/src/lib/components/link/link.component.ts +18 -0
  29. package/src/lib/components/radio-button/radio-button.component.html +24 -0
  30. package/src/lib/components/radio-button/radio-button.component.scss +135 -0
  31. package/src/lib/components/radio-button/radio-button.component.stories.ts +76 -0
  32. package/src/lib/components/radio-button/radio-button.component.ts +22 -0
  33. package/src/lib/components/radio-button-group/radio-button-group.component.html +45 -0
  34. package/src/lib/components/radio-button-group/radio-button-group.component.scss +82 -0
  35. package/src/lib/components/radio-button-group/radio-button-group.component.stories.ts +121 -0
  36. package/src/lib/components/radio-button-group/radio-button-group.component.ts +28 -0
  37. package/src/lib/components/tooltip/tooltip.component.html +7 -0
  38. package/src/lib/components/tooltip/tooltip.component.scss +118 -0
  39. package/src/lib/components/tooltip/tooltip.component.ts +16 -0
  40. package/src/lib/components/tooltip/tooltip.directive.stories.ts +218 -0
  41. package/src/lib/components/tooltip/tooltip.directive.ts +187 -0
  42. package/src/public-api.ts +9 -0
  43. package/tsconfig.lib.json +22 -0
  44. package/tsconfig.lib.prod.json +10 -0
  45. package/tsconfig.spec.json +14 -0
  46. package/design-system-rte-angular.d.ts.map +0 -1
  47. package/esm2022/design-system-rte-angular.mjs +0 -5
  48. package/esm2022/lib/components/button/button.component.mjs +0 -22
  49. package/esm2022/lib/components/checkbox/checkbox.component.mjs +0 -34
  50. package/esm2022/lib/components/checkbox-group/checkbox-group.component.mjs +0 -29
  51. package/esm2022/lib/components/grid/col/col.directive.mjs +0 -41
  52. package/esm2022/lib/components/grid/grid.directive.mjs +0 -30
  53. package/esm2022/lib/components/link/link.component.mjs +0 -19
  54. package/esm2022/lib/components/radio-button/radio-button.component.mjs +0 -24
  55. package/esm2022/lib/components/radio-button-group/radio-button-group.component.mjs +0 -29
  56. package/esm2022/public-api.mjs +0 -12
  57. package/fesm2022/design-system-rte-angular.mjs +0 -215
  58. package/fesm2022/design-system-rte-angular.mjs.map +0 -1
  59. package/index.d.ts +0 -6
  60. package/lib/components/button/button.component.d.ts +0 -13
  61. package/lib/components/button/button.component.d.ts.map +0 -1
  62. package/lib/components/checkbox/checkbox.component.d.ts +0 -19
  63. package/lib/components/checkbox/checkbox.component.d.ts.map +0 -1
  64. package/lib/components/checkbox-group/checkbox-group.component.d.ts +0 -19
  65. package/lib/components/checkbox-group/checkbox-group.component.d.ts.map +0 -1
  66. package/lib/components/grid/col/col.directive.d.ts +0 -15
  67. package/lib/components/grid/col/col.directive.d.ts.map +0 -1
  68. package/lib/components/grid/grid.directive.d.ts +0 -11
  69. package/lib/components/grid/grid.directive.d.ts.map +0 -1
  70. package/lib/components/link/link.component.d.ts +0 -10
  71. package/lib/components/link/link.component.d.ts.map +0 -1
  72. package/lib/components/radio-button/radio-button.component.d.ts +0 -14
  73. package/lib/components/radio-button/radio-button.component.d.ts.map +0 -1
  74. package/lib/components/radio-button-group/radio-button-group.component.d.ts +0 -19
  75. package/lib/components/radio-button-group/radio-button-group.component.d.ts.map +0 -1
  76. package/public-api.d.ts +0 -9
  77. package/public-api.d.ts.map +0 -1
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/lib",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ },
7
+ "allowedNonPeerDependencies": [
8
+ "@design-system-rte/core"
9
+ ]
10
+ }
package/package.json CHANGED
@@ -1,27 +1,14 @@
1
1
  {
2
2
  "name": "@design-system-rte/angular",
3
- "version": "0.2.0-rc2",
3
+ "version": "0.2.1",
4
4
  "description": "Angular components for the Design System RTE",
5
5
  "peerDependencies": {
6
6
  "@angular/common": "^17.3.0",
7
7
  "@angular/core": "^17.3.0"
8
8
  },
9
9
  "dependencies": {
10
- "@design-system-rte/core": "^0.1.2-rc3",
10
+ "@design-system-rte/core": "^0.3.0",
11
11
  "tslib": "^2.3.0"
12
12
  },
13
- "sideEffects": false,
14
- "module": "fesm2022/design-system-rte-angular.mjs",
15
- "typings": "index.d.ts",
16
- "exports": {
17
- "./package.json": {
18
- "default": "./package.json"
19
- },
20
- ".": {
21
- "types": "./index.d.ts",
22
- "esm2022": "./esm2022/design-system-rte-angular.mjs",
23
- "esm": "./esm2022/design-system-rte-angular.mjs",
24
- "default": "./fesm2022/design-system-rte-angular.mjs"
25
- }
26
- }
27
- }
13
+ "sideEffects": false
14
+ }
@@ -0,0 +1,10 @@
1
+ <button
2
+ class="rte-button {{ variant() }} size-{{ size() }}"
3
+ [attr.aria-label]="ariaLabel()"
4
+ [attr.aria-labelledby]="ariaLabelledBy()"
5
+ [attr.type]="buttonType()"
6
+ [disabled]="disabled()"
7
+ (click)="onClick($event)"
8
+ >
9
+ <span class="rte-button-label">{{ label() }}</span>
10
+ </button>
@@ -0,0 +1,156 @@
1
+ @use '@design-system-rte/core/tokens/main.scss' as *;
2
+
3
+ .rte-button {
4
+ align-items: center;
5
+ cursor: pointer;
6
+ display: inline-flex;
7
+ flex-shrink: 0;
8
+ justify-content: center;
9
+
10
+ &:focus-visible {
11
+ outline: 1px solid var(--border-brand-focused);
12
+ outline-offset: 4px;
13
+ }
14
+
15
+ &.size-s {
16
+ @include typography-button-s;
17
+ height: 24px;
18
+ border-radius: $radius-s;
19
+ padding: $positive-spacing_050 $positive-spacing_100;
20
+
21
+ .rte-button-label {
22
+ margin: 0 $positive-spacing_050;
23
+ }
24
+ }
25
+
26
+ &.size-m {
27
+ @include typography-button-m;
28
+ height: 32px;
29
+ border-radius: $radius-s;
30
+ padding: $positive-spacing_050 $positive-spacing_150;
31
+
32
+ .rte-button-label {
33
+ margin: 0 $positive-spacing_075;
34
+ }
35
+ }
36
+
37
+ &.size-l {
38
+ @include typography-button-l;
39
+ height: 40px;
40
+ border-radius: $radius-m;
41
+ padding: $positive-spacing_050 $positive-spacing_200;
42
+
43
+ .rte-button-label {
44
+ margin: 0 $positive-spacing_100;
45
+ }
46
+ }
47
+
48
+ &.primary {
49
+ border: var(--border-brand-default);
50
+ color: var(--content-primary-inverse);
51
+ background: var(--background-brand-default);
52
+
53
+ &:hover {
54
+ background: var(--background-brand-hover);
55
+ border: var(--background-brand-hover);
56
+ }
57
+
58
+ &:active {
59
+ background: var(--background-brand-pressed);
60
+ }
61
+
62
+ &:disabled {
63
+ background: var(--background-disabled);
64
+ border: solid 1px var(--border-disabled);
65
+ color: var(--content-disabled);
66
+ box-shadow: none;
67
+ cursor: default;
68
+ }
69
+ };
70
+
71
+ &.secondary {
72
+ background: var(--background-default);
73
+ border: solid 1px var(--border-brand-default);
74
+ color: var(--content-brand-default);
75
+
76
+ &:hover {
77
+ background: var(--background-brand-inverse-hover);
78
+ border: solid 1px var(--border-brand-default);
79
+ }
80
+
81
+ &:active {
82
+ border: var(--background-brand-inverse);
83
+ background: var(--background-brand-inverse-pressed);
84
+ }
85
+
86
+ &:disabled {
87
+ background: var(--background-disabled);
88
+ border: solid 1px var(--border-disabled);
89
+ color: var(--content-disabled);
90
+ cursor: default;
91
+ }
92
+ };
93
+
94
+ &.text {
95
+ background: transparent;
96
+ border: none;
97
+ color: var(--content-brand-default);
98
+
99
+ &:hover {
100
+ background: var(--background-brand-inverse-hover);
101
+ }
102
+
103
+ &:active {
104
+ background: var(--background-brand-inverse-pressed);
105
+ }
106
+
107
+ &:disabled {
108
+ background: var(--background-disabled);
109
+ color: var(--content-disabled);
110
+ cursor: default;
111
+ }
112
+ };
113
+
114
+ &.transparent {
115
+ background: transparent;
116
+ border: none;
117
+ color: var(--content-brand-default);
118
+
119
+ &:hover {
120
+ color: var(--content-brand-hover);
121
+ }
122
+
123
+ &:active {
124
+ color: var(--content-brand-pressed);
125
+ }
126
+
127
+ &:disabled {
128
+ color: var(--content-disabled);
129
+ box-shadow: none;
130
+ cursor: default;
131
+ }
132
+ };
133
+
134
+ &.danger {
135
+ background: var(--background-danger-default);
136
+ border: none;
137
+ color: var(--content-primary-inverse);
138
+ border-radius: $radius-m;
139
+
140
+ &:hover {
141
+ background: var(--background-danger-hover);
142
+ }
143
+
144
+ &:active {
145
+ background: var(--background-danger-pressed);
146
+ }
147
+
148
+ &:disabled {
149
+ background: var(--background-disabled);
150
+ border: var(--border-disabled);
151
+ color: var(--content-disabled);
152
+ box-shadow: none;
153
+ cursor: default;
154
+ }
155
+ }
156
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentFixture, TestBed } from "@angular/core/testing";
2
+
3
+ import { ButtonComponent } from "./button.component";
4
+
5
+ describe("ButtonComponent", () => {
6
+ let component: ButtonComponent;
7
+ let fixture: ComponentFixture<ButtonComponent>;
8
+
9
+ beforeEach(async () => {
10
+ await TestBed.configureTestingModule({
11
+ imports: [ButtonComponent],
12
+ }).compileComponents();
13
+
14
+ fixture = TestBed.createComponent(ButtonComponent);
15
+ component = fixture.componentInstance;
16
+ fixture.detectChanges();
17
+ });
18
+
19
+ it("should create", () => {
20
+ expect(component).toBeTruthy();
21
+ });
22
+ });
@@ -0,0 +1,99 @@
1
+ import { ENTER_KEY, TAB_KEY, SPACE_KEY } from "@design-system-rte/core/constants/keyboard.constants";
2
+ import type { Meta, StoryObj } from "@storybook/angular";
3
+ import { fn, userEvent, within, expect } from "@storybook/test";
4
+
5
+ import { ButtonComponent } from "./button.component";
6
+
7
+ const meta: Meta<ButtonComponent> = {
8
+ title: "Button",
9
+ component: ButtonComponent,
10
+ tags: ["autodocs"],
11
+ argTypes: {
12
+ variant: {
13
+ control: "select",
14
+ options: ["primary", "secondary", "text", "transparent", "danger"],
15
+ },
16
+ size: {
17
+ control: "select",
18
+ options: ["s", "m", "l"],
19
+ },
20
+ disabled: {
21
+ control: "boolean",
22
+ },
23
+ },
24
+ args: { click: fn() },
25
+ };
26
+
27
+ export default meta;
28
+ type Story = StoryObj<ButtonComponent>;
29
+
30
+ const mockFn = fn();
31
+
32
+ export const Default: Story = {
33
+ args: {
34
+ variant: "primary",
35
+ label: "Button",
36
+ click: mockFn,
37
+ },
38
+ play: async ({ canvasElement }) => {
39
+ const canvas = within(canvasElement);
40
+ const button = canvas.getByRole("button");
41
+ await userEvent.click(button);
42
+ expect(mockFn).toHaveBeenCalled();
43
+ button.blur();
44
+ },
45
+ };
46
+
47
+ export const Sizing: Story = {
48
+ render: (args) => ({
49
+ props: args,
50
+ template: `
51
+ <div style="display: flex; gap: 8px;">
52
+ <rte-button
53
+ size="s"
54
+ label="Small"
55
+ variant="primary"
56
+ data-testid="small-button"
57
+ />
58
+ <rte-button
59
+ size="m"
60
+ label="Medium"
61
+ variant="primary"
62
+ data-testid="medium-button"
63
+ />
64
+ <rte-button
65
+ size="l"
66
+ label="Large"
67
+ variant="primary"
68
+ data-testid="large-button"
69
+ />
70
+ </div>
71
+ `,
72
+ }),
73
+ play: async ({ canvasElement }) => {
74
+ const canvas = within(canvasElement);
75
+ const smallButton = canvas.getByTestId("small-button").getElementsByTagName("button")[0];
76
+ const mediumButton = canvas.getByTestId("medium-button").getElementsByTagName("button")[0];
77
+ const largeButton = canvas.getByTestId("large-button").getElementsByTagName("button")[0];
78
+
79
+ expect(smallButton.clientHeight).toBe(24);
80
+ expect(mediumButton.clientHeight).toBe(32);
81
+ expect(largeButton.clientHeight).toBe(40);
82
+ },
83
+ };
84
+
85
+ export const KeyboardInteraction: Story = {
86
+ args: {
87
+ ...Default.args,
88
+ },
89
+ play: async ({ canvasElement }) => {
90
+ const canvas = within(canvasElement);
91
+ const button = canvas.getByRole("button");
92
+ await userEvent.keyboard(TAB_KEY);
93
+ expect(button).toHaveFocus();
94
+ await userEvent.keyboard(ENTER_KEY);
95
+ await userEvent.keyboard(SPACE_KEY);
96
+ expect(mockFn).toHaveBeenCalledTimes(2);
97
+ button.blur();
98
+ },
99
+ };
@@ -0,0 +1,27 @@
1
+ import { Component, input, output } from "@angular/core";
2
+ import { ButtonSize, ButtonType, ButtonVariant } from "@design-system-rte/core/components/button/button.interface";
3
+
4
+ @Component({
5
+ selector: "rte-button",
6
+ imports: [],
7
+ standalone: true,
8
+ templateUrl: "./button.component.html",
9
+ styleUrl: "./button.component.scss",
10
+ })
11
+ export class ButtonComponent {
12
+ readonly label = input("");
13
+ readonly variant = input<ButtonVariant>("primary");
14
+ readonly size = input<ButtonSize>("m");
15
+ readonly disabled = input(false);
16
+ readonly icon = input<string>("");
17
+ readonly ariaLabel = input<string>("");
18
+ readonly ariaLabelledBy = input<string>("");
19
+ readonly buttonType = input<ButtonType>("button");
20
+
21
+ readonly click = output<void>();
22
+
23
+ onClick(event: MouseEvent | KeyboardEvent): void {
24
+ event.stopPropagation();
25
+ this.click.emit();
26
+ }
27
+ }
@@ -0,0 +1,31 @@
1
+ <div class="rte-checkbox-container">
2
+ <input
3
+ type="checkbox"
4
+ class="rte-checkbox"
5
+ [id]="id()"
6
+ [value]="value()"
7
+ [ngClass]="{'error': error(), 'read-only': readOnly()}"
8
+ [disabled]="disabled()"
9
+ [indeterminate]="indeterminate()"
10
+ [checked]="checked()"
11
+ (keydown)="onKeydown($event)"
12
+ />
13
+ <rte-icon class="rte-checkbox-icons rte-checkbox-icon-selected" name="check-small" [size]="16"/>
14
+ <rte-icon class="rte-checkbox-icons rte-checkbox-icon-indeterminated" name="check-indeterminate" [size]="16" />
15
+ <div class="rte-checkbox-text-container">
16
+ <label
17
+ *ngIf="showLabel()"
18
+ class="rte-checkbox-label"
19
+ [for]="id()"
20
+ [ngClass]="{
21
+ 'error': error(),
22
+ 'read-only': readOnly(),
23
+ 'disabled': disabled()
24
+ }"
25
+ >
26
+ {{ label() }}
27
+ </label>
28
+ <p class="rte-checkbox-description">{{ description() }}</p>
29
+ <p *ngIf="error() && errorMessage()" class="rte-checkbox-error">{{ errorMessage() }}</p>
30
+ </div>
31
+ </div>
@@ -0,0 +1,170 @@
1
+ @use '@design-system-rte/core/tokens/main.scss' as *;
2
+
3
+ @mixin checked-indeterminate-style {
4
+ border: 1px solid var(--content-brand-default);
5
+ background: var(--background-brand-default);
6
+
7
+ &:hover {
8
+ &:not(:disabled):not(:active)::before {
9
+ opacity: $opacity-20;
10
+ background: var(--background-brand-default);
11
+ }
12
+ }
13
+
14
+ &:disabled {
15
+ border: 1px solid var(--content-disabled);
16
+ background: var(--background-disabled);
17
+
18
+ ~ .rte-checkbox-icons {
19
+ color: var(--content-disabled);
20
+ }
21
+ }
22
+
23
+ &.error {
24
+ background: var(--background-danger-default);
25
+ }
26
+ }
27
+
28
+ .rte-checkbox-container {
29
+ display: flex;
30
+ gap: $positive-spacing-150;
31
+
32
+ .rte-checkbox {
33
+ appearance: none;
34
+ display: flex;
35
+ width: 16px;
36
+ height: 16px;
37
+ border-radius: $radius-xs;
38
+ border: 1px solid var(--content-tertiary);
39
+ opacity: $opacity-100;
40
+ background: var(--background-default);
41
+ align-items: center;
42
+ justify-content: center;
43
+ margin: $positive-spacing_050 0;
44
+
45
+ &::before {
46
+ content: '';
47
+ display: none;
48
+ position: absolute;
49
+ border-radius: $radius-pill;
50
+ background: var(--background-hover);
51
+ width: 32px;
52
+ height: 32px;
53
+ z-index: -1;
54
+ }
55
+
56
+ &:active::before {
57
+ opacity: $opacity-100;
58
+ transform: scale(0);
59
+ transition: transform 0s, opacity 0s;
60
+ }
61
+
62
+ &:focus-visible {
63
+ outline: 1px solid var(--border-brand-focused);
64
+ outline-offset: 4px;
65
+ }
66
+
67
+ &:hover {
68
+ cursor: pointer;
69
+
70
+ &:not(:disabled)::before {
71
+ display: inline-block;
72
+ }
73
+ &:not(:disabled):not(:active)::before {
74
+ opacity: $opacity-50;
75
+ transition: transform 0.15s ease, opacity 0.3s ease;
76
+ }
77
+ }
78
+
79
+ &:disabled {
80
+ cursor: default;
81
+ border: 1px solid var(--content-disabled);
82
+ background: var(--background-disabled);
83
+
84
+ ~ .rte-checkbox-text-container {
85
+ label,
86
+ .rte-checkbox-description {
87
+ color: var(--content-disabled);
88
+ }
89
+ }
90
+ }
91
+
92
+ &:checked {
93
+ @include checked-indeterminate-style;
94
+
95
+ &:not(:indeterminate) {
96
+ ~ .rte-checkbox-icon-selected {
97
+ display: block;
98
+ }
99
+ }
100
+ }
101
+
102
+ &:indeterminate {
103
+ @include checked-indeterminate-style;
104
+
105
+ ~ .rte-checkbox-icon-indeterminated {
106
+ display: block;
107
+ }
108
+ }
109
+
110
+ &.read-only {
111
+ pointer-events: none;
112
+ cursor: default;
113
+ border: 1px solid var(--content-tertiary);
114
+ opacity: $opacity-100;
115
+ background: var(--background-disabled);
116
+
117
+ ~ .rte-checkbox-text-container {
118
+ label,
119
+ .checkbox-description {
120
+ color: var(--content-tertiary);
121
+ }
122
+ }
123
+ ~ .rte-checkbox-icons {
124
+ color: var(--content-tertiary);
125
+ }
126
+
127
+ &.error {
128
+ border: 1px solid var(--content-danger);
129
+ background: var(--background-disabled);
130
+ }
131
+ }
132
+
133
+ &.error {
134
+ border: 1px solid var(--content-danger);
135
+ background: var(--background-default);
136
+
137
+ &:hover {
138
+ &:not(:disabled):not(:active)::before {
139
+ opacity: $opacity-20;
140
+ background: var(--background-danger-hover);
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ .rte-checkbox-text-container {
147
+ label {
148
+ @include typography-text-l;
149
+ }
150
+ .rte-checkbox-description {
151
+ @include typography-text-s;
152
+ margin: 0;
153
+ color: var(--content-tertiary);
154
+ }
155
+ .rte-checkbox-error {
156
+ @include typography-checkbox-error;
157
+ margin: 0;
158
+ color: var(--content-danger);
159
+ }
160
+ }
161
+
162
+ .rte-checkbox-icons {
163
+ display: none;
164
+ z-index: 1;
165
+ pointer-events: none;
166
+ transform: translateY(4px);
167
+ position: absolute;
168
+ color: white;
169
+ }
170
+ }
@@ -0,0 +1,126 @@
1
+ import { Meta, StoryObj } from "@storybook/angular";
2
+ import { userEvent, within, expect } from "@storybook/test";
3
+
4
+ import { CheckboxComponent } from "./checkbox.component";
5
+
6
+ const meta: Meta<CheckboxComponent> = {
7
+ title: "Checkbox",
8
+ component: CheckboxComponent,
9
+ tags: ["autodocs"],
10
+ argTypes: {
11
+ label: {
12
+ control: "text",
13
+ defaultValue: "Label",
14
+ },
15
+ description: {
16
+ control: "text",
17
+ defaultValue: "Description",
18
+ },
19
+ showLabel: {
20
+ control: "boolean",
21
+ defaultValue: true,
22
+ },
23
+ disabled: {
24
+ control: "boolean",
25
+ defaultValue: false,
26
+ },
27
+ indeterminate: {
28
+ control: "boolean",
29
+ defaultValue: false,
30
+ },
31
+ errorMessage: {
32
+ control: "text",
33
+ defaultValue: "",
34
+ },
35
+ readOnly: {
36
+ control: "boolean",
37
+ defaultValue: false,
38
+ },
39
+ checked: {
40
+ control: "boolean",
41
+ defaultValue: false,
42
+ },
43
+ },
44
+ };
45
+ export default meta;
46
+ type Story = StoryObj<CheckboxComponent>;
47
+
48
+ export const Default: Story = {
49
+ args: {
50
+ id: "my-checkbox",
51
+ label: "Label",
52
+ description: "Description",
53
+ disabled: false,
54
+ readOnly: false,
55
+ showLabel: true,
56
+ indeterminate: false,
57
+ errorMessage: "",
58
+ },
59
+ play: async ({ canvasElement }) => {
60
+ const canvas = within(canvasElement);
61
+ const checkbox = canvas.getByRole("checkbox");
62
+ await userEvent.click(checkbox);
63
+ expect(checkbox).toBeChecked();
64
+ checkbox.blur();
65
+ },
66
+ };
67
+
68
+ export const Disabled: Story = {
69
+ args: {
70
+ ...Default.args,
71
+ disabled: true,
72
+ },
73
+ play: async ({ canvasElement }) => {
74
+ const canvas = within(canvasElement);
75
+ const checkbox = canvas.getByRole("checkbox");
76
+ expect(checkbox).toBeDisabled();
77
+ await userEvent.click(checkbox);
78
+ expect(checkbox).not.toBeChecked();
79
+ },
80
+ };
81
+
82
+ export const Indeterminated: Story = {
83
+ args: {
84
+ ...Default.args,
85
+ indeterminate: true,
86
+ },
87
+ };
88
+
89
+ export const ReadOnly: Story = {
90
+ args: {
91
+ ...Default.args,
92
+ readOnly: true,
93
+ checked: true,
94
+ },
95
+ play: async ({ canvasElement }) => {
96
+ const canvas = within(canvasElement);
97
+ const checkbox = canvas.getByRole("checkbox");
98
+ await userEvent.keyboard(`{Tab}`);
99
+ expect(checkbox).toHaveFocus();
100
+ await userEvent.keyboard(`{ }`);
101
+ expect(checkbox).toBeChecked();
102
+ checkbox.blur();
103
+ },
104
+ };
105
+
106
+ export const Error: Story = {
107
+ args: {
108
+ ...Default.args,
109
+ errorMessage: "Error message",
110
+ },
111
+ };
112
+
113
+ export const KeyboardInteractions: Story = {
114
+ args: {
115
+ ...Default.args,
116
+ },
117
+ play: async ({ canvasElement }) => {
118
+ const canvas = within(canvasElement);
119
+ const checkbox = canvas.getByRole("checkbox");
120
+ await userEvent.keyboard(`{Tab}`);
121
+ expect(checkbox).toHaveFocus();
122
+ await userEvent.keyboard(`{ }`);
123
+ expect(checkbox).toBeChecked();
124
+ checkbox.blur();
125
+ },
126
+ };