-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tabs and container components (#1549)
- Loading branch information
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react'; | ||
import { Container as MUIContainer, ContainerProps } from '@mui/material'; | ||
import { createComponent } from '@mui/toolpad-core'; | ||
import { SX_PROP_HELPER_TEXT } from './constants'; | ||
|
||
interface Props extends ContainerProps { | ||
visible: boolean; | ||
} | ||
|
||
function Container({ children, visible, sx, ...props }: Props) { | ||
return visible ? ( | ||
<MUIContainer disableGutters sx={sx} {...props}> | ||
{children} | ||
</MUIContainer> | ||
) : null; | ||
} | ||
|
||
export default createComponent(Container, { | ||
argTypes: { | ||
children: { | ||
typeDef: { type: 'element' }, | ||
control: { type: 'layoutSlot' }, | ||
}, | ||
visible: { | ||
typeDef: { type: 'boolean' }, | ||
defaultValue: true, | ||
helperText: 'Control whether container element is visible.', | ||
}, | ||
sx: { | ||
helperText: SX_PROP_HELPER_TEXT, | ||
typeDef: { type: 'object' }, | ||
defaultValue: { padding: 1, border: 'solid 1px' }, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as React from 'react'; | ||
import { Tabs as MUITabs, Tab } from '@mui/material'; | ||
import { createComponent } from '@mui/toolpad-core'; | ||
|
||
interface TabProps { | ||
title: string; | ||
name: string; | ||
} | ||
|
||
interface Props { | ||
active: string; | ||
onChange: (value: number) => void; | ||
tabs: TabProps[]; | ||
defaultValue: string; | ||
} | ||
|
||
function Tabs({ active, onChange, tabs, defaultValue }: Props) { | ||
return ( | ||
<MUITabs | ||
value={active || defaultValue} | ||
onChange={(event, value) => { | ||
onChange(value); | ||
}} | ||
> | ||
{tabs.map(({ title, name }) => ( | ||
<Tab label={title} value={name} key={name} /> | ||
))} | ||
</MUITabs> | ||
); | ||
} | ||
|
||
export default createComponent(Tabs, { | ||
layoutDirection: 'horizontal', | ||
argTypes: { | ||
active: { | ||
typeDef: { type: 'string' }, | ||
onChangeProp: 'onChange', | ||
defaultValueProp: 'defaultValue', | ||
helperText: 'Currently active tab.', | ||
}, | ||
defaultValue: { | ||
label: 'Default active tab', | ||
typeDef: { type: 'string' }, | ||
defaultValue: 'tab-one', | ||
helperText: 'The tab which will be active by default.', | ||
}, | ||
tabs: { | ||
typeDef: { type: 'array' }, | ||
defaultValue: [ | ||
{ | ||
title: 'Tab one', | ||
name: 'tab-one', | ||
}, | ||
{ title: 'Tab two', name: 'tab-two' }, | ||
{ title: 'Tab three', name: 'tab-three' }, | ||
], | ||
helperText: 'Tabs configuration object.', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters