PromucFlow_constructor/app/client/src/pages/setup/common.tsx

125 lines
2.9 KiB
TypeScript
Raw Normal View History

import React from "react";
feat: Renamed design system package (#19854) ## Description This PR includes changes for renaming design system package. Since we are building new package for the refactored design system components, the old package is renaming to design-system-old. Fixes #19536 ## Type of change - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) ## How Has This Been Tested? - Manual - Jest - Cypress ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test
2023-01-23 03:50:47 +00:00
import { Dropdown, FormGroup as StyledFormGroup } from "design-system-old";
import { FormTextFieldProps } from "components/utils/ReduxFormTextField";
import { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form";
import styled from "styled-components";
import { OptionType } from "./constants";
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;
}
`;
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%);
}
}
.ads-dropdown-errorMsg {
font-size: ${(props) => props.theme.fontSizes[3]}px;
}
`;
export const Center = styled.div`
height: 100vh;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
`;
export function withDropdown(options: OptionType[], width: string) {
return function DropdownField(
componentProps: FormTextFieldProps & {
meta: Partial<WrappedFieldMetaProps>;
input: Partial<WrappedFieldInputProps>;
},
) {
function onSelect(value?: string) {
componentProps.input.onChange && componentProps.input.onChange(value);
componentProps.input.onBlur && componentProps.input.onBlur(value);
}
const selected = options.find(
(option) => option.value == componentProps.input.value,
) || { label: componentProps.placeholder };
const hasError = componentProps.meta.invalid && componentProps.meta.touched;
return (
<Dropdown
className={DROPDOWN_CLASSNAME}
dontUsePortal
errorMsg={hasError ? componentProps.meta.error : ""}
fillOptions
onSelect={onSelect}
options={options}
selected={selected}
showLabelOnly
width={width}
/>
);
};
}