-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5239 from reactioncommerce/feat-mikemurray-side-p…
…anel feat: Add DetailDrawer component for supplementary views
- Loading branch information
Showing
19 changed files
with
567 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React, { Children } from "react"; | ||
import PropTypes from "prop-types"; | ||
import AppBar from "@material-ui/core/AppBar"; | ||
import IconButton from "@material-ui/core/IconButton"; | ||
import Toolbar from "@material-ui/core/Toolbar"; | ||
import Drawer from "@material-ui/core/Drawer"; | ||
import withStyles from "@material-ui/core/styles/withStyles"; | ||
import CloseIcon from "mdi-material-ui/Close"; | ||
import { Typography } from "@material-ui/core"; | ||
import { UIContext } from "../../context/UIContext"; | ||
|
||
const styles = (theme) => ({ | ||
action: { | ||
marginLeft: theme.spacing.unit | ||
}, | ||
content: { | ||
paddingTop: theme.spacing.unit, | ||
marginLeft: "-1px", | ||
marginRight: "-1px" | ||
}, | ||
title: { | ||
flex: 1, | ||
paddingLeft: theme.spacing.unit | ||
} | ||
}); | ||
|
||
/** | ||
* Detail drawer used for displaying supplementary info and actions for a view. | ||
* @param {Object} props Component props | ||
* @returns {React.Component} Sidebar component | ||
*/ | ||
function DetailDrawer(props) { | ||
const { | ||
anchor, | ||
children, | ||
classes, | ||
title | ||
} = props; | ||
|
||
return ( | ||
<UIContext.Consumer> | ||
{({ isMobile, onCloseDetailDrawer, isDetailDrawerOpen }) => ( | ||
<Drawer | ||
elevation={2} | ||
variant={isMobile ? "temporary" : "persistent"} | ||
anchor={anchor} | ||
open={isDetailDrawerOpen} | ||
onClose={onCloseDetailDrawer} | ||
ModalProps={{ | ||
keepMounted: true // Better open performance on mobile. | ||
}} | ||
> | ||
<AppBar | ||
color="default" | ||
elevation={0} | ||
position="sticky" | ||
> | ||
<Toolbar> | ||
<Typography className={classes.title} variant="h3">{title}</Typography> | ||
<IconButton onClick={onCloseDetailDrawer} size="small"> | ||
<CloseIcon /> | ||
</IconButton> | ||
</Toolbar> | ||
</AppBar> | ||
{Children.map(children, (child) => ( | ||
<div className={classes.content}>{child}</div> | ||
))} | ||
</Drawer> | ||
)} | ||
</UIContext.Consumer> | ||
); | ||
} | ||
|
||
DetailDrawer.propTypes = { | ||
anchor: PropTypes.oneOf(["left", "right", "top", "bottom"]), | ||
children: PropTypes.node, | ||
classes: PropTypes.object, | ||
title: PropTypes.string | ||
}; | ||
|
||
DetailDrawer.defaultProps = { | ||
anchor: "right" | ||
}; | ||
|
||
export default withStyles(styles, { name: "RuiDetailDrawer" })(DetailDrawer); |
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 @@ | ||
export { default } from "./DetailDrawer"; |
36 changes: 36 additions & 0 deletions
36
imports/client/ui/components/DetailDrawerButton/DetailDrawerButton.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,36 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import Button from "@material-ui/core/Button"; | ||
import { UIContext } from "../../context/UIContext"; | ||
|
||
/** | ||
* Detail drawer open button | ||
* @param {Object} props Component props | ||
* @returns {React.Component} Sidebar component | ||
*/ | ||
function DetailDrawerButton(props) { | ||
const { | ||
component: ComponentProp, | ||
children, | ||
...otherProps | ||
} = props; | ||
|
||
return ( | ||
<UIContext.Consumer> | ||
{({ onToggleDetailDrawer }) => ( | ||
<ComponentProp {...otherProps} onClick={onToggleDetailDrawer}>{children}</ComponentProp> | ||
)} | ||
</UIContext.Consumer> | ||
); | ||
} | ||
|
||
DetailDrawerButton.propTypes = { | ||
children: PropTypes.node, | ||
component: PropTypes.func | ||
}; | ||
|
||
DetailDrawerButton.defaultProps = { | ||
component: Button | ||
}; | ||
|
||
export default DetailDrawerButton; |
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 @@ | ||
export { default } from "./DetailDrawerButton"; |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { createContext } from "react"; | ||
|
||
export const UIContext = createContext({ | ||
isDetailDrawerOpen: false, | ||
isMobile: false, | ||
isPrimarySidebarOpen: true, | ||
onCloseDetailDrawer: () => { }, | ||
onClosePrimarySidebar: () => { }, | ||
onToggleDetailDrawer: () => { }, | ||
onTogglePrimarySidebar: () => { } | ||
}); |
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
Oops, something went wrong.