@harpercollins/harpercollins-design-system 1.8.56 → 1.8.57

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.
@@ -1,2 +1,3 @@
1
1
  export { useToggle } from "./useToggle";
2
2
  export { useLocalStorage } from "./useLocalStorage";
3
+ export { useFetch } from "./useFetch";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Custom hook to fetch data from an API.
3
+ */
4
+ export declare const useFetch: <T = unknown>(url: string, options?: RequestInit) => {
5
+ data: T | null;
6
+ loading: boolean;
7
+ error: Error | null;
8
+ };
9
+ export default useFetch;
@@ -1 +1,9 @@
1
+ /**
2
+ * A hook to store a value in local storage.
3
+ * @param key The key to store the value under in local storage.
4
+ * @param initialValue The initial value to store in local storage.
5
+ * @returns An array with the current value and a function to set the value.
6
+ * @example
7
+ * const [value, setValue] = useLocalStorage("myValue", "initialValue");
8
+ */
1
9
  export declare function useLocalStorage<V>(key: string, initialValue: V): [V, (newValue: V) => void];
@@ -1,3 +1,8 @@
1
+ /**
2
+ * A hook to toggle a boolean value.
3
+ * @param initialState The initial state of the toggle.
4
+ * @returns An object with the current value and functions to toggle, set to true, and set to false.
5
+ */
1
6
  export declare function useToggle(initialState: boolean | (() => boolean)): {
2
7
  value: boolean;
3
8
  toggle: () => void;
package/dist/esm/index.js CHANGED
@@ -1289,5 +1289,5 @@ function af(e,t){const n=of(e,t);return"production"!==process.env.NODE_ENV?(...t
1289
1289
  }
1290
1290
  `,Lw=rn.div`
1291
1291
  position: relative;
1292
- `;let Fw=1;const Vw=p((({children:n,side:o,size:i="md",open:l=!1,closeBlocked:s,onClose:c=(()=>{}),onCloseCompleted:d=(()=>{}),closeRequested:p=!1,...f},m)=>{const g=a(null);g.current||(g.current=`overlay-${Fw}`,Fw+=1);const h=a(null),[v,b]=r.useState(!1);r.useEffect((()=>{if(v){const e=setTimeout(d,200);return()=>{clearTimeout(e)}}return()=>{}})),u((()=>{p&&b(!0)}),[p]),g.current||(g.current=`modal-${Fw}`,Fw+=1),u((()=>{document.body.style.overflow=l?"hidden":"auto"}),[l]),u((()=>{const e=e=>{"Escape"===e.key&&(e.preventDefault(),c())};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}}),[c]);return e(kw,{open:l&&!v,anchor:o,className:`${o} ${l?"open":"closing"}`,size:i,...f,children:e(Dw,{children:t(Tw,{ref:h,children:[s&&t(_w,{role:"alert","aria-live":"assertive",children:[e(Ti,{name:["fas","exclamation-triangle"]}),t("p",{children:[e("strong",{children:"You have unsaved changes."})," Please save or cancel before closing."]})]}),e(Lw,{ref:m,children:e(Ow,{children:n})})]})})})}));function jw(e){const[t,n]=c(e);return{value:t,toggle:f((()=>n((e=>!e))),[]),setTrue:f((()=>n(!0)),[]),setFalse:f((()=>n(!1)),[])}}export{Li as Accordion,Lu as AppBar,yw as Autocomplete,Sw as AutocompleteSelectMultiple,Hi as Badge,Ky as Box,Nh as Breadcrumb,ll as Button,jb as Chip,Wi as Divider,Vw as Drawer,zu as DropDownMenu,cn as Heading,Ti as Icon,zb as IconButton,Cw as Input,Eh as Layout,Wv as List,Dv as ListItem,Xv as ListItemButton,hw as ListItemDecorator,Ki as LoadingSpinner,Iu as Logo,wu as ProgressBar,Gi as ProgressCircle,dl as ReadMore,fl as RelativeTime,ec as StatusIcon,ou as Table,du as Tabs,hu as TextBlock,vw as TextField,Ou as ToastMessages,qs as Tooltip,Zc as useLocalStorage,jw as useToggle};
1292
+ `;let Fw=1;const Vw=p((({children:n,side:o,size:i="md",open:l=!1,closeBlocked:s,onClose:c=(()=>{}),onCloseCompleted:d=(()=>{}),closeRequested:p=!1,...f},m)=>{const g=a(null);g.current||(g.current=`overlay-${Fw}`,Fw+=1);const h=a(null),[v,b]=r.useState(!1);r.useEffect((()=>{if(v){const e=setTimeout(d,200);return()=>{clearTimeout(e)}}return()=>{}})),u((()=>{p&&b(!0)}),[p]),g.current||(g.current=`modal-${Fw}`,Fw+=1),u((()=>{document.body.style.overflow=l?"hidden":"auto"}),[l]),u((()=>{const e=e=>{"Escape"===e.key&&(e.preventDefault(),c())};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}}),[c]);return e(kw,{open:l&&!v,anchor:o,className:`${o} ${l?"open":"closing"}`,size:i,...f,children:e(Dw,{children:t(Tw,{ref:h,children:[s&&t(_w,{role:"alert","aria-live":"assertive",children:[e(Ti,{name:["fas","exclamation-triangle"]}),t("p",{children:[e("strong",{children:"You have unsaved changes."})," Please save or cancel before closing."]})]}),e(Lw,{ref:m,children:e(Ow,{children:n})})]})})})}));function jw(e){const[t,n]=c(e);return{value:t,toggle:f((()=>n((e=>!e))),[]),setTrue:f((()=>n(!0)),[]),setFalse:f((()=>n(!1)),[])}}const Bw=(e,t)=>{const[n,o]=c(null),[r,a]=c(!0),[i,l]=c(null);return u((()=>{let n=!0;return(async()=>{try{const r=await fetch(e,t);if(!r.ok)throw new Error(`Error: ${r.statusText}`);const i=await r.json();n&&(o(i),a(!1))}catch(e){n&&(l(e),a(!1))}})(),()=>{n=!1}}),[e,t]),{data:n,loading:r,error:i}};export{Li as Accordion,Lu as AppBar,yw as Autocomplete,Sw as AutocompleteSelectMultiple,Hi as Badge,Ky as Box,Nh as Breadcrumb,ll as Button,jb as Chip,Wi as Divider,Vw as Drawer,zu as DropDownMenu,cn as Heading,Ti as Icon,zb as IconButton,Cw as Input,Eh as Layout,Wv as List,Dv as ListItem,Xv as ListItemButton,hw as ListItemDecorator,Ki as LoadingSpinner,Iu as Logo,wu as ProgressBar,Gi as ProgressCircle,dl as ReadMore,fl as RelativeTime,ec as StatusIcon,ou as Table,du as Tabs,hu as TextBlock,vw as TextField,Ou as ToastMessages,qs as Tooltip,Bw as useFetch,Zc as useLocalStorage,jw as useToggle};
1293
1293
  //# sourceMappingURL=index.js.map