Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
refactor(modal): align modal with component structure
Browse files Browse the repository at this point in the history
The Modal nested the ModalTitle, ModalContent, and ModalActions
components inside of Modal as a way to reduce the API surface. This
change aligns the components with the other components.

BREAKING CHANGE: This deprecated use of Modal.Actions. Instead, use
ModalActions.

BREAKING CHANGE: This deprecated use of Modal.Content. Instead, use
ModalContent.

BREAKING CHANGE: This deprecated use of Modal.Title. Instead, use
ModalTitle.
  • Loading branch information
varl committed Nov 20, 2019
1 parent 118c3f3 commit 1cafa84
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 74 deletions.
23 changes: 8 additions & 15 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,28 @@ import { createPortal } from 'react-dom'
import { sizePropType } from './common-prop-types.js'
import { ScreenCover } from './ScreenCover.js'

import { Actions } from './Modal/Actions.js'
import { Content } from './Modal/Content.js'
import { ModalCard } from './Modal/ModalCard.js'
import { Title } from './Modal/Title.js'

/**
* Modal provides a UI to prompt the user to respond to a question
* or a note to the user.
*
* Use Model with the following Components:
* Model.Title (optional)
* Model.Content (required)
* Model.Actions (required)
* ModelTitle (optional)
* ModelContent (required)
* ModelActions (required)
* @module
* @param {Modal.PropTypes} props
* @returns {React.Component}
*
* @example import { Modal } from @dhis2/ui-core
* @example
* <Modal>
* <Modal.Title>Hello</Modal.Title>
* <Modal.Content>Some content here</Modal.Content>
* <Modal.Actions>
* <ModalTitle>Hello</ModalTitle>
* <ModalContent>Some content here</ModalContent>
* <ModalActions>
* <Button primary>My action</Button>
* </Modal.Actions>
* </ModalActions>
* </Modal>
*
* @see Specification: {@link https://github.com/dhis2/design-system/blob/master/molecules/modal.md|Design system}
Expand Down Expand Up @@ -59,10 +56,6 @@ export const Modal = ({ children, onClose, small, large, open, className }) => {
)
}

Modal.Title = Title
Modal.Content = Content
Modal.Actions = Actions

/**
* @typedef {Object} PropTypes
* @static
Expand All @@ -75,7 +68,7 @@ Modal.Actions = Actions
* @prop {bool} large
*/
Modal.propTypes = {
// Can contain Modal.Title; Must contain Modal.Content and Modal.Actions
// Can contain ModalTitle; Must contain ModalContent and ModalActions
children: propTypes.oneOfType([
propTypes.element,
propTypes.arrayOf(propTypes.element),
Expand Down
8 changes: 4 additions & 4 deletions src/Modal/Actions.js → src/ModalActions.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'
import propTypes from '@dhis2/prop-types'

import { spacers } from '../theme.js'
import { spacers } from './theme.js'

/**
* @module
*
* @param {Actions.PropTypes} props
* @param {ModalActions.PropTypes} props
* @returns {React.Component}
*/
export const Actions = ({ children }) => (
export const ModalActions = ({ children }) => (
<div>
{children}

Expand All @@ -28,7 +28,7 @@ export const Actions = ({ children }) => (
* @static
* @prop {Object} children - Accepts one or more `Element`s
*/
Actions.propTypes = {
ModalActions.propTypes = {
children: propTypes.oneOfType([
propTypes.element,
propTypes.arrayOf(propTypes.element),
Expand Down
8 changes: 4 additions & 4 deletions src/Modal/Content.js → src/ModalContent.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'
import propTypes from '@dhis2/prop-types'

import { spacers } from '../theme.js'
import { spacers } from './theme.js'

/**
* @module
*
* @param {Content.PropTypes} props
* @param {ModalContent.PropTypes} props
* @returns {React.Component}
*/
export const Content = ({ children, className }) => (
export const ModalContent = ({ children, className }) => (
<div className={className}>
{children}

Expand All @@ -34,7 +34,7 @@ export const Content = ({ children, className }) => (
* @prop {Node} children
* @prop {string} [className]
*/
Content.propTypes = {
ModalContent.propTypes = {
children: propTypes.node.isRequired,
className: propTypes.string,
}
8 changes: 4 additions & 4 deletions src/Modal/Title.js → src/ModalTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react'
import propTypes from '@dhis2/prop-types'
import cx from 'classnames'

import { spacers } from '../theme.js'
import { spacers } from './theme.js'

/**
* @module
* @param {Title.PropTypes} props
* @param {ModalTitle.PropTypes} props
* @returns {React.Component}
*/
export const Title = ({ children }) => (
export const ModalTitle = ({ children }) => (
<h1 className={cx('title')}>
{children}

Expand All @@ -30,6 +30,6 @@ export const Title = ({ children }) => (
* @static
* @prop {string} children
*/
Title.propTypes = {
ModalTitle.propTypes = {
children: propTypes.string.isRequired,
}
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export { DropdownButton } from './DropdownButton.js'
export { Menu } from './Menu.js'
export { Node } from './Node.js'
export { Modal } from './Modal.js'
export { ModalActions } from './ModalActions.js'
export { ModalContent } from './ModalContent.js'
export { ModalTitle } from './ModalTitle.js'
export { SplitButton } from './SplitButton.js'
export { Tab, TabBar, ScrollBar } from './Tabs.js'

Expand Down
Loading

0 comments on commit 1cafa84

Please sign in to comment.