import {OOElement} from '../oo-element' import {html} from '../../lib/html' import weakMap from '../../lib/weak-map' type State = 'open' | 'close' type Direction = 'column' const ATTR = { DATA_DIRECTION: 'data-direction' } const state = weakMap() const direction = weakMap() const asDirection = (d: string): Direction => { if (d === 'column') { return d } return 'column' } export default class extends OOElement { static get observedAttributes() { return [ATTR.DATA_DIRECTION] } constructor() { super() state.set(this, 'close') direction.set(this, asDirection(this.getAttribute(ATTR.DATA_DIRECTION))) } attributeChangedCallback(attr, prev, next) { if (prev === next) { return } direction.set(this, asDirection(next)) if (this.connected) { this.update() } } render() { const {stte, dir} = { stte: state.get(this), dir: direction.get(this) } return html`
` } onHandleClick() { state.set(this, state.get(this) === 'close' ? 'open' : 'close') this.update() } }