Skip to content

Commit

Permalink
Fix Popups
Browse files Browse the repository at this point in the history
It worked before but not now for some reason, ho hum, add some
middleware in to size the new selects correctly.
  • Loading branch information
spjmurray committed Jul 30, 2024
1 parent 50bf1b0 commit 8c1de1f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions charts/ui/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn UI

type: application

version: v0.2.29
appVersion: v0.2.29
version: v0.2.30
appVersion: v0.2.30

icon: https://assets.unikorn-cloud.org/assets/images/logos/dark-on-light/icon.png

Expand Down
28 changes: 22 additions & 6 deletions src/lib/forms/SelectNew.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import { popup } from '@skeletonlabs/skeleton';
import { ListBox } from '@skeletonlabs/skeleton';
import type { PopupSettings } from '@skeletonlabs/skeleton';
import type { SizeOptions } from '@floating-ui/dom';
// Unique element ID.
export let id: string;
Expand All @@ -10,6 +12,23 @@
// Formatting hint.
export let hint: string = '';
let sizeOptions: SizeOptions = {
apply({ rects, elements }) {
Object.assign(elements.floating.style, {
width: `${rects.reference.width}px`
});
}
};
let settings: PopupSettings = {
event: 'click',
target: `select-${id}`,
closeQuery: '.listbox-item',
middleware: {
size: sizeOptions
}
};
</script>

<div class="flex flex-col gap-1">
Expand All @@ -20,16 +39,13 @@
{/if}
</div>

<button
class="btn variant-ghost w-full justify-between"
use:popup={{ event: 'click', target: `select-${id}`, closeQuery: '.listbox-item' }}
>
<button class="btn variant-ghost w-full justify-between" use:popup={settings}>
<slot name="selected_body" />
<iconify-icon icon="ph:caret-down-bold" />
</button>

<div class="w-full py-2i z-10" data-popup={`select-${id}`}>
<div class="card shadow-xl mx-4">
<div class="z-10" data-popup={`select-${id}`}>
<div class="card shadow-xl">
<ListBox>
<slot />
</ListBox>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/(shell)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
/* Required for popups */
import { storePopup } from '@skeletonlabs/skeleton';
import { computePosition, autoUpdate, offset, shift, flip, arrow } from '@floating-ui/dom';
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
import { computePosition, autoUpdate, offset, shift, flip, arrow, size } from '@floating-ui/dom';
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow, size });
/* Shell components */
import { AppShell } from '@skeletonlabs/skeleton';
Expand Down
6 changes: 0 additions & 6 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<script lang="ts">
/* Required for styling */
import '../app.postcss';
/* Required for popups (rich selects essentially) */
import { computePosition, autoUpdate, offset, shift, flip, arrow } from '@floating-ui/dom';
import { storePopup } from '@skeletonlabs/skeleton';
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
</script>

<svelte:head>
Expand Down
12 changes: 1 addition & 11 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,16 @@
provider.register();
/* Required for drawers and modals */
import { initializeStores, Modal } from '@skeletonlabs/skeleton';
import { initializeStores } from '@skeletonlabs/skeleton';
initializeStores();
/* Required for toasts */
import { Toast } from '@skeletonlabs/skeleton';
/* Required for popups */
import { storePopup } from '@skeletonlabs/skeleton';
import { computePosition, autoUpdate, offset, shift, flip, arrow } from '@floating-ui/dom';
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
/* Shell components */
import { AppShell } from '@skeletonlabs/skeleton';
import ShellAppBar from '$lib/shell/ShellAppBar.svelte';
import ShellSideBar from '$lib/shell/ShellSideBar.svelte';
import ShellDrawer from '$lib/shell/ShellDrawer.svelte';
</script>

<Modal />
<Toast />
<ShellDrawer />

<AppShell class="h-screen">
Expand Down

0 comments on commit 8c1de1f

Please sign in to comment.