|
| 1 | +import { AkLitElement } from "../component-base.js"; |
| 2 | +import styles from "./ak-divider.css"; |
| 3 | + |
| 4 | +import { html } from "lit"; |
| 5 | + |
| 6 | +// These are documented here because they are used by the builder as type constraints. They have |
| 7 | +// only visual consequences, so there's no need for them in the component's codebase. |
| 8 | + |
| 9 | +export const dividerVariant = ["default", "strong", "subtle"] as const; |
| 10 | +export type DividerVariant = (typeof dividerVariant)[number]; |
| 11 | + |
| 12 | +export const dividerOrientation = ["horizontal", "vertical"] as const; |
| 13 | +export type DividerOrientation = (typeof dividerOrientation)[number]; |
| 14 | + |
| 15 | +/** |
| 16 | + * @element ak-divider |
| 17 | + * @summary A visual divider that creates thematic breaks or separation between content sections |
| 18 | + * |
| 19 | + * @attr {string} variant - Visual style variant: "default", "strong", "subtle" |
| 20 | + * @attr {string} orientation - Layout orientation: "horizontal", "vertical" |
| 21 | + * |
| 22 | + * @slot - Optional content to display in the middle of the divider line |
| 23 | + * |
| 24 | + * @csspart divider - The main container element for the divider |
| 25 | + * @csspart line - The line elements (before and after content if content exists) |
| 26 | + * @csspart line start - The line element before content (when content is present) |
| 27 | + * @csspart line end - The line element after content (when content is present) |
| 28 | + * @csspart content - The wrapper around the slotted content |
| 29 | + * |
| 30 | + * @cssprop --pf-v5-c-divider--line-thickness - Width/thickness of the divider line |
| 31 | + * @cssprop --pf-v5-c-divider--color - Default color of the divider line |
| 32 | + * @cssprop --pf-v5-c-divider--strong-color - Color for the "strong" variant |
| 33 | + * @cssprop --pf-v5-c-divider--subtle-color - Color for the "subtle" variant |
| 34 | + * @cssprop --pf-v5-c-divider--display - Display type for the host element |
| 35 | + * @cssprop --pf-v5-c-divider--flex-direction - Flex direction for the divider container |
| 36 | + * @cssprop --pf-v5-c-divider--content-spacing - Spacing between content and lines |
| 37 | + * @cssprop --pf-v5-c-divider--height - Height of the divider component |
| 38 | + * @cssprop --pf-v5-c-divider--margin - Margin around the divider |
| 39 | + * @cssprop --pf-v5-c-divider__line--before--top - Top position of the line pseudo-element |
| 40 | + * @cssprop --pf-v5-c-divider__line--before--left - Left position of the line pseudo-element |
| 41 | + * @cssprop --pf-v5-c-divider__line--before--right - Right position of the line pseudo-element |
| 42 | + * @cssprop --pf-v5-c-divider__line--before--width - Width of the line pseudo-element |
| 43 | + * @cssprop --pf-v5-c-divider__line--before--height - Height of the line pseudo-element |
| 44 | + */ |
| 45 | +export class Divider extends AkLitElement { |
| 46 | + static readonly styles = [styles]; |
| 47 | + |
| 48 | + render() { |
| 49 | + // The `null` slot means use the unnamed slot; usually only for one-slot components. |
| 50 | + const hasContent = this.hasSlotted(null); |
| 51 | + return html`<div part="divider"> |
| 52 | + ${hasContent |
| 53 | + ? html` <span part="line start"></span> |
| 54 | + <span part="content"><slot></slot></span> |
| 55 | + <span part="line end"></span>` |
| 56 | + : html` <span part="line"></span> `} |
| 57 | + </div> `; |
| 58 | + } |
| 59 | +} |
0 commit comments