Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
67 changes: 67 additions & 0 deletions dev/src/pages/kitchen-sink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,68 @@ const SwitchJS: Component = () => {
);
};

const Collapse: Component = () => {
const [show, toggleShow] = createSignal(true);

const COLLAPSED_PROPERTIES = {
height: 0,
marginTop: 0,
marginBottom: 0,
paddingTop: 0,
paddingBottom: 0,
borderTopWidth: 0,
borderBottomWidth: 0
};

function getHeight(el: Element): string {
const rect = el.getBoundingClientRect();
return `${rect.height}px`;
}

function onEnter(el: Element, done: VoidFunction) {
const a = el.animate(
[
COLLAPSED_PROPERTIES,
{
height: getHeight(el)
}
],
{ duration: 500, easing: "ease" }
);

a.finished.then(done);
}

function onExit(el: Element, done: VoidFunction) {
const a = el.animate(
[
{
height: getHeight(el)
},
COLLAPSED_PROPERTIES
],
{ duration: 500, easing: "ease" }
);

a.finished.then(done);
}

return (
<>
<button onClick={() => toggleShow(!show())}>{show() ? "Hide" : "Show"}</button>
<br />
<Transition mode="outin" name="collapse" onEnter={onEnter} onExit={onExit}>
<Show when={show()}>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris facilisis enim libero,
at lacinia diam fermentum id. Pellentesque habitant morbi tristique senectus et netus.
</p>
</Show>
</Transition>
</>
);
};

const Example = () => {
const [show, toggleShow] = createSignal(true);

Expand Down Expand Up @@ -164,6 +226,11 @@ const Example = () => {
<SwitchJS />
<br />

<b>Collapse OutIn CSS & JS</b>
<br />
<Collapse />
<br />

<b>Group</b>
<br />
<Group />
Expand Down
5 changes: 5 additions & 0 deletions dev/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ button {
}
}

.collapse-exit-active,
.collapse-enter-active {
overflow: hidden;
}

.group-item {
transition: all 0.5s;
}
Expand Down