Skip to content

Commit

Permalink
various ui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvoskamp committed Sep 5, 2023
1 parent 362f940 commit 33c5491
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 14 deletions.
7 changes: 7 additions & 0 deletions apps/gallery/stories/composites/wui-account-button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ type Component = Meta<WuiAccountButton>
export default {
title: 'Composites/wui-account-button',
args: {
disabled: false,
networkSrc: networkImageSrc,
avatarSrc: avatarImageSrc,
address,
balance: '0.527 ETH'
},
argTypes: {
disabled: {
control: { type: 'boolean' }
}
}
} as Component

export const Default: Component = {
render: args =>
html`<wui-account-button
?disabled=${args.disabled}
.networkSrc=${args.networkSrc}
.avatarSrc=${args.avatarSrc}
.balance=${args.balance}
Expand Down
39 changes: 39 additions & 0 deletions apps/gallery/stories/composites/wui-connect-button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { Meta } from '@storybook/web-components'
import '@web3modal/ui/src/composites/wui-connect-button'
import type { WuiConnectButton } from '@web3modal/ui/src/composites/wui-connect-button'
import { html } from 'lit'
import { buttonOptions, iconOptions } from '../../utils/PresetUtils'

Check failure on line 5 in apps/gallery/stories/composites/wui-connect-button.stories.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

'buttonOptions' is defined but never used

Check failure on line 5 in apps/gallery/stories/composites/wui-connect-button.stories.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

'iconOptions' is defined but never used

type Component = Meta<WuiConnectButton>

export default {
title: 'Composites/wui-connect-button',
args: {
size: 'md',
disabled: false,
loading: false,
text: 'Connect Wallet'
},
argTypes: {
size: {
options: ['sm', 'md'],
control: { type: 'select' }
},
disabled: {
control: { type: 'boolean' }
},
loading: {
control: { type: 'boolean' }
}
}
} as Component

export const Default: Component = {
render: args =>
html`<wui-connect-button
size=${args.size}
?loading=${args.loading}
?disabled=${args.disabled}
text=${args.text}
></wui-connect-button>`
}
10 changes: 6 additions & 4 deletions packages/ui/src/composites/wui-account-button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ export class WuiAccountButton extends LitElement {

@property() public balance?: string = undefined

@property({ type: Boolean }) public disabled = false

@property() public address = ''

// -- Render -------------------------------------------- //
public override render() {
return html`
<button>
<button ?disabled=${this.disabled}>
${this.balanceTemplate()}
<wui-flex gap="xxs" alignItems="center">
<wui-flex gap="xxs" alignItems="center" class=${this.balance ? '' : 'noBalance'}>
<wui-avatar
.imageSrc=${this.avatarSrc}
alt=${this.address}
address=${this.address}
></wui-avatar>
<wui-text variant="paragraph-600" color="inverse-100">
<wui-text variant="paragraph-600" color="inherit">
${UiHelperUtil.getTruncateAddress(this.address, 4)}
</wui-text>
</wui-flex>
Expand All @@ -57,7 +59,7 @@ export class WuiAccountButton extends LitElement {

return html`
${networkElement}
<wui-text variant="paragraph-600" color="fg-100"> ${this.balance} </wui-text>
<wui-text variant="paragraph-600" color="inherit"> ${this.balance} </wui-text>
`
}

Expand Down
55 changes: 48 additions & 7 deletions packages/ui/src/composites/wui-account-button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,75 @@ export default css`
gap: var(--wui-spacing-xs);
padding: var(--wui-spacing-3xs) var(--wui-spacing-xs) var(--wui-spacing-3xs)
var(--wui-spacing-xs);
border: 1px solid var(--wui-overlay-005);
}
button:disabled {
background: var(--wui-overlay-015);
}
button:disabled > wui-text {
color: var(--wui-overlay-015);
}
button:disabled > wui-flex > wui-text {
color: var(--wui-overlay-015);
}
button:disabled > wui-image,
button:disabled > wui-icon-box,
button:disabled > wui-flex > wui-avatar {
filter: grayscale(1);
}
button:has(wui-image) {
padding: var(--wui-spacing-3xs) var(--wui-spacing-3xs) var(--wui-spacing-3xs)
var(--wui-spacing-xs);
}
wui-text {
color: var(--wui-color-fg-100);
}
wui-flex > wui-text {
color: var(--wui-color-fg-200);
transition: all var(--wui-ease-out-power-1) var(--wui-duration-lg);
}
wui-image,
wui-icon-box {
border-radius: var(--wui-border-radius-3xl);
width: 24px;
height: 24px;
}
wui-icon-box {
border: 1px solid var(--wui-overlay-010);
outline: 2px solid var(--wui-overlay-005);
}
wui-flex {
border-radius: var(--wui-border-radius-3xl);
border: 1px solid var(--wui-overlay-010);
background: var(--wui-color-accent-100);
border: 1px solid var(--wui-overlay-005);
background: var(--wui-overlay-005);
padding: 4px var(--wui-spacing-m) 4px var(--wui-spacing-xxs);
}
wui-flex.noBalance {
border-radius: 0px;
border: none;
background: transparent;
}
wui-avatar {
width: 20px;
height: 20px;
border: 2px solid var(--wui-color-accent-080);
outline: 2px solid var(--wui-overlay-010);
}
@media (hover: hover) and (pointer: fine) {
button:hover:enabled > wui-flex > wui-text {
color: var(--wui-color-fg-175);
}
button:active:enabled > wui-flex > wui-text {
color: var(--wui-color-fg-175);
}
}
`
57 changes: 57 additions & 0 deletions packages/ui/src/composites/wui-connect-button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { html, LitElement } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import '../../components/wui-icon/index.js'
import '../../components/wui-loading-spinner/index.js'
import '../../components/wui-text/index.js'
import { elementStyles, resetStyles } from '../../utils/ThemeUtil.js'
import type { ButtonType, SizeType } from '../../utils/TypesUtil.js'
import styles from './styles.js'

@customElement('wui-connect-button')
export class WuiConnectButton extends LitElement {
public static override styles = [resetStyles, elementStyles, styles]

// -- State & Properties -------------------------------- //
@property() public size: Exclude<SizeType, 'inherit' | 'lg' | 'xs' | 'xxs'> = 'md'

@property({ type: Boolean }) public disabled = false

@property({ type: Boolean }) public loading = false

@property() public text = 'Connect Wallet'

// -- Render -------------------------------------------- //
public override render() {
const textVariant = this.size === 'md' ? 'paragraph-600' : 'small-600'

return html`
<button
data-size=${this.size}
?disabled=${this.disabled}
class=${this.loading ? 'loading' : ''}
ontouchstart
>
${this.loadingTemplate()}
<wui-text variant=${textVariant} color="inherit">
${this.loading ? 'Connecting...' : this.text}
</wui-text>
</button>
`
}

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

return html``
}
}

declare global {
interface HTMLElementTagNameMap {
'wui-connect-button': WuiConnectButton
}
}
120 changes: 120 additions & 0 deletions packages/ui/src/composites/wui-connect-button/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { css } from 'lit'

export default css`
:host {
width: var(--local-width);
position: relative;
}
button {
background: var(--wui-color-accent-100);
border: 1px solid var(--wui-overlay-010);
border-radius: var(--wui-border-radius-m);
gap: var(--wui-spacing-xs);
}
button.loading {
background: var(--wui-overlay-010);
border: 1px solid var(--wui-overlay-010);
pointer-events: none;
}
button:disabled {
background-color: var(--wui-overlay-015);
border: 1px solid var(--wui-overlay-010);
}
button:disabled > wui-text {
color: var(--wui-overlay-015);
}
@media (hover: hover) and (pointer: fine) {
button:hover:enabled {
background-color: var(--wui-color-accent-090);
}
button:active:enabled {
background-color: var(--wui-color-accent-080);
}
}
button:focus-visible {
border: 1px solid var(--wui-overlay-010);
background-color: var(--wui-color-accent-090);
-webkit-box-shadow: 0px 0px 0px 4px var(--wui-box-shadow-blue);
-moz-box-shadow: 0px 0px 0px 4px var(--wui-box-shadow-blue);
box-shadow: 0px 0px 0px 4px var(--wui-box-shadow-blue);
}
button[data-size='sm'] {
padding: 6.75px 10px 7.25px;
}
::slotted(*) {
transition: opacity 200ms ease-in-out;
opacity: var(--local-opacity-100);
}
button > wui-text {
transition: opacity 200ms ease-in-out;
opacity: var(--local-opacity-100);
color: var(--wui-color-inverse-100);
}
button[data-size='md'] {
padding: 9px var(--wui-spacing-l) 9px var(--wui-spacing-l);
}
button[data-size='md'] + wui-text {
padding-left: var(--wui-spacing-3xs);
}
button.loading > wui-text,
button.loading > wui-loading-spinner {
color: var(--wui-color-accent-100);
}
svg {
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);
}
}
@keyframes dash {
0% {
stroke-dasharray: 1, 124;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 90, 124;
stroke-dashoffset: -35;
}
100% {
stroke-dashoffset: -125;
}
}
`
4 changes: 2 additions & 2 deletions packages/ui/src/composites/wui-transaction-visual/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export class WuiTransactionVisual extends LitElement {
let icon: TransactionIconType = 'arrowTop'

if (outgoing.includes(this.type)) {
color = 'inverse-100'
color = 'accent-100'
icon = 'arrowTop'
} else if (incoming.includes(this.type) && nft.includes(this.type)) {
color = 'accent-100'
color = 'success-100'
icon = 'arrowBottom'
} else if (incoming.includes(this.type) && currency.includes(this.type)) {
color = 'success-100'
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/utils/ThemeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function createRootStyles(themeVariables: ThemeVariables) {
var(--w3m-color-mix) var(--w3m-color-mix-strength),
var(--wui-icon-box-bg-error-base-100)
);
--wui-icon-box-bg-blue-100: color-mix(
--wui-icon-box-bg-accent-100: color-mix(
in srgb,
var(--w3m-color-mix) var(--w3m-color-mix-strength),
var(--wui-icon-box-bg-blue-base-100)
Expand Down

0 comments on commit 33c5491

Please sign in to comment.