Skip to content

Commit

Permalink
feat: add on_close prop for passing in a callback to perform when Res…
Browse files Browse the repository at this point in the history
…ponsiveSlideover close is triggered
  • Loading branch information
jacob-8 committed Mar 16, 2024
1 parent de2e445 commit 7b39dbe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 48 deletions.
13 changes: 1 addition & 12 deletions src/index.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
<script lang="ts">
import Button from '$lib/ui/Button.svelte';
import { toast } from '$lib/ui/Toasts.svelte';
</script>

# Svelte Pieces

Install with `npm i -D svelte-pieces`.

Built using Kitbook, Windicss, and Iconify icons - you don't need Tailwind nor Windi installed for these components to work properly as the classes get generated at packaging time.

## Smoke Test
<Button onclick={() => toast('hello')}>Push Toast</Button>
Built using Kitbook, UnoCSS, and Iconify icons - you don't need UnoCSS installed for these components to work properly as the classes get generated at packaging time thanks to `@unocss/svelte-scoped`'s [preprocessor](https://unocss.dev/integrations/svelte-scoped#svelte-preprocessor).

{#await import('$lib/ui/Toasts.svelte') then { default: Toasts }}
<Toasts />
{/await}
26 changes: 26 additions & 0 deletions src/lib/ui/ResponsiveSlideover.composition
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="ts">
import ShowHide from '$lib/functions/ShowHide.svelte';
import Button from './Button.svelte';
import ResponsiveSlideover from './ResponsiveSlideover.svelte';

let size: 'sm' | 'md' | 'lg' | 'xl' = 'xl';
</script>

<ShowHide let:show let:toggle>
<Button color="primary" onclick={toggle}>Show Slideover</Button>
<Button form="menu" active={size === 'sm'} onclick={() => size = 'sm'}>Size: sm</Button>
<Button form="menu" active={size === 'md'} onclick={() => size = 'md'}>Size: md</Button>
<Button form="menu" active={size === 'lg'} onclick={() => size = 'lg'}>Size: lg</Button>
<Button form="menu" active={size === 'xl'} onclick={() => size = 'xl'}>Size: xl</Button>

<ResponsiveSlideover showWidth={size} open={show} on_close={toggle}>
<div slot="title">Universal Title</div>
<div class="p-3 border-b font-semibold" slot="heading">Universal Heading</div>
<div class="p-3 border-b font-semibold" slot="desktopHeading">Desktop Heading</div>
<div class="p-3 border-b font-semibold" slot="mobileHeading">Mobile Heading</div>
<div class="p-3 hover:bg-gray-100">Menu Item</div>
<div class="p-3 hover:bg-gray-100">Menu Item</div>
<div class="p-3 hover:bg-gray-100">Menu Item</div>
<div class="p-3 hover:bg-gray-100">Menu Item</div>
</ResponsiveSlideover>
</ShowHide>
34 changes: 0 additions & 34 deletions src/lib/ui/ResponsiveSlideover.md

This file was deleted.

5 changes: 3 additions & 2 deletions src/lib/ui/ResponsiveSlideover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
export let mobileClasses = '';
export let open = false;
export let on_close: () => void = undefined
</script>

<div
Expand Down Expand Up @@ -47,7 +48,7 @@
{side}
{widthRem}
{maxWidthPercentage}
on:close={() => (open = false)}
on:close={on_close}
>
<svelte:fragment slot="heading">
{#if $$slots.mobileTitle}
Expand All @@ -56,7 +57,7 @@
<slot name="mobileTitle" />
</h3>
<button
on:click={() => (open = false)}
on:click={on_close}
type="button"
class="text-gray-400 px-3 py-4 flex hover:text-gray-500 focus:outline-none
focus:text-gray-500 transition ease-in-out duration-150"
Expand Down

0 comments on commit 7b39dbe

Please sign in to comment.