@duetds/components
Version:
This package includes Duet Core Components and related tools.
150 lines (149 loc) • 12.5 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 DuetCheckbox = /** @class */ (function () {
function class_1(hostRef) {
var _this = this;
registerInstance(this, hostRef);
this.checkboxId = jsUtils_2("DuetCheckbox");
/**
* 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;
/**
* Theme of the checkbox. Can be one of: "default", "turva".
*/
this.theme = "";
/**
* Makes the checkbox component disabled. This prevents users from being able to interact with the checkbox, and conveys its inactive state to assistive technologies.
*/
this.disabled = false;
/**
* Label for the checkbox
*/
this.label = "label";
/**
* Check state of the checkbox.
*/
this.checked = false;
/**
* Component event handling.
*/
this.onClick = function (ev) {
ev.preventDefault();
_this.setFocus();
_this.checked = !_this.checked;
};
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.checkedChanged = function (isChecked) {
this.duetChange.emit({
checked: isChecked,
value: this.value,
component: "duet-checkbox",
});
};
/**
* Component lifecycle events.
*/
class_1.prototype.componentWillLoad = function () {
if (this.value === undefined) {
this.value = this.identifier;
}
if (this.theme !== "default" && document.documentElement.classList.contains("duet-theme-turva")) {
this.theme = "turva";
}
};
/**
* Sets focus on the specified `duet-checkbox`. 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.checkboxId;
return (h(Host, { onClick: this.onClick, class: { "duet-m-0": this.margin === "none" } }, h("div", { class: { "duet-checkbox-container": true, "duet-theme-turva": this.theme === "turva" } }, h("input", { type: "checkbox", onFocus: this.onFocus, onBlur: this.onBlur, value: this.value, class: { "duet-checkbox": true, disabled: this.disabled }, checked: this.checked, disabled: this.disabled, "aria-controls": this.accessibleControls, "aria-active-descendant": this.accessibleActiveDescendant, "aria-owns": this.accessibleOwns, required: this.required, role: this.role, name: this.name, id: identifier }), h("label", { class: "duet-label", htmlFor: identifier }, h("span", null, this.label)))));
};
Object.defineProperty(class_1.prototype, "element", {
get: function () { return getElement(this); },
enumerable: true,
configurable: true
});
Object.defineProperty(class_1, "watchers", {
get: function () {
return {
"checked": ["checkedChanged"]
};
},
enumerable: true,
configurable: true
});
Object.defineProperty(class_1, "style", {
get: function () { return ".sc-duet-checkbox-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:8px!important;margin-bottom:12px!important;-webkit-tap-highlight-color:transparent;display:-ms-inline-flexbox;display:inline-flex;vertical-align:bottom;width:100%}.sc-duet-checkbox-h:last-child, .sc-duet-checkbox-h:last-of-type{margin-right:0!important}.duet-m-0.sc-duet-checkbox-h{margin:0!important}.duet-label.sc-duet-checkbox{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box;border:0;padding:0;margin:0;margin-bottom:12px!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;background:transparent;color:#00294d;font-weight:400;line-height:1.25;-webkit-transition:.3s ease;transition:.3s ease;z-index:100;position:relative;cursor:pointer;display:inline;vertical-align:top}.duet-label.duet-p-0.sc-duet-checkbox{padding:0!important}.duet-label.duet-m-0.sc-duet-checkbox{margin:0!important}.duet-theme-turva.sc-duet-checkbox .duet-label.sc-duet-checkbox{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.sc-duet-checkbox span.sc-duet-checkbox{-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;display:inline-block;vertical-align:top;width:calc(100% - 32px)}.duet-label-hidden.sc-duet-checkbox .duet-label.sc-duet-checkbox{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.duet-checkbox.sc-duet-checkbox{padding:0;padding:14px!important;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;position:absolute;opacity:0;z-index:2;left:0;top:0;cursor:pointer}.duet-checkbox.sc-duet-checkbox, .duet-checkbox-container.sc-duet-checkbox{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box;background:transparent;border:0;margin:0;width:100%;height:100%}.duet-checkbox-container.sc-duet-checkbox{padding:0;margin-top:4px!important;position:relative}.duet-checkbox.sc-duet-checkbox + label.sc-duet-checkbox:before{-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;content:\"\";display:inline-block;vertical-align:top;z-index:100;width:20px;height:20px;border-radius:4px;background:#fff;margin:0 10px 1px 1px;border:1px solid #00294d}.duet-theme-turva.sc-duet-checkbox .duet-checkbox.sc-duet-checkbox + label.sc-duet-checkbox:before{border-color:#111}.duet-checkbox.sc-duet-checkbox:checked + label.sc-duet-checkbox:before{background:#00294d;border:1px solid #00294d}.duet-theme-turva.sc-duet-checkbox .duet-checkbox.sc-duet-checkbox:checked + label.sc-duet-checkbox:before{background:#111;border-color:#111}.user-is-tabbing.sc-duet-checkbox-h .duet-checkbox.sc-duet-checkbox:focus + label.sc-duet-checkbox:before{outline:1px dotted #0077b3;outline:5px auto -webkit-focus-ring-color}.duet-checkbox.sc-duet-checkbox + label.sc-duet-checkbox{position:static}.duet-checkbox.sc-duet-checkbox:checked + label.sc-duet-checkbox:after{-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;content:\"\";position:absolute;left:5px;top:4px;z-index:200;background:transparent url(\"data:image/svg+xml,%3Csvg%20fill%3D%27white%27%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%2724%27%20height%3D%2724%27%20viewBox%3D%270%200%2024%2024%27%3E%3Cpath%20d%3D%27M23.374.287a1.5%2C1.5%2C0%2C0%2C0-2.093.345L7.246%2C20.2%2C2.561%2C15.511A1.5%2C1.5%2C0%2C1%2C0%2C.439%2C17.632l5.935%2C5.934a1.525%2C1.525%2C0%2C0%2C0%2C2.279-.186l15.066-21A1.5%2C1.5%2C0%2C0%2C0%2C23.374.287Z%27%20%2F%3E%3C%2Fsvg%3E\") no-repeat 0 0;background-size:100% auto;width:12px;height:12px}.duet-theme-turva.sc-duet-checkbox .duet-checkbox.sc-duet-checkbox:checked + label.sc-duet-checkbox:after{top:3px}.duet-checkbox.disabled.sc-duet-checkbox + label.sc-duet-checkbox, .duet-checkbox[disabled].sc-duet-checkbox + label.sc-duet-checkbox{cursor:not-allowed;color:#657787}.duet-theme-turva.sc-duet-checkbox .duet-checkbox.disabled.sc-duet-checkbox + label.sc-duet-checkbox, .duet-theme-turva.sc-duet-checkbox .duet-checkbox[disabled].sc-duet-checkbox + label.sc-duet-checkbox{color:#757575}.duet-checkbox.disabled.sc-duet-checkbox + label.sc-duet-checkbox:before, .duet-checkbox[disabled].sc-duet-checkbox + label.sc-duet-checkbox:before{border-color:#cfd2d4}.duet-theme-turva.sc-duet-checkbox .duet-checkbox.disabled.sc-duet-checkbox + label.sc-duet-checkbox:before, .duet-theme-turva.sc-duet-checkbox .duet-checkbox[disabled].sc-duet-checkbox + label.sc-duet-checkbox:before{border-color:#d1d1d1}.duet-checkbox.disabled.sc-duet-checkbox:checked + label.sc-duet-checkbox:before, .duet-checkbox[disabled].sc-duet-checkbox:checked + label.sc-duet-checkbox:before{background:#657787;border:1px solid #657787}.duet-theme-turva.sc-duet-checkbox .duet-checkbox.disabled.sc-duet-checkbox:checked + label.sc-duet-checkbox:before, .duet-theme-turva.sc-duet-checkbox .duet-checkbox[disabled].sc-duet-checkbox:checked + label.sc-duet-checkbox:before{border-color:#757575;background:#757575}"; },
enumerable: true,
configurable: true
});
return class_1;
}());
export { DuetCheckbox as duet_checkbox };