|
1 | | -import type { CSSProperties, JSX, ReactNode, SVGAttributes } from 'react'; |
2 | 1 | import { useMemo } from 'react'; |
3 | 2 |
|
4 | 3 | import { useRois } from '../hooks/useRois.js'; |
5 | 4 | import { useRoiState } from '../index.js'; |
6 | | -import type { Roi } from '../types/Roi.js'; |
| 5 | +import type { |
| 6 | + GetOverlayOpacity, |
| 7 | + GetReadOnlyCallback, |
| 8 | + GetStyleCallback, |
| 9 | + RenderLabelCallback, |
| 10 | +} from '../types/RoiList.ts'; |
7 | 11 | import { assert } from '../utilities/assert.js'; |
8 | 12 |
|
9 | 13 | import { RoiBox } from './box/RoiBox.js'; |
10 | 14 | import { defaultGridLineOpacity, defaultHandlerColor } from './constants.js'; |
11 | 15 | import { LabelContainer } from './label/LabelContainer.js'; |
12 | 16 |
|
13 | | -export interface RoiAdditionalCallbackState { |
14 | | - isSelected: boolean; |
15 | | - isReadOnly: boolean; |
16 | | - zoomScale: number; |
17 | | -} |
18 | | - |
19 | | -export interface CustomRoiStyle { |
20 | | - /** |
21 | | - * The attributes to forward to the SVG rect element which draws the ROI |
22 | | - */ |
23 | | - rectAttributes?: SVGAttributes<SVGRectElement>; |
24 | | - resizeHandlerColor?: CSSProperties['color']; |
25 | | - gridLineOpacity?: CSSProperties['opacity']; |
26 | | - /** |
27 | | - * This property allows to render custom markup inside the ROI SVG |
28 | | - * This can be used for example to render an svg pattern that can then be used as a fill in `rectAttributes` |
29 | | - * It is not meant to be used to render markup that will be displayed on screen, see `rectAttributes` to customize the ROI appearance |
30 | | - */ |
31 | | - renderCustomPattern?: () => JSX.Element; |
32 | | -} |
33 | | - |
34 | | -export type GetStyleCallback<TData = unknown> = ( |
35 | | - roi: Roi<TData>, |
36 | | - roiAdditionalState: RoiAdditionalCallbackState, |
37 | | -) => CustomRoiStyle; |
38 | | - |
39 | | -export type GetReadOnlyCallback<TData = unknown> = (roi: Roi<TData>) => boolean; |
40 | | -export type GetOverlayOpacity<TData = unknown> = ( |
41 | | - roi: Roi<TData>, |
42 | | - roiAdditionalState: RoiAdditionalCallbackState, |
43 | | -) => number; |
44 | | -export type RenderLabelCallback<TData = unknown> = ( |
45 | | - roi: Roi<TData>, |
46 | | - roiAdditionalState: RoiAdditionalCallbackState, |
47 | | -) => ReactNode; |
48 | | - |
49 | 17 | export interface RoiListProps<TData = unknown> { |
50 | 18 | getStyle?: GetStyleCallback<TData>; |
51 | 19 | getReadOnly?: GetReadOnlyCallback<TData>; |
@@ -132,12 +100,12 @@ export function RoiList<TData = unknown>(props: RoiListProps<TData>) { |
132 | 100 | ); |
133 | 101 | } |
134 | 102 |
|
135 | | -const defaultGetStyle: GetStyleCallback = (roi, state) => { |
| 103 | +const defaultGetStyle: GetStyleCallback = ({ isReadOnly, isSelected }) => { |
136 | 104 | return { |
137 | 105 | rectAttributes: { |
138 | | - fill: state.isReadOnly |
| 106 | + fill: isReadOnly |
139 | 107 | ? 'rgba(0,0,0,0.6)' |
140 | | - : state.isSelected |
| 108 | + : isSelected |
141 | 109 | ? 'rgba(0,0,0,0.2)' |
142 | 110 | : 'rgba(0,0,0,0.4)', |
143 | 111 | }, |
|
0 commit comments