@vaadin/checkbox 22.0.0-alpha10

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,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2021 Vaadin Ltd.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @vaadin/checkbox
2
+
3
+ An input field representing a binary choice.
4
+
5
+ [Live Demo ↗](https://vaadin.com/docs/latest/ds/components/checkbox)
6
+
7
+ ```html
8
+ <vaadin-checkbox>I accept the terms and conditions</vaadin-checkbox>
9
+ ```
10
+
11
+ ## Installation
12
+
13
+ Install the component:
14
+
15
+ ```sh
16
+ npm i @vaadin/checkbox --save
17
+ ```
18
+
19
+ Once installed, import the component in your application:
20
+
21
+ ```js
22
+ import '@vaadin/checkbox';
23
+ ```
24
+
25
+ ## Themes
26
+
27
+ Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/ds/customization/using-themes),
28
+ Lumo and Material. The [main entrypoint](https://github.com/vaadin/web-components/blob/master/packages/checkbox/vaadin-checkbox.js)
29
+ of the package uses the Lumo theme.
30
+
31
+ To use the Material theme, import the component from the `theme/material` folder:
32
+
33
+ ```js
34
+ import '@vaadin/checkbox/theme/material/vaadin-checkbox.js';
35
+ ```
36
+
37
+ You can also import the Lumo version of the component explicitly:
38
+
39
+ ```js
40
+ import '@vaadin/checkbox/theme/lumo/vaadin-checkbox.js';
41
+ ```
42
+
43
+ Finally, you can import the un-themed component from the `src` folder to get a minimal starting point:
44
+
45
+ ```js
46
+ import '@vaadin/checkbox/src/vaadin-checkbox.js';
47
+ ```
48
+
49
+ ## License
50
+
51
+ Apache License 2.0
52
+
53
+ Vaadin collects development time usage statistics to improve this product.
54
+ For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@vaadin/checkbox",
3
+ "version": "22.0.0-alpha10",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "vaadin-checkbox",
8
+ "license": "Apache-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/vaadin/web-components.git",
12
+ "directory": "packages/checkbox"
13
+ },
14
+ "author": "Vaadin Ltd",
15
+ "homepage": "https://vaadin.com/components",
16
+ "bugs": {
17
+ "url": "https://github.com/vaadin/web-components/issues"
18
+ },
19
+ "main": "vaadin-checkbox.js",
20
+ "module": "vaadin-checkbox.js",
21
+ "files": [
22
+ "src",
23
+ "theme",
24
+ "vaadin-*.d.ts",
25
+ "vaadin-*.js"
26
+ ],
27
+ "keywords": [
28
+ "Vaadin",
29
+ "checkbox",
30
+ "web-components",
31
+ "web-component",
32
+ "polymer"
33
+ ],
34
+ "dependencies": {
35
+ "@polymer/polymer": "^3.0.0",
36
+ "@vaadin/component-base": "22.0.0-alpha10",
37
+ "@vaadin/field-base": "22.0.0-alpha10",
38
+ "@vaadin/vaadin-lumo-styles": "22.0.0-alpha10",
39
+ "@vaadin/vaadin-material-styles": "22.0.0-alpha10",
40
+ "@vaadin/vaadin-themable-mixin": "22.0.0-alpha10"
41
+ },
42
+ "devDependencies": {
43
+ "@esm-bundle/chai": "^4.3.4",
44
+ "@vaadin/testing-helpers": "^0.3.0",
45
+ "sinon": "^9.2.0"
46
+ },
47
+ "gitHead": "6d3055383b9c3c8306ea34c6f2e2087e63c49348"
48
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ActiveMixin } from '@vaadin/component-base/src/active-mixin.js';
7
+ import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
+ import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js';
9
+ import { DelegateFocusMixin } from '@vaadin/field-base/src/delegate-focus-mixin.js';
10
+ import { SlotLabelMixin } from '@vaadin/field-base/src/slot-label-mixin.js';
11
+ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
+
13
+ /**
14
+ * Fired when the `checked` property changes.
15
+ */
16
+ export type CheckboxCheckedChangedEvent = CustomEvent<{ value: boolean }>;
17
+
18
+ /**
19
+ * Fired when the `indeterminate` property changes.
20
+ */
21
+ export type CheckboxIndeterminateChangedEvent = CustomEvent<{ value: boolean }>;
22
+
23
+ export interface CheckboxCustomEventMap {
24
+ 'checked-changed': CheckboxCheckedChangedEvent;
25
+
26
+ 'indeterminate-changed': CheckboxIndeterminateChangedEvent;
27
+ }
28
+
29
+ export interface CheckboxEventMap extends HTMLElementEventMap, CheckboxCustomEventMap {}
30
+
31
+ /**
32
+ * `<vaadin-checkbox>` is an input field representing a binary choice.
33
+ *
34
+ * ```html
35
+ * <vaadin-checkbox>I accept the terms and conditions</vaadin-checkbox>
36
+ * ```
37
+ *
38
+ * ### Styling
39
+ *
40
+ * The following shadow DOM parts are available for styling:
41
+ *
42
+ * Part name | Description
43
+ * ------------|----------------
44
+ * `container` | The container element
45
+ * `checkbox` | The wrapper element that contains slotted `<input type="checkbox">`
46
+ * `label` | The wrapper element that contains slotted `<label>`
47
+ *
48
+ * The following state attributes are available for styling:
49
+ *
50
+ * Attribute | Description | Part name
51
+ * ----------------|-------------|--------------
52
+ * `active` | Set when the checkbox is pressed down, either with mouse, touch or the keyboard. | `:host`
53
+ * `disabled` | Set when the checkbox is disabled. | `:host`
54
+ * `focus-ring` | Set when the checkbox is focused using the keyboard. | `:host`
55
+ * `focused` | Set when the checkbox is focused. | `:host`
56
+ * `indeterminate` | Set when the checkbox is in the indeterminate state. | `:host`
57
+ * `checked` | Set when the checkbox is checked. | `:host`
58
+ * `has-label` | Set when the checkbox has a label. | `:host`
59
+ *
60
+ * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
61
+ *
62
+ * @fires {CustomEvent} checked-changed - Fired when the `checked` property changes.
63
+ * @fires {CustomEvent} indeterminate-changed - Fired when the `indeterminate` property changes.
64
+ */
65
+ declare class Checkbox extends SlotLabelMixin(
66
+ CheckedMixin(DelegateFocusMixin(ActiveMixin(ElementMixin(ThemableMixin(HTMLElement)))))
67
+ ) {
68
+ /**
69
+ * True if the checkbox is in the indeterminate state which means
70
+ * it is not possible to say whether it is checked or unchecked.
71
+ * The state is reset once the user switches the checkbox by hand.
72
+ *
73
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Indeterminate_state_checkboxes
74
+ */
75
+ indeterminate: boolean;
76
+
77
+ /**
78
+ * The name of the checkbox.
79
+ */
80
+ name: string;
81
+
82
+ addEventListener<K extends keyof CheckboxEventMap>(
83
+ type: K,
84
+ listener: (this: Checkbox, ev: CheckboxEventMap[K]) => void,
85
+ options?: boolean | AddEventListenerOptions
86
+ ): void;
87
+
88
+ removeEventListener<K extends keyof CheckboxEventMap>(
89
+ type: K,
90
+ listener: (this: Checkbox, ev: CheckboxEventMap[K]) => void,
91
+ options?: boolean | EventListenerOptions
92
+ ): void;
93
+ }
94
+
95
+ declare global {
96
+ interface HTMLElementTagNameMap {
97
+ 'vaadin-checkbox': Checkbox;
98
+ }
99
+ }
100
+
101
+ export { Checkbox };
@@ -0,0 +1,244 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
7
+ import { ActiveMixin } from '@vaadin/component-base/src/active-mixin.js';
8
+ import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
+ import { AriaLabelController } from '@vaadin/field-base/src/aria-label-controller.js';
10
+ import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js';
11
+ import { DelegateFocusMixin } from '@vaadin/field-base/src/delegate-focus-mixin.js';
12
+ import { InputController } from '@vaadin/field-base/src/input-controller.js';
13
+ import { SlotLabelMixin } from '@vaadin/field-base/src/slot-label-mixin.js';
14
+ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
15
+
16
+ /**
17
+ * `<vaadin-checkbox>` is an input field representing a binary choice.
18
+ *
19
+ * ```html
20
+ * <vaadin-checkbox>I accept the terms and conditions</vaadin-checkbox>
21
+ * ```
22
+ *
23
+ * ### Styling
24
+ *
25
+ * The following shadow DOM parts are available for styling:
26
+ *
27
+ * Part name | Description
28
+ * ------------|----------------
29
+ * `container` | The container element.
30
+ * `checkbox` | The wrapper element that contains slotted <input type="checkbox">.
31
+ * `label` | The wrapper element that contains slotted <label>.
32
+ *
33
+ * The following state attributes are available for styling:
34
+ *
35
+ * Attribute | Description | Part name
36
+ * ----------------|-------------|--------------
37
+ * `active` | Set when the checkbox is pressed down, either with mouse, touch or the keyboard. | `:host`
38
+ * `disabled` | Set when the checkbox is disabled. | `:host`
39
+ * `focus-ring` | Set when the checkbox is focused using the keyboard. | `:host`
40
+ * `focused` | Set when the checkbox is focused. | `:host`
41
+ * `indeterminate` | Set when the checkbox is in the indeterminate state. | `:host`
42
+ * `checked` | Set when the checkbox is checked. | `:host`
43
+ * `has-label` | Set when the checkbox has a label. | `:host`
44
+ *
45
+ * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
46
+ *
47
+ * @fires {CustomEvent} checked-changed - Fired when the `checked` property changes.
48
+ * @fires {CustomEvent} indeterminate-changed - Fired when the `indeterminate` property changes.
49
+ *
50
+ * @extends HTMLElement
51
+ * @mixes ThemableMixin
52
+ * @mixes ElementMixin
53
+ * @mixes ActiveMixin
54
+ * @mixes DelegateFocusMixin
55
+ * @mixes CheckedMixin
56
+ * @mixes SlotLabelMixin
57
+ */
58
+ class Checkbox extends SlotLabelMixin(
59
+ CheckedMixin(DelegateFocusMixin(ActiveMixin(ElementMixin(ThemableMixin(PolymerElement)))))
60
+ ) {
61
+ static get is() {
62
+ return 'vaadin-checkbox';
63
+ }
64
+
65
+ static get template() {
66
+ return html`
67
+ <style>
68
+ :host {
69
+ display: inline-block;
70
+ }
71
+
72
+ :host([hidden]) {
73
+ display: none !important;
74
+ }
75
+
76
+ :host([disabled]) {
77
+ -webkit-tap-highlight-color: transparent;
78
+ }
79
+
80
+ .vaadin-checkbox-container {
81
+ display: inline-flex;
82
+ align-items: baseline;
83
+ }
84
+
85
+ .vaadin-checkbox-wrapper {
86
+ position: relative;
87
+ flex: none;
88
+ }
89
+
90
+ /* visually hidden */
91
+ ::slotted(input) {
92
+ position: absolute;
93
+ top: 0;
94
+ left: 0;
95
+ right: 0;
96
+ width: 100%;
97
+ height: 100%;
98
+ opacity: 0;
99
+ cursor: inherit;
100
+ margin: 0;
101
+ }
102
+ </style>
103
+ <div class="vaadin-checkbox-container">
104
+ <div class="vaadin-checkbox-wrapper">
105
+ <div part="checkbox"></div>
106
+ <slot name="input"></slot>
107
+ </div>
108
+
109
+ <slot name="label"></slot>
110
+
111
+ <div style="display: none !important">
112
+ <slot id="noop"></slot>
113
+ </div>
114
+ </div>
115
+ `;
116
+ }
117
+
118
+ static get properties() {
119
+ return {
120
+ /**
121
+ * True if the checkbox is in the indeterminate state which means
122
+ * it is not possible to say whether it is checked or unchecked.
123
+ * The state is reset once the user switches the checkbox by hand.
124
+ *
125
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Indeterminate_state_checkboxes
126
+ *
127
+ * @type {boolean}
128
+ */
129
+ indeterminate: {
130
+ type: Boolean,
131
+ notify: true,
132
+ value: false,
133
+ reflectToAttribute: true
134
+ },
135
+
136
+ /**
137
+ * The name of the checkbox.
138
+ *
139
+ * @type {string}
140
+ */
141
+ name: {
142
+ type: String,
143
+ value: ''
144
+ }
145
+ };
146
+ }
147
+
148
+ /** @override */
149
+ static get delegateProps() {
150
+ return [...super.delegateProps, 'indeterminate'];
151
+ }
152
+
153
+ /** @override */
154
+ static get delegateAttrs() {
155
+ return [...super.delegateAttrs, 'name'];
156
+ }
157
+
158
+ constructor() {
159
+ super();
160
+
161
+ this._setType('checkbox');
162
+
163
+ // Set the string "on" as the default value for the checkbox following the HTML specification:
164
+ // https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default-on
165
+ this.value = 'on';
166
+ }
167
+
168
+ /** @protected */
169
+ ready() {
170
+ super.ready();
171
+
172
+ this.addController(
173
+ new InputController(this, (input) => {
174
+ this._setInputElement(input);
175
+ this._setFocusElement(input);
176
+ this.stateTarget = input;
177
+ })
178
+ );
179
+ this.addController(new AriaLabelController(this, this.inputElement, this._labelNode));
180
+ }
181
+
182
+ /**
183
+ * A reference to the default slot from which nodes are copied to the label node.
184
+ *
185
+ * @override
186
+ * @protected
187
+ * @type {HTMLSlotElement}
188
+ */
189
+ get _sourceSlot() {
190
+ return this.$.noop;
191
+ }
192
+
193
+ /**
194
+ * Override __copyNodesToSlotTarget from SlotTargetMixin to show a warning.
195
+ * @override
196
+ * @protected
197
+ * @param {!Array<!Node>} nodes
198
+ **/
199
+ __copyNodesToSlotTarget(nodes) {
200
+ super.__copyNodesToSlotTarget(nodes);
201
+
202
+ console.warn(
203
+ `WARNING: Since Vaadin 22, placing the label as a direct child of a <vaadin-checkbox> is deprecated.
204
+ Please use <label slot="label"> wrapper or the label property instead.`
205
+ );
206
+ }
207
+
208
+ /**
209
+ * Extends the method from `ActiveMixin` in order to
210
+ * prevent setting the `active` attribute when interacting with a link inside the label.
211
+ *
212
+ * @param {Event} event
213
+ * @return {boolean}
214
+ * @protected
215
+ * @override
216
+ */
217
+ _shouldSetActive(event) {
218
+ if (event.target.localName === 'a') {
219
+ return false;
220
+ }
221
+
222
+ return super._shouldSetActive(event);
223
+ }
224
+
225
+ /**
226
+ * Extends the method from `CheckedMixin` in order to
227
+ * reset the indeterminate state once the user switches the checkbox.
228
+ *
229
+ * @param {boolean} checked
230
+ * @protected
231
+ * @override
232
+ */
233
+ _toggleChecked(checked) {
234
+ if (this.indeterminate) {
235
+ this.indeterminate = false;
236
+ }
237
+
238
+ super._toggleChecked(checked);
239
+ }
240
+ }
241
+
242
+ customElements.define(Checkbox.is, Checkbox);
243
+
244
+ export { Checkbox };
@@ -0,0 +1,171 @@
1
+ import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
+ import '@vaadin/vaadin-lumo-styles/color.js';
3
+ import '@vaadin/vaadin-lumo-styles/sizing.js';
4
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
5
+ import '@vaadin/vaadin-lumo-styles/style.js';
6
+ import '@vaadin/vaadin-lumo-styles/typography.js';
7
+
8
+ registerStyles(
9
+ 'vaadin-checkbox',
10
+ css`
11
+ :host {
12
+ color: var(--lumo-body-text-color);
13
+ font-size: var(--lumo-font-size-m);
14
+ font-family: var(--lumo-font-family);
15
+ line-height: var(--lumo-line-height-s);
16
+ -webkit-font-smoothing: antialiased;
17
+ -moz-osx-font-smoothing: grayscale;
18
+ -webkit-tap-highlight-color: transparent;
19
+ -webkit-user-select: none;
20
+ -moz-user-select: none;
21
+ user-select: none;
22
+ cursor: default;
23
+ outline: none;
24
+ }
25
+
26
+ :host([has-label]) ::slotted(label) {
27
+ padding: var(--lumo-space-xs) var(--lumo-space-s) var(--lumo-space-xs) var(--lumo-space-xs);
28
+ }
29
+
30
+ [part='checkbox'] {
31
+ width: calc(var(--lumo-size-m) / 2);
32
+ height: calc(var(--lumo-size-m) / 2);
33
+ margin: var(--lumo-space-xs);
34
+ position: relative;
35
+ border-radius: var(--lumo-border-radius-s);
36
+ background-color: var(--lumo-contrast-20pct);
37
+ transition: transform 0.2s cubic-bezier(0.12, 0.32, 0.54, 2), background-color 0.15s;
38
+ line-height: 1.2;
39
+ cursor: var(--lumo-clickable-cursor);
40
+ flex: none;
41
+ }
42
+
43
+ :host([indeterminate]) [part='checkbox'],
44
+ :host([checked]) [part='checkbox'] {
45
+ background-color: var(--lumo-primary-color);
46
+ }
47
+
48
+ /* Needed to align the checkbox nicely on the baseline */
49
+ [part='checkbox']::before {
50
+ content: '\\2003';
51
+ }
52
+
53
+ /* Checkmark */
54
+ [part='checkbox']::after {
55
+ content: '';
56
+ pointer-events: none;
57
+ display: inline-block;
58
+ width: 0;
59
+ height: 0;
60
+ border: 0 solid var(--lumo-primary-contrast-color);
61
+ border-width: 0.1875em 0 0 0.1875em;
62
+ box-sizing: border-box;
63
+ transform-origin: 0 0;
64
+ position: absolute;
65
+ top: 0.8125em;
66
+ left: 0.5em;
67
+ transform: scale(0.55) rotate(-135deg);
68
+ opacity: 0;
69
+ }
70
+
71
+ :host([checked]) [part='checkbox']::after {
72
+ opacity: 1;
73
+ width: 0.625em;
74
+ height: 1.0625em;
75
+ }
76
+
77
+ /* Indeterminate checkmark */
78
+ :host([indeterminate]) [part='checkbox']::after {
79
+ transform: none;
80
+ opacity: 1;
81
+ top: 45%;
82
+ height: 10%;
83
+ left: 22%;
84
+ right: 22%;
85
+ width: auto;
86
+ border: 0;
87
+ background-color: var(--lumo-primary-contrast-color);
88
+ transition: opacity 0.25s;
89
+ }
90
+
91
+ /* Focus ring */
92
+ :host([focus-ring]) [part='checkbox'] {
93
+ box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 3px var(--lumo-primary-color-50pct);
94
+ }
95
+
96
+ /* Disabled */
97
+ :host([disabled]) {
98
+ pointer-events: none;
99
+ color: var(--lumo-disabled-text-color);
100
+ }
101
+
102
+ :host([disabled]) ::slotted(label) {
103
+ color: inherit;
104
+ }
105
+
106
+ :host([disabled]) [part='checkbox'] {
107
+ background-color: var(--lumo-contrast-10pct);
108
+ }
109
+
110
+ :host([disabled]) [part='checkbox']::after {
111
+ border-color: var(--lumo-contrast-30pct);
112
+ }
113
+
114
+ :host([indeterminate][disabled]) [part='checkbox']::after {
115
+ background-color: var(--lumo-contrast-30pct);
116
+ }
117
+
118
+ /* RTL specific styles */
119
+ :host([dir='rtl'][has-label]) ::slotted(label) {
120
+ padding: var(--lumo-space-xs) var(--lumo-space-xs) var(--lumo-space-xs) var(--lumo-space-s);
121
+ }
122
+
123
+ /* Transition the checkmark if activated with the mouse (disabled for grid select-all this way) */
124
+ :host(:hover) [part='checkbox']::after {
125
+ transition: width 0.1s, height 0.25s;
126
+ }
127
+
128
+ /* Used for activation "halo" */
129
+ [part='checkbox']::before {
130
+ pointer-events: none;
131
+ color: transparent;
132
+ display: inline-block;
133
+ width: 100%;
134
+ height: 100%;
135
+ border-radius: inherit;
136
+ background-color: inherit;
137
+ transform: scale(1.4);
138
+ opacity: 0;
139
+ transition: transform 0.1s, opacity 0.8s;
140
+ }
141
+
142
+ /* Hover */
143
+ :host(:not([checked]):not([indeterminate]):not([disabled]):hover) [part='checkbox'] {
144
+ background-color: var(--lumo-contrast-30pct);
145
+ }
146
+
147
+ /* Disable hover for touch devices */
148
+ @media (pointer: coarse) {
149
+ :host(:not([checked]):not([indeterminate]):not([disabled]):hover) [part='checkbox'] {
150
+ background-color: var(--lumo-contrast-20pct);
151
+ }
152
+ }
153
+
154
+ /* Active */
155
+ :host([active]) [part='checkbox'] {
156
+ transform: scale(0.9);
157
+ transition-duration: 0.05s;
158
+ }
159
+
160
+ :host([active][checked]) [part='checkbox'] {
161
+ transform: scale(1.1);
162
+ }
163
+
164
+ :host([active]:not([checked])) [part='checkbox']::before {
165
+ transition-duration: 0.01s, 0.01s;
166
+ transform: scale(0);
167
+ opacity: 0.4;
168
+ }
169
+ `,
170
+ { moduleId: 'lumo-checkbox' }
171
+ );
@@ -0,0 +1,2 @@
1
+ import './vaadin-checkbox-styles.js';
2
+ import '../../src/vaadin-checkbox.js';
@@ -0,0 +1,130 @@
1
+ import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
+ import '@vaadin/vaadin-material-styles/color.js';
3
+
4
+ registerStyles(
5
+ 'vaadin-checkbox',
6
+ css`
7
+ :host {
8
+ display: inline-block;
9
+ -webkit-user-select: none;
10
+ -moz-user-select: none;
11
+ -ms-user-select: none;
12
+ user-select: none;
13
+ outline: none;
14
+ -webkit-tap-highlight-color: transparent;
15
+ }
16
+
17
+ :host([has-label]) ::slotted(label) {
18
+ padding: 3px 12px 3px 6px;
19
+ }
20
+
21
+ [part='checkbox'] {
22
+ display: inline-block;
23
+ width: 16px;
24
+ height: 16px;
25
+ margin: 4px;
26
+ position: relative;
27
+ border-radius: 2px;
28
+ box-shadow: inset 0 0 0 2px var(--material-secondary-text-color);
29
+ line-height: 1.275;
30
+ background-color: transparent;
31
+ }
32
+
33
+ /* Used for the ripple */
34
+ [part='checkbox']::before {
35
+ /* Needed to align the checkbox nicely on the baseline */
36
+ content: '\\2003';
37
+ pointer-events: none;
38
+ display: inline-block;
39
+ width: 100%;
40
+ height: 100%;
41
+ border-radius: 50%;
42
+ background-color: var(--material-disabled-text-color);
43
+ transform: scale(0);
44
+ opacity: 0;
45
+ transition: transform 0s 0.8s, opacity 0.8s;
46
+ will-change: transform, opacity;
47
+ }
48
+
49
+ /* Used for the checkmark */
50
+ [part='checkbox']::after {
51
+ content: '';
52
+ pointer-events: none;
53
+ display: inline-block;
54
+ width: 10px;
55
+ height: 19px;
56
+ border: 0 solid var(--material-background-color);
57
+ border-width: 3px 0 0 3px;
58
+ box-sizing: border-box;
59
+ transform-origin: 0 0;
60
+ position: absolute;
61
+ top: 12px;
62
+ left: 6px;
63
+ transform: scale(0) rotate(-135deg);
64
+ transition: transform 0.2s;
65
+ }
66
+
67
+ :host([indeterminate]) [part='checkbox'],
68
+ :host([checked]) [part='checkbox'] {
69
+ background-color: var(--material-primary-color);
70
+ box-shadow: none;
71
+ }
72
+
73
+ :host([checked]) [part='checkbox']::after {
74
+ transform: scale(0.55) rotate(-135deg);
75
+ }
76
+
77
+ :host(:not([checked]):not([indeterminate]):not([disabled]):hover) [part='checkbox'] {
78
+ background-color: transparent;
79
+ }
80
+
81
+ :host([focus-ring]) [part='checkbox']::before,
82
+ :host([active]) [part='checkbox']::before {
83
+ transition-duration: 0.08s, 0.01s;
84
+ transition-delay: 0s, 0s;
85
+ transform: scale(2.5);
86
+ opacity: 0.15;
87
+ }
88
+
89
+ :host([checked]) [part='checkbox']::before {
90
+ background-color: var(--material-primary-color);
91
+ }
92
+
93
+ :host([indeterminate]) [part='checkbox']::after {
94
+ transform: none;
95
+ opacity: 1;
96
+ top: 45%;
97
+ height: 10%;
98
+ left: 22%;
99
+ right: 22%;
100
+ width: auto;
101
+ border: 0;
102
+ background-color: var(--material-background-color);
103
+ transition: opacity 0.4s;
104
+ }
105
+
106
+ :host([disabled]) {
107
+ pointer-events: none;
108
+ color: var(--material-disabled-text-color);
109
+ }
110
+
111
+ :host([disabled]) ::slotted(label) {
112
+ color: inherit;
113
+ }
114
+
115
+ :host([disabled]:not([checked]):not([indeterminate])) [part='checkbox'] {
116
+ box-shadow: inset 0 0 0 2px var(--material-disabled-color);
117
+ }
118
+
119
+ :host([disabled][checked]) [part='checkbox'],
120
+ :host([disabled][indeterminate]) [part='checkbox'] {
121
+ background-color: var(--material-disabled-color);
122
+ }
123
+
124
+ /* RTL specific styles */
125
+ :host([dir='rtl'][has-label]) ::slotted(label) {
126
+ padding: 3px 6px 3px 12px;
127
+ }
128
+ `,
129
+ { moduleId: 'material-checkbox' }
130
+ );
@@ -0,0 +1,2 @@
1
+ import './vaadin-checkbox-styles.js';
2
+ import '../../src/vaadin-checkbox.js';
@@ -0,0 +1 @@
1
+ export * from './src/vaadin-checkbox.js';
@@ -0,0 +1,2 @@
1
+ import './theme/lumo/vaadin-checkbox.js';
2
+ export * from './src/vaadin-checkbox.js';