-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tabs and container components #1549
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' }, | ||
}, | ||
}, | ||
}); |
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: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify what you mean? the name of prop? if yes, why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes, because:
|
||
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', | ||
bytasv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name: 'tab-one', | ||
}, | ||
{ title: 'Tab two', name: 'tab-two' }, | ||
{ title: 'Tab three', name: 'tab-three' }, | ||
], | ||
helperText: 'Tabs configuration object.', | ||
}, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing: there is a bug I've found so if this prop is not called
children
it doesn't work, but it should. I'm including the fix in #1527