-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFR] Add options prop to TabbedShowLayout (#2740)
* Add options prop to TabbedShowLayout * Use tabs prop to pass a material-ui's Tabs element Instead of using an "options" prop to pass props to the <Tabs> in <TabbedShowLayout>, now a whole <Tabs> custom component can be passed through the new "tabs" prop. * Add options prop to TabbedShowLayout * Use tabs prop to pass a material-ui's Tabs element Instead of using an "options" prop to pass props to the <Tabs> in <TabbedShowLayout>, now a whole <Tabs> custom component can be passed through the new "tabs" prop. * Remove grandchildren mapping from TabbedShowLayout Also fix linting. * Remove unused props and fix misused spread operator * Pass the rest of the TabbedShowLayoutTabs props to its children * Pass TabbedShowLayoutTabs rest props to Tabs Previously it was being passed to its children. * Fix propTypes
- Loading branch information
1 parent
bee7f09
commit ce9ddda
Showing
2 changed files
with
54 additions
and
27 deletions.
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
34 changes: 34 additions & 0 deletions
34
packages/ra-ui-materialui/src/detail/TabbedShowLayoutTabs.js
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,34 @@ | ||
import React, { Children, cloneElement } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Tabs from '@material-ui/core/Tabs'; | ||
|
||
const getTabFullPath = (tab, index, baseUrl) => | ||
`${baseUrl}${ | ||
tab.props.path ? `/${tab.props.path}` : index > 0 ? `/${index}` : '' | ||
}`; | ||
|
||
const TabbedShowLayoutTabs = ({ children, match, ...rest }) => ( | ||
<Tabs indicatorColor='primary' {...rest} > | ||
{Children.map(children, (tab, index) => { | ||
if (!tab) return null; | ||
// Builds the full tab tab which is the concatenation of the last matched route in the | ||
// TabbedShowLayout hierarchy (ex: '/posts/create', '/posts/12', , '/posts/12/show') | ||
// and the tab path. | ||
// This will be used as the Tab's value | ||
const tabPath = getTabFullPath(tab, index, match.url); | ||
|
||
return cloneElement(tab, { | ||
context: 'header', | ||
value: tabPath, | ||
}); | ||
})} | ||
</Tabs> | ||
); | ||
|
||
TabbedShowLayoutTabs.propTypes = { | ||
children: PropTypes.node, | ||
match: PropTypes.object, | ||
value: PropTypes.string, | ||
}; | ||
|
||
export default TabbedShowLayoutTabs; |