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

fix(core): blur event will trigger on gap outside dock-wrapper #4

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions packages/dockbar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@
<body>
<button id="toggleDirection">Change direction(horizontal)</button>
<button id="togglePosition">Change Position(bottom)</button>
padding: <input type="range" id="padding" value="0" min="0" max="100" />
padding: <input type="range" id="padding" value="8" min="0" max="100" />
maxScale: <input type="range" id="maxScale" value="0" min="0" max="10" />
size: <input type="range" id="size" value="40" min="20" max="100" />
gap: <input type="range" id="gap" value="8" min="0" max="100" />


<dock-wrapper class="glass" id="dock">
Expand All @@ -116,6 +117,7 @@
const paddingInput = $id('padding')
const maxScaleInput = $id('maxScale')
const sizeInput = $id('size')
const gapInput = $id('gap')
const dock = $id('dock')

paddingInput.oninput = function (e) {
Expand All @@ -127,7 +129,10 @@
sizeInput.oninput = function (e) {
dock.setAttribute('size', e.target.value)
}

gapInput.oninput = function (e) {
dock.setAttribute('gap', e.target.value)
}

// const fragment = document.createDocumentFragment()
// for (let i = 0; i < 15; i++) {
// const dockItem = document.createElement('dock-item')
Expand Down
51 changes: 46 additions & 5 deletions packages/dockbar/src/components/dock-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export class DockItem extends LitElement {
@property({ type: Number })
scale = 1

get liStyle() {
@property({ type: Number })
gap = 8

get sizeStyle() {
const styleObj = {
width: `${this.size}px`,
height: `${this.size}px`,
Expand All @@ -24,11 +27,21 @@ export class DockItem extends LitElement {
}, '')
}

get gapStyle() {
return `--gap: ${this.gap}px`
}

get liStyle() {
return `${this.sizeStyle};${this.gapStyle}`
}

render() {
return html`
<li class="dock-item">
<div class="dock-item__scale" style=${this.liStyle}>
<slot></slot>
<li class="dock-item" style=${this.liStyle}>
<div class="dock-item__pos">
<div class="dock-item__scale" style=${this.sizeStyle}>
<slot></slot>
</div>
</div>
</li>
`
Expand All @@ -40,8 +53,17 @@ export class DockItem extends LitElement {
}

onScaleChanged(scale: number) {
const sizeEl = this.shadowRoot?.querySelector('.dock-item')
const scaleEl = this.shadowRoot?.querySelector('.dock-item__scale')
anime({
targets: sizeEl,
width: `${this.size * scale}px`,
height: `${this.size * scale}px`,
duration: 100,
easing: this.easing,
})
anime({
targets: this.shadowRoot?.querySelector('.dock-item__scale'),
targets: scaleEl,
scale,
duration: 100,
easing: this.easing,
Expand All @@ -50,11 +72,30 @@ export class DockItem extends LitElement {

static styles = css`
li.dock-item {
position: relative;
}
li.dock-item .dock-item__pos {
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%) scale(var(--scale, 1));
}
li::before,
li::after {
content: "";
width: var(--gap, 0px);
height: 100%;
position: absolute;
top: 0;
/* For debug */
/* background: red; */
}
li::before {
right: 100%
}
li::after {
left: 100%;
}
.dock-item__scale {
display: flex;
justify-content: center;
Expand Down
34 changes: 3 additions & 31 deletions packages/dockbar/src/components/dock-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LitElement, css, html } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import anime from 'animejs/lib/anime.es.js'

export type DockPosition = 'top' | 'right' | 'bottom' | 'left'
export type DockDirection = 'horizontal' | 'vertical'
Expand Down Expand Up @@ -54,12 +53,6 @@ export class DockWrapper extends LitElement {
this._children = nodes.filter(
(node: any) => node.nodeName.toUpperCase() === 'DOCK-ITEM',
)
this._children.forEach((element: any) => {
element.style.setProperty('flex-shrink', '0')
element.style.setProperty('display', 'flex')
element.style.setProperty('position', 'relative')
})
this.onSizeChanged(this.size)
this.onWillChangeChanged(this.willChange)
this.observe()
this.provideSharedProps()
Expand Down Expand Up @@ -104,13 +97,6 @@ export class DockWrapper extends LitElement {

resetAll() {
this._children.forEach((child) => {
anime({
targets: child,
width: `${this.size}px`,
height: `${this.size}px`,
duration: 100,
easing: this.easing,
})
child.setAttribute('scale', '1')
})
}
Expand Down Expand Up @@ -152,13 +138,6 @@ export class DockWrapper extends LitElement {
= distance > this.maxRange
? 1
: 1 + (this.maxScale - 1) * (1 - distance / this.maxRange)
anime({
targets: child,
width: `${this.size * scale}px`,
height: `${this.size * scale}px`,
duration: 100,
easing: this.easing,
})
child.setAttribute('scale', `${scale}`)
})
}
Expand Down Expand Up @@ -203,14 +182,7 @@ export class DockWrapper extends LitElement {
this._children?.forEach((el) => {
el.setAttribute('size', `${this.size}`)
el.setAttribute('easing', `${this.easing}`)
})
}

onSizeChanged(size: number) {
this.provideSharedProps()
this._children.forEach((child) => {
child.style.setProperty('width', `${size}px`)
child.style.setProperty('height', `${size}px`)
el.setAttribute('gap', `${this.gap}`)
})
}

Expand All @@ -219,8 +191,8 @@ export class DockWrapper extends LitElement {
setTimeout(this.onResize.bind(this))
if (changedProperties.has('willChange'))
this.onWillChangeChanged(this.willChange)
if (changedProperties.has('size'))
this.onSizeChanged(this.size)
if (['size', 'gap', 'easing'].some(key => changedProperties.has(key)))
this.provideSharedProps()
}

static styles = css`
Expand Down