@stackoverflow/stacks 2.0.1 → 2.0.3

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.
@@ -0,0 +1,17 @@
1
+ import { html } from "@open-wc/testing";
2
+ import { SpotEmptyXL } from "@stackoverflow/stacks-icons";
3
+ import { runComponentTests } from "../../test/test-utils";
4
+ import "../../index";
5
+
6
+ describe("empty-state", () => {
7
+ runComponentTests({
8
+ type: "a11y",
9
+ baseClass: "s-empty-state",
10
+ children: {
11
+ default: `${SpotEmptyXL}<p class="mt24"><strong>Hello!</strong> This is a wonderful empty state component.</p>`,
12
+ },
13
+ template: ({ component, testid }) => html`
14
+ <div class="ws3 p16" data-testid="${testid}">${component}</div>
15
+ `,
16
+ });
17
+ });
@@ -0,0 +1,17 @@
1
+ import { html } from "@open-wc/testing";
2
+ import { SpotEmptyXL } from "@stackoverflow/stacks-icons";
3
+ import { runComponentTests } from "../../test/test-utils";
4
+ import "../../index";
5
+
6
+ describe("empty-state", () => {
7
+ runComponentTests({
8
+ type: "visual",
9
+ baseClass: "s-empty-state",
10
+ children: {
11
+ default: `${SpotEmptyXL}<p class="mt24"><strong>Hello!</strong> This is a wonderful empty state component.</p>`,
12
+ },
13
+ template: ({ component, testid }) => html`
14
+ <div class="ws3 p16" data-testid="${testid}">${component}</div>
15
+ `,
16
+ });
17
+ });
@@ -0,0 +1,48 @@
1
+ import { html } from "@open-wc/testing";
2
+ import { runComponentTests } from "../../test/test-utils";
3
+ import "../../index";
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ const labelTemplate = ({ component, testid }: any) => {
7
+ return html`
8
+ <fieldset data-testid="${testid}" class="p8 ws3">${component}</fieldset>
9
+ `;
10
+ };
11
+
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ const getChildren = (status?: any) => {
14
+ const typeClass =
15
+ status && status !== "base" ? `s-label--status__${status}` : "";
16
+ return `
17
+ Example label
18
+ ${
19
+ status
20
+ ? `
21
+ <span class="s-label--status ${typeClass}">${
22
+ status ?? "no type"
23
+ }</span>
24
+ `
25
+ : ""
26
+ }
27
+ `;
28
+ };
29
+
30
+ describe("label", () => {
31
+ runComponentTests({
32
+ type: "a11y",
33
+ baseClass: `s-label`,
34
+ modifiers: {
35
+ primary: ["sm", "md", "lg", "xl"],
36
+ },
37
+ children: {
38
+ "default": getChildren(),
39
+ "status": getChildren("base"),
40
+ "status-beta": getChildren("beta"),
41
+ "status-new": getChildren("new"),
42
+ "status-required": getChildren("required"),
43
+ },
44
+ tag: "label",
45
+ template: ({ component, testid }) =>
46
+ labelTemplate({ component, testid }),
47
+ });
48
+ });
@@ -79,6 +79,7 @@
79
79
  vertical-align: text-bottom;
80
80
  }
81
81
 
82
+ // TODO we shouldn't support descriptions and messages within labels
82
83
  .s-description,
83
84
  .s-input-message {
84
85
  font-weight: normal;
@@ -0,0 +1,66 @@
1
+ import { html } from "@open-wc/testing";
2
+ import { runComponentTests } from "../../test/test-utils";
3
+ import "../../index";
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ const labelTemplate = ({ component, testid, isDisabled }: any) => {
7
+ return html`
8
+ <fieldset
9
+ data-testid="${testid}"
10
+ class="p8 ws3"
11
+ ?disabled="${isDisabled}"
12
+ >
13
+ ${component}
14
+ </fieldset>
15
+ `;
16
+ };
17
+
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ const getChildren = (text: string, status?: any) => {
20
+ const typeClass =
21
+ status && status !== "base" ? `s-label--status__${status}` : "";
22
+ return `
23
+ ${text}
24
+ ${
25
+ status
26
+ ? `
27
+ <span class="s-label--status ${typeClass}">${
28
+ status ?? "no type"
29
+ }</span>
30
+ `
31
+ : ""
32
+ }
33
+ `;
34
+ };
35
+
36
+ describe("label", () => {
37
+ [true, false].forEach((isDisabled) => {
38
+ const text = isDisabled ? "Disabled label" : "Example label";
39
+
40
+ runComponentTests({
41
+ type: "visual",
42
+ baseClass: `s-label`,
43
+ modifiers: {
44
+ primary: ["sm", "md", "lg", "xl"],
45
+ },
46
+ children: isDisabled
47
+ ? {
48
+ "disabled": getChildren(text),
49
+ "disabled-status": getChildren(text, "base"),
50
+ "disabled-status-beta": getChildren(text, "beta"),
51
+ "disabled-status-new": getChildren(text, "new"),
52
+ "disabled-status-required": getChildren(text, "required"),
53
+ }
54
+ : {
55
+ "default": getChildren(text),
56
+ "status": getChildren(text, "base"),
57
+ "status-beta": getChildren(text, "beta"),
58
+ "status-new": getChildren(text, "new"),
59
+ "status-required": getChildren(text, "required"),
60
+ },
61
+ tag: "label",
62
+ template: ({ component, testid }) =>
63
+ labelTemplate({ component, testid, isDisabled }),
64
+ });
65
+ });
66
+ });
@@ -0,0 +1,40 @@
1
+ import { html } from "@open-wc/testing";
2
+ import { runComponentTests } from "../../test/test-utils";
3
+ import "../../index";
4
+
5
+ describe("menu", () => {
6
+ runComponentTests({
7
+ type: "a11y",
8
+ baseClass: `s-menu`,
9
+ children: {
10
+ default: `
11
+ <li class="s-menu--title" role="separator">Title 1</li>
12
+ <li role="menuitem">
13
+ <a href="#" class="s-block-link">Example li</a>
14
+ </li>
15
+ <li class="s-menu--title" role="separator">Title 2</li>
16
+ <li role="menuitem">
17
+ <a href="#" class="s-block-link s-block-link__left is-selected">Selected link</a>
18
+ </li>
19
+ <li role="menuitem">
20
+ <a href="#" class="s-block-link">Example li</a>
21
+ </li>
22
+ <li role="menuitem" class="s-menu--label">Example label</li>
23
+ <li role="menuitem">
24
+ <a href="#" class="s-block-link">Block link</a>
25
+ </li>
26
+ <li class="s-menu--divider" role="separator"></li>
27
+ <li role="menuitem">
28
+ <a href="…" class="s-block-link s-block-link__danger">Danger link</a>
29
+ </li>
30
+ `,
31
+ },
32
+ tag: "ul",
33
+ attributes: {
34
+ role: "menu",
35
+ },
36
+ template: ({ component, testid }) => html`
37
+ <div class="ws2" data-testid="${testid}">${component}</div>
38
+ `,
39
+ });
40
+ });
@@ -0,0 +1,40 @@
1
+ import { html } from "@open-wc/testing";
2
+ import { runComponentTests } from "../../test/test-utils";
3
+ import "../../index";
4
+
5
+ describe("menu", () => {
6
+ runComponentTests({
7
+ type: "visual",
8
+ baseClass: `s-menu`,
9
+ children: {
10
+ default: `
11
+ <li class="s-menu--title" role="separator">Title 1</li>
12
+ <li role="menuitem">
13
+ <a href="#" class="s-block-link">Example li</a>
14
+ </li>
15
+ <li class="s-menu--title" role="separator">Title 2</li>
16
+ <li role="menuitem">
17
+ <a href="#" class="s-block-link s-block-link__left is-selected">Selected link</a>
18
+ </li>
19
+ <li role="menuitem">
20
+ <a href="#" class="s-block-link">Example li</a>
21
+ </li>
22
+ <li role="menuitem" class="s-menu--label">Example label</li>
23
+ <li role="menuitem">
24
+ <a href="#" class="s-block-link">Block link</a>
25
+ </li>
26
+ <li class="s-menu--divider" role="separator"></li>
27
+ <li role="menuitem">
28
+ <a href="…" class="s-block-link s-block-link__danger">Danger link</a>
29
+ </li>
30
+ `,
31
+ },
32
+ tag: "ul",
33
+ attributes: {
34
+ role: "menu",
35
+ },
36
+ template: ({ component, testid }) => html`
37
+ <div class="ws2" data-testid="${testid}">${component}</div>
38
+ `,
39
+ });
40
+ });
@@ -0,0 +1,200 @@
1
+ import { html } from "@open-wc/testing";
2
+ import {
3
+ IconAchievementsSm,
4
+ IconCheckmarkSm,
5
+ } from "@stackoverflow/stacks-icons/icons";
6
+ import { defaultOptions, runComponentTests } from "../../test/test-utils";
7
+ import "../../index";
8
+
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const template = ({ component, testid }: any) => html`
11
+ <div class="d-flex ai-center jc-center p8 ws2" data-testid="${testid}">
12
+ ${component}
13
+ </div>
14
+ `;
15
+
16
+ const steppedItems = [
17
+ {
18
+ complete: true,
19
+ label: "Select plan",
20
+ },
21
+ {
22
+ complete: true,
23
+ label: "Team name",
24
+ },
25
+ {
26
+ active: true,
27
+ label: "Payment",
28
+ },
29
+ {
30
+ label: "Create account",
31
+ },
32
+ ];
33
+
34
+ const getChildren = (type: string) => {
35
+ switch (type) {
36
+ case "badge":
37
+ return `<div class="s-progress--label" id="example-label">
38
+ <div class="s-badge--label">Electorate</div>
39
+ </div>
40
+ <div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-labelledby="example-label" style="width: 75%;"></div>`;
41
+ case "circular":
42
+ return `<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75">
43
+ <circle cx="16" cy="16" r="14"></circle>
44
+ <circle cx="16" cy="16" r="14"></circle>
45
+ </svg>`;
46
+ case "privilege":
47
+ return `
48
+ <div class="s-progress--label" id="progress-label">
49
+ ${IconAchievementsSm}
50
+ Access Review Queues
51
+ </div>
52
+ <div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-labelledby="progress-label" style="width: 75%;"></div>
53
+ `;
54
+ case "segmented":
55
+ return `
56
+ <div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-label="…" style="width: 75%;"></div>
57
+ <ol class="s-progress--segments">
58
+ <li></li><li></li><li></li>
59
+ </ol>
60
+ `;
61
+ case "stepped":
62
+ return steppedItems
63
+ .map((step, i) => {
64
+ return `
65
+ <div
66
+ class="
67
+ s-progress--step
68
+ ${step.active ? "is-active" : ""}
69
+ ${step.complete ? "is-complete" : ""}
70
+ "
71
+ >
72
+ <a href="#" class="s-progress--stop">
73
+ ${step.complete ? IconCheckmarkSm : ""}
74
+ <span class="v-visible-sr">${step.label} ${
75
+ step.complete ? "complete" : "incomplete"
76
+ }</span>
77
+ </a>
78
+ ${
79
+ i > 0
80
+ ? '<div class="s-progress--bar s-progress--bar__left"></div>'
81
+ : ""
82
+ }
83
+
84
+ ${
85
+ i < steppedItems.length - 1
86
+ ? '<div class="s-progress--bar s-progress--bar__right"></div>'
87
+ : ""
88
+ }
89
+ <a class="s-progress--label">${step.label}</a>
90
+ </div>
91
+ `;
92
+ })
93
+ .join("");
94
+ default:
95
+ return `<div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-label="progress" style="width: 75%"></div>`;
96
+ }
97
+ };
98
+ describe("progress-bar", () => {
99
+ // Base
100
+ runComponentTests({
101
+ type: "a11y",
102
+ baseClass: "s-progress",
103
+ variants: ["brand", "info"],
104
+ children: {
105
+ default: getChildren(""),
106
+ },
107
+ template,
108
+ });
109
+
110
+ // Badge
111
+ runComponentTests({
112
+ type: "a11y",
113
+ baseClass: "s-progress",
114
+ variants: ["badge"],
115
+ modifiers: {
116
+ primary: ["gold", "silver", "bronze"],
117
+ },
118
+ children: {
119
+ default: getChildren("badge"),
120
+ },
121
+ template,
122
+ options: {
123
+ ...defaultOptions,
124
+ includeNullVariant: false,
125
+ includeNullModifier: false,
126
+ },
127
+ });
128
+
129
+ // Circular
130
+ runComponentTests({
131
+ type: "a11y",
132
+ baseClass: "s-progress",
133
+ variants: ["circular"],
134
+ modifiers: {
135
+ global: ["fc-green-400", "fc-theme-primary"],
136
+ },
137
+ children: {
138
+ default: getChildren("circular"),
139
+ },
140
+ template,
141
+ attributes: {
142
+ style: "--s-progress-value: .75",
143
+ },
144
+ options: {
145
+ ...defaultOptions,
146
+ includeNullVariant: false,
147
+ includeNullModifier: false,
148
+ },
149
+ });
150
+
151
+ // Privilege
152
+ runComponentTests({
153
+ type: "a11y",
154
+ baseClass: "s-progress",
155
+ variants: ["privilege"],
156
+ children: {
157
+ default: getChildren("privilege"),
158
+ },
159
+ template,
160
+ options: {
161
+ ...defaultOptions,
162
+ includeNullVariant: false,
163
+ },
164
+ });
165
+
166
+ // Segmented
167
+ runComponentTests({
168
+ type: "a11y",
169
+ baseClass: "s-progress",
170
+ variants: ["segmented"],
171
+ children: {
172
+ default: getChildren("segmented"),
173
+ },
174
+ template,
175
+ options: {
176
+ ...defaultOptions,
177
+ includeNullVariant: false,
178
+ },
179
+ });
180
+
181
+ // Stepped
182
+ runComponentTests({
183
+ type: "a11y",
184
+ baseClass: "s-progress",
185
+ variants: ["stepped"],
186
+ children: {
187
+ default: getChildren("stepped"),
188
+ },
189
+ template: ({ component, testid }) => html`
190
+ <div class="d-block p8 ws5" data-testid="${testid}">
191
+ ${component}
192
+ </div>
193
+ `,
194
+ options: {
195
+ ...defaultOptions,
196
+ includeNullVariant: false,
197
+ },
198
+ // TODO add skipped test ids
199
+ });
200
+ });
@@ -0,0 +1,199 @@
1
+ import { html } from "@open-wc/testing";
2
+ import {
3
+ IconAchievementsSm,
4
+ IconCheckmarkSm,
5
+ } from "@stackoverflow/stacks-icons/icons";
6
+ import { defaultOptions, runComponentTests } from "../../test/test-utils";
7
+ import "../../index";
8
+
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const template = ({ component, testid }: any) => html`
11
+ <div class="d-flex ai-center jc-center p8 ws2" data-testid="${testid}">
12
+ ${component}
13
+ </div>
14
+ `;
15
+
16
+ const steppedItems = [
17
+ {
18
+ complete: true,
19
+ label: "Select plan",
20
+ },
21
+ {
22
+ complete: true,
23
+ label: "Team name",
24
+ },
25
+ {
26
+ active: true,
27
+ label: "Payment",
28
+ },
29
+ {
30
+ label: "Create account",
31
+ },
32
+ ];
33
+
34
+ const getChildren = (type: string) => {
35
+ switch (type) {
36
+ case "badge":
37
+ return `<div class="s-progress--label" id="example-label">
38
+ <div class="s-badge--label">Electorate</div>
39
+ </div>
40
+ <div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-labelledby="example-label" style="width: 75%;"></div>`;
41
+ case "circular":
42
+ return `<svg class="s-progress-bar" role="progressbar" viewbox="0 0 32 32" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75">
43
+ <circle cx="16" cy="16" r="14"></circle>
44
+ <circle cx="16" cy="16" r="14"></circle>
45
+ </svg>`;
46
+ case "privilege":
47
+ return `
48
+ <div class="s-progress--label" id="progress-label">
49
+ ${IconAchievementsSm}
50
+ Access Review Queues
51
+ </div>
52
+ <div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-labelledby="progress-label" style="width: 75%;"></div>
53
+ `;
54
+ case "segmented":
55
+ return `
56
+ <div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-label="…" style="width: 75%;"></div>
57
+ <ol class="s-progress--segments">
58
+ <li></li><li></li><li></li>
59
+ </ol>
60
+ `;
61
+ case "stepped":
62
+ return steppedItems
63
+ .map((step, i) => {
64
+ return `
65
+ <div
66
+ class="
67
+ s-progress--step
68
+ ${step.active ? "is-active" : ""}
69
+ ${step.complete ? "is-complete" : ""}
70
+ "
71
+ >
72
+ <a href="#" class="s-progress--stop">
73
+ ${step.complete ? IconCheckmarkSm : ""}
74
+ <span class="v-visible-sr">${step.label} ${
75
+ step.complete ? "complete" : "incomplete"
76
+ }</span>
77
+ </a>
78
+ ${
79
+ i > 0
80
+ ? '<div class="s-progress--bar s-progress--bar__left"></div>'
81
+ : ""
82
+ }
83
+
84
+ ${
85
+ i < steppedItems.length - 1
86
+ ? '<div class="s-progress--bar s-progress--bar__right"></div>'
87
+ : ""
88
+ }
89
+ <a class="s-progress--label">${step.label}</a>
90
+ </div>
91
+ `;
92
+ })
93
+ .join("");
94
+ default:
95
+ return `<div class="s-progress--bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="75" aria-label="progress" style="width: 75%"></div>`;
96
+ }
97
+ };
98
+ describe("progress-bar", () => {
99
+ // Base
100
+ runComponentTests({
101
+ type: "visual",
102
+ baseClass: "s-progress",
103
+ variants: ["brand", "info"],
104
+ children: {
105
+ default: getChildren(""),
106
+ },
107
+ template,
108
+ });
109
+
110
+ // Badge
111
+ runComponentTests({
112
+ type: "visual",
113
+ baseClass: "s-progress",
114
+ variants: ["badge"],
115
+ modifiers: {
116
+ primary: ["gold", "silver", "bronze"],
117
+ },
118
+ children: {
119
+ default: getChildren("badge"),
120
+ },
121
+ template,
122
+ options: {
123
+ ...defaultOptions,
124
+ includeNullVariant: false,
125
+ includeNullModifier: false,
126
+ },
127
+ });
128
+
129
+ // Circular
130
+ runComponentTests({
131
+ type: "visual",
132
+ baseClass: "s-progress",
133
+ variants: ["circular"],
134
+ modifiers: {
135
+ global: ["fc-green-400", "fc-theme-primary"],
136
+ },
137
+ children: {
138
+ default: getChildren("circular"),
139
+ },
140
+ template,
141
+ attributes: {
142
+ style: "--s-progress-value: .75",
143
+ },
144
+ options: {
145
+ ...defaultOptions,
146
+ includeNullVariant: false,
147
+ includeNullModifier: false,
148
+ },
149
+ });
150
+
151
+ // Privilege
152
+ runComponentTests({
153
+ type: "visual",
154
+ baseClass: "s-progress",
155
+ variants: ["privilege"],
156
+ children: {
157
+ default: getChildren("privilege"),
158
+ },
159
+ template,
160
+ options: {
161
+ ...defaultOptions,
162
+ includeNullVariant: false,
163
+ },
164
+ });
165
+
166
+ // Segmented
167
+ runComponentTests({
168
+ type: "visual",
169
+ baseClass: "s-progress",
170
+ variants: ["segmented"],
171
+ children: {
172
+ default: getChildren("segmented"),
173
+ },
174
+ template,
175
+ options: {
176
+ ...defaultOptions,
177
+ includeNullVariant: false,
178
+ },
179
+ });
180
+
181
+ // Stepped
182
+ runComponentTests({
183
+ type: "visual",
184
+ baseClass: "s-progress",
185
+ variants: ["stepped"],
186
+ children: {
187
+ default: getChildren("stepped"),
188
+ },
189
+ template: ({ component, testid }) => html`
190
+ <div class="d-block p8 ws5" data-testid="${testid}">
191
+ ${component}
192
+ </div>
193
+ `,
194
+ options: {
195
+ ...defaultOptions,
196
+ includeNullVariant: false,
197
+ },
198
+ });
199
+ });