Skip to content

Commit

Permalink
馃獰 馃帹 Add color variants to PillSelect component (#18687)
Browse files Browse the repository at this point in the history
* Add color variants to PillSelect

* Add disabled, variant props
* Update $transition-out var to not use `all` and fix users of the var

* Add strong-blue variant to PillButton
  • Loading branch information
edmundito committed Nov 2, 2022
1 parent 87d79f7 commit 33194df
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 15 deletions.
35 changes: 28 additions & 7 deletions airbyte-webapp/src/components/ui/PillSelect/PillButton.module.scss
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
@use "scss/colors";
@use "scss/variables";

@mixin theme($name, $background, $text, $hover) {
&.#{$name} {
background-color: $background;
color: $text;

.text {
color: $text;
}

&:not(:disabled) {
&:hover,
&.active {
background: $hover;
}
}
}
}

.button {
max-width: 100%;
display: flex;
flex-direction: row;
align-items: center;
padding: 3px 10px;
gap: variables.$spacing-sm;
border: none;
border-radius: 20px;
cursor: pointer;
background: colors.$grey-50;
border: variables.$border-thin solid colors.$grey-50;
color: colors.$grey-600;
transition: background-color variables.$transition-out, color variables.$transition-out;

&:hover,
&.active {
background: colors.$grey-100;
}
@include theme("grey", colors.$grey-50, colors.$grey-600, colors.$grey-100);
@include theme("blue", colors.$blue-50, colors.$blue-600, colors.$blue-100);
@include theme("strongBlue", colors.$blue-300, colors.$white, colors.$blue-200);
@include theme("green", colors.$green-50, colors.$green-600, colors.$green-100);
@include theme("red", colors.$red-50, colors.$red-600, colors.$red-100);
@include theme("strongRed", colors.$red-300, colors.$white, colors.$red-400);

@include theme("disabled", colors.$grey-50, colors.$grey, colors.$grey-50);
}

.text {
Expand Down
14 changes: 14 additions & 0 deletions airbyte-webapp/src/components/ui/PillSelect/PillButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@ import classNames from "classnames";
import { Text } from "../Text";
import styles from "./PillButton.module.scss";

export type PillButtonVariant = "grey" | "blue" | "green" | "red" | "strong-red" | "strong-blue";

const STYLES_BY_VARIANT: Readonly<Record<PillButtonVariant, string>> = {
grey: styles.grey,
blue: styles.blue,
green: styles.green,
red: styles.red,
"strong-red": styles.strongRed,
"strong-blue": styles.strongBlue,
};

interface PillButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
active?: boolean;
variant?: PillButtonVariant;
}

export const PillButton: React.FC<React.PropsWithChildren<PillButtonProps>> = ({
children,
active,
variant = "grey",
...buttonProps
}) => {
const buttonClassName = classNames(
styles.button,
{
[styles.active]: active,
},
buttonProps.disabled ? styles.disabled : STYLES_BY_VARIANT[variant],
buttonProps.className
);

Expand Down
14 changes: 11 additions & 3 deletions airbyte-webapp/src/components/ui/PillSelect/PillSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Popout, PopoutProps } from "../Popout";
import { Tooltip } from "../Tooltip";
import { PillButton } from "./PillButton";
import { PillButton, PillButtonVariant } from "./PillButton";

type PillSelectProps = Pick<PopoutProps, "value" | "options" | "isMulti" | "onChange" | "className">;
type PickedPopoutProps = Pick<PopoutProps, "value" | "options" | "isMulti" | "onChange" | "className">;

interface PillSelectProps extends PickedPopoutProps {
variant?: PillButtonVariant;
disabled?: boolean;
}

export const PillSelect: React.FC<PillSelectProps> = ({ className, ...props }) => {
const { isMulti } = props;
const { isMulti, variant, disabled } = props;

return (
<Popout
{...props}
isDisabled={disabled}
targetComponent={({ onOpen, isOpen, value }) => {
const label = value
? isMulti
Expand All @@ -21,6 +27,8 @@ export const PillSelect: React.FC<PillSelectProps> = ({ className, ...props }) =
<Tooltip
control={
<PillButton
variant={variant}
disabled={disabled}
onClick={(event) => {
event.stopPropagation();
onOpen();
Expand Down
2 changes: 1 addition & 1 deletion airbyte-webapp/src/scss/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$transition: 0.3s;
$transition-out: all $transition ease-out;
$transition-out: $transition ease-out;

$border-thin: 1px;
$border-thick: 2px;
Expand Down
6 changes: 3 additions & 3 deletions airbyte-webapp/src/views/layout/SideBar/SideBar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@
&:hover,
&:focus-visible {
background: colors.$dark-blue-800;
transition: variables.$transition-out;
transition: all variables.$transition-out;
}

&.active {
color: colors.$white;
background: colors.$blue-400;
transition: variables.$transition-out;
transition: all variables.$transition-out;

&:hover,
&:focus-visible {
color: colors.$white;
background: colors.$blue-300;
transition: variables.$transition-out;
transition: all variables.$transition-out;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
border-radius: variables.$border-radius-md;
color: colors.$grey-30;
text-decoration: none;
transition: variables.$transition-out;
transition: all variables.$transition-out;

.text {
margin-top: 7px;
Expand Down

0 comments on commit 33194df

Please sign in to comment.