React UI: Changing color for a shape (#1194)
* Minimized size of an element in side panel * To background / to foreground like in legacy UI * Added color changer for a shape * Adjusted color updatingmain
parent
93d57131c3
commit
90d594d706
@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
|
||||
import {
|
||||
Row,
|
||||
Col,
|
||||
Button,
|
||||
} from 'antd';
|
||||
|
||||
interface Props {
|
||||
colors: string[];
|
||||
onChange(color: string): void;
|
||||
}
|
||||
|
||||
function ColorChanger(props: Props): JSX.Element {
|
||||
const {
|
||||
colors,
|
||||
onChange,
|
||||
} = props;
|
||||
|
||||
const cols = 6;
|
||||
const rows = Math.ceil(colors.length / cols);
|
||||
|
||||
const antdRows = [];
|
||||
for (let row = 0; row < rows; row++) {
|
||||
const antdCols = [];
|
||||
for (let col = 0; col < cols; col++) {
|
||||
const idx = row * cols + col;
|
||||
if (idx >= colors.length) {
|
||||
break;
|
||||
}
|
||||
const color = colors[idx];
|
||||
antdCols.push(
|
||||
<Col key={col} span={4}>
|
||||
<Button
|
||||
onClick={(): void => onChange(color)}
|
||||
style={{ background: color }}
|
||||
className='cvat-label-item-color-button'
|
||||
/>
|
||||
</Col>,
|
||||
);
|
||||
}
|
||||
|
||||
antdRows.push(
|
||||
// eslint-disable-next-line react/no-children-prop
|
||||
<Row key={row} children={antdCols} />,
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{antdRows}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(ColorChanger);
|
||||
Loading…
Reference in New Issue