1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Improve tabs UI on smaller devices (#2014)

* Improve tabs UI on smaller devices

* Improve tabs UI on smaller devices

* bug fix

* add proper scrollable tabs

* removed centered from Tabs (conflicts with scrollable)

* PR comments
This commit is contained in:
andreas-unleash 2022-09-06 15:32:42 +03:00 committed by GitHub
parent 13e0130824
commit b74b2bf070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 31 deletions

View File

@ -1,28 +1,30 @@
import React from 'react'; import React from 'react';
import { NavLink, useLocation } from 'react-router-dom'; import { NavLink, useLocation } from 'react-router-dom';
import { Paper, Tab, Tabs } from '@mui/material'; import { Paper, Tab, Tabs, Theme } from '@mui/material';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { useInstanceStatus } from 'hooks/api/getters/useInstanceStatus/useInstanceStatus'; import { useInstanceStatus } from 'hooks/api/getters/useInstanceStatus/useInstanceStatus';
import { useTheme } from '@mui/material/styles';
const navLinkStyle = {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
textDecoration: 'none',
color: 'inherit',
padding: '0.8rem 1.5rem',
};
const activeNavLinkStyle: React.CSSProperties = {
fontWeight: 'bold',
borderRadius: '3px',
padding: '0.8rem 1.5rem',
};
const createNavLinkStyle = (props: { const createNavLinkStyle = (props: {
isActive: boolean; isActive: boolean;
theme: Theme;
}): React.CSSProperties => { }): React.CSSProperties => {
const navLinkStyle = {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
textDecoration: 'none',
color: 'inherit',
padding: props.theme.spacing(1.5, 3),
};
const activeNavLinkStyle: React.CSSProperties = {
fontWeight: 'bold',
borderRadius: '3px',
padding: props.theme.spacing(1.5, 3),
};
return props.isActive return props.isActive
? { ...navLinkStyle, ...activeNavLinkStyle } ? { ...navLinkStyle, ...activeNavLinkStyle }
: navLinkStyle; : navLinkStyle;
@ -30,6 +32,7 @@ const createNavLinkStyle = (props: {
function AdminMenu() { function AdminMenu() {
const { uiConfig } = useUiConfig(); const { uiConfig } = useUiConfig();
const theme = useTheme();
const { pathname } = useLocation(); const { pathname } = useLocation();
const { isBilling } = useInstanceStatus(); const { isBilling } = useInstanceStatus();
const { flags } = uiConfig; const { flags } = uiConfig;
@ -42,11 +45,21 @@ function AdminMenu() {
boxShadow: 'none', boxShadow: 'none',
}} }}
> >
<Tabs centered value={pathname}> <Tabs
value={pathname}
variant="scrollable"
scrollButtons="auto"
allowScrollButtonsMobile
>
<Tab <Tab
value="/admin/users" value="/admin/users"
label={ label={
<NavLink to="/admin/users" style={createNavLinkStyle}> <NavLink
to="/admin/users"
style={({ isActive }) =>
createNavLinkStyle({ isActive, theme })
}
>
<span>Users</span> <span>Users</span>
</NavLink> </NavLink>
} }
@ -57,7 +70,9 @@ function AdminMenu() {
label={ label={
<NavLink <NavLink
to="/admin/groups" to="/admin/groups"
style={createNavLinkStyle} style={({ isActive }) =>
createNavLinkStyle({ isActive, theme })
}
> >
<span>Groups</span> <span>Groups</span>
</NavLink> </NavLink>
@ -70,7 +85,9 @@ function AdminMenu() {
label={ label={
<NavLink <NavLink
to="/admin/roles" to="/admin/roles"
style={createNavLinkStyle} style={({ isActive }) =>
createNavLinkStyle({ isActive, theme })
}
> >
<span>Project roles</span> <span>Project roles</span>
</NavLink> </NavLink>
@ -80,7 +97,12 @@ function AdminMenu() {
<Tab <Tab
value="/admin/api" value="/admin/api"
label={ label={
<NavLink to="/admin/api" style={createNavLinkStyle}> <NavLink
to="/admin/api"
style={({ isActive }) =>
createNavLinkStyle({ isActive, theme })
}
>
API access API access
</NavLink> </NavLink>
} }
@ -91,7 +113,9 @@ function AdminMenu() {
label={ label={
<NavLink <NavLink
to="/admin/cors" to="/admin/cors"
style={createNavLinkStyle} style={({ isActive }) =>
createNavLinkStyle({ isActive, theme })
}
> >
CORS origins CORS origins
</NavLink> </NavLink>
@ -101,7 +125,12 @@ function AdminMenu() {
<Tab <Tab
value="/admin/auth" value="/admin/auth"
label={ label={
<NavLink to="/admin/auth" style={createNavLinkStyle}> <NavLink
to="/admin/auth"
style={({ isActive }) =>
createNavLinkStyle({ isActive, theme })
}
>
Single sign-on Single sign-on
</NavLink> </NavLink>
} }
@ -112,7 +141,9 @@ function AdminMenu() {
label={ label={
<NavLink <NavLink
to="/admin/billing" to="/admin/billing"
style={createNavLinkStyle} style={({ isActive }) =>
createNavLinkStyle({ isActive, theme })
}
> >
Billing Billing
</NavLink> </NavLink>

View File

@ -15,7 +15,6 @@ interface ITabData {
label: string; label: string;
component: ReactNode; component: ReactNode;
} }
export const TabNav = ({ export const TabNav = ({
tabData, tabData,
className = '', className = '',
@ -24,7 +23,6 @@ export const TabNav = ({
}: ITabNavProps) => { }: ITabNavProps) => {
const { classes: styles } = useStyles(); const { classes: styles } = useStyles();
const [activeTab, setActiveTab] = useState(startingTab); const [activeTab, setActiveTab] = useState(startingTab);
const renderTabs = () => const renderTabs = () =>
tabData.map((tab, index) => ( tabData.map((tab, index) => (
<Tab <Tab

View File

@ -262,20 +262,25 @@ export default createTheme({
}, },
MuiTabs: { MuiTabs: {
styleOverrides: { styleOverrides: {
root: { root: ({ theme }) => ({
'& .MuiTabs-indicator': { '& .MuiTabs-indicator': {
height: '4px', height: '4px',
}, },
}, '& .MuiTabs-flexContainer': {
minHeight: '70px',
maxHeight: '70px',
},
}),
}, },
}, },
MuiTab: { MuiTab: {
styleOverrides: { styleOverrides: {
root: { root: ({ theme }) => ({
color: colors.grey[900], color: colors.grey[900],
fontSize: '1rem', fontSize: '1rem',
textTransform: 'none', textTransform: 'none',
fontWeight: 400, fontWeight: 400,
lineHeight: '1',
minHeight: '62px', minHeight: '62px',
'&:hover': { '&:hover': {
backgroundColor: colors.grey[200], backgroundColor: colors.grey[200],
@ -287,7 +292,10 @@ export default createTheme({
'& > span': { '& > span': {
color: colors.purple[900], color: colors.purple[900],
}, },
}, [theme.breakpoints.down('md')]: {
padding: '12px 0px',
},
}),
}, },
}, },
MuiAccordion: { MuiAccordion: {