Skip to content
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

feat: collapse #55

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions components/composition/Collapse/Collapse.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { StoryObj } from '@storybook/web-components';
import { html } from 'lit';

import './Collapse';

export default {
component: 'diamond-collapse',
gavmck marked this conversation as resolved.
Show resolved Hide resolved
};

export const Collapse: StoryObj = {
render: () => html`
<diamond-button>
<button type="button" id="toggle">Toggle collapse</button>
gavmck marked this conversation as resolved.
Show resolved Hide resolved
</diamond-button>
<diamond-collapse open>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
suscipit leo sodales sem sollicitudin maximus.
</p>
<p>
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.
</p>
<p>
Nulla id enim vehicula, varius leo et, sagittis libero. Nam vel dolor
fringilla, viverra massa ut, pharetra enim. Praesent non varius nisl.
</p>
</diamond-collapse>
<script>
document.getElementById('toggle').addEventListener('click', () => {
const collapse = document.querySelector('diamond-collapse');
collapse.open = !collapse.open;
});
</script>
`,
};
59 changes: 59 additions & 0 deletions components/composition/Collapse/Collapse.ts
Original file line number Diff line number Diff line change
@@ -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 App extends LitElement {
gavmck marked this conversation as resolved.
Show resolved Hide resolved
@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`
<div class="diamond-collapse__content">
<slot></slot>
</div>
`;
}
}

declare global {
interface HTMLElementTagNameMap {
'diamond-collapse': CollapseAttributes;
}
}

declare module 'react' {
namespace JSX {
interface IntrinsicElements {
'diamond-collapse': JSXCustomElement<CollapseAttributes>;
}
}
}
4 changes: 3 additions & 1 deletion components/composition/Dialog/Dialog.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default {

export const Dialog: StoryObj = {
render: () => html`
<button id="toggle">Open dialog</button>
<diamond-button>
<button type="button" id="toggle">Open dialog</button>
</diamond-button>
<dialog>
<diamond-wrap size="xs" gutter="none">
<diamond-card border radius>
Expand Down
Loading