155 lines
3.2 KiB
TypeScript
155 lines
3.2 KiB
TypeScript
import {
|
|
customElement,
|
|
html,
|
|
DeesElement,
|
|
property,
|
|
TemplateResult,
|
|
cssManager,
|
|
css,
|
|
unsafeCSS,
|
|
} from '@designestate/dees-element';
|
|
|
|
import * as domtools from '@designestate/dees-domtools';
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'dees-button': DeesButton;
|
|
}
|
|
}
|
|
|
|
@customElement('dees-button')
|
|
export class DeesButton extends DeesElement {
|
|
public static demo = () => html`<dees-button></dees-button>`;
|
|
|
|
@property()
|
|
public text: string;
|
|
|
|
@property()
|
|
public eventDetailData: string;
|
|
|
|
@property({
|
|
type: Boolean
|
|
})
|
|
public disabled = false;
|
|
|
|
@property()
|
|
public isHidden = false;
|
|
|
|
@property()
|
|
public type: 'normal' | 'highlighted' | 'discreet' | 'big' = 'normal';
|
|
|
|
constructor() {
|
|
super();
|
|
}
|
|
|
|
public static styles = [
|
|
cssManager.defaultStyles,
|
|
css`
|
|
:host {
|
|
display: block;
|
|
box-sizing: border-box;
|
|
}
|
|
:host([hidden]) {
|
|
display: none;
|
|
}
|
|
|
|
.button {
|
|
transition: all 0.2s ease;
|
|
font-size: 14px;
|
|
display: block;
|
|
text-align: center;
|
|
background: ${cssManager.bdTheme('#eee', '#333')};
|
|
box-shadow: ${cssManager.bdTheme('0px 0px 5px rgba(0,0,0,0.1)', 'none')};
|
|
border-top: ${cssManager.bdTheme('1px solid #eee', '1px solid #444')};
|
|
border-radius: 2px;
|
|
line-height: 40px;
|
|
padding: 0px 10px;
|
|
min-width: 100px;
|
|
user-select: none;
|
|
color: ${cssManager.bdTheme('#333', ' #ccc')};
|
|
}
|
|
|
|
.button:hover {
|
|
cursor: pointer;
|
|
background: #039be5;
|
|
border: 0px dashed ${cssManager.bdTheme('#eeeff300', '#66666600')};
|
|
border-top: 1px solid #039be5;
|
|
color: #ffffff;
|
|
}
|
|
|
|
.button:active {
|
|
background: #0277bd;
|
|
border-top: 1px solid #0277bd;
|
|
}
|
|
|
|
.button.disabled {
|
|
background: ${cssManager.bdTheme('#ffffff00', '#11111100')};
|
|
border: 1px dashed ${cssManager.bdTheme('#666666', '#666666')};
|
|
color: #9b9b9e;
|
|
cursor: default;
|
|
}
|
|
|
|
.button.highlighted {
|
|
background: #e4002b;
|
|
color: #fff;
|
|
}
|
|
|
|
.button.discreet {
|
|
background: none;
|
|
border: 1px solid #9b9b9e;
|
|
color: #000;
|
|
}
|
|
|
|
.button.discreet:hover {
|
|
background: rgba(0, 0, 0, 0.1);
|
|
}
|
|
.hidden {
|
|
display: none;
|
|
}
|
|
|
|
.big {
|
|
display: inline-block;
|
|
line-height: 48px;
|
|
font-size: 16px;
|
|
padding: 0px 48px;
|
|
margin-top: 36px;
|
|
}
|
|
`,
|
|
];
|
|
|
|
public render(): TemplateResult {
|
|
return html`
|
|
<div
|
|
class="button ${this.isHidden ? 'hidden' : 'block'} ${this.type} ${this.disabled
|
|
? 'disabled'
|
|
: null}"
|
|
@click="${this.dispatchClick}"
|
|
>
|
|
${this.text ? this.text : this.textContent}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
public async dispatchClick() {
|
|
if (this.disabled) {
|
|
return;
|
|
}
|
|
|
|
this.dispatchEvent(
|
|
new CustomEvent('clicked', {
|
|
detail: {
|
|
data: this.eventDetailData,
|
|
},
|
|
bubbles: true,
|
|
})
|
|
);
|
|
}
|
|
|
|
public async firstUpdated() {
|
|
if (!this.textContent) {
|
|
this.textContent = 'Button';
|
|
this.performUpdate();
|
|
}
|
|
}
|
|
}
|