@kelvininc/ui-components
Version:
Kelvin UI Components
271 lines (270 loc) • 10.6 kB
JavaScript
import { h } from "@stencil/core";
import { EIconName } from "../icon/icon.types";
import { EActionButtonType } from "../action-button/action-button.types";
import { EComponentSize } from "../../types";
import { isEmpty } from "lodash-es";
/**
* @part create-button - The create action button element.
* @part cancel-button - The cancel action button element.
* @part text-field - The text field element.
*/
export class KvSelectCreateOption {
constructor() {
/** @inheritdoc */
this.value = '';
/** @inheritdoc */
this.disabled = false;
/** @inheritdoc */
this.size = EComponentSize.Small;
/** @inheritdoc */
this.inputConfig = {};
this.onKeyPress = (event) => {
if (event.key === 'Enter') {
this.onCreate();
}
};
this.onCreate = () => {
if (!this.canSubmit) {
return;
}
this.clickCreate.emit();
};
this.onCancel = () => {
this.clickCancel.emit();
};
}
/** Focus the input */
async focusInput() {
this.input.focus();
}
/** Blur the input */
async blurInput() {
this.input.blur();
}
get canSubmit() {
return !isEmpty(this.value) && !this.disabled;
}
componentDidLoad() {
this.input.focusInput();
}
render() {
return (h("div", { key: 'c8ccebfa424bcf032d5dab34ed1b32ba2ca541f7', class: "select-create-option" }, h("div", { key: '3d38f0ac952e6616361311bfe818494a5b4f881e', class: "form" }, h("kv-text-field", Object.assign({ key: 'e90e6969aa10f7b94e52b60336dac224d9258522', ref: element => (this.input = element), inputDisabled: this.disabled, size: this.size, value: this.value }, this.inputConfig, { onKeyPress: this.onKeyPress, onTextChange: ({ detail: newValue }) => this.valueChanged.emit(newValue), part: "text-field" }))), h("div", { key: '0832568dbd3c07c40fb0940f6d0db20482c782dc', class: "actions" }, h("kv-action-button-icon", { key: 'd0a109b2282462d0daa18cf3f3a3c610fd714904', type: EActionButtonType.Tertiary, icon: EIconName.Close, size: this.size, onClickButton: this.onCancel, part: "cancel-button" }), h("kv-action-button-icon", { key: 'd106162544014b86468c070ac2381a295157c7e2', type: EActionButtonType.Primary, icon: EIconName.DoneAll, size: this.size, disabled: !this.canSubmit, onClickButton: this.onCreate, part: "create-button" }))));
}
static get is() { return "kv-select-create-option"; }
static get originalStyleUrls() {
return {
"$": ["select-create-option.scss"]
};
}
static get styleUrls() {
return {
"$": ["select-create-option.css"]
};
}
static get properties() {
return {
"value": {
"type": "string",
"attribute": "value",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) The new option value."
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "''"
},
"disabled": {
"type": "boolean",
"attribute": "disabled",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) If `true` the input and actions will be disabled. Default: `false`."
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "false"
},
"size": {
"type": "string",
"attribute": "size",
"mutable": false,
"complexType": {
"original": "EComponentSize",
"resolved": "EComponentSize.Large | EComponentSize.Small",
"references": {
"EComponentSize": {
"location": "import",
"path": "../../types",
"id": "src/types.ts::EComponentSize"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) The input and actions size. Default: `small\u00B4"
},
"getter": false,
"setter": false,
"reflect": true,
"defaultValue": "EComponentSize.Small"
},
"inputConfig": {
"type": "unknown",
"attribute": "input-config",
"mutable": false,
"complexType": {
"original": "Partial<ITextField>",
"resolved": "{ type?: EInputFieldType; label?: string; icon?: EIconName; actionIcon?: EIconName; inputName?: string; examples?: string[]; placeholder?: string; maxLength?: number; minLength?: number; max?: string | number; min?: string | number; step?: string | number; size?: EComponentSize; inputDisabled?: boolean; inputRequired?: boolean; loading?: boolean; state?: EValidationState; helpText?: string | string[]; value?: string | number; valuePrefix?: string; badge?: string; inputReadonly?: boolean; forcedFocus?: boolean; tooltipConfig?: Partial<ITooltip>; useInputMask?: boolean; inputMaskRegex?: string; fitContent?: boolean; customStyle?: { [key: string]: string; }; isDirty?: boolean; }",
"references": {
"Partial": {
"location": "global",
"id": "global::Partial"
},
"ITextField": {
"location": "import",
"path": "../../types",
"id": "src/types.ts::ITextField"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "(optional) The text field custom config."
},
"getter": false,
"setter": false,
"defaultValue": "{}"
}
};
}
static get events() {
return [{
"method": "clickCreate",
"name": "clickCreate",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "Emitted when the create button is pressed"
},
"complexType": {
"original": "void",
"resolved": "void",
"references": {}
}
}, {
"method": "clickCancel",
"name": "clickCancel",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "Emitted when the cancel button is pressed"
},
"complexType": {
"original": "void",
"resolved": "void",
"references": {}
}
}, {
"method": "valueChanged",
"name": "valueChanged",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [{
"name": "inheritdoc",
"text": undefined
}],
"text": "Emitted when the value changes"
},
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
}
}];
}
static get methods() {
return {
"focusInput": {
"complexType": {
"signature": "() => Promise<void>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "Focus the input",
"tags": []
}
},
"blurInput": {
"complexType": {
"signature": "() => Promise<void>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "Blur the input",
"tags": []
}
}
};
}
}