@spectrum-web-components/sidenav 0.12.6 → 0.12.7
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/package.json +5 -5
- package/sp-sidenav-heading.d.ts +6 -0
- package/sp-sidenav-heading.js +14 -0
- package/sp-sidenav-heading.js.map +1 -0
- package/sp-sidenav-item.d.ts +6 -0
- package/sp-sidenav-item.js +14 -0
- package/sp-sidenav-item.js.map +1 -0
- package/sp-sidenav.d.ts +6 -0
- package/sp-sidenav.js +14 -0
- package/sp-sidenav.js.map +1 -0
- package/src/Sidenav.d.ts +38 -0
- package/src/Sidenav.js +154 -0
- package/src/Sidenav.js.map +1 -0
- package/src/SidenavHeading.d.ts +12 -0
- package/src/SidenavHeading.js +48 -0
- package/src/SidenavHeading.js.map +1 -0
- package/src/SidenavItem.d.ts +35 -0
- package/src/SidenavItem.js +154 -0
- package/src/SidenavItem.js.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +15 -0
- package/src/index.js.map +1 -0
- package/src/sidenav-heading.css.d.ts +2 -0
- package/src/sidenav-heading.css.js +69 -0
- package/src/sidenav-heading.css.js.map +1 -0
- package/src/sidenav-item.css.d.ts +2 -0
- package/src/sidenav-item.css.js +125 -0
- package/src/sidenav-item.css.js.map +1 -0
- package/src/sidenav.css.d.ts +2 -0
- package/src/sidenav.css.js +23 -0
- package/src/sidenav.css.js.map +1 -0
- package/src/spectrum-sidenav-heading.css.d.ts +2 -0
- package/src/spectrum-sidenav-heading.css.js +69 -0
- package/src/spectrum-sidenav-heading.css.js.map +1 -0
- package/src/spectrum-sidenav-item.css.d.ts +2 -0
- package/src/spectrum-sidenav-item.css.js +97 -0
- package/src/spectrum-sidenav-item.css.js.map +1 -0
- package/src/spectrum-sidenav.css.d.ts +2 -0
- package/src/spectrum-sidenav.css.js +19 -0
- package/src/spectrum-sidenav.css.js.map +1 -0
- package/stories/sidenav.stories.js +147 -0
- package/stories/sidenav.stories.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/sidenav",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"lit-html"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@spectrum-web-components/base": "^0.5.
|
|
52
|
-
"@spectrum-web-components/reactive-controllers": "^0.2.
|
|
53
|
-
"@spectrum-web-components/shared": "^0.13.
|
|
51
|
+
"@spectrum-web-components/base": "^0.5.4",
|
|
52
|
+
"@spectrum-web-components/reactive-controllers": "^0.2.2",
|
|
53
|
+
"@spectrum-web-components/shared": "^0.13.6",
|
|
54
54
|
"tslib": "^2.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"sideEffects": [
|
|
62
62
|
"./sp-*.js"
|
|
63
63
|
],
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "caf12727e7f91dcf961e1fadacc727eea9ece27b"
|
|
65
65
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { SideNavHeading } from './src/SidenavHeading.js';
|
|
13
|
+
customElements.define('sp-sidenav-heading', SideNavHeading);
|
|
14
|
+
//# sourceMappingURL=sp-sidenav-heading.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sp-sidenav-heading.js","sourceRoot":"","sources":["sp-sidenav-heading.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,cAAc,CAAC,MAAM,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { SideNavHeading } from './src/SidenavHeading.js';\n\ncustomElements.define('sp-sidenav-heading', SideNavHeading);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-sidenav-heading': SideNavHeading;\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { SideNavItem } from './src/SidenavItem.js';
|
|
13
|
+
customElements.define('sp-sidenav-item', SideNavItem);
|
|
14
|
+
//# sourceMappingURL=sp-sidenav-item.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sp-sidenav-item.js","sourceRoot":"","sources":["sp-sidenav-item.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { SideNavItem } from './src/SidenavItem.js';\n\ncustomElements.define('sp-sidenav-item', SideNavItem);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-sidenav-item': SideNavItem;\n }\n}\n"]}
|
package/sp-sidenav.d.ts
ADDED
package/sp-sidenav.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { SideNav } from './src/Sidenav.js';
|
|
13
|
+
customElements.define('sp-sidenav', SideNav);
|
|
14
|
+
//# sourceMappingURL=sp-sidenav.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sp-sidenav.js","sourceRoot":"","sources":["sp-sidenav.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { SideNav } from './src/Sidenav.js';\n\ncustomElements.define('sp-sidenav', SideNav);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-sidenav': SideNav;\n }\n}\n"]}
|
package/src/Sidenav.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CSSResultArray, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
|
|
3
|
+
import { Focusable } from '@spectrum-web-components/shared';
|
|
4
|
+
import { SideNavItem } from './SidenavItem.js';
|
|
5
|
+
export interface SidenavSelectDetail {
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @element sp-sidenav
|
|
10
|
+
*
|
|
11
|
+
* @slot - the Sidenav Items to display
|
|
12
|
+
* @fires change - Announces a change in the `value` property of the navigation element.
|
|
13
|
+
* This change can be "canceled" via `event.preventDefault()`.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SideNav extends Focusable {
|
|
16
|
+
static get styles(): CSSResultArray;
|
|
17
|
+
private items;
|
|
18
|
+
startTrackingSelectionForItem(item: SideNavItem): void;
|
|
19
|
+
stopTrackingSelectionForItem(item: SideNavItem): void;
|
|
20
|
+
rovingTabindexController: RovingTabindexController<SideNavItem>;
|
|
21
|
+
manageTabIndex: boolean;
|
|
22
|
+
value: string | undefined;
|
|
23
|
+
private handleSelect;
|
|
24
|
+
focus(): void;
|
|
25
|
+
blur(): void;
|
|
26
|
+
click(): void;
|
|
27
|
+
get focusElement(): SideNavItem | SideNav;
|
|
28
|
+
private isDisabledChild;
|
|
29
|
+
private handleSlotchange;
|
|
30
|
+
protected render(): TemplateResult;
|
|
31
|
+
protected firstUpdated(changes: PropertyValues): void;
|
|
32
|
+
protected updated(changes: PropertyValues): void;
|
|
33
|
+
}
|
|
34
|
+
declare global {
|
|
35
|
+
interface GlobalEventHandlersEventMap {
|
|
36
|
+
'sp-sidenav:select': CustomEvent<SidenavSelectDetail>;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/Sidenav.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { __decorate } from "tslib";
|
|
13
|
+
import { html, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
|
|
16
|
+
import sidenavStyles from './sidenav.css.js';
|
|
17
|
+
import { Focusable } from '@spectrum-web-components/shared';
|
|
18
|
+
import { SideNavItem } from './SidenavItem.js';
|
|
19
|
+
import { SideNavHeading } from './SidenavHeading.js';
|
|
20
|
+
/**
|
|
21
|
+
* @element sp-sidenav
|
|
22
|
+
*
|
|
23
|
+
* @slot - the Sidenav Items to display
|
|
24
|
+
* @fires change - Announces a change in the `value` property of the navigation element.
|
|
25
|
+
* This change can be "canceled" via `event.preventDefault()`.
|
|
26
|
+
*/
|
|
27
|
+
export class SideNav extends Focusable {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.items = new Set();
|
|
31
|
+
this.rovingTabindexController = new RovingTabindexController(this, {
|
|
32
|
+
focusInIndex: (elements) => {
|
|
33
|
+
return elements.findIndex((el) => {
|
|
34
|
+
return this.value
|
|
35
|
+
? !el.disabled &&
|
|
36
|
+
!this.isDisabledChild(el) &&
|
|
37
|
+
el.value === this.value
|
|
38
|
+
: !el.disabled && !this.isDisabledChild(el);
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
direction: 'vertical',
|
|
42
|
+
elements: () => [...this.querySelectorAll('sp-sidenav-item')],
|
|
43
|
+
isFocusableElement: (el) => !el.disabled && !this.isDisabledChild(el),
|
|
44
|
+
});
|
|
45
|
+
this.manageTabIndex = false;
|
|
46
|
+
this.value = undefined;
|
|
47
|
+
}
|
|
48
|
+
static get styles() {
|
|
49
|
+
return [sidenavStyles];
|
|
50
|
+
}
|
|
51
|
+
startTrackingSelectionForItem(item) {
|
|
52
|
+
this.items.add(item);
|
|
53
|
+
this.rovingTabindexController.clearElementCache();
|
|
54
|
+
}
|
|
55
|
+
stopTrackingSelectionForItem(item) {
|
|
56
|
+
this.items.delete(item);
|
|
57
|
+
this.rovingTabindexController.clearElementCache();
|
|
58
|
+
}
|
|
59
|
+
handleSelect(event) {
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
if (this.value === event.detail.value) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const oldValue = this.value;
|
|
65
|
+
this.value = event.detail.value;
|
|
66
|
+
const applyDefault = this.dispatchEvent(new Event('change', {
|
|
67
|
+
bubbles: true,
|
|
68
|
+
composed: true,
|
|
69
|
+
cancelable: true,
|
|
70
|
+
}));
|
|
71
|
+
if (!applyDefault) {
|
|
72
|
+
this.value = oldValue;
|
|
73
|
+
event.target.selected = false;
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.items.forEach((item) => item.handleSideNavSelect(event));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
focus() {
|
|
81
|
+
this.rovingTabindexController.focus();
|
|
82
|
+
}
|
|
83
|
+
blur() {
|
|
84
|
+
if (this.focusElement === this) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
super.blur();
|
|
88
|
+
}
|
|
89
|
+
click() {
|
|
90
|
+
if (this.focusElement === this) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
super.click();
|
|
94
|
+
}
|
|
95
|
+
get focusElement() {
|
|
96
|
+
return this.rovingTabindexController.focusInElement || this;
|
|
97
|
+
}
|
|
98
|
+
isDisabledChild(child) {
|
|
99
|
+
if (child.disabled) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
let parent = child.parentElement;
|
|
103
|
+
while (parent instanceof SideNavHeading ||
|
|
104
|
+
(!parent.disabled &&
|
|
105
|
+
parent instanceof SideNavItem &&
|
|
106
|
+
parent.expanded)) {
|
|
107
|
+
parent = parent.parentElement;
|
|
108
|
+
}
|
|
109
|
+
return parent !== this;
|
|
110
|
+
}
|
|
111
|
+
handleSlotchange() {
|
|
112
|
+
if (this.manageTabIndex) {
|
|
113
|
+
this.rovingTabindexController.manage();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.rovingTabindexController.unmanage();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
render() {
|
|
120
|
+
return html `
|
|
121
|
+
<nav @sidenav-select=${this.handleSelect}>
|
|
122
|
+
<slot
|
|
123
|
+
name="descendant"
|
|
124
|
+
@slotchange=${this.handleSlotchange}
|
|
125
|
+
></slot>
|
|
126
|
+
</nav>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
firstUpdated(changes) {
|
|
130
|
+
super.firstUpdated(changes);
|
|
131
|
+
const selectedChild = this.querySelector('[selected]');
|
|
132
|
+
if (selectedChild) {
|
|
133
|
+
this.value = selectedChild.value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
updated(changes) {
|
|
137
|
+
super.updated(changes);
|
|
138
|
+
if (changes.has('manageTabIndex')) {
|
|
139
|
+
if (this.manageTabIndex) {
|
|
140
|
+
this.rovingTabindexController.manage();
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this.rovingTabindexController.unmanage();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
__decorate([
|
|
149
|
+
property({ type: Boolean, reflect: true, attribute: 'manage-tab-index' })
|
|
150
|
+
], SideNav.prototype, "manageTabIndex", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
property({ reflect: true })
|
|
153
|
+
], SideNav.prototype, "value", void 0);
|
|
154
|
+
//# sourceMappingURL=Sidenav.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sidenav.js","sourceRoot":"","sources":["Sidenav.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,GAGP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,qEAAqE,CAAC;AAE/G,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OA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CAAC,wBAAwB,CAAC,MAAM,EAAE,CAAC;aAC1C;iBAAM;gBACH,IAAI,CAAC,wBAAwB,CAAC,QAAQ,EAAE,CAAC;aAC5C;SACJ;IACL,CAAC;CACJ;AAjHG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;+CAC5C;AAG9B;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;sCACiB","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\n\nimport sidenavStyles from './sidenav.css.js';\nimport { Focusable } from '@spectrum-web-components/shared';\nimport { SideNavItem } from './SidenavItem.js';\nimport { SideNavHeading } from './SidenavHeading.js';\n\nexport interface SidenavSelectDetail {\n value: string;\n}\n\n/**\n * @element sp-sidenav\n *\n * @slot - the Sidenav Items to display\n * @fires change - Announces a change in the `value` property of the navigation element.\n * This change can be \"canceled\" via `event.preventDefault()`.\n */\nexport class SideNav extends Focusable {\n public static get styles(): CSSResultArray {\n return [sidenavStyles];\n }\n\n private items = new Set<SideNavItem>();\n\n public startTrackingSelectionForItem(item: SideNavItem): void {\n this.items.add(item);\n this.rovingTabindexController.clearElementCache();\n }\n\n public stopTrackingSelectionForItem(item: SideNavItem): void {\n this.items.delete(item);\n this.rovingTabindexController.clearElementCache();\n }\n\n rovingTabindexController = new RovingTabindexController<SideNavItem>(this, {\n focusInIndex: (elements: SideNavItem[]) => {\n return elements.findIndex((el) => {\n return this.value\n ? !el.disabled &&\n !this.isDisabledChild(el) &&\n el.value === this.value\n : !el.disabled && !this.isDisabledChild(el);\n });\n },\n direction: 'vertical',\n elements: () => [...this.querySelectorAll('sp-sidenav-item')],\n isFocusableElement: (el: SideNavItem) =>\n !el.disabled && !this.isDisabledChild(el),\n });\n\n @property({ type: Boolean, reflect: true, attribute: 'manage-tab-index' })\n public manageTabIndex = false;\n\n @property({ reflect: true })\n public value: string | undefined = undefined;\n\n private handleSelect(\n event: CustomEvent<SidenavSelectDetail> & { target: SideNavItem }\n ): void {\n event.stopPropagation();\n if (this.value === event.detail.value) {\n return;\n }\n const oldValue = this.value;\n this.value = event.detail.value;\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.value = oldValue;\n event.target.selected = false;\n event.preventDefault();\n } else {\n this.items.forEach((item) => item.handleSideNavSelect(event));\n }\n }\n\n public focus(): void {\n this.rovingTabindexController.focus();\n }\n\n public blur(): void {\n if (this.focusElement === this) {\n return;\n }\n\n super.blur();\n }\n\n public click(): void {\n if (this.focusElement === this) {\n return;\n }\n\n super.click();\n }\n\n public get focusElement(): SideNavItem | SideNav {\n return this.rovingTabindexController.focusInElement || this;\n }\n\n private isDisabledChild(child: SideNavItem): boolean {\n if (child.disabled) {\n return true;\n }\n let parent = child.parentElement as\n | SideNavItem\n | SideNav\n | SideNavHeading;\n while (\n parent instanceof SideNavHeading ||\n (!(parent as SideNavItem).disabled &&\n parent instanceof SideNavItem &&\n parent.expanded)\n ) {\n parent = parent.parentElement as\n | SideNavItem\n | SideNav\n | SideNavHeading;\n }\n return parent !== this;\n }\n\n private handleSlotchange(): void {\n if (this.manageTabIndex) {\n this.rovingTabindexController.manage();\n } else {\n this.rovingTabindexController.unmanage();\n }\n }\n\n protected render(): TemplateResult {\n return html`\n <nav @sidenav-select=${this.handleSelect}>\n <slot\n name=\"descendant\"\n @slotchange=${this.handleSlotchange}\n ></slot>\n </nav>\n `;\n }\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n const selectedChild = this.querySelector('[selected]') as SideNavItem;\n if (selectedChild) {\n this.value = selectedChild.value;\n }\n }\n\n protected updated(changes: PropertyValues): void {\n super.updated(changes);\n if (changes.has('manageTabIndex')) {\n if (this.manageTabIndex) {\n this.rovingTabindexController.manage();\n } else {\n this.rovingTabindexController.unmanage();\n }\n }\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-sidenav:select': CustomEvent<SidenavSelectDetail>;\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
/**
|
|
3
|
+
* @element sp-sidenav-heading
|
|
4
|
+
*
|
|
5
|
+
* @slot - the Sidenav Items to display in association with the heading
|
|
6
|
+
*/
|
|
7
|
+
export declare class SideNavHeading extends SpectrumElement {
|
|
8
|
+
label: string;
|
|
9
|
+
static get styles(): CSSResultArray;
|
|
10
|
+
protected update(changes: PropertyValues): void;
|
|
11
|
+
protected render(): TemplateResult;
|
|
12
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { __decorate } from "tslib";
|
|
13
|
+
import { html, SpectrumElement, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import sidenavItemStyles from './sidenav-item.css.js';
|
|
16
|
+
import sidenavHeadingStyles from './sidenav-heading.css.js';
|
|
17
|
+
/**
|
|
18
|
+
* @element sp-sidenav-heading
|
|
19
|
+
*
|
|
20
|
+
* @slot - the Sidenav Items to display in association with the heading
|
|
21
|
+
*/
|
|
22
|
+
export class SideNavHeading extends SpectrumElement {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.label = '';
|
|
26
|
+
}
|
|
27
|
+
static get styles() {
|
|
28
|
+
return [sidenavItemStyles, sidenavHeadingStyles];
|
|
29
|
+
}
|
|
30
|
+
update(changes) {
|
|
31
|
+
if (!this.hasAttribute('slot')) {
|
|
32
|
+
this.slot = 'descendant';
|
|
33
|
+
}
|
|
34
|
+
super.update(changes);
|
|
35
|
+
}
|
|
36
|
+
render() {
|
|
37
|
+
return html `
|
|
38
|
+
<h2 id="heading">${this.label}</h2>
|
|
39
|
+
<div id="list" aria-labelledby="heading">
|
|
40
|
+
<slot name="descendant"></slot>
|
|
41
|
+
</div>
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
__decorate([
|
|
46
|
+
property({ reflect: true })
|
|
47
|
+
], SideNavHeading.prototype, "label", void 0);
|
|
48
|
+
//# sourceMappingURL=SidenavHeading.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidenavHeading.js","sourceRoot":"","sources":["SidenavHeading.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EAEJ,eAAe,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAE3E,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AACtD,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAE5D;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAAnD;;QAEW,UAAK,GAAG,EAAE,CAAC;IAqBtB,CAAC;IAnBU,MAAM,KAAK,MAAM;QACpB,OAAO,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;IACrD,CAAC;IAES,MAAM,CAAC,OAAuB;QACpC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YAC5B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;SAC5B;QACD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAES,MAAM;QACZ,OAAO,IAAI,CAAA;+BACY,IAAI,CAAC,KAAK;;;;SAIhC,CAAC;IACN,CAAC;CACJ;AArBG;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACV","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\n\nimport sidenavItemStyles from './sidenav-item.css.js';\nimport sidenavHeadingStyles from './sidenav-heading.css.js';\n\n/**\n * @element sp-sidenav-heading\n *\n * @slot - the Sidenav Items to display in association with the heading\n */\nexport class SideNavHeading extends SpectrumElement {\n @property({ reflect: true })\n public label = '';\n\n public static get styles(): CSSResultArray {\n return [sidenavItemStyles, sidenavHeadingStyles];\n }\n\n protected update(changes: PropertyValues): void {\n if (!this.hasAttribute('slot')) {\n this.slot = 'descendant';\n }\n super.update(changes);\n }\n\n protected render(): TemplateResult {\n return html`\n <h2 id=\"heading\">${this.label}</h2>\n <div id=\"list\" aria-labelledby=\"heading\">\n <slot name=\"descendant\"></slot>\n </div>\n `;\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CSSResultArray, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
|
|
3
|
+
import { SideNav } from './Sidenav.js';
|
|
4
|
+
declare const SideNavItem_base: typeof Focusable & {
|
|
5
|
+
new (...args: any[]): import("@spectrum-web-components/shared/src/like-anchor.js").LikeAnchorInterface;
|
|
6
|
+
prototype: import("@spectrum-web-components/shared/src/like-anchor.js").LikeAnchorInterface;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @element sp-sidenav-item
|
|
10
|
+
*
|
|
11
|
+
* @slot - the Sidenav Items to display as children of this item
|
|
12
|
+
*/
|
|
13
|
+
export declare class SideNavItem extends SideNavItem_base {
|
|
14
|
+
static get styles(): CSSResultArray;
|
|
15
|
+
value: string | undefined;
|
|
16
|
+
selected: boolean;
|
|
17
|
+
expanded: boolean;
|
|
18
|
+
protected get parentSideNav(): SideNav | undefined;
|
|
19
|
+
protected _parentSidenav?: SideNav;
|
|
20
|
+
protected get hasChildren(): boolean;
|
|
21
|
+
protected get depth(): number;
|
|
22
|
+
handleSideNavSelect(event: Event): void;
|
|
23
|
+
protected handleClick(event?: Event): void;
|
|
24
|
+
private announceSelected;
|
|
25
|
+
click(): void;
|
|
26
|
+
get focusElement(): HTMLElement;
|
|
27
|
+
protected update(changes: PropertyValues): void;
|
|
28
|
+
protected render(): TemplateResult;
|
|
29
|
+
protected updated(changes: PropertyValues): void;
|
|
30
|
+
connectedCallback(): void;
|
|
31
|
+
disconnectedCallback(): void;
|
|
32
|
+
private startTrackingSelection;
|
|
33
|
+
private stopTrackingSelection;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { __decorate } from "tslib";
|
|
13
|
+
import { html, } from '@spectrum-web-components/base';
|
|
14
|
+
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
15
|
+
import { ifDefined } from '@spectrum-web-components/base/src/directives.js';
|
|
16
|
+
import { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';
|
|
17
|
+
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
|
|
18
|
+
import sidenavItemStyles from './sidenav-item.css.js';
|
|
19
|
+
/**
|
|
20
|
+
* @element sp-sidenav-item
|
|
21
|
+
*
|
|
22
|
+
* @slot - the Sidenav Items to display as children of this item
|
|
23
|
+
*/
|
|
24
|
+
export class SideNavItem extends LikeAnchor(Focusable) {
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.value = undefined;
|
|
28
|
+
this.selected = false;
|
|
29
|
+
this.expanded = false;
|
|
30
|
+
}
|
|
31
|
+
static get styles() {
|
|
32
|
+
return [sidenavItemStyles];
|
|
33
|
+
}
|
|
34
|
+
get parentSideNav() {
|
|
35
|
+
if (!this._parentSidenav) {
|
|
36
|
+
this._parentSidenav = this.closest('sp-sidenav');
|
|
37
|
+
}
|
|
38
|
+
return this._parentSidenav;
|
|
39
|
+
}
|
|
40
|
+
get hasChildren() {
|
|
41
|
+
return !!this.querySelector('sp-sidenav-item');
|
|
42
|
+
}
|
|
43
|
+
get depth() {
|
|
44
|
+
let depth = 0;
|
|
45
|
+
let element = this.parentElement;
|
|
46
|
+
while (element instanceof SideNavItem) {
|
|
47
|
+
depth++;
|
|
48
|
+
element = element.parentElement;
|
|
49
|
+
}
|
|
50
|
+
return depth;
|
|
51
|
+
}
|
|
52
|
+
handleSideNavSelect(event) {
|
|
53
|
+
this.selected = event.target === this;
|
|
54
|
+
}
|
|
55
|
+
handleClick(event) {
|
|
56
|
+
if (!this.href && event) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
}
|
|
59
|
+
if (!this.disabled) {
|
|
60
|
+
if (this.hasChildren) {
|
|
61
|
+
this.expanded = !this.expanded;
|
|
62
|
+
}
|
|
63
|
+
else if (this.value) {
|
|
64
|
+
this.announceSelected(this.value);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
announceSelected(value) {
|
|
69
|
+
const selectDetail = {
|
|
70
|
+
value,
|
|
71
|
+
};
|
|
72
|
+
const selectionEvent = new CustomEvent('sidenav-select', {
|
|
73
|
+
bubbles: true,
|
|
74
|
+
composed: true,
|
|
75
|
+
detail: selectDetail,
|
|
76
|
+
});
|
|
77
|
+
this.dispatchEvent(selectionEvent);
|
|
78
|
+
}
|
|
79
|
+
click() {
|
|
80
|
+
this.handleClick();
|
|
81
|
+
}
|
|
82
|
+
get focusElement() {
|
|
83
|
+
return this.shadowRoot.querySelector('#item-link');
|
|
84
|
+
}
|
|
85
|
+
update(changes) {
|
|
86
|
+
if (!this.hasAttribute('slot')) {
|
|
87
|
+
this.slot = 'descendant';
|
|
88
|
+
}
|
|
89
|
+
super.update(changes);
|
|
90
|
+
}
|
|
91
|
+
render() {
|
|
92
|
+
return html `
|
|
93
|
+
<a
|
|
94
|
+
href=${this.href || '#'}
|
|
95
|
+
target=${ifDefined(this.target)}
|
|
96
|
+
download=${ifDefined(this.download)}
|
|
97
|
+
rel=${ifDefined(this.rel)}
|
|
98
|
+
data-level="${this.depth}"
|
|
99
|
+
@click="${this.handleClick}"
|
|
100
|
+
id="item-link"
|
|
101
|
+
aria-current=${ifDefined(this.selected && this.href ? 'page' : undefined)}
|
|
102
|
+
>
|
|
103
|
+
<slot name="icon"></slot>
|
|
104
|
+
${this.label}
|
|
105
|
+
<slot></slot>
|
|
106
|
+
</a>
|
|
107
|
+
${this.expanded
|
|
108
|
+
? html `
|
|
109
|
+
<slot name="descendant"></slot>
|
|
110
|
+
`
|
|
111
|
+
: html ``}
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
114
|
+
updated(changes) {
|
|
115
|
+
if (this.hasChildren && this.expanded && !this.selected) {
|
|
116
|
+
this.focusElement.tabIndex = -1;
|
|
117
|
+
}
|
|
118
|
+
super.updated(changes);
|
|
119
|
+
}
|
|
120
|
+
connectedCallback() {
|
|
121
|
+
super.connectedCallback();
|
|
122
|
+
this.startTrackingSelection();
|
|
123
|
+
}
|
|
124
|
+
disconnectedCallback() {
|
|
125
|
+
this.stopTrackingSelection();
|
|
126
|
+
super.disconnectedCallback();
|
|
127
|
+
}
|
|
128
|
+
async startTrackingSelection() {
|
|
129
|
+
const parentSideNav = this.parentSideNav;
|
|
130
|
+
if (parentSideNav) {
|
|
131
|
+
await parentSideNav.updateComplete;
|
|
132
|
+
parentSideNav.startTrackingSelectionForItem(this);
|
|
133
|
+
this.selected =
|
|
134
|
+
this.value != null && this.value === parentSideNav.value;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
stopTrackingSelection() {
|
|
138
|
+
const parentSideNav = this.parentSideNav;
|
|
139
|
+
if (parentSideNav) {
|
|
140
|
+
parentSideNav.stopTrackingSelectionForItem(this);
|
|
141
|
+
}
|
|
142
|
+
this._parentSidenav = undefined;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
__decorate([
|
|
146
|
+
property()
|
|
147
|
+
], SideNavItem.prototype, "value", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
property({ type: Boolean, reflect: true })
|
|
150
|
+
], SideNavItem.prototype, "selected", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
property({ type: Boolean, reflect: true })
|
|
153
|
+
], SideNavItem.prototype, "expanded", void 0);
|
|
154
|
+
//# sourceMappingURL=SidenavItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidenavItem.js","sourceRoot":"","sources":["SidenavItem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,GAGP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,kDAAkD,CAAC;AAI7E,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,UAAU,CAAC,SAAS,CAAC;IAAtD;;QAMW,UAAK,GAAuB,SAAS,CAAC;QAGtC,aAAQ,GAAG,KAAK,CAAC;QAGjB,aAAQ,GAAG,KAAK,CAAC;IAqI5B,CAAC;IAhJU,MAAM,KAAK,MAAM;QACpB,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC/B,CAAC;IAWD,IAAc,aAAa;QACvB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACtB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAEhC,CAAC;SACnB;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAID,IAAc,WAAW;QACrB,OAAO,CAAC,CAAC,IAAI,CAAC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;QACzC,IAAI,aAAa,EAAE;YACf,MAAM,aAAa,CAAC,cAAc,CAAC;YACnC,aAAa,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;YAClD,IAAI,CAAC,QAAQ;gBACT,IAAI,CAAC,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,aAAa,CAAC,KAAK,CAAC;SAChE;IACL,CAAC;IAEO,qBAAqB;QACzB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACzC,IAAI,aAAa,EAAE;YACf,aAAa,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAC;SACpD;QACD,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;IACpC,CAAC;CACJ;AA3IG;IADC,QAAQ,EAAE;0CACkC;AAG7C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACnB;AAGxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;6CACnB","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\n\nimport { SideNav, SidenavSelectDetail } from './Sidenav.js';\n\nimport sidenavItemStyles from './sidenav-item.css.js';\n\n/**\n * @element sp-sidenav-item\n *\n * @slot - the Sidenav Items to display as children of this item\n */\nexport class SideNavItem extends LikeAnchor(Focusable) {\n public static get styles(): CSSResultArray {\n return [sidenavItemStyles];\n }\n\n @property()\n public value: string | undefined = undefined;\n\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n @property({ type: Boolean, reflect: true })\n public expanded = false;\n\n protected get parentSideNav(): SideNav | undefined {\n if (!this._parentSidenav) {\n this._parentSidenav = this.closest('sp-sidenav') as\n | SideNav\n | undefined;\n }\n return this._parentSidenav;\n }\n\n protected _parentSidenav?: SideNav;\n\n protected get hasChildren(): boolean {\n return !!this.querySelector('sp-sidenav-item');\n }\n\n protected get depth(): number {\n let depth = 0;\n let element = this.parentElement;\n while (element instanceof SideNavItem) {\n depth++;\n element = element.parentElement;\n }\n return depth;\n }\n\n public handleSideNavSelect(event: Event): void {\n this.selected = event.target === this;\n }\n\n protected handleClick(event?: Event): void {\n if (!this.href && event) {\n event.preventDefault();\n }\n if (!this.disabled) {\n if (this.hasChildren) {\n this.expanded = !this.expanded;\n } else if (this.value) {\n this.announceSelected(this.value);\n }\n }\n }\n\n private announceSelected(value: string): void {\n const selectDetail: SidenavSelectDetail = {\n value,\n };\n\n const selectionEvent = new CustomEvent('sidenav-select', {\n bubbles: true,\n composed: true,\n detail: selectDetail,\n });\n\n this.dispatchEvent(selectionEvent);\n }\n\n public click(): void {\n this.handleClick();\n }\n\n public get focusElement(): HTMLElement {\n return this.shadowRoot.querySelector('#item-link') as HTMLElement;\n }\n\n protected update(changes: PropertyValues): void {\n if (!this.hasAttribute('slot')) {\n this.slot = 'descendant';\n }\n super.update(changes);\n }\n\n protected render(): TemplateResult {\n return html`\n <a\n href=${this.href || '#'}\n target=${ifDefined(this.target)}\n download=${ifDefined(this.download)}\n rel=${ifDefined(this.rel)}\n data-level=\"${this.depth}\"\n @click=\"${this.handleClick}\"\n id=\"item-link\"\n aria-current=${ifDefined(\n this.selected && this.href ? 'page' : undefined\n )}\n >\n <slot name=\"icon\"></slot>\n ${this.label}\n <slot></slot>\n </a>\n ${this.expanded\n ? html`\n <slot name=\"descendant\"></slot>\n `\n : html``}\n `;\n }\n\n protected updated(changes: PropertyValues): void {\n if (this.hasChildren && this.expanded && !this.selected) {\n this.focusElement.tabIndex = -1;\n }\n super.updated(changes);\n }\n\n public connectedCallback(): void {\n super.connectedCallback();\n this.startTrackingSelection();\n }\n\n public disconnectedCallback(): void {\n this.stopTrackingSelection();\n super.disconnectedCallback();\n }\n\n private async startTrackingSelection(): Promise<void> {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n await parentSideNav.updateComplete;\n parentSideNav.startTrackingSelectionForItem(this);\n this.selected =\n this.value != null && this.value === parentSideNav.value;\n }\n }\n\n private stopTrackingSelection(): void {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n parentSideNav.stopTrackingSelectionForItem(this);\n }\n this._parentSidenav = undefined;\n }\n}\n"]}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export * from './Sidenav.js';
|
|
13
|
+
export * from './SidenavItem.js';
|
|
14
|
+
export * from './SidenavHeading.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nexport * from './Sidenav.js';\nexport * from './SidenavItem.js';\nexport * from './SidenavHeading.js';\n"]}
|