/*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2022 Valeriy Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ import './button.less'; import type { IDictionary } from 'jodit/types'; import { UIElement } from 'jodit/core/ui'; import { css } from 'jodit/core/helpers'; import { component, watch } from 'jodit/core/decorators'; import { isString } from 'jodit/core/helpers/checker'; import { assert } from 'jodit/src/core/helpers'; @component export class UIGButton extends UIElement { /** @override */ override className(): string { return 'UIGButton'; } /** @override */ constructor(jodit: UIElement['jodit'], protected style: IDictionary) { super(jodit); } @watch('style') private updateStyles(): void { const { style } = this; const btn = this.getElm('button'); assert(btn != null, 'button element does not exist'); const wrapper = this.getElm('wrapper'); assert(wrapper != null, 'wrapper element does not exist'); wrapper.style.backgroundColor = style.previewBgColor; UIGButton.applyStyle(style, btn); } static applyStyle(style: IDictionary, btn: HTMLElement): void { const _ = (v: string | number): string => (isString(v) ? v : v + 'px'); btn.innerText = style.text || 'css'; btn.setAttribute('href', style.href); css(btn, { background: !style.solid ? `linear-gradient(to bottom, ${style.bgStart} 5%, ${style.bgEnd} 100%)` : null, backgroundColor: style.bgStart, borderRadius: _(style.borderRadius), border: `${_(style.borderSize)} solid ${style.borderColor}`, display: 'inline-block', cursor: 'pointer', color: style.fontColor, fontFamily: style.fontFamily, fontSize: _(style.fontSize), fontWeight: style.fontWeight ? 'bold' : null, fontStyle: style.fontItalic ? 'italic' : null, padding: `${_(style.paddingY)} ${_(style.paddingX)}`, textDecoration: 'none' }); css(btn, { textShadow: style.textShadow ? [ style.textShadowOffsetX, style.textShadowOffsetY, style.textShadowBlurRadius, style.textShadowColor ] .map(_) .join(' ') : null }); css(btn, { boxShadow: style.boxShadow ? [ style.boxShadowInset ? 'inset' : '', style.boxShadowOffsetX, style.boxShadowOffsetY, style.boxShadowBlurRadius, style.boxShadowSpreadRadius, style.boxShadowColor ] .map(_) .join(' ') : null }); } override update(): void { this.updateStyles(); } /** @override */ protected override render(): string { return `