diff --git a/packages/main/src/CheckBox.hbs b/packages/main/src/CheckBox.hbs index 442b95cf0409..31cf806c3604 100644 --- a/packages/main/src/CheckBox.hbs +++ b/packages/main/src/CheckBox.hbs @@ -1,14 +1,14 @@
indeterminate
- * and checked
properties:
- * Warning
Error
None
(default)Success
Information
None
- The text will be truncated with an ellipsis.Normal
- The text will wrap. The words will not be broken based on hyphenation.name
property to have effect, you must add the following import to your project:
- * import "@ui5/webcomponents/dist/features/InputElementsFormSupport.js";
- *
- * input
HTML element
- * will be created inside the component so that it can be submitted as
- * part of an HTML form. Do not use this property unless you need to submit a form.
- *
- * @type {string}
- * @defaultvalue ""
- * @public
- */
- name: {
- type: String,
- },
-
- /**
- * Defines the active state (pressed or not) of the component.
- * @private
- */
- active: {
- type: Boolean,
- },
- },
- events: /** @lends sap.ui.webc.main.CheckBox.prototype */ {
-
- /**
- * Fired when the component checked state changes.
- *
- * @public
- * @event
- */
- change: {},
- },
- slots: /** @lends sap.ui.webc.main.CheckBox.prototype */ {
- /**
- * The slot is used to render native input
HTML element within Light DOM to enable form submit,
- * when name
property is set.
- * @type {HTMLElement[]}
- * @slot
- * @private
- */
- formSupport: {
- type: HTMLElement,
- },
- },
-};
-
-/**
- * @class
- *
- * ui5-checkbox
component consists of a box and a label that describes its purpose.
- * If it's checked, an indicator is displayed inside the box.
- * To check/uncheck the ui5-checkbox
, the user has to click or tap the square
- * box or its label.
- * ui5-checkbox
component only has 2 states - checked and unchecked.
- * Clicking or tapping toggles the ui5-checkbox
between checked and unchecked state.
- *
- * text
property. If the text exceeds the available width, it is truncated by default.
- * In case you prefer text to wrap, set the wrappingType
property to "Normal".
- * The touchable area for toggling the ui5-checkbox
ends where the text ends.
- * ui5-checkbox
by setting the disabled
property to
- * true
,
- * or use the ui5-checkbox
in read-only mode by setting the readonly
- * property to true
.
- *
- * ui5-checkbox
.
- * import "@ui5/webcomponents/dist/CheckBox";
- *
- * @constructor
- * @author SAP SE
- * @alias sap.ui.webc.main.CheckBox
- * @extends sap.ui.webc.base.UI5Element
- * @tagname ui5-checkbox
- * @public
- */
-class CheckBox extends UI5Element {
- static get metadata() {
- return metadata;
- }
-
- static get render() {
- return litRender;
- }
-
- static get template() {
- return CheckBoxTemplate;
- }
-
- static get styles() {
- return checkboxCss;
- }
-
- constructor() {
- super();
-
- this._deactivate = () => {
- if (activeCb) {
- activeCb.active = false;
- }
- };
-
- if (!isGlobalHandlerAttached) {
- document.addEventListener("mouseup", this._deactivate);
- isGlobalHandlerAttached = true;
- }
- }
-
- onBeforeRendering() {
- this._enableFormSupport();
- }
-
- _enableFormSupport() {
- const FormSupport = getFeature("FormSupport");
- if (FormSupport) {
- FormSupport.syncNativeHiddenInput(this, (element, nativeInput) => {
- nativeInput.disabled = element.disabled || !element.checked;
- nativeInput.value = element.checked ? "on" : "";
- });
- } else if (this.name) {
- console.warn(`In order for the "name" property to have effect, you should also: import "@ui5/webcomponents/dist/features/InputElementsFormSupport.js";`); // eslint-disable-line
- }
- }
-
- _onclick() {
- this.toggle();
- }
-
- _onmousedown() {
- if (this.readonly || this.disabled) {
- return;
- }
-
- this.active = true;
- activeCb = this; // eslint-disable-line
- }
-
- _onmouseup() {
- this.active = false;
- }
-
- _onfocusout() {
- this.active = false;
- }
-
- _onkeydown(event) {
- if (isSpace(event)) {
- event.preventDefault();
- this.active = true;
- }
-
- if (isEnter(event)) {
- this.toggle();
- this.active = true;
- }
- }
-
- _onkeyup(event) {
- if (isSpace(event)) {
- this.toggle();
- }
-
- this.active = false;
- }
-
- toggle() {
- if (this.canToggle()) {
- if (this.indeterminate) {
- this.indeterminate = false;
- this.checked = true;
- } else {
- this.checked = !this.checked;
- }
-
- this.fireEvent("change");
- // Angular two way data binding
- this.fireEvent("value-changed");
- }
- return this;
- }
-
- canToggle() {
- return !(this.disabled || this.readonly);
- }
-
- valueStateTextMappings() {
- return {
- "Error": CheckBox.i18nBundle.getText(VALUE_STATE_ERROR),
- "Warning": CheckBox.i18nBundle.getText(VALUE_STATE_WARNING),
- "Success": CheckBox.i18nBundle.getText(VALUE_STATE_SUCCESS),
- };
- }
-
- get ariaLabelText() {
- return getEffectiveAriaLabelText(this);
- }
-
- get classes() {
- return {
- main: {
- "ui5-checkbox--hoverable": !this.disabled && !this.readonly && isDesktop(),
- },
- };
- }
-
- get ariaReadonly() {
- return this.readonly ? "true" : undefined;
- }
-
- get ariaDisabled() {
- return this.disabled ? "true" : undefined;
- }
-
- get ariaChecked() {
- return this.indeterminate && this.checked ? "mixed" : this.checked;
- }
-
- get ariaLabelledBy() {
- if (!this.ariaLabelText) {
- return this.text ? `${this._id}-label` : undefined;
- }
-
- return undefined;
- }
-
- get ariaDescribedBy() {
- return this.hasValueState ? `${this._id}-descr` : undefined;
- }
-
- get hasValueState() {
- return this.valueState !== ValueState.None;
- }
-
- get valueStateText() {
- return this.valueStateTextMappings()[this.valueState];
- }
-
- get tabIndex() {
- const tabindex = this.getAttribute("tabindex");
- return this.disabled ? undefined : tabindex || "0";
- }
-
- get isCompletelyChecked() {
- return this.checked && !this.indeterminate;
- }
-
- static get dependencies() {
- return [
- Label,
- Icon,
- ];
- }
-
- static async onDefine() {
- CheckBox.i18nBundle = await getI18nBundle("@ui5/webcomponents");
- }
-}
-
-CheckBox.define();
-
-export default CheckBox;
diff --git a/packages/main/src/CheckBox.ts b/packages/main/src/CheckBox.ts
new file mode 100644
index 000000000000..ead2c4125fb7
--- /dev/null
+++ b/packages/main/src/CheckBox.ts
@@ -0,0 +1,466 @@
+import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
+import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
+import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
+import languageAware from "@ui5/webcomponents-base/dist/decorators/languageAware.js";
+import property from "@ui5/webcomponents-base/dist/decorators/property.js";
+import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
+import event from "@ui5/webcomponents-base/dist/decorators/event.js";
+import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
+import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
+import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
+import type { I18nText } from "@ui5/webcomponents-base/dist/i18nBundle.js";
+import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
+import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
+import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
+import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
+import "@ui5/webcomponents-icons/dist/accept.js";
+import Icon from "./Icon.js";
+import Label from "./Label.js";
+import WrappingType from "./types/WrappingType.js";
+import {
+ VALUE_STATE_ERROR,
+ VALUE_STATE_WARNING,
+ VALUE_STATE_SUCCESS,
+ // @ts-ignore
+} from "./generated/i18n/i18n-defaults.js";
+
+// Styles
+import checkboxCss from "./generated/themes/CheckBox.css.js";
+import type FormSupport from "./features/InputElementsFormSupport.js";
+import type { IFormElement } from "./features/InputElementsFormSupport.js";
+
+// Template
+import CheckBoxTemplate from "./generated/templates/CheckBoxTemplate.lit.js";
+
+let isGlobalHandlerAttached = false;
+let activeCb: CheckBox;
+
+/**
+ * @class
+ *
+ * ui5-checkbox
component consists of a box and a label that describes its purpose.
+ * If it's checked, an indicator is displayed inside the box.
+ * To check/uncheck the ui5-checkbox
, the user has to click or tap the square
+ * box or its label.
+ * ui5-checkbox
component only has 2 states - checked and unchecked.
+ * Clicking or tapping toggles the ui5-checkbox
between checked and unchecked state.
+ *
+ * text
property. If the text exceeds the available width, it is truncated by default.
+ * In case you prefer text to wrap, set the wrappingType
property to "Normal".
+ * The touchable area for toggling the ui5-checkbox
ends where the text ends.
+ * ui5-checkbox
by setting the disabled
property to
+ * true
,
+ * or use the ui5-checkbox
in read-only mode by setting the readonly
+ * property to true
.
+ *
+ * ui5-checkbox
.
+ * import "@ui5/webcomponents/dist/CheckBox";
+ *
+ * @constructor
+ * @author SAP SE
+ * @alias sap.ui.webc.main.CheckBox
+ * @extends sap.ui.webc.base.UI5Element
+ * @tagname ui5-checkbox
+ * @public
+ */
+@customElement("ui5-checkbox")
+@languageAware
+/**
+ * Fired when the component checked state changes.
+ *
+ * @public
+ * @event sap.ui.webc.main.CheckBox#change
+ */
+@event("change")
+
+class CheckBox extends UI5Element implements IFormElement {
+ /**
+ * Receives id(or many ids) of the elements that label the component
+ * @type {string}
+ * @defaultvalue ""
+ * @name sap.ui.webc.main.CheckBox.prototype.accessibleNameRef
+ * @public
+ * @since 1.1.0
+ */
+ @property()
+ accessibleNameRef!: string;
+
+ /**
+ * Defines the accessible ARIA name of the component.
+ *
+ * @type {string}
+ * @public
+ * @name sap.ui.webc.main.CheckBox.prototype.accessibleName
+ * @defaultvalue ""
+ * @since 1.1.0
+ */
+ @property()
+ accessibleName!: string;
+
+ /**
+ * Defines whether the component is disabled.
+ * indeterminate
+ * and checked
properties:
+ * Warning
Error
None
(default)Success
Information
None
- The text will be truncated with an ellipsis.Normal
- The text will wrap. The words will not be broken based on hyphenation.name
property to have effect, you must add the following import to your project:
+ * import "@ui5/webcomponents/dist/features/InputElementsFormSupport.js";
+ *
+ * input
HTML element
+ * will be created inside the component so that it can be submitted as
+ * part of an HTML form. Do not use this property unless you need to submit a form.
+ *
+ * @type {string}
+ * @name sap.ui.webc.main.CheckBox.prototype.name
+ * @defaultvalue ""
+ * @public
+ */
+ @property()
+ name!: string;
+
+ /**
+ * Defines the active state (pressed or not) of the component.
+ * @private
+ */
+ @property({ type: Boolean })
+ active!: boolean;
+
+ /**
+ * The slot is used to render native input
HTML element within Light DOM to enable form submit,
+ * when name
property is set.
+ * @type {HTMLElement[]}
+ * @slot
+ * @private
+ */
+ @slot()
+ formSupport!: Array