From b0e7921e94afdc205cddb4486b6c5924cc8c867b Mon Sep 17 00:00:00 2001
From: ek-hystax <33006768+ek-hystax@users.noreply.github.com>
Date: Mon, 26 Aug 2024 15:27:28 +0400
Subject: [PATCH] OS-7761. Restore the 'Expand' button to the side modal header
---
.../ui/src/components/SideModal/SideModal.tsx | 23 ++++++++++++++++---
.../SideModalHeader/SideModalHeader.tsx | 23 +++++++++++++++++--
.../SideModalTitle/SideModalTitle.tsx | 9 ++++++--
ngui/ui/src/utils/strings.ts | 3 ++-
4 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/ngui/ui/src/components/SideModal/SideModal.tsx b/ngui/ui/src/components/SideModal/SideModal.tsx
index ac85a00ce..e18f9cab4 100644
--- a/ngui/ui/src/components/SideModal/SideModal.tsx
+++ b/ngui/ui/src/components/SideModal/SideModal.tsx
@@ -1,9 +1,25 @@
-import { useState } from "react";
+import { ReactNode, SyntheticEvent, useState } from "react";
import Drawer from "@mui/material/Drawer";
import SideModalHeader from "components/SideModalHeader";
+import { SideModalHeaderProps } from "components/SideModalHeader/SideModalHeader";
import useStyles from "./SideModal.styles";
-const DrawerContent = ({ headerProps, handleClose, children }) => {
+type DrawerContentProps = {
+ headerProps: SideModalHeaderProps;
+ handleClose: (event: SyntheticEvent) => void;
+ children: ReactNode;
+};
+
+type SideModalProps = {
+ isOpen: boolean;
+ closeHandler: (isOpen: boolean) => void;
+ dataTestId: string;
+ headerProps: SideModalHeaderProps;
+ onClose?: (event: SyntheticEvent) => void;
+ children: ReactNode;
+};
+
+const DrawerContent = ({ headerProps, handleClose, children }: DrawerContentProps) => {
const { showExpand, ...sideModalHeaderProps } = headerProps;
const [isExpanded, setIsExpanded] = useState(showExpand);
@@ -14,6 +30,7 @@ const DrawerContent = ({ headerProps, handleClose, children }) => {
setIsExpanded(!isExpanded)}
@@ -23,7 +40,7 @@ const DrawerContent = ({ headerProps, handleClose, children }) => {
);
};
-const SideModal = ({ isOpen, closeHandler, dataTestId, headerProps = {}, onClose, children }) => {
+const SideModal = ({ isOpen, closeHandler, dataTestId, headerProps, onClose, children }: SideModalProps) => {
const handleClose = (event) => {
if (event.type === "keydown" && (event.key === "Tab" || event.key === "Shift")) {
return;
diff --git a/ngui/ui/src/components/SideModalHeader/SideModalHeader.tsx b/ngui/ui/src/components/SideModalHeader/SideModalHeader.tsx
index 65c28edb2..dd25aaaaa 100644
--- a/ngui/ui/src/components/SideModalHeader/SideModalHeader.tsx
+++ b/ngui/ui/src/components/SideModalHeader/SideModalHeader.tsx
@@ -1,3 +1,4 @@
+import { ReactNode, SyntheticEvent } from "react";
import CloseIcon from "@mui/icons-material/Close";
import WidthNormalIcon from "@mui/icons-material/WidthNormal";
import WidthWideIcon from "@mui/icons-material/WidthWide";
@@ -10,6 +11,23 @@ import SideModalTitle from "components/SideModalTitle";
import { capitalize } from "utils/strings";
import useStyles from "./SideModalHeader.styles";
+type Title =
+ | { text: string; messageId?: never; formattedMessageValues?: never }
+ | { text?: never; messageId: string; formattedMessageValues?: Record };
+
+export type SideModalHeaderProps = Title & {
+ onClose: (event: SyntheticEvent) => void;
+ showExpand?: boolean;
+ onExpandChange?: () => void;
+ isExpanded?: boolean;
+ dataTestIds?: {
+ title?: string;
+ closeButton?: string;
+ expandButton?: string;
+ };
+ color?: "primary" | "success" | "info" | "error";
+};
+
const SideModalHeader = ({
text,
messageId,
@@ -20,7 +38,7 @@ const SideModalHeader = ({
formattedMessageValues,
dataTestIds,
color = "primary"
-}) => {
+}: SideModalHeaderProps) => {
const { classes, cx } = useStyles();
const {
@@ -29,7 +47,8 @@ const SideModalHeader = ({
expandButton: expandButtonDataTestId
} = dataTestIds || {};
- const headerClasses = cx(classes["header".concat(capitalize(color))]);
+ const headerColorClassName = `header${capitalize(color)}` as const;
+ const headerClasses = cx(classes[headerColorClassName]);
return (
diff --git a/ngui/ui/src/components/SideModalTitle/SideModalTitle.tsx b/ngui/ui/src/components/SideModalTitle/SideModalTitle.tsx
index fd86cac53..7be9c29a0 100644
--- a/ngui/ui/src/components/SideModalTitle/SideModalTitle.tsx
+++ b/ngui/ui/src/components/SideModalTitle/SideModalTitle.tsx
@@ -1,6 +1,11 @@
-import Typography from "@mui/material/Typography";
+import Typography, { TypographyProps } from "@mui/material/Typography";
-const SideModalTitle = ({ children, dataProductTourId, dataTestId, ...rest }) => (
+type SideModalTitleProps = {
+ dataProductTourId?: string;
+ dataTestId?: string;
+} & TypographyProps;
+
+const SideModalTitle = ({ children, dataProductTourId, dataTestId, ...rest }: SideModalTitleProps) => (
{children}
diff --git a/ngui/ui/src/utils/strings.ts b/ngui/ui/src/utils/strings.ts
index d267a53e0..3f70f08e9 100644
--- a/ngui/ui/src/utils/strings.ts
+++ b/ngui/ui/src/utils/strings.ts
@@ -31,7 +31,8 @@ export const getHash = (s) => {
return h;
};
-export const capitalize = (s) => (isString(s) ? s.charAt(0).toUpperCase() + s.slice(1) : "");
+export const capitalize = (s: T): Capitalize =>
+ (isString(s) ? s.charAt(0).toUpperCase() + s.slice(1) : "") as Capitalize;
export const concatenate = (array, pre, separator) => {
const string = array.join(separator);