@vscode-elements/elements 2.1.1-pre.0 → 2.2.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/custom-elements.json +1053 -986
- package/dist/bundled.js +147 -76
- package/dist/includes/VscElement.js +1 -1
- package/dist/includes/VscElement.js.map +1 -1
- package/dist/includes/test-helpers.d.ts +2 -2
- package/dist/includes/test-helpers.d.ts.map +1 -1
- package/dist/includes/test-helpers.js +2 -1
- package/dist/includes/test-helpers.js.map +1 -1
- package/dist/vscode-button/vscode-button.d.ts +8 -0
- package/dist/vscode-button/vscode-button.d.ts.map +1 -1
- package/dist/vscode-button/vscode-button.js +37 -12
- package/dist/vscode-button/vscode-button.js.map +1 -1
- package/dist/vscode-button/vscode-button.styles.d.ts.map +1 -1
- package/dist/vscode-button/vscode-button.styles.js +47 -54
- package/dist/vscode-button/vscode-button.styles.js.map +1 -1
- package/dist/vscode-button-group/vscode-button-group.styles.d.ts.map +1 -1
- package/dist/vscode-button-group/vscode-button-group.styles.js +2 -0
- package/dist/vscode-button-group/vscode-button-group.styles.js.map +1 -1
- package/dist/vscode-checkbox/vscode-checkbox.d.ts +5 -2
- package/dist/vscode-checkbox/vscode-checkbox.d.ts.map +1 -1
- package/dist/vscode-checkbox/vscode-checkbox.js +14 -9
- package/dist/vscode-checkbox/vscode-checkbox.js.map +1 -1
- package/dist/vscode-checkbox/vscode-checkbox.styles.d.ts.map +1 -1
- package/dist/vscode-checkbox/vscode-checkbox.styles.js +71 -0
- package/dist/vscode-checkbox/vscode-checkbox.styles.js.map +1 -1
- package/package.json +1 -1
- package/vscode.css-custom-data.json +19 -15
- package/vscode.html-custom-data.json +23 -18
|
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { html, LitElement, nothing } from 'lit';
|
|
8
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
8
9
|
import { property, query } from 'lit/decorators.js';
|
|
9
10
|
import { classMap } from 'lit/directives/class-map.js';
|
|
10
11
|
import { customElement } from '../includes/VscElement.js';
|
|
@@ -101,6 +102,10 @@ let VscodeCheckbox = class VscodeCheckbox extends LabelledCheckboxOrRadioMixin(F
|
|
|
101
102
|
this.defaultChecked = false;
|
|
102
103
|
this.invalid = false;
|
|
103
104
|
this.name = undefined;
|
|
105
|
+
/**
|
|
106
|
+
* When true, renders as a toggle switch instead of a checkbox.
|
|
107
|
+
*/
|
|
108
|
+
this.toggle = false;
|
|
104
109
|
/**
|
|
105
110
|
* Associate a value to the checkbox. According to the native checkbox [specification](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value_2), If the component participates in a form:
|
|
106
111
|
*
|
|
@@ -145,14 +150,6 @@ let VscodeCheckbox = class VscodeCheckbox extends LabelledCheckboxOrRadioMixin(F
|
|
|
145
150
|
disconnectedCallback() {
|
|
146
151
|
this.removeEventListener('keydown', this._handleKeyDown);
|
|
147
152
|
}
|
|
148
|
-
update(
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
150
|
-
changedProperties) {
|
|
151
|
-
super.update(changedProperties);
|
|
152
|
-
if (changedProperties.has('checked')) {
|
|
153
|
-
this.ariaChecked = this.checked ? 'true' : 'false';
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
153
|
/** @internal */
|
|
157
154
|
formResetCallback() {
|
|
158
155
|
this.checked = this.defaultChecked;
|
|
@@ -222,6 +219,9 @@ let VscodeCheckbox = class VscodeCheckbox extends LabelledCheckboxOrRadioMixin(F
|
|
|
222
219
|
const indeterminate = this.indeterminate
|
|
223
220
|
? html `<span class="indeterminate-icon"></span>`
|
|
224
221
|
: nothing;
|
|
222
|
+
const iconContent = this.toggle
|
|
223
|
+
? html `<span class="thumb"></span>`
|
|
224
|
+
: html `${indeterminate}${check}`;
|
|
225
225
|
return html `
|
|
226
226
|
<div class="wrapper">
|
|
227
227
|
<input
|
|
@@ -230,9 +230,11 @@ let VscodeCheckbox = class VscodeCheckbox extends LabelledCheckboxOrRadioMixin(F
|
|
|
230
230
|
class="checkbox"
|
|
231
231
|
type="checkbox"
|
|
232
232
|
?checked=${this.checked}
|
|
233
|
+
role=${ifDefined(this.toggle ? 'switch' : undefined)}
|
|
234
|
+
aria-checked=${ifDefined(this.toggle ? (this.checked ? 'true' : 'false') : undefined)}
|
|
233
235
|
value=${this.value}
|
|
234
236
|
>
|
|
235
|
-
<div class=${iconClasses}>${
|
|
237
|
+
<div class=${iconClasses}>${iconContent}</div>
|
|
236
238
|
<label for="input" class="label" @click=${this._handleClick}>
|
|
237
239
|
<span class=${labelInnerClasses}>
|
|
238
240
|
${this._renderLabelAttribute()}
|
|
@@ -266,6 +268,9 @@ __decorate([
|
|
|
266
268
|
__decorate([
|
|
267
269
|
property({ reflect: true })
|
|
268
270
|
], VscodeCheckbox.prototype, "name", void 0);
|
|
271
|
+
__decorate([
|
|
272
|
+
property({ type: Boolean, reflect: true })
|
|
273
|
+
], VscodeCheckbox.prototype, "toggle", void 0);
|
|
269
274
|
__decorate([
|
|
270
275
|
property()
|
|
271
276
|
], VscodeCheckbox.prototype, "value", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vscode-checkbox.js","sourceRoot":"","sources":["../../src/vscode-checkbox/vscode-checkbox.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAmC,MAAM,KAAK,CAAC;AAChF,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,QAAQ,EAAC,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,oBAAoB,EAAC,MAAM,wDAAwD,CAAC;AAC5F,OAAO,EAAC,4BAA4B,EAAC,MAAM,2DAA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aAAa,CAAC,iBAAiB,CAAC;GACpB,cAAc,CAsR1B","sourcesContent":["import {html, LitElement, nothing, PropertyValueMap, TemplateResult} from 'lit';\nimport {property, query} from 'lit/decorators.js';\nimport {classMap} from 'lit/directives/class-map.js';\nimport {customElement} from '../includes/VscElement.js';\nimport {FormButtonWidgetBase} from '../includes/form-button-widget/FormButtonWidgetBase.js';\nimport {LabelledCheckboxOrRadioMixin} from '../includes/form-button-widget/LabelledCheckboxOrRadio.js';\nimport styles from './vscode-checkbox.styles.js';\nimport {AssociatedFormControl} from '../includes/AssociatedFormControl.js';\n\n/**\n * Allows users to select one or more options from a set. When participating in a form, it supports\n * the `:invalid` pseudo class. Otherwise the error styles can be applied through the `invalid`\n * property.\n *\n * @tag vscode-checkbox\n *\n * @attr name - Name which is used as a variable name in the data of the form-container.\n * @attr label - Attribute pair of the `label` property.\n * @prop label - Label text. It is only applied if component's innerHTML doesn't contain any text.\n *\n * @fires {Event} change - Dispatched when checked state is changed. The event is bubbled, so it can be listened on a parent element like the `CheckboxGroup`.\n * @fires {Event} invalid - Dispatched when the element is invalid and `checkValidity()` has been called or the form containing this element is submitted.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/invalid_event)\n *\n * @cssprop [--vscode-font-family=sans-serif]\n * @cssprop [--vscode-font-size=13px]\n * @cssprop [--vscode-font-weight=normal]\n * @cssprop [--vscode-foreground=#cccccc]\n * @cssprop [--vscode-settings-checkboxBackground=#313131]\n * @cssprop [--vscode-settings-checkboxBorder=#3c3c3c]\n * @cssprop [--vscode-settings-checkboxForeground=#cccccc]\n * @cssprop [--vscode-focusBorder=#0078d4]\n * @cssprop [--vscode-inputValidation-errorBackground=#5a1d1d]\n * @cssprop [--vscode-inputValidation-errorBorder=#be1100]\n */\n@customElement('vscode-checkbox')\nexport class VscodeCheckbox\n extends LabelledCheckboxOrRadioMixin(FormButtonWidgetBase)\n implements AssociatedFormControl\n{\n static override styles = styles;\n\n /** @internal */\n static formAssociated = true;\n\n /** @internal */\n static override shadowRootOptions: ShadowRootInit = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n /**\n * Automatically focus on the element when the page loads.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus)\n */\n @property({type: Boolean, reflect: true})\n override autofocus = false;\n\n @property({type: Boolean, reflect: true})\n set checked(newVal: boolean) {\n this._checked = newVal;\n this._manageRequired();\n this.requestUpdate();\n }\n get checked(): boolean {\n return this._checked;\n }\n\n private _checked = false;\n\n /**\n * The element's initial checked state, which will be restored when the containing form is reset.\n */\n @property({type: Boolean, reflect: true, attribute: 'default-checked'})\n defaultChecked = false;\n\n @property({type: Boolean, reflect: true})\n invalid = false;\n\n @property({reflect: true})\n name: string | undefined = undefined;\n\n /**\n * Associate a value to the checkbox. According to the native checkbox [specification](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value_2), If the component participates in a form:\n *\n * - If it is unchecked, the value will not be submitted.\n * - If it is checked but the value is not set, `on` will be submitted.\n * - If it is checked and value is set, the value will be submitted.\n */\n @property()\n value = '';\n\n @property({type: Boolean, reflect: true})\n disabled = false;\n\n @property({type: Boolean, reflect: true})\n indeterminate = false;\n\n @property({type: Boolean, reflect: true})\n set required(newVal: boolean) {\n this._required = newVal;\n this._manageRequired();\n this.requestUpdate();\n }\n get required() {\n return this._required;\n }\n private _required = false;\n\n get form(): HTMLFormElement | null {\n return this._internals.form;\n }\n\n /** @internal */\n @property()\n type = 'checkbox';\n\n get validity(): ValidityState {\n return this._internals.validity;\n }\n\n get validationMessage(): string {\n return this._internals.validationMessage;\n }\n\n get willValidate(): boolean {\n return this._internals.willValidate;\n }\n\n /**\n * Returns `true` if the element's value is valid; otherwise, it returns `false`.\n * If the element's value is invalid, an invalid event is triggered on the element.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity)\n */\n checkValidity(): boolean {\n return this._internals.checkValidity();\n }\n\n /**\n * Returns `true` if the element's value is valid; otherwise, it returns `false`.\n * If the element's value is invalid, an invalid event is triggered on the element, and the\n * browser displays an error message to the user.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity)\n */\n reportValidity(): boolean {\n return this._internals.reportValidity();\n }\n\n constructor() {\n super();\n this._internals = this.attachInternals();\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n\n this.addEventListener('keydown', this._handleKeyDown);\n\n this.updateComplete.then(() => {\n this._manageRequired();\n this._setActualFormValue();\n });\n }\n\n override disconnectedCallback(): void {\n this.removeEventListener('keydown', this._handleKeyDown);\n }\n\n override update(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.update(changedProperties);\n\n if (changedProperties.has('checked')) {\n this.ariaChecked = this.checked ? 'true' : 'false';\n }\n }\n\n /** @internal */\n formResetCallback(): void {\n this.checked = this.defaultChecked;\n }\n\n /** @internal */\n formStateRestoreCallback(\n state: string,\n _mode: 'restore' | 'autocomplete'\n ): void {\n if (state) {\n this.checked = true;\n }\n }\n\n @query('#input')\n private _inputEl!: HTMLInputElement;\n\n private _internals: ElementInternals;\n\n // Sets the value of the control according to the native checkbox behavior.\n // - If the checkbox is unchecked, the value will be null, so the control will\n // excluded from the form.\n // - If the control is checked but the value is not set, the value will be \"on\".\n // - If the control is checked and value is set, the value won't be changed.\n private _setActualFormValue() {\n let actualValue: string | null = '';\n\n if (this.checked) {\n actualValue = !this.value ? 'on' : this.value;\n } else {\n actualValue = null;\n }\n\n this._internals.setFormValue(actualValue);\n }\n\n private _toggleState() {\n this.checked = !this.checked;\n this.indeterminate = false;\n this._setActualFormValue();\n this._manageRequired();\n this.dispatchEvent(new Event('change', {bubbles: true}));\n }\n\n private _handleClick = (ev: MouseEvent): void => {\n ev.preventDefault();\n\n if (this.disabled) {\n return;\n }\n\n this._toggleState();\n };\n\n private _handleKeyDown = (ev: KeyboardEvent): void => {\n if (!this.disabled && (ev.key === 'Enter' || ev.key === ' ')) {\n ev.preventDefault();\n\n if (ev.key === ' ') {\n this._toggleState();\n }\n\n if (ev.key === 'Enter') {\n this._internals.form?.requestSubmit();\n }\n }\n };\n\n private _manageRequired() {\n if (!this.checked && this.required) {\n this._internals.setValidity(\n {\n valueMissing: true,\n },\n 'Please check this box if you want to proceed.',\n this._inputEl ?? undefined\n );\n } else {\n this._internals.setValidity({});\n }\n }\n\n override render(): TemplateResult {\n const iconClasses = classMap({\n icon: true,\n checked: this.checked,\n indeterminate: this.indeterminate,\n });\n const labelInnerClasses = classMap({\n 'label-inner': true,\n });\n\n const icon = html`<svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"currentColor\"\n class=\"check-icon\"\n >\n <path\n fill-rule=\"evenodd\"\n clip-rule=\"evenodd\"\n d=\"M14.431 3.323l-8.47 10-.79-.036-3.35-4.77.818-.574 2.978 4.24 8.051-9.506.764.646z\"\n />\n </svg>`;\n const check = this.checked && !this.indeterminate ? icon : nothing;\n const indeterminate = this.indeterminate\n ? html`<span class=\"indeterminate-icon\"></span>`\n : nothing;\n\n return html`\n <div class=\"wrapper\">\n <input\n ?autofocus=${this.autofocus}\n id=\"input\"\n class=\"checkbox\"\n type=\"checkbox\"\n ?checked=${this.checked}\n value=${this.value}\n >\n <div class=${iconClasses}>${indeterminate}${check}</div>\n <label for=\"input\" class=\"label\" @click=${this._handleClick}>\n <span class=${labelInnerClasses}>\n ${this._renderLabelAttribute()}\n <slot @slotchange=${this._handleSlotChange}></slot>\n </span>\n </label>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'vscode-checkbox': VscodeCheckbox;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vscode-checkbox.js","sourceRoot":"","sources":["../../src/vscode-checkbox/vscode-checkbox.ts"],"names":[],"mappings":";;;;;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AC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;+CACzB;AAGhB;IADC,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;4CACW;AAMrC;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;8CAC1B;AAUf;IADC,QAAQ,EAAE;6CACA;AAGX;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;gDACxB;AAGjB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;qDACnB;AAGtB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;8CAKxC;AAYD;IADC,QAAQ,EAAE;4CACO;AAuEV;IADP,KAAK,CAAC,QAAQ,CAAC;gDACoB;AA7JzB,cAAc;IAD1B,aAAa,CAAC,iBAAiB,CAAC;GACpB,cAAc,CAyR1B","sourcesContent":["import {html, LitElement, nothing, TemplateResult} from 'lit';\nimport {ifDefined} from 'lit/directives/if-defined.js';\nimport {property, query} from 'lit/decorators.js';\nimport {classMap} from 'lit/directives/class-map.js';\nimport {customElement} from '../includes/VscElement.js';\nimport {FormButtonWidgetBase} from '../includes/form-button-widget/FormButtonWidgetBase.js';\nimport {LabelledCheckboxOrRadioMixin} from '../includes/form-button-widget/LabelledCheckboxOrRadio.js';\nimport styles from './vscode-checkbox.styles.js';\nimport {AssociatedFormControl} from '../includes/AssociatedFormControl.js';\n\n/**\n * Allows users to select one or more options from a set. When participating in a form, it supports\n * the `:invalid` pseudo class. Otherwise the error styles can be applied through the `invalid`\n * property.\n *\n * @tag vscode-checkbox\n *\n * @attr name - Name which is used as a variable name in the data of the form-container.\n * @attr label - Attribute pair of the `label` property.\n * @prop label - Label text. It is only applied if component's innerHTML doesn't contain any text.\n *\n * @fires {Event} change - Dispatched when checked state is changed. The event is bubbled, so it can be listened on a parent element like the `CheckboxGroup`.\n * @fires {Event} invalid - Dispatched when the element is invalid and `checkValidity()` has been called or the form containing this element is submitted.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/invalid_event)\n *\n * @cssprop [--vscode-font-family=sans-serif]\n * @cssprop [--vscode-font-size=13px]\n * @cssprop [--vscode-font-weight=normal]\n * @cssprop [--vscode-foreground=#cccccc]\n * @cssprop [--vscode-settings-checkboxBackground=#313131]\n * @cssprop [--vscode-settings-checkboxBorder=#3c3c3c]\n * @cssprop [--vscode-settings-checkboxForeground=#cccccc]\n * @cssprop [--vscode-focusBorder=#0078d4]\n * @cssprop [--vscode-inputValidation-errorBackground=#5a1d1d]\n * @cssprop [--vscode-inputValidation-errorBorder=#be1100]\n */\n@customElement('vscode-checkbox')\nexport class VscodeCheckbox\n extends LabelledCheckboxOrRadioMixin(FormButtonWidgetBase)\n implements AssociatedFormControl\n{\n static override styles = styles;\n\n /** @internal */\n static formAssociated = true;\n\n /** @internal */\n static override shadowRootOptions: ShadowRootInit = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n /**\n * Automatically focus on the element when the page loads.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus)\n */\n @property({type: Boolean, reflect: true})\n override autofocus = false;\n\n @property({type: Boolean, reflect: true})\n set checked(newVal: boolean) {\n this._checked = newVal;\n this._manageRequired();\n this.requestUpdate();\n }\n get checked(): boolean {\n return this._checked;\n }\n\n private _checked = false;\n\n /**\n * The element's initial checked state, which will be restored when the containing form is reset.\n */\n @property({type: Boolean, reflect: true, attribute: 'default-checked'})\n defaultChecked = false;\n\n @property({type: Boolean, reflect: true})\n invalid = false;\n\n @property({reflect: true})\n name: string | undefined = undefined;\n\n /**\n * When true, renders as a toggle switch instead of a checkbox.\n */\n @property({type: Boolean, reflect: true})\n toggle = false;\n\n /**\n * Associate a value to the checkbox. According to the native checkbox [specification](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value_2), If the component participates in a form:\n *\n * - If it is unchecked, the value will not be submitted.\n * - If it is checked but the value is not set, `on` will be submitted.\n * - If it is checked and value is set, the value will be submitted.\n */\n @property()\n value = '';\n\n @property({type: Boolean, reflect: true})\n disabled = false;\n\n @property({type: Boolean, reflect: true})\n indeterminate = false;\n\n @property({type: Boolean, reflect: true})\n set required(newVal: boolean) {\n this._required = newVal;\n this._manageRequired();\n this.requestUpdate();\n }\n get required() {\n return this._required;\n }\n private _required = false;\n\n get form(): HTMLFormElement | null {\n return this._internals.form;\n }\n\n /** @internal */\n @property()\n type = 'checkbox';\n\n get validity(): ValidityState {\n return this._internals.validity;\n }\n\n get validationMessage(): string {\n return this._internals.validationMessage;\n }\n\n get willValidate(): boolean {\n return this._internals.willValidate;\n }\n\n /**\n * Returns `true` if the element's value is valid; otherwise, it returns `false`.\n * If the element's value is invalid, an invalid event is triggered on the element.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity)\n */\n checkValidity(): boolean {\n return this._internals.checkValidity();\n }\n\n /**\n * Returns `true` if the element's value is valid; otherwise, it returns `false`.\n * If the element's value is invalid, an invalid event is triggered on the element, and the\n * browser displays an error message to the user.\n *\n * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity)\n */\n reportValidity(): boolean {\n return this._internals.reportValidity();\n }\n\n constructor() {\n super();\n this._internals = this.attachInternals();\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n\n this.addEventListener('keydown', this._handleKeyDown);\n\n this.updateComplete.then(() => {\n this._manageRequired();\n this._setActualFormValue();\n });\n }\n\n override disconnectedCallback(): void {\n this.removeEventListener('keydown', this._handleKeyDown);\n }\n\n /** @internal */\n formResetCallback(): void {\n this.checked = this.defaultChecked;\n }\n\n /** @internal */\n formStateRestoreCallback(\n state: string,\n _mode: 'restore' | 'autocomplete'\n ): void {\n if (state) {\n this.checked = true;\n }\n }\n\n @query('#input')\n private _inputEl!: HTMLInputElement;\n\n private _internals: ElementInternals;\n\n // Sets the value of the control according to the native checkbox behavior.\n // - If the checkbox is unchecked, the value will be null, so the control will\n // excluded from the form.\n // - If the control is checked but the value is not set, the value will be \"on\".\n // - If the control is checked and value is set, the value won't be changed.\n private _setActualFormValue() {\n let actualValue: string | null = '';\n\n if (this.checked) {\n actualValue = !this.value ? 'on' : this.value;\n } else {\n actualValue = null;\n }\n\n this._internals.setFormValue(actualValue);\n }\n\n private _toggleState() {\n this.checked = !this.checked;\n this.indeterminate = false;\n this._setActualFormValue();\n this._manageRequired();\n this.dispatchEvent(new Event('change', {bubbles: true}));\n }\n\n private _handleClick = (ev: MouseEvent): void => {\n ev.preventDefault();\n\n if (this.disabled) {\n return;\n }\n\n this._toggleState();\n };\n\n private _handleKeyDown = (ev: KeyboardEvent): void => {\n if (!this.disabled && (ev.key === 'Enter' || ev.key === ' ')) {\n ev.preventDefault();\n\n if (ev.key === ' ') {\n this._toggleState();\n }\n\n if (ev.key === 'Enter') {\n this._internals.form?.requestSubmit();\n }\n }\n };\n\n private _manageRequired() {\n if (!this.checked && this.required) {\n this._internals.setValidity(\n {\n valueMissing: true,\n },\n 'Please check this box if you want to proceed.',\n this._inputEl ?? undefined\n );\n } else {\n this._internals.setValidity({});\n }\n }\n\n override render(): TemplateResult {\n const iconClasses = classMap({\n icon: true,\n checked: this.checked,\n indeterminate: this.indeterminate,\n });\n const labelInnerClasses = classMap({\n 'label-inner': true,\n });\n\n const icon = html`<svg\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n xmlns=\"http://www.w3.org/2000/svg\"\n fill=\"currentColor\"\n class=\"check-icon\"\n >\n <path\n fill-rule=\"evenodd\"\n clip-rule=\"evenodd\"\n d=\"M14.431 3.323l-8.47 10-.79-.036-3.35-4.77.818-.574 2.978 4.24 8.051-9.506.764.646z\"\n />\n </svg>`;\n const check = this.checked && !this.indeterminate ? icon : nothing;\n const indeterminate = this.indeterminate\n ? html`<span class=\"indeterminate-icon\"></span>`\n : nothing;\n\n const iconContent = this.toggle\n ? html`<span class=\"thumb\"></span>`\n : html`${indeterminate}${check}`;\n\n return html`\n <div class=\"wrapper\">\n <input\n ?autofocus=${this.autofocus}\n id=\"input\"\n class=\"checkbox\"\n type=\"checkbox\"\n ?checked=${this.checked}\n role=${ifDefined(this.toggle ? 'switch' : undefined)}\n aria-checked=${ifDefined(\n this.toggle ? (this.checked ? 'true' : 'false') : undefined\n )}\n value=${this.value}\n >\n <div class=${iconClasses}>${iconContent}</div>\n <label for=\"input\" class=\"label\" @click=${this._handleClick}>\n <span class=${labelInnerClasses}>\n ${this._renderLabelAttribute()}\n <slot @slotchange=${this._handleSlotChange}></slot>\n </span>\n </label>\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'vscode-checkbox': VscodeCheckbox;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vscode-checkbox.styles.d.ts","sourceRoot":"","sources":["../../src/vscode-checkbox/vscode-checkbox.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,cAAc,EAAC,MAAM,KAAK,CAAC;AAIxC,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"vscode-checkbox.styles.d.ts","sourceRoot":"","sources":["../../src/vscode-checkbox/vscode-checkbox.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,cAAc,EAAC,MAAM,KAAK,CAAC;AAIxC,QAAA,MAAM,MAAM,EAAE,cAiGb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -26,6 +26,77 @@ const styles = [
|
|
|
26
26
|
outline: 1px solid var(--vscode-focusBorder, #0078d4);
|
|
27
27
|
outline-offset: -1px;
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
/* Toggle appearance */
|
|
31
|
+
:host([toggle]) .icon {
|
|
32
|
+
/* Track */
|
|
33
|
+
width: 36px;
|
|
34
|
+
height: 20px;
|
|
35
|
+
border-radius: 999px;
|
|
36
|
+
background-color: var(--vscode-button-secondaryBackground, #313131);
|
|
37
|
+
border-color: var(--vscode-button-border, transparent);
|
|
38
|
+
justify-content: flex-start;
|
|
39
|
+
position: absolute;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
:host(:focus):host([toggle]):host(:not([disabled])) .icon {
|
|
43
|
+
outline-offset: 2px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* Reserve space for the wider toggle track so text doesn't overlap */
|
|
47
|
+
:host([toggle]) .label-inner {
|
|
48
|
+
padding-left: 45px; /* 36px track + 9px spacing */
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:host([toggle]) .label {
|
|
52
|
+
min-height: 20px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
:host([toggle]) .wrapper {
|
|
56
|
+
min-height: 20px;
|
|
57
|
+
line-height: 20px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:host([toggle]) .thumb {
|
|
61
|
+
/* Thumb */
|
|
62
|
+
box-sizing: border-box;
|
|
63
|
+
display: block;
|
|
64
|
+
width: 16px;
|
|
65
|
+
height: 16px;
|
|
66
|
+
border-radius: 50%;
|
|
67
|
+
background-color: var(--vscode-button-secondaryForeground, #cccccc);
|
|
68
|
+
margin-left: 1px;
|
|
69
|
+
transition: transform 120ms ease-in-out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
:host([toggle][checked]) .icon {
|
|
73
|
+
background-color: var(--vscode-button-background, #04395e);
|
|
74
|
+
border-color: var(--vscode-button-border, transparent);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
:host([toggle][checked]) .thumb {
|
|
78
|
+
transform: translateX(16px);
|
|
79
|
+
background-color: var(--vscode-button-foreground, #ffffff);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
:host([toggle]):host(:invalid) .icon {
|
|
83
|
+
background-color: var(--vscode-inputValidation-errorBackground, #5a1d1d);
|
|
84
|
+
border-color: var(--vscode-inputValidation-errorBorder, #be1100);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:host([toggle]):host(:invalid) .thumb {
|
|
88
|
+
background-color: var(--vscode-inputValidation-errorBorder, #be1100);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:host([toggle]) .check-icon,
|
|
92
|
+
:host([toggle]) .indeterminate-icon {
|
|
93
|
+
display: none;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
:host([toggle]:focus):host(:not([disabled])) .icon {
|
|
97
|
+
outline: 1px solid var(--vscode-focusBorder, #0078d4);
|
|
98
|
+
outline-offset: -1px;
|
|
99
|
+
}
|
|
29
100
|
`,
|
|
30
101
|
];
|
|
31
102
|
export default styles;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vscode-checkbox.styles.js","sourceRoot":"","sources":["../../src/vscode-checkbox/vscode-checkbox.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAiB,MAAM,KAAK,CAAC;AACxC,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,UAAU,MAAM,+CAA+C,CAAC;AAEvE,MAAM,MAAM,GAAmB;IAC7B,aAAa;IACb,UAAU;IACV,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"vscode-checkbox.styles.js","sourceRoot":"","sources":["../../src/vscode-checkbox/vscode-checkbox.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAiB,MAAM,KAAK,CAAC;AACxC,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,UAAU,MAAM,+CAA+C,CAAC;AAEvE,MAAM,MAAM,GAAmB;IAC7B,aAAa;IACb,UAAU;IACV,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6FF;CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import {css, CSSResultGroup} from 'lit';\nimport defaultStyles from '../includes/default.styles.js';\nimport baseStyles from '../includes/form-button-widget/base.styles.js';\n\nconst styles: CSSResultGroup = [\n defaultStyles,\n baseStyles,\n css`\n :host(:invalid) .icon,\n :host([invalid]) .icon {\n background-color: var(--vscode-inputValidation-errorBackground, #5a1d1d);\n border-color: var(--vscode-inputValidation-errorBorder, #be1100);\n }\n\n .icon {\n border-radius: 3px;\n }\n\n .indeterminate-icon {\n background-color: currentColor;\n position: absolute;\n height: 1px;\n width: 12px;\n }\n\n :host(:focus):host(:not([disabled])) .icon {\n outline: 1px solid var(--vscode-focusBorder, #0078d4);\n outline-offset: -1px;\n }\n\n /* Toggle appearance */\n :host([toggle]) .icon {\n /* Track */\n width: 36px;\n height: 20px;\n border-radius: 999px;\n background-color: var(--vscode-button-secondaryBackground, #313131);\n border-color: var(--vscode-button-border, transparent);\n justify-content: flex-start;\n position: absolute;\n }\n\n :host(:focus):host([toggle]):host(:not([disabled])) .icon {\n outline-offset: 2px;\n }\n\n /* Reserve space for the wider toggle track so text doesn't overlap */\n :host([toggle]) .label-inner {\n padding-left: 45px; /* 36px track + 9px spacing */\n }\n\n :host([toggle]) .label {\n min-height: 20px;\n }\n\n :host([toggle]) .wrapper {\n min-height: 20px;\n line-height: 20px;\n }\n\n :host([toggle]) .thumb {\n /* Thumb */\n box-sizing: border-box;\n display: block;\n width: 16px;\n height: 16px;\n border-radius: 50%;\n background-color: var(--vscode-button-secondaryForeground, #cccccc);\n margin-left: 1px;\n transition: transform 120ms ease-in-out;\n }\n\n :host([toggle][checked]) .icon {\n background-color: var(--vscode-button-background, #04395e);\n border-color: var(--vscode-button-border, transparent);\n }\n\n :host([toggle][checked]) .thumb {\n transform: translateX(16px);\n background-color: var(--vscode-button-foreground, #ffffff);\n }\n\n :host([toggle]):host(:invalid) .icon {\n background-color: var(--vscode-inputValidation-errorBackground, #5a1d1d);\n border-color: var(--vscode-inputValidation-errorBorder, #be1100);\n }\n\n :host([toggle]):host(:invalid) .thumb {\n background-color: var(--vscode-inputValidation-errorBorder, #be1100);\n }\n\n :host([toggle]) .check-icon,\n :host([toggle]) .indeterminate-icon {\n display: none;\n }\n\n :host([toggle]:focus):host(:not([disabled])) .icon {\n outline: 1px solid var(--vscode-focusBorder, #0078d4);\n outline-offset: -1px;\n }\n `,\n];\n\nexport default styles;\n"]}
|
package/package.json
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/microsoft/vscode-css-languageservice/main/docs/customData.schema.json",
|
|
3
3
|
"version": 1.1,
|
|
4
4
|
"properties": [
|
|
5
|
+
{ "name": "--vscode-button-background", "values": [] },
|
|
6
|
+
{ "name": "--vscode-button-foreground", "values": [] },
|
|
7
|
+
{ "name": "--vscode-button-border", "values": [] },
|
|
8
|
+
{ "name": "--vscode-button-hoverBackground", "values": [] },
|
|
9
|
+
{
|
|
10
|
+
"name": "--vscode-font-family",
|
|
11
|
+
"description": "A sans-serif font type depends on the host OS.",
|
|
12
|
+
"values": []
|
|
13
|
+
},
|
|
14
|
+
{ "name": "--vscode-font-size", "values": [] },
|
|
15
|
+
{ "name": "--vscode-font-weight", "values": [] },
|
|
16
|
+
{ "name": "--vscode-button-secondaryForeground", "values": [] },
|
|
17
|
+
{ "name": "--vscode-button-secondaryBackground", "values": [] },
|
|
18
|
+
{ "name": "--vscode-button-secondaryHoverBackground", "values": [] },
|
|
19
|
+
{ "name": "--vscode-focusBorder", "values": [] },
|
|
5
20
|
{
|
|
6
21
|
"name": "--vscode-font-family",
|
|
7
22
|
"description": "A sans-serif font type depends on the host OS.",
|
|
@@ -43,21 +58,6 @@
|
|
|
43
58
|
{ "name": "--vscode-button-secondaryBackground", "values": [] },
|
|
44
59
|
{ "name": "--vscode-button-secondaryHoverBackground", "values": [] },
|
|
45
60
|
{ "name": "--vscode-focusBorder", "values": [] },
|
|
46
|
-
{ "name": "--vscode-button-background", "values": [] },
|
|
47
|
-
{ "name": "--vscode-button-foreground", "values": [] },
|
|
48
|
-
{ "name": "--vscode-button-border", "values": [] },
|
|
49
|
-
{ "name": "--vscode-button-hoverBackground", "values": [] },
|
|
50
|
-
{
|
|
51
|
-
"name": "--vscode-font-family",
|
|
52
|
-
"description": "A sans-serif font type depends on the host OS.",
|
|
53
|
-
"values": []
|
|
54
|
-
},
|
|
55
|
-
{ "name": "--vscode-font-size", "values": [] },
|
|
56
|
-
{ "name": "--vscode-font-weight", "values": [] },
|
|
57
|
-
{ "name": "--vscode-button-secondaryForeground", "values": [] },
|
|
58
|
-
{ "name": "--vscode-button-secondaryBackground", "values": [] },
|
|
59
|
-
{ "name": "--vscode-button-secondaryHoverBackground", "values": [] },
|
|
60
|
-
{ "name": "--vscode-focusBorder", "values": [] },
|
|
61
61
|
{ "name": "--vscode-font-family", "values": [] },
|
|
62
62
|
{ "name": "--vscode-font-size", "values": [] },
|
|
63
63
|
{ "name": "--vscode-font-weight", "values": [] },
|
|
@@ -283,6 +283,10 @@
|
|
|
283
283
|
{ "name": "--vscode-tree-indentGuidesStroke", "values": [] }
|
|
284
284
|
],
|
|
285
285
|
"pseudoElements": [
|
|
286
|
+
{
|
|
287
|
+
"name": "::part(base)",
|
|
288
|
+
"description": "The main content area of the component."
|
|
289
|
+
},
|
|
286
290
|
{
|
|
287
291
|
"name": "::part(body)",
|
|
288
292
|
"description": "Container for the toggleable content of the component. The container's overflow content is hidden by default. This CSS part can serve as an escape hatch to modify this behavior."
|
|
@@ -2,26 +2,9 @@
|
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/microsoft/vscode-html-languageservice/main/docs/customData.schema.json",
|
|
3
3
|
"version": 1.1,
|
|
4
4
|
"tags": [
|
|
5
|
-
{
|
|
6
|
-
"name": "vscode-badge",
|
|
7
|
-
"description": "Show counts or status information. Badges can also be used within [Textfield](https://vscode-elements.github.io/components/textfield) and [TabHeader](https://vscode-elements.github.io/components/tabs) components.\n---\n\n\n### **CSS Properties:**\n - **--vscode-font-family** - A sans-serif font type depends on the host OS. _(default: sans-serif)_\n- **--vscode-contrastBorder** - undefined _(default: transparent)_\n- **--vscode-badge-background** - default and counter variant background color _(default: #616161)_\n- **--vscode-badge-foreground** - default and counter variant foreground color _(default: #f8f8f8)_\n- **--vscode-activityBarBadge-background** - activity bar variant background color _(default: #0078d4)_\n- **--vscode-activityBarBadge-foreground** - activity bar variant foreground color _(default: #ffffff)_",
|
|
8
|
-
"attributes": [
|
|
9
|
-
{
|
|
10
|
-
"name": "variant",
|
|
11
|
-
"values": [
|
|
12
|
-
{ "name": "" },
|
|
13
|
-
{ "name": "default" },
|
|
14
|
-
{ "name": "counter" },
|
|
15
|
-
{ "name": "activity-bar-counter" },
|
|
16
|
-
{ "name": "tab-header-counter" }
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"references": []
|
|
21
|
-
},
|
|
22
5
|
{
|
|
23
6
|
"name": "vscode-button",
|
|
24
|
-
"description": "Clickable element that are used to trigger actions.\n---\n\n\n### **CSS Properties:**\n - **--vscode-button-background** - undefined _(default: #0078d4)_\n- **--vscode-button-foreground** - undefined _(default: #ffffff)_\n- **--vscode-button-border** - undefined _(default: var(--vscode-button-background, rgba(255, 255, 255, 0.07)))_\n- **--vscode-button-hoverBackground** - undefined _(default: #026ec1)_\n- **--vscode-font-family** - A sans-serif font type depends on the host OS. _(default: sans-serif)_\n- **--vscode-font-size** - undefined _(default: 13px)_\n- **--vscode-font-weight** - undefined _(default: normal)_\n- **--vscode-button-secondaryForeground** - undefined _(default: #cccccc)_\n- **--vscode-button-secondaryBackground** - undefined _(default: #313131)_\n- **--vscode-button-secondaryHoverBackground** - undefined _(default: #3c3c3c)_\n- **--vscode-focusBorder** - undefined _(default: #0078d4)_",
|
|
7
|
+
"description": "Clickable element that are used to trigger actions.\n---\n\n\n### **Slots:**\n - **content-before** - Slot before the main content.\n- **content-after** - Slot after the main content.\n\n### **CSS Properties:**\n - **--vscode-button-background** - undefined _(default: #0078d4)_\n- **--vscode-button-foreground** - undefined _(default: #ffffff)_\n- **--vscode-button-border** - undefined _(default: var(--vscode-button-background, rgba(255, 255, 255, 0.07)))_\n- **--vscode-button-hoverBackground** - undefined _(default: #026ec1)_\n- **--vscode-font-family** - A sans-serif font type depends on the host OS. _(default: sans-serif)_\n- **--vscode-font-size** - undefined _(default: 13px)_\n- **--vscode-font-weight** - undefined _(default: normal)_\n- **--vscode-button-secondaryForeground** - undefined _(default: #cccccc)_\n- **--vscode-button-secondaryBackground** - undefined _(default: #313131)_\n- **--vscode-button-secondaryHoverBackground** - undefined _(default: #3c3c3c)_\n- **--vscode-focusBorder** - undefined _(default: #0078d4)_\n\n### **CSS Parts:**\n - **base** - The main content area of the component.",
|
|
25
8
|
"attributes": [
|
|
26
9
|
{ "name": "autofocus", "values": [] },
|
|
27
10
|
{
|
|
@@ -75,6 +58,23 @@
|
|
|
75
58
|
],
|
|
76
59
|
"references": []
|
|
77
60
|
},
|
|
61
|
+
{
|
|
62
|
+
"name": "vscode-badge",
|
|
63
|
+
"description": "Show counts or status information. Badges can also be used within [Textfield](https://vscode-elements.github.io/components/textfield) and [TabHeader](https://vscode-elements.github.io/components/tabs) components.\n---\n\n\n### **CSS Properties:**\n - **--vscode-font-family** - A sans-serif font type depends on the host OS. _(default: sans-serif)_\n- **--vscode-contrastBorder** - undefined _(default: transparent)_\n- **--vscode-badge-background** - default and counter variant background color _(default: #616161)_\n- **--vscode-badge-foreground** - default and counter variant foreground color _(default: #f8f8f8)_\n- **--vscode-activityBarBadge-background** - activity bar variant background color _(default: #0078d4)_\n- **--vscode-activityBarBadge-foreground** - activity bar variant foreground color _(default: #ffffff)_",
|
|
64
|
+
"attributes": [
|
|
65
|
+
{
|
|
66
|
+
"name": "variant",
|
|
67
|
+
"values": [
|
|
68
|
+
{ "name": "" },
|
|
69
|
+
{ "name": "default" },
|
|
70
|
+
{ "name": "counter" },
|
|
71
|
+
{ "name": "activity-bar-counter" },
|
|
72
|
+
{ "name": "tab-header-counter" }
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"references": []
|
|
77
|
+
},
|
|
78
78
|
{
|
|
79
79
|
"name": "vscode-button-group",
|
|
80
80
|
"description": "Shows a split button, including several components in a single button. Commonly used to show a button with a dropdown to the right.\n---\n\n\n### **CSS Properties:**\n - **--vscode-button-background** - undefined _(default: #0078d4)_\n- **--vscode-button-foreground** - undefined _(default: #ffffff)_\n- **--vscode-button-border** - undefined _(default: var(--vscode-button-background, rgba(255, 255, 255, 0.07)))_\n- **--vscode-button-hoverBackground** - undefined _(default: #026ec1)_\n- **--vscode-font-family** - A sans-serif font type depends on the host OS. _(default: sans-serif)_\n- **--vscode-font-size** - undefined _(default: 13px)_\n- **--vscode-font-weight** - undefined _(default: normal)_\n- **--vscode-button-secondaryForeground** - undefined _(default: #cccccc)_\n- **--vscode-button-secondaryBackground** - undefined _(default: #313131)_\n- **--vscode-button-secondaryHoverBackground** - undefined _(default: #3c3c3c)_\n- **--vscode-focusBorder** - undefined _(default: #0078d4)_",
|
|
@@ -107,6 +107,11 @@
|
|
|
107
107
|
"values": []
|
|
108
108
|
},
|
|
109
109
|
{ "name": "invalid", "values": [] },
|
|
110
|
+
{
|
|
111
|
+
"name": "toggle",
|
|
112
|
+
"description": "When true, renders as a toggle switch instead of a checkbox.",
|
|
113
|
+
"values": []
|
|
114
|
+
},
|
|
110
115
|
{
|
|
111
116
|
"name": "value",
|
|
112
117
|
"description": "Associate a value to the checkbox. According to the native checkbox [specification](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value_2), If the component participates in a form:\n\n- If it is unchecked, the value will not be submitted.\n- If it is checked but the value is not set, `on` will be submitted.\n- If it is checked and value is set, the value will be submitted.",
|