PromucFlow_constructor/app/client/src/components/ads/TableDropdown.tsx
albinAppsmith 71886c3b9e
feat: Property pane dropdown overflow issues (#8236)
* * hide subtext for date picker fix
* EE clicking on entity, unfolding/folding added

* * bug fixes in action dropdown

* bug fix for cursor

* fix: 8190 background api request and welcome helper button (#8281)

* chore: Move action/js debugger tabs related logic to a common component (#8199)

* removed background of api request textbox and added hover text on "no thanks" button

Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com>

* fix: added scrolling in invited users more popup (#8226)

* added scrolling in invited users more popup

* always scrollbar displaying on invited users pan

* fixed issue related with 8190

* updated cursor of invited users more

* replace edit data source icon with remix icon (#8192)

* * active text color

* fix: dropdownlist props issue (#8322)

* Commented failing JS tests (#8276)

Co-authored-by: Yatin Chaubal <yatin.chaubal@gmail.com>

* docs: Update ServerSetup.md (#8255)

* Make port customizable from env variable (#8288)

* fix: issue with string templates (#7848)

* Remove bracket highlight on error

* fix string template issue

* using string template to join strings

* fix breaking tests

* fixed props pass issue

Co-authored-by: yatinappsmith <84702014+yatinappsmith@users.noreply.github.com>
Co-authored-by: Yatin Chaubal <yatin.chaubal@gmail.com>
Co-authored-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Vinod <4994565+vnodecg@users.noreply.github.com>

* * bug fixes

* * bug fix

* * test cases fix

* - test case fix

* * test fixes

* * bug fix in test case

Co-authored-by: haojin111 <63215848+haojin111@users.noreply.github.com>
Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com>
Co-authored-by: yatinappsmith <84702014+yatinappsmith@users.noreply.github.com>
Co-authored-by: Yatin Chaubal <yatin.chaubal@gmail.com>
Co-authored-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Vinod <4994565+vnodecg@users.noreply.github.com>
Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2021-10-11 11:31:05 +05:30

138 lines
3.7 KiB
TypeScript

import { Position } from "@blueprintjs/core/lib/esm/common/position";
import {
Popover,
PopoverInteractionKind,
} from "@blueprintjs/core/lib/esm/components/popover/popover";
import React, { useState } from "react";
import styled from "styled-components";
import { Classes, CommonComponentProps } from "./common";
import Icon, { IconSize } from "./Icon";
import Spinner from "./Spinner";
import Text, { TextType } from "./Text";
type DropdownOption = {
name: string;
desc: string;
};
export type DropdownProps = CommonComponentProps & {
options: DropdownOption[];
onSelect: (selectedValue: DropdownOption) => void;
selectedIndex: number;
position?: Position;
selectedTextWidth?: string;
};
const SelectedItem = styled.div<{
width?: string;
}>`
display: flex;
align-items: center;
cursor: pointer;
user-select: none;
.${Classes.TEXT} {
margin-right: ${(props) => props.theme.spaces[1] + 1}px;
width: ${(props) => props.width || "auto"};
}
`;
const OptionsWrapper = styled.div`
width: 200px;
display: flex;
flex-direction: column;
background-color: ${(props) => props.theme.colors.tableDropdown.bg};
box-shadow: ${(props) => props.theme.spaces[0]}px
${(props) => props.theme.spaces[5]}px
${(props) => props.theme.spaces[13] - 2}px
${(props) => props.theme.colors.tableDropdown.shadow};
`;
const DropdownOption = styled.div<{
isSelected: boolean;
}>`
display: flex;
flex-direction: column;
padding: 10px 12px;
cursor: pointer;
${(props) =>
props.isSelected
? `background-color: ${props.theme.colors.tableDropdown.selectedBg}`
: null};
.${Classes.TEXT}:last-child {
margin-top: ${(props) => props.theme.spaces[1] + 1}px;
}
&:hover {
.${Classes.TEXT} {
color: ${(props) => props.theme.colors.tableDropdown.selectedText};
}
}
`;
const Content = styled.div<{ isLoading?: boolean }>`
position: relative;
& .${Classes.SPINNER} {
position: absolute;
}
& .selected-item {
${(props) => (props.isLoading ? `visibility: hidden;` : null)}
}
`;
function TableDropdown(props: DropdownProps) {
const [selectedIndex, setSelectedIndex] = useState(props.selectedIndex);
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const [selectedOption, setSelectedOption] = useState(
props.options[props.selectedIndex] || {},
);
const optionSelector = (index: number) => {
setSelectedIndex(index);
setSelectedOption(props.options[index]);
props.onSelect && props.onSelect(props.options[index]);
setIsDropdownOpen(false);
};
return props.isLoading ? (
<Spinner size={IconSize.LARGE} />
) : (
<Popover
data-cy={props.cypressSelector}
interactionKind={PopoverInteractionKind.CLICK}
isOpen={isDropdownOpen}
onInteraction={(state) => setIsDropdownOpen(state)}
position={props.position || Position.BOTTOM_LEFT}
usePortal={false}
>
<Content isLoading={props.isLoading}>
<SelectedItem className="selected-item" width={props.selectedTextWidth}>
<Text type={TextType.P1}>{selectedOption.name}</Text>
<Icon
fillColor="#A9A7A7"
hoverFillColor="#A9A7A7"
name="downArrow"
size={IconSize.XXXL}
/>
</SelectedItem>
</Content>
<OptionsWrapper>
{props.options.map((el: DropdownOption, index: number) => (
<DropdownOption
isSelected={selectedIndex === index}
key={index}
onClick={() => optionSelector(index)}
>
<Text type={TextType.H5}>{el.name}</Text>
<Text type={TextType.P3}>{el.desc}</Text>
</DropdownOption>
))}
</OptionsWrapper>
</Popover>
);
}
export default TableDropdown;