@duetds/components
Version:
This package includes Duet Core Components and related tools.
245 lines (244 loc) • 20.1 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { r as registerInstance, d as createEvent, h, H as Host, c as getElement } from './core-12b6bfe8.js';
import { a as jsUtils_2, c as jsUtils_4, j as jsUtils_6 } from './js-utils-b3b951a3.js';
import { d as duetIcons } from './icons-cfd0386d.js';
var DuetInput = /** @class */ (function () {
function class_1(hostRef) {
var _this = this;
registerInstance(this, hostRef);
/**
* Own Properties
*/
this.inputId = jsUtils_2("DuetInput");
this.labelId = jsUtils_2("DuetLabel");
this.errorId = 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 = function (ev) {
var input = ev.target;
if (input) {
_this.value = input.value || "";
}
_this.duetInput.emit(ev);
};
this.onBlur = function () {
_this.duetBlur.emit();
};
this.onFocus = function () {
_this.duetFocus.emit();
};
this.duetInput = createEvent(this, "duetInput", 7);
this.duetChange = createEvent(this, "duetChange", 3);
this.duetBlur = createEvent(this, "duetBlur", 7);
this.duetFocus = createEvent(this, "duetFocus", 7);
}
class_1.prototype.debounceChanged = function () {
this.duetChange = jsUtils_4(this.duetChange, this.debounce);
};
/**
* Update the native input element when the value changes
*/
class_1.prototype.valueChanged = function () {
this.duetChange.emit({
value: this.value,
component: "duet-input",
});
};
/**
* Component lifecycle events.
*/
class_1.prototype.componentWillLoad = function () {
if (this.theme !== "default" && document.documentElement.classList.contains("duet-theme-turva")) {
this.theme = "turva";
}
};
class_1.prototype.componentDidLoad = function () {
this.debounceChanged();
};
/**
* Sets focus on the specified `duet-input`. Use this method instead of the global
* `input.focus()`.
*/
class_1.prototype.setFocus = function () {
return __awaiter(this, void 0, void 0, function () {
var nativeInput;
return __generator(this, function (_a) {
nativeInput = this.element.querySelector("input");
if (nativeInput) {
nativeInput.focus();
}
return [2 /*return*/];
});
});
};
/**
* render() function
* Always the last one in the class.
*/
class_1.prototype.render = function () {
var identifier = this.identifier || this.inputId;
// Set validation regexes
var regexType = false;
if (this.type === "tel") {
regexType = "[0-9+ ]+";
}
var regex = this.pattern ? this.pattern : regexType;
return (h(Host, { class: { "duet-expand": this.expand, "duet-m-0": this.margin === "none" } }, 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 !== "",
} }, h("duet-label", { theme: this.theme === "turva" ? "turva" : "default", id: this.labelId, for: identifier }, this.label), this.tooltip !== "" ? h("duet-tooltip", null, this.tooltip) : "", 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" ? (h("div", { class: "duet-input-icon", "aria-hidden": "true", innerHTML: duetIcons["form-" + jsUtils_6(this.type)].svg })) : (""), this.icon ? (h("div", { class: "duet-input-icon", "aria-hidden": "true", innerHTML: duetIcons[jsUtils_6(this.icon)].svg })) : (""), h("span", { class: "duet-input-help", id: this.errorId, "aria-live": "assertive", "aria-relevant": "additions removals" }, this.error !== "" ? h("span", null, this.error) : ""))));
};
Object.defineProperty(class_1.prototype, "element", {
get: function () { return getElement(this); },
enumerable: true,
configurable: true
});
Object.defineProperty(class_1, "watchers", {
get: function () {
return {
"debounce": ["debounceChanged"],
"value": ["valueChanged"]
};
},
enumerable: true,
configurable: true
});
Object.defineProperty(class_1, "style", {
get: function () { 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}"; },
enumerable: true,
configurable: true
});
return class_1;
}());
var DuetLabel = /** @class */ (function () {
function DuetLabel(hostRef) {
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.
*/
DuetLabel.prototype.componentWillLoad = function () {
if (this.theme !== "default" && document.documentElement.classList.contains("duet-theme-turva")) {
this.theme = "turva";
}
};
/**
* render() function
* Always the last one in the class.
*/
DuetLabel.prototype.render = function () {
return (h(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",
} }, h("label", { htmlFor: this.for }, h("span", null, h("slot", null)))));
};
Object.defineProperty(DuetLabel, "style", {
get: function () { 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}"; },
enumerable: true,
configurable: true
});
return DuetLabel;
}());
export { DuetInput as duet_input, DuetLabel as duet_label };