Skip to content

Commit

Permalink
reuse loading spinner & small feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvoskamp committed Sep 5, 2023
1 parent dad4142 commit 6d7c639
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
11 changes: 9 additions & 2 deletions apps/gallery/stories/components/wui-loading-spinner.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ type Component = Meta<WuiLoadingSpinner>
export default {
title: 'Components/wui-loading-spinner',
args: {
color: 'accent-100'
color: 'accent-100',
size: 'lg'
},
argTypes: {
size: {
options: ['sm', 'md', 'lg'],
control: { type: 'select' }
},
color: {
options: colorOptions,
control: { type: 'select' }
Expand All @@ -20,5 +25,7 @@ export default {
} as Component

export const Default: Component = {
render: args => html` <wui-loading-spinner color=${args.color}></wui-loading-spinner> `
render: args => html`
<wui-loading-spinner size=${args.size} color=${args.color}></wui-loading-spinner>
`
}
6 changes: 5 additions & 1 deletion packages/ui/src/components/wui-loading-spinner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ import { html, LitElement } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import { resetStyles } from '../../utils/ThemeUtil.js'
import styles from './styles.js'
import type { ColorType } from '../../utils/TypesUtil.js'
import type { ColorType, SizeType } from '../../utils/TypesUtil.js'

@customElement('wui-loading-spinner')
export class WuiLoadingSpinner extends LitElement {
public static override styles = [resetStyles, styles]

@property() public color: ColorType = 'accent-100'

@property() public size: Exclude<SizeType, 'inherit' | 'xs' | 'xxs'> = 'lg'

// -- Render -------------------------------------------- //
public override render() {
this.style.cssText = `--local-color: var(--wui-color-${this.color});`

this.dataset['size'] = this.size

return html`<svg viewBox="25 25 50 50">
<circle r="20" cy="50" cx="50"></circle>
</svg>`
Expand Down
23 changes: 22 additions & 1 deletion packages/ui/src/components/wui-loading-spinner/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@ export default css`
display: flex;
}
svg {
:host([data-size='sm']) > svg {
width: 12px;
height: 12px;
}
:host([data-size='md']) > svg {
width: 14px;
height: 14px;
}
:host([data-size='lg']) > svg {
width: 24px;
height: 24px;
}
svg {
animation: rotate 2s linear infinite;
transition: all var(--wui-ease-in-power-3) var(--wui-duration-lg);
}
Expand All @@ -22,6 +35,14 @@ export default css`
animation: dash 1.5s ease-in-out infinite;
}
:host([data-size='md']) > svg > circle {
stroke-width: 6px;
}
:host([data-size='sm']) > svg > circle {
stroke-width: 8px;
}
@keyframes rotate {
100% {
transform: rotate(360deg);
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/composites/wui-account-button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class WuiAccountButton extends LitElement {
return html`
<button ?disabled=${this.disabled}>
${this.balanceTemplate()}
<wui-flex gap="xxs" alignItems="center" class=${this.balance ? '' : 'noBalance'}>
<wui-flex gap="xxs" alignItems="center" class=${this.balance ? undefined : 'noBalance'}>
<wui-avatar
.imageSrc=${this.avatarSrc}
alt=${this.address}
Expand Down
10 changes: 4 additions & 6 deletions packages/ui/src/composites/wui-connect-button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WuiConnectButton extends LitElement {
<button
data-size=${this.size}
?disabled=${this.disabled}
class=${this.loading ? 'loading' : ''}
class=${this.loading && 'loading'}
ontouchstart
>
${this.loadingTemplate()}
Expand All @@ -40,13 +40,11 @@ export class WuiConnectButton extends LitElement {
}

public loadingTemplate() {
if (this.loading) {
return html`<svg viewBox="25 25 50 50">
<circle r="20" cy="50" cx="50"></circle>
</svg>`
if (!this.loading) {
return null
}

return html``
return html`<wui-loading-spinner size=${this.size} color="accent-100"></wui-loading-spinner>`
}
}

Expand Down
46 changes: 8 additions & 38 deletions packages/ui/src/composites/wui-connect-button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,52 +69,22 @@ export default css`
padding-left: var(--wui-spacing-3xs);
}
button.loading > wui-text,
button.loading > wui-loading-spinner {
button.loading > wui-text {
color: var(--wui-color-accent-100);
}
svg {
wui-loading-spinner {
width: 14px;
height: 14px;
animation: rotate 2s linear infinite;
transition: all var(--wui-ease-in-power-3) var(--wui-duration-lg);
}
button[data-size='sm'] > svg {
width: 12px;
height: 12px;
}
circle {
fill: none;
stroke: var(--wui-color-accent-100);
stroke-width: 8px;
stroke-dasharray: 1, 124;
stroke-dashoffset: 0;
stroke-linecap: round;
animation: dash 1.5s ease-in-out infinite;
}
@keyframes rotate {
100% {
transform: rotate(360deg);
}
wui-loading-spinner::slotted(svg) {
width: 10px !important;
height: 10px !important;
}
@keyframes dash {
0% {
stroke-dasharray: 1, 124;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 90, 124;
stroke-dashoffset: -35;
}
100% {
stroke-dashoffset: -125;
}
button[data-size='sm'] > wui-loading-spinner {
width: 12px;
height: 12px;
}
`

0 comments on commit 6d7c639

Please sign in to comment.