@blockquote-web-components/blockquote-directive-ariaidref-slot 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) 2024 blockquote-directive-ariaidref-slot
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,81 @@
1
+ # blockquoteDirectiveAriaidrefSlot
2
+
3
+ ![Lit](https://img.shields.io/badge/lit-3.0.0-blue.svg)
4
+
5
+ This directive creates a slot element, hidden by default, with a specific name and id.
6
+ The name and id of this slot should correspond to the 'slot' attribute of an element in the Light DOM.
7
+ It connects the 'slot', 'name', and 'id' attributes of a slot to be used with ARIA relationships.
8
+
9
+ This slot element is used to overcome some limitations of the Shadow DOM.
10
+
11
+ > [aria attribute reflection](https://web.dev/articles/aria-labels-and-relationships#relationships)
12
+
13
+ ### Demo
14
+
15
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/oscarmarina/blockquote-web-components/tree/main/packages/directives/blockquote-directive-ariaidref-slot)
16
+
17
+ ### Usage
18
+
19
+ __Light Dom__:
20
+
21
+ ```html
22
+ <wrapper-dialog>
23
+ <span slot="idref_">Registration - All fields are required</span>
24
+ </wrapper-dialog>
25
+ ```
26
+
27
+ __Shadow Dom__:
28
+
29
+ ```js
30
+ class MyDialog extends LitElement {
31
+ constructor() {
32
+ super();
33
+ this.labelledby = 'idref_';
34
+ }
35
+
36
+ get _labeledbyTpl() {
37
+ return html`${this.labelledby ? blockquoteDirectiveAriaidrefSlot(this.labelledby) : ''}`;
38
+ }
39
+
40
+ render() {
41
+ return html`
42
+ <dialog aria-labelledby="${this.labelledby || nothing}"><slot></slot></dialog>
43
+ // slot is hidden by default
44
+ ${this._labeledbyTpl} // <slot name="idref_" id="idref_" hidden=""></slot>
45
+
46
+ // slot not hidden
47
+ ${this._labeledbyTpl, false} // <slot name="idref_" id="idref_"></slot>
48
+ `;
49
+ }
50
+ }
51
+ ```
52
+
53
+
54
+ ### `src/BlockquoteDirectiveAriaidrefSlot.js`:
55
+
56
+ #### class: `README`
57
+
58
+ <hr/>
59
+
60
+ #### Variables
61
+
62
+ | Name | Description | Type |
63
+ | ---------------------------------- | ----------- | ---- |
64
+ | `blockquoteDirectiveAriaidrefSlot` | | |
65
+
66
+ <hr/>
67
+
68
+ #### Exports
69
+
70
+ | Kind | Name | Declaration | Module | Package |
71
+ | ---- | ---------------------------------- | -------------------------------- | --------------------------------------- | ------- |
72
+ | `js` | `README` | README | src/BlockquoteDirectiveAriaidrefSlot.js | |
73
+ | `js` | `blockquoteDirectiveAriaidrefSlot` | blockquoteDirectiveAriaidrefSlot | src/BlockquoteDirectiveAriaidrefSlot.js | |
74
+
75
+ ### `src/index.js`:
76
+
77
+ #### Exports
78
+
79
+ | Kind | Name | Declaration | Module | Package |
80
+ | ---- | ---------------------------------- | -------------------------------- | ------------------------------------- | ------- |
81
+ | `js` | `blockquoteDirectiveAriaidrefSlot` | blockquoteDirectiveAriaidrefSlot | ./BlockquoteDirectiveAriaidrefSlot.js | |
package/package.json ADDED
@@ -0,0 +1,160 @@
1
+ {
2
+ "name": "@blockquote-web-components/blockquote-directive-ariaidref-slot",
3
+ "version": "1.0.0",
4
+ "description": "This directive creates a slot element, hidden by default, with a specific name and id",
5
+ "keywords": [
6
+ "lit",
7
+ "web-component",
8
+ "lit-element",
9
+ "aria",
10
+ "slot",
11
+ "aria-labels",
12
+ "relationships"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "blockquote-directive-ariaidref-slot",
16
+ "type": "module",
17
+ "exports": {
18
+ ".": {
19
+ "default": "./src/index.js"
20
+ },
21
+ "./package.json": {
22
+ "default": "./package.json"
23
+ },
24
+ "./src/BlockquoteDirectiveAriaidrefSlot.js": {
25
+ "default": "./src/BlockquoteDirectiveAriaidrefSlot.js"
26
+ },
27
+ "./index.js": {
28
+ "default": "./src/index.js"
29
+ }
30
+ },
31
+ "main": "src/index.js",
32
+ "module": "src/index.js",
33
+ "files": [
34
+ "/define/",
35
+ "/src/",
36
+ "index.js",
37
+ "!/**/*.scss"
38
+ ],
39
+ "scripts": {
40
+ "analyze": "cem analyze --litelement --globs \"{src,define}/**/*.{js,ts}\" \"index.js\"",
41
+ "build": "echo \"This is not a TypeScript project, so no need to build.\"",
42
+ "dev:vite": "vite build",
43
+ "format": "npm run format:eslint && npm run format:prettier && npm run format:stylelint",
44
+ "format:eslint": "eslint \"**/*.{js,ts,html}\" --fix --ignore-path .eslintignore",
45
+ "format:prettier": "prettier \"**/*.{js,ts,json,html}\" --write --ignore-path .eslintignore",
46
+ "format:stylelint": "stylelint \"**/*.{scss,css}\" --fix --allow-empty-input --ignore-path .eslintignore",
47
+ "postinstall": "npm run sort:package",
48
+ "lint": "npm run lint:eslint && npm run lint:prettier && npm run lint:stylelint",
49
+ "lint:eslint": "eslint \"**/*.{js,ts,html}\" --ignore-path .eslintignore",
50
+ "lint:prettier": "prettier \"**/*.{js,ts,json,html}\" --check --ignore-path .eslintignore",
51
+ "lint:stylelint": "stylelint \"**/*.{scss,css}\" --allow-empty-input --ignore-path .eslintignore",
52
+ "prepare": "husky",
53
+ "preview:vite": "vite preview",
54
+ "sass:watch": "sass-style-template",
55
+ "sort:package": "npx sort-package-json",
56
+ "start": "concurrently -k -r \"npm:sass:watch\" \"npm:vite\"",
57
+ "test": "wtr",
58
+ "test:watch": "wtr --watch",
59
+ "vite": "vite"
60
+ },
61
+ "lint-staged": {
62
+ "**/*.{js,ts,html}": [
63
+ "npm run format:eslint"
64
+ ],
65
+ "**/*.{js,ts,json,html}": [
66
+ "npm run format:prettier"
67
+ ],
68
+ "**/*.{scss,css}": [
69
+ "npm run format:stylelint"
70
+ ]
71
+ },
72
+ "prettier": {
73
+ "arrowParens": "avoid",
74
+ "printWidth": 100,
75
+ "singleQuote": true,
76
+ "trailingComma": "all",
77
+ "overrides": [
78
+ {
79
+ "files": "*.{scss,css}",
80
+ "options": {
81
+ "printWidth": 280,
82
+ "singleQuote": false
83
+ }
84
+ }
85
+ ]
86
+ },
87
+ "eslintConfig": {
88
+ "parserOptions": {
89
+ "ecmaVersion": "latest"
90
+ },
91
+ "extends": [
92
+ "@open-wc",
93
+ "prettier"
94
+ ],
95
+ "rules": {
96
+ "class-methods-use-this": "off",
97
+ "indent": [
98
+ "error",
99
+ 2,
100
+ {
101
+ "SwitchCase": 1,
102
+ "ignoredNodes": [
103
+ "PropertyDefinition",
104
+ "TemplateLiteral > CallExpression"
105
+ ]
106
+ }
107
+ ],
108
+ "no-unused-expressions": [
109
+ "error",
110
+ {
111
+ "allowShortCircuit": true,
112
+ "allowTernary": true
113
+ }
114
+ ],
115
+ "object-curly-newline": "off",
116
+ "import/extensions": [
117
+ "error",
118
+ "always",
119
+ {
120
+ "ignorePackages": true
121
+ }
122
+ ],
123
+ "import/no-extraneous-dependencies": [
124
+ "error",
125
+ {
126
+ "devDependencies": [
127
+ "**/test/**/*.{js,ts}",
128
+ "**/*.config.{js,ts,mjs,cjs}",
129
+ "**/*.conf.{js,ts,mjs,cjs}"
130
+ ]
131
+ }
132
+ ],
133
+ "import/no-unresolved": "off",
134
+ "import/prefer-default-export": "off",
135
+ "lit-a11y/click-events-have-key-events": "off",
136
+ "lit/no-classfield-shadowing": "off",
137
+ "lit/no-native-attributes": "off"
138
+ }
139
+ },
140
+ "stylelint": {
141
+ "extends": "stylelint-config-standard-scss",
142
+ "rules": {
143
+ "custom-property-pattern": null,
144
+ "no-duplicate-selectors": null,
145
+ "color-function-notation": null,
146
+ "alpha-value-notation": null
147
+ }
148
+ },
149
+ "dependencies": {
150
+ "lit": "^3.1.1"
151
+ },
152
+ "devDependencies": {
153
+ "@blockquote-web-components/blockquote-base-common-dev-dependencies": "^1.9.0",
154
+ "@blockquote-web-components/blockquote-base-embedded-webview": "^1.10.1"
155
+ },
156
+ "publishConfig": {
157
+ "access": "public"
158
+ },
159
+ "customElements": "custom-elements.json"
160
+ }
@@ -0,0 +1,90 @@
1
+ // eslint-disable-next-line max-classes-per-file
2
+ import { Directive, directive, PartType } from 'lit/directive.js';
3
+ import { noChange } from 'lit';
4
+
5
+ /**
6
+ * # blockquoteDirectiveAriaidrefSlot
7
+ *
8
+ * ![Lit](https://img.shields.io/badge/lit-3.0.0-blue.svg)
9
+ *
10
+ * This directive creates a slot element, hidden by default, with a specific name and id.
11
+ * The name and id of this slot should correspond to the 'slot' attribute of an element in the Light DOM.
12
+ * It connects the 'slot', 'name', and 'id' attributes of a slot to be used with ARIA relationships.
13
+ *
14
+ * This slot element is used to overcome some limitations of the Shadow DOM.
15
+ *
16
+ * > [aria attribute reflection](https://web.dev/articles/aria-labels-and-relationships#relationships)
17
+ *
18
+ * ### Demo
19
+ *
20
+ * [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/oscarmarina/blockquote-web-components/tree/main/packages/directives/blockquote-directive-ariaidref-slot)
21
+ *
22
+ * ### Usage
23
+ *
24
+ * __Light Dom__:
25
+ *
26
+ * ```html
27
+ * <wrapper-dialog>
28
+ * <span slot="idref_">Registration - All fields are required</span>
29
+ * </wrapper-dialog>
30
+ * ```
31
+ *
32
+ * __Shadow Dom__:
33
+ *
34
+ * ```js
35
+ * class MyDialog extends LitElement {
36
+ * constructor() {
37
+ * super();
38
+ * this.labelledby = 'idref_';
39
+ * }
40
+ *
41
+ * get _labeledbyTpl() {
42
+ * return html`${this.labelledby ? blockquoteDirectiveAriaidrefSlot(this.labelledby) : ''}`;
43
+ * }
44
+ *
45
+ * render() {
46
+ * return html`
47
+ * <dialog aria-labelledby="${this.labelledby || nothing}"><slot></slot></dialog>
48
+ * // slot is hidden by default
49
+ * ${this._labeledbyTpl} // <slot name="idref_" id="idref_" hidden=""></slot>
50
+ *
51
+ * // slot not hidden
52
+ * ${this._labeledbyTpl, false} // <slot name="idref_" id="idref_"></slot>
53
+ * `;
54
+ * }
55
+ * }
56
+ * ```
57
+ */
58
+ export class README extends Text {}
59
+
60
+ class BlockquoteDirectiveAriaidrefSlot extends Directive {
61
+ /**
62
+ * @param {*} partInfo - The part information.
63
+ */
64
+ constructor(partInfo) {
65
+ super(partInfo);
66
+ if (partInfo.type !== PartType.CHILD) {
67
+ throw new Error('blockquoteDirectiveAriaidrefSlot can only be used in child expressions');
68
+ }
69
+ this.hasSlotNode = false;
70
+ }
71
+
72
+ /**
73
+ * Creates an accessible slot element.
74
+ *
75
+ * @param {string} value - The name and id of the slot.
76
+ * @param {boolean} [isVisible=true] - A flag indicating whether the slot is visible (defaults to true).
77
+ * @returns {HTMLSlotElement | import('lit').noChange} - The created slot element, or noChange if the slot was not created.
78
+ */
79
+ render(value, isVisible = false) {
80
+ if (!value || typeof value !== 'string' || this.hasSlotNode) {
81
+ return noChange;
82
+ }
83
+ const slot = document.createElement('slot');
84
+ Object.assign(slot, { name: value, id: value, hidden: !isVisible });
85
+ this.hasSlotNode = true;
86
+ return slot;
87
+ }
88
+ }
89
+
90
+ export const blockquoteDirectiveAriaidrefSlot = directive(BlockquoteDirectiveAriaidrefSlot);
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { blockquoteDirectiveAriaidrefSlot } from './BlockquoteDirectiveAriaidrefSlot.js';