@uninspired/cookie-banner 0.0.8 → 0.0.10

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 (41) hide show
  1. package/dist/react/index.cjs +1994 -4061
  2. package/dist/react/index.js +1343 -3393
  3. package/dist/react/style.css +165 -18
  4. package/dist/script/index.cjs +1 -45
  5. package/dist/script/index.js +1561 -2091
  6. package/dist/script/style.css +1 -1
  7. package/package.json +2 -4
  8. package/dist/components/Banner/Banner.js +0 -38
  9. package/dist/components/Banner/index.js +0 -1
  10. package/dist/components/BannerItem/BannerItem.js +0 -24
  11. package/dist/components/BannerItem/index.js +0 -1
  12. package/dist/components/Button/Button.js +0 -6
  13. package/dist/components/Button/index.js +0 -1
  14. package/dist/components/Switch/Switch.js +0 -7
  15. package/dist/components/Switch/index.js +0 -1
  16. package/dist/components/Text/Text.js +0 -9
  17. package/dist/components/Text/index.js +0 -1
  18. package/dist/contexts/SelectionContext.js +0 -101
  19. package/dist/react.js +0 -1
  20. package/dist/script.js +0 -1
  21. package/dist/types/components/Banner/Banner.d.ts +0 -21
  22. package/dist/types/components/Banner/index.d.ts +0 -1
  23. package/dist/types/components/BannerItem/BannerItem.d.ts +0 -23
  24. package/dist/types/components/BannerItem/index.d.ts +0 -1
  25. package/dist/types/components/Button/Button.d.ts +0 -5
  26. package/dist/types/components/Button/index.d.ts +0 -1
  27. package/dist/types/components/Switch/Switch.d.ts +0 -5
  28. package/dist/types/components/Switch/index.d.ts +0 -1
  29. package/dist/types/components/Text/Text.d.ts +0 -8
  30. package/dist/types/components/Text/index.d.ts +0 -1
  31. package/dist/types/contexts/SelectionContext.d.ts +0 -23
  32. package/dist/types/react.d.ts +0 -1
  33. package/dist/types/script.d.ts +0 -1
  34. package/dist/types/utils/classes.d.ts +0 -2
  35. package/dist/types/utils/mountBanner.d.ts +0 -2
  36. package/dist/types/utils/scriptDefinition.d.ts +0 -35
  37. package/dist/types/utils/selection.d.ts +0 -3
  38. package/dist/utils/classes.js +0 -9
  39. package/dist/utils/mountBanner.js +0 -18
  40. package/dist/utils/scriptDefinition.js +0 -21
  41. package/dist/utils/selection.js +0 -2
@@ -1 +1 @@
1
- ._root_hw69b_1{all:unset;cursor:pointer;will-change:background-color;transition:background-color .15s ease-in-out;font-size:var(--cb-font-size-caption);line-height:var(--cb-line-height-caption);font-family:var(--cb-font-family-caption);letter-spacing:var(--cb-letter-spacing-caption);font-weight:var(--cb-font-weight-caption-bold);padding:var(--cb-space-xs) var(--cb-space-sm);border-radius:var(--cb-radius-md);display:flex;flex-direction:row;align-items:center}._root_hw69b_1._neutral_hw69b_17{background-color:var(--cb-color-button-neutral-background);color:var(--cb-color-button-neutral-foreground)}._root_hw69b_1._neutral_hw69b_17:hover{background-color:var(--cb-color-button-neutral-background-hover)}._root_hw69b_1._neutral_hw69b_17:active{background-color:var(--cb-color-button-neutral-background-active)}._root_hw69b_1._brand_hw69b_30{background-color:var(--cb-color-button-brand-background);color:var(--cb-color-button-brand-foreground)}._root_hw69b_1._brand_hw69b_30:hover{background-color:var(--cb-color-button-brand-background-hover)}._root_hw69b_1._brand_hw69b_30:active{background-color:var(--cb-color-button-brand-background-active)}._root_hw69b_1._ghost_hw69b_43{background-color:var(--cb-color-button-ghost-background);color:var(--cb-color-button-ghost-foreground)}._root_hw69b_1._ghost_hw69b_43:hover{background-color:var(--cb-color-button-ghost-background-hover)}._root_hw69b_1._ghost_hw69b_43:active{background-color:var(--cb-color-button-ghost-background-active)}._root_14l5h_1{color:var(--cb-color-text-default)}._root_14l5h_1._muted_14l5h_4{color:var(--cb-color-text-muted)}._root_14l5h_1._body_14l5h_8{font-size:var(--cb-font-size-body);font-family:var(--cb-font-family-body);line-height:var(--cb-line-height-body);letter-spacing:var(--cb-letter-spacing-body)}._root_14l5h_1._body_14l5h_8._normal_14l5h_14{font-weight:var(--cb-font-weight-body-normal)}._root_14l5h_1._body_14l5h_8._bold_14l5h_18{font-weight:var(--cb-font-weight-body-bold)}._root_14l5h_1._caption_14l5h_23{font-size:var(--cb-font-size-caption);font-family:var(--cb-font-family-caption);line-height:var(--cb-line-height-caption);letter-spacing:var(--cb-letter-spacing-caption)}._root_14l5h_1._caption_14l5h_23._normal_14l5h_14{font-weight:var(--cb-font-weight-caption-normal)}._root_14l5h_1._caption_14l5h_23._bold_14l5h_18{font-weight:var(--cb-font-weight-caption-bold)}._root_14l5h_1 a{all:unset;color:var(--cb-color-text-link);cursor:pointer;text-decoration:none}._root_14l5h_1 a:hover{color:var(--cb-color-text-link-hover);text-decoration:underline}@keyframes _contentShow_1wsw7_1{0%{opacity:0;transform:translate(-100px)}to{opacity:1;transform:translate(0)}}@keyframes _slideDown_1wsw7_1{0%{max-height:var(--cb-size-settings-max-height);overflow:auto}1%{max-height:var(--cb-size-settings-max-height);overflow:hidden}to{max-height:0;overflow:hidden}}@keyframes _slideUp_1wsw7_1{0%{max-height:0;overflow:hidden}99%{max-height:var(--cb-size-settings-max-height);overflow:hidden}to{max-height:var(--cb-size-settings-max-height);overflow:auto}}._root_1wsw7_42{display:flex;flex-direction:column;gap:var(--cb-space-md);padding:var(--cb-space-md);background-color:var(--cb-color-background-default);box-shadow:var(--cb-shadow-lg);border-radius:var(--cb-radius-md);overflow:hidden;animation:_contentShow_1wsw7_1 .15s cubic-bezier(.16,1,.3,1)}._root_1wsw7_42._noTarget_1wsw7_53{position:fixed;bottom:var(--cb-space-md);left:var(--cb-space-md);width:100%;max-width:var(--cb-size-banner-max-width)}._root_1wsw7_42 ._collapsible_1wsw7_62{display:contents}._root_1wsw7_42 ._collapsible_1wsw7_62 ._header_1wsw7_65{display:flex;flex-direction:row;align-items:flex-start;justify-content:space-between;gap:var(--cb-space-md)}._root_1wsw7_42 ._collapsible_1wsw7_62 ._header_1wsw7_65 ._heading_1wsw7_72{display:flex;flex-direction:column;align-items:flex-start}._root_1wsw7_42 ._collapsible_1wsw7_62 ._header_1wsw7_65 ._chevron_1wsw7_78{transform:rotate(0);will-change:transform;transition:transform .15s ease-out}._root_1wsw7_42 ._collapsible_1wsw7_62 ._header_1wsw7_65 ._chevron_1wsw7_78._open_1wsw7_83{transform:rotate(180deg)}._root_1wsw7_42 ._collapsible_1wsw7_62 ._settings_1wsw7_89{display:flex;flex-direction:column;background-color:var(--cb-color-background-muted);border-radius:var(--cb-radius-md);overflow:hidden;will-change:max-height,overflow;animation:_slideDown_1wsw7_1 .25s ease-out}._root_1wsw7_42 ._collapsible_1wsw7_62 ._settings_1wsw7_89[data-state=open]{animation:_slideUp_1wsw7_1 .25s ease-out}._root_1wsw7_42 ._collapsible_1wsw7_62 ._footer_1wsw7_103{display:flex;flex-direction:row;align-items:center;justify-content:space-between;gap:var(--cb-space-md)}._root_1wsw7_42 ._collapsible_1wsw7_62 ._footer_1wsw7_103 ._actions_1wsw7_113{display:flex;flex-direction:row;align-items:center;gap:var(--cb-space-md)}:root{--cb-color-background-default: var(--cb-color-neutral-0);--cb-color-background-muted: var(--cb-color-neutral-50);--cb-color-text-default: var(--cb-color-neutral-900);--cb-color-text-muted: var(--cb-color-neutral-500);--cb-color-text-link: var(--cb-color-brand-600);--cb-color-text-link-hover: var(--cb-color-brand-700);--cb-color-border-neutral: var(--cb-color-neutral-200);--cb-color-border-brand: var(--cb-color-brand-200);--cb-color-switch-background-neutral: var(--cb-color-neutral-100);--cb-color-switch-background-light: var(--cb-color-brand-500);--cb-color-switch-background-brand: var(--cb-color-brand-600);--cb-color-switch-background-disabled: var(--cb-color-neutral-300);--cb-color-switch-thumb-background-neutral: var(--cb-color-neutral-0);--cb-color-button-neutral-background: var(--cb-color-neutral-100);--cb-color-button-neutral-background-hover: var(--cb-color-neutral-200);--cb-color-button-neutral-background-active: var(--cb-color-neutral-100);--cb-color-button-neutral-foreground: var(--cb-color-neutral-700);--cb-color-button-brand-background: var(--cb-color-brand-100);--cb-color-button-brand-background-hover: var(--cb-color-brand-200);--cb-color-button-brand-background-active: var(--cb-color-brand-100);--cb-color-button-brand-foreground: var(--cb-color-brand-700);--cb-color-button-ghost-background: rgba(0, 0, 0, 0);--cb-color-button-ghost-background-hover: var(--cb-color-neutral-200);--cb-color-button-ghost-background-active: var(--cb-color-neutral-100);--cb-color-button-ghost-foreground: var(--cb-color-neutral-700)}
1
+ ._root_hw69b_1{all:unset;cursor:pointer;will-change:background-color;transition:background-color .15s ease-in-out;font-size:var(--cb-font-size-caption);line-height:var(--cb-line-height-caption);font-family:var(--cb-font-family-caption);letter-spacing:var(--cb-letter-spacing-caption);font-weight:var(--cb-font-weight-caption-bold);padding:var(--cb-space-xs) var(--cb-space-sm);border-radius:var(--cb-radius-md);display:flex;flex-direction:row;align-items:center}._root_hw69b_1._neutral_hw69b_17{background-color:var(--cb-color-button-neutral-background);color:var(--cb-color-button-neutral-foreground)}._root_hw69b_1._neutral_hw69b_17:hover{background-color:var(--cb-color-button-neutral-background-hover)}._root_hw69b_1._neutral_hw69b_17:active{background-color:var(--cb-color-button-neutral-background-active)}._root_hw69b_1._brand_hw69b_30{background-color:var(--cb-color-button-brand-background);color:var(--cb-color-button-brand-foreground)}._root_hw69b_1._brand_hw69b_30:hover{background-color:var(--cb-color-button-brand-background-hover)}._root_hw69b_1._brand_hw69b_30:active{background-color:var(--cb-color-button-brand-background-active)}._root_hw69b_1._ghost_hw69b_43{background-color:var(--cb-color-button-ghost-background);color:var(--cb-color-button-ghost-foreground)}._root_hw69b_1._ghost_hw69b_43:hover{background-color:var(--cb-color-button-ghost-background-hover)}._root_hw69b_1._ghost_hw69b_43:active{background-color:var(--cb-color-button-ghost-background-active)}._root_14l5h_1{color:var(--cb-color-text-default)}._root_14l5h_1._muted_14l5h_4{color:var(--cb-color-text-muted)}._root_14l5h_1._body_14l5h_8{font-size:var(--cb-font-size-body);font-family:var(--cb-font-family-body);line-height:var(--cb-line-height-body);letter-spacing:var(--cb-letter-spacing-body)}._root_14l5h_1._body_14l5h_8._normal_14l5h_14{font-weight:var(--cb-font-weight-body-normal)}._root_14l5h_1._body_14l5h_8._bold_14l5h_18{font-weight:var(--cb-font-weight-body-bold)}._root_14l5h_1._caption_14l5h_23{font-size:var(--cb-font-size-caption);font-family:var(--cb-font-family-caption);line-height:var(--cb-line-height-caption);letter-spacing:var(--cb-letter-spacing-caption)}._root_14l5h_1._caption_14l5h_23._normal_14l5h_14{font-weight:var(--cb-font-weight-caption-normal)}._root_14l5h_1._caption_14l5h_23._bold_14l5h_18{font-weight:var(--cb-font-weight-caption-bold)}._root_14l5h_1 a{all:unset;color:var(--cb-color-text-link);cursor:pointer;text-decoration:none}._root_14l5h_1 a:hover{color:var(--cb-color-text-link-hover);text-decoration:underline}@keyframes _contentShow_2wcp0_1{0%{opacity:0;transform:translate(-100px)}to{opacity:1;transform:translate(0)}}@keyframes _contentHide_2wcp0_1{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(-100px)}}@keyframes _slideDown_2wcp0_1{0%{max-height:var(--cb-size-settings-max-height);overflow:auto}1%{max-height:var(--cb-size-settings-max-height);overflow:hidden}to{max-height:0;overflow:hidden}}@keyframes _slideUp_2wcp0_1{0%{max-height:0;overflow:hidden}99%{max-height:var(--cb-size-settings-max-height);overflow:hidden}to{max-height:var(--cb-size-settings-max-height);overflow:auto}}._root_2wcp0_53{display:none;visibility:hidden;flex-direction:column;gap:var(--cb-space-md);padding:var(--cb-space-md);background-color:var(--cb-color-background-default);box-shadow:var(--cb-shadow-lg);border-radius:var(--cb-radius-md);overflow:hidden;will-change:opacity,transform;animation:_contentHide_2wcp0_1 .15s cubic-bezier(.16,1,.3,1)}._root_2wcp0_53._open_2wcp0_66{visibility:visible;display:flex;animation:_contentShow_2wcp0_1 .15s cubic-bezier(.16,1,.3,1)}._root_2wcp0_53._noTarget_2wcp0_72{position:fixed;bottom:var(--cb-space-md);left:var(--cb-space-md);width:100%;max-width:var(--cb-size-banner-max-width)}._root_2wcp0_53 ._collapsible_2wcp0_81{display:contents}._root_2wcp0_53 ._collapsible_2wcp0_81 ._header_2wcp0_84{display:flex;flex-direction:row;align-items:flex-start;justify-content:space-between;gap:var(--cb-space-md)}._root_2wcp0_53 ._collapsible_2wcp0_81 ._header_2wcp0_84 ._heading_2wcp0_91{display:flex;flex-direction:column;align-items:flex-start}._root_2wcp0_53 ._collapsible_2wcp0_81 ._header_2wcp0_84 ._chevron_2wcp0_97{transform:rotate(0);will-change:transform;transition:transform .15s ease-out}._root_2wcp0_53 ._collapsible_2wcp0_81 ._header_2wcp0_84 ._chevron_2wcp0_97._open_2wcp0_66{transform:rotate(180deg)}._root_2wcp0_53 ._collapsible_2wcp0_81 ._settings_2wcp0_108{display:flex;flex-direction:column;background-color:var(--cb-color-background-muted);border-radius:var(--cb-radius-md);overflow:hidden;will-change:max-height,overflow;animation:_slideDown_2wcp0_1 .25s ease-out}._root_2wcp0_53 ._collapsible_2wcp0_81 ._settings_2wcp0_108[data-state=open]{animation:_slideUp_2wcp0_1 .25s ease-out}._root_2wcp0_53 ._collapsible_2wcp0_81 ._footer_2wcp0_122{display:flex;flex-direction:row;align-items:center;justify-content:space-between;gap:var(--cb-space-md)}._root_2wcp0_53 ._collapsible_2wcp0_81 ._footer_2wcp0_122 ._actions_2wcp0_132{display:flex;flex-direction:row;align-items:center;gap:var(--cb-space-md)}@keyframes _slideDown_mqtha_1{0%{height:0}to{height:var(--radix-accordion-content-height)}}@keyframes _slideUp_mqtha_1{0%{height:var(--radix-accordion-content-height)}to{height:0}}._root_mqtha_19{display:flex;flex-direction:column;overflow:hidden}._root_mqtha_19 ._header_mqtha_24{all:unset;display:flex;flex-direction:row;align-items:center;justify-content:space-between;padding:var(--cb-space-sm) var(--cb-space-md);cursor:pointer}._root_mqtha_19 ._header_mqtha_24 ._label_mqtha_33{display:flex;flex-direction:column;width:100%}._root_mqtha_19 ._header_mqtha_24 ._actions_mqtha_39{display:flex;flex-direction:row;align-items:center;gap:var(--cb-space-sm)}._root_mqtha_19 ._header_mqtha_24 ._actions_mqtha_39 ._chevron_mqtha_45{color:var(--cb-color-text-default);transition:transform .15s ease-out;will-change:transform;transform:rotate(0)}._root_mqtha_19 ._header_mqtha_24 ._actions_mqtha_39 ._chevron_mqtha_45._open_mqtha_51{transform:rotate(180deg)}._root_mqtha_19 ._description_mqtha_58{padding:var(--cb-space-xs) var(--cb-space-md);max-width:96ch;overflow:hidden}._root_mqtha_19 ._description_mqtha_58[data-state=open]{animation:_slideDown_mqtha_1 .15s ease-out}._root_mqtha_19 ._description_mqtha_58[data-state=closed]{animation:_slideUp_mqtha_1 .15s ease-out}._root_dibqz_1{display:flex;flex-direction:row;align-items:center;justify-content:space-between;gap:var(--cb-space-sm)}._root_dibqz_1 ._switch_dibqz_8{width:32px;height:20px;padding:2px;border-width:1px;border-style:solid;border-color:var(--cb-color-border-neutral);border-radius:9999px;will-change:background-color;transition:background-color .15s ease-out;background-color:var(--cb-color-switch-background-neutral);position:relative}._root_dibqz_1 ._switch_dibqz_8[data-state=checked]{background-color:var(--cb-color-switch-background-brand)}._root_dibqz_1 ._switch_dibqz_8[data-disabled]{cursor:not-allowed;background-color:var(--cb-color-switch-background-disabled)}._root_dibqz_1 ._switch_dibqz_8:not([data-disabled]){cursor:pointer}._root_dibqz_1 ._switch_dibqz_8:not([data-disabled]):hover{background-color:var(--cb-color-switch-background-light)}._root_dibqz_1 ._switch_dibqz_8 ._thumb_dibqz_38{width:14px;height:14px;position:absolute;left:0;top:0;background-color:var(--cb-color-switch-thumb-background-neutral);box-shadow:var(--cb-shadow-sm);border-radius:9999px;transition:transform .15s ease-out;transform:translate(2px) translateY(2px);will-change:transform}._root_dibqz_1 ._switch_dibqz_8 ._thumb_dibqz_38[data-state=checked]{transform:translate(14px) translateY(2px)}:root{--cb-color-background-default: var(--cb-color-neutral-0);--cb-color-background-muted: var(--cb-color-neutral-50);--cb-color-text-default: var(--cb-color-neutral-900);--cb-color-text-muted: var(--cb-color-neutral-500);--cb-color-text-link: var(--cb-color-brand-600);--cb-color-text-link-hover: var(--cb-color-brand-700);--cb-color-border-neutral: var(--cb-color-neutral-200);--cb-color-border-brand: var(--cb-color-brand-200);--cb-color-switch-background-neutral: var(--cb-color-neutral-100);--cb-color-switch-background-light: var(--cb-color-brand-500);--cb-color-switch-background-brand: var(--cb-color-brand-600);--cb-color-switch-background-disabled: var(--cb-color-neutral-300);--cb-color-switch-thumb-background-neutral: var(--cb-color-neutral-0);--cb-color-button-neutral-background: var(--cb-color-neutral-100);--cb-color-button-neutral-background-hover: var(--cb-color-neutral-200);--cb-color-button-neutral-background-active: var(--cb-color-neutral-100);--cb-color-button-neutral-foreground: var(--cb-color-neutral-700);--cb-color-button-brand-background: var(--cb-color-brand-100);--cb-color-button-brand-background-hover: var(--cb-color-brand-200);--cb-color-button-brand-background-active: var(--cb-color-brand-100);--cb-color-button-brand-foreground: var(--cb-color-brand-700);--cb-color-button-ghost-background: rgba(0, 0, 0, 0);--cb-color-button-ghost-background-hover: var(--cb-color-neutral-200);--cb-color-button-ghost-background-active: var(--cb-color-neutral-100);--cb-color-button-ghost-foreground: var(--cb-color-neutral-700)}
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.8",
7
+ "version": "0.0.10",
8
8
  "type": "module",
9
9
  "exports": {
10
10
  "./react": {
@@ -38,9 +38,7 @@
38
38
  "peerDependencies": {
39
39
  "react": "^18",
40
40
  "react-dom": "^18",
41
- "preact": "^10.28.4"
42
- },
43
- "dependencies": {
41
+ "preact": "^10.28.4",
44
42
  "@radix-ui/react-accordion": "^1.2.12",
45
43
  "@radix-ui/react-collapsible": "^1.1.12",
46
44
  "@radix-ui/react-dialog": "^1.1.15",
@@ -1,38 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { useMemo, useState } from "react";
3
- import { cls, clx } from "../../utils/classes";
4
- import { Button } from "../Button";
5
- import { Text } from "../Text";
6
- import classes from "./Banner.module.css";
7
- import {} from "../BannerItem";
8
- // import { BannerItem, type BannerItemOptions } from "../BannerItem";
9
- // import { Root as AccordionRoot } from "@radix-ui/react-accordion";
10
- import { ChevronUp } from "lucide-react";
11
- import { SelectionProvider, useSelection, } from "../../contexts/SelectionContext";
12
- import { Root as DialogRoot, Content as DialogContent, Title as DialogTitle, Description as DialogDescription, Close as DialogClose, } from "@radix-ui/react-dialog";
13
- import { Root as CollapsibleRoot, Trigger as CollapsibleTrigger,
14
- // Content as CollapsibleContent,
15
- } from "@radix-ui/react-collapsible";
16
- import "../../styles/variables.css";
17
- const BannerContent = ({ noTarget = true, heading = "We use cookies.", subheading = "Please define your selection below.", selectLabel = "Select", hideLabel = "Hide", saveLabel = "Save selection", declineLabel = "Decline all", defaultSettingsOpen = true, privacyPolicy,
18
- // items,
19
- }) => {
20
- const { onSave, onDeclineAll, selectionTaken } = useSelection();
21
- // const [openItem, setOpenItem] = useState<string | undefined>(undefined);
22
- const [settingsOpen, setSettingsOpen] = useState(defaultSettingsOpen);
23
- return (_jsx(DialogRoot, { open: !selectionTaken, children: _jsx(DialogContent, { className: cls(classes.root, noTarget ? classes.noTarget : ""), children: _jsxs(CollapsibleRoot, { open: settingsOpen, onOpenChange: setSettingsOpen, className: classes.collapsible, children: [_jsxs("div", { className: classes.header, children: [_jsxs("div", { className: classes.heading, children: [_jsx(DialogTitle, { asChild: true, children: _jsx(Text, { weight: "bold", children: heading }) }), _jsx(DialogDescription, { asChild: true, children: _jsx(Text, { size: "caption", color: "muted", children: subheading }) })] }), _jsx(CollapsibleTrigger, { asChild: true, children: _jsxs(Button, { variant: "ghost", children: [settingsOpen ? hideLabel : selectLabel, "\u00A0", _jsx(ChevronUp, { size: 12, className: clx({
24
- [classes.chevron]: true,
25
- [classes.open]: settingsOpen,
26
- }) })] }) })] }), _jsxs("div", { className: classes.footer, children: [_jsx("div", { className: classes.legal, children: privacyPolicy && (_jsx(Text, { size: "caption", children: _jsx("a", { href: privacyPolicy.url, target: "_blank", children: privacyPolicy.label }) })) }), _jsxs("div", { className: classes.actions, children: [_jsx(DialogClose, { asChild: true, children: _jsx(Button, { variant: "neutral", onClick: () => onDeclineAll(), children: declineLabel }) }), _jsx(DialogClose, { asChild: true, children: _jsx(Button, { variant: "brand", onClick: () => onSave(), children: saveLabel }) })] })] })] }) }) }));
27
- };
28
- export const Banner = ({ localStorageKey = "cb-selection", items, ...rest }) => {
29
- const selectionItems = useMemo(() => items
30
- .filter((item) => !item.required)
31
- .map((item) => ({
32
- value: item.value,
33
- script: item.script,
34
- defaultSelected: item.defaultSelected,
35
- required: item.required,
36
- })), [items]);
37
- return (_jsx(SelectionProvider, { items: selectionItems, localStorageKey: localStorageKey, children: _jsx(BannerContent, { items: items, ...rest }) }));
38
- };
@@ -1 +0,0 @@
1
- export * from "./Banner";
@@ -1,24 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import classes from "./BannerItem.module.css";
3
- import {} from "../../utils/scriptDefinition";
4
- import { Text } from "../Text";
5
- import { Item, Trigger, Content } from "@radix-ui/react-accordion";
6
- import { ChevronDown } from "lucide-react";
7
- import { clx } from "../../utils/classes";
8
- import { Switch } from "../Switch";
9
- import { useEffect, useMemo } from "react";
10
- import { useSelection } from "../../contexts/SelectionContext";
11
- export const BannerItem = ({ value, label, sublabel, required = false, description, openItem, }) => {
12
- const { toggleSelection, selection } = useSelection();
13
- const selected = useMemo(() => selection?.[value] ?? false, [selection, value]);
14
- useEffect(() => {
15
- toggleSelection(value, selected);
16
- }, [value, selected]);
17
- const checked = useMemo(() => (required ? true : selected), [required, selected]);
18
- const onCheckedChange = useMemo(() => (checked) => required ? () => { } : toggleSelection(value, checked), [required, toggleSelection, value]);
19
- const disabled = useMemo(() => required, [required]);
20
- return (_jsxs(Item, { value: value, className: classes.root, children: [_jsxs("div", { className: classes.header, children: [_jsx(Trigger, { asChild: true, children: _jsxs("div", { className: classes.label, children: [_jsx(Text, { weight: "bold", children: label }), sublabel && (_jsx(Text, { size: "caption", color: "muted", children: sublabel }))] }) }), _jsxs("div", { className: classes.actions, children: [_jsx(Switch, { checked: checked, onCheckedChange: onCheckedChange, disabled: disabled }), _jsx(Trigger, { asChild: true, children: _jsx(ChevronDown, { size: 16, className: clx({
21
- [classes.chevron]: true,
22
- [classes.open]: openItem === value,
23
- }) }) })] })] }), description && (_jsx(Content, { className: classes.description, children: _jsx(Text, { size: "caption", dangerouslySetInnerHTML: { __html: description } }) }))] }));
24
- };
@@ -1 +0,0 @@
1
- export * from "./BannerItem";
@@ -1,6 +0,0 @@
1
- import { jsx as _jsx } from "preact/jsx-runtime";
2
- import classes from "./Button.module.css";
3
- import { cls } from "../../utils/classes";
4
- export const Button = ({ variant = "neutral", ...rest }) => {
5
- return _jsx("button", { className: cls(classes.root, classes[variant]), ...rest });
6
- };
@@ -1 +0,0 @@
1
- export * from "./Button";
@@ -1,7 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { Root, Thumb, } from "@radix-ui/react-switch";
3
- import classes from "./Switch.module.css";
4
- import { Text } from "../Text";
5
- export const Switch = ({ label, id, ...rest }) => {
6
- return (_jsxs("div", { className: classes.root, children: [label && (_jsx(Text, { className: classes.label, as: "label", htmlFor: id, children: label })), _jsx(Root, { className: classes.switch, ...rest, children: _jsx(Thumb, { className: classes.thumb }) })] }));
7
- };
@@ -1 +0,0 @@
1
- export * from "./Switch";
@@ -1,9 +0,0 @@
1
- import { jsx as _jsx } from "preact/jsx-runtime";
2
- import { cls } from "../../utils/classes";
3
- import classes from "./Text.module.css";
4
- export const Text = ({ as = "span", size = "body", weight = "normal", color = "default", ...rest }) => {
5
- const Component = as ?? "span";
6
- return (
7
- // @ts-ignore
8
- _jsx(Component, { className: cls(classes.root, classes[size], classes[weight], classes[color]), ...rest }));
9
- };
@@ -1 +0,0 @@
1
- export * from "./Text";
@@ -1,101 +0,0 @@
1
- import { jsx as _jsx } from "preact/jsx-runtime";
2
- import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
3
- import { selectionSchema } from "../utils/selection";
4
- import { scriptDefinitionSchema } from "../utils/scriptDefinition";
5
- export const SelectionContext = createContext(null);
6
- export const SelectionProvider = ({ children, items, localStorageKey, }) => {
7
- function getLsSelection(localStorageKey) {
8
- const storedSelection = localStorage.getItem(localStorageKey);
9
- if (!storedSelection)
10
- return null;
11
- const { success, data } = selectionSchema.safeParse(JSON.parse(storedSelection));
12
- if (!success)
13
- return null;
14
- return data;
15
- }
16
- const defaultSelection = useMemo(() => Object.fromEntries(items.map((item) => [item.value, item.defaultSelected ?? false])), [items]);
17
- const [selection, setSelection] = useState(getLsSelection(localStorageKey) ?? defaultSelection);
18
- const [savedSelection, setSavedSelection] = useState(getLsSelection(localStorageKey));
19
- function toggleSelection(key, value) {
20
- const newSelection = selection
21
- ? { ...selection, [key]: value }
22
- : { [key]: value };
23
- setSelection(newSelection);
24
- }
25
- useEffect(() => {
26
- let selectedValues = [];
27
- if (savedSelection !== null) {
28
- selectedValues = Object.entries(savedSelection)
29
- .filter(([_, value]) => value)
30
- .map(([key]) => key);
31
- }
32
- const mountedItems = items.filter((item) => selectedValues.includes(item.value));
33
- for (const item of items) {
34
- const elem = document.head.querySelector(`#${item.value}`);
35
- if (!elem)
36
- continue;
37
- elem.remove();
38
- }
39
- for (const item of mountedItems) {
40
- const elem = document.createElement("script");
41
- elem.id = item.value;
42
- if (!item.script) {
43
- if (!item.required)
44
- console.warn("CookieBanner: Missing script for", item.value);
45
- continue;
46
- }
47
- const { success, data: script } = scriptDefinitionSchema.safeParse(item.script);
48
- if (!success) {
49
- console.error("CookieBanner: Invalid script definition for", item.value);
50
- continue;
51
- }
52
- elem.type = script.type ?? "text/javascript";
53
- elem.async = script.async ?? false;
54
- elem.defer = script.defer ?? false;
55
- switch (script.variant) {
56
- case "inline":
57
- elem.textContent = script.content;
58
- break;
59
- case "remote":
60
- elem.src = script.src;
61
- elem.crossOrigin = script.crossorigin ?? null;
62
- elem.integrity = script.integrity ?? "";
63
- break;
64
- }
65
- document.head.appendChild(elem);
66
- }
67
- }, [savedSelection, items]);
68
- function saveSelection(newSelection) {
69
- setSavedSelection(newSelection);
70
- localStorage.setItem(localStorageKey, JSON.stringify(newSelection));
71
- }
72
- const onDeclineAll = useCallback(() => {
73
- const newSelection = Object.fromEntries(items.map((item) => [item.value, false]));
74
- setSelection(newSelection);
75
- saveSelection(newSelection);
76
- }, [items]);
77
- const onSave = useCallback(() => {
78
- saveSelection(selection);
79
- }, [selection]);
80
- const selectionTaken = useMemo(() => {
81
- if (!savedSelection)
82
- return false;
83
- const selectedKeys = Object.keys(savedSelection);
84
- const itemKeys = items.map((item) => item.value);
85
- return itemKeys.every((key) => selectedKeys.includes(key));
86
- }, [savedSelection, items]);
87
- return (_jsx(SelectionContext.Provider, { value: {
88
- selection,
89
- toggleSelection,
90
- onDeclineAll,
91
- onSave,
92
- selectionTaken,
93
- }, children: children }));
94
- };
95
- export function useSelection() {
96
- const context = useContext(SelectionContext);
97
- if (!context) {
98
- throw new Error("useSelection must be used within a SelectionProvider");
99
- }
100
- return context;
101
- }
package/dist/react.js DELETED
@@ -1 +0,0 @@
1
- export { Banner } from "./components/Banner";
package/dist/script.js DELETED
@@ -1 +0,0 @@
1
- export { mountBanner } from "./utils/mountBanner";
@@ -1,21 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export * from "./Banner";
@@ -1,23 +0,0 @@
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 {};
@@ -1 +0,0 @@
1
- export * from "./BannerItem";
@@ -1,5 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export * from "./Button";
@@ -1,5 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export * from "./Switch";
@@ -1,8 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export * from "./Text";
@@ -1,23 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- export { Banner, type BannerProps } from "./components/Banner";
@@ -1 +0,0 @@
1
- export { mountBanner } from "./utils/mountBanner";
@@ -1,2 +0,0 @@
1
- export declare function cls(...classes: (string | undefined)[]): string;
2
- export declare function clx(classes: Record<string, boolean>): string;
@@ -1,2 +0,0 @@
1
- import { type BannerOptions } from "../components/Banner";
2
- export declare function mountBanner(options: BannerOptions, targetElement?: HTMLElement | string): void;
@@ -1,35 +0,0 @@
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>;
@@ -1,3 +0,0 @@
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>;
@@ -1,9 +0,0 @@
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
- }
@@ -1,18 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
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
- ]);
@@ -1,2 +0,0 @@
1
- import * as z from "zod/mini";
2
- export const selectionSchema = z.record(z.string(), z.boolean());