-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: listbox component refactor (#14691)
Co-authored-by: Volodymyr Petrov <[email protected]>
- Loading branch information
Showing
27 changed files
with
558 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
airbyte-webapp/src/components/ui/ListBox/ListboxButton.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@use "scss/colors"; | ||
@use "scss/variables"; | ||
|
||
.listboxButton { | ||
width: 100%; | ||
cursor: pointer; | ||
background-color: initial; | ||
color: colors.$dark-blue; | ||
border: variables.$border-thin solid colors.$grey-200; | ||
border-radius: variables.$border-radius-sm; | ||
text-align: left; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: variables.$spacing-md; | ||
font-size: variables.$font-size-lg; | ||
line-height: 1.4; | ||
min-height: 36px; | ||
|
||
&:disabled { | ||
border-color: colors.$grey-100; | ||
cursor: not-allowed; | ||
} | ||
|
||
&[aria-expanded="true"] { | ||
border-color: colors.$blue; | ||
} | ||
|
||
&:hover:not(:disabled) { | ||
border-color: colors.$grey-300; | ||
} | ||
|
||
&:focus:not(:disabled) { | ||
border-color: colors.$blue; | ||
} | ||
|
||
&:hover:not(:disabled)[aria-expanded="true"] { | ||
border-color: colors.$blue; | ||
} | ||
|
||
&--error { | ||
border-color: colors.$red-200; | ||
|
||
&:hover:not(:disabled) { | ||
border-color: colors.$red; | ||
} | ||
} | ||
|
||
.disabledText { | ||
color: colors.$grey-300; | ||
} | ||
|
||
&__content { | ||
width: 100%; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
airbyte-webapp/src/components/ui/ListBox/ListboxButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ListboxButton as HeadlessUIListboxButton } from "@headlessui/react"; | ||
import classNames from "classnames"; | ||
import React, { ComponentType } from "react"; | ||
|
||
import styles from "./ListboxButton.module.scss"; | ||
import { FlexContainer, FlexItem } from "../Flex"; | ||
import { Icon } from "../Icon"; | ||
|
||
export type ExtractProps<T> = T extends ComponentType<infer P> ? P : T; | ||
|
||
export const ListboxButton = React.forwardRef<HTMLButtonElement, ExtractProps<typeof HeadlessUIListboxButton>>( | ||
(props, ref) => { | ||
const mergedClassNames = classNames(styles.listboxButton, props.className); | ||
return ( | ||
<HeadlessUIListboxButton {...props} className={mergedClassNames} ref={ref}> | ||
{(bag) => ( | ||
<FlexContainer justifyContent="space-between" className={styles.listboxButton__content} alignItems="center"> | ||
<FlexItem>{typeof props.children === "function" ? props.children(bag) : props.children}</FlexItem> | ||
<Icon type="chevronDown" color="action" /> | ||
</FlexContainer> | ||
)} | ||
</HeadlessUIListboxButton> | ||
); | ||
} | ||
); | ||
|
||
ListboxButton.displayName = "ListboxButton"; |
24 changes: 24 additions & 0 deletions
24
airbyte-webapp/src/components/ui/ListBox/ListboxOption.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@use "scss/colors"; | ||
|
||
.listboxOption { | ||
list-style-type: none; | ||
background: colors.$foreground; | ||
user-select: none; | ||
cursor: pointer; | ||
|
||
&:hover, | ||
&:focus-visible, | ||
&[data-focus] { | ||
background-color: colors.$grey-50; | ||
} | ||
|
||
&[aria-selected="true"] { | ||
background-color: colors.$blue-50; | ||
|
||
&:hover, | ||
&:focus-visible, | ||
&[data-focus] { | ||
background-color: colors.$grey-50; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
airbyte-webapp/src/components/ui/ListBox/ListboxOption.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ListboxOption as HeadlessUIListboxOption } from "@headlessui/react"; | ||
import classNames from "classnames"; | ||
import { ComponentType } from "react"; | ||
|
||
import styles from "./ListboxOption.module.scss"; | ||
|
||
export type ExtractProps<T> = T extends ComponentType<infer P> ? P : T; | ||
|
||
export const ListboxOption = (props: ExtractProps<typeof HeadlessUIListboxOption>) => { | ||
const mergedClassNames = classNames(styles.listboxOption, props.className); | ||
return ( | ||
<HeadlessUIListboxOption {...props} className={mergedClassNames}> | ||
{props.children} | ||
</HeadlessUIListboxOption> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
airbyte-webapp/src/components/ui/ListBox/ListboxOptions.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@use "scss/variables"; | ||
|
||
.listboxOptions { | ||
min-width: 140px; | ||
border-radius: variables.$border-radius-lg; | ||
box-shadow: variables.$box-shadow-menu; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0; | ||
overflow: auto; | ||
|
||
&:focus-visible { | ||
outline: none; | ||
} | ||
|
||
&--fullWidth { | ||
/** --button-width is a variable exposed by headless-ui */ | ||
width: var(--button-width); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
airbyte-webapp/src/components/ui/ListBox/ListboxOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ListboxOptions as HeadlessUIListboxOptions } from "@headlessui/react"; | ||
import classNames from "classnames"; | ||
import React, { ComponentType } from "react"; | ||
|
||
import styles from "./ListboxOptions.module.scss"; | ||
|
||
export type ExtractProps<T> = T extends ComponentType<infer P> ? P : T; | ||
|
||
export interface OurProps { | ||
fullWidth?: boolean; | ||
} | ||
|
||
export const ListboxOptions = React.forwardRef<HTMLElement, ExtractProps<typeof HeadlessUIListboxOptions> & OurProps>( | ||
(props, ref) => { | ||
const mergedClassNames = classNames( | ||
styles.listboxOptions, | ||
{ | ||
[styles["listboxOptions--fullWidth"]]: !!props.fullWidth, | ||
}, | ||
props.className | ||
); | ||
return ( | ||
<HeadlessUIListboxOptions {...props} className={mergedClassNames} ref={ref}> | ||
{props.children} | ||
</HeadlessUIListboxOptions> | ||
); | ||
} | ||
); | ||
|
||
ListboxOptions.displayName = "ListboxOptions"; |
Oops, something went wrong.