2021-10-21 05:36:17 +00:00
|
|
|
import React from "react";
|
2022-08-22 05:09:39 +00:00
|
|
|
import { Dropdown } from "design-system";
|
2021-10-21 05:36:17 +00:00
|
|
|
import StyledFormGroup from "components/ads/formFields/FormGroup";
|
|
|
|
|
import { FormTextFieldProps } from "components/ads/formFields/TextField";
|
|
|
|
|
import { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form";
|
2021-09-12 16:36:43 +00:00
|
|
|
import styled from "styled-components";
|
2021-10-21 05:36:17 +00:00
|
|
|
import { OptionType } from "./constants";
|
2021-09-12 16:36:43 +00:00
|
|
|
|
|
|
|
|
export const FormHeaderWrapper = styled.div`
|
|
|
|
|
position: relative;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const FormHeaderLabel = styled.h5`
|
|
|
|
|
width: 100%;
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const FormHeaderIndex = styled.h5`
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const FormBodyWrapper = styled.div`
|
|
|
|
|
padding: ${(prop) => prop.theme.spaces[10]}px 0px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const FormHeaderSubtext = styled.p``;
|
|
|
|
|
|
|
|
|
|
export const ControlWrapper = styled.div`
|
|
|
|
|
margin: ${(prop) => prop.theme.spaces[6]}px 0px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const Label = styled.label`
|
|
|
|
|
display: inline-block;
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const ButtonWrapper = styled.div`
|
|
|
|
|
margin: ${(prop) => prop.theme.spaces[17] * 2}px 0px 0px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const AllowToggleWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const AllowToggle = styled.div`
|
|
|
|
|
flex-basis: 68px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const AllowToggleLabel = styled.p`
|
|
|
|
|
margin-bottom: 0px;
|
|
|
|
|
margin-top: 2px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const StyledLink = styled.a`
|
|
|
|
|
&,
|
|
|
|
|
&:hover {
|
|
|
|
|
color: ${(props) => props.theme.colors.link};
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
}
|
|
|
|
|
`;
|
2021-10-21 05:36:17 +00:00
|
|
|
|
|
|
|
|
const DROPDOWN_CLASSNAME = "setup-dropdown";
|
|
|
|
|
export const DropdownWrapper = styled(StyledFormGroup)`
|
|
|
|
|
&& {
|
|
|
|
|
margin-bottom: 33px;
|
|
|
|
|
}
|
|
|
|
|
&& .cs-text {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.${DROPDOWN_CLASSNAME} {
|
|
|
|
|
.ads-dropdown-options-wrapper {
|
|
|
|
|
padding: 0;
|
|
|
|
|
border: 1px solid rgba(0, 0, 0, 8%);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-13 10:07:11 +00:00
|
|
|
|
|
|
|
|
.ads-dropdown-errorMsg {
|
|
|
|
|
font-size: ${(props) => props.theme.fontSizes[3]}px;
|
|
|
|
|
}
|
2021-10-21 05:36:17 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-05-04 08:43:02 +00:00
|
|
|
export const Center = styled.div`
|
|
|
|
|
height: 100vh;
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
position: absolute;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-10-21 05:36:17 +00:00
|
|
|
export function withDropdown(options: OptionType[], width: string) {
|
|
|
|
|
return function DropdownField(
|
2022-03-11 11:21:58 +00:00
|
|
|
componentProps: FormTextFieldProps & {
|
2021-10-21 05:36:17 +00:00
|
|
|
meta: Partial<WrappedFieldMetaProps>;
|
|
|
|
|
input: Partial<WrappedFieldInputProps>;
|
|
|
|
|
},
|
|
|
|
|
) {
|
|
|
|
|
function onSelect(value?: string) {
|
2022-03-11 11:21:58 +00:00
|
|
|
componentProps.input.onChange && componentProps.input.onChange(value);
|
|
|
|
|
componentProps.input.onBlur && componentProps.input.onBlur(value);
|
2021-10-21 05:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 10:07:11 +00:00
|
|
|
const selected = options.find(
|
|
|
|
|
(option) => option.value == componentProps.input.value,
|
|
|
|
|
) || { label: componentProps.placeholder };
|
|
|
|
|
const hasError = componentProps.meta.invalid && componentProps.meta.touched;
|
2021-10-21 05:36:17 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dropdown
|
|
|
|
|
className={DROPDOWN_CLASSNAME}
|
|
|
|
|
dontUsePortal
|
2022-04-13 10:07:11 +00:00
|
|
|
errorMsg={hasError ? componentProps.meta.error : ""}
|
2021-10-21 05:36:17 +00:00
|
|
|
fillOptions
|
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
options={options}
|
|
|
|
|
selected={selected}
|
|
|
|
|
showLabelOnly
|
|
|
|
|
width={width}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
}
|