|
| 1 | +import { defineElement } from '@umbraco-ui/uui-base/lib/registration'; |
| 2 | +import { css, LitElement } from 'lit'; |
| 3 | +import { property } from 'lit/decorators.js'; |
| 4 | + |
| 5 | +/** |
| 6 | + * @element uui-divider |
| 7 | + * @cssprop --uui-divider-width - Divider width |
| 8 | + * @cssprop --uui-divider-color - Divider color |
| 9 | + * @cssprop --uui-divider-spacing - Spacing around the divider |
| 10 | + */ |
| 11 | +@defineElement('uui-divider') |
| 12 | +export class UUIDividerElement extends LitElement { |
| 13 | + /** |
| 14 | + * Draws the divider in a vertical orientation. |
| 15 | + * @type {boolean} |
| 16 | + * @attr |
| 17 | + * @default false |
| 18 | + **/ |
| 19 | + @property({ type: Boolean, reflect: true }) vertical = false; |
| 20 | + |
| 21 | + connectedCallback() { |
| 22 | + super.connectedCallback(); |
| 23 | + this.setAttribute('role', 'separator'); |
| 24 | + } |
| 25 | + |
| 26 | + updated(_changedProperties: Map<string | number | symbol, unknown>) { |
| 27 | + super.updated(_changedProperties); |
| 28 | + if (_changedProperties.has('vertical')) { |
| 29 | + this.setAttribute( |
| 30 | + 'aria-orientation', |
| 31 | + this.vertical ? 'vertical' : 'horizontal', |
| 32 | + ); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + static styles = [ |
| 37 | + css` |
| 38 | + :host(:not([vertical])) { |
| 39 | + display: block; |
| 40 | + border-top: var(--uui-divider-width, 1px) solid |
| 41 | + var(--uui-divider-color, var(--uui-color-border)); |
| 42 | + margin: var(--uui-divider-spacing) 0; |
| 43 | + } |
| 44 | +
|
| 45 | + :host([vertical]) { |
| 46 | + display: inline-block; |
| 47 | + height: 100%; |
| 48 | + border-left: solid var(--uui-divider-border-width, 1px) |
| 49 | + var(--uui-divider-color, var(--uui-color-border)); |
| 50 | + margin: 0 var(--uui-divider-spacing); |
| 51 | + } |
| 52 | + `, |
| 53 | + ]; |
| 54 | +} |
| 55 | + |
| 56 | +declare global { |
| 57 | + interface HTMLElementTagNameMap { |
| 58 | + 'uui-divider': UUIDividerElement; |
| 59 | + } |
| 60 | +} |
0 commit comments