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

131 lines
3.0 KiB
TypeScript
Raw Normal View History

2021-08-27 11:38:08 +00:00
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-spinner': DeesSpinner;
}
}
@customElement('dees-spinner')
export class DeesSpinner extends DeesElement {
public static demo = () => html`
<dees-spinner></dees-spinner>
<dees-spinner status="success"></dees-spinner>
<dees-spinner status="error"></dees-spinner>
2023-01-12 23:30:56 +00:00
<dees-spinner size=${64} status="success"></dees-spinner>
<dees-spinner .size=${64} status="error"></dees-spinner>
2021-08-27 11:38:08 +00:00
`;
@property({
type: Number,
})
public size = 20;
2023-01-13 00:17:08 +00:00
@property({
type: String,
})
public bnw: boolean = false;
2021-08-27 11:38:08 +00:00
@property()
public status: 'normal' | 'pending' | 'success' | 'error' = 'normal';
constructor() {
super();
}
public static styles = [
cssManager.defaultStyles,
css`
:host {
display: block;
}
#loading {
2023-01-12 23:30:56 +00:00
position: relative;
2021-08-27 12:25:44 +00:00
transition: none;
2021-08-27 11:38:08 +00:00
display: flex;
justify-content: center;
align-content: center;
background: #8bc34a00;
border: 3px solid ${cssManager.bdTheme('rgba(0, 0, 0, 0.1)', 'rgba(255, 255, 255, 0.3)')};
border-radius: 50%;
border-top-color: ${cssManager.bdTheme('#333', '#fff')};
animation: spin 1s ease-in-out infinite;
-webkit-animation: spin 1s ease-in-out infinite;
}
#loading.success {
2023-01-13 00:17:08 +00:00
border: none;
2021-08-27 11:38:08 +00:00
border-radius: 50%;
animation: none;
-webkit-animation: none;
}
#loading.error {
2023-01-13 00:17:08 +00:00
border: none;
2021-08-27 11:38:08 +00:00
border-radius: 50%;
animation: none;
-webkit-animation: none;
}
@keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
2023-01-12 23:30:56 +00:00
dees-icon {
2021-08-27 11:38:08 +00:00
position: absolute;
2023-01-12 23:30:56 +00:00
height: 100%;
width: 100%;
2021-08-27 11:38:08 +00:00
}
`,
];
render() {
return html`
<style>
#loading {
width: ${this.size}px;
height: ${this.size}px;
}
2023-01-12 23:46:17 +00:00
#loading.success {
2023-01-13 00:17:08 +00:00
color: ${cssManager.bdTheme(this.bnw ? '#333': `#8bc34a`, this.bnw ? '#fff' : `#8bc34a`)};
2023-01-12 23:46:17 +00:00
}
#loading.error {
2023-01-13 00:17:08 +00:00
color: ${cssManager.bdTheme(this.bnw ? '#333': `#e64a19`, this.bnw ? '#fff' : `#e64a19`)};
2023-01-12 23:46:17 +00:00
}
2023-01-12 23:30:56 +00:00
dees-icon {
2023-01-13 00:17:08 +00:00
font-size: ${this.size}px;
2023-01-12 23:30:56 +00:00
}
2021-08-27 11:38:08 +00:00
</style>
<div class="${this.status}" id="loading">
2023-01-12 23:30:56 +00:00
${(() => {
if (this.status === 'success') {
2023-01-13 00:17:08 +00:00
return html`<dees-icon style="transform: translateX(1%) translateY(3%);" .iconFA=${'circleCheck' as any}></dees-icon>`;
2023-01-12 23:30:56 +00:00
} else if (this.status === 'error') {
2023-01-13 00:17:08 +00:00
return html`<dees-icon .iconFA=${'circleXmark' as any}></dees-icon>`;
2023-01-12 23:30:56 +00:00
}
})()}
2021-08-27 11:38:08 +00:00
</div>
`;
}
}