@duetds/components
Version:
This package includes Duet Components and related tools.
94 lines (89 loc) • 7.88 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const __chunk_1 = require('./chunk-7888512a.js');
const __chunk_3 = require('./chunk-af70acd5.js');
const __chunk_4 = require('./chunk-ed4aae81.js');
const __chunk_5 = require('./chunk-4d3bde67.js');
class DuetInput {
constructor(hostRef) {
__chunk_1.registerInstance(this, hostRef);
/**
* Theme of the input. Can be one of: default, turva.
*/
this.theme = "";
/**
* Expands the input to fill 100% of the container width.
*/
this.expand = false;
/**
* Makes the input component disabled. This prevents users from being able to interact with the input, and conveys its inactive state to assistive technologies.
*/
this.disabled = false;
/**
* Automatically focus the input.
*/
this.autofocus = false;
/**
* Set whether the input is required or not.
*/
this.required = false;
/**
* Type of the input. Can be one of: text, email, number, password, search, tel, time.
*/
this.type = "text";
/**
* Label for the input.
*/
this.label = "label";
/**
* Visually hide the label, but still show it to screen readers.
*/
this.labelHidden = false;
/**
* Indicate whether value should have spelling checked
*/
this.spellCheck = false;
/**
* Enable or disable automatic completion by the browser
*/
this.autoComplete = "on";
}
/**
* Component lifecycle events.
*/
componentWillLoad() {
// Check whether global Turva theme is active
if (this.theme !== "default" && document.documentElement.classList.contains("duet-theme-turva")) {
this.theme = "turva";
}
}
/**
* render() function
* Always the last one in the class.
*/
render() {
// Set constants for input classes used.
if (this.expand) {
this.element.classList.add("duet-expand");
}
const containerClasses = __chunk_3.classNames("duet-input-container", {
"duet-theme-turva": this.theme === "turva",
"duet-label-hidden": this.labelHidden,
"has-icon": this.type !== "text" && this.type !== "number" && this.type !== "password",
});
const inputClasses = __chunk_3.classNames("duet-input", {
disabled: this.disabled,
});
const identifier = this.identifier || __chunk_5.createUniqueID("DuetCheckbox");
// Set validation regexes
let regexType = false;
if (this.type === "tel") {
regexType = "[0-9+ ]+";
}
const regex = this.pattern ? this.pattern : regexType;
return (__chunk_1.h("div", { class: containerClasses }, __chunk_1.h("label", { class: "duet-label", htmlFor: identifier }, this.label), __chunk_1.h("input", { type: this.type, class: inputClasses, value: this.value, autofocus: this.autofocus, disabled: this.disabled, "label-hidden": this.labelHidden, "aria-controls": this.accessibleControls, "aria-autocomplete": this.accessibleAutocomplete, "aria-active-descendant": this.accessibleActiveDescendant, "aria-owns": this.accessibleOwns, maxlength: this.maxLength, minlength: this.minLength, pattern: regex, placeholder: this.placeholder, spellcheck: this.spellCheck, autocomplete: this.autoComplete, required: this.required, role: this.role, name: this.name, id: identifier }), this.type !== "text" && this.type !== "number" && this.type !== "password" ? (__chunk_1.h("div", { class: "duet-input-icon", innerHTML: __chunk_4.duetIcons["form-" + this.type].svg })) : (""), __chunk_1.h("span", { class: "duet-input-help" }, this.helpText)));
}
get element() { return __chunk_1.getElement(this); }
static get style() { return ":host{background:transparent;margin:0;margin-right:8px;margin-bottom:12px;display:-ms-inline-flexbox;display:inline-flex;vertical-align:bottom;max-width:100%}.duet-label,:host{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box;border:0;padding:0}.duet-label{background:transparent;margin:0;margin-bottom:8px;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:localtapiola-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;font-size:1rem;background:#fff;color:#00294d;font-weight:600;line-height:1.25;-webkit-transition:.3s ease;transition:.3s ease;z-index:100;width:100%;cursor:pointer;position:relative;display:block}.duet-theme-turva .duet-label{color:#111;font-family:turva-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}.duet-label-hidden .duet-label{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.duet-input-icon{pointer-events:none;z-index:200;width:20px;height:20px;color:#00294d;position:absolute;bottom:16px;right:16px}.duet-theme-turva .duet-input-icon{color:#c60c30}.duet-input{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box;background:transparent;border:0;padding:0;margin:0;padding:13.5px;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:localtapiola-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;border:2px solid #cfd2d4;border-radius:4px;font-size:1rem;background:#fff;color:#00294d;font-weight:400;line-height:1.25;-webkit-transition:.3s ease;transition:.3s ease;z-index:100;min-width:13.75rem;width:100%;position:relative;display:block}.has-icon .duet-input{padding-right:48px}.duet-theme-turva .duet-input{font-family:turva-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;border-color:#d1d1d1;color:#111}.duet-input-container{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box;background:transparent;border:0;padding:0;margin:0;position:relative;width:100%;height:100%}.duet-input::-webkit-input-placeholder{color:#cfd2d4}.duet-theme-turva .duet-input::-webkit-input-placeholder{color:#d1d1d1}.duet-input::-moz-placeholder{color:#cfd2d4;opacity:1!important}.duet-theme-turva .duet-input::-moz-placeholder{color:#d1d1d1}.duet-input:-ms-input-placeholder{color:#cfd2d4}.duet-theme-turva .duet-input:-ms-input-placeholder{color:#d1d1d1}.duet-input.disabled,.duet-input[disabled]{cursor:not-allowed!important;border-color:#f5f8fa!important;background:#f5f8fa!important;color:#657787!important}.duet-theme-turva .duet-input.disabled,.duet-theme-turva .duet-input[disabled]{border-color:#f9f9f9!important;background:#f9f9f9!important;color:#757575!important}.duet-input:hover{border-color:#657787}.duet-theme-turva .duet-input:hover{border-color:#757575}.duet-input:focus{border-color:#0077b3;outline:0}.duet-theme-turva .duet-input:focus{border-color:#111}.duet-input:not(:placeholder-shown):focus:required:invalid{border-color:#de2362}.duet-theme-turva .duet-input:not(:placeholder-shown):focus:required:invalid{border-color:#e02a0d}.duet-input:focus:required:valid{border-color:#0077b3}.duet-theme-turva .duet-input:focus:required:valid{border-color:#111}.duet-input[type=number]::-webkit-inner-spin-button,.duet-input[type=number]::-webkit-outer-spin-button,.duet-input[type=time]::-webkit-inner-spin-button,.duet-input[type=time]::-webkit-outer-spin-button{-webkit-appearance:none;display:none;margin:0}"; }
}
exports.duet_input = DuetInput;