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

feat: Checkbox Tile Variant #1104

Merged
merged 7 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"peerDependencies": {
"react": "^16.x || ^17.x",
"react-dom": "^16.x || ^17.x",
"uswds": "2.9.0"
"uswds": "2.10.0"
},
"devDependencies": {
"@babel/core": "^7.10.5",
Expand Down Expand Up @@ -126,7 +126,7 @@
"ts-jest": "^26.1.2",
"typescript": "^3.8.0",
"url-loader": "^4.0.0",
"uswds": "2.9.0",
"uswds": "2.10.0",
"webpack": "^4.41.0",
"webpack-cli": "^4.0.0"
},
Expand Down
23 changes: 23 additions & 0 deletions src/components/forms/Checkbox/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,26 @@ export const withRichLabel = (): React.ReactElement => (
label={<strong>My Checkbox</strong>}
/>
)

export const WithLabelDescription = (): React.ReactElement => (
<Checkbox
id="checkbox"
name="checkbox"
label="My Checkbox"
labelDescription="Optional label description"
mlm55 marked this conversation as resolved.
Show resolved Hide resolved
/>
)

export const tile = (): React.ReactElement => (
<Checkbox id="checkbox" name="checkbox" label="My Checkbox" tile />
)

export const tileWithLabelDescription = (): React.ReactElement => (
<Checkbox
id="checkbox"
name="checkbox"
label="My Checkbox"
labelDescription="Optional label description"
tile
/>
)
29 changes: 29 additions & 0 deletions src/components/forms/Checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,32 @@ describe('Checkbox component', () => {
expect(queryByTestId('checkbox')).toBeInTheDocument()
})
})

it('renders tiled checkbox', () => {
const { queryByLabelText } = render(
<Checkbox
id="input-checkbox"
name="input-checkbox"
label="My checkbox"
tile
/>
)
expect(queryByLabelText('My checkbox')).toHaveClass(
'usa-checkbox__input usa-checkbox__input--tile'
)
})

it('renders label description', () => {
const { queryByText } = render(
<Checkbox
id="input-checkbox"
name="input-checkbox"
label="My checkbox"
labelDescription="Label description"
tile
/>
)
expect(queryByText('Label description')).toHaveClass(
'usa-checkbox__label-description'
)
})
16 changes: 15 additions & 1 deletion src/components/forms/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface CheckboxProps {
| React.RefObject<HTMLInputElement>
| null
| undefined
tile?: boolean
labelDescription?: React.ReactNode
brandonlenz marked this conversation as resolved.
Show resolved Hide resolved
}

export const Checkbox = ({
Expand All @@ -20,14 +22,25 @@ export const Checkbox = ({
className,
label,
inputRef,
tile,
labelDescription,
...inputProps
}: CheckboxProps & JSX.IntrinsicElements['input']): React.ReactElement => {
const classes = classnames('usa-checkbox', className)
const checkboxClasses = classnames('usa-checkbox__input', {
'usa-checkbox__input--tile': tile,
})
const description =
labelDescription != null ? (
<span className="usa-checkbox__label-description">
{labelDescription}
</span>
) : null

return (
<div data-testid="checkbox" className={classes}>
<input
className="usa-checkbox__input"
className={checkboxClasses}
id={id}
type="checkbox"
name={name}
Expand All @@ -36,6 +49,7 @@ export const Checkbox = ({
/>
<label className="usa-checkbox__label" htmlFor={id}>
{label}
{description}
mlm55 marked this conversation as resolved.
Show resolved Hide resolved
</label>
</div>
)
Expand Down
58 changes: 28 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5389,18 +5389,18 @@ define-property@^2.0.2:
is-descriptor "^1.0.2"
isobject "^3.0.1"

del@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/del/-/del-5.1.0.tgz#d9487c94e367410e6eff2925ee58c0c84a75b3a7"
integrity sha512-wH9xOVHnczo9jN2IW68BabcecVPxacIA3g/7z6vhSU/4stOKQzeCRK0yD0A24WiAAUJmmVpWqrERcTxnLo3AnA==
del@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/del/-/del-6.0.0.tgz#0b40d0332cea743f1614f818be4feb717714c952"
integrity sha512-1shh9DQ23L16oXSZKB2JxpL7iMy2E0S9d517ptA1P8iw0alkPtQcrKH7ru31rYtKwF499HkTu+DRzq3TCKDFRQ==
dependencies:
globby "^10.0.1"
graceful-fs "^4.2.2"
globby "^11.0.1"
graceful-fs "^4.2.4"
is-glob "^4.0.1"
is-path-cwd "^2.2.0"
is-path-inside "^3.0.1"
p-map "^3.0.0"
rimraf "^3.0.0"
is-path-inside "^3.0.2"
p-map "^4.0.0"
rimraf "^3.0.2"
slash "^3.0.0"

delayed-stream@~1.0.0:
Expand Down Expand Up @@ -6450,7 +6450,7 @@ fast-glob@^2.2.6:
merge2 "^1.2.3"
micromatch "^3.1.10"

fast-glob@^3.0.3, fast-glob@^3.1.1, fast-glob@^3.2.5:
fast-glob@^3.1.1, fast-glob@^3.2.5:
version "3.2.5"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.5.tgz#7939af2a656de79a4f1901903ee8adcaa7cb9661"
integrity sha512-2DtFcgT68wiTTiwZ2hNdJfcHNke9XOfnwmBRWXhmeKM8rF0TGwmC/Qto3S7RoZKp5cilZbxzO5iTNTQsJ+EeDg==
Expand Down Expand Up @@ -7192,18 +7192,16 @@ globby@11.0.1:
merge2 "^1.3.0"
slash "^3.0.0"

globby@^10.0.1:
version "10.0.2"
resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.2.tgz#277593e745acaa4646c3ab411289ec47a0392543"
integrity sha512-7dUi7RvCoT/xast/o/dLN53oqND4yk0nsHkhRgn9w65C4PofCLOoJ39iSOg+qVDdWQPIEj+eszMHQ+aLVwwQSg==
globby@^11.0.1:
version "11.0.3"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.3.tgz#9b1f0cb523e171dd1ad8c7b2a9fb4b644b9593cb"
integrity sha512-ffdmosjA807y7+lA1NM0jELARVmYul/715xiILEjo3hBLPTcirgQNnXECn5g3mtR8TOLCVbkfua1Hpen25/Xcg==
dependencies:
"@types/glob" "^7.1.1"
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.0.3"
glob "^7.1.3"
ignore "^5.1.1"
merge2 "^1.2.3"
fast-glob "^3.1.1"
ignore "^5.1.4"
merge2 "^1.3.0"
slash "^3.0.0"

globby@^11.0.2:
Expand Down Expand Up @@ -7251,7 +7249,7 @@ good-listener@^1.2.2:
dependencies:
delegate "^3.1.2"

graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0, graceful-fs@^4.2.2, graceful-fs@^4.2.4:
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0, graceful-fs@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
Expand Down Expand Up @@ -7740,7 +7738,7 @@ ignore@^4.0.3, ignore@^4.0.6:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==

ignore@^5.1.1, ignore@^5.1.4, ignore@^5.1.8:
ignore@^5.1.4, ignore@^5.1.8:
version "5.1.8"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57"
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==
Expand Down Expand Up @@ -8187,10 +8185,10 @@ is-path-cwd@^2.2.0:
resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-2.2.0.tgz#67d43b82664a7b5191fd9119127eb300048a9fdb"
integrity sha512-w942bTcih8fdJPJmQHFzkS76NEP8Kzzvmw92cXsazb8intwLqPibPPdXf4ANdKV3rYMuuQYGIWtvz9JilB3NFQ==

is-path-inside@^3.0.1:
version "3.0.2"
resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.2.tgz#f5220fc82a3e233757291dddc9c5877f2a1f3017"
integrity sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg==
is-path-inside@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.3.tgz#d231362e53a07ff2b0e0ea7fed049161ffd16283"
integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==

is-plain-obj@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -13947,13 +13945,13 @@ use@^3.1.0:
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==

uswds@2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/uswds/-/uswds-2.9.0.tgz#002089d74582960099b0ee836f89f043cdf6d0bc"
integrity sha512-5IMVgMCUUlgWVFrB7Wf1qTvv5L3oDDlSsAgvJ02+/sV2uh4JzO9YPm3493RTaMuHTc+feRCuYyEIloXsEQY0Pg==
uswds@2.10.0:
version "2.10.0"
resolved "https://registry.yarnpkg.com/uswds/-/uswds-2.10.0.tgz#c7ecb779c82302fa189b36ca3eefe59dfde7f782"
integrity sha512-A6HjL42ryf9pdfbm6JrGxZywKzCZraHO4v3Ve21uFDqoA3ijoNjiSYME+3SG86CIgC6zRasrbQVuI3bvd3Xv2w==
dependencies:
classlist-polyfill "^1.0.3"
del "^5.1.0"
del "^6.0.0"
domready "^1.0.8"
elem-dataset "^2.0.0"
lodash.debounce "^4.0.7"
Expand Down