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

211 lines
4.7 KiB
TypeScript
Raw Normal View History

2023-09-12 23:37:02 +00:00
import { demoFunc } from './dees-button.demo.js';
2021-05-05 20:55:49 +00:00
import {
customElement,
html,
DeesElement,
property,
2023-08-07 18:02:18 +00:00
type TemplateResult,
2021-05-05 20:55:49 +00:00
cssManager,
css,
2023-08-07 23:10:02 +00:00
type CSSResult,
2021-05-05 20:55:49 +00:00
unsafeCSS,
2023-08-07 17:13:29 +00:00
} from '@design.estate/dees-element';
2020-09-13 16:24:48 +00:00
2023-08-07 17:13:29 +00:00
import * as domtools from '@design.estate/dees-domtools';
2020-09-13 16:24:48 +00:00
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 {
2023-09-12 23:37:02 +00:00
public static demo = demoFunc;
2020-12-09 14:06:24 +00:00
2023-01-17 15:52:13 +00:00
@property({
reflect: true,
hasChanged() {
return true;
}
})
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,
reflect: true,
2021-08-24 10:41:01 +00:00
})
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;
font-family: 'Geist Sans', 'monospace';
2021-05-05 20:55:49 +00:00
}
:host([hidden]) {
display: none;
}
.button {
2023-01-07 15:08:10 +00:00
transition: all 0.1s , color 0s;
2021-08-27 11:38:08 +00:00
position: relative;
2021-05-05 20:55:49 +00:00
font-size: 14px;
2023-01-07 15:32:43 +00:00
font-weight: 400;
2021-08-27 11:38:08 +00:00
display: flex;
justify-content: center;
align-items: center;
2023-01-13 10:48:00 +00:00
background: ${cssManager.bdTheme('#fff', '#333')};
2023-04-05 16:57:12 +00:00
box-shadow: ${cssManager.bdTheme('0px 1px 3px rgba(0,0,0,0.3)', 'none')};
2021-08-29 15:10:25 +00:00
border: 1px solid ${cssManager.bdTheme('#eee', '#333')};
2021-05-05 20:55:49 +00:00
border-top: ${cssManager.bdTheme('1px solid #eee', '1px solid #444')};
2022-12-07 01:28:31 +00:00
border-radius: 4px;
2024-02-13 22:31:26 +00:00
height: 40px;
2022-05-30 21:15:32 +00:00
padding: 0px 8px;
2021-05-05 20:55:49 +00:00
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 {
2024-01-10 04:11:55 +00:00
background: #0050b9;
2023-01-07 15:08:10 +00:00
color: #ffffff;
2024-01-10 04:11:55 +00:00
border: 1px solid #0050b9;
border-top: 1px solid #0050b9;
2021-05-05 20:55:49 +00:00
}
.button:active {
2024-01-10 04:11:55 +00:00
background: #0069f2;
border-top: 1px solid #0069f2;
2021-05-05 20:55:49 +00:00
}
.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
}
.button.disabled {
background: ${cssManager.bdTheme('#ffffff00', '#11111100')};
border: 1px dashed ${cssManager.bdTheme('#666666', '#666666')};
color: #9b9b9e;
cursor: default;
}
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;
2022-05-30 21:15:32 +00:00
margin-top: 32px;
2021-05-05 20:55:49 +00:00
}
2021-08-27 11:38:08 +00:00
.button.pending {
2024-01-10 04:11:55 +00:00
border: 1px dashed ${cssManager.bdTheme('#0069f2', '#0069f270')};
background: ${cssManager.bdTheme('#0069f2', '#0069f270')};
2021-08-27 11:38:08 +00:00
color: #fff;
}
.button.success {
2021-08-27 12:48:58 +00:00
border: 1px dashed ${cssManager.bdTheme('#689F38', '#8BC34A70')};
2021-08-27 12:25:44 +00:00
background: ${cssManager.bdTheme('#689F38', '#8BC34A70')};
2021-08-27 11:38:08 +00:00
color: #fff;
}
.button.error {
2021-08-27 12:48:58 +00:00
border: 1px dashed ${cssManager.bdTheme('#B71C1C', '#E64A1970')};
2021-08-27 12:27:18 +00:00
background: ${cssManager.bdTheme('#B71C1C', '#E64A1970')};
2021-08-27 11:38:08 +00:00
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`
2023-01-13 00:17:08 +00:00
<dees-spinner .bnw=${true} status="${this.status}"></dees-spinner>
2021-08-27 11:38:08 +00:00
`}
2023-01-07 13:23:17 +00:00
<div class="textbox">${this.text ? this.text : this.textContent}</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();
}
}
}