## Description Move [old ADS components](https://github.com/appsmithorg/design-system/tree/release/packages/design-system-old) used in widgets to a local package. Fix prettier, linter and type check errors List of widgets that may be affected: 1. BaseInputWidget 2. ButtonWidget 3. CurrencyInputWidget 4. InputWidget 5. PhoneInputWidget 6. DropdownWidget 7. ListWidget 8. ListWidgetV2 9. MultiSelectTreeWidget 10. MultiSelectWidget 11. MultiSelectWidgetV2 12. RateWidget 13. SelectWidget 14. SingleSelectTreeWidget 15. TableWidget 16. TableWidgetV2 17. TabsWidget 18. TextWidget #### PR fixes following issue(s) Fixes #22988 #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [x] Jest - [x] 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 - [x] 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 - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Valera Melnikov <melnikov.vv@greendatasoft.ru>
171 lines
4.8 KiB
TypeScript
171 lines
4.8 KiB
TypeScript
import React from "react";
|
|
import styled, { createGlobalStyle } from "styled-components";
|
|
import type { DropdownOption } from "@design-system/widgets-old";
|
|
import { Dropdown, Icon, IconSize } from "@design-system/widgets-old";
|
|
import { countryToFlag } from "./utilities";
|
|
import type { ISDCodeProps } from "constants/ISDCodes";
|
|
import { ISDCodeOptions } from "constants/ISDCodes";
|
|
import { Colors } from "constants/Colors";
|
|
import { Classes } from "@blueprintjs/core";
|
|
import { lightenColor } from "widgets/WidgetUtils";
|
|
|
|
const DropdownTriggerIconWrapper = styled.div<{ disabled?: boolean }>`
|
|
height: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
font-size: 14px;
|
|
line-height: ${(props) => (props.disabled ? 36 : 18)}px;
|
|
letter-spacing: -0.24px;
|
|
color: #090707;
|
|
cursor: pointer;
|
|
position: ${(props) => props.disabled && "absolute"};
|
|
|
|
.dropdown {
|
|
svg {
|
|
width: 14px;
|
|
height: 14px;
|
|
|
|
path {
|
|
fill: ${Colors.GREY_10} !important;
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
const FlagWrapper = styled.span`
|
|
font-size: 20px;
|
|
line-height: 19px;
|
|
`;
|
|
|
|
export const PopoverStyles = createGlobalStyle<{
|
|
borderRadius: string;
|
|
portalClassName: string;
|
|
accentColor: string;
|
|
}>`
|
|
${(props) => `
|
|
.${props.portalClassName} .${Classes.POPOVER} {
|
|
border-radius: ${props.borderRadius} !important;
|
|
overflow: hidden;
|
|
box-shadow: 0 6px 20px 0px rgba(0, 0, 0, 0.15) !important;
|
|
margin-top: 4px !important;
|
|
}
|
|
|
|
.${props.portalClassName} .${Classes.BUTTON} {
|
|
border-radius: ${props.borderRadius} !important;
|
|
}
|
|
|
|
.${props.portalClassName} .${Classes.INPUT} {
|
|
border-radius: ${props.borderRadius} !important;
|
|
min-height: 32px;
|
|
}
|
|
|
|
.${props.portalClassName} .${Classes.INPUT}:focus, .${
|
|
props.portalClassName
|
|
} .${Classes.INPUT}:active {
|
|
border: 1px solid ${props.accentColor} !important;
|
|
box-shadow: 0px 0px 0px 3px ${lightenColor(
|
|
props.accentColor,
|
|
)} !important;
|
|
}
|
|
|
|
.${props.portalClassName} .t--dropdown-option:hover,
|
|
.${props.portalClassName} .t--dropdown-option.selected {
|
|
background-color: ${lightenColor(props.accentColor)} !important;
|
|
}
|
|
|
|
.${props.portalClassName} .ads-dropdown-options-wrapper {
|
|
border: 0px solid !important;
|
|
}
|
|
`}
|
|
`;
|
|
|
|
const getISDCodeOptions = (): Array<DropdownOption> => {
|
|
return ISDCodeOptions.map((item: ISDCodeProps) => {
|
|
return {
|
|
leftElement: countryToFlag(item.code),
|
|
searchText: item.name,
|
|
label: `${item.name} (${item.dial_code})`,
|
|
value: item.code,
|
|
id: item.dial_code,
|
|
};
|
|
});
|
|
};
|
|
|
|
export const ISDCodeDropdownOptions = getISDCodeOptions();
|
|
|
|
export const getSelectedISDCode = (code?: string): DropdownOption => {
|
|
let selectedCountry: ISDCodeProps | undefined = code
|
|
? ISDCodeOptions.find((item: ISDCodeProps) => {
|
|
return item.code === code;
|
|
})
|
|
: undefined;
|
|
if (!selectedCountry) {
|
|
selectedCountry = {
|
|
name: "United States",
|
|
dial_code: "+1",
|
|
code: "US",
|
|
};
|
|
}
|
|
return {
|
|
label: `${selectedCountry.name} (${selectedCountry.dial_code})`,
|
|
searchText: selectedCountry.name,
|
|
value: selectedCountry.code,
|
|
id: selectedCountry.dial_code,
|
|
};
|
|
};
|
|
|
|
interface ISDCodeDropdownProps {
|
|
onISDCodeChange: (code?: string) => void;
|
|
options: Array<DropdownOption>;
|
|
selected: DropdownOption;
|
|
allowCountryCodeChange?: boolean;
|
|
disabled: boolean;
|
|
borderRadius: string;
|
|
accentColor: string;
|
|
widgetId: string;
|
|
}
|
|
|
|
export default function ISDCodeDropdown(props: ISDCodeDropdownProps) {
|
|
const selectedCountry = getSelectedISDCode(props.selected.value);
|
|
const dropdownTrigger = (
|
|
<DropdownTriggerIconWrapper
|
|
className="gap-2 px-3 t--input-country-code-change focus:bg-gray-50"
|
|
disabled={props.disabled}
|
|
tabIndex={0}
|
|
>
|
|
<FlagWrapper>
|
|
{selectedCountry.value && countryToFlag(selectedCountry.value)}
|
|
</FlagWrapper>
|
|
<div className="code">{selectedCountry.id && selectedCountry.id}</div>
|
|
<Icon className="dropdown" name="down-arrow" size={IconSize.XXS} />
|
|
</DropdownTriggerIconWrapper>
|
|
);
|
|
if (props.disabled) {
|
|
return dropdownTrigger;
|
|
}
|
|
return (
|
|
<>
|
|
<Dropdown
|
|
containerClassName="country-type-filter"
|
|
dropdownHeight="139px"
|
|
dropdownTriggerIcon={dropdownTrigger}
|
|
enableSearch
|
|
height="36px"
|
|
onSelect={props.onISDCodeChange}
|
|
optionWidth="340px"
|
|
options={props.options}
|
|
portalClassName={`country-type-filter-dropdown-${props.widgetId}`}
|
|
searchPlaceholder="Search by ISD code or country"
|
|
selected={props.selected}
|
|
showLabelOnly
|
|
/>
|
|
<PopoverStyles
|
|
accentColor={props.accentColor}
|
|
borderRadius={props.borderRadius}
|
|
portalClassName={`country-type-filter-dropdown-${props.widgetId}`}
|
|
/>
|
|
</>
|
|
);
|
|
}
|