Skip to content

Instantly share code, notes, and snippets.

@vnphanquang
Created July 27, 2023 07:23
Show Gist options
  • Save vnphanquang/da0cccb32035f67ddf2e3907b232e574 to your computer and use it in GitHub Desktop.
Save vnphanquang/da0cccb32035f67ddf2e3907b232e574 to your computer and use it in GitHub Desktop.
Dropdown with vanilla CSS transition
<script lang="ts">
export let open = false;
let cls ='';
export { cls as class };
</script>
<div class="grid-collapsible {cls}" data-open={open.toString()}>
<div class="grid-collapsible-content">
<slot />
</div>
</div>
<style lang="postcss">
.grid-collapsible {
--transition-duration: 250ms;
--template-rows-transition: grid-template-rows var(--transition-duration) ease-out;
display: grid;
grid-template-rows: 0fr;
transition: var(--template-rows-transition) box-shadow 1ms var(--transition-duration);
&[data-open="true"] {
grid-template-rows: 1fr;
transition: var(--template-rows-transition);
}
}
.grid-collapsible-content {
overflow: hidden;
}
</style>
<script context="module" lang="ts">
type SingleSelectBaseOption = string | { label: string; value: string };
</script>
<script lang='ts' generics="T extends SingleSelectBaseOption">
import { GridCollapsible } from '$client/components/grid-collapsible';
// eslint-disable-next-line no-undef
type Option = T;
export let options: Option[];
</script>
<GridCollapsible>
</GridCollapsible>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment