diff --git a/components/composition/Collapse/Collapse.stories.ts b/components/composition/Collapse/Collapse.stories.ts new file mode 100644 index 0000000..9a85f1d --- /dev/null +++ b/components/composition/Collapse/Collapse.stories.ts @@ -0,0 +1,62 @@ +import { StoryObj } from '@storybook/web-components'; +import { html } from 'lit'; + +import './Collapse'; + +const description = ` +Animates the expansion and collapse of content within +when the open prop is toggled. + +The button to control the collapse must include aria-controls and aria-expanded attributes. +`; + +export default { + component: 'diamond-collapse', + parameters: { + docs: { + description: { + component: description, + }, + }, + }, +}; + +export const Collapse: StoryObj = { + render: () => html` + + + + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse + suscipit leo sodales sem sollicitudin maximus. +

+

+ Vestibulum viverra turpis sed nisl malesuada lacinia. Aliquam turpis + mauris, egestas vulputate erat ut, maximus efficitur augue. Phasellus in + ante sit amet enim tristique viverra aliquam vitae libero. +

+

+ Nulla id enim vehicula, varius leo et, sagittis libero. Nam vel dolor + fringilla, viverra massa ut, pharetra enim. Praesent non varius nisl. +

+
+ + `, +}; diff --git a/components/composition/Collapse/Collapse.ts b/components/composition/Collapse/Collapse.ts new file mode 100644 index 0000000..ccd25c0 --- /dev/null +++ b/components/composition/Collapse/Collapse.ts @@ -0,0 +1,59 @@ +import { LitElement, css, html } from 'lit'; +import { customElement, property } from 'lit/decorators.js'; + +import { JSXCustomElement } from '../../../types/jsx-custom-element'; + +export interface CollapseAttributes { + open?: boolean; +} + +@customElement('diamond-collapse') +export class Collapse extends LitElement { + @property({ reflect: true, type: Boolean }) open?: boolean; + + static readonly styles = [ + css` + :host { + content-visibility: hidden; + display: grid; + grid-template-rows: 0fr; + overflow: hidden; + transition: + grid-template-rows var(--diamond-transition), + content-visibility var(--diamond-transition); + transition-behavior: allow-discrete; + } + + :host([open]:not([open='false'])) { + content-visibility: visible; + grid-template-rows: 1fr; + } + + .diamond-collapse__content { + overflow: hidden; + } + `, + ]; + + render() { + return html` +
+ +
+ `; + } +} + +declare global { + interface HTMLElementTagNameMap { + 'diamond-collapse': CollapseAttributes; + } +} + +declare module 'react' { + namespace JSX { + interface IntrinsicElements { + 'diamond-collapse': JSXCustomElement; + } + } +} diff --git a/components/composition/Dialog/Dialog.stories.ts b/components/composition/Dialog/Dialog.stories.ts index f6f1af8..a01f877 100644 --- a/components/composition/Dialog/Dialog.stories.ts +++ b/components/composition/Dialog/Dialog.stories.ts @@ -29,7 +29,9 @@ export default { export const Dialog: StoryObj = { render: () => html` - + + +