-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add detailed and compact section view
- Loading branch information
Showing
7 changed files
with
307 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useCallback } from 'react' | ||
import cx from 'classnames' | ||
|
||
import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu' | ||
import Button from 'cozy-ui/transpiled/react/Buttons' | ||
import Divider from 'cozy-ui/transpiled/react/MuiCozyTheme/Divider' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import SquareAppIcon from 'cozy-ui/transpiled/react/SquareAppIcon' | ||
import DotsIcon from 'cozy-ui/transpiled/react/Icons/Dots' | ||
import { | ||
DisplayMode, | ||
SectionItem, | ||
SectionViewProps | ||
} from 'components/Shortcuts/types/shortcuts_types' | ||
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints' | ||
import { actions } from 'components/Shortcuts/actions/SectionActions' | ||
|
||
export const SectionView = ({ section }: SectionViewProps): JSX.Element => { | ||
const { isMobile } = useBreakpoints() | ||
const [display, setDisplay] = React.useState( | ||
section[isMobile ? 'mobile' : 'desktop'].detailed_lines | ||
? DisplayMode.DETAILED | ||
: DisplayMode.COMPACT | ||
) | ||
const [state, setState] = React.useState(false) | ||
const toggleMenu = (): void => setState(!state) | ||
const anchorRef = React.useRef(null) | ||
const handleAction = useCallback( | ||
(action: DisplayMode) => { | ||
if (action === display) return | ||
|
||
setDisplay(action) | ||
}, | ||
[display] | ||
) | ||
const items = [] as SectionItem[] // TODO: fetch items from section ID with useQuery (already used in another file) | ||
|
||
return ( | ||
<div className="shortcuts-list-wrapper u-m-auto u-w-100"> | ||
<Divider className="u-mv-0" variant="subtitle2"> | ||
{section.originalName} | ||
</Divider> | ||
|
||
<Button | ||
label={<Icon icon={DotsIcon} />} | ||
ref={anchorRef} | ||
onClick={toggleMenu} | ||
/> | ||
|
||
<ActionsMenu | ||
ref={anchorRef} | ||
open={state} | ||
anchorOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: 'left' | ||
}} | ||
docs={[section]} | ||
actions={actions} | ||
autoClose | ||
onClose={toggleMenu} | ||
componentsProps={{ actionsItems: { actionOptions: { handleAction } } }} | ||
/> | ||
|
||
<div | ||
className={cx( | ||
'shortcuts-list u-w-100 u-mv-3 u-mv-2-t u-mh-auto u-flex-justify-center', | ||
{ detailed: display === DisplayMode.DETAILED } | ||
)} | ||
> | ||
{items.map((item, index) => ( | ||
<SquareAppIcon | ||
key={index} | ||
display={display} | ||
name={item.name} | ||
description={item.description} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} |
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,35 @@ | ||
import React from 'react' | ||
|
||
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem' | ||
import FileIcon from 'cozy-ui/transpiled/react/Icons/File' | ||
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon' | ||
import ListItemText from 'cozy-ui/transpiled/react/ListItemText' | ||
import { makeActions } from 'cozy-ui/transpiled/react/ActionsMenu/Actions' | ||
import { Action, DisplayMode } from 'components/Shortcuts/types/shortcuts_types' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
|
||
const createCustomAction = (primaryText: DisplayMode): (() => Action) => { | ||
return () => ({ | ||
name: `customAction_${primaryText}`, | ||
action: (_doc, opts): void => { | ||
opts.handleAction(primaryText) | ||
}, | ||
Component: React.forwardRef(function CustomActionComponent(props, ref) { | ||
return ( | ||
<ActionsMenuItem {...props} ref={ref}> | ||
<ListItemIcon> | ||
<Icon icon={FileIcon} /> | ||
</ListItemIcon> | ||
<ListItemText primary={primaryText} /> | ||
</ActionsMenuItem> | ||
) | ||
}) | ||
}) | ||
} | ||
|
||
const actionArray = [ | ||
createCustomAction(DisplayMode.COMPACT), | ||
createCustomAction(DisplayMode.DETAILED) | ||
] | ||
|
||
export const actions = makeActions(actionArray) |
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,74 @@ | ||
[ | ||
{ | ||
"id": [ | ||
"1" | ||
], | ||
"originalName": "Applications Toutatice", | ||
"createdByApp": [ | ||
"toutatice" | ||
], | ||
"mobile": { | ||
"detailed_lines": true, | ||
"grouped": false | ||
}, | ||
"desktop": { | ||
"detailed_lines": true, | ||
"grouped": false | ||
}, | ||
"order": 5001 | ||
}, | ||
{ | ||
"id": [ | ||
"2" | ||
], | ||
"originalName": "Infos", | ||
"createdByApp": [ | ||
"infos" | ||
], | ||
"mobile": { | ||
"detailed_lines": true, | ||
"grouped": true | ||
}, | ||
"desktop": { | ||
"detailed_lines": false, | ||
"grouped": true | ||
}, | ||
"order": 5002 | ||
}, | ||
{ | ||
"id": [ | ||
"3" | ||
], | ||
"originalName": "Espace", | ||
"createdByApp": [ | ||
"espace" | ||
], | ||
"mobile": { | ||
"detailed_lines": false, | ||
"grouped": true | ||
}, | ||
"desktop": { | ||
"detailed_lines": false, | ||
"grouped": true | ||
}, | ||
"order": 5003 | ||
}, | ||
{ | ||
"id": [ | ||
"4" | ||
], | ||
"originalName": "Mes liens & raccourcis", | ||
"createdByApp": [ | ||
"shortcuts" | ||
], | ||
"mobile": { | ||
"detailed_lines": true, | ||
"grouped": true | ||
}, | ||
"desktop": { | ||
"detailed_lines": false, | ||
"grouped": true | ||
}, | ||
"order": 5004 | ||
} | ||
] |
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,40 @@ | ||
export interface DeviceSettings { | ||
detailed_lines: boolean | ||
grouped: boolean | ||
} | ||
|
||
export interface Section { | ||
id: string[] | ||
originalName: string | ||
createdByApp: string[] | ||
mobile: DeviceSettings | ||
desktop: DeviceSettings | ||
order: number | ||
} | ||
|
||
export interface SectionsLayout { | ||
sections: Section[] | ||
} | ||
|
||
export interface SectionViewProps { | ||
section: Section | ||
} | ||
|
||
export interface SectionItem { | ||
id: string | ||
name: string | ||
description: string | ||
} | ||
|
||
export enum DisplayMode { | ||
COMPACT = 'COMPACT', | ||
DETAILED = 'DETAILED' | ||
} | ||
|
||
type HandleActionCallback = (action: DisplayMode) => void | ||
|
||
export type Action = { | ||
name: string | ||
action: (doc: Section, opts: { handleAction: HandleActionCallback }) => void | ||
Component: React.FC | ||
} |
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