-
Notifications
You must be signed in to change notification settings - Fork 53
Split panel #594
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
Closed
Closed
Split panel #594
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7c4dfc8
Add split panel component
bjarnef 58f926f
Update stories
bjarnef b4a32ad
Min and max story
bjarnef 738a9c2
Nested split panels story
bjarnef 511f69c
Direction property
bjarnef 824d9cc
Direction arg type
bjarnef 2a5e7dd
Add resize observer
bjarnef 54381c0
Handle disabled change
bjarnef 3126684
Simplify exports
bjarnef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,31 @@ | ||
# uui-resize-observer | ||
|
||
 | ||
|
||
Umbraco style resize-observer component. | ||
|
||
## Installation | ||
|
||
### ES imports | ||
|
||
```zsh | ||
npm i @umbraco-ui/uui-resize-observer | ||
``` | ||
|
||
Import the registration of `<uui-resize-observer>` via: | ||
|
||
```javascript | ||
import '@umbraco-ui/uui-resize-observer'; | ||
``` | ||
|
||
When looking to leverage the `UUIResizeObserverElement` base class as a type and/or for extension purposes, do so via: | ||
|
||
```javascript | ||
import { UUIResizeObserverElement } from '@umbraco-ui/uui-resize-observer'; | ||
``` | ||
|
||
## Usage | ||
|
||
```html | ||
<uui-resize-observer></uui-resize-observer> | ||
``` |
This file contains hidden or 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,13 @@ | ||
import { UUIEvent } from '@umbraco-ui/uui-base/lib/events'; | ||
import { UUIResizeObserverElement } from './uui-resize-observer.element'; | ||
|
||
export class UUIResizeEvent extends UUIEvent<{}, UUIResizeObserverElement> { | ||
public static readonly CHANGE = 'change'; | ||
|
||
constructor(evName: string, eventInit: any | null = {}) { | ||
super(evName, { | ||
...{ bubbles: true }, | ||
...eventInit, | ||
}); | ||
} | ||
} |
This file contains hidden or 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 @@ | ||
export * from './uui-resize-observer.element'; |
91 changes: 91 additions & 0 deletions
91
packages/uui-resize-observer/lib/uui-resize-observer.element.ts
This file contains hidden or 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,91 @@ | ||
import { defineElement } from '@umbraco-ui/uui-base/lib/registration'; | ||
import { property } from 'lit/decorators.js'; | ||
import { css, html, LitElement } from 'lit'; | ||
|
||
import { UUIResizeEvent } from './UUIResizeEvent'; | ||
|
||
/** | ||
* @element uui-resize-observer | ||
*/ | ||
@defineElement('uui-resize-observer') | ||
export class UUIResizeObserverElement extends LitElement { | ||
static styles = [ | ||
css` | ||
:host { | ||
display: contents; | ||
} | ||
`, | ||
]; | ||
|
||
private _resizeObserver!: ResizeObserver; | ||
private _observedElements: HTMLElement[] = []; | ||
|
||
/** Disables the observer. */ | ||
@property({ type: Boolean, reflect: true }) disabled = false; | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
this._resizeObserver = new ResizeObserver((entries: ResizeObserverEntry[]) => { | ||
this.dispatchEvent(new UUIResizeEvent(UUIResizeEvent.CHANGE)); | ||
}); | ||
|
||
if (!this.disabled) { | ||
this.startObserver(); | ||
} | ||
} | ||
|
||
disconnectedCallback() { | ||
super.disconnectedCallback(); | ||
this.stopObserver(); | ||
} | ||
|
||
private handleSlotChange() { | ||
if (!this.disabled) { | ||
this.startObserver(); | ||
} | ||
} | ||
|
||
private startObserver() { | ||
const slot = this.shadowRoot!.querySelector('slot'); | ||
|
||
if (slot !== null) { | ||
const elements = slot.assignedElements({ flatten: true }) as HTMLElement[]; | ||
|
||
// Unwatch previous elements | ||
this._observedElements.forEach(el => this._resizeObserver.unobserve(el)); | ||
this._observedElements = []; | ||
|
||
// Watch new elements | ||
elements.forEach(el => { | ||
this._resizeObserver.observe(el); | ||
this._observedElements.push(el); | ||
}); | ||
} | ||
} | ||
|
||
private stopObserver() { | ||
this._resizeObserver.disconnect(); | ||
} | ||
|
||
firstUpdated() { | ||
this.handleDisabledChange(); | ||
} | ||
|
||
handleDisabledChange() { | ||
if (this.disabled) { | ||
this.stopObserver(); | ||
} else { | ||
this.startObserver(); | ||
} | ||
} | ||
|
||
render() { | ||
return html` <slot @slotchange=${this.handleSlotChange}></slot> `; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'uui-resize-observer': UUIResizeObserverElement ; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/uui-resize-observer/lib/uui-resize-observer.story.ts
This file contains hidden or 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,26 @@ | ||
import type { Meta, StoryObj } from '@storybook/web-components'; | ||
|
||
import './uui-resize-observer.element'; | ||
import type { UUIResizeObserverElement } from './uui-resize-observer.element'; | ||
import readme from '../README.md?raw'; | ||
|
||
const meta: Meta<UUIResizeObserverElement> = { | ||
id: 'uui-resize-observer', | ||
title: 'Resize Observer', | ||
component: 'uui-resize-observer', | ||
parameters: { | ||
readme: { markdown: readme }, | ||
docs: { | ||
source: { | ||
code: `<uui-resize-observer> | ||
<div>Resize this box</div> | ||
</uui-resize-observer>`, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<UUIResizeObserverElement>; | ||
|
||
export const Overview: Story = {}; |
20 changes: 20 additions & 0 deletions
20
packages/uui-resize-observer/lib/uui-resize-observer.test.ts
This file contains hidden or 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,20 @@ | ||
import { html, fixture, expect } from '@open-wc/testing'; | ||
import { UUIResizeObserverElement } from './uui-resize-observer.element'; | ||
|
||
describe('UUIResizeObserverElement', () => { | ||
let element: UUIResizeObserverElement; | ||
|
||
beforeEach(async () => { | ||
element = await fixture( | ||
html` <uui-resize-observer></uui-resize-observer> ` | ||
); | ||
}); | ||
|
||
it('is defined with its own instance', () => { | ||
expect(element).to.be.instanceOf(UUIResizeObserverElement); | ||
}); | ||
|
||
it('passes the a11y audit', async () => { | ||
await expect(element).shadowDom.to.be.accessible(); | ||
}); | ||
}); |
This file contains hidden or 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,44 @@ | ||
{ | ||
"name": "@umbraco-ui/uui-resize-observer", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"keywords": [ | ||
"Umbraco", | ||
"Custom elements", | ||
"Web components", | ||
"UI", | ||
"Lit", | ||
"Resize Observer" | ||
], | ||
"description": "Umbraco UI resize-observer component", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/umbraco/Umbraco.UI.git", | ||
"directory": "packages/uui-resize-observer" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/umbraco/Umbraco.UI/issues" | ||
}, | ||
"main": "./lib/index.js", | ||
"module": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"type": "module", | ||
"customElements": "custom-elements.json", | ||
"files": [ | ||
"lib/**/*.d.ts", | ||
"lib/**/*.js", | ||
"custom-elements.json" | ||
], | ||
"dependencies": { | ||
"@umbraco-ui/uui-base": "1.5.0-rc.0" | ||
}, | ||
"scripts": { | ||
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js", | ||
"clean": "tsc --build --clean && rimraf -g dist lib/*.js lib/**/*.js *.tgz lib/**/*.d.ts custom-elements.json", | ||
"analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"homepage": "https://uui.umbraco.com/?path=/story/uui-resize-observer" | ||
} |
This file contains hidden or 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,5 @@ | ||
import { UUIProdConfig } from '../rollup-package.config.mjs'; | ||
|
||
export default UUIProdConfig({ | ||
entryPoints: ['index'] | ||
}); |
This file contains hidden or 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,17 @@ | ||
// Don't edit this file directly. It is generated by /scripts/generate-ts-config.js | ||
|
||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./lib", | ||
"rootDir": "./lib", | ||
"composite": true | ||
}, | ||
"include": ["./**/*.ts"], | ||
"exclude": ["./**/*.test.ts", "./**/*.story.ts"], | ||
"references": [ | ||
{ | ||
"path": "../uui-base" | ||
} | ||
] | ||
} |
This file contains hidden or 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,31 @@ | ||
# uui-split-panel | ||
|
||
 | ||
|
||
Umbraco style split-panel component. | ||
|
||
## Installation | ||
|
||
### ES imports | ||
|
||
```zsh | ||
npm i @umbraco-ui/uui-split-panel | ||
``` | ||
|
||
Import the registration of `<uui-split-panel>` via: | ||
|
||
```javascript | ||
import '@umbraco-ui/uui-split-panel'; | ||
``` | ||
|
||
When looking to leverage the `UUISplitPanelElement` base class as a type and/or for extension purposes, do so via: | ||
|
||
```javascript | ||
import { UUISplitPanelElement } from '@umbraco-ui/uui-split-panel'; | ||
``` | ||
|
||
## Usage | ||
|
||
```html | ||
<uui-split-panel></uui-split-panel> | ||
``` |
This file contains hidden or 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 @@ | ||
export * from './uui-split-panel.element'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iOvergaard would
CustomEvent
be better instead of aUUIResizeEvent
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tend to use UUI-events inside the library. They ultimately extend Event. I think it's perfectly fine what you are doing here.