Skip to content

Commit

Permalink
Wrap checkbox + label in HStack, adjust css
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskoster committed Apr 18, 2024
1 parent db42921 commit 55e5dc7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
71 changes: 37 additions & 34 deletions packages/components/src/checkbox-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useState } from '@wordpress/element';
import { useInstanceId, useRefEffect } from '@wordpress/compose';
import deprecated from '@wordpress/deprecated';
import { Icon, check, reset } from '@wordpress/icons';
import { __experimentalHStack as HStack } from '@wordpress/components';

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 3

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 5

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 6

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 8

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 7

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Build JavaScript assets for PHP unit tests

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 1

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 2

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Playwright - 4

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Check

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Build Release Artifact

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / Run performance tests

Cannot find module '@wordpress/components' or its corresponding type declarations.

Check failure on line 14 in packages/components/src/checkbox-control/index.tsx

View workflow job for this annotation

GitHub Actions / All

Cannot find module '@wordpress/components' or its corresponding type declarations.

/**
* Internal dependencies
Expand Down Expand Up @@ -98,41 +99,43 @@ export function CheckboxControl(
help={ help }
className={ classnames( 'components-checkbox-control', className ) }
>
<span className="components-checkbox-control__input-container">
<input
ref={ ref }
id={ id }
className="components-checkbox-control__input"
type="checkbox"
value="1"
onChange={ onChangeValue }
checked={ checked }
aria-describedby={ !! help ? id + '__help' : undefined }
{ ...additionalProps }
/>
{ showIndeterminateIcon ? (
<Icon
icon={ reset }
className="components-checkbox-control__indeterminate"
role="presentation"
<HStack spacing={ 0 } justify="start" alignment="top">
<span className="components-checkbox-control__input-container">
<input
ref={ ref }
id={ id }
className="components-checkbox-control__input"
type="checkbox"
value="1"
onChange={ onChangeValue }
checked={ checked }
aria-describedby={ !! help ? id + '__help' : undefined }
{ ...additionalProps }
/>
) : null }
{ showCheckedIcon ? (
<Icon
icon={ check }
className="components-checkbox-control__checked"
role="presentation"
/>
) : null }
</span>
{ label && (
<label
className="components-checkbox-control__label"
htmlFor={ id }
>
{ label }
</label>
) }
{ showIndeterminateIcon ? (
<Icon
icon={ reset }
className="components-checkbox-control__indeterminate"
role="presentation"
/>
) : null }
{ showCheckedIcon ? (
<Icon
icon={ check }
className="components-checkbox-control__checked"
role="presentation"
/>
) : null }
</span>
{ label && (
<label
className="components-checkbox-control__label"
htmlFor={ id }
>
{ label }
</label>
) }
</HStack>
</BaseControl>
);
}
Expand Down
15 changes: 5 additions & 10 deletions packages/components/src/checkbox-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
.components-base-control__help {
margin-left: calc(var(--checkbox-input-size) + #{$grid-unit-15});
}
}

.components-base-control__field {
// Emsure label doesn't wrap beneath checkbox
display: flex;
}

.components-checkbox-control__label {
// Ensure label is aligned with checkbox along X axis
line-height: var(--checkbox-input-size);
}
.components-checkbox-control__label {
// Ensure label is aligned with checkbox along X axis
line-height: var(--checkbox-input-size);
}

.components-checkbox-control__input[type="checkbox"] {
Expand Down Expand Up @@ -67,8 +62,8 @@
margin-right: $grid-unit-15;
vertical-align: middle;
width: var(--checkbox-input-size);
height: var(--checkbox-input-size);
aspect-ratio: 1;
flex-shrink: 0;
}

svg.components-checkbox-control__checked,
Expand Down

0 comments on commit 55e5dc7

Please sign in to comment.