-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/download template redesign #342
base: development
Are you sure you want to change the base?
Changes from 2 commits
4c2d642
3f125d4
3956019
bfbee3f
6c03661
7d1a064
b8b34e7
8704405
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,89 @@ | ||
import { Icon, IconButton, makeStyles, Paper } from "@material-ui/core"; | ||
import React from "react"; | ||
|
||
type iconPosition = "left" | "right"; | ||
type arrowStyle = "upDown" | "rightLeft"; | ||
|
||
export interface SectionProps { | ||
isOpen?: boolean; | ||
setOpen?: (open: boolean) => void; | ||
children: React.ReactNode; | ||
title: React.ReactNode; | ||
collapsible?: boolean; | ||
elevation?: number; | ||
iconPos?: iconPosition; | ||
classProps?: { | ||
section?: string; | ||
header?: string; | ||
content?: string; | ||
}; | ||
arrowStyle?: arrowStyle; | ||
} | ||
|
||
export const Section = ({ | ||
children, | ||
title, | ||
collapsible, | ||
isOpen = true, | ||
setOpen = () => {}, | ||
elevation = 1, | ||
iconPos = "right", | ||
classProps = {}, | ||
arrowStyle = "upDown", | ||
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. About the expand/collapse styles, I checked what DHIS2 does, and... it depends: orgUnits tree (icon: left the name): right/down https://play.im.dhis2.org/stable-2-40-6/dhis-web-maps/#/GlCLRPPLsWF I have no strong opinion on this, so PM to decide. |
||
}: SectionProps) => { | ||
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. That's not wrong at all, but typically we prefer to write |
||
const classes = useStyles(); | ||
const leftIcon = iconPos === "left" ? classes.leftIcon : null; | ||
const toggle = () => setOpen(!isOpen); | ||
|
||
return ( | ||
<Paper elevation={elevation} className={`${classes.paper} ${classProps.section}`}> | ||
<div | ||
className={`${classes.header} ${leftIcon} ${classProps.header} ${isOpen ? "" : classes.noBorder}`} | ||
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. If I am not mistaken, when |
||
onClick={toggle} | ||
> | ||
{collapsible && leftIcon && <CollapsibleToggle isOpen={isOpen} arrowStyle={arrowStyle} />} | ||
{title} | ||
{collapsible && !leftIcon && <CollapsibleToggle isOpen={isOpen} arrowStyle={arrowStyle} />} | ||
</div> | ||
<div className={`${classProps.content}`} style={{ display: isOpen ? "" : "none" }}> | ||
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. Whenever possible, we strive for immutable props (memoized components will benefit from that). |
||
{children} | ||
</div> | ||
</Paper> | ||
); | ||
}; | ||
|
||
export interface CollapsibleToggleProps { | ||
isOpen: boolean; | ||
arrowStyle: "upDown" | "rightLeft"; | ||
} | ||
|
||
export const CollapsibleToggle = ({ isOpen, arrowStyle }: CollapsibleToggleProps) => { | ||
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. It's not used externally, right? we can remove the export. |
||
const classes = useStyles(); | ||
const [open, close] = arrowStyle === "upDown" ? ["up", "down"] : ["right", "left"]; | ||
|
||
return ( | ||
<IconButton disableTouchRipple={true} style={isOpen ? {} : { left: 0 }} className={classes.button}> | ||
<Icon>{isOpen ? `keyboard_arrow_${open}` : `keyboard_arrow_${close}`}</Icon> | ||
</IconButton> | ||
); | ||
}; | ||
|
||
const useStyles = makeStyles({ | ||
header: { | ||
margin: 0, | ||
padding: "1em", | ||
paddingLeft: 0, | ||
display: "flex", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
borderBottom: "solid 1px #e8edf2", | ||
cursor: "pointer", | ||
}, | ||
noBorder: { border: "none" }, | ||
leftIcon: { | ||
justifyContent: "normal", | ||
gap: 10, | ||
}, | ||
paper: { padding: "1em", paddingTop: "0.5em", marginBottom: "1em" }, | ||
button: { padding: 0 }, | ||
}); |
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.
I see you preferred to define children explicitly in the props instead of using React.FC. We typically use FC, BUT since it adds always children (that's why some people don't like FC), we lose some control, so let's go with this. Eventually, we can decide on creating our own "FCWithProps" or whatever, but no need to to it here.