Compare commits
19 Commits
ed48b404d4
...
v1.0.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28c027c48b | ||
|
|
80fc26eb3b | ||
|
|
aa39aaf84f | ||
|
|
2d694a7277 | ||
|
|
ae7d4912f9 | ||
|
|
1c66bc0fcf | ||
|
|
3b659c1e2d | ||
|
|
90ff836061 | ||
|
|
5e5f133763 | ||
|
|
7317d69d9b | ||
|
|
e6d99cdfd2 | ||
|
|
2ae35cf847 | ||
|
|
96daed474b | ||
|
|
eabb0f2dda | ||
|
|
d3c4962495 | ||
|
|
3cdda64686 | ||
|
|
6630051d67 | ||
|
|
bf77a20ff9 | ||
|
|
42c9bc0bcc |
@@ -4,7 +4,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://gitea.auvem.com/svelte-toolkit/sui.git"
|
"url": "https://gitea.auvem.com/svelte-toolkit/sui.git"
|
||||||
},
|
},
|
||||||
"version": "0.3.3",
|
"version": "1.0.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build && pnpm run prepack",
|
"build": "vite build && pnpm run prepack",
|
||||||
|
|||||||
22
pnpm-lock.yaml
generated
22
pnpm-lock.yaml
generated
@@ -4,9 +4,6 @@ settings:
|
|||||||
autoInstallPeers: true
|
autoInstallPeers: true
|
||||||
excludeLinksFromLockfile: false
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
overrides:
|
|
||||||
'@svelte-toolkit/validate': link:../validate
|
|
||||||
|
|
||||||
importers:
|
importers:
|
||||||
|
|
||||||
.:
|
.:
|
||||||
@@ -18,8 +15,8 @@ importers:
|
|||||||
specifier: ^0.2.1
|
specifier: ^0.2.1
|
||||||
version: 0.2.1(svelte@5.38.1)
|
version: 0.2.1(svelte@5.38.1)
|
||||||
'@svelte-toolkit/validate':
|
'@svelte-toolkit/validate':
|
||||||
specifier: link:../validate
|
specifier: ^1.0.1
|
||||||
version: link:../validate
|
version: 1.0.1(svelte@5.38.1)
|
||||||
'@sveltejs/kit':
|
'@sveltejs/kit':
|
||||||
specifier: ^2.20.2
|
specifier: ^2.20.2
|
||||||
version: 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(@types/node@24.2.1)(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(@types/node@24.2.1)(jiti@2.5.1)(lightningcss@1.30.1))
|
version: 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(@types/node@24.2.1)(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(@types/node@24.2.1)(jiti@2.5.1)(lightningcss@1.30.1))
|
||||||
@@ -517,6 +514,11 @@ packages:
|
|||||||
'@standard-schema/spec@1.0.0':
|
'@standard-schema/spec@1.0.0':
|
||||||
resolution: {integrity: sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==}
|
resolution: {integrity: sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==}
|
||||||
|
|
||||||
|
'@svelte-toolkit/validate@1.0.1':
|
||||||
|
resolution: {integrity: sha512-KqyWc9m0nQwG7gay+hbHqwBFcUsb8q5+v7/wEwul7YedSEOwofK3XTLm5m9TSMm3djfhNSBJ+XER8E9YE8TDXA==, tarball: https://gitea.auvem.com/api/packages/svelte-toolkit/npm/%40svelte-toolkit%2Fvalidate/-/1.0.1/validate-1.0.1.tgz}
|
||||||
|
peerDependencies:
|
||||||
|
svelte: ^5.0.0
|
||||||
|
|
||||||
'@sveltejs/acorn-typescript@1.0.5':
|
'@sveltejs/acorn-typescript@1.0.5':
|
||||||
resolution: {integrity: sha512-IwQk4yfwLdibDlrXVE04jTZYlLnwsTT2PIOQQGNLWfjavGifnk1JD1LcZjZaBTRcxZu2FfPfNLOE04DSu9lqtQ==}
|
resolution: {integrity: sha512-IwQk4yfwLdibDlrXVE04jTZYlLnwsTT2PIOQQGNLWfjavGifnk1JD1LcZjZaBTRcxZu2FfPfNLOE04DSu9lqtQ==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -667,6 +669,9 @@ packages:
|
|||||||
'@types/estree@1.0.8':
|
'@types/estree@1.0.8':
|
||||||
resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==}
|
resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==}
|
||||||
|
|
||||||
|
'@types/google.maps@3.58.1':
|
||||||
|
resolution: {integrity: sha512-X9QTSvGJ0nCfMzYOnaVs/k6/4L+7F5uCS+4iUmkLEls6J9S/Phv+m/i3mDeyc49ZBgwab3EFO1HEoBY7k98EGQ==}
|
||||||
|
|
||||||
'@types/json-schema@7.0.15':
|
'@types/json-schema@7.0.15':
|
||||||
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
|
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
|
||||||
|
|
||||||
@@ -1937,6 +1942,11 @@ snapshots:
|
|||||||
|
|
||||||
'@standard-schema/spec@1.0.0': {}
|
'@standard-schema/spec@1.0.0': {}
|
||||||
|
|
||||||
|
'@svelte-toolkit/validate@1.0.1(svelte@5.38.1)':
|
||||||
|
dependencies:
|
||||||
|
'@types/google.maps': 3.58.1
|
||||||
|
svelte: 5.38.1
|
||||||
|
|
||||||
'@sveltejs/acorn-typescript@1.0.5(acorn@8.15.0)':
|
'@sveltejs/acorn-typescript@1.0.5(acorn@8.15.0)':
|
||||||
dependencies:
|
dependencies:
|
||||||
acorn: 8.15.0
|
acorn: 8.15.0
|
||||||
@@ -2086,6 +2096,8 @@ snapshots:
|
|||||||
|
|
||||||
'@types/estree@1.0.8': {}
|
'@types/estree@1.0.8': {}
|
||||||
|
|
||||||
|
'@types/google.maps@3.58.1': {}
|
||||||
|
|
||||||
'@types/json-schema@7.0.15': {}
|
'@types/json-schema@7.0.15': {}
|
||||||
|
|
||||||
'@types/node@24.2.1':
|
'@types/node@24.2.1':
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
overrides:
|
onlyBuiltDependencies:
|
||||||
'@svelte-toolkit/validate': link:../validate
|
- '@tailwindcss/oxide'
|
||||||
|
- esbuild
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
| null;
|
| null;
|
||||||
dismiss?: Omit<BannerControlButton, 'framed'> | null;
|
dismiss?: Omit<BannerControlButton, 'framed'> | null;
|
||||||
/** if true, accept and decline buttons are swapped with more info */
|
/** if true, accept and decline buttons are swapped with more info */
|
||||||
swap?: boolean;
|
swap?: boolean | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultBannerControls: BannerControls = {
|
const defaultBannerControls: BannerControls = {
|
||||||
@@ -58,21 +58,6 @@
|
|||||||
},
|
},
|
||||||
swap: false
|
swap: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const mergeBannerControls = (
|
|
||||||
defaults: BannerControls,
|
|
||||||
overrides: BannerControls | null | undefined
|
|
||||||
): BannerControls => {
|
|
||||||
if (!overrides) return defaults;
|
|
||||||
|
|
||||||
return {
|
|
||||||
accept: overrides.accept ?? defaults.accept,
|
|
||||||
decline: overrides.decline ?? defaults.decline,
|
|
||||||
moreInfo: overrides.moreInfo ?? defaults.moreInfo,
|
|
||||||
dismiss: overrides.dismiss ?? defaults.dismiss,
|
|
||||||
swap: overrides.swap ?? defaults.swap
|
|
||||||
};
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -82,6 +67,7 @@
|
|||||||
import Button from './Button.svelte';
|
import Button from './Button.svelte';
|
||||||
import FramelessButton from './FramelessButton.svelte';
|
import FramelessButton from './FramelessButton.svelte';
|
||||||
import { X } from 'phosphor-svelte';
|
import { X } from 'phosphor-svelte';
|
||||||
|
import { mergeOverrideObject } from './util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Banner provides a simple component to display a banner message with
|
* Banner provides a simple component to display a banner message with
|
||||||
@@ -118,7 +104,7 @@
|
|||||||
children
|
children
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
const controls = $derived(mergeBannerControls(defaultBannerControls, rawControls));
|
const controls = $derived(mergeOverrideObject(defaultBannerControls, rawControls));
|
||||||
|
|
||||||
const api: BannerAPI = {
|
const api: BannerAPI = {
|
||||||
open: () => (open = true),
|
open: () => (open = true),
|
||||||
|
|||||||
@@ -41,30 +41,49 @@
|
|||||||
title: (title: string) => void;
|
title: (title: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DialogControlButton = {
|
||||||
|
/** Label for the button */
|
||||||
|
label?: string;
|
||||||
|
/** Additional classes to apply to the button */
|
||||||
|
class?: ClassValue;
|
||||||
|
/** Callback when the button is pressed */
|
||||||
|
action?: (dialog: DialogAPI) => void;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the default dialog controls.
|
* Configures the default dialog controls.
|
||||||
*/
|
*/
|
||||||
export type DialogControlOpts = {
|
export type DialogControls = {
|
||||||
cancel?: {
|
/** Options for the bottom cancel button */
|
||||||
label?: string;
|
cancel?: DialogControlButton | null;
|
||||||
class?: ClassValue;
|
/** Options for the bottom submit button */
|
||||||
action?: (dialog: DialogAPI) => void;
|
ok?: DialogControlButton | null;
|
||||||
};
|
/** Inverts the order of the buttons */
|
||||||
ok?: {
|
flip?: boolean;
|
||||||
label?: string;
|
|
||||||
class?: ClassValue;
|
|
||||||
action?: (dialog: DialogAPI) => void;
|
|
||||||
};
|
|
||||||
close?: {
|
|
||||||
class?: ClassValue;
|
|
||||||
action?: (dialog: DialogAPI) => void;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores internal state of the dialog, everything necessary to render
|
||||||
|
* internal snippets.
|
||||||
|
*/
|
||||||
|
type DialogState = {
|
||||||
|
frozen: boolean;
|
||||||
|
loading: boolean;
|
||||||
|
disabled: boolean;
|
||||||
|
api: DialogAPI;
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultDialogControls: DialogControls = {
|
||||||
|
cancel: { label: 'Cancel' },
|
||||||
|
ok: { label: 'OK' }
|
||||||
|
};
|
||||||
|
|
||||||
|
export { dialogCancelButton, dialogOkButton, dialogCloseButton };
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Portal } from '@jsrob/svelte-portal';
|
import { Portal } from '@jsrob/svelte-portal';
|
||||||
import { type Snippet } from 'svelte';
|
import { untrack, type Snippet } from 'svelte';
|
||||||
import type { ClassValue } from 'svelte/elements';
|
import type { ClassValue } from 'svelte/elements';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import { flyAndScale } from './transition';
|
import { flyAndScale } from './transition';
|
||||||
@@ -72,19 +91,36 @@
|
|||||||
import { X } from 'phosphor-svelte';
|
import { X } from 'phosphor-svelte';
|
||||||
import { ErrorMessage, type RawError } from './error';
|
import { ErrorMessage, type RawError } from './error';
|
||||||
import ErrorBox from './ErrorBox.svelte';
|
import ErrorBox from './ErrorBox.svelte';
|
||||||
|
import { mergeOverrideObject } from './util';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
/** Bindable open state of the dialog */
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
title: string;
|
/** Title of the dialog */
|
||||||
description?: string;
|
title: string | Snippet;
|
||||||
|
/** Description of the dialog, optionally rendered below the title */
|
||||||
|
description?: string | Snippet;
|
||||||
|
/** Size of the dialog (default: 'sm') */
|
||||||
size?: 'sm' | 'md' | 'lg' | 'max';
|
size?: 'sm' | 'md' | 'lg' | 'max';
|
||||||
|
/** Additional classes for the dialog */
|
||||||
class?: ClassValue;
|
class?: ClassValue;
|
||||||
|
/** Content of the dialog */
|
||||||
children?: Snippet;
|
children?: Snippet;
|
||||||
controls?: Snippet | DialogControlOpts;
|
/** Bottom controls for the dialog */
|
||||||
|
controls?: Snippet | DialogControls;
|
||||||
|
/** Sets bottom alignment of controls (default: end) */
|
||||||
|
controlsAlign?: 'start' | 'center' | 'end';
|
||||||
|
/** Top-right close control */
|
||||||
|
close?: Snippet | Omit<DialogControlButton, 'label'> | null;
|
||||||
|
/** Callback when the dialog is opened */
|
||||||
onopen?: (dialog: DialogAPI) => void;
|
onopen?: (dialog: DialogAPI) => void;
|
||||||
|
/** Callback when the dialog is closed */
|
||||||
onclose?: (dialog: DialogAPI) => void;
|
onclose?: (dialog: DialogAPI) => void;
|
||||||
|
/** If default controls are used, controls loading state of submit button */
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
|
/** If default controls are used, freezes all interactions */
|
||||||
frozen?: boolean;
|
frozen?: boolean;
|
||||||
|
/** If default controls are used, disables submit button */
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +131,9 @@
|
|||||||
size = 'sm',
|
size = 'sm',
|
||||||
class: classValue,
|
class: classValue,
|
||||||
children,
|
children,
|
||||||
controls,
|
controls: rawControls = defaultDialogControls,
|
||||||
|
controlsAlign = 'end',
|
||||||
|
close = {},
|
||||||
onopen,
|
onopen,
|
||||||
onclose,
|
onclose,
|
||||||
loading = $bindable(false),
|
loading = $bindable(false),
|
||||||
@@ -103,6 +141,12 @@
|
|||||||
disabled = $bindable(false)
|
disabled = $bindable(false)
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
|
let controls = $derived(
|
||||||
|
typeof rawControls === 'function'
|
||||||
|
? rawControls
|
||||||
|
: mergeOverrideObject(defaultDialogControls, rawControls)
|
||||||
|
);
|
||||||
|
|
||||||
let dialogContainer = $state<HTMLDivElement | null>(null);
|
let dialogContainer = $state<HTMLDivElement | null>(null);
|
||||||
let error = $state<ErrorMessage | null>(null);
|
let error = $state<ErrorMessage | null>(null);
|
||||||
|
|
||||||
@@ -110,14 +154,15 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (open) {
|
if (open) {
|
||||||
document.body.style.overflow = 'hidden';
|
document.body.style.overflow = 'hidden';
|
||||||
onopen?.(dialogAPI);
|
untrack(() => onopen?.(dialogAPI));
|
||||||
} else {
|
} else {
|
||||||
document.body.style.overflow = '';
|
document.body.style.overflow = '';
|
||||||
onclose?.(dialogAPI);
|
untrack(() => onclose?.(dialogAPI));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const dialogAPI: DialogAPI = {
|
/** DialogAPI instance to control this dialog */
|
||||||
|
export const dialogAPI: DialogAPI = {
|
||||||
error: (message) => (error = ErrorMessage.from(message)),
|
error: (message) => (error = ErrorMessage.from(message)),
|
||||||
close: () => (open = false),
|
close: () => (open = false),
|
||||||
open: () => (open = true),
|
open: () => (open = true),
|
||||||
@@ -134,6 +179,16 @@
|
|||||||
canContinue: () => !loading && !disabled && !frozen,
|
canContinue: () => !loading && !disabled && !frozen,
|
||||||
title: (newTitle) => (title = newTitle)
|
title: (newTitle) => (title = newTitle)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Returns the current state of the dialog */
|
||||||
|
export const getState = (): DialogState => {
|
||||||
|
return {
|
||||||
|
frozen,
|
||||||
|
loading,
|
||||||
|
disabled,
|
||||||
|
api: dialogAPI
|
||||||
|
};
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Portal target="body">
|
<Portal target="body">
|
||||||
@@ -178,7 +233,21 @@
|
|||||||
start: 0.96
|
start: 0.96
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<h2 class="pointer-events-none mb-2 text-lg font-medium text-black select-none">{title}</h2>
|
<div class="flex items-center justify-between">
|
||||||
|
<!-- Dialog title -->
|
||||||
|
<h2 class="pointer-events-none mb-2 text-lg font-medium text-black select-none">
|
||||||
|
{@render stringOrSnippet(title)}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<!-- Close Button -->
|
||||||
|
{#if close !== null}
|
||||||
|
{#if typeof close === 'function'}
|
||||||
|
{@render close()}
|
||||||
|
{:else}
|
||||||
|
{@render dialogCloseButton(getState(), close)}
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
{#if error}
|
{#if error}
|
||||||
<ErrorBox {error} />
|
<ErrorBox {error} />
|
||||||
@@ -186,55 +255,100 @@
|
|||||||
|
|
||||||
{#if description}
|
{#if description}
|
||||||
<p class="mb-3 leading-normal text-zinc-600">
|
<p class="mb-3 leading-normal text-zinc-600">
|
||||||
{description}
|
{@render stringOrSnippet(description)}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if children}{@render children()}{:else}Dialog is empty{/if}
|
{#if children}{@render children()}{:else}Dialog is empty{/if}
|
||||||
|
|
||||||
<div class="mt-6 flex justify-end gap-4">
|
<!-- Dialog Controls -->
|
||||||
{#if controls && typeof controls === 'function'}{@render controls()}{:else}
|
<div
|
||||||
<Button
|
class={[
|
||||||
class={controls?.cancel?.class}
|
'mt-6 flex gap-4',
|
||||||
onclick={() => {
|
controlsAlign === 'start' && 'justify-start',
|
||||||
if (controls?.cancel?.action) {
|
controlsAlign === 'center' && 'justify-center',
|
||||||
controls.cancel.action(dialogAPI);
|
controlsAlign === 'end' && 'justify-end'
|
||||||
} else if (!frozen) {
|
]}
|
||||||
open = false;
|
>
|
||||||
}
|
{#if controls && typeof controls === 'function'}{@render controls()}{:else if controls?.flip}
|
||||||
}}
|
{#if controls.ok !== null}
|
||||||
disabled={frozen}
|
{@render dialogOkButton(getState(), controls.ok)}
|
||||||
>
|
{/if}
|
||||||
{controls?.cancel?.label || 'Cancel'}
|
{#if controls.cancel !== null}
|
||||||
</Button>
|
{@render dialogCancelButton(getState(), controls.cancel)}
|
||||||
<Button
|
{/if}
|
||||||
class={controls?.ok?.class}
|
{:else}
|
||||||
onclick={() => {
|
{#if controls.cancel !== null}
|
||||||
if (controls?.ok?.action) {
|
{@render dialogCancelButton(getState(), controls.cancel)}
|
||||||
controls.ok.action(dialogAPI);
|
{/if}
|
||||||
} else if (!frozen && !loading && !disabled) {
|
{#if controls.ok !== null}
|
||||||
open = false;
|
{@render dialogOkButton(getState(), controls.ok)}
|
||||||
}
|
{/if}
|
||||||
}}
|
|
||||||
disabled={frozen || loading || disabled}
|
|
||||||
{loading}
|
|
||||||
>
|
|
||||||
{controls?.ok?.label || 'OK'}
|
|
||||||
</Button>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
aria-label="close"
|
|
||||||
class="absolute top-4 right-4 inline-flex cursor-pointer items-center
|
|
||||||
justify-center disabled:cursor-not-allowed disabled:opacity-50"
|
|
||||||
onclick={() => {
|
|
||||||
if (!frozen) open = false;
|
|
||||||
}}
|
|
||||||
disabled={frozen}
|
|
||||||
>
|
|
||||||
<X size="1.5em" weight="bold" />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
|
{#snippet dialogCancelButton(state: DialogState, opts?: DialogControls['cancel'])}
|
||||||
|
<Button
|
||||||
|
class={opts?.class}
|
||||||
|
onclick={() => {
|
||||||
|
if (opts?.action) {
|
||||||
|
opts.action(state.api);
|
||||||
|
} else if (!state.frozen) {
|
||||||
|
state.api.close();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={state.frozen}
|
||||||
|
>
|
||||||
|
{opts?.label || 'Cancel'}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
|
{#snippet dialogOkButton(state: DialogState, opts?: DialogControls['ok'])}
|
||||||
|
<Button
|
||||||
|
class={opts?.class}
|
||||||
|
onclick={() => {
|
||||||
|
if (opts?.action) {
|
||||||
|
opts.action(state.api);
|
||||||
|
} else if (!state.frozen && !state.loading && !state.disabled) {
|
||||||
|
state.api.close();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={state.frozen || state.loading || state.disabled}
|
||||||
|
loading={state.loading}
|
||||||
|
>
|
||||||
|
{opts?.label || 'OK'}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
|
{#snippet dialogCloseButton(state: DialogState, opts?: Omit<DialogControlButton, 'label'> | null)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="close"
|
||||||
|
class={[
|
||||||
|
'inline-flex cursor-pointer items-center justify-center',
|
||||||
|
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||||
|
'rounded-full p-2 transition-colors hover:bg-zinc-200/50'
|
||||||
|
]}
|
||||||
|
onclick={() => {
|
||||||
|
if (opts?.action) {
|
||||||
|
opts.action(state.api);
|
||||||
|
} else if (!state.frozen) {
|
||||||
|
state.api.close();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={state.frozen}
|
||||||
|
>
|
||||||
|
<X size="1.25em" weight="bold" />
|
||||||
|
</button>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
|
{#snippet stringOrSnippet(val: string | Snippet)}
|
||||||
|
{#if typeof val === 'string'}
|
||||||
|
{val}
|
||||||
|
{:else}
|
||||||
|
{@render val()}
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
|||||||
@@ -1,18 +1,28 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { ClassValue } from 'svelte/elements';
|
import type { ClassValue } from 'svelte/elements';
|
||||||
import type { ErrorMessage } from './error';
|
import { ErrorMessage, type RawError } from './error';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
error: ErrorMessage | null;
|
/** Error in the form of an ErrorMessage */
|
||||||
|
error?: ErrorMessage | null;
|
||||||
|
/** Raw error that can be converted to an ErrorMessage */
|
||||||
|
rawError?: RawError | null;
|
||||||
|
/** Additional CSS classes for the error box */
|
||||||
class?: ClassValue | null;
|
class?: ClassValue | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { error, class: classValue }: Props = $props();
|
let { error, rawError, class: classValue }: Props = $props();
|
||||||
|
|
||||||
|
let errorMessage = $derived.by(() => {
|
||||||
|
if (error) return error;
|
||||||
|
if (rawError) return new ErrorMessage(rawError);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if error}
|
{#if errorMessage && errorMessage.hasError()}
|
||||||
<!-- eslint-disable svelte/no-at-html-tags -->
|
|
||||||
<div class={['bg-sui-accent text-sui-background my-4 rounded-xs px-6 py-4', classValue]}>
|
<div class={['bg-sui-accent text-sui-background my-4 rounded-xs px-6 py-4', classValue]}>
|
||||||
{@html error.message}
|
{#each errorMessage.lines as line}
|
||||||
|
<p>{line}</p>
|
||||||
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
28
src/lib/ScrollBox.svelte
Normal file
28
src/lib/ScrollBox.svelte
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<!-- @component
|
||||||
|
ScrollBox provides a small convenience wrapper for creating a scrollable container.
|
||||||
|
This component expects to be used as a direct child of a flex container that typically
|
||||||
|
has a constrained height. It applies the necessary CSS styles to ensure that its content
|
||||||
|
can scroll properly and that the container expands to the maximum available space within
|
||||||
|
the parent flexbox. Typically, a parent might have these Tailwind classes applied:
|
||||||
|
`flex h-full`
|
||||||
|
|
||||||
|
More complex layouts that should not expand to fill all available space should use
|
||||||
|
a custom container with `overflow-auto` and an intentionally constrained height.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import type { ClassValue } from 'svelte/elements';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
/** Applies ui-layout-px padding to the scrollable content area (default: false) */
|
||||||
|
padded?: boolean;
|
||||||
|
class?: ClassValue;
|
||||||
|
children?: import('svelte').Snippet;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { padded = false, class: classValue, children }: Props = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class={['min-h-0 min-w-0 flex-1 overflow-auto', padded && 'p-layout', classValue]}>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
import { tweened } from 'svelte/motion';
|
import { tweened } from 'svelte/motion';
|
||||||
import { fade, fly } from 'svelte/transition';
|
import { fade, fly } from 'svelte/transition';
|
||||||
import { validateForm } from '@svelte-toolkit/validate';
|
import { validateForm } from '@svelte-toolkit/validate';
|
||||||
import { ArrowLeft, Check, CheckFat } from 'phosphor-svelte';
|
import { ArrowLeft, CheckFat } from 'phosphor-svelte';
|
||||||
import type { IconDef } from './util';
|
import type { IconDef } from './util';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -49,6 +49,13 @@
|
|||||||
failure: StateMachinePage;
|
failure: StateMachinePage;
|
||||||
index?: number;
|
index?: number;
|
||||||
action?: string;
|
action?: string;
|
||||||
|
/**
|
||||||
|
* Called when the form is submitted at the end of the state machine.
|
||||||
|
* Receives the collated form data as a key-value object.
|
||||||
|
* If you wish to prevent the submission, return false.
|
||||||
|
* If you wish to indicate a failure, you can also throw an error.
|
||||||
|
*/
|
||||||
|
onsubmit?: (data: Record<string, string>) => Promise<boolean> | boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -57,7 +64,8 @@
|
|||||||
success,
|
success,
|
||||||
failure,
|
failure,
|
||||||
index = $bindable(0),
|
index = $bindable(0),
|
||||||
action
|
action,
|
||||||
|
onsubmit
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
// add success and failure pages to the end of the pages array
|
// add success and failure pages to the end of the pages array
|
||||||
@@ -250,6 +258,22 @@
|
|||||||
// update button state
|
// update button state
|
||||||
buttonLoading = true;
|
buttonLoading = true;
|
||||||
|
|
||||||
|
if (onsubmit) {
|
||||||
|
try {
|
||||||
|
const res = await onsubmit(collatedFormData);
|
||||||
|
if (res === false) {
|
||||||
|
buttonLoading = false;
|
||||||
|
index = pages.length - 2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log('onsubmit handler failed, submission prevented', e);
|
||||||
|
buttonLoading = false;
|
||||||
|
index = pages.length - 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const form_data = new FormData();
|
const form_data = new FormData();
|
||||||
for (const [key, value] of Object.entries(collatedFormData)) {
|
for (const [key, value] of Object.entries(collatedFormData)) {
|
||||||
form_data.append(key, value);
|
form_data.append(key, value);
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
<!--
|
||||||
|
Documents the purpose, API, and usage details of the selected component.
|
||||||
|
Include key props, expected behavior, and any important notes for consumers.
|
||||||
|
-->
|
||||||
|
|
||||||
<script lang="ts" module>
|
<script lang="ts" module>
|
||||||
export type TabPage = {
|
export type TabPage = {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -14,12 +19,16 @@
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
pages: TabPage[];
|
pages: TabPage[];
|
||||||
|
/** Currently active tab index (default: 0) */
|
||||||
activeIndex?: number;
|
activeIndex?: number;
|
||||||
|
/** Callback fired when the active tab changes */
|
||||||
onchange?: (event: { index: number; tab: TabPage }) => void;
|
onchange?: (event: { index: number; tab: TabPage }) => void;
|
||||||
|
/** Applies layout padding to the tab header & content areas (default: false) */
|
||||||
|
padded?: boolean;
|
||||||
class?: ClassValue | null;
|
class?: ClassValue | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { pages, activeIndex = 0, onchange, class: classValue }: Props = $props();
|
let { pages, activeIndex = 0, onchange, padded = false, class: classValue }: Props = $props();
|
||||||
|
|
||||||
let primaryContainerEl: HTMLDivElement;
|
let primaryContainerEl: HTMLDivElement;
|
||||||
let tabContainerEl: HTMLDivElement;
|
let tabContainerEl: HTMLDivElement;
|
||||||
@@ -88,7 +97,10 @@
|
|||||||
<div bind:this={primaryContainerEl} class={[classValue]}>
|
<div bind:this={primaryContainerEl} class={[classValue]}>
|
||||||
<div
|
<div
|
||||||
bind:this={tabContainerEl}
|
bind:this={tabContainerEl}
|
||||||
class={['border-sui-text/15 relative mb-4 flex items-center gap-5 border-b-2']}
|
class={[
|
||||||
|
'border-sui-text/15 relative mb-4 flex items-center gap-5 border-b-2',
|
||||||
|
padded && 'px-layout'
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
{#each pages as page, i (page.title)}
|
{#each pages as page, i (page.title)}
|
||||||
{@const active = activeIndex === i}
|
{@const active = activeIndex === i}
|
||||||
@@ -122,7 +134,7 @@
|
|||||||
|
|
||||||
{#key activeIndex}
|
{#key activeIndex}
|
||||||
<div
|
<div
|
||||||
class={[]}
|
class={[padded && 'px-layout']}
|
||||||
in:flyX={{ direction: activeIndex > prevIndex ? 1 : -1, duration: 180, delay: 181 }}
|
in:flyX={{ direction: activeIndex > prevIndex ? 1 : -1, duration: 180, delay: 181 }}
|
||||||
out:flyX={{ direction: activeIndex > prevIndex ? -1 : 1, duration: 180 }}
|
out:flyX={{ direction: activeIndex > prevIndex ? -1 : 1, duration: 180 }}
|
||||||
onoutrostart={lockHeight}
|
onoutrostart={lockHeight}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
value?: string;
|
value?: string;
|
||||||
invalidMessage?: string | null;
|
invalidMessage?: string | null;
|
||||||
ref?: HTMLInputElement | null;
|
ref?: HTMLInputElement | null;
|
||||||
asterisk?: boolean;
|
asterisk?: boolean | null;
|
||||||
class?: ClassValue | null | undefined;
|
class?: ClassValue | null | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,12 +21,16 @@
|
|||||||
value = $bindable(''),
|
value = $bindable(''),
|
||||||
invalidMessage = 'Field is required',
|
invalidMessage = 'Field is required',
|
||||||
ref = $bindable<HTMLInputElement | null>(null),
|
ref = $bindable<HTMLInputElement | null>(null),
|
||||||
asterisk = false,
|
asterisk = null,
|
||||||
class: classValue,
|
class: classValue,
|
||||||
|
forceInvalid = false,
|
||||||
...others
|
...others
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
let valid: boolean = $state(true);
|
let valid: boolean = $state(true);
|
||||||
|
let displayAsterisk = $derived(
|
||||||
|
asterisk === true || (asterisk !== false && others.validate && others.validate.required)
|
||||||
|
);
|
||||||
|
|
||||||
export const focus = () => {
|
export const focus = () => {
|
||||||
if (ref) ref.focus();
|
if (ref) ref.focus();
|
||||||
@@ -37,7 +41,7 @@
|
|||||||
{#if label}
|
{#if label}
|
||||||
<Label for={id}>
|
<Label for={id}>
|
||||||
{label}
|
{label}
|
||||||
{#if asterisk}
|
{#if displayAsterisk}
|
||||||
<span class="text-red-500">*</span>
|
<span class="text-red-500">*</span>
|
||||||
{/if}
|
{/if}
|
||||||
</Label>
|
</Label>
|
||||||
@@ -50,11 +54,12 @@
|
|||||||
onvalidate={(e) => {
|
onvalidate={(e) => {
|
||||||
valid = e.detail.valid;
|
valid = e.detail.valid;
|
||||||
}}
|
}}
|
||||||
|
{forceInvalid}
|
||||||
{...others}
|
{...others}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{#if others.validate && invalidMessage !== null}
|
{#if others.validate && invalidMessage !== null}
|
||||||
<div class={['opacity-0 transition-opacity', !valid && 'opacity-100']}>
|
<div class={['opacity-0 transition-opacity', (!valid || forceInvalid) && 'opacity-100']}>
|
||||||
<Label for={id} error>
|
<Label for={id} error>
|
||||||
{invalidMessage}
|
{invalidMessage}
|
||||||
</Label>
|
</Label>
|
||||||
|
|||||||
@@ -10,20 +10,41 @@ export interface GraphError {
|
|||||||
export type RawError = Error | string | GraphError[];
|
export type RawError = Error | string | GraphError[];
|
||||||
|
|
||||||
export class ErrorMessage {
|
export class ErrorMessage {
|
||||||
private _message: string;
|
private _lines: string[] = [];
|
||||||
|
|
||||||
/** converts a RawError to a string and stores it for later access */
|
/**
|
||||||
constructor(raw: RawError) {
|
* Converts a RawError to an array of lines and stores it for later access,
|
||||||
this._message = ErrorMessage.rawErrorToString(raw);
|
* or initializes without any errors if the input is null or undefined.
|
||||||
|
* @param raw The raw error to convert and store, or null/undefined for no error.
|
||||||
|
* @throws If the raw error is of an unsupported type.
|
||||||
|
*/
|
||||||
|
constructor(raw: RawError | null | undefined) {
|
||||||
|
if (raw) {
|
||||||
|
this._lines = ErrorMessage.rawErrorToLines(raw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** returns the stored message */
|
/** returns the stored lines */
|
||||||
get message(): string {
|
get lines(): string[] {
|
||||||
return this._message;
|
return this._lines;
|
||||||
}
|
}
|
||||||
/** returns the error as a string */
|
/** returns the error lines as a string, separated by newlines */
|
||||||
toString(): string {
|
toString(): string {
|
||||||
return this._message;
|
return this._lines.join('\n');
|
||||||
|
}
|
||||||
|
/** returns the error lines as an HTML string, separated by <br /> */
|
||||||
|
toHTML(): string {
|
||||||
|
return this._lines.join('<br />');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** returns true if there are any error lines */
|
||||||
|
hasError(): boolean {
|
||||||
|
return this._lines.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** adds a new line to the error message */
|
||||||
|
addLine(line: string): void {
|
||||||
|
this._lines.push(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** optionally returns a new ErrorMessage only if the RawError is not empty */
|
/** optionally returns a new ErrorMessage only if the RawError is not empty */
|
||||||
@@ -32,28 +53,27 @@ export class ErrorMessage {
|
|||||||
return new ErrorMessage(raw);
|
return new ErrorMessage(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** converts a RawError to a string */
|
/** converts a RawError to an array of lines */
|
||||||
static rawErrorToString(raw: RawError | null | undefined): string {
|
static rawErrorToLines(raw: RawError | null | undefined): string[] {
|
||||||
if (!raw) return 'No error';
|
if (!raw) return ['No error'];
|
||||||
|
|
||||||
let errorString: string;
|
let errorLines: string[];
|
||||||
if (typeof raw === 'string') {
|
if (typeof raw === 'string') {
|
||||||
errorString = raw;
|
errorLines = [raw];
|
||||||
} else if (raw instanceof Error) {
|
} else if (raw instanceof Error) {
|
||||||
errorString = raw.message;
|
errorLines = [raw.message];
|
||||||
} else if (Array.isArray(raw)) {
|
} else if (Array.isArray(raw)) {
|
||||||
errorString = raw
|
errorLines = raw.map((e) => {
|
||||||
.flatMap((e) => {
|
const messageString = e.message || 'Unknown error';
|
||||||
const messageString = e.message || 'Unknown error';
|
if (e.path && e.path.length > 0) {
|
||||||
if (e.path && e.path.length > 0) {
|
return `"${messageString}" at ${e.path.join('.')}`;
|
||||||
return `"${messageString}" at ${e.path.join('.')}`;
|
}
|
||||||
}
|
return messageString;
|
||||||
})
|
});
|
||||||
.join('<br />');
|
|
||||||
} else {
|
} else {
|
||||||
throw `Bad error value ${raw}`;
|
throw `Bad error value ${raw}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorString;
|
return errorLines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,14 @@ export { default as CenterBox } from './CenterBox.svelte';
|
|||||||
export { default as Checkbox, type CheckboxState } from './Checkbox.svelte';
|
export { default as Checkbox, type CheckboxState } from './Checkbox.svelte';
|
||||||
export { default as Combobox, type ComboboxOption } from './Combobox.svelte';
|
export { default as Combobox, type ComboboxOption } from './Combobox.svelte';
|
||||||
export { default as DateInput } from './DateInput.svelte';
|
export { default as DateInput } from './DateInput.svelte';
|
||||||
export { default as Dialog, type DialogAPI, type DialogControlOpts } from './Dialog.svelte';
|
export {
|
||||||
|
default as Dialog,
|
||||||
|
type DialogAPI,
|
||||||
|
type DialogControls,
|
||||||
|
dialogCancelButton,
|
||||||
|
dialogCloseButton,
|
||||||
|
dialogOkButton
|
||||||
|
} from './Dialog.svelte';
|
||||||
export {
|
export {
|
||||||
default as DurationInput,
|
default as DurationInput,
|
||||||
formatDuration,
|
formatDuration,
|
||||||
@@ -23,6 +30,7 @@ export { default as Link, rewriteHref } from './Link.svelte';
|
|||||||
export { default as PhoneInput } from './PhoneInput.svelte';
|
export { default as PhoneInput } from './PhoneInput.svelte';
|
||||||
export { default as PinInput } from './PinInput.svelte';
|
export { default as PinInput } from './PinInput.svelte';
|
||||||
export { default as RadioGroup } from './RadioGroup.svelte';
|
export { default as RadioGroup } from './RadioGroup.svelte';
|
||||||
|
export { default as ScrollBox } from './ScrollBox.svelte';
|
||||||
export { default as Spinner } from './Spinner.svelte';
|
export { default as Spinner } from './Spinner.svelte';
|
||||||
export { default as StateMachine, type StateMachinePage } from './StateMachine.svelte';
|
export { default as StateMachine, type StateMachinePage } from './StateMachine.svelte';
|
||||||
export { default as StyledRawInput } from './StyledRawInput.svelte';
|
export { default as StyledRawInput } from './StyledRawInput.svelte';
|
||||||
|
|||||||
@@ -17,6 +17,15 @@
|
|||||||
monospace
|
monospace
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/* Layout Controls */
|
||||||
|
--spacing-layout: calc(var(--spacing) * var(--ui-layout-gap, 4));
|
||||||
|
--spacing-layout-2x: calc(var(--spacing-layout) * 2);
|
||||||
|
|
||||||
|
/** TODO: Refine colors so we can pick more intent-based colors, perhaps on a per-component level???
|
||||||
|
Perhaps it's best to just wrap those individual components and apply classes there instead of
|
||||||
|
bloating the base styles with too many color variables?
|
||||||
|
*/
|
||||||
|
|
||||||
/* Primary Colors */
|
/* Primary Colors */
|
||||||
--color-sui-primary-50: var(--ui-primary-50, #f0f8fe);
|
--color-sui-primary-50: var(--ui-primary-50, #f0f8fe);
|
||||||
--color-sui-primary-100: var(--ui-primary-100, #ddeefc);
|
--color-sui-primary-100: var(--ui-primary-100, #ddeefc);
|
||||||
|
|||||||
@@ -143,3 +143,55 @@ export const trimEdges = (str: string, char: string, trimStart?: boolean, trimEn
|
|||||||
|
|
||||||
return str.substring(start, end);
|
return str.substring(start, end);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// helper: only treat plain objects as mergeable
|
||||||
|
const isPlainObject = (v: unknown): v is Record<string, unknown> =>
|
||||||
|
typeof v === 'object' &&
|
||||||
|
v !== null &&
|
||||||
|
!Array.isArray(v) &&
|
||||||
|
Object.getPrototypeOf(v) === Object.prototype;
|
||||||
|
|
||||||
|
/** Merge two plain object maps. No `any` used. */
|
||||||
|
function mergePlainObjects(
|
||||||
|
baseObj: Record<string, unknown>,
|
||||||
|
overrideObj: Record<string, unknown>
|
||||||
|
): Record<string, unknown> {
|
||||||
|
const res: Record<string, unknown> = { ...baseObj };
|
||||||
|
|
||||||
|
for (const k of Object.keys(overrideObj)) {
|
||||||
|
const v = overrideObj[k];
|
||||||
|
if (v === undefined) continue; // undefined preserves base
|
||||||
|
const b = res[k];
|
||||||
|
|
||||||
|
if (isPlainObject(v) && isPlainObject(b)) {
|
||||||
|
res[k] = mergePlainObjects(b as Record<string, unknown>, v as Record<string, unknown>);
|
||||||
|
} else {
|
||||||
|
// primitives, null, arrays, non-plain objects replace base
|
||||||
|
res[k] = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge `base` with `override`.
|
||||||
|
* - `null` in `override` replaces (kept as valid override)
|
||||||
|
* - `undefined` in `override` is ignored (keeps base)
|
||||||
|
* - Only plain objects are deep-merged
|
||||||
|
* - If `override` is null/undefined we return a shallow copy of `base`
|
||||||
|
*/
|
||||||
|
export const mergeOverrideObject = <T extends Record<string, unknown>>(
|
||||||
|
base: T,
|
||||||
|
override?: Partial<T> | null
|
||||||
|
): T => {
|
||||||
|
if (override == null) return { ...base } as T;
|
||||||
|
|
||||||
|
// Use plain maps internally to avoid explicit any
|
||||||
|
const baseMap = { ...base } as Record<string, unknown>;
|
||||||
|
const overrideMap = override as Record<string, unknown>;
|
||||||
|
|
||||||
|
const merged = mergePlainObjects(baseMap, overrideMap);
|
||||||
|
|
||||||
|
return merged as T;
|
||||||
|
};
|
||||||
|
|||||||
@@ -84,6 +84,7 @@
|
|||||||
title="Manage Cookies"
|
title="Manage Cookies"
|
||||||
controls={{
|
controls={{
|
||||||
moreInfo: { label: 'More Info', type: 'link', href: '#!' },
|
moreInfo: { label: 'More Info', type: 'link', href: '#!' },
|
||||||
|
dismiss: null,
|
||||||
swap: true
|
swap: true
|
||||||
}}
|
}}
|
||||||
onaccept={() => console.log('Cookies accepted!')}
|
onaccept={() => console.log('Cookies accepted!')}
|
||||||
@@ -428,6 +429,7 @@
|
|||||||
<p class="title">Tabs</p>
|
<p class="title">Tabs</p>
|
||||||
|
|
||||||
<Tabs
|
<Tabs
|
||||||
|
padded={true}
|
||||||
pages={[
|
pages={[
|
||||||
{
|
{
|
||||||
title: 'Dashboard',
|
title: 'Dashboard',
|
||||||
@@ -522,7 +524,8 @@
|
|||||||
dialog.close();
|
dialog.close();
|
||||||
alert('Dialog submitted!');
|
alert('Dialog submitted!');
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
cancel: null
|
||||||
}}
|
}}
|
||||||
onopen={(dialog) => {
|
onopen={(dialog) => {
|
||||||
dialog.error('Example error message!');
|
dialog.error('Example error message!');
|
||||||
|
|||||||
Reference in New Issue
Block a user