@antv/s2-react-components
Version:
React components for S2
45 lines • 2.1 kB
JavaScript
import { DownOutlined, UpOutlined, VerticalAlignTopOutlined, } from '@ant-design/icons';
import { ADVANCED_SORT_PRE_CLS } from '@antv/s2';
import { Card } from 'antd';
import React from 'react';
export const CustomSort = (props) => {
const { splitOrders = [], setSplitOrders } = props;
const upHandler = (value) => {
const res = splitOrders.concat();
res.splice(res.indexOf(value), 1);
res.unshift(value);
setSplitOrders(res);
};
const downHandler = (value) => {
const res = splitOrders.concat();
let index = res.indexOf(value);
res.splice(res.indexOf(value), 1);
res.splice((index += 1), 0, value);
setSplitOrders(res);
};
const toTopHandler = (value) => {
const res = splitOrders.concat();
let index = res.indexOf(value);
if (index > 0) {
res.splice(res.indexOf(value), 1);
res.splice((index -= 1), 0, value);
setSplitOrders(res);
}
};
const renderItem = (value) => (React.createElement(React.Fragment, null,
React.createElement("span", { className: "split-text" }, value),
React.createElement("span", { className: `${ADVANCED_SORT_PRE_CLS}-split-icon`, onClick: () => {
upHandler(value);
} },
React.createElement(VerticalAlignTopOutlined, null)),
React.createElement("span", { className: `${ADVANCED_SORT_PRE_CLS}-split-icon`, onClick: () => {
downHandler(value);
} },
React.createElement(DownOutlined, null)),
React.createElement("span", { className: `${ADVANCED_SORT_PRE_CLS}-split-icon`, onClick: () => {
toTopHandler(value);
} },
React.createElement(UpOutlined, null))));
return (React.createElement(Card, { className: `${ADVANCED_SORT_PRE_CLS}-card-content` }, splitOrders.map((value) => (React.createElement("li", { key: value, className: `${ADVANCED_SORT_PRE_CLS}-split-value`, title: value }, renderItem(value))))));
};
//# sourceMappingURL=custom-sort.js.map