-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
694 additions
and
308 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
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
106 changes: 106 additions & 0 deletions
106
packages/datatrak-web/src/features/MobileSelectList/ListItem.tsx
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,106 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import React, { useState, ReactNode } from 'react'; | ||
import { TransitionProps } from '@material-ui/core/transitions'; | ||
import styled from 'styled-components'; | ||
import { | ||
Dialog, | ||
ListItem as MuiListItem, | ||
ListItemProps as MuiListItemProps, | ||
Slide, | ||
} from '@material-ui/core'; | ||
import { ArrowLeftIcon } from '../../components'; | ||
import { StickyMobileHeader } from '../../layout'; | ||
import { ListItemType } from '../useGroupedSurveyList'; | ||
|
||
const Content = styled.div` | ||
flex: 1; | ||
`; | ||
|
||
const Arrow = styled(ArrowLeftIcon)` | ||
font-size: 1rem; | ||
color: ${({ theme }) => theme.palette.primary.main}; | ||
transform: rotate(180deg); | ||
`; | ||
|
||
export const BaseListItem = styled(MuiListItem)<MuiListItemProps>` | ||
border-radius: 10px; | ||
background: white; | ||
padding: 1rem; | ||
margin-bottom: 10px; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
border: 1px solid transparent; | ||
text-align: left; | ||
`; | ||
|
||
const IconWrapper = styled.div` | ||
padding-right: 0.5rem; | ||
display: flex; | ||
align-items: center; | ||
width: 2rem; | ||
font-size: 2rem; | ||
svg { | ||
color: ${({ theme }) => theme.palette.primary.main}; | ||
height: auto; | ||
} | ||
`; | ||
|
||
/** | ||
* Taken from [Material UI's example](https://v4.mui.com/components/dialogs/#full-screen-dialogs) to make the dialog slide up from the bottom | ||
*/ | ||
const Transition = React.forwardRef(function Transition( | ||
props: TransitionProps & { children?: React.ReactElement }, | ||
ref: React.Ref<unknown>, | ||
) { | ||
return <Slide direction="left" ref={ref} {...props} />; | ||
}); | ||
|
||
interface ListItemProps { | ||
item: ListItemType; | ||
onSelect: (item: any) => void; | ||
children?: ReactNode; | ||
} | ||
|
||
export const ListItem = ({ item, onSelect, children }: ListItemProps) => { | ||
const [expanded, setExpanded] = useState(false); | ||
const { content, icon } = item; | ||
const isNested = !!item.children; | ||
|
||
const onClose = () => setExpanded(false); | ||
|
||
const handleOnClick = () => { | ||
if (children) { | ||
setExpanded(true); | ||
} else { | ||
onSelect(item); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<BaseListItem button onClick={handleOnClick}> | ||
<IconWrapper>{icon}</IconWrapper> | ||
<Content>{content}</Content> | ||
{isNested && <Arrow />} | ||
</BaseListItem> | ||
{children && ( | ||
<Dialog | ||
open={expanded} | ||
TransitionComponent={Transition} | ||
keepMounted={false} | ||
onClose={onClose} | ||
fullScreen | ||
> | ||
<StickyMobileHeader onBack={onClose} onClose={onClose} title="Select a survey" /> | ||
{children} | ||
</Dialog> | ||
)} | ||
</> | ||
); | ||
}; |
97 changes: 97 additions & 0 deletions
97
packages/datatrak-web/src/features/MobileSelectList/MobileSelectList.tsx
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,97 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { List as MuiList, Typography } from '@material-ui/core'; | ||
import { ListItem } from './ListItem'; | ||
import { CountrySelectWrapper } from '../CountrySelector'; | ||
import { ListItemType } from '../useGroupedSurveyList'; | ||
|
||
const BaseList = styled(MuiList)` | ||
padding: 20px 25px; | ||
height: 100%; | ||
background: ${({ theme }) => theme.palette.background.default}; | ||
${CountrySelectWrapper} { | ||
margin-bottom: 1rem; | ||
.MuiOutlinedInput-notchedOutline { | ||
border: none; | ||
} | ||
.MuiInputBase-root .MuiSvgIcon-root { | ||
display: none; | ||
} | ||
} | ||
`; | ||
|
||
const CategoryTitle = styled(Typography)` | ||
margin: -0.5rem 0 0.8rem; | ||
padding-top: 1rem; | ||
border-top: 1px solid ${({ theme }) => theme.palette.divider}; | ||
`; | ||
|
||
const NoResultsMessage = styled(Typography)` | ||
padding: 0.8rem 0.5rem; | ||
font-size: 0.875rem; | ||
color: ${({ theme }) => theme.palette.text.secondary}; | ||
`; | ||
|
||
interface SelectListProps { | ||
items?: ListItemType[]; | ||
onSelect: (item: ListItemType) => void; | ||
CountrySelector: React.ReactNode; | ||
} | ||
|
||
const List = ({ parentItem, items, onSelect, CountrySelector }) => { | ||
const parentTitle = parentItem?.value; | ||
return ( | ||
<> | ||
<BaseList> | ||
{CountrySelector} | ||
{parentTitle && <CategoryTitle>{parentTitle}</CategoryTitle>} | ||
{items?.map(item => ( | ||
<ListItem item={item} onSelect={onSelect} key={item.value}> | ||
{item?.children && ( | ||
<List | ||
parentItem={item} | ||
items={item.children} | ||
onSelect={onSelect} | ||
CountrySelector={CountrySelector} | ||
/> | ||
)} | ||
</ListItem> | ||
))} | ||
</BaseList> | ||
</> | ||
); | ||
}; | ||
|
||
export const MobileSelectList = ({ items = [], onSelect, CountrySelector }: SelectListProps) => { | ||
return ( | ||
<> | ||
{items.length === 0 ? ( | ||
<NoResultsMessage>No items to display</NoResultsMessage> | ||
) : ( | ||
<BaseList> | ||
{CountrySelector} | ||
{items?.map(item => ( | ||
<ListItem item={item} onSelect={onSelect} key={item.value}> | ||
{item?.children && ( | ||
<List | ||
parentItem={item} | ||
items={item.children} | ||
onSelect={onSelect} | ||
CountrySelector={CountrySelector} | ||
/> | ||
)} | ||
</ListItem> | ||
))} | ||
</BaseList> | ||
)} | ||
</> | ||
); | ||
}; |
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,6 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
export { MobileSelectList } from './MobileSelectList'; |
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.