@c2n/checkbox 0.0.6 → 0.0.8

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/dist/checkbox.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { LitElement, html, unsafeCSS } from "lit";
2
- import { customElement, property, query } from "lit/decorators.js";
2
+ import { property, query, state } from "lit/decorators.js";
3
+ import { customElement } from "@c2n/core/element-helper.js";
3
4
  import { ifDefined } from "lit/directives/if-defined.js";
4
5
  import { redispatchEvent } from "@c2n/core/dom-helper.js";
5
6
  //#region src/checkbox.scss?inline
@@ -17,10 +18,55 @@ function __decorate(decorators, target, key, desc) {
17
18
  var Checkbox = class Checkbox extends LitElement {
18
19
  constructor(..._args) {
19
20
  super(..._args);
21
+ this.internals = this.attachInternals();
22
+ this.customValidityMessage = "";
23
+ this.disabledByForm = false;
20
24
  this.checked = false;
21
25
  this.indeterminate = false;
22
26
  this.disabled = false;
23
27
  this.name = "";
28
+ this.value = "on";
29
+ this.required = false;
30
+ }
31
+ static {
32
+ this.formAssociated = true;
33
+ }
34
+ /** The containing form, when this control is associated with one. */
35
+ get form() {
36
+ return this.internals.form;
37
+ }
38
+ /** Labels associated with this form control. */
39
+ get labels() {
40
+ return this.internals.labels;
41
+ }
42
+ get validity() {
43
+ return this.internals.validity;
44
+ }
45
+ get validationMessage() {
46
+ return this.internals.validationMessage;
47
+ }
48
+ get willValidate() {
49
+ return this.internals.willValidate;
50
+ }
51
+ formResetCallback() {
52
+ this.checked = this.hasAttribute("checked");
53
+ this.indeterminate = false;
54
+ }
55
+ formDisabledCallback(disabled) {
56
+ this.disabledByForm = disabled && !this.hasAttribute("disabled");
57
+ }
58
+ formStateRestoreCallback(state) {
59
+ this.checked = state === "checked";
60
+ }
61
+ checkValidity() {
62
+ return this.internals.checkValidity();
63
+ }
64
+ reportValidity() {
65
+ return this.internals.reportValidity();
66
+ }
67
+ setCustomValidity(message) {
68
+ this.customValidityMessage = message;
69
+ this.requestUpdate();
24
70
  }
25
71
  render() {
26
72
  const ariaChecked = this.indeterminate ? "mixed" : void 0;
@@ -34,7 +80,9 @@ var Checkbox = class Checkbox extends LitElement {
34
80
  aria-label="${ifDefined(this.ariaLabel)}"
35
81
  aria-labelledby="${ifDefined(this.ariaLabelledBy)}"
36
82
  aria-describedby="${ifDefined(this.ariaDescribedBy)}"
37
- ?disabled="${this.disabled}"
83
+ ?disabled="${this.effectiveDisabled}"
84
+ ?required="${this.required}"
85
+ .value="${this.value}"
38
86
  .indeterminate="${this.indeterminate}"
39
87
  ?checked="${this.checked}"
40
88
  @change="${this.handleChange}"
@@ -71,6 +119,16 @@ var Checkbox = class Checkbox extends LitElement {
71
119
  if (changedProperties.has("checked") && this.formElement) this.formElement.checked = this.checked;
72
120
  super.update(changedProperties);
73
121
  }
122
+ updated(_changedProperties) {
123
+ this.internals.setFormValue(this.checked ? this.value : null, this.checked ? "checked" : "unchecked");
124
+ const missing = this.required && !this.checked;
125
+ const flags = this.customValidityMessage ? { customError: true } : missing ? { valueMissing: true } : {};
126
+ const message = this.customValidityMessage || (missing ? "Please check this box." : "");
127
+ this.internals.setValidity(flags, message, this.formElement);
128
+ }
129
+ get effectiveDisabled() {
130
+ return this.disabled || this.disabledByForm;
131
+ }
74
132
  handleChange(event) {
75
133
  this.checked = this.formElement.checked;
76
134
  this.indeterminate = this.formElement.indeterminate;
@@ -80,11 +138,9 @@ var Checkbox = class Checkbox extends LitElement {
80
138
  this.styles = unsafeCSS(checkbox_default);
81
139
  }
82
140
  };
141
+ __decorate([state()], Checkbox.prototype, "disabledByForm", void 0);
83
142
  __decorate([query("input")], Checkbox.prototype, "formElement", void 0);
84
- __decorate([property({
85
- type: Boolean,
86
- reflect: true
87
- })], Checkbox.prototype, "checked", void 0);
143
+ __decorate([property({ type: Boolean })], Checkbox.prototype, "checked", void 0);
88
144
  __decorate([property({
89
145
  type: Boolean,
90
146
  reflect: true
@@ -94,6 +150,11 @@ __decorate([property({
94
150
  reflect: true
95
151
  })], Checkbox.prototype, "disabled", void 0);
96
152
  __decorate([property({ type: String })], Checkbox.prototype, "name", void 0);
153
+ __decorate([property({ type: String })], Checkbox.prototype, "value", void 0);
154
+ __decorate([property({
155
+ type: Boolean,
156
+ reflect: true
157
+ })], Checkbox.prototype, "required", void 0);
97
158
  __decorate([property({
98
159
  type: String,
99
160
  attribute: "aria-label"
package/package.json CHANGED
@@ -1,18 +1,30 @@
1
1
  {
2
2
  "name": "@c2n/checkbox",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "dist/checkbox.js",
6
6
  "exports": {
7
7
  ".": {
8
- "default": "./dist/checkbox.js",
9
- "types": "./types/src/checkbox.d.ts"
8
+ "types": "./types/src/checkbox.d.ts",
9
+ "default": "./dist/checkbox.js"
10
+ },
11
+ "./react": {
12
+ "types": "./react.d.ts",
13
+ "default": "./react.js"
14
+ },
15
+ "./vue": {
16
+ "types": "./vue.d.ts",
17
+ "default": "./vue.js"
10
18
  },
11
19
  "./custom-elements.json": "./custom-elements.json"
12
20
  },
13
21
  "files": [
14
22
  "dist",
15
- "types"
23
+ "types",
24
+ "react.d.ts",
25
+ "react.js",
26
+ "vue.d.ts",
27
+ "vue.js"
16
28
  ],
17
29
  "keywords": [
18
30
  "checkbox",
@@ -48,12 +60,12 @@
48
60
  }
49
61
  },
50
62
  "dependencies": {
51
- "@c2n/core": "0.0.6",
63
+ "@c2n/core": "0.0.8",
52
64
  "lit": "3.3.3"
53
65
  },
54
66
  "devDependencies": {
55
67
  "@c2n/config": "*"
56
68
  },
57
69
  "customElements": "custom-elements.json",
58
- "gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
70
+ "gitHead": "be59cbccee1d33ca248e39f69b05c0b595ec6c6d"
59
71
  }
package/react.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // JSX types for the custom elements of @c2n/checkbox. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/checkbox/react'
6
+ //
7
+ // Register the elements at module scope before React renders, or React writes an object prop as an
8
+ // attribute and it stringifies.
9
+
10
+ import type { DetailedHTMLProps, HTMLAttributes } from 'react'
11
+ import type { Checkbox } from '@c2n/checkbox'
12
+
13
+ /** Standard React host-element attributes plus the element's own public properties. */
14
+ type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
15
+
16
+ declare module 'react' {
17
+ namespace JSX {
18
+ interface IntrinsicElements {
19
+ 'c2-checkbox': C2Props<Checkbox>
20
+ }
21
+ }
22
+ }
23
+
24
+ export {}
package/react.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}
@@ -1,4 +1,13 @@
1
1
  import { LitElement, type PropertyValues } from 'lit';
2
+ import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
3
+ /** Events fired by {@link Checkbox}, keyed for `addEventListener`. */
4
+ export interface CheckboxEventMap {
5
+ change: Event;
6
+ }
7
+ export interface Checkbox {
8
+ addEventListener: TypedAddEventListener<Checkbox, CheckboxEventMap>;
9
+ removeEventListener: TypedRemoveEventListener<Checkbox, CheckboxEventMap>;
10
+ }
2
11
  /**
3
12
  * A checkbox with native `<input type="checkbox">` behaviour. The visible box sits centred in a square touch target
4
13
  * (`state-layer--size`) that doubles as the hover layer; that layer is transparent unless a
@@ -56,6 +65,10 @@ import { LitElement, type PropertyValues } from 'lit';
56
65
  * @cssproperty {color} --c2-checkbox__state-layer__hover__selected--color
57
66
  */
58
67
  export declare class Checkbox extends LitElement {
68
+ static formAssociated: boolean;
69
+ private readonly internals;
70
+ private customValidityMessage;
71
+ private disabledByForm;
59
72
  protected formElement: HTMLInputElement;
60
73
  /** Whether the checkbox is checked. */
61
74
  checked: boolean;
@@ -65,12 +78,34 @@ export declare class Checkbox extends LitElement {
65
78
  disabled: boolean;
66
79
  /** Form field name forwarded to the inner input. */
67
80
  name: string;
81
+ /** Value submitted while checked. */
82
+ value: string;
83
+ /** Requires the checkbox to be checked for the form to be valid. */
84
+ required: boolean;
85
+ /** Accessible name used when no visible label names the checkbox. */
68
86
  ariaLabel: string;
87
+ /** Id of the element that labels the checkbox. */
69
88
  ariaLabelledBy: undefined | string;
89
+ /** Id of the element that describes the checkbox. */
70
90
  ariaDescribedBy: undefined | string;
91
+ /** The containing form, when this control is associated with one. */
92
+ get form(): HTMLFormElement | null;
93
+ /** Labels associated with this form control. */
94
+ get labels(): NodeList;
95
+ get validity(): ValidityState;
96
+ get validationMessage(): string;
97
+ get willValidate(): boolean;
98
+ formResetCallback(): void;
99
+ formDisabledCallback(disabled: boolean): void;
100
+ formStateRestoreCallback(state: string | File | FormData | null): void;
101
+ checkValidity(): boolean;
102
+ reportValidity(): boolean;
103
+ setCustomValidity(message: string): void;
71
104
  render(): import("lit-html").TemplateResult<1>;
72
105
  focus(options?: FocusOptions | undefined): void;
73
106
  protected update(changedProperties: PropertyValues): void;
107
+ protected updated(_changedProperties: PropertyValues): void;
108
+ private get effectiveDisabled();
74
109
  protected handleChange(event: Event): void;
75
110
  static styles: import("lit").CSSResult;
76
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAMtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBACa,QAAS,SAAQ,UAAU;IACtB,SAAS,CAAC,WAAW,EAAG,gBAAgB,CAAA;IAExD,uCAAuC;IACK,OAAO,UAAQ;IAE3D,8GAA8G;IAClE,aAAa,UAAQ;IAEjE,yEAAyE;IAC7B,QAAQ,UAAQ;IAE5D,oDAAoD;IACxB,IAAI,SAAK;IAG5B,SAAS,EAA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AAyE;IAC7B,QAAQ,UAAQ;IAE5D,oDAAoD;IACxB,IAAI,SAAK;IAErC,qCAAqC;IACT,KAAK,SAAO;IAExC,oEAAoE;IACxB,QAAQ,UAAQ;IAE5D,qEAAqE;IAE5D,SAAS,EAAG,MAAM,CAAA;IAE3B,kDAAkD;IAElD,cAAc,EAAG,SAAS,GAAG,MAAM,CAAA;IAEnC,qDAAqD;IAErD,eAAe,EAAG,SAAS,GAAG,MAAM,CAAA;IAEpC,qEAAqE;IACrE,IAAI,IAAI,2BAEP;IAED,gDAAgD;IAChD,IAAI,MAAM,aAET;IAED,IAAI,QAAQ,kBAEX;IAED,IAAI,iBAAiB,WAEpB;IAED,IAAI,YAAY,YAEf;IAED,iBAAiB;IAKjB,oBAAoB,CAAC,QAAQ,EAAE,OAAO;IAItC,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI;IAI/D,aAAa;IAIb,cAAc;IAId,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAKxB,MAAM;IA6CN,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI;cAIrC,MAAM,CAAC,iBAAiB,EAAE,cAAc;cAOxC,OAAO,CAAC,kBAAkB,EAAE,cAAc;IAQ7D,OAAO,KAAK,iBAAiB,GAE5B;IAED,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK;IAMnC,OAAgB,MAAM,0BAAoB;CAC3C;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,QAAQ,CAAA;KACxB;CACF"}
package/vue.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // Vue template types for the custom elements of @c2n/checkbox. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/checkbox/vue'
6
+ //
7
+ // Tell the compiler about the tags as well, or every c2-* tag is resolved as a Vue component and renders
8
+ // nothing: template.compilerOptions.isCustomElement = (tag) => tag.startsWith('c2-') in vite.config.ts.
9
+
10
+ import type { DefineComponent, HTMLAttributes } from 'vue'
11
+ import type { Checkbox, CheckboxEventMap } from '@c2n/checkbox'
12
+
13
+ /** The element's own public properties, plus every attribute Vue understands on a host element. */
14
+ type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
15
+
16
+ declare module 'vue' {
17
+ interface GlobalComponents {
18
+ 'c2-checkbox': DefineComponent<
19
+ C2Props<Checkbox> & {
20
+ 'aria-label'?: unknown
21
+ 'aria-labelledby'?: unknown
22
+ 'aria-describedby'?: unknown
23
+ onChange?: (event: CheckboxEventMap['change']) => void
24
+ }
25
+ >
26
+ }
27
+ }
28
+
29
+ declare module '@vue/runtime-dom' {
30
+ interface HTMLAttributes {
31
+ /** Vue's own definition omits it, and slotting a plain element into a component needs it. */
32
+ slot?: string
33
+ }
34
+ }
35
+
36
+ export {}
package/vue.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}