UNPKG

3.12 kBJSXView Raw
1/**
2 * Style for ApToast.
3 * @class ApToastStyle
4 */
5
6'use strict'
7
8import React, {PropTypes as types} from 'react'
9import classnames from 'classnames'
10import {ApStyle} from 'apeman-react-style'
11
12/** @lends ApToastStyle */
13const ApToastStyle = React.createClass({
14 propTypes: {
15 style: types.object,
16 normalColor: types.string,
17 infoColor: types.string,
18 warnColor: types.string,
19 errorColor: types.string
20 },
21 getDefaultProps () {
22 return {
23 style: {},
24 normalColor: ApStyle.NORMAL_COLOR,
25 infoColor: ApStyle.INFO_COLOR,
26 warnColor: ApStyle.WARN_COLOR,
27 errorColor: ApStyle.ERROR_COLOR
28 }
29 },
30 statics: {
31 styleData (config) {
32
33 let {
34 normalColor,
35 infoColor,
36 warnColor,
37 errorColor
38 } = config
39 return {
40 all: {
41 '.ap-toast-group': {
42 position: 'fixed',
43 height: 0,
44 top: 'initial',
45 overflow: 'visible',
46 left: 0,
47 bottom: 24,
48 right: 0,
49 textAlign: 'center',
50 padding: 0,
51 zIndex: 49,
52 display: 'flex',
53 flexDirection: `column`,
54 justifyContent: `flex-end`
55 },
56 '.ap-toast': {
57 display: 'block',
58 margin: `0 auto`
59 },
60 '.ap-toast-inner': {
61 margin: `4px auto`,
62 maxWidth: `420px`,
63 display: 'inline-block',
64 textAlign: 'left',
65 padding: `4px`,
66 boxShadow: `2px 2px 4px rgba(0,0,0,0.33)`,
67 backgroundColor: `rgba(255, 255, 255, 0.95)`,
68 color: `${normalColor}`,
69 border: `4px solid ${normalColor}`,
70 fontSize: `14px`,
71 width: `240px`,
72 borderRadius: `2px`
73 },
74 '.ap-toast-item': {
75 display: 'block',
76 padding: `2px 0`
77 },
78 '.ap-toast-item:active': {
79 opacity: 0.8
80 },
81 '.ap-info-toast .ap-toast-inner': {
82 color: `${infoColor}`,
83 borderColor: `${infoColor}`
84 },
85 '.ap-warn-toast .ap-toast-inner': {
86 color: `${warnColor}`,
87 borderColor: `${warnColor}`
88 },
89 '.ap-error-toast .ap-toast-inner': {
90 color: `${errorColor}`,
91 borderColor: `${errorColor}`
92 },
93 '.ap-toast-item-icon': {
94 display: 'inline-block',
95 pointerEvents: 'none'
96 },
97 '.ap-toast-text': {
98 display: 'inline-block',
99 pointerEvents: 'none',
100 margin: '0 2px',
101 cursor: 'default'
102 }
103 }
104 }
105 }
106 },
107 render () {
108 const s = this
109 let { props } = s
110
111 let { all, small, medium, large } = ApToastStyle.styleData(props)
112
113 return (
114 <ApStyle data={ Object.assign(all, props.style) }
115 smallMediaData={ small }
116 mediumMediaData={ medium }
117 largeMediaData={ large }
118 >{ props.children }</ApStyle>
119 )
120 }
121})
122
123export default ApToastStyle