Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V 3/tabs #1311

Merged
merged 21 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c9db2a3
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 8, 2023
797a677
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 15, 2023
5bb31c4
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 15, 2023
9d7d7fb
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 16, 2023
e4751ef
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 16, 2023
c283ab2
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 21, 2023
035cfef
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 23, 2023
44b0366
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 23, 2023
f00815b
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 25, 2023
482e54e
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Aug 30, 2023
bf7059a
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Sep 4, 2023
362f940
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Sep 5, 2023
9b91647
Merge branch 'V3' of github.com:WalletConnect/web3modal into V3
svenvoskamp Sep 5, 2023
dfee7f2
wip
svenvoskamp Sep 6, 2023
6dc5f3c
tab refactor if length > 3
svenvoskamp Sep 6, 2023
6840421
cleanup
svenvoskamp Sep 6, 2023
d349dd8
tabs animation change
svenvoskamp Sep 6, 2023
9b25a4f
cleanup
svenvoskamp Sep 6, 2023
a5f3413
fix initial
svenvoskamp Sep 6, 2023
6521615
fix initial
svenvoskamp Sep 6, 2023
36c75a7
clean build
svenvoskamp Sep 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 65 additions & 64 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/scaffold/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"dependencies": {
"@web3modal/core": "3.0.0-alpha.5",
"@web3modal/ui": "3.0.0-alpha.5",
"lit": "2.8.0",
"motion": "10.16.2"
"lit": "2.8.0"
},
"keywords": [
"web3",
Expand Down
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"lit": "2.8.0",
"motion": "10.16.2",
svenvoskamp marked this conversation as resolved.
Show resolved Hide resolved
"qrcode": "1.5.3"
},
"devDependencies": {
Expand Down
63 changes: 58 additions & 5 deletions packages/ui/src/composites/wui-tabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { customElement, property, state } from 'lit/decorators.js'
import { elementStyles, resetStyles } from '../../utils/ThemeUtil.js'
import type { IconType } from '../../utils/TypesUtil.js'
import styles from './styles.js'
import { animate } from 'motion'
svenvoskamp marked this conversation as resolved.
Show resolved Hide resolved

@customElement('wui-tabs')
export class WuiTabs extends LitElement {
Expand All @@ -13,36 +14,88 @@ export class WuiTabs extends LitElement {

@property() public onTabChange: (index: number) => void = () => null

@property({ type: Array }) public buttons: HTMLButtonElement[] = []

@state() public activeTab = 0

@state() public localTabWidth = '100px'

@state() public isDense = false

// -- Render -------------------------------------------- //
public override render() {
const isDense = this.tabs.length > 3
this.isDense = this.tabs.length > 3

this.style.cssText = `
--local-tab: ${this.activeTab};
--local-tab-width: ${isDense ? '80px' : '100px'}
--local-tab-width: ${this.localTabWidth};
`

this.dataset['type'] = this.isDense ? 'flex' : 'block'

return this.tabs.map((tab, index) => {
const isActive = index === this.activeTab

return html`
<button @click=${() => this.onTabClick(index)} data-active=${isActive}>
<wui-icon size="sm" color="inherit" name=${tab.icon}></wui-icon>
<wui-text variant=${isDense ? 'tiny-600' : 'small-600'} color="inherit">
${tab.label}
</wui-text>
<wui-text variant="small-600" color="inherit">${tab.label}</wui-text>
</button>
`
})
}

override firstUpdated() {
svenvoskamp marked this conversation as resolved.
Show resolved Hide resolved
if (this.shadowRoot && this.isDense) {
this.buttons = [...this.shadowRoot.querySelectorAll('button')]
setTimeout(() => {
this.animateTabs(0, true)
}, 0)
}
}

// -- Private ------------------------------------------- //
private onTabClick(index: number) {
if (this.buttons) {
this.animateTabs(index, false)
}
this.activeTab = index
this.onTabChange(index)
}

private animateTabs(index: number, initialAnimation: boolean) {
const passiveBtn = this.buttons[this.activeTab]
const activeBtn = this.buttons[index]

const passiveBtnText = passiveBtn?.querySelector('wui-text')
const activeBtnText = activeBtn?.querySelector('wui-text')

const activeBtnBounds = activeBtn?.getBoundingClientRect()
const activeBtnTextBounds = activeBtnText?.getBoundingClientRect()

if (passiveBtn && passiveBtnText && !initialAnimation) {
animate(passiveBtnText, { opacity: 0 }, { duration: 0.25 })
animate(passiveBtn, { width: `20px` }, { duration: 0.25, delay: 0.05 })
}

if (activeBtn && activeBtnBounds && activeBtnTextBounds && activeBtnText) {
this.localTabWidth = `${Math.round(
activeBtnBounds.width + activeBtnTextBounds.width + 6 + 12
)}px`

animate(
activeBtn,
{ width: `${activeBtnBounds.width + activeBtnTextBounds.width + 6}px` },
{ duration: initialAnimation ? 0 : 0.5, delay: initialAnimation ? 0 : 0.1 }
)

animate(
activeBtnText,
{ opacity: 1 },
{ duration: initialAnimation ? 0 : 0.25, delay: initialAnimation ? 0 : 0.15 }
)
}
}
}

declare global {
Expand Down
Loading