UNPKG

2.86 kBJSXView Raw
1/**
2 * Style for ApText.
3 * @class ApTextStyle
4 */
5
6'use strict'
7
8import React, {Component, PropTypes as types} from 'react'
9import {ApStyle} from 'apeman-react-style'
10import {alpha} from 'acolor'
11
12/** @lends ApTextStyle */
13class ApTextStyle extends Component {
14 render () {
15 const s = this
16 let { props } = s
17
18 let { all, small, medium, large } = ApTextStyle.styleData(props)
19
20 return (
21 <ApStyle data={ Object.assign(all, props.style) }
22 smallMediaData={ small }
23 mediumMediaData={ medium }
24 largeMediaData={ large }
25 >{ props.children }</ApStyle>
26 )
27 }
28}
29
30Object.assign(ApTextStyle, {
31 propTypes: {
32 style: types.object,
33 highlightColor: types.string,
34 maxWidth: types.number
35 },
36
37 defaultProps: {
38 style: {},
39 maxWidth: ApStyle.CONTENT_WIDTH,
40 highlightColor: ApStyle.DEFAULT_HIGHLIGHT_COLOR
41 },
42
43 styleData (config) {
44 let { highlightColor, maxWidth } = config
45 return {
46 all: {
47 '.ap-text': {
48 display: 'block',
49 padding: '4px 8px',
50 border: '1px solid #AAA',
51 width: '100%',
52 maxWidth: `${maxWidth}px`,
53 borderRadius: '2px',
54 boxSizing: 'border-box',
55 outlineColor: `${highlightColor}`,
56 boxShadow: '1px 1px 1px rgba(0,0,0,.05) inset'
57 },
58 '.ap-text-wrap': {
59 position: 'relative',
60 width: '100%',
61 margin: '4px',
62 verticalAlign: 'middle',
63 boxSizing: 'border-box',
64 maxWidth: `${maxWidth}px`,
65 display: 'block'
66 },
67 '.ap-text-multiple': {
68 overflow: 'auto'
69 },
70 '.ap-text-candidate-list': {
71 position: 'absolute',
72 left: 0,
73 right: '1px',
74 top: '100%',
75 zIndex: 4,
76 padding: '4px 0',
77 margin: '0 1px',
78 boxShadow: '1px 1px 2px rgba(0,0,0,0.33)',
79 background: 'white',
80 boxSizing: 'border-box'
81 },
82 '.ap-text-candidate-list-item': {
83 display: 'block',
84 padding: 0,
85 margin: 0
86 },
87 '.ap-text-candidate-list-item a': {
88 display: 'block',
89 padding: '4px 8px'
90 },
91 '.ap-text-candidate-list-item a:hover': {
92 cursor: 'pointer',
93 background: '#FAFAFA'
94 },
95 '.ap-text-candidate-list-item a:active': {
96 background: '#F5F5F5'
97 },
98 '.ap-text-candidate-list-item-selected a': {
99 background: alpha(highlightColor, 0.33)
100 },
101 '.ap-text-candidate-list-item-selected a:hover': {
102 background: alpha(highlightColor, 0.5)
103 },
104 '.ap-text-candidate-list-item-selected a:active': {
105 background: alpha(highlightColor, 0.2)
106 }
107 }
108 }
109 }
110
111})
112export default ApTextStyle