Skip to content

Commit

Permalink
feat: Add PermissionDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Jul 5, 2023
1 parent 959dd51 commit cf85f4c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 5 deletions.
94 changes: 94 additions & 0 deletions react/CozyDialogs/PermissionDialog.jsx
@@ -0,0 +1,94 @@
import React from 'react'
import cx from 'classnames'

import { makeStyles } from '../styles'
import CozyTheme from '../CozyTheme'
import ConfirmDialog from './ConfirmDialog'
import PropTypes from 'prop-types'
import Icon from '../Icon'
import Paper from '../Paper'

const useStyles = makeStyles({
floatingIcon: {
top: '-2.25rem',
width: '4.5rem',
height: '4.5rem'
}
})

/**
* Dialog for confirmation actions linked to the Cozy system (permissions, authentication, etc.)
*/
const PermissionDialog = ({
open,
icon,
title,
content,
actions,
actionsLayout,
onClose
}) => {
const styles = useStyles()

return (
<CozyTheme variant="inverted">
<ConfirmDialog
open={open}
size="small"
disableTitleAutoPadding
classes={{
// remove overflow in makeOverride and replace it by u-ov-visible when https://github.com/cozy/cozy-ui/issues/2284 is solved
paper: 'overflow'
}}
componentsProps={{
dialogTitle: {
className: 'u-ta-center u-pt-2 u-pb-half'
}
}}
title={
<>
<CozyTheme
variant="normal"
className="u-flex u-flex-justify-center"
>
<Paper
square
elevation={2}
className={cx(
styles.floatingIcon,
'u-pos-absolute u-bdrs-circle u-flex'
)}
>
<Icon className="u-m-auto" icon={icon} size={48} />
</Paper>
</CozyTheme>
{title}
</>
}
content={content}
actions={actions}
actionsLayout={actionsLayout}
onClose={onClose}
/>
</CozyTheme>
)
}

PermissionDialog.propTypes = {
/** To open/close the modal */
open: PropTypes.bool.isRequired,
/** Icon to describe the action to be taken */
icon: PropTypes.func.isRequired,
/** Title of the modal */
title: PropTypes.string.isRequired,
/** Content of the modal */
content: PropTypes.node,
/** Actions of the modal */
actions: PropTypes.node,
/** Actions can be displayed as "rows" or "columns" */
actionsLayout: PropTypes.oneOf(['row', 'column']),
/** Triggered function on modal close action */
onClose: PropTypes.func
}

export default PermissionDialog
17 changes: 12 additions & 5 deletions react/CozyDialogs/Readme.md
Expand Up @@ -59,7 +59,8 @@ import {
ConfirmDialog,
IllustrationDialog,
FixedDialog,
FixedActionsDialog
FixedActionsDialog,
PermissionDialog
} from 'cozy-ui/transpiled/react/CozyDialogs'

import { BreakpointsProvider } from 'cozy-ui/transpiled/react/hooks/useBreakpoints'
Expand All @@ -77,6 +78,7 @@ import FormLabel from 'cozy-ui/transpiled/react/FormLabel'
import BottomSheet, { BottomSheetItem } from 'cozy-ui/transpiled/react/BottomSheet'
import Stack from 'cozy-ui/transpiled/react/Stack'

import ToTheCloudIcon from 'cozy-ui/transpiled/react/Icons/ToTheCloud'
import CloudIcon from "cozy-ui/transpiled/react/Icons/Cloud"
import BackgroundImg from './background.png'

Expand Down Expand Up @@ -133,31 +135,35 @@ const dialogTitles = {
IllustrationDialog: <Icon icon={CloudIcon} size="140" />,
FixedDialog: 'Fixed Dialog',
FixedActionsDialog: 'Fixed Actions Dialog',
Dialog: 'Dialog'
Dialog: 'Dialog',
PermissionDialog: 'Are you sure ?'
}

const dialogContents = {
ConfirmDialog: "Content of a confirm dialog, precising what the actions will do, and asking the user if she is sure.",
IllustrationDialog: "An IllustrationDialog contains short content." + content.ada.short,
FixedDialog: "A FixedDialog can contain very long content. Actions are at the bottom of the content are not visible to the user if she has not scrolled to the bottom. " + content.ada.long,
FixedActionsDialog: "A FixedActionsDialog can contain very long content. Actions are visible even without scrolling. " + content.ada.long,
Dialog: "A normal Dialog should contain short content. " + content.ada.short
Dialog: "A normal Dialog should contain short content. " + content.ada.short,
PermissionDialog: "Content of a confirm dialog, precising what the actions will do, and asking the user if she is sure.",
}

const dialogActions = {
ConfirmDialog: <ConfirmDialogActions />,
IllustrationDialog: <ExampleDialogActions />,
FixedDialog: <ExampleDialogActions />,
FixedActionsDialog: <ExampleDialogActions />,
Dialog: <ExampleDialogActions />
Dialog: <ExampleDialogActions />,
PermissionDialog: <ExampleDialogActions />,
}

const dialogs = [
Dialog,
ConfirmDialog,
IllustrationDialog,
FixedDialog,
FixedActionsDialog
FixedActionsDialog,
PermissionDialog
]

const StateRadio = ({ name, ...props }) => {
Expand Down Expand Up @@ -326,6 +332,7 @@ const setFlagshipVars = () => {
}
disableGutters={variant.disableGutters}
background={variant.withBackground ? `var(--paperBackgroundColor) repeat-x url(${BackgroundImg})` : undefined}
icon={DialogComponent === PermissionDialog ? CloudIcon : undefined}
content={
<>
<Typography component="div" variant="body1">
Expand Down
1 change: 1 addition & 0 deletions react/CozyDialogs/index.jsx
Expand Up @@ -6,6 +6,7 @@ export { default as ConfirmDialog } from './ConfirmDialog'
export { default as FixedActionsDialog } from './FixedActionsDialog'
export { default as FixedDialog } from './FixedDialog'
export { default as IllustrationDialog } from './IllustrationDialog'
export { default as PermissionDialog } from './PermissionDialog'
export { default as useCozyDialog } from './useCozyDialog'
export { default as TopAnchoredDialog } from './TopAnchoredDialog'
export { InstallFlagshipAppDialog } from './SpecificDialogs'
3 changes: 3 additions & 0 deletions react/MuiCozyTheme/makeOverrides.js
Expand Up @@ -404,6 +404,9 @@ export const makeOverrides = theme => ({
width: '800px',
maxWidth: '800px'
}
},
'&.overflow': {
overflowY: 'visible !important' // Allow the icon to overflow the dialog, otherwise it will be cut off
}
},
scrollPaper: {
Expand Down

0 comments on commit cf85f4c

Please sign in to comment.