Skip to content

Commit

Permalink
Merge pull request #1551 from cozy/dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne authored Sep 14, 2020
2 parents 7c3a76a + 217dbee commit dcf31bb
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 79 deletions.
2 changes: 1 addition & 1 deletion docs/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module.exports = {
'../react/Media/Media.jsx',
'../react/MidEllipsis/index.jsx',
'../react/Modal/index.jsx',
'../react/Dialog',
'../react/OrderedList/index.jsx',
'../react/Table/index.jsx',
'../react/Text/index.jsx',
Expand Down Expand Up @@ -154,7 +155,6 @@ module.exports = {
name: 'Labs',
components: () => [
'../react/Labs/GridItem',
'../react/Labs/ExperimentalDialog',
'../react/Labs/IconGrid',
'../react/Labs/CollectionField',
'../react/Labs/PasswordInput'
Expand Down
9 changes: 9 additions & 0 deletions react/Dialog/DialogActions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import MUIDialogActions from '@material-ui/core/DialogActions'

const DialogActions = ({ layout, children }) => {
const className = layout === 'row' ? { className: 'modal_actions_row' } : {}
return <MUIDialogActions {...className}>{children}</MUIDialogActions>
}

export default DialogActions
3 changes: 3 additions & 0 deletions react/Dialog/DialogCloseButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ModalCross from '../Modal/ModalCross'

export default ModalCross
3 changes: 3 additions & 0 deletions react/Dialog/DialogContent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import DialogContent from '@material-ui/core/DialogContent'

export default DialogContent
3 changes: 3 additions & 0 deletions react/Dialog/DialogContentText.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import DialogContentText from '@material-ui/core/DialogContentText'

export default DialogContentText
13 changes: 13 additions & 0 deletions react/Dialog/DialogTitle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'
import MUIDialogTitle from '@material-ui/core/DialogTitle'
import AppTitle from '../AppTitle'

const DialogTitle = ({ children }) => {
return (
<MUIDialogTitle disableTypography>
<AppTitle id="dialog-title">{children}</AppTitle>
</MUIDialogTitle>
)
}

export default DialogTitle
56 changes: 26 additions & 30 deletions react/Labs/ExperimentalDialog/Readme.md → react/Dialog/Readme.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
## Experimental Dialog
## Dialog

### With default Actions (mobile and desktop)

```jsx
import ExperimentalDialog, {
ExperimentalDialogTitle,
ExperimentalDialogActions
} from './index'
import Dialog from 'cozy-ui/transpiled/react/Dialog'
import DialogTitle from 'cozy-ui/transpiled/react/Dialog/DialogTitle'
import DialogActions from 'cozy-ui/transpiled/react/Dialog/DialogActions'
import MuiCozyTheme from 'cozy-ui/transpiled/react/MuiCozyTheme/'

import DialogContent from 'cozy-ui/transpiled/react/MuiCozyTheme/Dialog/DialogContent'
import DialogContentText from 'cozy-ui/transpiled/react/MuiCozyTheme/Dialog/DialogContentText'
import DialogContent from 'cozy-ui/transpiled/react/Dialog/DialogContent'
import DialogContentText from 'cozy-ui/transpiled/react/Dialog/DialogContentText'
import DialogCloseButton from 'cozy-ui/transpiled/react/Dialog/DialogCloseButton'
import Divider from 'cozy-ui/transpiled/react/MuiCozyTheme/Divider'
import DialogCloseButton from 'cozy-ui/transpiled/react/MuiCozyTheme/Dialog/DialogCloseButton'
import Button from 'cozy-ui/transpiled/react/Button'

const onClose = () => setState({ modalOpened: !state.modalOpened })
Expand All @@ -23,9 +21,9 @@ initialState = { modalOpened: isTesting() }
Toggle modal
</button>
<MuiCozyTheme>
<ExperimentalDialog open={state.modalOpened} onClose={() => onClose()}>
<Dialog open={state.modalOpened} onClose={() => onClose()}>
<DialogCloseButton onClick={() => onClose()} />
<ExperimentalDialogTitle>Ada Lovelace</ExperimentalDialogTitle>
<DialogTitle>Ada Lovelace</DialogTitle>
<Divider />
<DialogContent>
Augusta Ada King-Noel, Countess of Lovelace (née Byron; 10 December 1815
Expand All @@ -38,7 +36,7 @@ initialState = { modalOpened: isTesting() }
the full potential of a "computing machine" and the first computer
programmer.
</DialogContent>
<ExperimentalDialogActions>
<DialogActions>
<Button
theme="secondary"
onClick={() => onClose()}
Expand All @@ -49,24 +47,22 @@ initialState = { modalOpened: isTesting() }
label={'Touch Me'}
onClick={() => alert('click')}
/>
</ExperimentalDialogActions>
</ExperimentalDialog>
</DialogActions>
</Dialog>
</MuiCozyTheme>
</>
```
### With "below" Actions (mobile)
```jsx
import ExperimentalDialog, {
ExperimentalDialogTitle,
ExperimentalDialogActions
} from './index'
import Dialog from 'cozy-ui/transpiled/react/Dialog'
import DialogTitle from 'cozy-ui/transpiled/react/Dialog/DialogTitle'
import DialogActions from 'cozy-ui/transpiled/react/Dialog/DialogActions'
import MuiCozyTheme from 'cozy-ui/transpiled/react/MuiCozyTheme/'
import DialogContent from 'cozy-ui/transpiled/react/MuiCozyTheme/Dialog/DialogContent'
import DialogContentText from 'cozy-ui/transpiled/react/MuiCozyTheme/Dialog/DialogContentText'
import DialogCloseButton from 'cozy-ui/transpiled/react/MuiCozyTheme/Dialog/DialogCloseButton'
import DialogContent from 'cozy-ui/transpiled/react/Dialog/DialogContent'
import DialogContentText from 'cozy-ui/transpiled/react/Dialog/DialogContentText'
import DialogCloseButton from 'cozy-ui/transpiled/react/Dialog/DialogCloseButton'
import Button from 'cozy-ui/transpiled/react/Button'
const onClose = () => setState({ modalOpened: !state.modalOpened })
Expand All @@ -76,9 +72,9 @@ initialState = { modalOpened: isTesting() }
Toggle modal
</button>
<MuiCozyTheme>
<ExperimentalDialog open={state.modalOpened} onClose={() => onClose()}>
<Dialog open={state.modalOpened} onClose={() => onClose()}>
<DialogCloseButton onClick={() => onClose()} />
<ExperimentalDialogTitle>Ada Lovelace</ExperimentalDialogTitle>
<DialogTitle>Ada Lovelace</DialogTitle>
<DialogContent>
Augusta Ada King-Noel, Countess of Lovelace (née Byron; 10 December 1815
– 27 November 1852) was an English mathematician and writer, chiefly
Expand All @@ -90,7 +86,7 @@ initialState = { modalOpened: isTesting() }
the full potential of a "computing machine" and the first computer
programmer.
</DialogContent>
<ExperimentalDialogActions layout="row">
<DialogActions layout="row">
<Button
theme="secondary"
onClick={() => onClose()}
Expand All @@ -101,12 +97,12 @@ initialState = { modalOpened: isTesting() }
label={'Touch Me'}
onClick={() => alert('click')}
/>
</ExperimentalDialogActions>
</ExperimentalDialog>
</DialogActions>
</Dialog>
</MuiCozyTheme>
</>
```

- ExperimentalDialogs have no close button, but Cozy-UI exposes `cozy-ui/transpiled/react/MuiCozyTheme/Dialog/DialogCloseButton` that can be included as a child of `<ExperimentalDialog />`.
- Use `<ExperimentalDialog scroll="body" />` to make the whole Dialog scrollable, instead of only the `DialogContent`.
- Use [Divider components](https://v3.material-ui.com/api/divider/) when you need to materialize the separation between `ExperimentalDialogTitle`, `DialogContent` and `ExperimentalDialogActions`.
- Dialogs have no close button, but Cozy-UI exposes `cozy-ui/transpiled/react/MuiCozyTheme/Dialog/DialogCloseButton` that can be included as a child of `<Dialog />`.
- Use `<Dialog scroll="body" />` to make the whole Dialog scrollable, instead of only the `DialogContent`.
- Use [Divider components](https://v3.material-ui.com/api/divider/) when you need to materialize the separation between `DialogTitle`, `DialogContent` and `DialogActions`.
40 changes: 40 additions & 0 deletions react/Dialog/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'

import MUIDialog from '@material-ui/core/Dialog'
import withMobileDialog from '@material-ui/core/withMobileDialog'
import PropTypes from 'prop-types'

export const Dialog = props => {
const { onClose, fullScreen, children, open, scroll, ...otherProps } = props
return (
<MUIDialog
open={open}
onClose={onClose}
fullScreen={fullScreen}
aria-labelledby="dialog-title"
scroll={scroll}
{...otherProps}
>
{children}
</MUIDialog>
)
}
Dialog.defaultProps = {
open: true,
scroll: 'paper'
}

Dialog.propTypes = {
onClose: PropTypes.func,
open: PropTypes.bool,
fullScreen: PropTypes.bool,
scroll: PropTypes.oneOf(['paper', 'body'])
}

export default withMobileDialog()(Dialog)

export { default as DialogActions } from './DialogActions'
export { default as DialogCloseButton } from './DialogCloseButton'
export { default as DialogContent } from './DialogContent'
export { default as DialogContentText } from './DialogContentText'
export { default as DialogTitle } from './DialogTitle'
56 changes: 19 additions & 37 deletions react/Labs/ExperimentalDialog/index.jsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,31 @@
import React from 'react'

import Dialog from '@material-ui/core/Dialog'
import DialogTitle from '@material-ui/core/DialogTitle'
import DialogActions from '@material-ui/core/DialogActions'
import withMobileDialog from '@material-ui/core/withMobileDialog'
import PropTypes from 'prop-types'
import AppTitle from '../../AppTitle'
import Dialog from '../../Dialog'
import DialogTitle from '../../Dialog/DialogTitle'
import DialogActions from '../../Dialog/DialogActions'
import createDepreciationLogger from '../../helpers/createDepreciationLogger'

const logDepecratedExperimentalDialog = createDepreciationLogger()

export const ExperimentalDialog = props => {
const { onClose, fullScreen, children, open, scroll, ...otherProps } = props
return (
<Dialog
open={open}
onClose={onClose}
fullScreen={fullScreen}
aria-labelledby="dialog-title"
scroll={scroll}
{...otherProps}
>
{children}
</Dialog>
logDepecratedExperimentalDialog(
'ExperimentalDialog is no longer Experimental. Please change the import path to "cozy-ui/transpiled/react/Dialog"'
)
}
ExperimentalDialog.defaultProps = {
open: true,
scroll: 'paper'
return <Dialog {...props} />
}

ExperimentalDialog.propTypes = {
onClose: PropTypes.func,
open: PropTypes.bool,
fullScreen: PropTypes.bool,
scroll: PropTypes.oneOf(['paper', 'body'])
}
export const ExperimentalDialogTitle = ({ children }) => {
return (
<DialogTitle disableTypography>
<AppTitle id="dialog-title">{children}</AppTitle>
</DialogTitle>
export const ExperimentalDialogTitle = props => {
logDepecratedExperimentalDialog(
'ExperimentalDialogTitle is no longer Experimental. Please change the import path to "cozy-ui/transpiled/react/Dialog/DialogTitle"'
)
return <DialogTitle {...props} />
}

export const ExperimentalDialogActions = ({ layout, children }) => {
const className = layout === 'row' ? { className: 'modal_actions_row' } : {}
return <DialogActions {...className}>{children}</DialogActions>
export const ExperimentalDialogActions = props => {
logDepecratedExperimentalDialog(
'ExperimentalDialogActions is no longer Experimental. Please change the import path to "cozy-ui/transpiled/react/Dialog/DialogActions"'
)
return <DialogActions {...props} />
}

export default withMobileDialog()(ExperimentalDialog)
export default ExperimentalDialog
15 changes: 13 additions & 2 deletions react/MuiCozyTheme/Dialog/DialogCloseButton.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import ModalCross from '../../Modal/ModalCross'
import React from 'react'
import DialogCloseButton from '../../Dialog/DialogCloseButton'
import createDepreciationLogger from '../../helpers/createDepreciationLogger'

export default ModalCross
const logDepecratedMUIDialog = createDepreciationLogger()

const DeprecatedDialogCloseButton = props => {
logDepecratedMUIDialog(
'DialogCloseButton is now exported from the cozy-ui Dialog folder. Please change the import path to "cozy-ui/transpiled/react/Dialog/DialogCloseButton"'
)
return <DialogCloseButton {...props} />
}

export default DeprecatedDialogCloseButton
15 changes: 13 additions & 2 deletions react/MuiCozyTheme/Dialog/DialogContent.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import DialogContent from '@material-ui/core/DialogContent'
import React from 'react'
import DialogContent from '../../Dialog/DialogContent'
import createDepreciationLogger from '../../helpers/createDepreciationLogger'

export default DialogContent
const logDepecratedMUIDialog = createDepreciationLogger()

const OldDialogContent = props => {
logDepecratedMUIDialog(
'DialogContent is now exported from the cozy-ui Dialog folder. Please change the import path to "cozy-ui/transpiled/react/Dialog/DialogContent"'
)
return <DialogContent {...props} />
}

export default OldDialogContent
15 changes: 13 additions & 2 deletions react/MuiCozyTheme/Dialog/DialogContentText.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import DialogContentText from '@material-ui/core/DialogContentText'
import React from 'react'
import DialogContentText from '../../Dialog/DialogContentText'
import createDepreciationLogger from '../../helpers/createDepreciationLogger'

export default DialogContentText
const logDepecratedMUIDialog = createDepreciationLogger()

const OldDialogContentText = props => {
logDepecratedMUIDialog(
'DialogContentText is now exported from the cozy-ui Dialog folder. Please change the import path to "cozy-ui/transpiled/react/Dialog/DialogContentText"'
)
return <DialogContentText {...props} />
}

export default OldDialogContentText
8 changes: 4 additions & 4 deletions react/__snapshots__/examples.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,10 @@ exports[`DateMonthPicker should render examples: DateMonthPicker 1`] = `
</div>"
`;

exports[`Dialog should render examples: Dialog 1`] = `"<div><button>Toggle modal</button></div>"`;

exports[`Dialog should render examples: Dialog 2`] = `"<div><button>Toggle modal</button></div>"`;

exports[`Empty should render examples: Empty 1`] = `
"<div>
<div style=\\"position: relative; transform: translateZ(0); height: 500px; display: flex;\\">
Expand Down Expand Up @@ -5417,10 +5421,6 @@ exports[`Labs/CollectionField should render examples: Labs/CollectionField 2`] =
</div>"
`;

exports[`Labs/ExperimentalDialog should render examples: Labs/ExperimentalDialog 1`] = `"<div><button>Toggle modal</button></div>"`;

exports[`Labs/ExperimentalDialog should render examples: Labs/ExperimentalDialog 2`] = `"<div><button>Toggle modal</button></div>"`;

exports[`ListItemText should render examples: ListItemText 1`] = `
"<div>
<div class=\\"styles__c-list-text___3kc3E\\">
Expand Down
2 changes: 1 addition & 1 deletion react/examples.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ testComponent('Checkbox')
testComponent('ContactsList')
testComponent('ContactsListModal')
testComponent('DateMonthPicker')
testComponent('Dialog')
testComponent('Empty')
testComponent('Field')
testComponent('Hero')
Expand All @@ -48,7 +49,6 @@ testComponent('InlineCard')
testComponent('InputGroup')
testComponent('Label')
testComponent('Labs/CollectionField')
testComponent('Labs/ExperimentalDialog')
testComponent('ListItemText')
testComponent('Media')
testComponent('Menu')
Expand Down

0 comments on commit dcf31bb

Please sign in to comment.