@duetds/components
Version: 
This package includes Duet Core Components and related tools.
190 lines (184 loc) • 16.6 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const core = require('./core-e5cda7d4.js');
const jsUtils = require('./js-utils-286cf29e.js');
const icons = require('./icons-4dd2177d.js');
const DuetInput = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        /**
         * Own Properties
         */
        this.inputId = jsUtils.jsUtils_2("DuetInput");
        this.labelId = jsUtils.jsUtils_2("DuetLabel");
        this.errorId = jsUtils.jsUtils_2("DuetError");
        /**
         * Set the amount of time, in milliseconds, to wait to trigger the duetChange event after each keystroke.
         */
        this.debounce = 0;
        /**
         * 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;
        /**
         * Controls the margin of the component. Can be one of: "auto", "none".
         */
        this.margin = "auto";
        /**
         * Set whether the input is required or not.
         */
        this.required = false;
        /**
         * Type of the input. Can be one of: "text", "email", "password", "search", "tel".
         */
        this.type = "text";
        /**
         * Label for the input.
         */
        this.label = "label";
        /**
         * Display the input in error state along with an error message.
         */
        this.error = "";
        /**
         * Visually hide the label, but still show it to screen readers.
         */
        this.labelHidden = false;
        /**
         * Enable or disable automatic completion by the browser
         */
        this.autoComplete = "on";
        /**
         * Tooltip to display next to the label of the input.
         */
        this.tooltip = "";
        /**
         * Component event handling.
         */
        this.onInput = (ev) => {
            const input = ev.target;
            if (input) {
                this.value = input.value || "";
            }
            this.duetInput.emit(ev);
        };
        this.onBlur = () => {
            this.duetBlur.emit();
        };
        this.onFocus = () => {
            this.duetFocus.emit();
        };
        this.duetInput = core.createEvent(this, "duetInput", 7);
        this.duetChange = core.createEvent(this, "duetChange", 3);
        this.duetBlur = core.createEvent(this, "duetBlur", 7);
        this.duetFocus = core.createEvent(this, "duetFocus", 7);
    }
    debounceChanged() {
        this.duetChange = jsUtils.jsUtils_4(this.duetChange, this.debounce);
    }
    /**
     * Update the native input element when the value changes
     */
    valueChanged() {
        this.duetChange.emit({
            value: this.value,
            component: "duet-input",
        });
    }
    /**
     * Component lifecycle events.
     */
    componentWillLoad() {
        if (this.theme !== "default" && document.documentElement.classList.contains("duet-theme-turva")) {
            this.theme = "turva";
        }
    }
    componentDidLoad() {
        this.debounceChanged();
    }
    /**
     * Sets focus on the specified `duet-input`. Use this method instead of the global
     * `input.focus()`.
     */
    async setFocus() {
        const nativeInput = this.element.querySelector("input");
        if (nativeInput) {
            nativeInput.focus();
        }
    }
    /**
     * render() function
     * Always the last one in the class.
     */
    render() {
        const identifier = this.identifier || this.inputId;
        // Set validation regexes
        let regexType = false;
        if (this.type === "tel") {
            regexType = "[0-9+ ]+";
        }
        const regex = this.pattern ? this.pattern : regexType;
        return (core.h(core.Host, { class: { "duet-expand": this.expand, "duet-m-0": this.margin === "none" } }, core.h("div", { class: {
                "duet-input-container": true,
                "duet-theme-turva": this.theme === "turva",
                "duet-label-hidden": this.labelHidden,
                "has-icon": this.type !== "text" && this.type !== "number" && this.type !== "password",
                "has-error": this.error !== "",
            } }, core.h("duet-label", { theme: this.theme === "turva" ? "turva" : "default", id: this.labelId, for: identifier }, this.label), this.tooltip !== "" ? core.h("duet-tooltip", null, this.tooltip) : "", core.h("input", { onInput: this.onInput, onBlur: this.onBlur, onFocus: this.onFocus, type: this.type, class: { "duet-input": true, disabled: this.disabled }, value: this.value, disabled: this.disabled, "aria-invalid": this.error !== "", "aria-labelledby": this.labelId + " " + this.errorId, "aria-controls": this.accessibleControls, "aria-autocomplete": this.accessibleAutocomplete, "aria-active-descendant": this.accessibleActiveDescendant, "aria-owns": this.accessibleOwns, pattern: regex, placeholder: this.placeholder, spellcheck: "false", minlength: this.minlength, maxlength: this.maxlength, autocomplete: this.autoComplete, required: this.required, role: this.role, name: this.name, id: identifier }), !this.icon && this.type !== "text" && this.type !== "number" && this.type !== "password" ? (core.h("div", { class: "duet-input-icon", "aria-hidden": "true", innerHTML: icons.duetIcons["form-" + jsUtils.jsUtils_6(this.type)].svg })) : (""), this.icon ? (core.h("div", { class: "duet-input-icon", "aria-hidden": "true", innerHTML: icons.duetIcons[jsUtils.jsUtils_6(this.icon)].svg })) : (""), core.h("span", { class: "duet-input-help", id: this.errorId, "aria-live": "assertive", "aria-relevant": "additions removals" }, this.error !== "" ? core.h("span", null, this.error) : ""))));
    }
    get element() { return core.getElement(this); }
    static get watchers() { return {
        "debounce": ["debounceChanged"],
        "value": ["valueChanged"]
    }; }
    static get style() { return ".sc-duet-input-h{-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;margin-right:16px!important;margin-bottom:12px!important;display:-ms-inline-flexbox;display:inline-flex;text-align:left;vertical-align:bottom;min-width:calc(33.333% - 8px);max-width:100%;width:100%}.sc-duet-input-h:last-child, .sc-duet-input-h:last-of-type{margin-right:0!important}\@media only screen and (min-width:36em){.sc-duet-input-h{width:calc(50% - 16px - 3px)}}.duet-expand.sc-duet-input-h{width:100%!important}.duet-m-0.sc-duet-input-h{margin:0!important}duet-tooltip.sc-duet-input{position:absolute;top:12px;right:0}\@media only screen and (min-width:48em){duet-tooltip.sc-duet-input{position:relative;top:4px;right:auto}}.duet-input-icon.sc-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;pointer-events:none;z-index:200;width:20px;height:20px;color:#00294d;position:absolute;top:54.4px;right:16px}.duet-theme-turva.sc-duet-input .duet-input-icon.sc-duet-input{color:#111}.duet-label-hidden.sc-duet-input .duet-input-icon.sc-duet-input{top:16px}.duet-input.sc-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:14px!important;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-variant-numeric:tabular-nums;font-family:localtapiola-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;border:1px solid #909599;border-radius:4px;font-size:1rem;background:#fff;color:#00294d;font-weight:400;line-height:1.25;-webkit-transition:border .15s ease,-webkit-box-shadow .15s ease;transition:border .15s ease,-webkit-box-shadow .15s ease;transition:box-shadow .15s ease,border .15s ease;transition:box-shadow .15s ease,border .15s ease,-webkit-box-shadow .15s ease;z-index:100;min-width:8rem;width:100%;position:relative;display:block}.has-error.sc-duet-input .duet-input.sc-duet-input{border-color:#de2362!important}.has-error.sc-duet-input .duet-input.sc-duet-input + .duet-input-icon.sc-duet-input{color:#de2362!important}.duet-theme-turva.has-error.sc-duet-input .duet-input.sc-duet-input{border-color:#e02a0d!important}.duet-theme-turva.has-error.sc-duet-input .duet-input.sc-duet-input + .duet-input-icon.sc-duet-input{color:#e02a0d!important}.has-icon.sc-duet-input .duet-input.sc-duet-input{padding-right:48px!important}.duet-theme-turva.sc-duet-input .duet-input.sc-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:#757575;color:#111}.duet-input-container.sc-duet-input{position:relative;width:100%;height:100%}.duet-input-container.sc-duet-input, .duet-input-help.sc-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}.duet-input-help.sc-duet-input{font-family:localtapiola-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;border-radius:4px;font-size:.875rem;color:#657787;font-weight:400;line-height:1.25;display:block}.duet-input-help.sc-duet-input span.sc-duet-input{display:block;margin-top:8px}.duet-theme-turva.sc-duet-input .duet-input-help.sc-duet-input{color:#757575;font-family:turva-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}.has-error.sc-duet-input .duet-input-help.sc-duet-input{color:#de2362}.duet-theme-turva.has-error.sc-duet-input .duet-input-help.sc-duet-input{color:#e02a0d}.duet-input.sc-duet-input::-webkit-contacts-auto-fill-button{display:none!important}.duet-input.sc-duet-input::-webkit-input-placeholder{color:#c4c8ca}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input::-webkit-input-placeholder{color:#c7c7c7}.duet-input.sc-duet-input::-moz-placeholder{color:#cfd2d4;opacity:1!important}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input::-moz-placeholder{color:#d1d1d1}.duet-input.sc-duet-input:-ms-input-placeholder{color:#cfd2d4}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input:-ms-input-placeholder{color:#d1d1d1}.duet-input.disabled.sc-duet-input, .duet-input[disabled].sc-duet-input{cursor:not-allowed!important;border-color:#f5f8fa!important;background:#f5f8fa!important;color:#00294d!important;-webkit-box-shadow:none!important;box-shadow:none!important;-webkit-text-fill-color:#00294d!important;opacity:1!important}.duet-theme-turva.sc-duet-input .duet-input.disabled.sc-duet-input, .duet-theme-turva.sc-duet-input .duet-input[disabled].sc-duet-input{border-color:#f7f7f7!important;background:#f7f7f7!important;color:#111!important;-webkit-text-fill-color:#111!important}.duet-input.sc-duet-input:hover{-webkit-box-shadow:0 0 0 1px #909599;box-shadow:0 0 0 1px #909599}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input:hover{-webkit-box-shadow:0 0 0 1px #757575;box-shadow:0 0 0 1px #757575}.has-error.sc-duet-input .duet-input.sc-duet-input:hover{-webkit-box-shadow:0 0 0 1px #de2362;box-shadow:0 0 0 1px #de2362}.duet-theme-turva.has-error.sc-duet-input .duet-input.sc-duet-input:hover{-webkit-box-shadow:0 0 0 1px #e02a0d;box-shadow:0 0 0 1px #e02a0d}.duet-input.sc-duet-input:focus{-webkit-transition:none;transition:none;border-color:#0077b3;-webkit-box-shadow:0 0 0 1px #0077b3;box-shadow:0 0 0 1px #0077b3;outline:0}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input:focus{border-color:#111;-webkit-box-shadow:0 0 0 1px #111;box-shadow:0 0 0 1px #111}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input:focus + .duet-input-icon.sc-duet-input{color:#111}.has-error.sc-duet-input .duet-input.sc-duet-input:focus{-webkit-box-shadow:0 0 0 1px #de2362;box-shadow:0 0 0 1px #de2362}.duet-theme-turva.has-error.sc-duet-input .duet-input.sc-duet-input:focus{-webkit-box-shadow:0 0 0 1px #e02a0d;box-shadow:0 0 0 1px #e02a0d}.duet-input.sc-duet-input:focus + .duet-input-icon.sc-duet-input{color:#0077b3}.duet-input[type=search].sc-duet-input:not(:placeholder-shown):focus + .duet-input-icon.sc-duet-input{display:none}.duet-input.sc-duet-input:not(:placeholder-shown):focus:required:invalid{border-color:#de2362;-webkit-box-shadow:0 0 0 1px #de2362;box-shadow:0 0 0 1px #de2362}.duet-input.sc-duet-input:not(:placeholder-shown):focus:required:invalid + .duet-input-icon.sc-duet-input{color:#de2362}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input:not(:placeholder-shown):focus:required:invalid{border-color:#e02a0d;-webkit-box-shadow:0 0 0 1px #e02a0d;box-shadow:0 0 0 1px #e02a0d}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input:not(:placeholder-shown):focus:required:invalid + .duet-input-icon.sc-duet-input{color:#e02a0d}.duet-input.sc-duet-input:focus:required:valid{border-color:#0077b3}.duet-theme-turva.sc-duet-input .duet-input.sc-duet-input:focus:required:valid{border-color:#111}.duet-input[type=number].sc-duet-input::-webkit-inner-spin-button, .duet-input[type=number].sc-duet-input::-webkit-outer-spin-button, .duet-input[type=time].sc-duet-input::-webkit-inner-spin-button, .duet-input[type=time].sc-duet-input::-webkit-outer-spin-button{-webkit-appearance:none;display:none;margin:0}.duet-input.sc-duet-input::-webkit-search-cancel-button{margin-right:-28px}.duet-label-hidden.sc-duet-input duet-label.sc-duet-input{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}"; }
};
const DuetLabel = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        /**
         * Theme of the label. Can be one of: "default", "turva".
         */
        this.theme = "";
        /**
         * Controls the margin of the component. Can be one of: "auto", "small", "none".
         */
        this.margin = "auto";
        /**
         * Controls the size of the label. Can be one of: "medium", "small".
         */
        this.size = "medium";
    }
    /**
     * Component lifecycle events.
     */
    componentWillLoad() {
        if (this.theme !== "default" && document.documentElement.classList.contains("duet-theme-turva")) {
            this.theme = "turva";
        }
    }
    /**
     * render() function
     * Always the last one in the class.
     */
    render() {
        return (core.h(core.Host, { class: {
                "duet-label": true,
                "duet-label-small": this.size === "small",
                "duet-theme-turva": this.theme === "turva",
                "duet-small-margin": this.margin === "small",
                "duet-m-0": this.margin === "none",
            } }, core.h("label", { htmlFor: this.for }, core.h("span", null, core.h("slot", null)))));
    }
    static get style() { return ".sc-duet-label-h{-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;margin-bottom:12px!important;margin-top:8px!important;-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;color:#00294d;font-weight:600;line-height:1.25;z-index:100;text-align:left;padding-right:48px;width:auto;cursor:default;position:relative;display:-ms-inline-flexbox;display:inline-flex}.duet-p-0.sc-duet-label-h{padding:0!important}.duet-m-0.sc-duet-label-h{margin:0!important}\@media only screen and (min-width:48em){.sc-duet-label-h{padding-right:0}}.duet-label-small.sc-duet-label-h{font-size:.875rem}.duet-theme-turva.sc-duet-label-h{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-m-0.sc-duet-label-h{margin-bottom:0!important}.duet-small-margin.sc-duet-label-h{margin-top:8px!important;margin-bottom:4px!important}"; }
};
exports.duet_input = DuetInput;
exports.duet_label = DuetLabel;