@equinor/amplify-component-lib 9.8.1 → 9.8.2

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.
@@ -20,7 +20,6 @@ export interface State {
20
20
  export declare const useSnackbar: () => State;
21
21
  export type SnackbarProviderProps = {
22
22
  children: ReactNode;
23
- showAPIErrors?: boolean;
24
23
  } & SnackbarProps;
25
24
  /**
26
25
  * @param children - Children to render under the SnackbarProvider
@@ -1 +1 @@
1
- import{jsxs as r,jsx as o}from"react/jsx-runtime";import{createContext as t,useContext as i,useState as e,useCallback as a}from"react";import{Icon as n,Typography as s,Snackbar as c,Button as d}from"@equinor/eds-core-react";import{close as l}from"@equinor/eds-icons";import{StyledSnackbar as h}from"./SnackbarProvider.styles.js";import{snackbarIcon as m}from"./SnackbarProvider.utils.js";import{useApiErrorSnackbar as u}from"./hooks/useApiErrorSnackbar.js";const v=t(void 0),b=()=>{const r=i(v);if(void 0===r)throw new Error("useSnackbar must be used within a SnackbarContextProvider");return r},p=({children:t,showAPIErrors:i=!0,...b})=>{const[p,k]=e(!1),[f,S]=e(void 0),[w,P]=e(b),[x,C]=e(),A=a(((r,o)=>{S("string"==typeof r?{text:r,variant:"info"}:r),P(o?.customProps??b),C(o?.action??void 0),k(!0)}),[b]);u({showAPIErrors:i,showSnackbar:A});const j=()=>{k(!1),w.onClose&&w.onClose()};return r(v.Provider,{value:{showSnackbar:A,setActionDisabledState:r=>{C((o=>o?{...o,disabled:r}:o))},hideSnackbar:()=>k(!1)},children:[t,r(h,{$variant:f?.variant,open:p,onClose:j,autoHideDuration:w.autoHideDuration,placement:w.placement,children:[f&&o(n,{data:m(f.variant)}),o(s,{variant:"body_short",children:f?.text}),x&&o(c.Action,{children:o(d,{disabled:x.disabled,variant:"ghost",onClick:x.handler,children:x.text})}),o(d,{variant:"ghost_icon",onClick:j,children:o(n,{data:l})})]})]})};export{p as SnackbarProvider,b as useSnackbar};
1
+ import{jsxs as r,jsx as o}from"react/jsx-runtime";import{createContext as t,useContext as i,useState as e,useCallback as n}from"react";import{Icon as a,Typography as d,Snackbar as c,Button as s}from"@equinor/eds-core-react";import{close as l}from"@equinor/eds-icons";import{StyledSnackbar as m}from"./SnackbarProvider.styles.js";import{snackbarIcon as v}from"./SnackbarProvider.utils.js";const h=t(void 0),u=()=>{const r=i(h);if(void 0===r)throw new Error("useSnackbar must be used within a SnackbarContextProvider");return r},b=({children:t,...i})=>{const[u,b]=e(!1),[p,f]=e(void 0),[k,S]=e(i),[x,C]=e(),P=n(((r,o)=>{f("string"==typeof r?{text:r,variant:"info"}:r),S(o?.customProps??i),C(o?.action??void 0),b(!0)}),[i]),w=()=>{b(!1),k.onClose&&k.onClose()};return r(h.Provider,{value:{showSnackbar:P,setActionDisabledState:r=>{C((o=>o?{...o,disabled:r}:o))},hideSnackbar:()=>b(!1)},children:[t,r(m,{$variant:p?.variant,open:u,onClose:w,autoHideDuration:k.autoHideDuration,placement:k.placement,children:[p&&o(a,{data:v(p.variant)}),o(d,{variant:"body_short",children:p?.text}),x&&o(c.Action,{children:o(s,{disabled:x.disabled,variant:"ghost",onClick:x.handler,children:x.text})}),o(s,{variant:"ghost_icon",onClick:w,children:o(a,{data:l})})]})]})};export{b as SnackbarProvider,u as useSnackbar};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/amplify-component-lib",
3
- "version": "9.8.1",
3
+ "version": "9.8.2",
4
4
  "description": "Frontend Typescript components for the Amplify team",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,7 +0,0 @@
1
- import { ShowSnackbar, ShowSnackbarSettings } from '../SnackbarProvider';
2
- interface UseApiErrorSnackbarArgs {
3
- showAPIErrors: boolean;
4
- showSnackbar: (text: string | ShowSnackbar, props?: ShowSnackbarSettings) => void;
5
- }
6
- export declare function useApiErrorSnackbar({ showAPIErrors, showSnackbar, }: UseApiErrorSnackbarArgs): void;
7
- export {};
@@ -1 +0,0 @@
1
- import{useRef as e,useEffect as r}from"react";import{useIsFetching as t,useQueryClient as o}from"@tanstack/react-query";function s({showAPIErrors:s,showSnackbar:n}){const a=t()>0,c=o(),i=c.getQueryCache().findAll({predicate:e=>null!==e.state.error}),y=e([]);r((()=>{if(s&&!a){const e=i.filter((e=>!y.current.includes(e.queryHash)));for(const r of e){y.current.push(r.queryHash);const e=r.state.error;if("object"==typeof e&&e&&"name"in e&&"ApiError"===e.name){const r=e;let t=r.message;"body"in r&&r.body&&("object"==typeof r.body&&"userMessage"in r.body&&"string"==typeof r.body.userMessage&&(t=r.body.userMessage),"string"==typeof r.body&&(t=r.body)),n({text:`${r.status}: ${t}`,variant:"error"})}}}}),[i,a,c,s,n])}export{s as useApiErrorSnackbar};