|
| 1 | +import React, {PureComponent} from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import {SelectBox} from '@neos-project/react-ui-components'; |
| 4 | +import {connect} from 'react-redux'; |
| 5 | +import {$transform} from 'plow-js'; |
| 6 | +import {selectors} from '@neos-project/neos-ui-redux-store'; |
| 7 | +import * as CkEditorApi from '@neos-project/neos-ui-ckeditor5-bindings'; |
| 8 | + |
| 9 | +@connect($transform({ |
| 10 | + formattingUnderCursor: selectors.UI.ContentCanvas.formattingUnderCursor |
| 11 | +})) |
| 12 | + |
| 13 | +export default class TableStylesSelectBox extends PureComponent { |
| 14 | + static propTypes = { |
| 15 | + presetConfiguration: PropTypes.shape({ |
| 16 | + label: PropTypes.string.isRequired, |
| 17 | + |
| 18 | + options: PropTypes.objectOf(PropTypes.shape({ |
| 19 | + label: PropTypes.string.isRequired, |
| 20 | + cssClass: PropTypes.string.isRequired |
| 21 | + })) |
| 22 | + }), |
| 23 | + formattingUnderCursor: PropTypes.object |
| 24 | + }; |
| 25 | + |
| 26 | + constructor(...args) { |
| 27 | + super(...args); |
| 28 | + this.handleOnSelect = this.handleOnSelect.bind(this); |
| 29 | + } |
| 30 | + |
| 31 | + render() { |
| 32 | + const selectOptions = Object.entries(this.props.presetConfiguration.options) |
| 33 | + .map(([optionIdentifier, optionConfiguration]) => ({ |
| 34 | + value: optionIdentifier, |
| 35 | + label: optionConfiguration.label |
| 36 | + })); |
| 37 | + |
| 38 | + if (selectOptions.length === 0) { |
| 39 | + return null; |
| 40 | + } |
| 41 | + |
| 42 | + const currentValue = this.props.formattingUnderCursor.tableStyles; |
| 43 | + |
| 44 | + return ( |
| 45 | + <SelectBox |
| 46 | + options={selectOptions} |
| 47 | + value={currentValue} |
| 48 | + allowEmpty={true} |
| 49 | + placeholder={this.props.presetConfiguration.label} |
| 50 | + onValueChange={this.handleOnSelect} |
| 51 | + /> |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + handleOnSelect(option) { |
| 56 | + CkEditorApi.executeCommand('tableStyles', {value: option}); |
| 57 | + } |
| 58 | +} |
0 commit comments