@blockquote-web-components/blockquote-tabs 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 blockquote-tabs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # blockquote-tab
2
+
3
+ **Mixins:** BlockquoteMixinSlotContent
4
+
5
+ ## Properties
6
+
7
+ | Property | Attribute | Type | Default | Description |
8
+ |------------------------|------------|-----------|------------------------------------------|-------------------|
9
+ | `globalRootAttributes` | | `object` | {"role":"tab","slot":"tab","tabindex":0} | |
10
+ | `selected` | `selected` | `boolean` | false | The tab selected. |
11
+
12
+ ## Events
13
+
14
+ | Event | Type |
15
+ |---------------|--------------------------------------------------|
16
+ | `slotchanges` | `CustomEvent<{ assignedSlotContent: { slotName: any; assignedSlot: any; }; assignedNodesContent: { assignedNodesByNode: any[]; assignedNodes: any[]; }; flattenedNodesContent: { assignedNodesByNode: any[]; assignedNodes: any[]; }; originalEvent: { ...; }; }>` |
17
+
18
+
19
+ # blockquote-tabpanel
20
+
21
+ ## Properties
22
+
23
+ | Property | Attribute | Type | Default | Description |
24
+ |------------------------|------------|-----------|--------------------------------------------------|-------------|
25
+ | `globalRootAttributes` | | `object` | {"role":"tabpanel","slot":"tabpanel","tabindex":0} | |
26
+ | `selected` | `selected` | `boolean` | false | The - |
27
+
28
+
29
+ # blockquote-tabs
30
+
31
+ ![Lit](https://img.shields.io/badge/lit-2.0.0-blue)
32
+
33
+ [ARIA patterns](https://www.w3.org/WAI/ARIA/apg/patterns/)
34
+
35
+ Tabs are a set of layered sections of content, known as tab panels, that display one panel of content at a time. Each tab panel has an associated tab element, that when activated, displays the panel. The list of tab elements is arranged along one edge of the currently displayed panel, most commonly the top edge.
36
+
37
+ ## Usage
38
+
39
+ ```html
40
+ <blockquote-tabs label="List of tabs">
41
+ <blockquote-tab id="tab-1">Tab 1</blockquote-tab>
42
+ <blockquote-tab id="tab-2">Tab 2</blockquote-tab>
43
+ <blockquote-tab id="tab-3">Tab 3</blockquote-tab>
44
+ <blockquote-tab id="tab-4">Tab 4</blockquote-tab>
45
+ <blockquote-tab id="tab-5">Tab 5</blockquote-tab>
46
+ <blockquote-tab id="tab-6">Tab 6</blockquote-tab>
47
+ <blockquote-tab id="tab-7">Tab 7</blockquote-tab>
48
+ <blockquote-tab id="tab-8">Tab 8</blockquote-tab>
49
+ <blockquote-tab id="tab-9">Tab 9</blockquote-tab>
50
+ <blockquote-tab id="tab-10">Tab 10</blockquote-tab>
51
+ <blockquote-tabpanel aria-labelledby="tab-1"><p>Panel 1</p></blockquote-tabpanel>
52
+ <blockquote-tabpanel aria-labelledby="tab-2"><p>Panel 2</p></blockquote-tabpanel>
53
+ <blockquote-tabpanel aria-labelledby="tab-3"><p>Panel 3</p></blockquote-tabpanel>
54
+ <blockquote-tabpanel aria-labelledby="tab-4"><p>Panel 4</p></blockquote-tabpanel>
55
+ <blockquote-tabpanel aria-labelledby="tab-5"><p>Panel 5</p></blockquote-tabpanel>
56
+ <blockquote-tabpanel aria-labelledby="tab-6"><p>Panel 6</p></blockquote-tabpanel>
57
+ <blockquote-tabpanel aria-labelledby="tab-7"><p>Panel 7</p></blockquote-tabpanel>
58
+ <blockquote-tabpanel aria-labelledby="tab-8"><p>Panel 8</p></blockquote-tabpanel>
59
+ <blockquote-tabpanel aria-labelledby="tab-9"><p>Panel 9</p></blockquote-tabpanel>
60
+ <blockquote-tabpanel aria-labelledby="tab-10"><p>Panel 10</p></blockquote-tabpanel>
61
+ </blockquote-tabs>
62
+ ```
63
+
64
+ ## Exports
65
+
66
+ - BlockquoteTabs
67
+
68
+ **Mixins:** BlockquoteMixinSlotContent
69
+
70
+ ## Properties
71
+
72
+ | Property | Attribute | Type | Default | Description |
73
+ |-------------|-------------|-----------|---------|----------------------------------------------|
74
+ | `autofocus` | `autofocus` | `Boolean` | false | If present, the tab automatically have focus |
75
+ | `label` | `label` | `String` | "" | `aria-label` for tabs group |
76
+ | `selected` | `selected` | `Number` | 1 | The tab selected. |
77
+
78
+ ## Events
79
+
80
+ | Event | Type |
81
+ |------------------|--------------------------------------------------|
82
+ | `selectedchange` | `CustomEvent<{ selected: number; tab: any; tabpanel: any; }>` |
83
+ | `slotchanges` | `CustomEvent<{ assignedSlotContent: { slotName: any; assignedSlot: any; }; assignedNodesContent: { assignedNodesByNode: any[]; assignedNodes: any[]; }; flattenedNodesContent: { assignedNodesByNode: any[]; assignedNodes: any[]; }; originalEvent: { ...; }; }>` |
84
+
85
+
86
+ # blockquote-tabs
87
+
88
+ ![Lit](https://img.shields.io/badge/lit-2.0.0-blue)
89
+
90
+ [ARIA patterns](https://www.w3.org/WAI/ARIA/apg/patterns/)
91
+
92
+ Tabs are a set of layered sections of content, known as tab panels, that display one panel of content at a time. Each tab panel has an associated tab element, that when activated, displays the panel. The list of tab elements is arranged along one edge of the currently displayed panel, most commonly the top edge.
93
+
94
+ ## Usage
95
+
96
+ ```html
97
+ <blockquote-tabs label="List of tabs">
98
+ <blockquote-tab id="tab-1">Tab 1</blockquote-tab>
99
+ <blockquote-tab id="tab-2">Tab 2</blockquote-tab>
100
+ <blockquote-tab id="tab-3">Tab 3</blockquote-tab>
101
+ <blockquote-tab id="tab-4">Tab 4</blockquote-tab>
102
+ <blockquote-tab id="tab-5">Tab 5</blockquote-tab>
103
+ <blockquote-tab id="tab-6">Tab 6</blockquote-tab>
104
+ <blockquote-tab id="tab-7">Tab 7</blockquote-tab>
105
+ <blockquote-tab id="tab-8">Tab 8</blockquote-tab>
106
+ <blockquote-tab id="tab-9">Tab 9</blockquote-tab>
107
+ <blockquote-tab id="tab-10">Tab 10</blockquote-tab>
108
+ <blockquote-tabpanel aria-labelledby="tab-1"><p>Panel 1</p></blockquote-tabpanel>
109
+ <blockquote-tabpanel aria-labelledby="tab-2"><p>Panel 2</p></blockquote-tabpanel>
110
+ <blockquote-tabpanel aria-labelledby="tab-3"><p>Panel 3</p></blockquote-tabpanel>
111
+ <blockquote-tabpanel aria-labelledby="tab-4"><p>Panel 4</p></blockquote-tabpanel>
112
+ <blockquote-tabpanel aria-labelledby="tab-5"><p>Panel 5</p></blockquote-tabpanel>
113
+ <blockquote-tabpanel aria-labelledby="tab-6"><p>Panel 6</p></blockquote-tabpanel>
114
+ <blockquote-tabpanel aria-labelledby="tab-7"><p>Panel 7</p></blockquote-tabpanel>
115
+ <blockquote-tabpanel aria-labelledby="tab-8"><p>Panel 8</p></blockquote-tabpanel>
116
+ <blockquote-tabpanel aria-labelledby="tab-9"><p>Panel 9</p></blockquote-tabpanel>
117
+ <blockquote-tabpanel aria-labelledby="tab-10"><p>Panel 10</p></blockquote-tabpanel>
118
+ </blockquote-tabs>
119
+ ```
120
+
121
+ ## Exports
122
+
123
+ - BlockquoteTabs
124
+
125
+ **Mixins:** BlockquoteMixinSlotContent
126
+
127
+ ## Properties
128
+
129
+ | Property | Attribute | Type | Default | Description |
130
+ |-------------|-------------|-----------|---------|----------------------------------------------|
131
+ | `autofocus` | `autofocus` | `Boolean` | false | If present, the tab automatically have focus |
132
+ | `label` | `label` | `String` | "" | `aria-label` for tabs group |
133
+ | `selected` | `selected` | `Number` | 1 | The tab selected. |
134
+
135
+ ## Events
136
+
137
+ | Event | Type |
138
+ |------------------|--------------------------------------------------|
139
+ | `selectedchange` | `CustomEvent<{ selected: number; tab: any; tabpanel: any; }>` |
140
+ | `slotchanges` | `CustomEvent<{ assignedSlotContent: { slotName: any; assignedSlot: any; }; assignedNodesContent: { assignedNodesByNode: any[]; assignedNodes: any[]; }; flattenedNodesContent: { assignedNodesByNode: any[]; assignedNodes: any[]; }; originalEvent: { ...; }; }>` |
@@ -0,0 +1,3 @@
1
+ import { BlockquoteTab } from '../src/tab/BlockquoteTab.js';
2
+
3
+ window.customElements.define(BlockquoteTab.is, BlockquoteTab);
@@ -0,0 +1,3 @@
1
+ import { BlockquoteTabPanel } from '../src/tabpanel/BlockquoteTabPanel.js';
2
+
3
+ window.customElements.define(BlockquoteTabPanel.is, BlockquoteTabPanel);
@@ -0,0 +1,5 @@
1
+ import { BlockquoteTabs } from '../src/BlockquoteTabs.js';
2
+ import './blockquote-tab.js';
3
+ import './blockquote-tabpanel.js';
4
+
5
+ window.customElements.define(BlockquoteTabs.is, BlockquoteTabs);
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { BlockquoteTabs } from './src/BlockquoteTabs.js';
2
+ export { BlockquoteTab } from './src/tab/BlockquoteTab.js';
3
+ export { BlockquoteTabPanel } from './src/tabpanel/BlockquoteTabPanel.js';
package/package.json ADDED
@@ -0,0 +1,173 @@
1
+ {
2
+ "name": "@blockquote-web-components/blockquote-tabs",
3
+ "version": "1.0.0",
4
+ "description": "Webcomponent blockquote-tabs following open-wc recommendations",
5
+ "keywords": [
6
+ "lit",
7
+ "web-component",
8
+ "lit-element"
9
+ ],
10
+ "license": "MIT",
11
+ "author": "blockquote-tabs",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "default": "./index.js"
16
+ },
17
+ "./package.json": "./package.json",
18
+ "./src/BlockquoteTabs.js": {
19
+ "default": "./src/BlockquoteTabs.js"
20
+ },
21
+ "./src/tab/BlockquoteTab.js": {
22
+ "default": "./src/tab/BlockquoteTab.js"
23
+ },
24
+ "./src/tabpanel/BlockquoteTabPanel.js": {
25
+ "default": "./src/tabpanel/BlockquoteTabPanel.js"
26
+ },
27
+ "./src/styles/blockquote-tabs-styles.css.js": {
28
+ "default": "./src/styles/blockquote-tabs-styles.css.js"
29
+ },
30
+ "./src/tab/styles/blockquote-tab-styles.css.js": {
31
+ "default": "./src/styles/blockquote-tab-styles.css.js"
32
+ },
33
+ "./src/tabpanel/styles/blockquote-tabpanel-styles.css.js": {
34
+ "default": "./src/styles/blockquote-tabpanel-styles.css.js"
35
+ },
36
+ "./define/blockquote-tabs.js": {
37
+ "default": "./define/blockquote-tabs.js"
38
+ },
39
+ "./define/blockquote-tab.js": {
40
+ "default": "./define/blockquote-tab.js"
41
+ },
42
+ "./define/blockquote-tabpanel.js": {
43
+ "default": "./define/blockquote-tabpanel.js"
44
+ },
45
+ "./index.js": {
46
+ "default": "./index.js"
47
+ }
48
+ },
49
+ "main": "index.js",
50
+ "module": "index.js",
51
+ "files": [
52
+ "/define/",
53
+ "/src/",
54
+ "index.js",
55
+ "!/**/*.scss"
56
+ ],
57
+ "scripts": {
58
+ "analyze": "cem analyze --litelement --globs \"{src,define}/**/*.{js,ts}\" \"index.js\"",
59
+ "analyze:doc": "npm run analyze && npx web-component-analyzer \"{src,define}/**/*.{js,ts}\" \"index.js\" \"README.js\" --outFile README.md",
60
+ "build": "echo \"This is not a TypeScript project, so no need to build.\"",
61
+ "dev:vite": "vite build",
62
+ "format": "npm run format:eslint && npm run format:prettier && npm run format:stylelint",
63
+ "format:eslint": "eslint \"**/*.{js,ts,html}\" --fix --ignore-path .eslintignore",
64
+ "format:prettier": "prettier \"**/*.{js,ts,json,html}\" --write --ignore-path .eslintignore",
65
+ "format:stylelint": "stylelint \"**/*.{scss,css}\" --fix --allow-empty-input --ignore-path .eslintignore",
66
+ "postinstall": "npm run sort:package",
67
+ "lint": "npm run lint:eslint && npm run lint:prettier && npm run lint:stylelint",
68
+ "lint:eslint": "eslint \"**/*.{js,ts,html}\" --ignore-path .eslintignore",
69
+ "lint:prettier": "prettier \"**/*.{js,ts,json,html}\" --check --ignore-path .eslintignore",
70
+ "lint:stylelint": "stylelint \"**/*.{scss,css}\" --allow-empty-input --ignore-path .eslintignore",
71
+ "preview:vite": "vite preview",
72
+ "sass:watch": "sass-style-template",
73
+ "sort:package": "npx sort-package-json",
74
+ "start": "concurrently -k -r \"npm:sass:watch\" \"npm:vite\"",
75
+ "test": "wtr --coverage",
76
+ "test:watch": "wtr --watch",
77
+ "vite": "vite"
78
+ },
79
+ "lint-staged": {
80
+ "**/*.{js,ts,html}": [
81
+ "npm run format:eslint"
82
+ ],
83
+ "**/*.{js,ts,json,html}": [
84
+ "npm run format:prettier"
85
+ ],
86
+ "**/*.{scss,css}": [
87
+ "npm run format:stylelint"
88
+ ]
89
+ },
90
+ "prettier": {
91
+ "arrowParens": "avoid",
92
+ "printWidth": 100,
93
+ "singleQuote": true,
94
+ "trailingComma": "all",
95
+ "overrides": [
96
+ {
97
+ "files": "*.{scss,css}",
98
+ "options": {
99
+ "printWidth": 280,
100
+ "singleQuote": false
101
+ }
102
+ }
103
+ ]
104
+ },
105
+ "eslintConfig": {
106
+ "parserOptions": {
107
+ "ecmaVersion": "latest"
108
+ },
109
+ "plugins": [
110
+ "log-filenames"
111
+ ],
112
+ "extends": [
113
+ "@open-wc",
114
+ "prettier"
115
+ ],
116
+ "rules": {
117
+ "class-methods-use-this": "off",
118
+ "no-unused-expressions": [
119
+ "error",
120
+ {
121
+ "allowShortCircuit": true,
122
+ "allowTernary": true
123
+ }
124
+ ],
125
+ "object-curly-newline": "off",
126
+ "import/extensions": [
127
+ "error",
128
+ "always",
129
+ {
130
+ "ignorePackages": true
131
+ }
132
+ ],
133
+ "import/no-extraneous-dependencies": [
134
+ "error",
135
+ {
136
+ "devDependencies": [
137
+ "**/test/**/*.{js,ts}",
138
+ "**/*.config.{js,ts,mjs,cjs}",
139
+ "**/*.conf.{js,ts,mjs,cjs}"
140
+ ]
141
+ }
142
+ ],
143
+ "import/no-unresolved": "off",
144
+ "import/prefer-default-export": "off"
145
+ }
146
+ },
147
+ "stylelint": {
148
+ "extends": "stylelint-config-standard-scss",
149
+ "rules": {
150
+ "custom-property-pattern": null,
151
+ "max-line-length": null,
152
+ "no-duplicate-selectors": null,
153
+ "color-function-notation": null,
154
+ "alpha-value-notation": null
155
+ }
156
+ },
157
+ "dependencies": {
158
+ "@blockquote-web-components/blockquote-mixin-slot-content": "^1.2.9",
159
+ "@juggle/resize-observer": "^3.4.0",
160
+ "@lit-labs/observers": "^1.1.0",
161
+ "lit": "^2.3.1"
162
+ },
163
+ "devDependencies": {
164
+ "@blockquote-web-components/blockquote-base-common-dev-dependencies": "^1.3.7",
165
+ "@blockquote-web-components/blockquote-base-embedded-webview": "^1.4.0",
166
+ "@blockquote-web-components/blockquote-foundations-sass": "^1.0.0"
167
+ },
168
+ "publishConfig": {
169
+ "access": "public"
170
+ },
171
+ "customElements": "custom-elements.json",
172
+ "gitHead": "0c5ec040de2e96a0464da78debdc5329d99ba700"
173
+ }
@@ -0,0 +1,387 @@
1
+ import { html, LitElement, nothing } from 'lit';
2
+ import { ref, createRef } from 'lit/directives/ref.js';
3
+ import { ResizeObserver as ResizeObserverPolyfill } from '@juggle/resize-observer';
4
+ import { ResizeController } from '@lit-labs/observers/resize_controller.js';
5
+ import { BlockquoteMixinSlotContent } from '@blockquote-web-components/blockquote-mixin-slot-content';
6
+ import { styles } from './styles/blockquote-tabs-styles.css.js';
7
+
8
+ /* A minimal library which polyfills the ResizeObserver */
9
+ window.ResizeObserver || /* c8 ignore next */ (window.ResizeObserver = ResizeObserverPolyfill);
10
+
11
+ // https://gist.github.com/ebidel/2d2bb0cdec3f2a16cf519dbaa791ce1b
12
+ // https://darn.es/building-tabs-in-web-components/
13
+ // https://slides.com/daviddarnes/tabs-web-components
14
+ /**
15
+ ![Lit](https://img.shields.io/badge/lit-2.0.0-blue)
16
+
17
+ [ARIA patterns](https://www.w3.org/WAI/ARIA/apg/patterns/)
18
+
19
+ Tabs are a set of layered sections of content, known as tab panels, that display one panel of content at a time. Each tab panel has an associated tab element, that when activated, displays the panel. The list of tab elements is arranged along one edge of the currently displayed panel, most commonly the top edge.
20
+
21
+ ## Usage
22
+
23
+ ```html
24
+ <blockquote-tabs label="List of tabs">
25
+ <blockquote-tab id="tab-1">Tab 1</blockquote-tab>
26
+ <blockquote-tab id="tab-2">Tab 2</blockquote-tab>
27
+ <blockquote-tab id="tab-3">Tab 3</blockquote-tab>
28
+ <blockquote-tab id="tab-4">Tab 4</blockquote-tab>
29
+ <blockquote-tab id="tab-5">Tab 5</blockquote-tab>
30
+ <blockquote-tab id="tab-6">Tab 6</blockquote-tab>
31
+ <blockquote-tab id="tab-7">Tab 7</blockquote-tab>
32
+ <blockquote-tab id="tab-8">Tab 8</blockquote-tab>
33
+ <blockquote-tab id="tab-9">Tab 9</blockquote-tab>
34
+ <blockquote-tab id="tab-10">Tab 10</blockquote-tab>
35
+ <blockquote-tabpanel aria-labelledby="tab-1"><p>Panel 1</p></blockquote-tabpanel>
36
+ <blockquote-tabpanel aria-labelledby="tab-2"><p>Panel 2</p></blockquote-tabpanel>
37
+ <blockquote-tabpanel aria-labelledby="tab-3"><p>Panel 3</p></blockquote-tabpanel>
38
+ <blockquote-tabpanel aria-labelledby="tab-4"><p>Panel 4</p></blockquote-tabpanel>
39
+ <blockquote-tabpanel aria-labelledby="tab-5"><p>Panel 5</p></blockquote-tabpanel>
40
+ <blockquote-tabpanel aria-labelledby="tab-6"><p>Panel 6</p></blockquote-tabpanel>
41
+ <blockquote-tabpanel aria-labelledby="tab-7"><p>Panel 7</p></blockquote-tabpanel>
42
+ <blockquote-tabpanel aria-labelledby="tab-8"><p>Panel 8</p></blockquote-tabpanel>
43
+ <blockquote-tabpanel aria-labelledby="tab-9"><p>Panel 9</p></blockquote-tabpanel>
44
+ <blockquote-tabpanel aria-labelledby="tab-10"><p>Panel 10</p></blockquote-tabpanel>
45
+ </blockquote-tabs>
46
+ ```
47
+
48
+ ## Exports
49
+
50
+ - BlockquoteTabs
51
+
52
+ @tagname blockquote-tabs
53
+ @element blockquote-tabs
54
+ */
55
+ export class BlockquoteTabs extends BlockquoteMixinSlotContent(LitElement) {
56
+ static get is() {
57
+ return 'blockquote-tabs';
58
+ }
59
+
60
+ static get styles() {
61
+ return [styles];
62
+ }
63
+
64
+ static get properties() {
65
+ return {
66
+ /**
67
+ * If present, the tab automatically have focus
68
+ * @type {Boolean}
69
+ */
70
+ // eslint-disable-next-line lit/no-native-attributes
71
+ autofocus: {
72
+ type: Boolean,
73
+ },
74
+
75
+ /**
76
+ * `aria-label` for tabs group
77
+ * @type {String}
78
+ */
79
+ label: {
80
+ type: String,
81
+ },
82
+
83
+ /**
84
+ * The tab selected.
85
+ * @type {Number}
86
+ */
87
+ selected: {
88
+ type: Number,
89
+ reflect: true,
90
+ },
91
+
92
+ _hasScrollLeftIndicator: {
93
+ type: Boolean,
94
+ state: true,
95
+ },
96
+
97
+ _hasScrollRightIndicator: {
98
+ type: Boolean,
99
+ state: true,
100
+ },
101
+ };
102
+ }
103
+
104
+ constructor() {
105
+ super();
106
+
107
+ /* initial state */
108
+ this.autofocus = false;
109
+ this.label = '';
110
+ this.selected = 1;
111
+
112
+ this._tabList = [];
113
+ this._tabpanelList = [];
114
+ this._selectTabLast = undefined;
115
+ this._selectTabpanelLast = undefined;
116
+ this._observedFocus = false;
117
+ this._observeScrollBehavior = false;
118
+
119
+ this._slotChangesCount = 0;
120
+ this._slotNodesCount = undefined;
121
+
122
+ this._scrollContentRef = createRef();
123
+ this._onTabClick = this._onTabClick.bind(this);
124
+ this._onTabKeyDown = this._onTabKeyDown.bind(this);
125
+
126
+ this._resizeControllerObserver = new ResizeController(this, {
127
+ callback: () => {
128
+ this._onResizeObserverChange();
129
+ },
130
+ skipInitial: true,
131
+ });
132
+ }
133
+
134
+ _selectedIsInRange(idx) {
135
+ return idx >= 0 && idx <= this._getTabListLength ? idx : 0;
136
+ }
137
+
138
+ get _selectedTab() {
139
+ return this._tabList[this._selectedIsInRange(this.selected - 1)];
140
+ }
141
+
142
+ get _selectedTabIndex() {
143
+ return this._tabList.indexOf(this._selectedTab);
144
+ }
145
+
146
+ get _selectedTabIndexFromOne() {
147
+ return this._selectedTabIndex + 1;
148
+ }
149
+
150
+ get _getTabListLength() {
151
+ return this._tabList.length;
152
+ }
153
+
154
+ connectedCallback() {
155
+ super.connectedCallback && super.connectedCallback();
156
+ this.shadowRoot.addEventListener('slotchanges', this._onSlotChanges.bind(this));
157
+ }
158
+
159
+ firstUpdated(props) {
160
+ super.firstUpdated && super.firstUpdated(props);
161
+ const tabSlot = this.shadowRoot.querySelector('[name="tab"]');
162
+ const tabpanelSlot = this.shadowRoot.querySelector('[name="tabpanel"]');
163
+
164
+ this._slotNodesCount = this.shadowRoot.querySelectorAll('slot');
165
+ this._tabList = tabSlot.assignedElements();
166
+ this._tabpanelList = tabpanelSlot.assignedElements();
167
+ this._indicators = this.shadowRoot.querySelectorAll('.indicator');
168
+ }
169
+
170
+ updated(props) {
171
+ super.updated && super.updated(props);
172
+ if (props.has('selected')) {
173
+ this._selectTab();
174
+
175
+ /**
176
+ * Fired when selected changes
177
+ * @event selectedchange
178
+ */
179
+ const event = new CustomEvent('selectedchange', {
180
+ bubbles: true,
181
+ detail: {
182
+ selected: this._selectedTabIndexFromOne,
183
+ tab: this._selectedTab,
184
+ tabpanel: this._tabpanelList[this._selectedTabIndex],
185
+ },
186
+ });
187
+ this.dispatchEvent(event);
188
+ }
189
+ }
190
+
191
+ _onSlotChanges(ev) {
192
+ ev.stopPropagation();
193
+ ev.preventDefault();
194
+
195
+ this._slotChangesCount += 1;
196
+
197
+ const { detail } = ev;
198
+ const assignedNodesList = detail.assignedNodesContent.assignedNodes;
199
+
200
+ if (detail.assignedSlotContent.slotName === 'tab') {
201
+ this._tabList = assignedNodesList;
202
+ }
203
+ if (detail.assignedSlotContent.slotName === 'tabpanel') {
204
+ this._tabpanelList = assignedNodesList;
205
+ }
206
+
207
+ if (this._slotChangesCount > this._slotNodesCount.length) {
208
+ this._requestPropertyUpdate('selected');
209
+ }
210
+ }
211
+
212
+ get _scrollContentTpl() {
213
+ return html` <div
214
+ class="scroll-content"
215
+ ${ref(this._scrollContentRef)}
216
+ @scroll="${this._scrollEdge}"
217
+ >
218
+ ${this._tablistTpl}
219
+ </div>`;
220
+ }
221
+
222
+ get _tablistTpl() {
223
+ return html` <div role="tablist" aria-label="${this.label || nothing}">
224
+ <slot @click="${this._onTabClick}" @keydown="${this._onTabKeyDown}" name="tab"></slot>
225
+ </div>`;
226
+ }
227
+
228
+ get _separatorTpl() {
229
+ return html`<span aria-hidden="true" class="separator"></span>`;
230
+ }
231
+
232
+ get _indicatorsTpl() {
233
+ return html` <span
234
+ aria-hidden="true"
235
+ class="indicator ${this._hasScrollLeftIndicator ? 'show-indicator' : ''}"
236
+ ></span>
237
+ <span
238
+ aria-hidden="true"
239
+ class="indicator ${this._hasScrollRightIndicator ? 'show-indicator' : ''}"
240
+ ></span>`;
241
+ }
242
+
243
+ get _holdTpl() {
244
+ return html`<div class="hold">
245
+ ${this._scrollContentTpl} ${this._separatorTpl} ${this._indicatorsTpl}
246
+ </div>`;
247
+ }
248
+
249
+ get _tabpanelTpl() {
250
+ return html` <div>
251
+ <slot name="tabpanel"></slot>
252
+ </div>`;
253
+ }
254
+
255
+ render() {
256
+ return html` ${this._holdTpl} ${this._tabpanelTpl} `;
257
+ }
258
+
259
+ _scrollEdge({ target = this._scrollContentRef.value } = {}) {
260
+ const { scrollLeft, scrollWidth, offsetWidth } = target;
261
+ const overflowingWidth = scrollWidth - offsetWidth;
262
+ this._hasScrollLeftIndicator = scrollLeft > 0;
263
+ this._hasScrollRightIndicator = scrollLeft < overflowingWidth;
264
+ }
265
+
266
+ _onTabClick(ev) {
267
+ const findSelectedTab = ev
268
+ .composedPath()
269
+ .find(tab => tab instanceof Element && tab.slot === 'tab');
270
+
271
+ const findSelectedTabIdxFromOne = this._tabList.indexOf(findSelectedTab) + 1;
272
+
273
+ if (this.selected === findSelectedTabIdxFromOne) {
274
+ this._scrollIntoView();
275
+ }
276
+
277
+ this.selected = findSelectedTabIdxFromOne;
278
+ }
279
+
280
+ _onTabKeyDown(ev) {
281
+ let idx = '';
282
+
283
+ switch (ev.key) {
284
+ case 'ArrowLeft':
285
+ ev.preventDefault();
286
+ idx = this._selectedTabIndexFromOne - 1;
287
+ this.selected = idx <= 0 ? this._getTabListLength : idx;
288
+ break;
289
+ case 'ArrowRight':
290
+ ev.preventDefault();
291
+ idx = this._selectedTabIndexFromOne + 1;
292
+ this.selected = idx > this._getTabListLength ? 1 : idx;
293
+ break;
294
+ case 'Home':
295
+ ev.preventDefault();
296
+ this.selected = 1;
297
+ break;
298
+ case 'End':
299
+ ev.preventDefault();
300
+ this.selected = this._getTabListLength;
301
+ break;
302
+ default:
303
+ break;
304
+ }
305
+ }
306
+
307
+ _selectTab() {
308
+ const newSelectedTab = this._tabList[this._selectedTabIndex];
309
+ const newSelectedTabPanel = this._tabpanelList[this._selectedTabIndex];
310
+ if (this._selectTabLast) {
311
+ this._selectTabLast.selected = false;
312
+ this._selectTabPanelLast.selected = false;
313
+ }
314
+ this._selectTabLast = newSelectedTab;
315
+ this._selectTabPanelLast = newSelectedTabPanel;
316
+ newSelectedTab.selected = true;
317
+ newSelectedTabPanel.selected = true;
318
+
319
+ if (this.autofocus || this._observedFocus) {
320
+ this._requestFocusUpdate();
321
+ }
322
+ this._observedFocus = true;
323
+ }
324
+
325
+ _moveFocusSelectedTab(selectedTab = this._selectedTab) {
326
+ /* same focus behavior between browsers */
327
+ window.setTimeout(() => {
328
+ selectedTab.focus();
329
+ }, 0);
330
+ }
331
+
332
+ async _requestFocusUpdate() {
333
+ await this.updateComplete;
334
+ this._moveFocusSelectedTab();
335
+ this._scrollIntoView();
336
+ }
337
+
338
+ _scrollIntoView() {
339
+ window.requestAnimationFrame(() => {
340
+ this._scrollIntoViewWithOffset();
341
+ this._observeScrollBehavior = true;
342
+ });
343
+ }
344
+
345
+ _scrollIntoViewWithOffset(
346
+ tabScroller = this._selectedTab,
347
+ behavior = this._observeScrollBehavior ? 'smooth' : 'auto',
348
+ ) {
349
+ const [rootA, rootB] = this._indicators;
350
+ const scrollContentNode = this._scrollContentRef.value;
351
+ const { right: boundaryight } = scrollContentNode.getBoundingClientRect();
352
+ const { offsetLeft: scrollerLeft } = tabScroller;
353
+ const {
354
+ left: tabScrollerXLeft,
355
+ right: tabScrollerXRight,
356
+ width: tabScrollerWidth,
357
+ } = tabScroller.getBoundingClientRect();
358
+
359
+ const { right: rootARight } = rootA.getBoundingClientRect();
360
+ const { width: rootBWidth, left: rootBLeft } = rootB.getBoundingClientRect();
361
+
362
+ if (tabScrollerXRight > rootBLeft || tabScrollerXLeft < rootARight) {
363
+ const left =
364
+ tabScrollerXRight > rootBLeft
365
+ ? scrollerLeft - boundaryight + tabScrollerWidth + rootBWidth
366
+ : scrollerLeft - rootARight;
367
+
368
+ scrollContentNode.scroll({
369
+ left,
370
+ behavior,
371
+ });
372
+ }
373
+
374
+ // tabScroller.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' });
375
+ }
376
+
377
+ _requestPropertyUpdate(prop) {
378
+ const oldVal = this[prop];
379
+ this[prop] = undefined;
380
+ this[prop] = oldVal;
381
+ }
382
+
383
+ _onResizeObserverChange() {
384
+ this._scrollIntoView();
385
+ this._scrollEdge();
386
+ }
387
+ }
@@ -0,0 +1,81 @@
1
+ import { css } from 'lit';
2
+
3
+ export const styles = css`:host {
4
+ --_unselected-color: var(--blockquote-tabs-unselected-color, rgb(234 234 234));
5
+ --_scroll-gradient-start-color: var(--blockquote-tabs-scroll-gradient-start-color, rgba(255, 255, 255, 0));
6
+ --_scroll-gradient-end-color: var(--blockquote-tabs-scroll-gradient-end-color, rgba(252, 252, 252, 1));
7
+ --_scroll-arrow-color: var(--blockquote-tabs-scroll-arrow-color, rgb(94, 94, 94));
8
+ contain: content;
9
+ display: block;
10
+ box-sizing: border-box;
11
+ color: #202020;
12
+ }
13
+
14
+ :host([hidden]),
15
+ [hidden] {
16
+ display: none !important;
17
+ }
18
+
19
+ *,
20
+ *::before,
21
+ *::after {
22
+ box-sizing: inherit;
23
+ }
24
+
25
+ .hold {
26
+ position: relative;
27
+ display: flex;
28
+ }
29
+ .hold .separator {
30
+ position: absolute;
31
+ z-index: -1;
32
+ bottom: 0;
33
+ height: 1px;
34
+ left: 0;
35
+ right: 0;
36
+ background-color: var(--_unselected-color);
37
+ }
38
+ .hold .indicator {
39
+ position: absolute;
40
+ width: 1rem;
41
+ pointer-events: none;
42
+ top: 0;
43
+ bottom: 1px;
44
+ left: 0;
45
+ box-shadow: rgb(255, 255, 255) 4px 0 12px 4px inset, rgb(210, 210, 210) 4px 0 4px -4px;
46
+ background-color: rgba(234, 234, 234, 0.5);
47
+ transition: opacity 92ms ease-in-out;
48
+ opacity: 0;
49
+ background-clip: padding-box;
50
+ }
51
+ .hold .indicator.show-indicator {
52
+ opacity: 1;
53
+ }
54
+ .hold .indicator + .indicator {
55
+ left: auto;
56
+ right: 0;
57
+ transform: scale(-1);
58
+ }
59
+
60
+ .scroll-content {
61
+ width: 100%;
62
+ overflow-x: auto;
63
+ overflow-y: hidden;
64
+ -webkit-overflow-scrolling: touch;
65
+ scrollbar-width: none;
66
+ overscroll-behavior: none;
67
+ }
68
+ .scroll-content::-webkit-scrollbar {
69
+ display: none;
70
+ }
71
+ .scroll-content:focus-visible {
72
+ outline: #9e9e9e dashed 0.0625rem;
73
+ outline-offset: -2px;
74
+ }
75
+ .scroll-content:focus:not(:focus-visible) {
76
+ outline: none;
77
+ }
78
+
79
+ [role=tablist] {
80
+ display: flex;
81
+ }`;
@@ -0,0 +1,75 @@
1
+ import { html, LitElement } from 'lit';
2
+ import { BlockquoteMixinSlotContent } from '@blockquote-web-components/blockquote-mixin-slot-content';
3
+ import { styles } from './styles/blockquote-tab-styles.css.js';
4
+
5
+ export class BlockquoteTab extends BlockquoteMixinSlotContent(LitElement) {
6
+ static get is() {
7
+ return 'blockquote-tab';
8
+ }
9
+
10
+ static get properties() {
11
+ return {
12
+ /**
13
+ * The tab selected.
14
+ * @type {boolean}
15
+ */
16
+ selected: {
17
+ type: Boolean,
18
+ },
19
+ };
20
+ }
21
+
22
+ constructor() {
23
+ super();
24
+ this.selected = false;
25
+ this.globalRootAttributes = {
26
+ role: 'tab',
27
+ slot: 'tab',
28
+ tabindex: 0,
29
+ };
30
+ }
31
+
32
+ static get styles() {
33
+ return [styles];
34
+ }
35
+
36
+ connectedCallback() {
37
+ super.connectedCallback && super.connectedCallback();
38
+ this.shadowRoot.addEventListener('slotchanges', this._onSlotChanges.bind(this));
39
+
40
+ this.__setArrayAttibute(this.globalRootAttributes);
41
+ }
42
+
43
+ updated(props) {
44
+ super.updated && super.updated(props);
45
+ if (props.has('selected')) {
46
+ const globalRootAttributes = {
47
+ ...this.globalRootAttributes,
48
+ ...{
49
+ 'aria-selected': !!this.selected,
50
+ tabindex: this.selected ? 0 : -1,
51
+ },
52
+ };
53
+
54
+ this.__setArrayAttibute(globalRootAttributes);
55
+ }
56
+ }
57
+
58
+ _onSlotChanges(ev) {
59
+ const { detail } = ev;
60
+ ev.stopPropagation();
61
+ ev.preventDefault();
62
+ const assignedNodesList = detail.assignedSlotContent.assignedSlot;
63
+ Object.assign(assignedNodesList.dataset, { text: this.textContent });
64
+ }
65
+
66
+ render() {
67
+ return html`<slot></slot>`;
68
+ }
69
+
70
+ __setArrayAttibute(entries = []) {
71
+ Object.entries(entries).forEach(([key, value]) => {
72
+ this.setAttribute(key, value);
73
+ });
74
+ }
75
+ }
@@ -0,0 +1,54 @@
1
+ import { css } from 'lit';
2
+
3
+ export const styles = css`:host {
4
+ --__color: var(--blockquote-tab-color-dark-mode, var(--blockquote-tab-color-ambient, var(--theme-colors-secondary500, rgb(32, 32, 32))));
5
+ --_color: var(--blockquote-tab-color, var(--__color));
6
+ --_selected-border-color: var(--blockquote-tab-selected-border-color, var(--blockquote-tab-selected-border-color-ambient, var(--theme-colors-secondary500, rgb(184, 184, 184))));
7
+ --_focus-outline-color: var(--blockquote-tab-focus-outline-color, var(--blockquote-tab-focus-outline-color-ambient, var(--theme-colors-secondary500, rgb(184, 184, 184))));
8
+ display: flex;
9
+ flex-direction: column;
10
+ justify-content: center;
11
+ white-space: nowrap;
12
+ color: var(--_color);
13
+ padding: 1em 0.5em;
14
+ min-width: 6.25rem;
15
+ border-bottom: 0.0625rem solid transparent;
16
+ transition: border-bottom-color 192ms ease-in-out;
17
+ cursor: pointer;
18
+ }
19
+
20
+ :host([hidden]),
21
+ [hidden] {
22
+ display: none !important;
23
+ }
24
+
25
+ *,
26
+ *::before,
27
+ *::after {
28
+ box-sizing: inherit;
29
+ }
30
+
31
+ :host([aria-selected=true]) {
32
+ font-weight: 700;
33
+ border-bottom-color: var(--_selected-border-color);
34
+ }
35
+
36
+ :host(:focus:not(:focus-visible)) {
37
+ outline: none;
38
+ }
39
+
40
+ :host(:focus-visible) {
41
+ outline: 0.0625rem dashed var(--_focus-outline-color);
42
+ outline-offset: -0.125rem;
43
+ }
44
+
45
+ slot::before {
46
+ content: attr(data-text);
47
+ display: block;
48
+ font: inherit;
49
+ font-weight: 700;
50
+ width: inherit;
51
+ height: 0;
52
+ overflow: hidden;
53
+ visibility: hidden;
54
+ }`;
@@ -0,0 +1,65 @@
1
+ import { html, LitElement } from 'lit';
2
+ import { styles } from './styles/blockquote-tabpanel-styles.css.js';
3
+
4
+ export class BlockquoteTabPanel extends LitElement {
5
+ static get is() {
6
+ return 'blockquote-tabpanel';
7
+ }
8
+
9
+ static get properties() {
10
+ return {
11
+ /**
12
+ * The -
13
+ * @type {boolean}
14
+ */
15
+ selected: {
16
+ type: Boolean,
17
+ },
18
+ };
19
+ }
20
+
21
+ constructor() {
22
+ super();
23
+ this.selected = false;
24
+ this.globalRootAttributes = {
25
+ role: 'tabpanel',
26
+ slot: 'tabpanel',
27
+ tabindex: 0,
28
+ };
29
+ }
30
+
31
+ static get styles() {
32
+ return [styles];
33
+ }
34
+
35
+ connectedCallback() {
36
+ super.connectedCallback && super.connectedCallback();
37
+ // https://www.scottohara.me/blog/2021/07/23/aria-idl.html
38
+ // https://wpt.fyi/results/html/dom/aria-attribute-reflection.html?label=master&label=experimental&aligned&view=subtest&q=aria-attribute-reflection
39
+ this.__setArrayAttibute(this.globalRootAttributes);
40
+ }
41
+
42
+ updated(props) {
43
+ super.updated && super.updated(props);
44
+ if (props.has('selected')) {
45
+ const globalRootAttributes = {
46
+ ...this.globalRootAttributes,
47
+ ...{
48
+ 'aria-hidden': !this.selected,
49
+ },
50
+ };
51
+
52
+ this.__setArrayAttibute(globalRootAttributes);
53
+ }
54
+ }
55
+
56
+ render() {
57
+ return html` <slot></slot> `;
58
+ }
59
+
60
+ __setArrayAttibute(entries = []) {
61
+ Object.entries(entries).forEach(([key, value]) => {
62
+ this.setAttribute(key, value);
63
+ });
64
+ }
65
+ }
@@ -0,0 +1,32 @@
1
+ import { css } from 'lit';
2
+
3
+ export const styles = css`:host {
4
+ display: block;
5
+ box-sizing: border-box;
6
+ padding: 1rem;
7
+ color: var(--tabpanel, inherit);
8
+ }
9
+
10
+ :host([hidden]),
11
+ [hidden] {
12
+ display: none !important;
13
+ }
14
+
15
+ *,
16
+ *::before,
17
+ *::after {
18
+ box-sizing: inherit;
19
+ }
20
+
21
+ :host([aria-hidden=true]) {
22
+ display: none;
23
+ }
24
+
25
+ :host(:focus:not(:focus-visible)) {
26
+ outline: none;
27
+ }
28
+
29
+ :host(:focus-visible) {
30
+ outline: #9e9e9e dashed 0.0625rem;
31
+ outline-offset: -2px;
32
+ }`;