@noctuatech/uswds 0.0.4 → 0.0.5
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/assets/uswds.min.js +1 -1
- package/package.json +4 -4
- package/src/lib/accordion/accordion.element.ts +22 -19
- package/src/lib/accordion/accordion.test.ts +50 -48
- package/src/lib/checkbox/checkbox.element.ts +3 -1
- package/src/lib/define.ts +2 -0
- package/src/lib/link/link.element.ts +6 -2
- package/src/lib/radio/radio-option.element.ts +31 -13
- package/src/lib/radio/radio.element.ts +27 -41
- package/src/lib/radio/radio.stories.ts +18 -8
- package/src/lib/select/select-option.element.ts +10 -11
- package/src/lib/select/select.element.ts +7 -21
- package/src/lib/side-nav/side-nav-item.element.ts +86 -0
- package/src/lib/side-nav/side-nav.element.ts +25 -0
- package/src/lib/side-nav/side-nav.stories.ts +62 -0
- package/src/lib/side-nav/side-nav.test.ts +110 -0
- package/src/lib.ts +1 -0
- package/target/lib/accordion/accordion.element.d.ts +5 -5
- package/target/lib/accordion/accordion.element.js +18 -15
- package/target/lib/accordion/accordion.element.js.map +1 -1
- package/target/lib/accordion/accordion.test.js +50 -40
- package/target/lib/accordion/accordion.test.js.map +1 -1
- package/target/lib/checkbox/checkbox.element.js +3 -1
- package/target/lib/checkbox/checkbox.element.js.map +1 -1
- package/target/lib/define.d.ts +2 -0
- package/target/lib/define.js +2 -0
- package/target/lib/define.js.map +1 -1
- package/target/lib/link/link.element.js +6 -2
- package/target/lib/link/link.element.js.map +1 -1
- package/target/lib/radio/radio-option.element.d.ts +5 -2
- package/target/lib/radio/radio-option.element.js +37 -15
- package/target/lib/radio/radio-option.element.js.map +1 -1
- package/target/lib/radio/radio.element.d.ts +2 -3
- package/target/lib/radio/radio.element.js +30 -37
- package/target/lib/radio/radio.element.js.map +1 -1
- package/target/lib/radio/radio.stories.d.ts +7 -2
- package/target/lib/radio/radio.stories.js +13 -7
- package/target/lib/radio/radio.stories.js.map +1 -1
- package/target/lib/select/select-option.element.d.ts +2 -1
- package/target/lib/select/select-option.element.js +8 -11
- package/target/lib/select/select-option.element.js.map +1 -1
- package/target/lib/select/select.element.d.ts +1 -3
- package/target/lib/select/select.element.js +10 -19
- package/target/lib/select/select.element.js.map +1 -1
- package/target/lib/side-nav/side-nav-item.element.d.ts +8 -0
- package/target/lib/side-nav/side-nav-item.element.js +109 -0
- package/target/lib/side-nav/side-nav-item.element.js.map +1 -0
- package/target/lib/side-nav/side-nav.element.d.ts +8 -0
- package/target/lib/side-nav/side-nav.element.js +36 -0
- package/target/lib/side-nav/side-nav.element.js.map +1 -0
- package/target/lib/side-nav/side-nav.stories.d.ts +12 -0
- package/target/lib/side-nav/side-nav.stories.js +55 -0
- package/target/lib/side-nav/side-nav.stories.js.map +1 -0
- package/target/lib/side-nav/side-nav.test.d.ts +2 -0
- package/target/lib/side-nav/side-nav.test.js +92 -0
- package/target/lib/side-nav/side-nav.test.js.map +1 -0
- package/target/lib.d.ts +1 -0
- package/target/lib.js +1 -0
- package/target/lib.js.map +1 -1
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { attr, css, element, html } from "@joist/element";
|
|
2
2
|
|
|
3
|
-
import { USARadioElement } from "./radio.element.js";
|
|
4
|
-
|
|
5
3
|
declare global {
|
|
6
4
|
interface HTMLElementTagNameMap {
|
|
7
|
-
"usa-radio-option":
|
|
5
|
+
"usa-radio-option": USARadioOptionElement;
|
|
8
6
|
}
|
|
9
7
|
}
|
|
10
8
|
|
|
@@ -13,8 +11,9 @@ declare global {
|
|
|
13
11
|
shadowDom: [
|
|
14
12
|
css`
|
|
15
13
|
:host {
|
|
16
|
-
display:
|
|
14
|
+
display: flex;
|
|
17
15
|
flex-direction: column;
|
|
16
|
+
margin-top: 0.05rem;
|
|
18
17
|
}
|
|
19
18
|
`,
|
|
20
19
|
html`<slot></slot>`,
|
|
@@ -24,23 +23,42 @@ export class USARadioOptionElement extends HTMLElement {
|
|
|
24
23
|
@attr()
|
|
25
24
|
accessor value = "";
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
@attr()
|
|
27
|
+
accessor name = "";
|
|
28
|
+
|
|
29
|
+
@attr()
|
|
30
|
+
accessor checked = false;
|
|
31
|
+
|
|
32
|
+
readonly radio = document.createElement("label");
|
|
33
|
+
|
|
34
|
+
readonly #input = document.createElement("input");
|
|
35
|
+
readonly #slotEl = document.createElement("slot");
|
|
36
|
+
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
|
|
40
|
+
this.#input.type = "radio";
|
|
41
|
+
|
|
42
|
+
this.radio.append(this.#input, this.#slotEl);
|
|
43
|
+
}
|
|
28
44
|
|
|
29
45
|
attributeChangedCallback() {
|
|
30
46
|
this.slot = this.value;
|
|
47
|
+
|
|
48
|
+
this.#input.name = this.name;
|
|
49
|
+
this.#input.value = this.value;
|
|
50
|
+
this.#input.checked = this.checked;
|
|
51
|
+
|
|
52
|
+
this.#slotEl.name = this.value;
|
|
31
53
|
}
|
|
32
54
|
|
|
33
55
|
connectedCallback() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.parentElement.onOptionAdded(this);
|
|
38
|
-
}
|
|
56
|
+
this.dispatchEvent(
|
|
57
|
+
new Event("usa::radio::option::added", { bubbles: true })
|
|
58
|
+
);
|
|
39
59
|
}
|
|
40
60
|
|
|
41
61
|
disconnectedCallback() {
|
|
42
|
-
|
|
43
|
-
this.#parent.onOptionRemoved(this);
|
|
44
|
-
}
|
|
62
|
+
this.radio.remove();
|
|
45
63
|
}
|
|
46
64
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { attr, css, element, html, listen
|
|
1
|
+
import { attr, css, element, html, listen } from "@joist/element";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { USARadioOptionElement } from "./radio-option.element.js";
|
|
4
4
|
|
|
5
5
|
declare global {
|
|
6
6
|
interface HTMLElementTagNameMap {
|
|
@@ -13,14 +13,10 @@ declare global {
|
|
|
13
13
|
shadowDom: [
|
|
14
14
|
css`
|
|
15
15
|
:host {
|
|
16
|
-
display: block;
|
|
17
|
-
max-width: 30rem;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.radios {
|
|
21
16
|
display: flex;
|
|
22
17
|
flex-direction: column;
|
|
23
18
|
gap: 1rem;
|
|
19
|
+
max-width: 30rem;
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
label {
|
|
@@ -59,7 +55,7 @@ declare global {
|
|
|
59
55
|
outline-offset: 0.25rem;
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
:host([tiled])
|
|
58
|
+
:host([tiled]) {
|
|
63
59
|
gap: 0.5rem;
|
|
64
60
|
}
|
|
65
61
|
|
|
@@ -75,12 +71,16 @@ declare global {
|
|
|
75
71
|
background-color: rgba(0, 94, 162, 0.1);
|
|
76
72
|
border-color: #005ea2;
|
|
77
73
|
}
|
|
78
|
-
`,
|
|
79
|
-
html`
|
|
80
|
-
<slot></slot>
|
|
81
74
|
|
|
82
|
-
|
|
75
|
+
slot {
|
|
76
|
+
display: flex;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
slot#main {
|
|
80
|
+
margin-bottom: 0.5rem;
|
|
81
|
+
}
|
|
83
82
|
`,
|
|
83
|
+
html`<slot id="main"></slot>`,
|
|
84
84
|
],
|
|
85
85
|
})
|
|
86
86
|
export class USARadioElement extends HTMLElement {
|
|
@@ -92,10 +92,15 @@ export class USARadioElement extends HTMLElement {
|
|
|
92
92
|
@attr()
|
|
93
93
|
accessor name = "";
|
|
94
94
|
|
|
95
|
-
@attr(
|
|
95
|
+
@attr({
|
|
96
|
+
observed: false,
|
|
97
|
+
})
|
|
96
98
|
accessor tiled = false;
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
get shadow() {
|
|
101
|
+
return this.shadowRoot!;
|
|
102
|
+
}
|
|
103
|
+
|
|
99
104
|
#internals = this.attachInternals();
|
|
100
105
|
|
|
101
106
|
@listen("change")
|
|
@@ -115,40 +120,21 @@ export class USARadioElement extends HTMLElement {
|
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
attributeChangedCallback() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
for (let radio of radios.querySelectorAll("input")) {
|
|
123
|
+
for (let radio of this.shadow.querySelectorAll("usa-radio-option")) {
|
|
121
124
|
radio.checked = radio.value === this.value;
|
|
122
125
|
radio.name = this.name;
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
radioLabel.id = el.value;
|
|
131
|
-
|
|
132
|
-
const input = document.createElement("input");
|
|
133
|
-
input.type = "radio";
|
|
134
|
-
input.name = this.name;
|
|
135
|
-
input.value = el.value;
|
|
136
|
-
input.checked = this.value === el.value;
|
|
137
|
-
|
|
138
|
-
const slot = document.createElement("slot");
|
|
139
|
-
slot.name = el.value;
|
|
140
|
-
|
|
141
|
-
radioLabel.append(input, slot);
|
|
142
|
-
|
|
143
|
-
radios.append(radioLabel);
|
|
144
|
-
}
|
|
129
|
+
@listen("usa::radio::option::added", (el) => el)
|
|
130
|
+
onOptionAdded(e: Event) {
|
|
131
|
+
if (e.target instanceof USARadioOptionElement) {
|
|
132
|
+
e.stopPropagation();
|
|
145
133
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const option = radios.querySelector(`#${el.value}`);
|
|
134
|
+
e.target.checked = e.target.value === this.value;
|
|
135
|
+
e.target.name = this.name;
|
|
149
136
|
|
|
150
|
-
|
|
151
|
-
option.remove();
|
|
137
|
+
this.shadow.append(e.target.radio);
|
|
152
138
|
}
|
|
153
139
|
}
|
|
154
140
|
}
|
|
@@ -2,6 +2,7 @@ import type { Meta, StoryObj } from "@storybook/web-components";
|
|
|
2
2
|
import { html } from "lit";
|
|
3
3
|
|
|
4
4
|
import type { USARadioElement } from "./radio.element.js";
|
|
5
|
+
import { when } from "lit/directives/when.js";
|
|
5
6
|
|
|
6
7
|
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
7
8
|
const meta = {
|
|
@@ -9,18 +10,23 @@ const meta = {
|
|
|
9
10
|
tags: ["autodocs"],
|
|
10
11
|
render(args) {
|
|
11
12
|
return html`
|
|
12
|
-
<usa-radio
|
|
13
|
+
<usa-radio
|
|
14
|
+
name="historical-figures"
|
|
15
|
+
value="frederick-douglass"
|
|
16
|
+
?tiled=${args.tiled}
|
|
17
|
+
>
|
|
18
|
+
<legend>Select one historical figure</legend>
|
|
19
|
+
|
|
13
20
|
<usa-radio-option value="sojourner-truth">
|
|
14
21
|
Sojourner Truth
|
|
15
22
|
</usa-radio-option>
|
|
16
23
|
|
|
17
24
|
<usa-radio-option value="frederick-douglass">
|
|
18
25
|
Frederick Douglass
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
</usa-description>
|
|
26
|
+
${when(
|
|
27
|
+
args.description,
|
|
28
|
+
() => html`<usa-description>${args.description}</usa-description>`
|
|
29
|
+
)}
|
|
24
30
|
</usa-radio-option>
|
|
25
31
|
|
|
26
32
|
<usa-radio-option value="booker-t-washington">
|
|
@@ -34,8 +40,12 @@ const meta = {
|
|
|
34
40
|
`;
|
|
35
41
|
},
|
|
36
42
|
argTypes: {},
|
|
37
|
-
args: {
|
|
38
|
-
|
|
43
|
+
args: {
|
|
44
|
+
tiled: true,
|
|
45
|
+
description:
|
|
46
|
+
"This is optional text that can be used to describe the label in more detail.",
|
|
47
|
+
},
|
|
48
|
+
} satisfies Meta<USARadioElement & { description: string }>;
|
|
39
49
|
|
|
40
50
|
export default meta;
|
|
41
51
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { attr, css, element } from "@joist/element";
|
|
2
2
|
|
|
3
|
-
import { USASelectElement } from "./select.element.js";
|
|
4
|
-
|
|
5
3
|
declare global {
|
|
6
4
|
interface HTMLElementTagNameMap {
|
|
7
5
|
"usa-select-option": USASelecOptionElement;
|
|
@@ -22,19 +20,20 @@ export class USASelecOptionElement extends HTMLElement {
|
|
|
22
20
|
@attr()
|
|
23
21
|
accessor value = "";
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
readonly option = document.createElement("option");
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
attributeChangedCallback() {
|
|
26
|
+
this.option.textContent = this.textContent;
|
|
27
|
+
this.option.value = this.value;
|
|
28
|
+
}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
this.dispatchEvent(
|
|
32
|
+
new Event("usa::select::option::added", { bubbles: true })
|
|
33
|
+
);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
disconnectedCallback() {
|
|
36
|
-
|
|
37
|
-
this.#parent.onOptionRemoved(this);
|
|
38
|
-
}
|
|
37
|
+
this.option.remove();
|
|
39
38
|
}
|
|
40
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { attr, css, element, html, listen, query } from "@joist/element";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { USASelecOptionElement } from "./select-option.element.js";
|
|
4
4
|
|
|
5
5
|
declare global {
|
|
6
6
|
interface HTMLElementTagNameMap {
|
|
@@ -95,27 +95,13 @@ export class USASelectElement extends HTMLElement {
|
|
|
95
95
|
this.#internals.setFormValue(select.value);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
option.id = this.#createId(el.value);
|
|
98
|
+
@listen("usa::select::option::added")
|
|
99
|
+
onOptionAdded(e: Event) {
|
|
100
|
+
if (e.target instanceof USASelecOptionElement) {
|
|
101
|
+
e.stopPropagation();
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
select.append(option);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
onOptionRemoved(el: USASelecOptionElement) {
|
|
110
|
-
const select = this.#select();
|
|
111
|
-
const option = select.querySelector(`#${this.#createId(el.value)}`);
|
|
112
|
-
|
|
113
|
-
if (option) {
|
|
114
|
-
option.remove();
|
|
103
|
+
const select = this.#select();
|
|
104
|
+
select.append(e.target.option);
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
|
-
|
|
118
|
-
#createId(val: string) {
|
|
119
|
-
return val.split(" ").join("-").toLowerCase();
|
|
120
|
-
}
|
|
121
107
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { attr, css, element, html } from "@joist/element";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElementTagNameMap {
|
|
5
|
+
"usa-side-nav-item": USASideNavItemElement;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@element({
|
|
10
|
+
tagName: "usa-side-nav-item",
|
|
11
|
+
shadowDom: [
|
|
12
|
+
css`
|
|
13
|
+
:host {
|
|
14
|
+
--usa-nav-item-padding-left: 2rem;
|
|
15
|
+
|
|
16
|
+
display: block;
|
|
17
|
+
border-top: 1px solid #e6e6e6;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.side-nav-item {
|
|
21
|
+
display: flex;
|
|
22
|
+
padding: 0.5rem 1rem;
|
|
23
|
+
text-decoration: none;
|
|
24
|
+
position: relative;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.side-nav-item:hover {
|
|
28
|
+
background-color: #f0f0f0;
|
|
29
|
+
color: #005ea2;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
::slotted(*) {
|
|
33
|
+
color: #5c5c5c;
|
|
34
|
+
text-decoration: none;
|
|
35
|
+
display: block;
|
|
36
|
+
width: 100%;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
:host(:hover) ::slotted(*) {
|
|
40
|
+
color: #005ea2;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
:host([current]) ::slotted(*:not(usa-side-nav-item)) {
|
|
44
|
+
color: #005ea2;
|
|
45
|
+
font-weight: 700;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
:host([current]) .side-nav-item::after {
|
|
49
|
+
background-color: #005ea2;
|
|
50
|
+
border-radius: 99rem;
|
|
51
|
+
content: "";
|
|
52
|
+
display: block;
|
|
53
|
+
position: absolute;
|
|
54
|
+
bottom: 0.25rem;
|
|
55
|
+
top: 0.25rem;
|
|
56
|
+
width: 0.25rem;
|
|
57
|
+
left: 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:host([slot="children"]) .side-nav-item {
|
|
61
|
+
padding-left: var(--usa-nav-item-padding-left);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
:host([slot="children"]) ::slotted(usa-side-nav-item) {
|
|
65
|
+
--usa-nav-item-padding-left: 3rem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
:host([slot="children"]) .side-nav-item::after {
|
|
69
|
+
display: none;
|
|
70
|
+
}
|
|
71
|
+
`,
|
|
72
|
+
html`
|
|
73
|
+
<div class="side-nav-item">
|
|
74
|
+
<slot></slot>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<slot name="children"></slot>
|
|
78
|
+
`,
|
|
79
|
+
],
|
|
80
|
+
})
|
|
81
|
+
export class USASideNavItemElement extends HTMLElement {
|
|
82
|
+
@attr({
|
|
83
|
+
observed: false,
|
|
84
|
+
})
|
|
85
|
+
accessor current = false;
|
|
86
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "./side-nav-item.element.js";
|
|
2
|
+
|
|
3
|
+
import { css, element, html } from "@joist/element";
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface HTMLElementTagNameMap {
|
|
7
|
+
"usa-side-nav": USASideNavElement;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@element({
|
|
12
|
+
tagName: "usa-side-nav",
|
|
13
|
+
shadowDom: [
|
|
14
|
+
css`
|
|
15
|
+
:host {
|
|
16
|
+
display: block;
|
|
17
|
+
font-size: 1.06rem;
|
|
18
|
+
line-height: 1.3;
|
|
19
|
+
border-bottom: 1px solid #e6e6e6;
|
|
20
|
+
}
|
|
21
|
+
`,
|
|
22
|
+
html`<slot></slot>`,
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
export class USASideNavElement extends HTMLElement {}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/web-components";
|
|
2
|
+
import { html } from "lit";
|
|
3
|
+
|
|
4
|
+
import type { USASideNavElement } from "./side-nav.element.js";
|
|
5
|
+
|
|
6
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
7
|
+
const meta = {
|
|
8
|
+
title: "usa-side-nav",
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
render(args) {
|
|
11
|
+
return html`
|
|
12
|
+
<usa-side-nav>
|
|
13
|
+
<usa-side-nav-item current>
|
|
14
|
+
<usa-link href="#">Current Page</usa-link>
|
|
15
|
+
|
|
16
|
+
<usa-side-nav-item slot="children">
|
|
17
|
+
<usa-link href="#">Child</usa-link>
|
|
18
|
+
</usa-side-nav-item>
|
|
19
|
+
|
|
20
|
+
<usa-side-nav-item slot="children" current>
|
|
21
|
+
<usa-link href="#">Child</usa-link>
|
|
22
|
+
|
|
23
|
+
<usa-side-nav-item slot="children">
|
|
24
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
25
|
+
</usa-side-nav-item>
|
|
26
|
+
|
|
27
|
+
<usa-side-nav-item slot="children" current>
|
|
28
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
29
|
+
</usa-side-nav-item>
|
|
30
|
+
|
|
31
|
+
<usa-side-nav-item slot="children">
|
|
32
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
33
|
+
</usa-side-nav-item>
|
|
34
|
+
</usa-side-nav-item>
|
|
35
|
+
|
|
36
|
+
<usa-side-nav-item slot="children">
|
|
37
|
+
<usa-link href="#">Child</usa-link>
|
|
38
|
+
</usa-side-nav-item>
|
|
39
|
+
</usa-side-nav-item>
|
|
40
|
+
|
|
41
|
+
<usa-side-nav-item>
|
|
42
|
+
<usa-link href="#">Parent</usa-link>
|
|
43
|
+
</usa-side-nav-item>
|
|
44
|
+
|
|
45
|
+
<usa-side-nav-item>
|
|
46
|
+
<usa-link href="#">Parent</usa-link>
|
|
47
|
+
</usa-side-nav-item>
|
|
48
|
+
</usa-side-nav>
|
|
49
|
+
`;
|
|
50
|
+
},
|
|
51
|
+
argTypes: {},
|
|
52
|
+
args: {},
|
|
53
|
+
} satisfies Meta<USASideNavElement>;
|
|
54
|
+
|
|
55
|
+
export default meta;
|
|
56
|
+
|
|
57
|
+
type Story = StoryObj<USASideNavElement>;
|
|
58
|
+
|
|
59
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
60
|
+
export const Primary: Story = {
|
|
61
|
+
args: {},
|
|
62
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import "../link/link.element.js";
|
|
2
|
+
import "./side-nav.element.js";
|
|
3
|
+
|
|
4
|
+
import { fixture, html, assert } from "@open-wc/testing";
|
|
5
|
+
|
|
6
|
+
import { USASideNavElement } from "./side-nav.element.js";
|
|
7
|
+
|
|
8
|
+
describe("usa-side-nav", () => {
|
|
9
|
+
it("should be accessible", async () => {
|
|
10
|
+
const sideNav = await fixture<USASideNavElement>(html`
|
|
11
|
+
<usa-side-nav>
|
|
12
|
+
<usa-side-nav-item current>
|
|
13
|
+
<usa-link href="#">Current Page</usa-link>
|
|
14
|
+
|
|
15
|
+
<usa-side-nav-item slot="children">
|
|
16
|
+
<usa-link href="#">Child</usa-link>
|
|
17
|
+
</usa-side-nav-item>
|
|
18
|
+
|
|
19
|
+
<usa-side-nav-item slot="children" current>
|
|
20
|
+
<usa-link href="#">Child</usa-link>
|
|
21
|
+
|
|
22
|
+
<usa-side-nav-item slot="children">
|
|
23
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
24
|
+
</usa-side-nav-item>
|
|
25
|
+
|
|
26
|
+
<usa-side-nav-item slot="children" current>
|
|
27
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
28
|
+
</usa-side-nav-item>
|
|
29
|
+
|
|
30
|
+
<usa-side-nav-item slot="children">
|
|
31
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
32
|
+
</usa-side-nav-item>
|
|
33
|
+
</usa-side-nav-item>
|
|
34
|
+
|
|
35
|
+
<usa-side-nav-item slot="children">
|
|
36
|
+
<usa-link href="#">Child</usa-link>
|
|
37
|
+
</usa-side-nav-item>
|
|
38
|
+
</usa-side-nav-item>
|
|
39
|
+
|
|
40
|
+
<usa-side-nav-item>
|
|
41
|
+
<usa-link href="#">Parent</usa-link>
|
|
42
|
+
</usa-side-nav-item>
|
|
43
|
+
|
|
44
|
+
<usa-side-nav-item>
|
|
45
|
+
<usa-link href="#">Parent</usa-link>
|
|
46
|
+
</usa-side-nav-item>
|
|
47
|
+
</usa-side-nav>
|
|
48
|
+
`);
|
|
49
|
+
|
|
50
|
+
return assert.isAccessible(sideNav);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should set child padding correctly", async () => {
|
|
54
|
+
const sideNav = await fixture<USASideNavElement>(html`
|
|
55
|
+
<usa-side-nav>
|
|
56
|
+
<usa-side-nav-item current>
|
|
57
|
+
<usa-link href="#">Current Page</usa-link>
|
|
58
|
+
|
|
59
|
+
<usa-side-nav-item slot="children">
|
|
60
|
+
<usa-link href="#">Child</usa-link>
|
|
61
|
+
</usa-side-nav-item>
|
|
62
|
+
|
|
63
|
+
<usa-side-nav-item slot="children" current>
|
|
64
|
+
<usa-link href="#">Child</usa-link>
|
|
65
|
+
|
|
66
|
+
<usa-side-nav-item slot="children">
|
|
67
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
68
|
+
</usa-side-nav-item>
|
|
69
|
+
|
|
70
|
+
<usa-side-nav-item slot="children" current>
|
|
71
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
72
|
+
</usa-side-nav-item>
|
|
73
|
+
|
|
74
|
+
<usa-side-nav-item slot="children">
|
|
75
|
+
<usa-link href="#">Grandchild</usa-link>
|
|
76
|
+
</usa-side-nav-item>
|
|
77
|
+
</usa-side-nav-item>
|
|
78
|
+
|
|
79
|
+
<usa-side-nav-item slot="children">
|
|
80
|
+
<usa-link href="#">Child</usa-link>
|
|
81
|
+
</usa-side-nav-item>
|
|
82
|
+
</usa-side-nav-item>
|
|
83
|
+
|
|
84
|
+
<usa-side-nav-item>
|
|
85
|
+
<usa-link href="#">Parent</usa-link>
|
|
86
|
+
</usa-side-nav-item>
|
|
87
|
+
|
|
88
|
+
<usa-side-nav-item>
|
|
89
|
+
<usa-link href="#">Parent</usa-link>
|
|
90
|
+
</usa-side-nav-item>
|
|
91
|
+
</usa-side-nav>
|
|
92
|
+
`);
|
|
93
|
+
|
|
94
|
+
const items = sideNav.querySelectorAll("usa-side-nav-item");
|
|
95
|
+
|
|
96
|
+
assert.equal(
|
|
97
|
+
getComputedStyle(items[1]).getPropertyValue(
|
|
98
|
+
"--usa-nav-item-padding-left"
|
|
99
|
+
),
|
|
100
|
+
"2rem"
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
assert.equal(
|
|
104
|
+
getComputedStyle(items[3]).getPropertyValue(
|
|
105
|
+
"--usa-nav-item-padding-left"
|
|
106
|
+
),
|
|
107
|
+
"3rem"
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
});
|
package/src/lib.ts
CHANGED
|
@@ -12,3 +12,4 @@ export { USASelectElement } from "./lib/select/select.element.js";
|
|
|
12
12
|
export { USASelecOptionElement } from "./lib/select/select-option.element.js";
|
|
13
13
|
export { USATagElement } from "./lib/tag/tag.element.js";
|
|
14
14
|
export { USAAccordionElement } from "./lib/accordion/accordion.element.js";
|
|
15
|
+
export { USASideNavElement } from "./lib/side-nav/side-nav.element.js";
|
|
@@ -3,11 +3,6 @@ declare global {
|
|
|
3
3
|
"usa-accordion": USAAccordionElement;
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
-
declare class USAAccordionToggleEvent extends Event {
|
|
7
|
-
open: boolean;
|
|
8
|
-
get target(): USAAccordionElement;
|
|
9
|
-
constructor(open: boolean);
|
|
10
|
-
}
|
|
11
6
|
export declare class USAAccordionElement extends HTMLElement {
|
|
12
7
|
#private;
|
|
13
8
|
accessor name: string;
|
|
@@ -16,4 +11,9 @@ export declare class USAAccordionElement extends HTMLElement {
|
|
|
16
11
|
onClick(e: Event): void;
|
|
17
12
|
onAccordionToggle(e: USAAccordionToggleEvent): void;
|
|
18
13
|
}
|
|
14
|
+
declare class USAAccordionToggleEvent extends Event {
|
|
15
|
+
open: boolean;
|
|
16
|
+
get target(): USAAccordionElement;
|
|
17
|
+
constructor(open: boolean);
|
|
18
|
+
}
|
|
19
19
|
export {};
|