@motech-development/breeze-ui 2.0.34 → 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.d.ts CHANGED
@@ -275,11 +275,13 @@ interface IMasonryProps {
275
275
  }
276
276
  declare const Masonry: FC<IMasonryProps>;
277
277
 
278
+ type TModalSize = 'sm' | 'lg';
278
279
  interface IModalProps {
279
280
  children: ReactNode;
280
281
  isOpen: boolean;
282
+ size?: TModalSize;
281
283
  title: string;
282
- onDismiss(): void;
284
+ onDismiss: () => void;
283
285
  }
284
286
  declare const Modal: FC<IModalProps>;
285
287
 
package/lib/index.esm.js CHANGED
@@ -1954,56 +1954,31 @@ const ModalContent = styled.div`
1954
1954
  pointer-events: auto;
1955
1955
  `;
1956
1956
  const ModalDialog = styled.div`
1957
- box-shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2), 0 5px 8px 0 rgba(0, 0, 0, 0.14),
1957
+ box-shadow:
1958
+ 0 3px 5px -1px rgba(0, 0, 0, 0.2),
1959
+ 0 5px 8px 0 rgba(0, 0, 0, 0.14),
1958
1960
  0 1px 14px 0 rgba(0, 0, 0, 0.12);
1959
1961
  margin: 5rem auto;
1960
- max-width: 500px;
1962
+ max-width: ${({ size })=>size === 'sm' ? '500px' : '90vw'};
1961
1963
  pointer-events: none;
1962
1964
  position: relative;
1963
1965
  `;
1964
- const Modal = ({ children, isOpen, onDismiss, title })=>{
1965
- const output = document.createElement('div');
1966
+ const Modal = ({ children, isOpen, onDismiss, size = 'sm', title })=>{
1966
1967
  const doNotDismiss = (e)=>{
1967
1968
  e.stopPropagation();
1968
1969
  };
1969
- const modal = /*#__PURE__*/ jsxs(Suspense, {
1970
- fallback: /*#__PURE__*/ jsx(Loader, {}),
1971
- children: [
1972
- /*#__PURE__*/ jsx(ModalOuter, {
1973
- "aria-modal": true,
1974
- "aria-label": title,
1975
- role: "dialog",
1976
- tabIndex: -1,
1977
- onClick: onDismiss,
1978
- children: /*#__PURE__*/ jsx(ModalDialog, {
1979
- role: "document",
1980
- children: /*#__PURE__*/ jsx(ModalContent, {
1981
- onClick: doNotDismiss,
1982
- children: /*#__PURE__*/ jsx(Card, {
1983
- padding: "lg",
1984
- children: children
1985
- })
1986
- })
1987
- })
1988
- }),
1989
- /*#__PURE__*/ jsx(Overlay, {})
1990
- ]
1991
- });
1992
1970
  useEffect(()=>{
1993
1971
  const keyboardEvent = (e)=>{
1994
1972
  if (e.key === 'Escape') {
1995
1973
  onDismiss();
1996
1974
  }
1997
1975
  };
1998
- document.body.appendChild(output);
1999
1976
  document.addEventListener('keydown', keyboardEvent, false);
2000
1977
  return ()=>{
2001
- document.body.removeChild(output);
2002
1978
  document.body.style.removeProperty('overflow');
2003
1979
  document.removeEventListener('keydown', keyboardEvent, false);
2004
1980
  };
2005
1981
  }, [
2006
- output,
2007
1982
  onDismiss
2008
1983
  ]);
2009
1984
  useEffect(()=>{
@@ -2014,7 +1989,30 @@ const Modal = ({ children, isOpen, onDismiss, title })=>{
2014
1989
  isOpen
2015
1990
  ]);
2016
1991
  if (isOpen) {
2017
- 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);
2018
2016
  }
2019
2017
  return null;
2020
2018
  };
@@ -2701,7 +2699,6 @@ const selectIcon = (alertType)=>{
2701
2699
  }
2702
2700
  };
2703
2701
  const ToastProvider = ({ children })=>{
2704
- const output = document.createElement('div');
2705
2702
  const [toasts, setToasts] = useState([]);
2706
2703
  const add = useCallback(({ colour, message, onDismiss })=>{
2707
2704
  const id = generateId();
@@ -2717,34 +2714,18 @@ const ToastProvider = ({ children })=>{
2717
2714
  }, [
2718
2715
  toasts
2719
2716
  ]);
2720
- const remove = useCallback((id)=>setToasts(toasts.filter((t)=>{
2721
- if (t.id === id && t.onDismiss) {
2722
- 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();
2723
2722
  }
2724
- return t.id !== id;
2725
- })), [
2726
- toasts
2727
- ]);
2728
- const alerts = /*#__PURE__*/ jsx(ToastContainer, {
2729
- children: toasts.map(({ colour, id, message })=>/*#__PURE__*/ jsx(Alert, {
2730
- spacing: "lg",
2731
- dismissable: 5000,
2732
- icon: /*#__PURE__*/ jsx(FontAwesomeIcon, {
2733
- icon: selectIcon(colour)
2734
- }),
2735
- colour: colour,
2736
- message: message,
2737
- onDismiss: ()=>remove(id)
2738
- }, id))
2739
- });
2740
- useEffect(()=>{
2741
- document.body.appendChild(output);
2742
- return ()=>{
2743
- document.body.removeChild(output);
2744
- };
2745
- }, [
2746
- output
2747
- ]);
2723
+ if (item !== -1) {
2724
+ value.splice(item, 1);
2725
+ }
2726
+ return value;
2727
+ });
2728
+ }, []);
2748
2729
  const value = useMemo(()=>({
2749
2730
  add,
2750
2731
  remove
@@ -2756,7 +2737,20 @@ const ToastProvider = ({ children })=>{
2756
2737
  value: value,
2757
2738
  children: [
2758
2739
  children,
2759
- /*#__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)
2760
2754
  ]
2761
2755
  });
2762
2756
  };