Skip to content

Commit

Permalink
fix: 添加Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
SzHeJason committed Jul 20, 2018
1 parent f6282dc commit 1380e2a
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 25 deletions.
26 changes: 26 additions & 0 deletions src/components/modal/action/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Taro from '@tarojs/taro'
import { Button } from '@tarojs/components'

import _isFunction from 'lodash/isFunction'

import './index.scss'

export default class ModalButton extends Taro.Component {
constructor() {
super(...arguments)
}

handleClick = () => {
const { onClick } = this.props
_isFunction(onClick) && onClick()
}

render() {
const { children } = this.props
return (
<Button className='at-modal-action__button' onClick={this.handleClick}>
{children}
</Button>
)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'

import ModalButton from './button.js'

import './index.scss'

export default class ModalFooter extends Taro.Component {
constructor() {
super(...arguments)
}

static Button = ModalButton

render() {
const { children } = this.props
return (
<View className='at-modal-header'>{children}</View>
<View className='at-modal-footer'>
<View className='at-modal-footer__action'>{children}</View>
</View>
)
}
}
}
17 changes: 17 additions & 0 deletions src/components/modal/action/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.at-modal-footer {
border-top: 2px solid #e5e5e5;
&__action {
display: flex;
}
}

.at-modal-action__button {
outline: 0;
flex: auto;
border: none;
font-size: 28px;
background-color: white;
&:not(:first-child) {
border-left: 2px solid #e5e5e5;
}
}
File renamed without changes.
File renamed without changes.
Empty file.
24 changes: 7 additions & 17 deletions src/components/modal/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Taro from '@tarojs/taro'
import { View, Button } from '@tarojs/components'
import { View } from '@tarojs/components'

import ModalBody from './body/index'
import ModalHeader from './header/index'
import ModalAction from './action/index'
import ModalContent from './content/index'

import './index.scss'

Expand All @@ -15,8 +16,9 @@ export default class Modal extends Taro.Component {
}
}

static Body = ModalBody
static Content = ModalContent
static Header = ModalHeader
static Action = ModalAction

componentWillReceiveProps(nextProps) {
const { open } = nextProps
Expand Down Expand Up @@ -45,23 +47,11 @@ export default class Modal extends Taro.Component {

render() {
const { open } = this.state
const { children, buttons } = this.props
const { children } = this.props
return open ? (
<View className='at-modal'>
<View className='at-modal__overlay' onClick={this.handleClickOverlay} />
<View className='at-modal__container'>
{children}
<View className='at-modal__container-footer at-footer' />
<View className='at-footer__actions'>
{buttons.map((item, key) => {
return (
<Button key={key} className='at-button'>
{item.name}
</Button>
)
})}
</View>
</View>
<View className='at-modal__container'>{children}</View>
</View>
) : null
}
Expand Down
14 changes: 8 additions & 6 deletions src/pages/action/modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ModalPage extends Taro.Component {
}

handleClick = e => {
const state = Object.assign({}, e.currentTarget.dataset)
const state = Object.assign({ isOpen: true }, e.currentTarget.dataset)
this.setState(state)
}

Expand All @@ -31,18 +31,20 @@ export default class ModalPage extends Taro.Component {
<Text className='example__header-title'>基本案例</Text>
</View>
<View className='example__body'>
<Button data-open={true} onClick={this.handleClick}>
打开Modal
</Button>
<Button onClick={this.handleClick}>打开Modal</Button>
</View>
</View>
<Modal open={open}>
<Modal.Header>
<Text>这是标题知道吧</Text>
</Modal.Header>
<Modal.Body>
<Modal.Content>
<View>这是内容知道吧</View>
</Modal.Body>
</Modal.Content>
<Modal.Action>
<Modal.Action.Button onClick={console.log.bind(this,1)}>取消</Modal.Action.Button>
<Modal.Action.Button>确认</Modal.Action.Button>
</Modal.Action>
</Modal>
</View>
)
Expand Down

0 comments on commit 1380e2a

Please sign in to comment.