@design-system-rte/angular 0.2.1 → 0.4.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/CHANGELOG.md +7 -0
- package/package.json +8 -5
- package/src/lib/components/button/button.component.scss +11 -13
- package/src/lib/components/button/button.component.ts +2 -1
- package/src/lib/components/checkbox/checkbox.component.scss +18 -12
- package/src/lib/components/checkbox-group/checkbox-group.component.scss +3 -3
- package/src/lib/components/icon/icon-map.ts +4 -0
- package/src/lib/components/icon/icon.stories.ts +1 -1
- package/src/lib/components/icon-button/icon-button.component.html +16 -0
- package/src/lib/components/icon-button/icon-button.component.scss +165 -0
- package/src/lib/components/icon-button/icon-button.component.ts +40 -0
- package/src/lib/components/icon-button/icon-button.stories.ts +200 -0
- package/src/lib/components/icon-button-toggle/icon-button-toggle.component.html +12 -0
- package/src/lib/components/icon-button-toggle/icon-button-toggle.component.ts +36 -0
- package/src/lib/components/icon-button-toggle/icon-button-toggle.stories.ts +197 -0
- package/src/lib/components/link/link.component.scss +37 -37
- package/src/lib/components/radio-button/radio-button.component.scss +2 -2
- package/src/lib/components/radio-button-group/radio-button-group.component.scss +3 -3
- package/src/lib/components/split-button/split-button.component.html +56 -0
- package/src/lib/components/split-button/split-button.component.scss +288 -0
- package/src/lib/components/split-button/split-button.component.stories.ts +227 -0
- package/src/lib/components/split-button/split-button.component.ts +55 -0
- package/src/lib/components/tooltip/tooltip.component.scss +2 -4
- package/tsconfig.lib.json +0 -2
package/CHANGELOG.md
ADDED
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@design-system-rte/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Angular components for the Design System RTE",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
5
8
|
"peerDependencies": {
|
|
6
|
-
"@angular/common": "^17.3.
|
|
7
|
-
"@angular/core": "^17.3.
|
|
9
|
+
"@angular/common": "^17.3.12",
|
|
10
|
+
"@angular/core": "^17.3.12"
|
|
8
11
|
},
|
|
9
12
|
"dependencies": {
|
|
10
|
-
"@design-system-rte/core": "^0.
|
|
13
|
+
"@design-system-rte/core": "^0.6.0",
|
|
11
14
|
"tslib": "^2.3.0"
|
|
12
15
|
},
|
|
13
16
|
"sideEffects": false
|
|
14
|
-
}
|
|
17
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@use '@design-system-rte/core/tokens/main.scss' as *;
|
|
1
|
+
@use '@design-system-rte/core/design-tokens/main.scss' as *;
|
|
2
2
|
|
|
3
3
|
.rte-button {
|
|
4
4
|
align-items: center;
|
|
@@ -61,35 +61,33 @@
|
|
|
61
61
|
|
|
62
62
|
&:disabled {
|
|
63
63
|
background: var(--background-disabled);
|
|
64
|
-
border: solid
|
|
64
|
+
border: solid $width-xs var(--border-disabled);
|
|
65
65
|
color: var(--content-disabled);
|
|
66
66
|
box-shadow: none;
|
|
67
67
|
cursor: default;
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
}
|
|
70
70
|
|
|
71
71
|
&.secondary {
|
|
72
72
|
background: var(--background-default);
|
|
73
|
-
border: solid
|
|
73
|
+
border: solid $width-xs var(--border-brand-default);
|
|
74
74
|
color: var(--content-brand-default);
|
|
75
75
|
|
|
76
76
|
&:hover {
|
|
77
77
|
background: var(--background-brand-inverse-hover);
|
|
78
|
-
border: solid 1px var(--border-brand-default);
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
&:active {
|
|
82
|
-
border: var(--background-brand-inverse);
|
|
83
81
|
background: var(--background-brand-inverse-pressed);
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
&:disabled {
|
|
87
85
|
background: var(--background-disabled);
|
|
88
|
-
border: solid
|
|
86
|
+
border: solid $width-xs var(--border-disabled);
|
|
89
87
|
color: var(--content-disabled);
|
|
90
88
|
cursor: default;
|
|
91
89
|
}
|
|
92
|
-
}
|
|
90
|
+
}
|
|
93
91
|
|
|
94
92
|
&.text {
|
|
95
93
|
background: transparent;
|
|
@@ -109,7 +107,7 @@
|
|
|
109
107
|
color: var(--content-disabled);
|
|
110
108
|
cursor: default;
|
|
111
109
|
}
|
|
112
|
-
}
|
|
110
|
+
}
|
|
113
111
|
|
|
114
112
|
&.transparent {
|
|
115
113
|
background: transparent;
|
|
@@ -121,7 +119,7 @@
|
|
|
121
119
|
}
|
|
122
120
|
|
|
123
121
|
&:active {
|
|
124
|
-
color: var(--content-brand-
|
|
122
|
+
color: var(--content-brand-press);
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
&:disabled {
|
|
@@ -129,8 +127,8 @@
|
|
|
129
127
|
box-shadow: none;
|
|
130
128
|
cursor: default;
|
|
131
129
|
}
|
|
132
|
-
}
|
|
133
|
-
|
|
130
|
+
}
|
|
131
|
+
|
|
134
132
|
&.danger {
|
|
135
133
|
background: var(--background-danger-default);
|
|
136
134
|
border: none;
|
|
@@ -144,7 +142,7 @@
|
|
|
144
142
|
&:active {
|
|
145
143
|
background: var(--background-danger-pressed);
|
|
146
144
|
}
|
|
147
|
-
|
|
145
|
+
|
|
148
146
|
&:disabled {
|
|
149
147
|
background: var(--background-disabled);
|
|
150
148
|
border: var(--border-disabled);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Component, input, output } from "@angular/core";
|
|
2
|
-
import {
|
|
2
|
+
import { ButtonType } from "@design-system-rte/core/components/button/button.interface";
|
|
3
|
+
import { ButtonSize, ButtonVariant } from "@design-system-rte/core/components/button/common/common-button";
|
|
3
4
|
|
|
4
5
|
@Component({
|
|
5
6
|
selector: "rte-button",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@use '@design-system-rte/core/tokens/main.scss' as *;
|
|
1
|
+
@use '@design-system-rte/core/design-tokens/main.scss' as *;
|
|
2
2
|
|
|
3
3
|
@mixin checked-indeterminate-style {
|
|
4
4
|
border: 1px solid var(--content-brand-default);
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
border: 1px solid var(--content-disabled);
|
|
16
16
|
background: var(--background-disabled);
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
color: var(--content-disabled);
|
|
18
|
+
~.rte-checkbox-icons {
|
|
19
|
+
color: var(--content-disabled);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
.rte-checkbox-container {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
display: flex;
|
|
30
|
+
gap: $positive-spacing-150;
|
|
31
31
|
|
|
32
32
|
.rte-checkbox {
|
|
33
33
|
appearance: none;
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
transform: scale(0);
|
|
59
59
|
transition: transform 0s, opacity 0s;
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
&:focus-visible {
|
|
63
63
|
outline: 1px solid var(--border-brand-focused);
|
|
64
64
|
outline-offset: 4px;
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
&:not(:disabled)::before {
|
|
71
71
|
display: inline-block;
|
|
72
72
|
}
|
|
73
|
+
|
|
73
74
|
&:not(:disabled):not(:active)::before {
|
|
74
75
|
opacity: $opacity-50;
|
|
75
76
|
transition: transform 0.15s ease, opacity 0.3s ease;
|
|
@@ -81,7 +82,8 @@
|
|
|
81
82
|
border: 1px solid var(--content-disabled);
|
|
82
83
|
background: var(--background-disabled);
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
~.rte-checkbox-text-container {
|
|
86
|
+
|
|
85
87
|
label,
|
|
86
88
|
.rte-checkbox-description {
|
|
87
89
|
color: var(--content-disabled);
|
|
@@ -93,7 +95,7 @@
|
|
|
93
95
|
@include checked-indeterminate-style;
|
|
94
96
|
|
|
95
97
|
&:not(:indeterminate) {
|
|
96
|
-
|
|
98
|
+
~.rte-checkbox-icon-selected {
|
|
97
99
|
display: block;
|
|
98
100
|
}
|
|
99
101
|
}
|
|
@@ -102,7 +104,7 @@
|
|
|
102
104
|
&:indeterminate {
|
|
103
105
|
@include checked-indeterminate-style;
|
|
104
106
|
|
|
105
|
-
|
|
107
|
+
~.rte-checkbox-icon-indeterminated {
|
|
106
108
|
display: block;
|
|
107
109
|
}
|
|
108
110
|
}
|
|
@@ -114,14 +116,16 @@
|
|
|
114
116
|
opacity: $opacity-100;
|
|
115
117
|
background: var(--background-disabled);
|
|
116
118
|
|
|
117
|
-
|
|
119
|
+
~.rte-checkbox-text-container {
|
|
120
|
+
|
|
118
121
|
label,
|
|
119
122
|
.checkbox-description {
|
|
120
123
|
color: var(--content-tertiary);
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
|
|
127
|
+
~.rte-checkbox-icons {
|
|
128
|
+
color: var(--content-tertiary);
|
|
125
129
|
}
|
|
126
130
|
|
|
127
131
|
&.error {
|
|
@@ -147,11 +151,13 @@
|
|
|
147
151
|
label {
|
|
148
152
|
@include typography-text-l;
|
|
149
153
|
}
|
|
154
|
+
|
|
150
155
|
.rte-checkbox-description {
|
|
151
156
|
@include typography-text-s;
|
|
152
157
|
margin: 0;
|
|
153
158
|
color: var(--content-tertiary);
|
|
154
159
|
}
|
|
160
|
+
|
|
155
161
|
.rte-checkbox-error {
|
|
156
162
|
@include typography-checkbox-error;
|
|
157
163
|
margin: 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@use '@design-system-rte/core/tokens/main.scss' as *;
|
|
1
|
+
@use '@design-system-rte/core/design-tokens/main.scss' as *;
|
|
2
2
|
|
|
3
3
|
.checkbox-group-container {
|
|
4
4
|
display: flex;
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
margin: $positive-spacing_0;
|
|
32
32
|
margin-top: $positive-spacing_050;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
&.error {
|
|
36
36
|
.group-title {
|
|
37
37
|
color: var(--content-danger);
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
color: var(--content-tertiary);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
.error{
|
|
46
|
+
.error {
|
|
47
47
|
.group-title {
|
|
48
48
|
color: var(--content-danger);
|
|
49
49
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isValidIconName as isValidIconNameShared } from "@design-system-rte/core/components/icon/icon-utils";
|
|
2
|
+
|
|
1
3
|
export const togglableIcons = {
|
|
2
4
|
"add-circle": ["add_circle_outlined", "add_circle_filled"],
|
|
3
5
|
"admin-panel-settings": ["admin_panel_settings_outlined", "admin_panel_settings_filled"],
|
|
@@ -299,3 +301,5 @@ export const regularIcons = {
|
|
|
299
301
|
"zoom-out": "zoom_out",
|
|
300
302
|
"zoom-in": "zoom_in",
|
|
301
303
|
};
|
|
304
|
+
|
|
305
|
+
export const isValidIconName = (name: string): boolean => isValidIconNameShared(name, regularIcons, togglableIcons);
|
|
@@ -13,7 +13,7 @@ const meta = {
|
|
|
13
13
|
argTypes: {
|
|
14
14
|
name: {
|
|
15
15
|
control: "select",
|
|
16
|
-
options: [...RegularIconIds, ...TogglableIconIds].sort(),
|
|
16
|
+
options: [...RegularIconIds, ...TogglableIconIds].sort((a, b) => a.localeCompare(b)),
|
|
17
17
|
description: "Nom de l’icône à afficher",
|
|
18
18
|
defaultValue: "check",
|
|
19
19
|
},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<button
|
|
2
|
+
*ngIf="isValidIconName"
|
|
3
|
+
class="rte-icon-button {{ variant() }} size-{{ size() }}"
|
|
4
|
+
[class.compact-spacing]="compactSpacing()"
|
|
5
|
+
[disabled]="disabled()"
|
|
6
|
+
[attr.aria-label]="ariaLabel()"
|
|
7
|
+
[attr.aria-labelledby]="ariaLabelledBy()"
|
|
8
|
+
[type]="type()"
|
|
9
|
+
(click)="onClick($event)"
|
|
10
|
+
>
|
|
11
|
+
<rte-icon
|
|
12
|
+
[name]="name()"
|
|
13
|
+
[appearance]="appearance()"
|
|
14
|
+
[size]="buttonIconSize()"
|
|
15
|
+
/>
|
|
16
|
+
</button>
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
@use '@design-system-rte/core/design-tokens/main.scss' as *;
|
|
2
|
+
|
|
3
|
+
.rte-icon-button {
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
height: 24px;
|
|
7
|
+
align-items: center;
|
|
8
|
+
gap: $positive-spacing_0;
|
|
9
|
+
flex-shrink: 0;
|
|
10
|
+
|
|
11
|
+
&:focus-visible {
|
|
12
|
+
outline: none;
|
|
13
|
+
position: relative;
|
|
14
|
+
|
|
15
|
+
&::after {
|
|
16
|
+
content: '';
|
|
17
|
+
position: absolute;
|
|
18
|
+
inset: -4px;
|
|
19
|
+
border-radius: 6px;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
box-shadow: 0 0 0 1px var(--border-brand-focused);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&.size-s {
|
|
26
|
+
border-radius: $radius-s;
|
|
27
|
+
height: 24px;
|
|
28
|
+
padding: $positive-spacing_025 $positive-spacing_050;
|
|
29
|
+
|
|
30
|
+
&.compact-spacing {
|
|
31
|
+
height: 16px;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&.size-m {
|
|
36
|
+
border-radius: $radius-s;
|
|
37
|
+
height: 32px;
|
|
38
|
+
padding: $positive-spacing_050 $positive-spacing_075;
|
|
39
|
+
|
|
40
|
+
&.compact-spacing {
|
|
41
|
+
height: 20px;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&.size-l {
|
|
46
|
+
border-radius: $radius-m;
|
|
47
|
+
height: 40px;
|
|
48
|
+
padding: $positive-spacing_075 $positive-spacing_100;
|
|
49
|
+
|
|
50
|
+
&.compact-spacing {
|
|
51
|
+
height: 24px;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&.primary {
|
|
56
|
+
background: var(--background-brand-default);
|
|
57
|
+
border: var(--border-brand-default);
|
|
58
|
+
color: var(--content-primary-inverse);
|
|
59
|
+
|
|
60
|
+
&:hover {
|
|
61
|
+
background: var(--background-brand-hover);
|
|
62
|
+
border: var(--background-brand-hover);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&:active {
|
|
66
|
+
background: var(--background-brand-pressed);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&:disabled {
|
|
70
|
+
background: var(--background-disabled);
|
|
71
|
+
border: solid $width-xs var(--border-disabled);
|
|
72
|
+
box-shadow: none;
|
|
73
|
+
color: var(--content-disabled);
|
|
74
|
+
cursor: default;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&.secondary {
|
|
79
|
+
background: var(--background-default);
|
|
80
|
+
border: solid $width-xs var(--border-brand-default);
|
|
81
|
+
color: var(--content-brand-default);
|
|
82
|
+
|
|
83
|
+
&:hover {
|
|
84
|
+
background: var(--background-brand-inverse-hover);
|
|
85
|
+
border: solid $width-xs var(--border-brand-default);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&:active {
|
|
89
|
+
background: var(--background-brand-inverse-pressed);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&:disabled {
|
|
93
|
+
background: var(--background-disabled);
|
|
94
|
+
border: solid $width-xs var(--border-disabled);
|
|
95
|
+
color: var(--content-disabled);
|
|
96
|
+
cursor: default;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
&.text {
|
|
101
|
+
background: transparent;
|
|
102
|
+
border: none;
|
|
103
|
+
color: var(--content-brand-default);
|
|
104
|
+
|
|
105
|
+
&:hover {
|
|
106
|
+
background: var(--background-brand-inverse-hover);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&:active {
|
|
110
|
+
background: var(--background-brand-inverse-pressed);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
&:disabled {
|
|
114
|
+
background: var(--background-disabled);
|
|
115
|
+
color: var(--content-disabled);
|
|
116
|
+
cursor: default;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&.transparent {
|
|
121
|
+
background: transparent;
|
|
122
|
+
border: none;
|
|
123
|
+
color: var(--content-brand-default);
|
|
124
|
+
|
|
125
|
+
&:hover {
|
|
126
|
+
color: var(--content-brand-hover);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
&:active {
|
|
130
|
+
color: var(--content-brand-press);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&:disabled {
|
|
134
|
+
box-shadow: none;
|
|
135
|
+
background-color: var(--background-disabled);
|
|
136
|
+
color: var(--content-disabled);
|
|
137
|
+
cursor: default;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
&.danger {
|
|
142
|
+
background: var(--background-danger-default);
|
|
143
|
+
border: none;
|
|
144
|
+
color: var(--content-primary-inverse);
|
|
145
|
+
|
|
146
|
+
&:hover {
|
|
147
|
+
background: var(--background-danger-hover);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
&:active {
|
|
151
|
+
background: var(--background-danger-pressed);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
&:disabled {
|
|
155
|
+
background: var(--background-disabled);
|
|
156
|
+
border: solid $width-xs var(--border-disabled);
|
|
157
|
+
color: var(--content-disabled);
|
|
158
|
+
cursor: default;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
&.compact-spacing {
|
|
163
|
+
padding: $positive-spacing_0;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CommonModule } from "@angular/common";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, computed, input, output } from "@angular/core";
|
|
3
|
+
import { ButtonType } from "@design-system-rte/core/components/button/button.interface";
|
|
4
|
+
import { ButtonSize, ButtonVariant } from "@design-system-rte/core/components/button/common/common-button";
|
|
5
|
+
import { buttonIconSize } from "@design-system-rte/core/components/button/common/common-button.constants";
|
|
6
|
+
|
|
7
|
+
import { isValidIconName } from "../icon/icon-map";
|
|
8
|
+
import { IconComponent } from "../icon/icon.component";
|
|
9
|
+
import { RegularIconIdKey, TogglableIconIdKey } from "../icon/icon.service";
|
|
10
|
+
|
|
11
|
+
@Component({
|
|
12
|
+
selector: "rte-icon-button",
|
|
13
|
+
imports: [CommonModule, IconComponent],
|
|
14
|
+
standalone: true,
|
|
15
|
+
templateUrl: "./icon-button.component.html",
|
|
16
|
+
styleUrl: "./icon-button.component.scss",
|
|
17
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
18
|
+
})
|
|
19
|
+
export class IconButtonComponent {
|
|
20
|
+
readonly disabled = input<boolean>(false);
|
|
21
|
+
readonly name = input.required<RegularIconIdKey | TogglableIconIdKey>();
|
|
22
|
+
readonly size = input<ButtonSize>("m");
|
|
23
|
+
readonly variant = input<ButtonVariant>("primary");
|
|
24
|
+
readonly type = input<ButtonType>("button");
|
|
25
|
+
readonly appearance = input<"outlined" | "filled">("outlined");
|
|
26
|
+
readonly compactSpacing = input<boolean>(false);
|
|
27
|
+
readonly ariaLabel = input<string | undefined>(undefined);
|
|
28
|
+
readonly ariaLabelledBy = input<string | undefined>(undefined);
|
|
29
|
+
|
|
30
|
+
readonly buttonIconSize = computed(() => buttonIconSize[this.size()]);
|
|
31
|
+
|
|
32
|
+
readonly isValidIconName = computed(() => isValidIconName(this.name()));
|
|
33
|
+
|
|
34
|
+
readonly click = output<MouseEvent | KeyboardEvent>();
|
|
35
|
+
|
|
36
|
+
onClick(event: MouseEvent | KeyboardEvent): void {
|
|
37
|
+
event.stopPropagation();
|
|
38
|
+
this.click.emit(event);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ENTER_KEY, SPACE_KEY, TAB_KEY } from "@design-system-rte/core/constants/keyboard.constants";
|
|
2
|
+
import { Meta, StoryObj } from "@storybook/angular";
|
|
3
|
+
import { fn, userEvent, within, expect } from "@storybook/test";
|
|
4
|
+
|
|
5
|
+
import { regularIcons as RegularIconsList, togglableIcons as TogglableIconsList } from "../icon/icon-map";
|
|
6
|
+
|
|
7
|
+
import { IconButtonComponent } from "./icon-button.component";
|
|
8
|
+
|
|
9
|
+
const RegularIconIds = Object.keys(RegularIconsList);
|
|
10
|
+
const TogglableIconIds = Object.keys(TogglableIconsList);
|
|
11
|
+
|
|
12
|
+
const meta = {
|
|
13
|
+
title: "IconButton",
|
|
14
|
+
component: IconButtonComponent,
|
|
15
|
+
tags: ["autodocs"],
|
|
16
|
+
argTypes: {
|
|
17
|
+
name: {
|
|
18
|
+
control: "select",
|
|
19
|
+
options: [...RegularIconIds, ...TogglableIconIds].sort((a, b) => a.localeCompare(b)),
|
|
20
|
+
description: "Nom de l’icône à afficher",
|
|
21
|
+
defaultValue: "check",
|
|
22
|
+
},
|
|
23
|
+
variant: {
|
|
24
|
+
control: "select",
|
|
25
|
+
options: ["primary", "secondary", "text", "transparent", "danger"],
|
|
26
|
+
},
|
|
27
|
+
appearance: {
|
|
28
|
+
control: "select",
|
|
29
|
+
options: ["outlined", "filled"],
|
|
30
|
+
description: "Apparence de l’icône (pour les icônes togglables)",
|
|
31
|
+
defaultValue: "outlined",
|
|
32
|
+
},
|
|
33
|
+
size: {
|
|
34
|
+
control: "select",
|
|
35
|
+
options: ["s", "m", "l"],
|
|
36
|
+
},
|
|
37
|
+
compactSpacing: {
|
|
38
|
+
control: "boolean",
|
|
39
|
+
description: "Utiliser un espacement compact",
|
|
40
|
+
},
|
|
41
|
+
disabled: {
|
|
42
|
+
control: "boolean",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
} satisfies Meta<IconButtonComponent>;
|
|
46
|
+
|
|
47
|
+
export default meta;
|
|
48
|
+
|
|
49
|
+
type Story = StoryObj<IconButtonComponent>;
|
|
50
|
+
|
|
51
|
+
const mockFn = fn();
|
|
52
|
+
|
|
53
|
+
export const Default: Story = {
|
|
54
|
+
args: {
|
|
55
|
+
name: "settings",
|
|
56
|
+
size: "m",
|
|
57
|
+
appearance: "outlined",
|
|
58
|
+
disabled: false,
|
|
59
|
+
compactSpacing: false,
|
|
60
|
+
variant: "primary",
|
|
61
|
+
ariaLabel: "icon button aria label",
|
|
62
|
+
click: mockFn,
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
play: async ({ canvasElement }) => {
|
|
66
|
+
const canvas = within(canvasElement);
|
|
67
|
+
const iconButton = canvas.getByRole("button");
|
|
68
|
+
await userEvent.click(iconButton);
|
|
69
|
+
expect(mockFn).toHaveBeenCalled();
|
|
70
|
+
iconButton.blur();
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const Sizing: Story = {
|
|
75
|
+
args: {
|
|
76
|
+
...Default.args,
|
|
77
|
+
compactSpacing: false,
|
|
78
|
+
},
|
|
79
|
+
render: (args) => ({
|
|
80
|
+
props: { ...args },
|
|
81
|
+
template: `
|
|
82
|
+
<div style="display: flex; gap: 8px">
|
|
83
|
+
<rte-icon-button
|
|
84
|
+
size="s"
|
|
85
|
+
name=${args.name}
|
|
86
|
+
data-testid="small-icon-button"
|
|
87
|
+
[compactSpacing]="${args.compactSpacing}"
|
|
88
|
+
[disabled]="${args.disabled}"
|
|
89
|
+
[appearance]="${args.appearance}"
|
|
90
|
+
[ariaLabel]="'Small Icon Button'"
|
|
91
|
+
[type]="'${args.type}'"
|
|
92
|
+
[variant]="'${args.variant}'"
|
|
93
|
+
/>
|
|
94
|
+
<rte-icon-button
|
|
95
|
+
name=${args.name}
|
|
96
|
+
data-testid="medium-icon-button"
|
|
97
|
+
[compactSpacing]="${args.compactSpacing}"
|
|
98
|
+
[disabled]="${args.disabled}"
|
|
99
|
+
[appearance]="${args.appearance}"
|
|
100
|
+
[ariaLabel]="'Small Icon Button'"
|
|
101
|
+
[type]="'${args.type}'"
|
|
102
|
+
[variant]="'${args.variant}'"
|
|
103
|
+
/>
|
|
104
|
+
<rte-icon-button
|
|
105
|
+
size="l"
|
|
106
|
+
name=${args.name}
|
|
107
|
+
data-testid="large-icon-button"
|
|
108
|
+
[compactSpacing]="${args.compactSpacing}"
|
|
109
|
+
[disabled]="${args.disabled}"
|
|
110
|
+
[appearance]="${args.appearance}"
|
|
111
|
+
[ariaLabel]="'Small Icon Button'"
|
|
112
|
+
[type]="'${args.type}'"
|
|
113
|
+
[variant]="'${args.variant}'"
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
`,
|
|
117
|
+
}),
|
|
118
|
+
play: async ({ canvasElement }) => {
|
|
119
|
+
const canvas = within(canvasElement);
|
|
120
|
+
const smallIconButton = canvas.getByTestId("small-icon-button").getElementsByTagName("button")[0];
|
|
121
|
+
const mediumIconButton = canvas.getByTestId("medium-icon-button").getElementsByTagName("button")[0];
|
|
122
|
+
const largeIconButton = canvas.getByTestId("large-icon-button").getElementsByTagName("button")[0];
|
|
123
|
+
|
|
124
|
+
expect(smallIconButton.clientHeight).toBe(24);
|
|
125
|
+
expect(mediumIconButton.clientHeight).toBe(32);
|
|
126
|
+
expect(largeIconButton.clientHeight).toBe(40);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const CompactSizing: Story = {
|
|
131
|
+
args: {
|
|
132
|
+
...Default.args,
|
|
133
|
+
compactSpacing: true,
|
|
134
|
+
},
|
|
135
|
+
render: (args) => ({
|
|
136
|
+
props: { ...args },
|
|
137
|
+
template: `
|
|
138
|
+
<div style="display: flex; gap: 8px">
|
|
139
|
+
<rte-icon-button
|
|
140
|
+
size="s"
|
|
141
|
+
name=${args.name}
|
|
142
|
+
data-testid="small-icon-button"
|
|
143
|
+
[compactSpacing]="${args.compactSpacing}"
|
|
144
|
+
[disabled]="${args.disabled}"
|
|
145
|
+
[appearance]="${args.appearance}"
|
|
146
|
+
[ariaLabel]="'Small Icon Button'"
|
|
147
|
+
[type]="'${args.type}'"
|
|
148
|
+
[variant]="'${args.variant}'"
|
|
149
|
+
/>
|
|
150
|
+
<rte-icon-button
|
|
151
|
+
name=${args.name}
|
|
152
|
+
data-testid="medium-icon-button"
|
|
153
|
+
[compactSpacing]="${args.compactSpacing}"
|
|
154
|
+
[disabled]="${args.disabled}"
|
|
155
|
+
[appearance]="${args.appearance}"
|
|
156
|
+
[ariaLabel]="'Small Icon Button'"
|
|
157
|
+
[type]="'${args.type}'"
|
|
158
|
+
[variant]="'${args.variant}'"
|
|
159
|
+
/>
|
|
160
|
+
<rte-icon-button
|
|
161
|
+
size="l"
|
|
162
|
+
name=${args.name}
|
|
163
|
+
data-testid="large-icon-button"
|
|
164
|
+
[compactSpacing]="${args.compactSpacing}"
|
|
165
|
+
[disabled]="${args.disabled}"
|
|
166
|
+
[appearance]="${args.appearance}"
|
|
167
|
+
[ariaLabel]="'Small Icon Button'"
|
|
168
|
+
[type]="'${args.type}'"
|
|
169
|
+
[variant]="'${args.variant}'"
|
|
170
|
+
/>
|
|
171
|
+
</div>
|
|
172
|
+
`,
|
|
173
|
+
}),
|
|
174
|
+
play: async ({ canvasElement }) => {
|
|
175
|
+
const canvas = within(canvasElement);
|
|
176
|
+
const smallIconButton = canvas.getByTestId("small-icon-button").getElementsByTagName("button")[0];
|
|
177
|
+
const mediumIconButton = canvas.getByTestId("medium-icon-button").getElementsByTagName("button")[0];
|
|
178
|
+
const largeIconButton = canvas.getByTestId("large-icon-button").getElementsByTagName("button")[0];
|
|
179
|
+
|
|
180
|
+
expect(smallIconButton.clientHeight).toBe(16);
|
|
181
|
+
expect(mediumIconButton.clientHeight).toBe(20);
|
|
182
|
+
expect(largeIconButton.clientHeight).toBe(24);
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const KeyboardInteraction: Story = {
|
|
187
|
+
args: {
|
|
188
|
+
...Default.args,
|
|
189
|
+
},
|
|
190
|
+
play: async ({ canvasElement }) => {
|
|
191
|
+
const canvas = within(canvasElement);
|
|
192
|
+
const button = canvas.getByRole("button");
|
|
193
|
+
await userEvent.keyboard(TAB_KEY);
|
|
194
|
+
expect(button).toHaveFocus();
|
|
195
|
+
await userEvent.keyboard(ENTER_KEY);
|
|
196
|
+
await userEvent.keyboard(SPACE_KEY);
|
|
197
|
+
expect(mockFn).toHaveBeenCalledTimes(2);
|
|
198
|
+
button.blur();
|
|
199
|
+
},
|
|
200
|
+
};
|