dees-catalog/ts_web/elements/dees-spinner.ts
2023-01-13 00:30:56 +01:00

122 lines
2.8 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-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>
<dees-spinner size=${64} status="success"></dees-spinner>
<dees-spinner .size=${64} status="error"></dees-spinner>
`;
@property({
type: Number,
})
public size = 20;
@property()
public status: 'normal' | 'pending' | 'success' | 'error' = 'normal';
constructor() {
super();
}
public static styles = [
cssManager.defaultStyles,
css`
:host {
display: block;
}
#loading {
position: relative;
transition: none;
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 {
border: 0px solid rgba(255, 255, 255, 0);
background: #8bc34a;
border-radius: 50%;
animation: none;
-webkit-animation: none;
}
#loading.error {
border: 0px solid rgba(255, 255, 255, 0);
background: #e64a19;
border-radius: 50%;
animation: none;
-webkit-animation: none;
}
@keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
dees-icon {
color: #fff;
position: absolute;
height: 100%;
width: 100%;
}
`,
];
render() {
return html`
<style>
#loading {
width: ${this.size}px;
height: ${this.size}px;
}
dees-icon {
font-size: ${Math.round(this.size * 0.6)}px;
}
</style>
<div class="${this.status}" id="loading">
${(() => {
if (this.status === 'success') {
return html`<dees-icon style="transform: translateX(1%) translateY(3%);" .iconFA=${'check' as any}></dees-icon>`;
} else if (this.status === 'error') {
return html`<dees-icon .iconFA=${'xmark' as any}></dees-icon>`;
}
})()}
</div>
`;
}
}