Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(web): Select field - Minor fixes #696

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const Default: Story = (args: Props) => {
{...args}
name="Disabled"
description="Props are controlled by the field above"
placeholder="This is a disabled field"
disabled={true}
onChange={handleChange}
/>
Expand All @@ -39,6 +40,7 @@ export const Default: Story = (args: Props) => {
name="Empty"
value={undefined}
description="Even if you try, you won't be able to select the value"
placeholder="This is a disabled field, so can't click this one"
onChange={handleChange}
/>
</div>
Expand All @@ -51,13 +53,14 @@ const Wrapper = styled.div`
flex-direction: column;
gap: 10%;
margin-left: 2rem;
margin-right: 2rem;
margin-top: 2rem;
height: 300px;
`;

Default.args = {
name: "Select Field",
description: "Select from the options",
description: "Select from the options ",
disabled: false,
value: undefined,
options: [
Expand Down
18 changes: 14 additions & 4 deletions web/src/beta/components/fields/SelectField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Props = {
onChange: (key: string) => void;
value?: string;
disabled?: boolean;
placeholder?: string;
// Property field
name?: string;
description?: string;
Expand All @@ -30,6 +31,7 @@ const SelectField: React.FC<Props> = ({
disabled = false,
name,
description,
placeholder,
}) => {
const t = useT();

Expand All @@ -55,9 +57,9 @@ const SelectField: React.FC<Props> = ({
<Popover.Trigger asChild>
<InputWrapper disabled={disabled} onClick={handlePopOver}>
<Select selected={selected ? true : false} open={open}>
{selected ? selected.label : t("Please choose an option")}
{selected ? selected.label : placeholder ? placeholder : t("Please choose an option")}
jashanbhullar marked this conversation as resolved.
Show resolved Hide resolved
</Select>
<ArrowDownIcon icon="arrowDown" size={12} />
<ArrowIcon icon="arrowDown" open={open} size={12} />
</InputWrapper>
</Popover.Trigger>
<PickerWrapper attachToRoot>
Expand Down Expand Up @@ -86,8 +88,14 @@ const InputWrapper = styled.div<{ disabled: boolean }>`
const Select = styled.div<{ open: boolean; selected: boolean }>`
display: flex;
padding: 4px 8px;
/* The width + placement of the arrow icon */
padding-right: 22px;
border-radius: 4px;
width: 100%;
height: 28px;
line-height: 2.33;
overflow: hidden;
text-overflow: ellipsis;
KaWaite marked this conversation as resolved.
Show resolved Hide resolved
font-size: 12px;
color: ${({ theme, selected }) => (selected ? theme.content.main : theme.content.weaker)};
background: ${({ theme }) => theme.bg[1]};
Expand All @@ -105,11 +113,11 @@ const Select = styled.div<{ open: boolean; selected: boolean }>`
}
`;

const ArrowDownIcon = styled(Icon)`
const ArrowIcon = styled(Icon)<{ open: boolean }>`
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
transform: ${({ open }) => (open ? "translateY(-50%) scaleY(-1)" : "translateY(-50%)")};
`;

const PickerWrapper = styled(Popover.Content)`
Expand All @@ -123,6 +131,8 @@ const PickerWrapper = styled(Popover.Content)`
display: flex;
flex-direction: column;
justify-content: space-between;
/* TODO: Need standardized z-index */
z-index: 1;
`;

const Option = styled(Text)<{ selected: boolean }>`
Expand Down
Loading