All files / components/cookie CookieConsentApiControls.tsx

100% Statements 13/13
100% Branches 0/0
100% Functions 6/6
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 561x                         1x 2x 2x     1x 1x 1x     1x 1x     1x 5x                 1x     1x                              
"use client";
 
import { Button } from "@/components/ui/button";
import { Card, CardHeader, CardContent } from "@/components/ui/card";
import {
  run,
  reset,
  hide,
  acceptCategory,
  showPreferences,
} from "vanilla-cookieconsent";
import pluginConfig from "./CookieConsentConfig";
 
const acceptAndHide = (acceptType: string | string[]) => {
  acceptCategory(acceptType);
  hide();
};
 
const resetPlugin = () => {
  reset(true);
  run(pluginConfig);
};
 
const toggleDarkMode = () => {
  document.documentElement.classList.toggle("cc--darkmode");
};
 
const CookieConsentApiBtns = () => {
  return (
    <Card className="max-w-md mx-auto mt-6 p-4 shadow-lg border border-gray-200 dark:border-gray-700">
      <CardHeader>
        <h2 className="text-lg font-semibold">Cookie Preferences</h2>
      </CardHeader>
      <CardContent className="space-y-3">
        <Button onClick={showPreferences} variant="outline">
          Show Preferences
        </Button>
        <Button onClick={() => acceptAndHide("all")} variant="default">
          Accept All
        </Button>
        <Button onClick={() => acceptAndHide([])} variant="secondary">
          Accept Necessary
        </Button>
        <Button onClick={resetPlugin} variant="destructive">
          Reset Plugin
        </Button>
        <Button onClick={toggleDarkMode} variant="ghost">
          Toggle Dark Mode
        </Button>
      </CardContent>
    </Card>
  );
};
 
export default CookieConsentApiBtns;