@uninspired/cookie-banner 0.0.4 → 0.0.6

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.
Files changed (40) hide show
  1. package/dist/components/Banner/Banner.js +35 -0
  2. package/dist/components/Banner/index.js +1 -0
  3. package/dist/components/BannerItem/BannerItem.js +24 -0
  4. package/dist/components/BannerItem/index.js +1 -0
  5. package/dist/components/Button/Button.js +6 -0
  6. package/dist/components/Button/index.js +1 -0
  7. package/dist/components/Switch/Switch.js +7 -0
  8. package/dist/components/Switch/index.js +1 -0
  9. package/dist/components/Text/Text.js +9 -0
  10. package/dist/components/Text/index.js +1 -0
  11. package/dist/contexts/SelectionContext.js +101 -0
  12. package/dist/react/index.cjs +950 -329
  13. package/dist/react/index.d.ts +2 -2
  14. package/dist/react/index.js +951 -330
  15. package/dist/react.js +1 -0
  16. package/dist/script/index.cjs +18 -18
  17. package/dist/script/index.js +1885 -1603
  18. package/dist/script.js +1 -0
  19. package/dist/types/components/Banner/Banner.d.ts +21 -0
  20. package/dist/types/components/Banner/index.d.ts +1 -0
  21. package/dist/types/components/BannerItem/BannerItem.d.ts +23 -0
  22. package/dist/types/components/BannerItem/index.d.ts +1 -0
  23. package/dist/types/components/Button/Button.d.ts +5 -0
  24. package/dist/types/components/Button/index.d.ts +1 -0
  25. package/dist/types/components/Switch/Switch.d.ts +5 -0
  26. package/dist/types/components/Switch/index.d.ts +1 -0
  27. package/dist/types/components/Text/Text.d.ts +8 -0
  28. package/dist/types/components/Text/index.d.ts +1 -0
  29. package/dist/types/contexts/SelectionContext.d.ts +23 -0
  30. package/dist/types/react.d.ts +1 -0
  31. package/dist/types/script.d.ts +1 -0
  32. package/dist/types/utils/classes.d.ts +2 -0
  33. package/dist/types/utils/mountBanner.d.ts +2 -0
  34. package/dist/types/utils/scriptDefinition.d.ts +35 -0
  35. package/dist/types/utils/selection.d.ts +3 -0
  36. package/dist/utils/classes.js +9 -0
  37. package/dist/utils/mountBanner.js +18 -0
  38. package/dist/utils/scriptDefinition.js +21 -0
  39. package/dist/utils/selection.js +2 -0
  40. package/package.json +7 -7
package/dist/script.js ADDED
@@ -0,0 +1 @@
1
+ export { mountBanner } from "./utils/mountBanner";
@@ -0,0 +1,21 @@
1
+ import { type BannerItemOptions } from "../BannerItem";
2
+ import "../../styles/variables.css";
3
+ export interface BannerOptions {
4
+ localStorageKey?: string;
5
+ heading?: string;
6
+ subheading?: string;
7
+ selectLabel?: string;
8
+ hideLabel?: string;
9
+ saveLabel?: string;
10
+ declineLabel?: string;
11
+ defaultSettingsOpen?: boolean;
12
+ privacyPolicy?: {
13
+ label: string;
14
+ url: string;
15
+ };
16
+ items: BannerItemOptions[];
17
+ }
18
+ export interface BannerProps extends BannerOptions {
19
+ noTarget?: boolean;
20
+ }
21
+ export declare const Banner: ({ localStorageKey, items, ...rest }: BannerProps) => import("preact").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from "./Banner";
@@ -0,0 +1,23 @@
1
+ import { type ScriptDefinition } from "../../utils/scriptDefinition";
2
+ interface BannerItemOptionsBase {
3
+ value: string;
4
+ label: string;
5
+ defaultSelected?: boolean;
6
+ sublabel?: string;
7
+ required?: boolean;
8
+ description?: string;
9
+ }
10
+ interface BannerItemOptionsRequired extends BannerItemOptionsBase {
11
+ required: true;
12
+ script: undefined;
13
+ }
14
+ interface BannerItemOptionsOptional extends BannerItemOptionsBase {
15
+ required: false;
16
+ script: ScriptDefinition;
17
+ }
18
+ export type BannerItemOptions = BannerItemOptionsRequired | BannerItemOptionsOptional;
19
+ export interface BannerItemProps extends Omit<BannerItemOptions, "script"> {
20
+ openItem?: string;
21
+ }
22
+ export declare const BannerItem: ({ value, label, sublabel, required, description, openItem, }: BannerItemProps) => import("preact").JSX.Element;
23
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./BannerItem";
@@ -0,0 +1,5 @@
1
+ import type { HTMLAttributes } from "react";
2
+ export interface ButtonProps extends HTMLAttributes<HTMLButtonElement> {
3
+ variant?: "neutral" | "brand" | "ghost";
4
+ }
5
+ export declare const Button: ({ variant, ...rest }: ButtonProps) => import("preact").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from "./Button";
@@ -0,0 +1,5 @@
1
+ import { type SwitchProps as RadixSwitchProps } from "@radix-ui/react-switch";
2
+ export interface SwitchProps extends RadixSwitchProps {
3
+ label?: string;
4
+ }
5
+ export declare const Switch: ({ label, id, ...rest }: SwitchProps) => import("preact").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from "./Switch";
@@ -0,0 +1,8 @@
1
+ import type { JSX } from "react";
2
+ export type TextProps<T extends keyof JSX.IntrinsicElements> = JSX.IntrinsicElements[T] & {
3
+ as?: T;
4
+ size?: "body" | "caption";
5
+ weight?: "normal" | "bold";
6
+ color?: "default" | "muted";
7
+ };
8
+ export declare const Text: <T extends keyof JSX.IntrinsicElements>({ as, size, weight, color, ...rest }: TextProps<T>) => JSX.Element;
@@ -0,0 +1 @@
1
+ export * from "./Text";
@@ -0,0 +1,23 @@
1
+ import { type PropsWithChildren } from "react";
2
+ import { type SelectionSchema } from "../utils/selection";
3
+ import type { BannerItemOptions } from "../components/BannerItem";
4
+ export type SelectionContextType = {
5
+ selection: SelectionSchema | null;
6
+ toggleSelection: (key: string, value: boolean) => void;
7
+ onDeclineAll: () => void;
8
+ onSave: () => void;
9
+ selectionTaken: boolean;
10
+ } | null;
11
+ export declare const SelectionContext: import("preact").Context<SelectionContextType>;
12
+ export interface SelectionProviderProps extends PropsWithChildren {
13
+ items: Pick<BannerItemOptions, "value" | "script" | "required" | "defaultSelected">[];
14
+ localStorageKey: string;
15
+ }
16
+ export declare const SelectionProvider: ({ children, items, localStorageKey, }: SelectionProviderProps) => import("preact").JSX.Element;
17
+ export declare function useSelection(): {
18
+ selection: SelectionSchema | null;
19
+ toggleSelection: (key: string, value: boolean) => void;
20
+ onDeclineAll: () => void;
21
+ onSave: () => void;
22
+ selectionTaken: boolean;
23
+ };
@@ -0,0 +1 @@
1
+ export { Banner, type BannerProps } from "./components/Banner";
@@ -0,0 +1 @@
1
+ export { mountBanner } from "./utils/mountBanner";
@@ -0,0 +1,2 @@
1
+ export declare function cls(...classes: (string | undefined)[]): string;
2
+ export declare function clx(classes: Record<string, boolean>): string;
@@ -0,0 +1,2 @@
1
+ import { type BannerOptions } from "../components/Banner";
2
+ export declare function mountBanner(options: BannerOptions, targetElement?: HTMLElement | string): void;
@@ -0,0 +1,35 @@
1
+ import * as z from "zod/mini";
2
+ export declare const remoteScriptDefinitionSchema: z.ZodMiniObject<{
3
+ variant: z.ZodMiniLiteral<"remote">;
4
+ type: z.ZodMiniOptional<z.ZodMiniString<string>>;
5
+ src: z.ZodMiniString<string>;
6
+ async: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
7
+ defer: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
8
+ crossorigin: z.ZodMiniOptional<z.ZodMiniString<string>>;
9
+ integrity: z.ZodMiniOptional<z.ZodMiniString<string>>;
10
+ }, z.core.$strip>;
11
+ export type RemoteScriptDefinition = z.infer<typeof remoteScriptDefinitionSchema>;
12
+ export declare const inlineScriptDefinitionSchema: z.ZodMiniObject<{
13
+ variant: z.ZodMiniLiteral<"inline">;
14
+ type: z.ZodMiniOptional<z.ZodMiniString<string>>;
15
+ async: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
16
+ defer: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
17
+ content: z.ZodMiniString<string>;
18
+ }, z.core.$strip>;
19
+ export type InlineScriptDefinition = z.infer<typeof inlineScriptDefinitionSchema>;
20
+ export declare const scriptDefinitionSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
21
+ variant: z.ZodMiniLiteral<"remote">;
22
+ type: z.ZodMiniOptional<z.ZodMiniString<string>>;
23
+ src: z.ZodMiniString<string>;
24
+ async: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
25
+ defer: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
26
+ crossorigin: z.ZodMiniOptional<z.ZodMiniString<string>>;
27
+ integrity: z.ZodMiniOptional<z.ZodMiniString<string>>;
28
+ }, z.core.$strip>, z.ZodMiniObject<{
29
+ variant: z.ZodMiniLiteral<"inline">;
30
+ type: z.ZodMiniOptional<z.ZodMiniString<string>>;
31
+ async: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
32
+ defer: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
33
+ content: z.ZodMiniString<string>;
34
+ }, z.core.$strip>], "variant">;
35
+ export type ScriptDefinition = z.infer<typeof scriptDefinitionSchema>;
@@ -0,0 +1,3 @@
1
+ import * as z from "zod/mini";
2
+ export declare const selectionSchema: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniBoolean<boolean>>;
3
+ export type SelectionSchema = z.infer<typeof selectionSchema>;
@@ -0,0 +1,9 @@
1
+ export function cls(...classes) {
2
+ return classes.filter(Boolean).join(" ");
3
+ }
4
+ export function clx(classes) {
5
+ return Object.entries(classes)
6
+ .filter(([, value]) => value)
7
+ .map(([key]) => key)
8
+ .join(" ");
9
+ }
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "preact/jsx-runtime";
2
+ import { Banner } from "../components/Banner";
3
+ import { render } from "preact";
4
+ export function mountBanner(options, targetElement) {
5
+ const noTarget = targetElement === undefined;
6
+ let element;
7
+ if (typeof targetElement === "string") {
8
+ const target = document.querySelector(targetElement);
9
+ if (!target) {
10
+ throw new Error(`Element with selector "${targetElement}" not found`);
11
+ }
12
+ element = target;
13
+ }
14
+ else {
15
+ element = targetElement;
16
+ }
17
+ render(_jsx(Banner, { noTarget: noTarget, ...options }), element ?? document.body);
18
+ }
@@ -0,0 +1,21 @@
1
+ import * as z from "zod/mini";
2
+ export const remoteScriptDefinitionSchema = z.object({
3
+ variant: z.literal("remote"),
4
+ type: z.optional(z.string()),
5
+ src: z.string(),
6
+ async: z.optional(z.boolean()),
7
+ defer: z.optional(z.boolean()),
8
+ crossorigin: z.optional(z.string()),
9
+ integrity: z.optional(z.string()),
10
+ });
11
+ export const inlineScriptDefinitionSchema = z.object({
12
+ variant: z.literal("inline"),
13
+ type: z.optional(z.string()),
14
+ async: z.optional(z.boolean()),
15
+ defer: z.optional(z.boolean()),
16
+ content: z.string(),
17
+ });
18
+ export const scriptDefinitionSchema = z.discriminatedUnion("variant", [
19
+ remoteScriptDefinitionSchema,
20
+ inlineScriptDefinitionSchema,
21
+ ]);
@@ -0,0 +1,2 @@
1
+ import * as z from "zod/mini";
2
+ export const selectionSchema = z.record(z.string(), z.boolean());
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Chris Kolb <chris@uninspired.studio>",
5
5
  "license": "MIT",
6
6
  "private": false,
7
- "version": "0.0.4",
7
+ "version": "0.0.6",
8
8
  "type": "module",
9
9
  "exports": {
10
10
  "./react": {
@@ -31,13 +31,14 @@
31
31
  "dev": "bunx --bun vite -c vite.config.dev.ts",
32
32
  "build:script": "bunx --bun vite build -c vite.config.script.ts",
33
33
  "build:react": "bunx --bun vite build -c vite.config.react.ts",
34
- "build:safe": "tsc -b && bunx --bun vite build",
34
+ "build:safe": "tsc -b && bun run build:script && bun run build:react",
35
35
  "build": "bun run build:script && bun run build:react",
36
36
  "preview": "bunx --bun vite preview"
37
37
  },
38
38
  "peerDependencies": {
39
- "react": "^19",
40
- "react-dom": "^19"
39
+ "react": "^18",
40
+ "react-dom": "^18",
41
+ "preact": "^10.28.4"
41
42
  },
42
43
  "dependencies": {
43
44
  "@radix-ui/react-accordion": "^1.2.12",
@@ -45,15 +46,14 @@
45
46
  "@radix-ui/react-dialog": "^1.1.15",
46
47
  "@radix-ui/react-switch": "^1.2.6",
47
48
  "lucide-react": "^0.575.0",
48
- "preact": "^10.28.4",
49
49
  "zod": "^4.3.6"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@preact/preset-vite": "^2.10.3",
53
53
  "@types/bun": "^1.3.9",
54
54
  "@types/node": "^24.10.1",
55
- "@types/react": "^19",
56
- "@types/react-dom": "^19",
55
+ "@types/react": "^18",
56
+ "@types/react-dom": "^18",
57
57
  "@vitejs/plugin-react": "^5.1.4",
58
58
  "typescript": "~5.9.3",
59
59
  "vite": "^7.3.1",