Skip to content

Commit

Permalink
feat: #1920 update doc for modal
Browse files Browse the repository at this point in the history
  • Loading branch information
duong-se committed Jul 16, 2020
1 parent 0935917 commit daa3aa9
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 17 deletions.
13 changes: 8 additions & 5 deletions packages/elements-next/src/components/headings/headings.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
---
name: Headings
name: Heading
route: /headings
---

import { Playground, Props } from 'docz'
import { HeadingMain } from './headings'
import { Heading } from './headings'
import { DocsWrapper } from '@/utils/docs-wrapper'

# Headings
# Heading

<Props of={HeadingMain} />
<Props of={Heading.Main} />

<Playground>
<DocsWrapper>
<HeadingMain>Heading Main</HeadingMain>
<Heading.Main>Heading Main</Heading.Main>
<Heading.SubMain>SubHeading Main</Heading.SubMain>
<Heading.Secondary>Heading Secondary</Heading.Secondary>
<Heading.SubSecondary>SubHeading Secondary</Heading.SubSecondary>
</DocsWrapper>
</Playground>

9 changes: 9 additions & 0 deletions packages/elements-next/src/components/headings/headings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ export const HeadingSecondary: React.FC<HeadingProps> = ({ children, isTextCente
export const SubHeadingSecondary: React.FC<HeadingProps> = ({ children, isTextCentered, className }) => (
<h6 className={cx(elHeadingMain, isTextCentered && elIsTextCentered, className)}>{children}</h6>
)

export const Heading = {
Main: HeadingMain,
SubMain: SubHeadingMain,
Secondary: HeadingSecondary,
SubSecondary: SubHeadingSecondary,
} as { [key: string]: React.ReactNode }

export default Heading
2 changes: 1 addition & 1 deletion packages/elements-next/src/components/headings/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './headings'
export { default } from './headings'
15 changes: 11 additions & 4 deletions packages/elements-next/src/components/modal/modal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import { Modal } from './modal'
import { DocsWrapper } from '@/utils/docs-wrapper'

# Modal

## Document
<Props of={Modal} />

## Usage
<Playground>
<DocsWrapper>
<Modal title="example">Heading Main</Modal>
</DocsWrapper>
{() => {
const [isShowModal, setIsShowModal] = React.useState(false)
return (
<DocsWrapper>
<Modal visible={isShowModal} isCentered={true} title="example" destroyOnClose={true} onClose={() => setIsShowModal(false)}>Heading Main</Modal>
<button onClick={() => setIsShowModal(true)}>Show Modal</button>
</DocsWrapper>
)
}}
</Playground>
162 changes: 155 additions & 7 deletions packages/elements-next/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,150 @@ import Dialog from 'rc-dialog'
import { cx } from 'linaria'
import IDialogPropTypes from 'rc-dialog/lib/IDialogPropTypes'
import { modalContainer, modalCentered } from './__styles__'
import '../../../../../node_modules/rc-dialog/assets/index.css'

declare type IStringOrHtmlElement = string | HTMLElement

export interface ModalProps extends IDialogPropTypes {
/**
* This is property to set Modal center of the screen
*/
isCentered?: boolean
/**
* The dialog dom node's prefixCls
*/
prefixCls?: string
/**
* Additional className for dialog
*/
className?: string
/**
* Additional className for dialog wrap
*/
wrapClassName?: string
/**
* Root style for dialog element.Such as width, height
*/
style?: React.CSSProperties
zIndex?: number
/**
* Body style for dialog body element.Such as height
*/
bodyStyle?: {}
/**
* Style for mask element.
*/
maskStyle?: {}
/**
* Current dialog's visible status
*/
visible?: boolean
/**
* part of dialog animation css class name
*/
animation?: any
/**
* Part of dialog's mask animation css class name
*/
maskAnimation?: any
/**
* whether support press esc to close
*/
keyboard?: boolean
/**
* whether show mask
*/
mask?: boolean
/**
* Children of the component
*/
children?: any
/**
* called when close animation end
*/
afterClose?: () => any
/**
* called when click close button or mask
*/
onClose?: (e: React.SyntheticEvent<HTMLDivElement>) => any
/**
* whether show close button
*/
closable?: boolean
/**
* whether click mask to close
*/
maskClosable?: boolean
/**
* to unmount child compenents on onClose
*/
destroyOnClose?: boolean
/**
* set pageX and pageY of current mouse(it will cause transform origin to be set).
*/
mousePosition?: {
x: number
y: number
}
/**
* Title of the dialog
*/
title?: React.ReactNode
/**
* footer of the dialog
*/
footer?: React.ReactNode
/**
* dialog animation css class name
*/
transitionName?: string
/**
* mask animation css class name
*/
maskTransitionName?: string
/**
* Style object for wrap
*/
wrapStyle?: {}
/**
* width of the modal
*/
width?: number
/**
* height of the modal
*/
height?: number
/**
* Props for body
*/
bodyProps?: any
/**
* Props for mask
*/
maskProps?: any
/**
* Props for wrap
*/
wrapProps?: any
/**
* to determine where Dialog will be mounted
*/
getContainer?: IStringOrHtmlElement | (() => IStringOrHtmlElement) | false
/**
* specific the close icon.
*/
closeIcon?: React.ReactNode
/**
* Create dialog dom node before dialog first show
*/
forceRender?: boolean
/**
* focus trigger element when dialog closed
*/
focusTriggerAfterClose?: boolean
}

export const Modal: React.FC<ModalProps> = ({
children,
className,
wrapClassName,
isCentered = false,
...restProps
}) => {
export const Modal: React.FC<ModalProps> = ({ children, className, wrapClassName, isCentered, ...restProps }) => {
return (
<Dialog
{...restProps}
Expand All @@ -26,4 +158,20 @@ export const Modal: React.FC<ModalProps> = ({
)
}

Modal.defaultProps = {
prefixCls: 'rc-dialog',
style: {},
bodyStyle: {},
maskStyle: {},
visible: false,
closable: true,
mask: true,
maskClosable: true,
keyboard: true,
destroyOnClose: false,
forceRender: false,
focusTriggerAfterClose: true,
isCentered: false,
}

export default React.memo(Modal)

0 comments on commit daa3aa9

Please sign in to comment.