-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
362f940
commit 33c5491
Showing
8 changed files
with
280 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/gallery/stories/composites/wui-connect-button.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / code_style (lint)
|
||
|
||
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>` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
120
packages/ui/src/composites/wui-connect-button/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters