-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 updating
- Loading branch information
Showing
8 changed files
with
195 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
cvat-ui/src/components/annotation-page/standard-workspace/objects-side-bar/color-changer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.