2019-11-05 05:09:50 +00:00
|
|
|
import React from "react";
|
2020-01-21 12:48:42 +00:00
|
|
|
import styled from "styled-components";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { ComponentProps } from "widgets/BaseComponent";
|
|
|
|
|
import { RadioOption } from "../constants";
|
2020-01-21 12:48:42 +00:00
|
|
|
import {
|
|
|
|
|
RadioGroup,
|
|
|
|
|
Radio,
|
|
|
|
|
ControlGroup,
|
|
|
|
|
Label,
|
|
|
|
|
Classes,
|
|
|
|
|
} from "@blueprintjs/core";
|
|
|
|
|
import { WIDGET_PADDING } from "constants/WidgetConstants";
|
2020-02-06 07:01:25 +00:00
|
|
|
import { BlueprintControlTransform, labelStyle } from "constants/DefaultTheme";
|
2021-11-11 17:41:43 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
2020-01-28 08:21:22 +00:00
|
|
|
|
2020-01-21 12:48:42 +00:00
|
|
|
const StyledControlGroup = styled(ControlGroup)`
|
|
|
|
|
&&& {
|
|
|
|
|
& > label {
|
2020-01-28 08:21:22 +00:00
|
|
|
${labelStyle}
|
2020-01-21 12:48:42 +00:00
|
|
|
flex: 0 1 30%;
|
2020-03-13 07:24:03 +00:00
|
|
|
margin: 7px ${WIDGET_PADDING * 2}px 0 0;
|
2020-01-21 12:48:42 +00:00
|
|
|
text-align: right;
|
2020-03-13 07:24:03 +00:00
|
|
|
align-self: flex-start;
|
|
|
|
|
max-width: calc(30% - ${WIDGET_PADDING}px);
|
2020-01-21 12:48:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2020-02-06 07:01:25 +00:00
|
|
|
const StyledRadioGroup = styled(RadioGroup)`
|
|
|
|
|
${BlueprintControlTransform};
|
2021-11-11 17:41:43 +00:00
|
|
|
.${Classes.CONTROL} {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
min-height: 36px;
|
|
|
|
|
margin: 0px 12px;
|
|
|
|
|
color: ${Colors.GREY_10};
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
& input:not(:checked) ~ .bp3-control-indicator {
|
|
|
|
|
border: 1px solid ${Colors.GREY_5} !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
& .bp3-control-indicator {
|
|
|
|
|
border: 1px solid ${Colors.GREY_3};
|
|
|
|
|
}
|
2020-03-13 07:24:03 +00:00
|
|
|
}
|
2020-02-06 07:01:25 +00:00
|
|
|
`;
|
2019-11-13 10:35:35 +00:00
|
|
|
|
2019-11-05 05:09:50 +00:00
|
|
|
class RadioGroupComponent extends React.Component<RadioGroupComponentProps> {
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
2020-01-21 12:48:42 +00:00
|
|
|
<StyledControlGroup fill>
|
2020-01-28 11:46:04 +00:00
|
|
|
{this.props.label && (
|
2020-01-31 11:13:16 +00:00
|
|
|
<Label
|
|
|
|
|
className={
|
|
|
|
|
this.props.isLoading
|
|
|
|
|
? Classes.SKELETON
|
|
|
|
|
: Classes.TEXT_OVERFLOW_ELLIPSIS
|
|
|
|
|
}
|
|
|
|
|
>
|
2020-01-28 11:46:04 +00:00
|
|
|
{this.props.label}
|
|
|
|
|
</Label>
|
|
|
|
|
)}
|
2020-01-21 12:48:42 +00:00
|
|
|
<StyledRadioGroup
|
2020-08-07 13:17:15 +00:00
|
|
|
disabled={this.props.isDisabled}
|
2021-04-28 10:28:39 +00:00
|
|
|
onChange={this.onRadioSelectionChange}
|
|
|
|
|
selectedValue={this.props.selectedOptionValue}
|
2020-01-21 12:48:42 +00:00
|
|
|
>
|
2021-10-20 12:15:54 +00:00
|
|
|
{this.props.options.map((option, optInd) => {
|
2020-01-21 12:48:42 +00:00
|
|
|
return (
|
|
|
|
|
<Radio
|
|
|
|
|
className={this.props.isLoading ? "bp3-skeleton" : ""}
|
2021-10-20 12:15:54 +00:00
|
|
|
key={optInd}
|
2020-01-21 12:48:42 +00:00
|
|
|
label={option.label}
|
|
|
|
|
value={option.value}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</StyledRadioGroup>
|
|
|
|
|
</StyledControlGroup>
|
2019-11-05 05:09:50 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onRadioSelectionChange = (event: React.FormEvent<HTMLInputElement>) => {
|
|
|
|
|
this.props.onRadioSelectionChange(event.currentTarget.value);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RadioGroupComponentProps extends ComponentProps {
|
|
|
|
|
label: string;
|
|
|
|
|
options: RadioOption[];
|
|
|
|
|
onRadioSelectionChange: (updatedOptionValue: string) => void;
|
|
|
|
|
selectedOptionValue: string;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2019-11-05 05:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default RadioGroupComponent;
|