Skip to content

Commit

Permalink
update: add alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
k0stik committed Jul 31, 2024
1 parent 9053b10 commit 006f2a4
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dist/hooks/useCopyToClipboard.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { enqueueSnackbar } from "notistack";
import { useCallback } from "react";
import { showSuccessAlert } from "../other/alerts";
import { copyToClipboard } from "../utils/clipboard";
export const useCopyToClipboard = () => {
return useCallback((textToCopy, content) => {
copyToClipboard(textToCopy, () => {
enqueueSnackbar(content, { variant: "success" });
showSuccessAlert(content);
});
}, []);
};
1 change: 0 additions & 1 deletion dist/mui/components/dialog/Dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface DialogModalProps extends DialogProps {
onSubmit?: (() => void) | undefined;
onClose?: (() => void) | undefined;
onCancel?: (() => void) | undefined;
scroll?: "body" | "paper";
children?: React.ReactNode;
maxWidth?: false | "md" | "xs" | "sm" | "lg" | "xl" | undefined;
dividers?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions dist/mui/components/popover/info-popover/InfoPopover.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export declare const InfoIconButton: import("@mui/styles").StyledComponent<Omit<
}>;
export declare const PopoverTitle: import("@mui/styles").StyledComponent<Omit<import("@mui/material/Typography").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
}, "variant" | "className" | "style" | "classes" | "children" | "color" | "fontSize" | "sx" | "p" | "height" | "width" | "display" | "fontFamily" | "fontStyle" | "fontWeight" | "letterSpacing" | "order" | "overflow" | "visibility" | "border" | "boxShadow" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "lineHeight" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "whiteSpace" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "marginBlock" | "marginInline" | "padding" | "paddingBlock" | "paddingInline" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint" | "align" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping">, "className" | "classes"> & import("@mui/styles").StyledComponentProps<"root"> & Omit<{
}, "bottom" | "top" | "left" | "right" | "variant" | "className" | "style" | "classes" | "children" | "color" | "fontSize" | "sx" | "p" | "height" | "width" | "display" | "fontFamily" | "fontStyle" | "fontWeight" | "letterSpacing" | "order" | "overflow" | "visibility" | "border" | "boxShadow" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "boxSizing" | "columnGap" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "justifyContent" | "justifyItems" | "justifySelf" | "lineHeight" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "whiteSpace" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "marginBlock" | "marginInline" | "padding" | "paddingBlock" | "paddingInline" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint" | "align" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping">, "className" | "classes"> & import("@mui/styles").StyledComponentProps<"root"> & Omit<{
theme: Theme;
}, "className" | "theme"> & {
className?: string | undefined;
theme?: Theme | undefined;
}>;
export declare const PopoverText: import("@mui/styles").StyledComponent<Omit<import("@mui/material/Typography").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
ref?: ((instance: HTMLSpanElement | null) => void) | React.RefObject<HTMLSpanElement> | null | undefined;
}, "variant" | "className" | "style" | "classes" | "children" | "color" | "fontSize" | "sx" | "p" | "height" | "width" | "display" | "fontFamily" | "fontStyle" | "fontWeight" | "letterSpacing" | "order" | "overflow" | "visibility" | "border" | "boxShadow" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "bottom" | "boxSizing" | "columnGap" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "lineHeight" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "right" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "top" | "whiteSpace" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "marginBlock" | "marginInline" | "padding" | "paddingBlock" | "paddingInline" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint" | "align" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping">, "className" | "classes"> & import("@mui/styles").StyledComponentProps<"root"> & Omit<{
}, "bottom" | "top" | "left" | "right" | "variant" | "className" | "style" | "classes" | "children" | "color" | "fontSize" | "sx" | "p" | "height" | "width" | "display" | "fontFamily" | "fontStyle" | "fontWeight" | "letterSpacing" | "order" | "overflow" | "visibility" | "border" | "boxShadow" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "boxSizing" | "columnGap" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "justifyContent" | "justifyItems" | "justifySelf" | "lineHeight" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "position" | "rowGap" | "textAlign" | "textOverflow" | "textTransform" | "whiteSpace" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderTop" | "flex" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "margin" | "marginBlock" | "marginInline" | "padding" | "paddingBlock" | "paddingInline" | "bgcolor" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "typography" | "displayPrint" | "align" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping">, "className" | "classes"> & import("@mui/styles").StyledComponentProps<"root"> & Omit<{
theme: Theme;
}, "className" | "theme"> & {
className?: string | undefined;
Expand Down
5 changes: 5 additions & 0 deletions dist/other/alerts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare function showSuccessAlert(message: string): void;
export declare function showErrorAlert(message: string): void;
export declare function showWarningAlert(message: string): void;
export declare function showInfoAlert(message: string): void;
export declare function showAlert(message: string, type: "info" | "warning" | "error" | "success"): void;
35 changes: 35 additions & 0 deletions dist/other/alerts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { enqueueSnackbar } from "notistack";
const anchorOrigin = {
vertical: "bottom",
horizontal: "left",
};
export function showSuccessAlert(message) {
enqueueSnackbar(message, { variant: "success", anchorOrigin });
}
export function showErrorAlert(message) {
enqueueSnackbar(message, { variant: "error", anchorOrigin });
}
export function showWarningAlert(message) {
enqueueSnackbar(message, { variant: "warning", anchorOrigin });
}
export function showInfoAlert(message) {
enqueueSnackbar(message, { variant: "info", anchorOrigin });
}
export function showAlert(message, type) {
switch (type) {
case "warning":
showWarningAlert(message);
break;
case "error":
showErrorAlert(message);
break;
case "success":
showSuccessAlert(message);
break;
case "info":
showInfoAlert(message);
break;
default:
showInfoAlert(message);
}
}
4 changes: 2 additions & 2 deletions src/hooks/useCopyToClipboard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { enqueueSnackbar } from "notistack";
import { useCallback } from "react";

import { showSuccessAlert } from "../other/alerts";
import { copyToClipboard } from "../utils/clipboard";

export const useCopyToClipboard = () => {
return useCallback((textToCopy: string, content: string) => {
copyToClipboard(textToCopy, () => {
enqueueSnackbar(content, { variant: "success" });
showSuccessAlert(content);
});
}, []);
};
1 change: 0 additions & 1 deletion src/mui/components/dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface DialogModalProps extends DialogProps {
onSubmit?: (() => void) | undefined;
onClose?: (() => void) | undefined;
onCancel?: (() => void) | undefined;
scroll?: "body" | "paper";
children?: React.ReactNode;
maxWidth?: false | "md" | "xs" | "sm" | "lg" | "xl" | undefined;
dividers?: boolean;
Expand Down
41 changes: 41 additions & 0 deletions src/other/alerts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { enqueueSnackbar, SnackbarOrigin } from "notistack";

const anchorOrigin: SnackbarOrigin = {
vertical: "bottom",
horizontal: "left",
};

export function showSuccessAlert(message: string) {
enqueueSnackbar(message, { variant: "success", anchorOrigin });
}

export function showErrorAlert(message: string) {
enqueueSnackbar(message, { variant: "error", anchorOrigin });
}

export function showWarningAlert(message: string) {
enqueueSnackbar(message, { variant: "warning", anchorOrigin });
}

export function showInfoAlert(message: string) {
enqueueSnackbar(message, { variant: "info", anchorOrigin });
}

export function showAlert(message: string, type: "info" | "warning" | "error" | "success") {
switch (type) {
case "warning":
showWarningAlert(message);
break;
case "error":
showErrorAlert(message);
break;
case "success":
showSuccessAlert(message);
break;
case "info":
showInfoAlert(message);
break;
default:
showInfoAlert(message);
}
}

0 comments on commit 006f2a4

Please sign in to comment.