From 723a6274efeed17bd9a4c0a4fd31c72d9db76f6a Mon Sep 17 00:00:00 2001 From: Alexis G Date: Fri, 8 Mar 2024 12:26:10 +0100 Subject: [PATCH] feat: Improve AlertProvider BREAKING CHANGE: The `showAlert` function returned by the `useAlert` hook changes signature. Also, the `variant` was set to `filled`, it now takes the default value of `Alert`, i.e. `standard`. Before: ``` const { showAlert } = useAlert() showAlert(t('foo.bar'), 'error',) ``` Now: ``` const { showAlert } = useAlert() showAlert({ message: t('foo.bar'), severity: 'error' }) ``` Its options now support Alert component props. Example: ``` showAlert({ message: t('foo.bar'), severity: 'info', icon: false, color: 'blue', square: true }) ``` --- .../Viewer/ViewersByFile/PdfMobileViewer.jsx | 6 ++- react/providers/Alert/Readme.md | 45 +++++++++++++++++-- react/providers/Alert/index.jsx | 34 +++++++++++--- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/react/Viewer/ViewersByFile/PdfMobileViewer.jsx b/react/Viewer/ViewersByFile/PdfMobileViewer.jsx index 2571355151..4ad5d93927 100644 --- a/react/Viewer/ViewersByFile/PdfMobileViewer.jsx +++ b/react/Viewer/ViewersByFile/PdfMobileViewer.jsx @@ -36,7 +36,11 @@ export const PdfMobileViewer = ({ file, url, t, gestures }) => { try { await client.collection('io.cozy.files').download(file) } catch (error) { - showAlert(t('Viewer.error.generic'), 'error') + showAlert({ + message: t('Viewer.error.generic'), + severity: 'error', + icon: false + }) } }, [client, showAlert, t] diff --git a/react/providers/Alert/Readme.md b/react/providers/Alert/Readme.md index c1bf10d103..c57553bb51 100644 --- a/react/providers/Alert/Readme.md +++ b/react/providers/Alert/Readme.md @@ -3,23 +3,60 @@ import Variants from 'cozy-ui/docs/components/Variants' import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints' import AlertProvider, { useAlert } from 'cozy-ui/transpiled/react/providers/Alert' import Button from 'cozy-ui/transpiled/react/Buttons' +import Icon from 'cozy-ui/transpiled/react/Icon' +import DeviceLaptopIcon from 'cozy-ui/transpiled/react/Icons/DeviceLaptop' -const initialVariants = [{ primary: true, secondary: false, success: false, error: false, warning: false, info: false }] +const initialVariants = [{ + title: false, + block: false, + color: false, + largeIcon: false, + noIcon: false, + square: false, + filled: false, + outlined: false, + close: true +}] const Component = ({ variant }) => { const { showAlert } = useAlert() - return