Compare commits
5 Commits
46bd6b935a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf77a20ff9 | ||
|
|
42c9bc0bcc | ||
|
|
ed48b404d4 | ||
|
|
54f7924c4a | ||
|
|
d9cd2b406a |
@@ -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.2",
|
"version": "0.3.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build && pnpm run prepack",
|
"build": "vite build && pnpm run prepack",
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
})
|
})
|
||||||
| null;
|
| null;
|
||||||
dismiss?: Omit<BannerControlButton, 'framed'> | null;
|
dismiss?: Omit<BannerControlButton, 'framed'> | null;
|
||||||
|
/** if true, accept and decline buttons are swapped with more info */
|
||||||
|
swap?: boolean | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultBannerControls: BannerControls = {
|
const defaultBannerControls: BannerControls = {
|
||||||
@@ -53,21 +55,40 @@
|
|||||||
},
|
},
|
||||||
dismiss: {
|
dismiss: {
|
||||||
action: (banner) => banner.close()
|
action: (banner) => banner.close()
|
||||||
}
|
},
|
||||||
|
swap: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const mergeBannerControls = (
|
const mergeBannerControls = (
|
||||||
defaults: BannerControls,
|
defaults: BannerControls,
|
||||||
overrides: BannerControls | null | undefined
|
overrides?: BannerControls | null
|
||||||
): BannerControls => {
|
): BannerControls => {
|
||||||
if (!overrides) return defaults;
|
if (overrides == null) return { ...defaults };
|
||||||
|
|
||||||
return {
|
const result: BannerControls = { ...defaults };
|
||||||
accept: overrides.accept ?? defaults.accept,
|
|
||||||
decline: overrides.decline ?? defaults.decline,
|
const keys: (keyof BannerControls)[] = ['accept', 'decline', 'moreInfo', 'dismiss', 'swap'];
|
||||||
moreInfo: overrides.moreInfo ?? defaults.moreInfo,
|
|
||||||
dismiss: overrides.dismiss ?? defaults.dismiss
|
for (const key of keys) {
|
||||||
};
|
const ov = overrides[key];
|
||||||
|
if (ov === null) {
|
||||||
|
// explicit disable
|
||||||
|
result[key] = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ov === undefined) continue; // keep default
|
||||||
|
if (key === 'swap') {
|
||||||
|
result.swap = ov as boolean;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// shallow merge individual control fields
|
||||||
|
result[key] = {
|
||||||
|
...(defaults[key] ?? {}),
|
||||||
|
...(ov as any)
|
||||||
|
} as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -157,6 +178,7 @@
|
|||||||
<FramelessButton
|
<FramelessButton
|
||||||
inverted={invertFrameless}
|
inverted={invertFrameless}
|
||||||
onclick={() => controls.dismiss?.action?.(api)}
|
onclick={() => controls.dismiss?.action?.(api)}
|
||||||
|
class="ml-auto"
|
||||||
>
|
>
|
||||||
{#if controls.dismiss?.label}
|
{#if controls.dismiss?.label}
|
||||||
{controls.dismiss.label}
|
{controls.dismiss.label}
|
||||||
@@ -170,7 +192,9 @@
|
|||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
|
|
||||||
{#if controls !== null}
|
{#if controls !== null}
|
||||||
<div class="mt-4 flex flex-wrap justify-between gap-4">
|
<div
|
||||||
|
class={['mt-4 flex flex-wrap justify-between gap-4', controls.swap && 'flex-row-reverse']}
|
||||||
|
>
|
||||||
<!-- More info button/link -->
|
<!-- More info button/link -->
|
||||||
{#if controls.moreInfo}
|
{#if controls.moreInfo}
|
||||||
{#if controls.moreInfo.type === 'link' && controls.moreInfo.href}
|
{#if controls.moreInfo.type === 'link' && controls.moreInfo.href}
|
||||||
@@ -199,7 +223,9 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="flex justify-end gap-4">
|
<div
|
||||||
|
class={['flex justify-end gap-4', controls.swap ? 'mr-auto flex-row-reverse' : 'ml-auto']}
|
||||||
|
>
|
||||||
<!-- Decline button -->
|
<!-- Decline button -->
|
||||||
{@render buttonControl(controls.decline, handleDecline, false)}
|
{@render buttonControl(controls.decline, handleDecline, false)}
|
||||||
<!-- Accept button -->
|
<!-- Accept button -->
|
||||||
|
|||||||
@@ -83,7 +83,9 @@
|
|||||||
<Banner
|
<Banner
|
||||||
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
|
||||||
}}
|
}}
|
||||||
onaccept={() => console.log('Cookies accepted!')}
|
onaccept={() => console.log('Cookies accepted!')}
|
||||||
ondecline={() => console.log('Cookies declined!')}
|
ondecline={() => console.log('Cookies declined!')}
|
||||||
|
|||||||
Reference in New Issue
Block a user