Merge pull request #2050 from bluewave-labs/refactor/fe/tabs
Unify tab styles with CustomTabList component
This commit is contained in:
4 files changed
+65
-60
No files matched your search
@@ -0,0 +1,36 @@
|
|||||||
|
import { Box, useTheme } from "@mui/material";
|
||||||
|
import { TabList } from "@mui/lab";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CustomTabList component
|
||||||
|
* @param {string} value - The currently selected tab's value.
|
||||||
|
* @param {function} onChange - Callback when a different tab is selected.
|
||||||
|
* @param {React.ReactNode} children - Tab components to render inside the TabList.
|
||||||
|
* @param {object} props - Additional props passed to the TabList component.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const CustomTabList = ({ value, onChange, children, ...props }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
borderBottom: `1px solid ${theme.palette.primary.lowContrast}`,
|
||||||
|
"& .MuiTabs-root": { height: "fit-content", minHeight: "0" },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TabList value={value} onChange={onChange} {...props}>
|
||||||
|
{children}
|
||||||
|
</TabList>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
CustomTabList.propTypes = {
|
||||||
|
value: PropTypes.string,
|
||||||
|
onChange: PropTypes.func,
|
||||||
|
children: PropTypes.node,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CustomTabList;
|
||||||
+13
-24
@@ -3,8 +3,8 @@ import PropTypes from "prop-types";
|
|||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { Box, Tab, useTheme } from "@mui/material";
|
import { Box, Tab, useTheme } from "@mui/material";
|
||||||
|
import CustomTabList from "../../Components/Tab";
|
||||||
import TabContext from "@mui/lab/TabContext";
|
import TabContext from "@mui/lab/TabContext";
|
||||||
import TabList from "@mui/lab/TabList";
|
|
||||||
import ProfilePanel from "../../Components/TabPanels/Account/ProfilePanel";
|
import ProfilePanel from "../../Components/TabPanels/Account/ProfilePanel";
|
||||||
import PasswordPanel from "../../Components/TabPanels/Account/PasswordPanel";
|
import PasswordPanel from "../../Components/TabPanels/Account/PasswordPanel";
|
||||||
import TeamPanel from "../../Components/TabPanels/Account/TeamPanel";
|
import TeamPanel from "../../Components/TabPanels/Account/TeamPanel";
|
||||||
@@ -59,29 +59,18 @@ const Account = ({ open = "profile" }) => {
|
|||||||
py={theme.spacing(12)}
|
py={theme.spacing(12)}
|
||||||
>
|
>
|
||||||
<TabContext value={tab}>
|
<TabContext value={tab}>
|
||||||
<Box
|
<CustomTabList value={tab} onChange={handleTabChange} aria-label="account tabs">
|
||||||
sx={{
|
{tabList.map((label, index) => (
|
||||||
borderBottom: 1,
|
<Tab
|
||||||
borderColor: theme.palette.primary.lowContrast,
|
label={label}
|
||||||
"& .MuiTabs-root": { height: "fit-content", minHeight: "0" },
|
key={index}
|
||||||
}}
|
value={label.toLowerCase()}
|
||||||
>
|
onKeyDown={handleKeyDown}
|
||||||
<TabList
|
onFocus={() => handleFocus(label.toLowerCase())}
|
||||||
onChange={handleTabChange}
|
tabIndex={index}
|
||||||
aria-label="account tabs"
|
/>
|
||||||
>
|
))}
|
||||||
{tabList.map((label, index) => (
|
</CustomTabList>
|
||||||
<Tab
|
|
||||||
label={label}
|
|
||||||
key={index}
|
|
||||||
value={label.toLowerCase()}
|
|
||||||
onKeyDown={handleKeyDown}
|
|
||||||
onFocus={() => handleFocus(label.toLowerCase())}
|
|
||||||
tabIndex={index}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</TabList>
|
|
||||||
</Box>
|
|
||||||
<ProfilePanel />
|
<ProfilePanel />
|
||||||
{user.role.includes("superadmin") && <PasswordPanel />}
|
{user.role.includes("superadmin") && <PasswordPanel />}
|
||||||
{!hideTeams && <TeamPanel />}
|
{!hideTeams && <TeamPanel />}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
// Components
|
// Components
|
||||||
import { TabContext, TabList } from "@mui/lab";
|
import { TabContext } from "@mui/lab";
|
||||||
import { Box, Tab, useTheme } from "@mui/material";
|
import { Tab, useTheme } from "@mui/material";
|
||||||
import Settings from "./Settings";
|
import Settings from "./Settings";
|
||||||
import Content from "./Content";
|
import Content from "./Content";
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
import CustomTabList from "../../../../../Components/Tab";
|
||||||
|
|
||||||
const Tabs = ({
|
const Tabs = ({
|
||||||
isCreate,
|
isCreate,
|
||||||
@@ -26,28 +27,20 @@ const Tabs = ({
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
<TabContext value={TAB_LIST[tab]}>
|
<TabContext value={TAB_LIST[tab]}>
|
||||||
<Box
|
<CustomTabList
|
||||||
sx={{
|
onChange={(_, selected) => {
|
||||||
borderBottom: `1px solid ${theme.palette.primary.lowContrast}`,
|
setTab(TAB_LIST.indexOf(selected));
|
||||||
"& .MuiTabs-root": { height: "fit-content", minHeight: "0" },
|
|
||||||
}}
|
}}
|
||||||
|
aria-label="status page tabs"
|
||||||
>
|
>
|
||||||
<TabList
|
{TAB_LIST.map((tabLabel, idx) => (
|
||||||
onChange={(_, tab) => {
|
<Tab
|
||||||
setTab(TAB_LIST.indexOf(tab));
|
key={tabLabel}
|
||||||
}}
|
label={tabLabel}
|
||||||
>
|
value={tabLabel}
|
||||||
{TAB_LIST.map((tab, idx) => {
|
/>
|
||||||
return (
|
))}
|
||||||
<Tab
|
</CustomTabList>
|
||||||
key={tab}
|
|
||||||
label={TAB_LIST[idx]}
|
|
||||||
value={TAB_LIST[idx]}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TabList>
|
|
||||||
</Box>
|
|
||||||
{tab === 0 ? (
|
{tab === 0 ? (
|
||||||
<Settings
|
<Settings
|
||||||
tabValue={TAB_LIST[0]}
|
tabValue={TAB_LIST[0]}
|
||||||
|
|||||||
@@ -368,7 +368,6 @@ const baseTheme = (palette) => ({
|
|||||||
root: ({ theme }) => ({
|
root: ({ theme }) => ({
|
||||||
fontSize: theme.typography.fontSize - 1,
|
fontSize: theme.typography.fontSize - 1,
|
||||||
color: theme.palette.tertiary.contrastText,
|
color: theme.palette.tertiary.contrastText,
|
||||||
backgroundColor: theme.palette.primary.main,
|
|
||||||
height: '34px',
|
height: '34px',
|
||||||
minHeight: '34px',
|
minHeight: '34px',
|
||||||
borderRadius: 0,
|
borderRadius: 0,
|
||||||
@@ -376,21 +375,13 @@ const baseTheme = (palette) => ({
|
|||||||
minWidth: "fit-content",
|
minWidth: "fit-content",
|
||||||
padding: `${theme.spacing(6)}px ${theme.spacing(4)}px`,
|
padding: `${theme.spacing(6)}px ${theme.spacing(4)}px`,
|
||||||
fontWeight: 400,
|
fontWeight: 400,
|
||||||
borderBottom: `${theme.shape.borderThick}px solid transparent`,
|
|
||||||
borderRight: `${theme.shape.borderRadius / 2}px solid ${theme.palette.primary.lowContrast}`,
|
|
||||||
"&:first-of-type": { borderTopLeftRadius: theme.shape.borderRadius * 4 },
|
|
||||||
"&:last-child": { borderTopRightRadius: theme.shape.borderRadius * 4, borderRight: 0 },
|
|
||||||
"&:focus-visible": {
|
"&:focus-visible": {
|
||||||
color: theme.palette.primary.contrastText,
|
color: theme.palette.primary.contrastText,
|
||||||
borderColor: theme.palette.tertiary.contrastText,
|
borderColor: theme.palette.tertiary.contrastText,
|
||||||
borderRightColor: theme.palette.primary.lowContrast,
|
borderRightColor: theme.palette.primary.lowContrast,
|
||||||
},
|
},
|
||||||
"&.Mui-selected": {
|
"&.Mui-selected": {
|
||||||
backgroundColor: theme.palette.secondary.main,
|
|
||||||
color: theme.palette.secondary.contrastText,
|
color: theme.palette.secondary.contrastText,
|
||||||
borderColor: theme.palette.secondary.contrastText,
|
|
||||||
borderRightColor: theme.palette.primary.lowContrast,
|
|
||||||
borderRadius: 0,
|
|
||||||
},
|
},
|
||||||
"&:hover": {
|
"&:hover": {
|
||||||
borderColor: theme.palette.primary.lowContrast,
|
borderColor: theme.palette.primary.lowContrast,
|
||||||
@@ -442,11 +433,7 @@ const baseTheme = (palette) => ({
|
|||||||
styleOverrides: {
|
styleOverrides: {
|
||||||
root: ({ theme }) => ({
|
root: ({ theme }) => ({
|
||||||
display: 'inline-flex',
|
display: 'inline-flex',
|
||||||
borderTop: '1px solid',
|
borderRadius: 0,
|
||||||
borderLeft: '1px solid',
|
|
||||||
borderRight: '1px solid',
|
|
||||||
borderColor: theme.palette.primary.lowContrast,
|
|
||||||
borderRadius: `${theme.shape.borderRadius}px ${theme.shape.borderRadius}px 0 0`,
|
|
||||||
"& .MuiTabs-indicator": {
|
"& .MuiTabs-indicator": {
|
||||||
backgroundColor: theme.palette.tertiary.contrastText,
|
backgroundColor: theme.palette.tertiary.contrastText,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user