@kontent-ai/smart-link
Version:
Kontent.ai Smart Link SDK allowing to automatically inject [smart links](https://docs.kontent.ai/tutorials/develop-apps/build-strong-foundation/set-up-editing-from-preview#a-using-smart-links) to Kontent.ai according to manually specified [HTML data attri
185 lines (169 loc) • 6.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KSLButtonElement = exports.ButtonType = void 0;
const KSLIconElement_1 = require("./KSLIconElement");
const assert_1 = require("../utils/assert");
const KSLCustomElementWithTooltip_1 = require("./abstract/KSLCustomElementWithTooltip");
const domElement_1 = require("../utils/domElement");
const colors_1 = require("./tokens/colors");
const shadows_1 = require("./tokens/shadows");
var ButtonType;
(function (ButtonType) {
ButtonType["Primary"] = "primary";
ButtonType["Quinary"] = "quinary";
})(ButtonType || (exports.ButtonType = ButtonType = {}));
const templateHTML = `
<style>
:host,
:host * {
box-sizing: border-box;
}
:host {
display: block;
}
:host([hidden]) {
display: none;
}
:host(:focus) {
outline: none;
}
.ksl-button {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: none;
cursor: pointer;
}
.ksl-button:focus {
outline: none;
}
:host([disabled]) .ksl-button {
cursor: not-allowed;
}
.ksl-button__content,
:host([loading]) .ksl-button__loader {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.ksl-button__loader,
:host([loading]) .ksl-button__content {
display: none;
}
:host([type=${ButtonType.Primary}]) .ksl-button {
--ksl-icon-width: 18px;
--ksl-icon-height: 18px;
min-width: 40px;
max-width: 40px;
min-height: 40px;
max-height: 40px;
border-radius: 5000px;
box-shadow: var(--ksl-shadow-primary, ${shadows_1.Shadows.Primary});
background-color: var(--ksl-color-primary, ${colors_1.Colors.Primary});
color: var(--ksl-color-text-secondary, ${colors_1.Colors.TextSecondary});
fill: var(--ksl-color-text-secondary, ${colors_1.Colors.TextSecondary});
}
:host([type=${ButtonType.Primary}]:not([disabled])) .ksl-button:hover,
:host([type=${ButtonType.Primary}]:not([disabled])) .ksl-button:active {
background-color: var(--ksl-color-primary-hover, ${colors_1.Colors.PrimaryHover});
}
:host([type=${ButtonType.Primary}][disabled]) .ksl-button {
background-color: var(--ksl-color-background-default-disabled, ${colors_1.Colors.BackgroundDefaultDisabled});
color: var(--ksl-color-text-default-disabled, ${colors_1.Colors.TextDefaultDisabled});
fill: var(--ksl-color-text-default-disabled, ${colors_1.Colors.TextDefaultDisabled});
box-shadow: none;
}
:host([type=${ButtonType.Primary}][loading]) .ksl-button {
color: var(--ksl-color-primary, ${colors_1.Colors.Primary});
fill: var(--ksl-color-primary, ${colors_1.Colors.Primary});
box-shadow: none;
}
:host([type=${ButtonType.Quinary}]) .ksl-button {
--ksl-icon-width: 16px;
--ksl-icon-height: 16px;
border-radius: 5px;
padding: 0;
min-height: 24px;
min-width: 24px;
max-height: 24px;
max-width: 24px;
color: var(--ksl-color-text-default, ${colors_1.Colors.TextDefault});
fill: var(--ksl-color-text-default, ${colors_1.Colors.TextDefault});
background-color: var(--ksl-color-background-default, ${colors_1.Colors.BackgroundDefault});
}
:host([type=${ButtonType.Quinary}][disabled]) .ksl-button {
color: var(--ksl-color-text-default-disabled, ${colors_1.Colors.TextDefaultDisabled});
fill: var(--ksl-color-text-default-disabled, ${colors_1.Colors.TextDefaultDisabled});
}
:host([type=${ButtonType.Quinary}]:not([disabled])) .ksl-button:hover {
background-color: var(--ksl-color-background-default-hover, ${colors_1.Colors.BackgroundDefaultHover});
}
:host([type=${ButtonType.Quinary}]:not([disabled])) .ksl-button:active {
background-color: var(--ksl-color-background-default-selected, ${colors_1.Colors.BackgroundDefaultSelected});
}
</style>
<button class="ksl-button">
<div class="ksl-button__content">
<slot></slot>
</div>
<ksl-icon icon-name="${KSLIconElement_1.IconName.Spinner}" class="ksl-button__loader" />
</button>
`;
class KSLButtonElement extends KSLCustomElementWithTooltip_1.KSLCustomElementWithTooltip {
static get is() {
return 'ksl-button';
}
static get observedAttributes() {
const base = KSLCustomElementWithTooltip_1.KSLCustomElementWithTooltip.observedAttributes;
return [...base, 'loading'];
}
get loading() {
return this.hasAttribute('loading');
}
set loading(value) {
this.updateAttribute('loading', value);
}
get disabled() {
return this.hasAttribute('disabled');
}
set disabled(value) {
this.updateAttribute('disabled', value);
}
buttonRef;
constructor() {
super();
(0, assert_1.assert)(this.shadowRoot, 'Shadow root must be always accessible in "open" mode.');
this.buttonRef = this.shadowRoot.querySelector('button');
}
static initializeTemplate() {
return (0, domElement_1.createTemplateForCustomElement)(templateHTML);
}
connectedCallback() {
super.connectedCallback();
this.addEventListener('click', this.handleClick, { capture: true });
}
disconnectedCallback() {
super.disconnectedCallback();
this.removeEventListener('click', this.handleClick, { capture: true });
}
attributeChangedCallback(attributeName, _oldValue, newValue) {
super.attributeChangedCallback(attributeName, _oldValue, newValue);
if (attributeName === 'loading') {
const value = Boolean(newValue);
this.disabled = value;
this.tooltipDisabled = value;
}
}
handleClick = (event) => {
// make sure the disabled button does not trigger events
if (this.disabled) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
}
};
}
exports.KSLButtonElement = KSLButtonElement;
//# sourceMappingURL=KSLButtonElement.js.map