@duetds/components
Version:
This package includes Duet Core Components and related tools.
178 lines (177 loc) • 16.7 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 } from './js-utils-b3b951a3.js';
var DuetSelect = /** @class */ (function () {
function class_1(hostRef) {
var _this = this;
registerInstance(this, hostRef);
this.selectId = jsUtils_2("DuetSelect");
this.errorId = jsUtils_2("DuetError");
this.labelId = jsUtils_2("DuetLabel");
/**
* Controls the margin of the component. Can be one of: "auto", "none".
*/
this.margin = "auto";
/**
* Display the select in error state along with an error message.
*/
this.error = "";
/**
* Expands the input to fill 100% of the container width.
*/
this.expand = false;
/**
* Theme of the select. Can be one of: "default", "turva".
*/
this.theme = "";
/**
* Visually hide the label, but still show it to screen readers.
*/
this.labelHidden = false;
/**
* Makes the select component disabled. This prevents users from being able to interact with the select, and conveys its inactive state to assistive technologies.
*/
this.disabled = false;
/**
* Label for the select.
*/
this.label = "label";
/**
* Tooltip to display next to the label of the input.
*/
this.tooltip = "";
/**
* Component event handling.
*/
this.onClick = function (ev) {
ev.stopPropagation();
};
this.onChange = function (event) {
var selectedOption = _this.element.querySelector("select").value;
_this.value = selectedOption;
_this.duetChange.emit({
originalEvent: event,
value: _this.value,
component: "duet-select",
});
};
this.onFocus = function () {
_this.duetFocus.emit();
};
this.onBlur = function () {
_this.duetBlur.emit();
};
this.duetChange = createEvent(this, "duetChange", 3);
this.duetFocus = createEvent(this, "duetFocus", 7);
this.duetBlur = createEvent(this, "duetBlur", 7);
}
class_1.prototype.valueChanged = function (event) {
this.duetChange.emit({
originalEvent: event,
value: this.value,
component: "duet-select",
});
};
/**
* 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.getSelectedItemLabel = function () {
var _this = this;
if (!this.hasValidItems()) {
return "";
}
var item = this.items.find(function (item) { return item["value"] + "" === _this.value; });
if (!item) {
return "";
}
return item["label"];
};
class_1.prototype.hasValidItems = function () {
return Array.isArray(this.items);
};
/**
* Sets focus on the specified `duet-select`. Use this method instead of the global
* `select.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("select");
if (nativeInput) {
nativeInput.focus();
}
return [2 /*return*/];
});
});
};
/**
* render() function
* Always the last one in the class.
*/
class_1.prototype.render = function () {
if (this.expand) {
this.element.classList.add("duet-expand");
}
var identifier = this.identifier || this.selectId;
var currentValue = "" + this.value;
return (h(Host, { onClick: this.onClick, class: { "duet-m-0": this.margin === "none" } }, h("div", { class: {
"duet-select-container": true,
"duet-label-hidden": this.labelHidden,
"duet-theme-turva": this.theme === "turva",
"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("div", { class: "duet-select-wrapper" }, h("select", { disabled: this.disabled, name: this.name, id: identifier, role: this.role, "aria-labelledby": this.labelId + " " + this.errorId, "aria-controls": this.accessibleControls, "aria-active-descendant": this.accessibleActiveDescendant, "aria-owns": this.accessibleOwns, onFocus: this.onFocus, onBlur: this.onBlur, onChange: this.onChange }, !this.hasValidItems() ? (h("option", null, "No options available")) : (this.items.map(function (item) { return (h("option", { value: item["value"], selected: currentValue === item["value"] ? true : false }, item["label"])); }))), h("div", { class: "duet-select", "aria-hidden": "true" }, this.getSelectedItemLabel(), h("svg", { role: "img", class: "duet-select-icon", fill: "currentColor", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "m12 18.999c-.4 0-.776-.156-1.059-.438l-10.721-10.72c-.142-.142-.22-.33-.22-.531 0-.2.078-.389.22-.53.142-.142.33-.22.53-.22s.389.078.53.22l10.72 10.719 10.72-10.719c.142-.142.33-.22.53-.22s.389.078.53.22c.142.142.22.33.22.53s-.078.389-.22.53l-10.72 10.72c-.282.283-.659.439-1.06.439z" })))), h("span", { class: "duet-select-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, "style", {
get: function () { return "\@charset \"UTF-8\";.sc-duet-select-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;vertical-align:bottom;max-width:100%;width:100%}.sc-duet-select-h:last-child, .sc-duet-select-h:last-of-type{margin-right:0!important}\@media only screen and (min-width:36em){.sc-duet-select-h{width:calc(50% - 16px - 3px)}.duet-expand.sc-duet-select-h{width:100%!important}}.duet-m-0.sc-duet-select-h{margin:0!important}duet-tooltip.sc-duet-select{position:absolute;top:12px;right:0}\@media only screen and (min-width:48em){duet-tooltip.sc-duet-select{position:relative;top:4px;right:auto}}.duet-select-container.sc-duet-select{padding:0}.duet-select-container.sc-duet-select, .duet-select-wrapper.sc-duet-select{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box;background:transparent;border:0;margin:0;position:relative;width:100%}.duet-select-wrapper.sc-duet-select{padding:0;padding:16px!important;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;font-weight:400;line-height:1.25}.duet-theme-turva.sc-duet-select .duet-select-wrapper.sc-duet-select{font-family:turva-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}.duet-select-wrapper.sc-duet-select:after{content:\" \"}.duet-select-wrapper.sc-duet-select select.sc-duet-select{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box;background:transparent;top:0;left:0;margin:0;right:0;bottom:0;padding:0;position:absolute;font-size:1rem;font-family:localtapiola-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;z-index:200;border:0;height:100%;width:100%;cursor:pointer;outline:none;opacity:0}.duet-theme-turva.sc-duet-select .duet-select-wrapper.sc-duet-select select.sc-duet-select{font-family:turva-sans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}.duet-select-wrapper.sc-duet-select select.sc-duet-select:hover + .duet-select.sc-duet-select{border-color:#909599;-webkit-box-shadow:0 0 0 1px #909599;box-shadow:0 0 0 1px #909599}.duet-theme-turva.sc-duet-select .duet-select-wrapper.sc-duet-select select.sc-duet-select:hover + .duet-select.sc-duet-select{border-color:#757575;-webkit-box-shadow:0 0 0 1px #757575;box-shadow:0 0 0 1px #757575}.has-error.sc-duet-select .duet-select-wrapper.sc-duet-select select.sc-duet-select:hover + .duet-select.sc-duet-select{-webkit-box-shadow:0 0 0 1px #de2362;box-shadow:0 0 0 1px #de2362}.duet-theme-turva.has-error.sc-duet-select .duet-select-wrapper.sc-duet-select select.sc-duet-select:hover + .duet-select.sc-duet-select{-webkit-box-shadow:0 0 0 1px #e02a0d;box-shadow:0 0 0 1px #e02a0d}.duet-select-wrapper.sc-duet-select select.sc-duet-select:focus + .duet-select.sc-duet-select{-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-select .duet-select-wrapper.sc-duet-select select.sc-duet-select:focus + .duet-select.sc-duet-select{border-color:#111;-webkit-box-shadow:0 0 0 1px #111;box-shadow:0 0 0 1px #111}.duet-theme-turva.sc-duet-select .duet-select-wrapper.sc-duet-select select.sc-duet-select:focus + .duet-select.sc-duet-select .duet-select-icon.sc-duet-select{color:#111}.duet-select-wrapper.sc-duet-select select.sc-duet-select:focus + .duet-select.sc-duet-select .duet-select-icon.sc-duet-select{color:#0077b3}.has-error.sc-duet-select .duet-select-wrapper.sc-duet-select select.sc-duet-select:focus + .duet-select.sc-duet-select{-webkit-box-shadow:0 0 0 1px #de2362;box-shadow:0 0 0 1px #de2362}.duet-theme-turva.has-error.sc-duet-select .duet-select-wrapper.sc-duet-select select.sc-duet-select:focus + .duet-select.sc-duet-select{-webkit-box-shadow:0 0 0 1px #e02a0d;box-shadow:0 0 0 1px #e02a0d}.duet-select-wrapper.sc-duet-select select[disabled].sc-duet-select{cursor:not-allowed!important}.duet-select-wrapper.sc-duet-select select[disabled].sc-duet-select + .duet-select.sc-duet-select{cursor:not-allowed!important;border-color:#f5f8fa!important;background:#f5f8fa!important;color:#657787!important;-webkit-text-fill-color:#657787!important;opacity:1!important}.duet-theme-turva.sc-duet-select .duet-select-wrapper.sc-duet-select select[disabled].sc-duet-select + .duet-select.sc-duet-select{border-color:#f7f7f7!important;background:#f7f7f7!important;color:#757575!important;-webkit-text-fill-color:#757575!important}.duet-select.sc-duet-select{-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:15px!important;position:absolute;text-align:left;left:0;top:0;bottom:0;right:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;-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:.15s ease;transition:.15s ease;z-index:100;min-width:8rem;width:100%;display:block}.has-error.sc-duet-select .duet-select.sc-duet-select{border-color:#de2362!important}.has-error.sc-duet-select .duet-select.sc-duet-select .duet-select-icon.sc-duet-select{color:#de2362!important}.duet-theme-turva.has-error.sc-duet-select .duet-select.sc-duet-select{border-color:#e02a0d!important}.duet-theme-turva.has-error.sc-duet-select .duet-select.sc-duet-select .duet-select-icon.sc-duet-select{color:#e02a0d!important}.duet-theme-turva.sc-duet-select .duet-select.sc-duet-select{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;border-color:#757575}.duet-select-help.sc-duet-select{-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;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-select-help.sc-duet-select span.sc-duet-select{display:block;margin-top:8px}.duet-theme-turva.sc-duet-select .duet-select-help.sc-duet-select{color:#757575}.has-error.sc-duet-select .duet-select-help.sc-duet-select{color:#de2362}.duet-theme-turva.has-error.sc-duet-select .duet-select-help.sc-duet-select{color:#e02a0d}.duet-select.sc-duet-select svg.sc-duet-select{-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:50%;-webkit-transform:translateY(-50%);transform:translateY(-50%);right:16px}.duet-theme-turva.sc-duet-select .duet-select.sc-duet-select svg.sc-duet-select{color:#111}.duet-label-hidden.sc-duet-select duet-label.sc-duet-select{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;
}());
export { DuetSelect as duet_select };