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

🪟 🧹 Update ListBox styling according to the DropDown component #20069

Merged
merged 14 commits into from
Dec 13, 2022
33 changes: 33 additions & 0 deletions airbyte-webapp/src/components/ui/DropDown/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";

import { DropDown } from "./DropDown";

const listOptions = [
{
label: "one",
value: "value",
},
{
label: "two",
value: "value",
},
{
label: "three",
value: "value",
},
];

export default {
title: "Ui/DropDown",
component: DropDown,
argTypes: {
options: listOptions,
},
} as ComponentMeta<typeof DropDown>;

const Template: ComponentStory<typeof DropDown> = (args) => <DropDown {...args} />;

export const Primary = Template.bind({});
Primary.args = {
options: listOptions,
};
6 changes: 6 additions & 0 deletions airbyte-webapp/src/components/ui/ListBox/CaretDownIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 31 additions & 3 deletions airbyte-webapp/src/components/ui/ListBox/ListBox.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@

.button {
width: 100%;
height: 100%;
cursor: pointer;
border: 1px solid colors.$grey-50;
background-color: colors.$grey-50;
border-radius: 4px;
natalyjazzviolin marked this conversation as resolved.
Show resolved Hide resolved
text-align: left;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 14px;
line-height: 20px;
min-height: 36px;

&:hover {
border: 1px solid colors.$grey-100;
natalyjazzviolin marked this conversation as resolved.
Show resolved Hide resolved
}
}

.optionsContainer {
Expand All @@ -29,10 +42,25 @@
list-style-type: none;
}

.icon {
padding-right: variables.$spacing-md;

& svg {
max-width: 18px;
max-height: 18px;
}
}

.label {
padding: variables.$spacing-lg 0;
}

.optionValue {
padding: variables.$spacing-lg variables.$spacing-md;
border-radius: variables.$border-radius-lg;
padding: 0 variables.$spacing-md;
border-radius: variables.$border-radius-md;
cursor: pointer;
display: flex;
align-items: center;
}

.active {
Expand Down
8 changes: 6 additions & 2 deletions airbyte-webapp/src/components/ui/ListBox/ListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Listbox } from "@headlessui/react";
import classNames from "classnames";
import React from "react";

import { ReactComponent as CaretDownIcon } from "./CaretDownIcon.svg";
import styles from "./ListBox.module.scss";

export interface ListBoxControlButtonProps<T> {
Expand All @@ -15,6 +16,7 @@ const DefaultControlButton = <T,>({ selectedOption }: ListBoxControlButtonProps<
export interface Option<T> {
label: string;
value: T;
icon?: React.ReactNode;
}

interface ListBoxProps<T> {
Expand Down Expand Up @@ -44,17 +46,19 @@ export const ListBox = <T,>({
<Listbox value={selectedValue} onChange={onSelect}>
<Listbox.Button className={classNames(buttonClassName, styles.button)}>
<ControlButton selectedOption={selectedOption} />
<CaretDownIcon />
</Listbox.Button>
{/* wrap in div to make `position: absolute` on Listbox.Options result in correct vertical positioning */}
<div className={styles.optionsContainer}>
<Listbox.Options className={classNames(styles.optionsMenu)}>
{options.map(({ label, value }) => (
{options.map(({ label, value, icon }) => (
<Listbox.Option key={label} value={value} className={styles.option}>
{({ active, selected }) => (
<div
className={classNames(styles.optionValue, { [styles.active]: active, [styles.selected]: selected })}
>
{label}
{icon && <span className={styles.icon}>{icon}</span>}
<span className={styles.label}>{label}</span>
</div>
)}
</Listbox.Option>
Expand Down
36 changes: 36 additions & 0 deletions airbyte-webapp/src/components/ui/ListBox/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { faEdit } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { ComponentMeta } from "@storybook/react";
import { useState } from "react";

import { ListBox } from "./ListBox";

const listOptions = [
{
label: "one",
value: 1,
icon: <FontAwesomeIcon icon={faEdit} size="2x" />,
},
{
label: "two",
value: 2,
},
{
label: "three",
value: 3,
},
];

export default {
title: "Ui/ListBox",
component: ListBox,
argTypes: {
options: listOptions,
},
} as ComponentMeta<typeof ListBox>;

export const Primary = () => {
const [selectedOption, setSelectedOption] = useState(1);

return <ListBox options={listOptions} selectedValue={selectedOption} onSelect={setSelectedOption} />;
};