@nekm/svelte-core 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,6 +13,14 @@ Install with your favorite package manager:
13
13
  npm install --save @nekm/svelte-core
14
14
  ```
15
15
 
16
+ ## Development
17
+
18
+ Run Storybook to develop and document components in isolation:
19
+
20
+ ```bash
21
+ npm run storybook
22
+ ```
23
+
16
24
  ## Versioning
17
25
 
18
26
  This project complies with [Semantic Versioning](https://semver.org/).
@@ -0,0 +1,111 @@
1
+ <script lang="ts">
2
+ import { noop } from "@nekm/core";
3
+ import type { Snippet } from "svelte";
4
+
5
+ interface BaseProps {
6
+ readonly class?: string;
7
+ readonly labels?: {
8
+ readonly accept?: string;
9
+ readonly decline?: string | null;
10
+ readonly privacy?: string;
11
+ };
12
+ readonly children?: Snippet;
13
+ readonly onAccept?: () => void;
14
+ readonly onDecline?: () => void;
15
+ }
16
+
17
+ /** Built-in privacy link + accept/decline buttons. */
18
+ type DefaultDesign = BaseProps & {
19
+ readonly privacyHref: string;
20
+ readonly privacyLink?: never;
21
+ readonly actions?: never;
22
+ };
23
+
24
+ /** Caller supplies privacy link and actions snippets. */
25
+ type CustomDesign = BaseProps & {
26
+ readonly privacyHref?: never;
27
+ readonly privacyLink: Snippet;
28
+ readonly actions: Snippet<
29
+ [
30
+ {
31
+ readonly onAccept: () => void;
32
+ readonly onDecline: () => void;
33
+ },
34
+ ]
35
+ >;
36
+ };
37
+
38
+ type Props = DefaultDesign | CustomDesign;
39
+
40
+ const DEFAULT_LABELS = {
41
+ accept: "Accept",
42
+ decline: "Decline optional",
43
+ privacy: "Read more",
44
+ } as const;
45
+
46
+ const props: Props = $props();
47
+
48
+ const className = $derived(props.class ?? "border-zinc-200 bg-white shadow rounded-lg");
49
+ const onAccept = $derived(props.onAccept ?? noop);
50
+ const onDecline = $derived(props.onDecline ?? noop);
51
+ const labelsProp = $derived(props.labels);
52
+ const children = $derived(props.children);
53
+
54
+ const labels = $derived({
55
+ accept: labelsProp?.accept ?? DEFAULT_LABELS.accept,
56
+ decline:
57
+ labelsProp?.decline === undefined
58
+ ? DEFAULT_LABELS.decline
59
+ : labelsProp.decline,
60
+ privacy: labelsProp?.privacy ?? DEFAULT_LABELS.privacy,
61
+ });
62
+
63
+ const actionProps = $derived({ onAccept, onDecline });
64
+ </script>
65
+
66
+ <div
67
+ class="{className} fixed right-4 bottom-4 flex max-w-md flex-col gap-4 border p-4"
68
+ role="dialog"
69
+ aria-label="Cookie consent"
70
+ >
71
+ <div>
72
+ {#if children}
73
+ {@render children()}
74
+ {:else}
75
+ This website uses cookies to enhance your experience and analyze usage.
76
+ {/if}
77
+ </div>
78
+
79
+ {#if props.privacyLink && props.actions}
80
+ <div>
81
+ {@render props.privacyLink()}
82
+ </div>
83
+ <div class="flex gap-4">
84
+ {@render props.actions(actionProps)}
85
+ </div>
86
+ {:else}
87
+ <div>
88
+ <a href={props.privacyHref} class="text-zinc-500 underline">
89
+ {labels.privacy}
90
+ </a>
91
+ </div>
92
+ <div class="flex gap-4">
93
+ <button
94
+ type="button"
95
+ class="flex-1 cursor-pointer rounded-lg border border-zinc-200 p-3 hover:opacity-40"
96
+ onclick={onAccept}
97
+ >
98
+ {labels.accept}
99
+ </button>
100
+ {#if labels.decline !== null}
101
+ <button
102
+ type="button"
103
+ class="flex-1 cursor-pointer rounded-lg border border-zinc-200 p-3 hover:opacity-40"
104
+ onclick={onDecline}
105
+ >
106
+ {labels.decline}
107
+ </button>
108
+ {/if}
109
+ </div>
110
+ {/if}
111
+ </div>
@@ -0,0 +1,33 @@
1
+ import type { Snippet } from "svelte";
2
+ interface BaseProps {
3
+ readonly class?: string;
4
+ readonly labels?: {
5
+ readonly accept?: string;
6
+ readonly decline?: string | null;
7
+ readonly privacy?: string;
8
+ };
9
+ readonly children?: Snippet;
10
+ readonly onAccept?: () => void;
11
+ readonly onDecline?: () => void;
12
+ }
13
+ /** Built-in privacy link + accept/decline buttons. */
14
+ type DefaultDesign = BaseProps & {
15
+ readonly privacyHref: string;
16
+ readonly privacyLink?: never;
17
+ readonly actions?: never;
18
+ };
19
+ /** Caller supplies privacy link and actions snippets. */
20
+ type CustomDesign = BaseProps & {
21
+ readonly privacyHref?: never;
22
+ readonly privacyLink: Snippet;
23
+ readonly actions: Snippet<[
24
+ {
25
+ readonly onAccept: () => void;
26
+ readonly onDecline: () => void;
27
+ }
28
+ ]>;
29
+ };
30
+ type Props = DefaultDesign | CustomDesign;
31
+ declare const CookieConsent: import("svelte").Component<Props, {}, "">;
32
+ type CookieConsent = ReturnType<typeof CookieConsent>;
33
+ export default CookieConsent;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export { default as Seo } from "./seo.svelte";
7
7
  export * from "./seo.svelte";
8
8
  export { default as DateTime } from "./date-time.svelte";
9
9
  export * from "./date-time.svelte";
10
+ export { default as CookieConsent } from "./cookie-consent.svelte";
11
+ export * from "./cookie-consent.svelte";
10
12
  export { default as CookieConsentPopupsmart } from "./cookie-consent-popupsmart.svelte";
11
13
  export * from "./cookie-consent-popupsmart.svelte";
12
14
  export { default as LdJson } from "./ld-json.svelte";
package/dist/index.js CHANGED
@@ -7,6 +7,8 @@ export { default as Seo } from "./seo.svelte";
7
7
  export * from "./seo.svelte";
8
8
  export { default as DateTime } from "./date-time.svelte";
9
9
  export * from "./date-time.svelte";
10
+ export { default as CookieConsent } from "./cookie-consent.svelte";
11
+ export * from "./cookie-consent.svelte";
10
12
  export { default as CookieConsentPopupsmart } from "./cookie-consent-popupsmart.svelte";
11
13
  export * from "./cookie-consent-popupsmart.svelte";
12
14
  export { default as LdJson } from "./ld-json.svelte";
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@nekm/svelte-core",
3
3
  "description": "Code I find myself re-writing over-and-over, Svelte edition.",
4
4
  "license": "MIT",
5
- "version": "2.0.1",
5
+ "version": "2.1.0",
6
6
  "scripts": {
7
7
  "dev": "vite dev",
8
8
  "build": "vite build && npm run prepack",
@@ -10,12 +10,15 @@
10
10
  "prepare": "svelte-kit sync || echo ''",
11
11
  "prepack": "svelte-kit sync && svelte-package && publint",
12
12
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
13
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
13
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
14
+ "storybook": "storybook dev -p 6006",
15
+ "build-storybook": "storybook build"
14
16
  },
15
17
  "files": [
16
18
  "dist",
17
19
  "!dist/**/*.test.*",
18
- "!dist/**/*.spec.*"
20
+ "!dist/**/*.spec.*",
21
+ "!dist/**/*.stories.*"
19
22
  ],
20
23
  "sideEffects": [
21
24
  "**/*.css"
@@ -34,16 +37,23 @@
34
37
  }
35
38
  },
36
39
  "devDependencies": {
40
+ "@storybook/addon-a11y": "^10.6.8",
41
+ "@storybook/addon-docs": "^10.6.8",
42
+ "@storybook/addon-svelte-csf": "latest",
43
+ "@storybook/sveltekit": "^10.6.8",
37
44
  "@sveltejs/adapter-auto": "^8.0.1",
38
45
  "@sveltejs/kit": "^3.3.1",
39
46
  "@sveltejs/package": "^3.0.3",
40
47
  "@sveltejs/vite-plugin-svelte": "^7",
48
+ "@tailwindcss/vite": "^4.3.5",
41
49
  "@types/node": "^25.5.0",
42
50
  "mongodb": "^7.1.1",
43
51
  "publint": "^0.3.18",
52
+ "storybook": "^10.6.8",
44
53
  "svelte": "^5.58.0",
45
54
  "svelte-check": "^4.7.8",
46
55
  "svelte-kit-sessions": "^0.4.0",
56
+ "tailwindcss": "^4.3.5",
47
57
  "typescript": "^6",
48
58
  "vite": "^8.0.12",
49
59
  "vite-plugin-devtools-json": "^1.1.2"