@motech-development/breeze-ui 2.1.0 → 2.1.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.
package/lib/index.esm.js CHANGED
@@ -1964,49 +1964,21 @@ const ModalDialog = styled.div`
1964
1964
  position: relative;
1965
1965
  `;
1966
1966
  const Modal = ({ children, isOpen, onDismiss, size = 'sm', title })=>{
1967
- const output = document.createElement('div');
1968
1967
  const doNotDismiss = (e)=>{
1969
1968
  e.stopPropagation();
1970
1969
  };
1971
- const modal = /*#__PURE__*/ jsxs(Suspense, {
1972
- fallback: /*#__PURE__*/ jsx(Loader, {}),
1973
- children: [
1974
- /*#__PURE__*/ jsx(ModalOuter, {
1975
- "aria-modal": true,
1976
- "aria-label": title,
1977
- role: "dialog",
1978
- tabIndex: -1,
1979
- onClick: onDismiss,
1980
- children: /*#__PURE__*/ jsx(ModalDialog, {
1981
- size: size,
1982
- role: "document",
1983
- children: /*#__PURE__*/ jsx(ModalContent, {
1984
- onClick: doNotDismiss,
1985
- children: /*#__PURE__*/ jsx(Card, {
1986
- padding: "lg",
1987
- children: children
1988
- })
1989
- })
1990
- })
1991
- }),
1992
- /*#__PURE__*/ jsx(Overlay, {})
1993
- ]
1994
- });
1995
1970
  useEffect(()=>{
1996
1971
  const keyboardEvent = (e)=>{
1997
1972
  if (e.key === 'Escape') {
1998
1973
  onDismiss();
1999
1974
  }
2000
1975
  };
2001
- document.body.appendChild(output);
2002
1976
  document.addEventListener('keydown', keyboardEvent, false);
2003
1977
  return ()=>{
2004
- document.body.removeChild(output);
2005
1978
  document.body.style.removeProperty('overflow');
2006
1979
  document.removeEventListener('keydown', keyboardEvent, false);
2007
1980
  };
2008
1981
  }, [
2009
- output,
2010
1982
  onDismiss
2011
1983
  ]);
2012
1984
  useEffect(()=>{
@@ -2017,7 +1989,30 @@ const Modal = ({ children, isOpen, onDismiss, size = 'sm', title })=>{
2017
1989
  isOpen
2018
1990
  ]);
2019
1991
  if (isOpen) {
2020
- return /*#__PURE__*/ createPortal(modal, output);
1992
+ return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsxs(Suspense, {
1993
+ fallback: /*#__PURE__*/ jsx(Loader, {}),
1994
+ children: [
1995
+ /*#__PURE__*/ jsx(ModalOuter, {
1996
+ "aria-modal": true,
1997
+ "aria-label": title,
1998
+ role: "dialog",
1999
+ tabIndex: -1,
2000
+ onClick: onDismiss,
2001
+ children: /*#__PURE__*/ jsx(ModalDialog, {
2002
+ size: size,
2003
+ role: "document",
2004
+ children: /*#__PURE__*/ jsx(ModalContent, {
2005
+ onClick: doNotDismiss,
2006
+ children: /*#__PURE__*/ jsx(Card, {
2007
+ padding: "lg",
2008
+ children: children
2009
+ })
2010
+ })
2011
+ })
2012
+ }),
2013
+ /*#__PURE__*/ jsx(Overlay, {})
2014
+ ]
2015
+ }), document.body);
2021
2016
  }
2022
2017
  return null;
2023
2018
  };
@@ -2704,7 +2699,6 @@ const selectIcon = (alertType)=>{
2704
2699
  }
2705
2700
  };
2706
2701
  const ToastProvider = ({ children })=>{
2707
- const output = document.createElement('div');
2708
2702
  const [toasts, setToasts] = useState([]);
2709
2703
  const add = useCallback(({ colour, message, onDismiss })=>{
2710
2704
  const id = generateId();
@@ -2720,34 +2714,18 @@ const ToastProvider = ({ children })=>{
2720
2714
  }, [
2721
2715
  toasts
2722
2716
  ]);
2723
- const remove = useCallback((id)=>setToasts(toasts.filter((t)=>{
2724
- if (t.id === id && t.onDismiss) {
2725
- t.onDismiss();
2717
+ const remove = useCallback((id)=>{
2718
+ setToasts((value)=>{
2719
+ const item = value.findIndex((t)=>t.id === id);
2720
+ if (value[item]?.onDismiss) {
2721
+ value[item].onDismiss();
2726
2722
  }
2727
- return t.id !== id;
2728
- })), [
2729
- toasts
2730
- ]);
2731
- const alerts = /*#__PURE__*/ jsx(ToastContainer, {
2732
- children: toasts.map(({ colour, id, message })=>/*#__PURE__*/ jsx(Alert, {
2733
- spacing: "lg",
2734
- dismissable: 5000,
2735
- icon: /*#__PURE__*/ jsx(FontAwesomeIcon, {
2736
- icon: selectIcon(colour)
2737
- }),
2738
- colour: colour,
2739
- message: message,
2740
- onDismiss: ()=>remove(id)
2741
- }, id))
2742
- });
2743
- useEffect(()=>{
2744
- document.body.appendChild(output);
2745
- return ()=>{
2746
- document.body.removeChild(output);
2747
- };
2748
- }, [
2749
- output
2750
- ]);
2723
+ if (item !== -1) {
2724
+ value.splice(item, 1);
2725
+ }
2726
+ return value;
2727
+ });
2728
+ }, []);
2751
2729
  const value = useMemo(()=>({
2752
2730
  add,
2753
2731
  remove
@@ -2759,7 +2737,20 @@ const ToastProvider = ({ children })=>{
2759
2737
  value: value,
2760
2738
  children: [
2761
2739
  children,
2762
- /*#__PURE__*/ createPortal(alerts, output)
2740
+ /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx(ToastContainer, {
2741
+ children: toasts.map(({ colour, id, message })=>/*#__PURE__*/ jsx(Alert, {
2742
+ spacing: "lg",
2743
+ dismissable: 5000,
2744
+ icon: /*#__PURE__*/ jsx(FontAwesomeIcon, {
2745
+ icon: selectIcon(colour)
2746
+ }),
2747
+ colour: colour,
2748
+ message: message,
2749
+ onDismiss: ()=>{
2750
+ remove(id);
2751
+ }
2752
+ }, id))
2753
+ }), document.body)
2763
2754
  ]
2764
2755
  });
2765
2756
  };