Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 1x 6x 6x 6x 3x 3x 9x 9x 6x 6x 6x 9x 9x 9x 9x | // @flow
import * as React from 'react';
import type {IconProps} from 'shared/src/types';
import {haveDataKeyEqualValueInSomeBlocks} from '@canner/slate-util-have';
import blockAddData from '@canner/slate-helper-block-adddata';
import blockClearDataByKey from '@canner/slate-helper-block-cleardatabykey';
type Props = IconProps;
export const applyChange = (change, type, align) => {
const isActive = haveDataKeyEqualValueInSomeBlocks(change, type, align);
Iif (isActive)
return change.call(blockClearDataByKey, type);
return change.call(blockAddData, {data: {[type]: align}});
}
export default (type: string, defaultIcon: string, align: string) =>
(Block: React.Element<any>) => {
return class AlignDecorator extends React.Component<Props> {
typeName: string
constructor(props: Props) {
super(props);
this.typeName = props.type || type;
}
onClick = (e: Event) => {
e.preventDefault();
let {change, onChange} = this.props;
onChange(applyChange(change, this.typeName, align));
}
render() {
const {change, icon, ...rest} = this.props;
const onClick = e => this.onClick(e);
const isActive = haveDataKeyEqualValueInSomeBlocks(change, type, align);
return (
// $FlowFixMe
<Block
type={this.typeName}
icon={icon || defaultIcon}
onClick={onClick}
isActive={isActive}
{...rest}
/>
);
}
};
};
|