UNPKG

@openpolicy/react

Version:

React components and hooks for OpenPolicy

308 lines (307 loc) 10.2 kB
import { CSSProperties, ComponentType, ReactNode } from "react"; import * as react_jsx_runtime0 from "react/jsx-runtime"; //#region ../core/dist/index.d.ts type PolicyCategory = "privacy" | "cookie"; type Jurisdiction = "us" | "eu" | "ca" | "au" | "nz" | "other"; type UserRight = "access" | "rectification" | "erasure" | "portability" | "restriction" | "objection" | "opt_out_sale" | "non_discrimination"; type LegalBasis = "consent" | "contract" | "legal_obligation" | "vital_interests" | "public_task" | "legitimate_interests"; type CompanyConfig = { name: string; legalName: string; address: string; contact: string; }; type EffectiveDate = `${number}-${number}-${number}`; type DataCollection = Record<string, string[]>; type Retention = Record<string, string>; type ThirdParty = { name: string; purpose: string; policyUrl?: string; }; type ChildrenConfig = { underAge: number; noticeUrl?: string; }; type CookiePolicyCookies = { essential: boolean; [key: string]: boolean; }; type TrackingTechnology = string; type ConsentMechanism = { hasBanner: boolean; hasPreferencePanel: boolean; canWithdraw: boolean; }; type PrivacyPolicyConfig = { effectiveDate: EffectiveDate; company: CompanyConfig; dataCollected: DataCollection; legalBasis: LegalBasis | LegalBasis[]; retention: Retention; cookies: CookiePolicyCookies; thirdParties: ThirdParty[]; userRights: UserRight[]; jurisdictions: Jurisdiction[]; children?: ChildrenConfig; }; type CookiePolicyConfig = { effectiveDate: EffectiveDate; company: CompanyConfig; cookies: CookiePolicyCookies; thirdParties: ThirdParty[]; trackingTechnologies?: TrackingTechnology[]; consentMechanism?: ConsentMechanism; jurisdictions: Jurisdiction[]; }; type OpenPolicyConfig = { company: CompanyConfig; effectiveDate: EffectiveDate; jurisdictions: Jurisdiction[]; dataCollected?: DataCollection; legalBasis?: LegalBasis | LegalBasis[]; retention?: Retention; children?: ChildrenConfig; thirdParties?: ThirdParty[]; cookies?: CookiePolicyCookies; trackingTechnologies?: TrackingTechnology[]; consentMechanism?: ConsentMechanism; policies?: PolicyCategory[]; }; //#endregion //#region src/consent.d.ts type CookieConsent = { essential: true; [key: string]: boolean; }; type CookieConsentStatus = "undecided" | "completed"; //#endregion //#region src/documents/types.d.ts type NodeContext = { reason?: string; }; type TextNode = { type: "text"; value: string; context?: NodeContext; }; type BoldNode = { type: "bold"; value: string; context?: NodeContext; }; type ItalicNode = { type: "italic"; value: string; context?: NodeContext; }; type LinkNode = { type: "link"; href: string; value: string; context?: NodeContext; }; type InlineNode = TextNode | BoldNode | ItalicNode | LinkNode; type HeadingNode = { type: "heading"; level?: 1 | 2 | 3 | 4 | 5 | 6; value: string; context?: NodeContext; }; type ParagraphNode = { type: "paragraph"; children: InlineNode[]; context?: NodeContext; }; type ListItemNode = { type: "listItem"; children: (InlineNode | ListNode)[]; context?: NodeContext; }; type ListNode = { type: "list"; ordered?: boolean; items: ListItemNode[]; context?: NodeContext; }; type ContentNode = HeadingNode | ParagraphNode | ListNode; type DocumentSection = { type: "section"; id: string; content: ContentNode[]; context?: NodeContext; }; type PolicyType = "privacy" | "cookie"; type Document = { type: "document"; policyType: PolicyType; sections: DocumentSection[]; context?: NodeContext; }; type Node = Document | DocumentSection | ContentNode | ListItemNode | InlineNode; //#endregion //#region src/documents/helpers.d.ts //#endregion //#region src/context.d.ts type CookieRoute = "cookie" | "preferences" | "closed"; type CookieCategory = { key: string; label: string; enabled: boolean; locked: boolean; }; type HasExpression = string | { and: HasExpression[]; } | { or: HasExpression[]; } | { not: HasExpression; }; type OpenPolicyProviderProps = { config: OpenPolicyConfig; shouldShow?: () => Promise<boolean>; children?: ReactNode; }; declare function OpenPolicyProvider({ config, shouldShow, children }: OpenPolicyProviderProps): react_jsx_runtime0.JSX.Element; //#endregion //#region src/components/ConsentGate.d.ts interface ConsentGateProps { requires: HasExpression; fallback?: ReactNode; children: ReactNode; } declare function ConsentGate({ requires, fallback, children }: ConsentGateProps): ReactNode; //#endregion //#region src/types.d.ts type PolicyTheme = Partial<Record<"--op-heading-color" | "--op-body-color" | "--op-section-gap" | "--op-font-family" | "--op-font-size-heading" | "--op-font-weight-heading" | "--op-font-size-body" | "--op-line-height" | "--op-link-color" | "--op-link-color-hover" | "--op-border-color" | "--op-border-radius", string>>; interface PolicyComponents { Section?: ComponentType<{ section: DocumentSection; children: ReactNode; }>; Heading?: ComponentType<{ node: HeadingNode; }>; Paragraph?: ComponentType<{ node: ParagraphNode; children: ReactNode; }>; List?: ComponentType<{ node: ListNode; children: ReactNode; }>; Text?: ComponentType<{ node: TextNode; }>; Bold?: ComponentType<{ node: BoldNode; }>; Italic?: ComponentType<{ node: ItalicNode; }>; Link?: ComponentType<{ node: LinkNode; }>; } //#endregion //#region src/components/CookiePolicy.d.ts interface CookiePolicyProps { config?: OpenPolicyConfig | CookiePolicyConfig; components?: PolicyComponents; style?: CSSProperties; } declare function CookiePolicy({ config: configProp, components, style }: CookiePolicyProps): react_jsx_runtime0.JSX.Element | null; //#endregion //#region src/components/defaults.d.ts declare function DefaultHeading({ node }: { node: HeadingNode; }): react_jsx_runtime0.JSX.Element; declare function DefaultText({ node }: { node: TextNode; }): react_jsx_runtime0.JSX.Element; declare function DefaultBold({ node }: { node: BoldNode; }): react_jsx_runtime0.JSX.Element; declare function DefaultLink({ node }: { node: LinkNode; }): react_jsx_runtime0.JSX.Element; declare function DefaultSection({ section, children }: { section: DocumentSection; children: ReactNode; }): react_jsx_runtime0.JSX.Element; declare function DefaultParagraph({ node: _node, children }: { node: ParagraphNode; children: ReactNode; }): react_jsx_runtime0.JSX.Element; declare function DefaultList({ node, children }: { node: ListNode; children: ReactNode; }): react_jsx_runtime0.JSX.Element; declare function renderNode(node: Node, components: PolicyComponents, key?: number): ReactNode; //#endregion //#region src/components/PrivacyPolicy.d.ts interface PrivacyPolicyProps { config?: OpenPolicyConfig | PrivacyPolicyConfig; components?: PolicyComponents; style?: CSSProperties; } declare function PrivacyPolicy({ config: configProp, components, style }: PrivacyPolicyProps): react_jsx_runtime0.JSX.Element | null; //#endregion //#region src/hooks/useCookies.d.ts declare function useCookies(): { readonly status: CookieConsentStatus; readonly consent: CookieConsent | null; readonly categories: CookieCategory[]; readonly route: CookieRoute; readonly has: (expr: HasExpression) => boolean; readonly acceptAll: () => void; readonly acceptNecessary: () => void; readonly toggle: (key: string) => void; readonly save: (onSave?: (consent: CookieConsent) => void) => void; readonly reset: () => void; readonly setRoute: (route: CookieRoute) => void; }; //#endregion //#region src/hooks/useShouldShowCookieBanner.d.ts declare function useShouldShowCookieBanner(status: CookieConsentStatus, shouldShow?: () => Promise<boolean>): boolean; //#endregion //#region src/render.d.ts declare function renderDocument(doc: Document, components?: PolicyComponents): ReactNode; //#endregion //#region src/styles.d.ts declare const defaultStyles = "\n.op-policy {\n --op-font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n --op-font-size-body: 1rem;\n --op-font-size-heading: 1.125rem;\n --op-font-weight-heading: 600;\n --op-line-height: 1.7;\n --op-body-color: #374151;\n --op-heading-color: #111827;\n --op-link-color: #2563eb;\n --op-link-color-hover: #1d4ed8;\n --op-section-gap: 2rem;\n --op-border-color: #e5e7eb;\n --op-border-radius: 0.375rem;\n\n font-family: var(--op-font-family);\n font-size: var(--op-font-size-body);\n color: var(--op-body-color);\n line-height: var(--op-line-height);\n max-width: 65ch;\n}\n\n.op-section {\n margin-bottom: var(--op-section-gap);\n padding-bottom: var(--op-section-gap);\n border-bottom: 1px solid var(--op-border-color);\n}\n.op-section:last-child {\n border-bottom: none;\n margin-bottom: 0;\n padding-bottom: 0;\n}\n\n.op-heading {\n font-size: var(--op-font-size-heading);\n font-weight: var(--op-font-weight-heading);\n color: var(--op-heading-color);\n line-height: 1.3;\n margin: 0 0 0.75rem;\n}\n\n.op-paragraph {\n margin: 0 0 0.75rem;\n}\n.op-paragraph:last-child { margin-bottom: 0; }\n\n.op-list {\n margin: 0 0 0.75rem;\n padding-left: 1.5rem;\n list-style-type: disc;\n}\n.op-list:last-child { margin-bottom: 0; }\n.op-list .op-list {\n margin-top: 0.375rem;\n margin-bottom: 0;\n list-style-type: circle;\n}\n\n.op-list-item {\n margin-bottom: 0.375rem;\n}\n.op-list-item:last-child { margin-bottom: 0; }\n\n.op-bold {\n font-weight: 600;\n color: var(--op-heading-color);\n}\n\n.op-link {\n color: var(--op-link-color);\n text-decoration: underline;\n text-underline-offset: 2px;\n transition: color 0.15s ease;\n}\n.op-link:hover { color: var(--op-link-color-hover); }\n"; //#endregion export { ConsentGate, type CookieCategory, CookiePolicy, type CookieRoute, DefaultBold, DefaultHeading, DefaultLink, DefaultList, DefaultParagraph, DefaultSection, DefaultText, type HasExpression, OpenPolicyProvider as OpenPolicy, type PolicyComponents, type PolicyTheme, PrivacyPolicy, defaultStyles, renderDocument, renderNode, useCookies, useShouldShowCookieBanner }; //# sourceMappingURL=index.d.ts.map