@tantainnovative/ndpr-toolkit
Version:
Nigeria Data Protection Toolkit — enterprise-grade compliance components for the Nigeria Data Protection Act (NDPA) 2023
1 lines • 1.71 kB
JavaScript
import {b}from'./chunk-5LJ652AH.mjs';import {c}from'./chunk-ZJYULEER.mjs';import {createContext,useMemo,useContext,Component}from'react';import {jsx,jsxs}from'react/jsx-runtime';var p=createContext({}),l=class extends Component{constructor(e){super(e);this.reset=()=>{this.setState({error:null});};this.state={error:null};}static getDerivedStateFromError(e){return {error:e}}componentDidCatch(e,r){var o,n;(n=(o=this.props).onError)==null||n.call(o,e,r);}render(){var r;let{error:e}=this.state;if(e){let{fallback:o}=this.props;return typeof o=="function"?o(e,this.reset):o!==void 0?o:jsxs("div",{role:"alert",style:{padding:"16px",border:"1px solid #e53e3e",borderRadius:"4px",backgroundColor:"#fff5f5",color:"#c53030"},children:[jsx("h3",{style:{margin:"0 0 8px 0",fontSize:"16px"},children:(r=this.props.errorTitle)!=null?r:"Something went wrong"}),jsx("p",{style:{margin:0,fontSize:"14px"},children:e.message})]})}return this.props.children}},x=o=>{var n=o,{children:t,fallback:c$1,onError:e}=n,r=c(n,["children","fallback","onError"]);var u;let m=useMemo(()=>{if(!r.theme)return;let i={};return r.theme.primary&&(i["--ndpr-primary"]=r.theme.primary),r.theme.primaryHover&&(i["--ndpr-primary-hover"]=r.theme.primaryHover),r.theme.primaryForeground&&(i["--ndpr-primary-foreground"]=r.theme.primaryForeground),Object.keys(i).length>0?i:void 0},[r.theme]),y=(u=useMemo(()=>b(r.locale),[r.locale]).common.error)!=null?u:"Something went wrong";return jsx(p.Provider,{value:r,children:jsx(l,{fallback:c$1,onError:e,errorTitle:y,children:m?jsx("div",{style:m,children:t}):t})})};function C(){return useContext(p)}function S(){let{locale:t}=useContext(p);return useMemo(()=>b(t),[t])}export{x as a,C as b,S as c};