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";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { ComponentProps } from "components/designSystems/appsmith/BaseComponent";
|
|
|
|
|
import { RadioOption } from "widgets/RadioGroupWidget";
|
2020-01-21 12:48:42 +00:00
|
|
|
import {
|
|
|
|
|
RadioGroup,
|
|
|
|
|
Radio,
|
|
|
|
|
ControlGroup,
|
|
|
|
|
Label,
|
|
|
|
|
Classes,
|
|
|
|
|
} from "@blueprintjs/core";
|
|
|
|
|
import { WIDGET_PADDING } from "constants/WidgetConstants";
|
2020-01-28 08:21:22 +00:00
|
|
|
import { labelStyle } from "constants/DefaultTheme";
|
|
|
|
|
|
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%;
|
|
|
|
|
align-self: flex-start;
|
|
|
|
|
text-align: right;
|
2020-01-28 08:21:22 +00:00
|
|
|
margin: 0 ${WIDGET_PADDING * 2}px 0 0;
|
2020-01-21 12:48:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledRadioGroup = styled(RadioGroup)``;
|
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 && (
|
|
|
|
|
<Label className={Classes.TEXT_OVERFLOW_ELLIPSIS}>
|
|
|
|
|
{this.props.label}
|
|
|
|
|
</Label>
|
|
|
|
|
)}
|
2020-01-21 12:48:42 +00:00
|
|
|
<StyledRadioGroup
|
|
|
|
|
selectedValue={this.props.selectedOptionValue}
|
|
|
|
|
onChange={this.onRadioSelectionChange}
|
|
|
|
|
>
|
|
|
|
|
{this.props.options.map(option => {
|
|
|
|
|
return (
|
|
|
|
|
<Radio
|
|
|
|
|
className={this.props.isLoading ? "bp3-skeleton" : ""}
|
|
|
|
|
label={option.label}
|
|
|
|
|
value={option.value}
|
|
|
|
|
key={option.id}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</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;
|