-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathSelectFeaturesButton.tsx
62 lines (52 loc) · 1.32 KB
/
SelectFeaturesButton.tsx
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
55
56
57
58
59
60
61
62
import * as React from 'react';
import {
useSelectFeatures,
UseSelectFeaturesProps
} from '@terrestris/react-util/dist/Hooks/useSelectFeatures/useSelectFeatures';
import { CSS_PREFIX } from '../../constants';
import ToggleButton, { ToggleButtonProps } from '../ToggleButton/ToggleButton';
interface OwnProps {
/**
* The className which should be added.
*/
className?: string;
}
export type SelectFeaturesButtonProps = OwnProps & Omit<UseSelectFeaturesProps, 'active'> & Partial<ToggleButtonProps>;
/**
* The className added to this component.
*/
const defaultClassName = `${CSS_PREFIX}selectbutton`;
const SelectFeaturesButton: React.FC<SelectFeaturesButtonProps> = ({
selectStyle,
selectInteractionConfig,
className,
onFeatureSelect,
hitTolerance = 5,
layers,
clearAfterSelect = false,
featuresCollection,
pressed,
...passThroughProps
}) => {
useSelectFeatures({
active: !!pressed,
onFeatureSelect,
clearAfterSelect,
featuresCollection,
hitTolerance,
layers,
selectStyle,
selectInteractionConfig
});
const finalClassName = className
? `${defaultClassName} ${className}`
: defaultClassName;
return (
<ToggleButton
className={finalClassName}
pressed={pressed}
{...passThroughProps}
/>
);
};
export default SelectFeaturesButton;