-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AtMessage Snap render AtMessage -- props className 1`] = `"<div class=\\"at-message at-message--hidden at-message--info test\\"></div>"`; | ||
exports[`AtMessage Snap render AtMessage -- props customStyle 1`] = `"<div style=\\"color:red;\\" class=\\"at-message at-message--hidden at-message--info\\"></div>"`; | ||
exports[`AtMessage Snap render initial AtMessage 1`] = `"<div class=\\"at-message at-message--hidden at-message--info\\"></div>"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import Taro from '@tarojs/taro' | ||
import PropTypes from 'prop-types' | ||
import { View } from '@tarojs/components' | ||
import classNames from 'classnames' | ||
|
||
import AtComponent from '../../common/component' | ||
import './index.scss' | ||
|
||
export default class AtMessage extends AtComponent { | ||
static defaultProps = { | ||
customStyle: '', | ||
className: '' | ||
} | ||
|
||
static propTypes = { | ||
customStyle: PropTypes.oneOfType([ | ||
PropTypes.object, | ||
PropTypes.string | ||
]), | ||
className: PropTypes.oneOfType([ | ||
PropTypes.array, | ||
PropTypes.string | ||
]), | ||
} | ||
|
||
constructor () { | ||
super(...arguments) | ||
this.state = { | ||
isOpened: false, | ||
message: '', | ||
type: 'info', | ||
duration: 3000, | ||
} | ||
this._timer = null | ||
} | ||
|
||
componentDidMount () { | ||
Taro.eventCenter.on('atMessage', (options = {}) => { | ||
options.isOpened = true | ||
this.setState(options) | ||
clearTimeout(this._timer) | ||
this._timer = setTimeout(() => { | ||
this.setState({ | ||
isOpened: false | ||
}) | ||
}, this.state.duration) | ||
}) | ||
} | ||
|
||
componentWillUnmount () { | ||
Taro.eventCenter.off('atMessage') | ||
} | ||
|
||
render () { | ||
const { | ||
className, | ||
customStyle, | ||
} = this.props | ||
|
||
const { | ||
message, | ||
isOpened, | ||
type, | ||
} = this.state | ||
|
||
return ( | ||
<View | ||
className={ | ||
classNames({ | ||
'at-message': true, | ||
'at-message--show': isOpened, | ||
'at-message--hidden': !isOpened | ||
}, `at-message--${type}`, className)} | ||
style={customStyle} | ||
> | ||
{message} | ||
</View> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@import "../../style/theme/default.scss"; | ||
@import "../../style/mixins/index.scss"; | ||
|
||
.at-message { | ||
position: fixed; | ||
top: 0; | ||
z-index: $zindex-toast; | ||
width: 100%; | ||
font-size: $font-size-base; | ||
padding: $spacing-v-sm $spacing-h-sm; | ||
line-height: $line-height-zh; | ||
text-align: center; | ||
background-color: $color-info; | ||
color: $color-white; | ||
animation: ease both; | ||
opacity: 0; | ||
transform: translate3d(0, -100%, 0); | ||
transition: all 300ms $ease-in-sine; | ||
|
||
&--success { | ||
background-color: $color-success; | ||
} | ||
|
||
&--error { | ||
background-color: $color-error; | ||
} | ||
|
||
&--warning { | ||
background-color: $color-warning; | ||
} | ||
|
||
&--show { | ||
opacity: 1; | ||
transform: translate3d(0, 0, 0); | ||
} | ||
|
||
&--hidden { | ||
opacity: 0; | ||
transform: translate3d(0, -100%, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Nerv from 'nervjs' | ||
import { renderToString } from 'nerv-server' | ||
|
||
import AtMessage from '../../../.temp/components/message/index' | ||
|
||
describe('AtMessage Snap', () => { | ||
it('render initial AtMessage', () => { | ||
const component = renderToString(<AtMessage />) | ||
expect(component).toMatchSnapshot() | ||
}) | ||
|
||
it('render AtMessage -- props className', () => { | ||
const component = renderToString(<AtMessage className='test' />) | ||
expect(component).toMatchSnapshot() | ||
}) | ||
|
||
it('render AtMessage -- props customStyle', () => { | ||
const component = renderToString(<AtMessage customStyle='color:red;' />) | ||
expect(component).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Taro, { Component } from '@tarojs/taro' | ||
import { View } from '@tarojs/components' | ||
|
||
import DocsHeader from '../../components/doc-header' | ||
import AtMessage from '../../../components/message/index' | ||
import AtButton from '../../../components/button/index' | ||
|
||
import './index.scss' | ||
|
||
export default class ToastPage extends Component { | ||
config = { | ||
navigationBarTitleText: 'Taro UI' | ||
} | ||
|
||
handleClick (type) { | ||
Taro.eventCenter.trigger( | ||
'atMessage', | ||
{ | ||
'message': '消息通知', | ||
'type': type, | ||
} | ||
) | ||
} | ||
|
||
render () { | ||
return ( | ||
<View className='page toast-page'> | ||
{/* S Header */} | ||
<DocsHeader title='Message 全局消息' /> | ||
{/* E Header */} | ||
|
||
{/* S Body */} | ||
<View className='doc-body'> | ||
<View className='panel'> | ||
<View className='panel__title'>基本案例</View> | ||
<View className='panel__content'> | ||
<View className='example-item'> | ||
<AtButton onClick={this.handleClick.bind(this)}> | ||
普通消息 | ||
</AtButton> | ||
</View> | ||
<View className='example-item'> | ||
<AtButton onClick={this.handleClick.bind(this, 'success')}> | ||
成功消息 | ||
</AtButton> | ||
</View> | ||
<View className='example-item'> | ||
<AtButton onClick={this.handleClick.bind(this, 'error')}> | ||
错误消息 | ||
</AtButton> | ||
</View> | ||
<View className='example-item'> | ||
<AtButton onClick={this.handleClick.bind(this, 'warning')}> | ||
警告消息 | ||
</AtButton> | ||
</View> | ||
</View> | ||
</View> | ||
</View> | ||
{/* E Body */} | ||
<AtMessage /> | ||
</View> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.toast-page .example__body { | ||
&-button { | ||
display: inline-block; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters