Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
feat: add ActionSheet
Browse files Browse the repository at this point in the history
  • Loading branch information
psaren committed May 12, 2020
1 parent c545f89 commit 4a83749
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 14 deletions.
15 changes: 15 additions & 0 deletions src/components/action-sheet/body/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import classNames from 'classnames'

export default {
name: 'ActionSheetBody',
props: {
className: {
type: [Array, String],
default: () => '',
},
},
render() {
const rootClass = classNames('at-action-sheet__body', this.className)
return <view className={rootClass}>{this.$slots.default}</view>
},
}
29 changes: 29 additions & 0 deletions src/components/action-sheet/body/item/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import classNames from 'classnames'

export default {
name: 'ActionSheetItem',
props: {
className: {
type: [Array, String],
default: () => '',
},
onClick: {
type: Function,
default: () => () => {},
},
},
methods: {
handleClick(e) {
this.onClick && this.onClick(e)
},
},
render() {
const rootClass = classNames('at-action-sheet__item', this.className)

return (
<view className={rootClass} onTap={this.handleClick}>
{this.slots.default}
</view>
)
},
}
29 changes: 29 additions & 0 deletions src/components/action-sheet/footer/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import classNames from 'classnames'

export default {
name: 'ActionSheetFooter',
props: {
className: {
type: [Array, String],
default: () => '',
},
onClick: {
type: Function,
default: () => () => {},
},
},
methds: {
handleClick(e) {
this.onClick && this.onClick(e)
},
},
render() {
const rootClass = classNames('at-action-sheet__footer', this.className)

return (
<view onTap={this.handleClick} className={rootClass}>
{this.$slots.default}
</view>
)
},
}
16 changes: 16 additions & 0 deletions src/components/action-sheet/header/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import classNames from 'classnames'

export default {
name: 'ActionSheetHeader',
props: {
className: {
type: [Array, String],
default: () => '',
},
},
render() {
const rootClass = classNames('at-action-sheet__header', this.className)

return <view className={rootClass}>{this.$slots.default}</view>
},
}
86 changes: 86 additions & 0 deletions src/components/action-sheet/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import classNames from 'classnames'
import ActionSheetBody from './body/index'
import ActionSheetFooter from './footer/index'
import ActionSheetHeader from './header/index'

export default {
name: 'ActionSheet',
props: {
title: {
type: String,
default: '',
},
cancelText: {
type: String,
default: '',
},
isOpened: {
type: Boolean,
default: false,
},
onClose: {
type: Function,
default: () => () => {},
},
onCancel: {
type: Function,
default: () => () => {},
},
},
data() {
return {
show: this.isOpened,
}
},
watch: {
isOpened(val) {
this.show = val
!val && this.handleClose()
},
},
methods: {
handleClose() {
if (typeof this.onClose === 'function') {
this.onClose()
}
},
handleCancel() {
if (typeof this.onCancel === 'function') {
return this.onCancel()
}
this.close()
},
close() {
this.show = false
},
handleTouchMove(e) {
e.stopPropagation()
e.preventDefault()
},
},
render() {
const { title, cancelText, className } = this
const { show } = this

const rootClass = classNames(
'at-action-sheet',
{
'at-action-sheet--active': show,
},
className
)

return (
<view className={rootClass} onTouchMove={this.handleTouchMove}>
<view onTap={this.close} className="at-action-sheet__overlay" />
<view className="at-action-sheet__container">
{title && <ActionSheetHeader>{title}</ActionSheetHeader>}
<ActionSheetBody>{this.$slots.default}</ActionSheetBody>
{cancelText && (
<ActionSheetFooter onTap={this.handleCancel}>{cancelText}</ActionSheetFooter>
)}
</view>
</view>
)
},
}
5 changes: 3 additions & 2 deletions src/components/button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ export default {
let loadingComponent = null
if (loading) {
loadingComponent = (
<View className="at-button__icon">
<view className="at-button__icon">
<Loading color={loadingColor} size={loadingSize} />
</View>
</view>
)
rootClassName.push('at-button--icon')
}
Expand Down Expand Up @@ -248,6 +248,7 @@ export default {
<Loading color={loadingColor} size={loadingSize} />
</view>
)}
{loadingComponent}
<view class="at-button__text">{this.$slots.default}</view>
</view>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/countdown/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames'
import CountdownItem from './item'
import CountdownItem from './item/index'

/**
*
Expand Down
22 changes: 11 additions & 11 deletions src/components/countdown/item/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* @param {number} num
*
* @param {number} num
*/
const formatNum = (num) => {
return num <= 9 ? `0${num}` : `${num}`
Expand All @@ -11,22 +11,22 @@ export default {
props: {
num: {
type: Number,
default: 0
default: 0,
},
separator: {
type: String,
default: ''
}
default: '',
},
},
render() {
const { num, separator } = this
return (
<view class='at-countdown__item'>
<view class='at-countdown__time-box'>
<text class='at-countdown__time'>{formatNum(num)}</text>
<view class="at-countdown__item">
<view class="at-countdown__time-box">
<text class="at-countdown__time">{formatNum(num)}</text>
</view>
<text class='at-countdown__separator'>{separator}</text>
<text class="at-countdown__separator">{separator}</text>
</view>
)
}
}
},
}

0 comments on commit 4a83749

Please sign in to comment.