Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | 1386x 1386x 1896x 650x 78x 1378x | import { Box, Stack, SxProps } from "@mui/material";
import {
ChatsCircleIcon,
DotsThreeIcon,
PencilSimpleIcon,
PlusIcon,
} from "@phosphor-icons/react";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import GiveText from "@shared/Text/GiveText";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { styled } from "@theme/v2/Provider";
import { isEmpty, isFunction } from "lodash";
import { ReactNode } from "react";
import { ActionsType, DisabledActionType } from "./SectionCardBase.types";
import GiveLink from "shared/Link/GiveLink";
interface Props {
leftTitle?: string;
tag?: ReactNode;
children?: ReactNode;
height?: string;
actions?: ActionsType;
disabledActions?: DisabledActionType;
sx?: SxProps;
childrenContainerSx?: SxProps;
}
function SectionCardBase({
leftTitle,
tag,
children,
actions,
height = "auto",
sx,
childrenContainerSx,
disabledActions,
}: Props) {
const rightHeadingItems = [
{
Icon: ChatsCircleIcon,
onClick: actions?.handleOpenConversation,
hidden:
disabledActions?.handleOpenConversation?.hidden ??
!isFunction(actions?.handleOpenConversation),
disabled: disabledActions?.handleOpenConversation?.disabled || false,
tooltipTitle: disabledActions?.handleOpenConversation?.tooltipTitle || "",
disableTooltip:
disabledActions?.handleOpenConversation?.disableTooltip ?? true,
},
{
Icon: PencilSimpleIcon,
onClick: actions?.handleEdit,
hidden:
disabledActions?.handleEdit?.hidden ?? !isFunction(actions?.handleEdit),
disabled: disabledActions?.handleEdit?.disabled || false,
tooltipTitle: disabledActions?.handleEdit?.tooltipTitle || "",
disableTooltip: disabledActions?.handleEdit?.disableTooltip ?? true,
},
{
Icon: DotsThreeIcon,
onClick: actions?.handleDotsThree,
hidden:
disabledActions?.handleDotsThree?.hidden ??
!isFunction(actions?.handleDotsThree),
disabled: disabledActions?.handleDotsThree?.disabled || false,
tooltipTitle: disabledActions?.handleDotsThree?.tooltipTitle || "",
disableTooltip: disabledActions?.handleDotsThree?.disableTooltip ?? true,
},
{
Icon: PlusIcon,
onClick: actions?.handleAdd,
hidden:
disabledActions?.handleAdd?.hidden ?? !isFunction(actions?.handleAdd),
disabled: disabledActions?.handleAdd?.disabled || false,
tooltipTitle: disabledActions?.handleAdd?.tooltipTitle || "",
disableTooltip: disabledActions?.handleAdd?.disableTooltip ?? true,
isLinkButton: true,
label: "Add",
},
];
return (
<Stack sx={sx} height={height} width="100%" gap={2}>
{leftTitle && (
<Stack
justifyContent="space-between"
alignItems="center"
flexDirection="row"
width="100%"
>
<Stack direction="row" gap="10px">
<GiveText>{leftTitle}</GiveText>
{tag && tag}
</Stack>
{!isEmpty(actions) && (
<Stack gap="10px" flexDirection="row" alignItems="center">
{rightHeadingItems?.map(
(
{
isLinkButton,
label,
Icon,
onClick,
hidden,
disabled,
tooltipTitle,
disableTooltip,
},
idx,
) => {
if (hidden) return null;
return (
<GiveTooltip
width="compact"
alignment="left"
title={tooltipTitle}
color="default"
disableHoverListener={disableTooltip}
key={idx}
>
{isLinkButton ? (
<GiveLink
component="button"
color="primary"
onClick={onClick}
disabled={disabled}
Icon={Icon}
>
{label}
</GiveLink>
) : (
<GiveIconButton
sx={{
cursor: "pointer",
}}
variant="ghost"
onClick={onClick}
Icon={Icon}
disabled={disabled}
/>
)}
</GiveTooltip>
);
},
)}
</Stack>
)}
</Stack>
)}
{children && (
<ChildContainer sx={childrenContainerSx}>{children}</ChildContainer>
)}
</Stack>
);
}
export default SectionCardBase;
const ChildContainer = styled(Box)(({ theme }) => {
return {
borderRadius: `${theme?.customs?.radius?.medium}px`,
width: "100%",
padding: "20px",
backgroundColor: theme.palette.background.paper,
"& > .MuiGrid-root": {
paddingTop: "8px",
},
};
});
|