@alextheman/components 7.0.0 → 7.0.1

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.
@@ -92,7 +92,7 @@ interface QueryBoundaryErrorProps {
92
92
  declare function QueryBoundaryError({
93
93
  children,
94
94
  logError
95
- }: QueryBoundaryErrorProps): string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
95
+ }: QueryBoundaryErrorProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
96
96
  //#endregion
97
97
  //#region src/QueryBoundary/QueryBoundaryNullable.d.ts
98
98
  interface QueryBoundaryNullablePropsWithUndefinedOrNull {
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from "react";
2
- import { OptionalOnCondition } from "@alextheman/utility";
3
2
  import { AlertColor } from "@mui/material/Alert";
3
+ import { OptionalOnCondition } from "@alextheman/utility";
4
4
 
5
5
  //#region src/root/types/ContextHookOptions.d.ts
6
6
  interface ContextHookOptions<Strict extends boolean = true> {
@@ -47,5 +47,9 @@ declare function SnackbarProvider({
47
47
  autoHideDuration
48
48
  }: SnackbarProviderProps): import("react/jsx-runtime").JSX.Element;
49
49
  //#endregion
50
- export { SnackbarProvider, type SnackbarProviderProps, useSnackbarContext };
50
+ //#region src/snackbar/Snackbars.d.ts
51
+ /** Displays the array of snackbars provided by `SnackbarProvider`. */
52
+ declare function Snackbars(): import("react/jsx-runtime").JSX.Element;
53
+ //#endregion
54
+ export { SnackbarProvider, type SnackbarProviderProps, Snackbars, useSnackbarContext };
51
55
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,2 @@
1
- import{DataError as e}from"@alextheman/utility/v6";import{createContext as t,use as n,useState as r}from"react";import{jsx as i}from"react/jsx-runtime";const a=t(void 0);function o({strict:t=!0}={}){let r=n(a);if(t&&!r)throw new e({strict:t,context:r},`SNACKBAR_PROVIDER_NOT_FOUND`,`Could not find the SnackbarProvider context. Please double-check that it is present.`);return r}function s({children:e,autoHideDuration:t=5e3}){let[n,o]=r([]);function s(e,n={}){let{severity:r=`info`,duration:i=t}=n;o(t=>[...t,{severity:r,id:crypto.randomUUID(),message:e,duration:i}])}function c(e){o(t=>{let n=[...t];return e===void 0?(n.shift(),n):n.filter(t=>t.id!==e)})}return i(a,{value:{snackbars:n,addSnackbar:s,removeSnackbar:c},children:e})}export{s as SnackbarProvider,o as useSnackbarContext};
1
+ import{DataError as e}from"@alextheman/utility/v6";import{createContext as t,use as n,useEffect as r,useState as i}from"react";import{jsx as a}from"react/jsx-runtime";import o from"@mui/material/Alert";import s from"@mui/material/Snackbar";const c=t(void 0);function l({strict:t=!0}={}){let r=n(c);if(t&&!r)throw new e({strict:t,context:r},`SNACKBAR_PROVIDER_NOT_FOUND`,`Could not find the SnackbarProvider context. Please double-check that it is present.`);return r}function u({children:e,autoHideDuration:t=5e3}){let[n,r]=i([]);function o(e,n={}){let{severity:i=`info`,duration:a=t}=n;r(t=>[...t,{severity:i,id:crypto.randomUUID(),message:e,duration:a}])}function s(e){r(t=>{let n=[...t];return e===void 0?(n.shift(),n):n.filter(t=>t.id!==e)})}return a(c,{value:{snackbars:n,addSnackbar:o,removeSnackbar:s},children:e})}function d(){let{snackbars:e,removeSnackbar:t}=l(),[n,c]=i(!1),[u,d]=i(null);function f(e,t){t!==`clickaway`&&(d(null),c(!1))}return r(()=>{!n&&e.length!==0&&(d(e[0]),t(),c(!0))},[n,t,e]),a(s,{open:n,autoHideDuration:u?.duration,onClose:f,children:a(o,{onClose:f,severity:u?.severity??`info`,children:u?.message})})}export{u as SnackbarProvider,d as Snackbars,l as useSnackbarContext};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/snackbar/SnackbarProvider.tsx"],"sourcesContent":["import type { OptionalOnCondition } from \"@alextheman/utility\";\nimport type { AlertColor } from \"@mui/material/Alert\";\nimport type { ReactNode } from \"react\";\n\nimport type { ContextHookOptions } from \"src/root/types\";\n\nimport { DataError } from \"@alextheman/utility/v6\";\nimport { createContext, use, useState } from \"react\";\n\nexport interface SnackbarProviderProps {\n /** The children that will have access to the snackbar context. */\n children: ReactNode;\n /** The amount of seconds to wait before hiding the snackbar. */\n autoHideDuration?: number;\n}\n\nexport interface SnackbarItem {\n /** The ID of the Snackbar */\n id: string;\n /** The severity of the alert. This defines the color and icon used. */\n severity?: AlertColor;\n /** The message to show as part of the snackbar. */\n message: string;\n /** The amount of milliseconds to show the snackbar for. */\n duration: number;\n}\n\nexport interface AddSnackbarOptions {\n severity?: AlertColor;\n duration?: number;\n}\nexport interface SnackbarContextValue {\n /** An array of all the snackbars to render. */\n snackbars: Array<SnackbarItem>;\n /** A function that adds the snackbar to the page. */\n addSnackbar: (message: string, options?: AddSnackbarOptions) => void;\n /** A function to remove a snackbar. */\n removeSnackbar: (id?: string) => void;\n}\n\nconst SnackbarContext = createContext<SnackbarContextValue | undefined>(undefined);\n\n/** Access the snackbar context directly. */\nexport function useSnackbarContext<Strict extends boolean = true>({\n strict = true as Strict,\n}: ContextHookOptions<Strict> = {}): OptionalOnCondition<Strict, SnackbarContextValue> {\n const context = use(SnackbarContext);\n if (strict && !context) {\n throw new DataError(\n { strict, context },\n \"SNACKBAR_PROVIDER_NOT_FOUND\",\n \"Could not find the SnackbarProvider context. Please double-check that it is present.\",\n );\n }\n return context as OptionalOnCondition<Strict, SnackbarContextValue>;\n}\n\n/** Provides an array of snackbars for the `Snackbars` component to display. */\nfunction SnackbarProvider({ children, autoHideDuration = 5000 }: SnackbarProviderProps) {\n const [snackbars, setSnackbars] = useState<Array<SnackbarItem>>([]);\n\n function addSnackbar(message: string, options: AddSnackbarOptions = {}) {\n const { severity = \"info\", duration = autoHideDuration } = options;\n setSnackbars((previous) => {\n return [\n ...previous,\n {\n severity,\n id: crypto.randomUUID(),\n message,\n duration,\n },\n ];\n });\n }\n\n function removeSnackbar(id?: string) {\n setSnackbars((previous) => {\n const newSnackbars = [...previous];\n if (id === undefined) {\n newSnackbars.shift();\n return newSnackbars;\n }\n\n return newSnackbars.filter((snackbar) => {\n return snackbar.id !== id;\n });\n });\n }\n\n return (\n <SnackbarContext value={{ snackbars, addSnackbar, removeSnackbar }}>{children}</SnackbarContext>\n );\n}\n\nexport default SnackbarProvider;\n"],"mappings":"wJAwCA,MAAM,EAAkB,EAAgD,IAAA,EAAS,EAGjF,SAAgB,EAAkD,CAChE,SAAS,IACqB,CAAC,EAAsD,CACrF,IAAM,EAAU,EAAI,CAAe,EACnC,GAAI,GAAU,CAAC,EACb,MAAM,IAAI,EACR,CAAE,SAAQ,SAAQ,EAClB,8BACA,sFACF,EAEF,OAAO,CACT,CAGA,SAAS,EAAiB,CAAE,WAAU,mBAAmB,KAA+B,CACtF,GAAM,CAAC,EAAW,GAAgB,EAA8B,CAAC,CAAC,EAElE,SAAS,EAAY,EAAiB,EAA8B,CAAC,EAAG,CACtE,GAAM,CAAE,WAAW,OAAQ,WAAW,GAAqB,EAC3D,EAAc,GACL,CACL,GAAG,EACH,CACE,WACA,GAAI,OAAO,WAAW,EACtB,UACA,UACF,CACF,CACD,CACH,CAEA,SAAS,EAAe,EAAa,CACnC,EAAc,GAAa,CACzB,IAAM,EAAe,CAAC,GAAG,CAAQ,EAMjC,OALI,IAAO,IAAA,IACT,EAAa,MAAM,EACZ,GAGF,EAAa,OAAQ,GACnB,EAAS,KAAO,CACxB,CACH,CAAC,CACH,CAEA,OACE,EAAC,EAAD,CAAiB,MAAO,CAAE,YAAW,cAAa,gBAAe,EAAI,UAA0B,CAAA,CAEnG"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/snackbar/SnackbarProvider.tsx","../../src/snackbar/Snackbars.tsx"],"sourcesContent":["import type { OptionalOnCondition } from \"@alextheman/utility\";\nimport type { AlertColor } from \"@mui/material/Alert\";\nimport type { ReactNode } from \"react\";\n\nimport type { ContextHookOptions } from \"src/root/types\";\n\nimport { DataError } from \"@alextheman/utility/v6\";\nimport { createContext, use, useState } from \"react\";\n\nexport interface SnackbarProviderProps {\n /** The children that will have access to the snackbar context. */\n children: ReactNode;\n /** The amount of seconds to wait before hiding the snackbar. */\n autoHideDuration?: number;\n}\n\nexport interface SnackbarItem {\n /** The ID of the Snackbar */\n id: string;\n /** The severity of the alert. This defines the color and icon used. */\n severity?: AlertColor;\n /** The message to show as part of the snackbar. */\n message: string;\n /** The amount of milliseconds to show the snackbar for. */\n duration: number;\n}\n\nexport interface AddSnackbarOptions {\n severity?: AlertColor;\n duration?: number;\n}\nexport interface SnackbarContextValue {\n /** An array of all the snackbars to render. */\n snackbars: Array<SnackbarItem>;\n /** A function that adds the snackbar to the page. */\n addSnackbar: (message: string, options?: AddSnackbarOptions) => void;\n /** A function to remove a snackbar. */\n removeSnackbar: (id?: string) => void;\n}\n\nconst SnackbarContext = createContext<SnackbarContextValue | undefined>(undefined);\n\n/** Access the snackbar context directly. */\nexport function useSnackbarContext<Strict extends boolean = true>({\n strict = true as Strict,\n}: ContextHookOptions<Strict> = {}): OptionalOnCondition<Strict, SnackbarContextValue> {\n const context = use(SnackbarContext);\n if (strict && !context) {\n throw new DataError(\n { strict, context },\n \"SNACKBAR_PROVIDER_NOT_FOUND\",\n \"Could not find the SnackbarProvider context. Please double-check that it is present.\",\n );\n }\n return context as OptionalOnCondition<Strict, SnackbarContextValue>;\n}\n\n/** Provides an array of snackbars for the `Snackbars` component to display. */\nfunction SnackbarProvider({ children, autoHideDuration = 5000 }: SnackbarProviderProps) {\n const [snackbars, setSnackbars] = useState<Array<SnackbarItem>>([]);\n\n function addSnackbar(message: string, options: AddSnackbarOptions = {}) {\n const { severity = \"info\", duration = autoHideDuration } = options;\n setSnackbars((previous) => {\n return [\n ...previous,\n {\n severity,\n id: crypto.randomUUID(),\n message,\n duration,\n },\n ];\n });\n }\n\n function removeSnackbar(id?: string) {\n setSnackbars((previous) => {\n const newSnackbars = [...previous];\n if (id === undefined) {\n newSnackbars.shift();\n return newSnackbars;\n }\n\n return newSnackbars.filter((snackbar) => {\n return snackbar.id !== id;\n });\n });\n }\n\n return (\n <SnackbarContext value={{ snackbars, addSnackbar, removeSnackbar }}>{children}</SnackbarContext>\n );\n}\n\nexport default SnackbarProvider;\n","import type { SyntheticEvent } from \"react\";\n\nimport type { SnackbarItem } from \"src/snackbar/SnackbarProvider\";\n\nimport Alert from \"@mui/material/Alert\";\nimport Snackbar from \"@mui/material/Snackbar\";\nimport { useEffect, useState } from \"react\";\n\nimport { useSnackbarContext } from \"src/snackbar/SnackbarProvider\";\n\n/** Displays the array of snackbars provided by `SnackbarProvider`. */\nfunction Snackbars() {\n const { snackbars, removeSnackbar } = useSnackbarContext();\n const [open, setOpen] = useState<boolean>(false);\n const [currentSnackbar, setCurrentSnackbar] = useState<SnackbarItem | null>(null);\n\n function onClose(_: SyntheticEvent | Event, reason?: string) {\n if (reason !== \"clickaway\") {\n setCurrentSnackbar(null);\n setOpen(false);\n }\n }\n\n useEffect(() => {\n if (!open && snackbars.length !== 0) {\n /* eslint-disable @eslint-react/set-state-in-effect -- This is a legitimate usage as we need to be able to control exactly when the snackbar gets added/shown. */\n setCurrentSnackbar(snackbars[0]);\n removeSnackbar();\n setOpen(true);\n /* eslint-enable */\n }\n }, [open, removeSnackbar, snackbars]);\n\n return (\n <Snackbar open={open} autoHideDuration={currentSnackbar?.duration} onClose={onClose}>\n <Alert onClose={onClose} severity={currentSnackbar?.severity ?? \"info\"}>\n {currentSnackbar?.message}\n </Alert>\n </Snackbar>\n );\n}\n\nexport default Snackbars;\n"],"mappings":"gPAwCA,MAAM,EAAkB,EAAgD,IAAA,EAAS,EAGjF,SAAgB,EAAkD,CAChE,SAAS,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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/components",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "A package containing common React components used across my projects.",
5
5
  "repository": {
6
6
  "type": "git",