Skip to content

Commit

Permalink
feat: make network tabs scrollable (DimensionDev#5732)
Browse files Browse the repository at this point in the history
* feat: make network tabs scrollable

* feat: add scrollable prop for AbstractTab

* fix: typo
  • Loading branch information
yanzhihong23 authored Feb 25, 2022
1 parent 14bed61 commit 273bf5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
11 changes: 7 additions & 4 deletions packages/mask/src/components/shared/AbstractTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ export interface AbstractTabProps
margin?: true | 'top' | 'bottom'
height?: number | string
hasOnlyOneChild?: boolean
scrollable?: boolean
}

export default function AbstractTab(props: AbstractTabProps) {
const { tabs, state, index, height = 200, hasOnlyOneChild = false } = props
const { tabs, state, index, height = 200, hasOnlyOneChild = false, scrollable = false } = props
const classes = useStylesExtends(useStyles(), props)
const [value, setValue] = state ?? [undefined, undefined]
const tabIndicatorStyle = tabs.length ? { width: 100 / tabs.length + '%' } : undefined
const tabIndicatorStyle = tabs.length && !scrollable ? { width: 100 / tabs.length + '%' } : undefined

return (
<>
Expand All @@ -53,10 +54,12 @@ export default function AbstractTab(props: AbstractTabProps) {
flexContainer: classes.flexContainer,
}}
value={index ? index : value ? value : 0}
TabIndicatorProps={{ style: tabIndicatorStyle }}
variant="fullWidth"
indicatorColor="primary"
textColor="primary"
variant={scrollable ? 'scrollable' : 'fullWidth'}
TabIndicatorProps={{ style: tabIndicatorStyle }}
scrollButtons={scrollable}
allowScrollButtonsMobile={scrollable}
onChange={(_: React.SyntheticEvent, newValue: number) => setValue?.(newValue)}>
{tabs.map((tab, i) => (
<Tab
Expand Down
20 changes: 16 additions & 4 deletions packages/mask/src/components/shared/NetworkTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,27 @@ const useStyles = makeStyles<StyleProps>()((theme, props) => ({
},
tabs: {
'& .MuiTabs-flexContainer': {
display: 'grid',
gridTemplateColumns: Array(props.chainLength)
.fill(100 / props.chainLength + '%')
.join(' '),
backgroundColor: theme.palette.background.paper,
},
'& .Mui-selected': {
color: '#ffffff',
backgroundColor: `${theme.palette.primary.main}!important`,
},
'& .MuiTabs-scroller': {
margin: '0 1px',
},
'& .MuiTabs-scrollButtons': {
width: 'unset',
backgroundColor: !props.isDashboard
? `${theme.palette.background.default}!important`
: `${MaskColorVar.primaryBackground2}!important`,
'&.Mui-disabled': {
opacity: 1,
'& svg': {
opacity: 0.3,
},
},
},
},
}))

Expand All @@ -52,6 +63,7 @@ export function NetworkTab(props: NetworkTabProps) {
index: chains.indexOf(chainId),
classes,
hasOnlyOneChild: true,
scrollable: true,
}

return <AbstractTab {...tabProps} />
Expand Down

0 comments on commit 273bf5d

Please sign in to comment.