-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟 🎨 Add style for disabled state to
<CheckBox />
+ replace `styled-…
…components` + add `small` size + add storybook (#20335) * add storybook for CheckBox component add disabled state style * just checking how to extend current implementation of storybook * remove experimental changes * replace styled components with css modules add disabled state style add small size style add storybook * update test snapshots * six size convention * Update airbyte-webapp/src/components/ui/CheckBox/CheckBox.module.scss Co-authored-by: Mark Berger <mark.berger@globallogic.com> * rename checkbox "size" prop add "mixed" aria-checked state * remove unneeded styled checkbox from signup page Co-authored-by: Mark Berger <mark.berger@globallogic.com>
- Loading branch information
Showing
6 changed files
with
156 additions
and
59 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
46 changes: 46 additions & 0 deletions
46
airbyte-webapp/src/components/ui/CheckBox/CheckBox.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,46 @@ | ||
@use "scss/colors"; | ||
@use "scss/variables" as vars; | ||
|
||
$lg-size: 18px; | ||
$sm-size: 14px; | ||
|
||
.container { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: vars.$border-thin 0; | ||
border: vars.$border-thin solid colors.$grey-100; | ||
border-radius: vars.$border-radius-2xs; | ||
color: colors.$white; | ||
background-color: colors.$white; | ||
cursor: pointer; | ||
|
||
input { | ||
display: none; | ||
} | ||
|
||
.disabled { | ||
border-color: colors.$grey-30; | ||
} | ||
} | ||
|
||
.checked, | ||
.indeterminate { | ||
border: vars.$border-thin solid colors.$blue; | ||
background: colors.$blue; | ||
|
||
&.disabled { | ||
background-color: colors.$blue-200; | ||
border-color: colors.$blue-200; | ||
} | ||
} | ||
|
||
.sizeLg { | ||
height: $lg-size; | ||
width: $lg-size; | ||
} | ||
|
||
.sizeSm { | ||
height: $sm-size; | ||
width: $sm-size; | ||
} |
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 |
---|---|---|
@@ -1,49 +1,40 @@ | ||
import { faCheck, faMinus } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import classNames from "classnames"; | ||
import React, { InputHTMLAttributes } from "react"; | ||
|
||
const CheckBoxInput = styled.input` | ||
opacity: 0; | ||
width: 0; | ||
height: 0; | ||
margin: 0; | ||
position: absolute; | ||
`; | ||
import styles from "./CheckBox.module.scss"; | ||
|
||
const CheckBoxContainer = styled.label<{ | ||
checked?: boolean; | ||
type CheckBoxSize = "lg" | "sm"; | ||
|
||
export interface CheckBoxProps extends InputHTMLAttributes<HTMLInputElement> { | ||
indeterminate?: boolean; | ||
}>` | ||
height: 18px; | ||
min-width: 18px; | ||
border: 1px solid | ||
${({ theme, checked, indeterminate }) => (checked || indeterminate ? theme.primaryColor : theme.greyColor20)}; | ||
background: ${({ theme, checked, indeterminate }) => | ||
checked || indeterminate ? theme.primaryColor : theme.whiteColor}; | ||
color: ${({ theme }) => theme.whiteColor}; | ||
text-align: center; | ||
border-radius: 4px; | ||
font-size: 13px; | ||
line-height: 13px; | ||
display: inline-block; | ||
padding: 1px 0; | ||
cursor: pointer; | ||
vertical-align: top; | ||
position: relative; | ||
`; | ||
checkboxSize?: CheckBoxSize; | ||
} | ||
|
||
export const CheckBox: React.FC<CheckBoxProps> = ({ indeterminate, checkboxSize = "lg", ...inputProps }) => { | ||
const { checked, disabled, className } = inputProps; | ||
|
||
export const CheckBox: React.FC<React.InputHTMLAttributes<HTMLInputElement> & { indeterminate?: boolean }> = ({ | ||
indeterminate, | ||
...props | ||
}) => ( | ||
<CheckBoxContainer | ||
onClick={(event: React.SyntheticEvent) => event.stopPropagation()} | ||
className={props.className} | ||
checked={props.checked} | ||
indeterminate={indeterminate} | ||
> | ||
<CheckBoxInput {...props} type="checkbox" /> | ||
{indeterminate ? <FontAwesomeIcon icon={faMinus} /> : props.checked && <FontAwesomeIcon icon={faCheck} />} | ||
</CheckBoxContainer> | ||
); | ||
return ( | ||
<label | ||
className={classNames( | ||
styles.container, | ||
{ | ||
[styles.checked]: checked, | ||
[styles.indeterminate]: indeterminate, | ||
[styles.disabled]: disabled, | ||
[styles.sizeLg]: checkboxSize === "lg", | ||
[styles.sizeSm]: checkboxSize === "sm", | ||
}, | ||
className | ||
)} | ||
> | ||
<input type="checkbox" aria-checked={indeterminate ? "mixed" : checked} {...inputProps} /> | ||
{indeterminate ? ( | ||
<FontAwesomeIcon size={checkboxSize} icon={faMinus} /> | ||
) : ( | ||
checked && <FontAwesomeIcon size={checkboxSize} icon={faCheck} /> | ||
)} | ||
</label> | ||
); | ||
}; |
71 changes: 71 additions & 0 deletions
71
airbyte-webapp/src/components/ui/CheckBox/index.stories.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,71 @@ | ||
import { action } from "@storybook/addon-actions"; | ||
import { ComponentMeta } from "@storybook/react"; | ||
import { ChangeEvent, useState } from "react"; | ||
|
||
import { CheckBox, CheckBoxProps } from "./CheckBox"; | ||
|
||
export default { | ||
title: "Ui/CheckBox", | ||
component: CheckBox, | ||
argTypes: { | ||
disabled: { control: "boolean" }, | ||
checked: { control: "boolean" }, | ||
indeterminate: { control: "boolean" }, | ||
elSize: { | ||
options: ["lg", "sm"], | ||
control: { type: "radio" }, | ||
}, | ||
}, | ||
} as ComponentMeta<typeof CheckBox>; | ||
|
||
const CheckBoxWithState = ({ checked: initial = false, ...props }: CheckBoxProps) => { | ||
const [checked, setChecked] = useState(initial); | ||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
action("Checkbox clicked")(event); | ||
setChecked((prev) => !prev); | ||
}; | ||
return <CheckBox {...props} checked={checked} onChange={handleChange} />; | ||
}; | ||
|
||
export const Base = (args: CheckBoxProps) => <CheckBoxWithState {...args} />; | ||
|
||
Base.args = {}; | ||
|
||
export const Checked = (args: CheckBoxProps) => <CheckBoxWithState {...args} />; | ||
|
||
Checked.args = { | ||
checked: true, | ||
}; | ||
|
||
export const CheckedSmall = (args: CheckBoxProps) => <CheckBoxWithState {...args} />; | ||
|
||
CheckedSmall.args = { | ||
checked: true, | ||
elSize: "sm", | ||
}; | ||
|
||
export const Disabled = (args: CheckBoxProps) => <CheckBoxWithState {...args} />; | ||
|
||
Disabled.args = { | ||
disabled: true, | ||
}; | ||
|
||
export const DisabledChecked = (args: CheckBoxProps) => <CheckBoxWithState {...args} />; | ||
|
||
DisabledChecked.args = { | ||
disabled: true, | ||
checked: true, | ||
}; | ||
|
||
export const Indeterminate = (args: CheckBoxProps) => <CheckBoxWithState {...args} />; | ||
|
||
Indeterminate.args = { | ||
indeterminate: true, | ||
}; | ||
|
||
export const IndeterminateDisabled = (args: CheckBoxProps) => <CheckBoxWithState {...args} />; | ||
|
||
IndeterminateDisabled.args = { | ||
indeterminate: true, | ||
disabled: true, | ||
}; |
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