dees-catalog/ts_web/elements/dees-button.ts

207 lines
4.8 KiB
TypeScript
Raw Normal View History

2021-05-05 20:55:49 +00:00
import {
customElement,
html,
DeesElement,
property,
TemplateResult,
cssManager,
css,
unsafeCSS,
} from '@designestate/dees-element';
2020-09-13 16:24:48 +00:00
import * as domtools from '@designestate/dees-domtools';
2021-02-13 21:52:36 +00:00
declare global {
interface HTMLElementTagNameMap {
'dees-button': DeesButton;
}
}
2020-09-13 16:24:48 +00:00
@customElement('dees-button')
2020-12-09 14:06:24 +00:00
export class DeesButton extends DeesElement {
2021-08-27 11:38:08 +00:00
public static demo = () => html`
<dees-button>This is a slotted Text</dees-button>
<p><dees-button text="Highlighted: This text shows" type="highlighted">Highlighted</dees-button></p>
<p><dees-button type="discreet">This is discreete button</dees-button></p>
<p><dees-button disabled>This is a disabled button</dees-button></p>
<p><dees-button type="big">This is a slotted Text</dees-button></p>
<p><dees-button status="normal">Normal Status</dees-button></p>
<p><dees-button disabled status="pending">Pending Status</dees-button></p>
<p><dees-button disabled status="success">Success Status</dees-button></p>
<p><dees-button disabled status="error">Error Status</dees-button></p>
`;
2020-12-09 14:06:24 +00:00
2020-09-13 16:24:48 +00:00
@property()
2021-08-25 11:51:55 +00:00
public text: string;
2020-09-13 16:24:48 +00:00
@property()
2021-08-25 11:51:55 +00:00
public eventDetailData: string;
2020-09-13 16:24:48 +00:00
2021-08-24 10:41:01 +00:00
@property({
type: Boolean
})
2021-08-25 11:51:55 +00:00
public disabled = false;
2020-09-13 16:24:48 +00:00
2021-08-27 11:38:08 +00:00
@property({
type: Boolean
})
2021-08-25 11:51:55 +00:00
public isHidden = false;
2020-09-13 16:24:48 +00:00
2021-08-27 11:38:08 +00:00
@property({
type: String
})
2020-09-13 16:24:48 +00:00
public type: 'normal' | 'highlighted' | 'discreet' | 'big' = 'normal';
2021-08-27 11:38:08 +00:00
@property({
type: String
})
public status: 'normal' | 'pending' | 'success' | 'error' = 'normal';
2020-09-13 16:24:48 +00:00
constructor() {
super();
}
2021-05-05 20:55:49 +00:00
public static styles = [
cssManager.defaultStyles,
css`
:host {
display: block;
box-sizing: border-box;
}
:host([hidden]) {
display: none;
}
.button {
2021-08-27 11:38:08 +00:00
position: relative;
2021-05-05 20:55:49 +00:00
transition: all 0.2s ease;
font-size: 14px;
2021-08-27 11:38:08 +00:00
display: flex;
justify-content: center;
align-items: center;
2021-05-05 20:55:49 +00:00
background: ${cssManager.bdTheme('#eee', '#333')};
2021-08-25 11:51:55 +00:00
box-shadow: ${cssManager.bdTheme('0px 0px 5px rgba(0,0,0,0.1)', 'none')};
2021-05-05 20:55:49 +00:00
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')};
2021-08-27 11:38:08 +00:00
max-width: 500px;
2021-05-05 20:55:49 +00:00
}
.button:hover {
cursor: pointer;
background: #039be5;
2021-08-24 10:41:01 +00:00
border: 0px dashed ${cssManager.bdTheme('#eeeff300', '#66666600')};
2021-05-05 20:55:49 +00:00
border-top: 1px solid #039be5;
color: #ffffff;
}
.button:active {
background: #0277bd;
border-top: 1px solid #0277bd;
}
.button.disabled {
2021-08-24 10:41:01 +00:00
background: ${cssManager.bdTheme('#ffffff00', '#11111100')};
border: 1px dashed ${cssManager.bdTheme('#666666', '#666666')};
2021-05-05 20:55:49 +00:00
color: #9b9b9e;
cursor: default;
}
.button.highlighted {
background: #e4002b;
2021-08-27 11:38:08 +00:00
border: none;
color: #fff;
}
.button.highlighted:hover {
background: #b50021;
border: none;
2021-05-05 20:55:49 +00:00
color: #fff;
}
.button.discreet {
background: none;
border: 1px solid #9b9b9e;
2021-08-27 11:38:08 +00:00
color: ${cssManager.bdTheme('#000', '#fff')};
2021-05-05 20:55:49 +00:00
}
.button.discreet:hover {
2021-08-27 11:38:08 +00:00
background: ${cssManager.bdTheme('rgba(0, 0, 0, 0.1)', 'rgba(255, 255, 255, 0.1)')};
2021-05-05 20:55:49 +00:00
}
2021-08-27 11:38:08 +00:00
.button.hidden {
2021-05-05 20:55:49 +00:00
display: none;
}
2021-08-27 11:38:08 +00:00
.button.big {
width: 300px;
2021-05-05 20:55:49 +00:00
line-height: 48px;
font-size: 16px;
padding: 0px 48px;
margin-top: 36px;
}
2021-08-27 11:38:08 +00:00
.button.pending {
background: #0277bd70;
color: #fff;
}
.button.success {
background: #8BC34A70;
color: #fff;
}
.button.error {
background: #E64A1970;
color: #fff;
}
dees-spinner {
position: absolute;
left: 10px;
}
2021-05-05 20:55:49 +00:00
`,
];
2020-09-13 16:24:48 +00:00
public render(): TemplateResult {
return html`
2021-05-05 20:55:49 +00:00
<div
2021-08-27 11:38:08 +00:00
class="button ${this.isHidden ? 'hidden' : 'block'} ${this.type} ${this.status} ${this.disabled
2021-05-05 20:55:49 +00:00
? 'disabled'
: null}"
@click="${this.dispatchClick}"
>
2021-08-27 11:38:08 +00:00
${this.status === 'normal' ? html``: html`
<dees-spinner status="${this.status}"></dees-spinner>
`}
<div class="textbox">${this.text ? this.text : html`<slot></slot>`}</div>
2020-09-13 16:24:48 +00:00
</div>
`;
}
public async dispatchClick() {
if (this.disabled) {
return;
}
2021-05-05 20:55:49 +00:00
this.dispatchEvent(
new CustomEvent('clicked', {
detail: {
data: this.eventDetailData,
},
bubbles: true,
})
);
2020-09-13 16:24:48 +00:00
}
2021-05-05 20:55:49 +00:00
public async firstUpdated() {
2020-09-13 16:24:48 +00:00
if (!this.textContent) {
this.textContent = 'Button';
this.performUpdate();
}
}
}