1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
8 |
|
9 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
10 |
|
11 | var _react = require('react');
|
12 |
|
13 | var React = _interopRequireWildcard(_react);
|
14 |
|
15 | var _ButtonGroup = require('./ui/ButtonGroup');
|
16 |
|
17 | var _ButtonGroup2 = _interopRequireDefault(_ButtonGroup);
|
18 |
|
19 | var _IconButton = require('./ui/IconButton');
|
20 |
|
21 | var _IconButton2 = _interopRequireDefault(_IconButton);
|
22 |
|
23 | var _Dropdown = require('./ui/Dropdown');
|
24 |
|
25 | var _Dropdown2 = _interopRequireDefault(_Dropdown);
|
26 |
|
27 | var _FontFamilyDropdown = require('./ui/FontFamilyDropdown');
|
28 |
|
29 | var _FontFamilyDropdown2 = _interopRequireDefault(_FontFamilyDropdown);
|
30 |
|
31 | var _Palette = require('./Palette');
|
32 |
|
33 | var _Palette2 = _interopRequireDefault(_Palette);
|
34 |
|
35 | var _config = require('./config');
|
36 |
|
37 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
38 |
|
39 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
40 |
|
41 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
42 |
|
43 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
44 |
|
45 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
46 |
|
47 | var ReactFontStyle = function (_React$Component) {
|
48 | _inherits(ReactFontStyle, _React$Component);
|
49 |
|
50 | function ReactFontStyle(props) {
|
51 | _classCallCheck(this, ReactFontStyle);
|
52 |
|
53 | var _this = _possibleConstructorReturn(this, (ReactFontStyle.__proto__ || Object.getPrototypeOf(ReactFontStyle)).call(this, props));
|
54 |
|
55 | _this.togglePalette = function (show) {
|
56 | var showPalette = _this.state.showPalette;
|
57 |
|
58 | var newShowPalette = void 0;
|
59 | if (show === showPalette) {
|
60 | newShowPalette = false;
|
61 | } else {
|
62 | newShowPalette = show;
|
63 | }
|
64 | _this.setState({ showPalette: newShowPalette });
|
65 | };
|
66 |
|
67 | _this.handleInlineStyleChange = function (type) {
|
68 | var activeInlineStyle = _this.state.activeInlineStyle;
|
69 |
|
70 | activeInlineStyle[type] = !activeInlineStyle[type];
|
71 | _this.onChange(activeInlineStyle);
|
72 | };
|
73 |
|
74 | _this.handleChangeFontSize = function (label) {
|
75 | _this.onChange({ activeFontSize: label });
|
76 | };
|
77 |
|
78 | _this.handleChangeFontFamily = function (label) {
|
79 | _this.onChange({ activeFontFamily: label });
|
80 | };
|
81 |
|
82 | _this.handleLineHeight = function (label) {
|
83 | _this.onChange({ activeLineHeight: label });
|
84 | };
|
85 |
|
86 | _this.handleAlign = function (label) {
|
87 | _this.onChange({ activeAlign: label });
|
88 | };
|
89 |
|
90 | _this.handleColorChange = function (color) {
|
91 | var showPalette = _this.state.showPalette;
|
92 | var hex = color.hex;
|
93 |
|
94 | if (showPalette === 'font') {
|
95 | _this.onChange({ activeColor: hex });
|
96 | } else if (showPalette === 'highlight') {
|
97 | _this.onChange({ activeBackgroundColor: hex });
|
98 | }
|
99 | };
|
100 |
|
101 | _this.onChange = function (updated) {
|
102 | var newState = _extends({}, _this.state, updated);
|
103 | var fontStyle = (0, _config.stateToStyle)(newState);
|
104 | _this.setState(_extends({}, newState, { fontStyle: fontStyle }));
|
105 | if (_this.props.onChange) {
|
106 | _this.props.onChange(fontStyle);
|
107 | }
|
108 | };
|
109 |
|
110 | var config = (0, _config.generateConfig)(props.customConfig);
|
111 | var state = (0, _config.generateConfigState)(config, props.defaultStyle);
|
112 | _this.state = _extends({}, state, {
|
113 | showPalette: false,
|
114 | config: config,
|
115 | fontStyle: (0, _config.stateToStyle)(_extends({}, state, { config: config }))
|
116 | });
|
117 | return _this;
|
118 | }
|
119 |
|
120 | _createClass(ReactFontStyle, [{
|
121 | key: 'render',
|
122 | value: function render() {
|
123 | var _this2 = this;
|
124 |
|
125 | var _state = this.state,
|
126 | activeInlineStyle = _state.activeInlineStyle,
|
127 | activeFontSize = _state.activeFontSize,
|
128 | activeColor = _state.activeColor,
|
129 | activeBackgroundColor = _state.activeBackgroundColor,
|
130 | activeLineHeight = _state.activeLineHeight,
|
131 | activeAlign = _state.activeAlign,
|
132 | activeFontFamily = _state.activeFontFamily,
|
133 | showPalette = _state.showPalette,
|
134 | config = _state.config,
|
135 | fontStyle = _state.fontStyle;
|
136 | var _props = this.props,
|
137 | text = _props.text,
|
138 | customizedPlugin = _props.customizedPlugin,
|
139 | textComponent = _props.textComponent;
|
140 |
|
141 | return React.createElement(
|
142 | 'div',
|
143 | null,
|
144 | config.display.includes('INLINE_STYLE_BUTTONS') ? React.createElement(
|
145 | _ButtonGroup2.default,
|
146 | null,
|
147 | config.INLINE_STYLE_BUTTONS.map(function (item) {
|
148 | return React.createElement(_IconButton2.default, { key: item.type,
|
149 | iconName: item.type,
|
150 | isActive: activeInlineStyle[item.type],
|
151 | onMouseDown: function onMouseDown() {
|
152 | return _this2.handleInlineStyleChange(item.type);
|
153 | } });
|
154 | })
|
155 | ) : null,
|
156 | config.display.includes('FONT_COLOR_BUTTON') || config.display.includes('FONT_HIGHLIGHT_BUTTON') ? React.createElement(
|
157 | _ButtonGroup2.default,
|
158 | null,
|
159 | config.display.includes('FONT_HIGHLIGHT_BUTTON') ? React.createElement(_IconButton2.default, { iconName: 'mark',
|
160 | onMouseDown: function onMouseDown() {
|
161 | return _this2.togglePalette('highlight');
|
162 | },
|
163 | isActive: showPalette === 'highlight' }) : null,
|
164 | config.display.includes('FONT_COLOR_BUTTON') ? React.createElement(_IconButton2.default, { iconName: 'color',
|
165 | onMouseDown: function onMouseDown() {
|
166 | return _this2.togglePalette('font');
|
167 | },
|
168 | isActive: showPalette === 'font' }) : null
|
169 | ) : null,
|
170 | config.display.includes('FONT_SIZE_DROPDOWN') ? React.createElement(_Dropdown2.default, { choices: config.FONT_SIZE_DROPDOWN,
|
171 | selectedKey: activeFontSize,
|
172 | onChange: this.handleChangeFontSize,
|
173 | icon: 'font'
|
174 | }) : null,
|
175 | config.display.includes('FONT_FAMILY_DROPDOWN') ? React.createElement(_FontFamilyDropdown2.default, { choices: config.FONT_FAMILY_DROPDOWN,
|
176 | selectedKey: activeFontFamily,
|
177 | onChange: this.handleChangeFontFamily,
|
178 | icon: 'font'
|
179 | }) : null,
|
180 | config.display.includes('LINE_HEIGHT_DROPDOWN') ? React.createElement(_Dropdown2.default, { choices: config.LINE_HEIGHT_DROPDOWN,
|
181 | selectedKey: activeLineHeight,
|
182 | icon: 'lineheight',
|
183 | onChange: this.handleLineHeight
|
184 | }) : null,
|
185 | config.display.includes('ALIGN_DROPDOWN') ? React.createElement(_Dropdown2.default, { choices: config.ALIGN_DROPDOWN,
|
186 | selectedKey: activeAlign,
|
187 | icon: activeAlign === 'Align Left' ? 'align-left' : activeAlign === 'Align Center' ? 'align-center' : 'align-right',
|
188 | onChange: this.handleAlign
|
189 | }) : null,
|
190 | customizedPlugin ? customizedPlugin : null,
|
191 | showPalette ? React.createElement(_Palette2.default, { color: showPalette === 'font' ? activeColor : activeBackgroundColor,
|
192 | onChange: this.handleColorChange }) : null,
|
193 | textComponent ? textComponent : React.createElement(
|
194 | 'div',
|
195 | { style: { padding: '20px 10px', backgroundColor: '#eee' } },
|
196 | React.createElement(
|
197 | 'div',
|
198 | { style: fontStyle },
|
199 | text
|
200 | )
|
201 | )
|
202 | );
|
203 | }
|
204 | }]);
|
205 |
|
206 | return ReactFontStyle;
|
207 | }(React.Component);
|
208 |
|
209 | ReactFontStyle.defaultProps = {
|
210 | defaultStyle: {},
|
211 | text: 'ABCD'
|
212 | };
|
213 | exports.default = ReactFontStyle;
|
214 | module.exports = exports['default']; |
\ | No newline at end of file |