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

Add possibility to position help text below the label of CheckboxControl component #30025

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
26 changes: 19 additions & 7 deletions packages/components/src/checkbox-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { Icon, check } from '@wordpress/icons';
* Internal dependencies
*/
import BaseControl from '../base-control';
import { StyledHelp } from '../base-control/styles/base-control-styles';

export default function CheckboxControl( {
label,
className,
heading,
checked,
help,
helpPosition = 'left',
onChange,
...props
} ) {
Expand All @@ -26,7 +28,7 @@ export default function CheckboxControl( {
<BaseControl
label={ heading }
id={ id }
help={ help }
help={ helpPosition === 'left' ? help : '' }
className={ className }
>
<span className="components-checkbox-control__input-container">
Expand All @@ -48,12 +50,22 @@ export default function CheckboxControl( {
/>
) : null }
</span>
<label
className="components-checkbox-control__label"
htmlFor={ id }
>
{ label }
</label>
<span className="components-checkbox-control__label-container">
<label
className="components-checkbox-control__label"
htmlFor={ id }
>
{ label }
</label>
{ helpPosition === 'center' && (
<StyledHelp
id={ id + '__help' }
className="components-base-control__help"
>
{ help }
</StyledHelp>
) }
</span>
</BaseControl>
);
}
11 changes: 10 additions & 1 deletion packages/components/src/checkbox-control/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { text } from '@storybook/addon-knobs';
import { select, text } from '@storybook/addon-knobs';

/**
* WordPress dependencies
Expand Down Expand Up @@ -40,12 +40,21 @@ export const all = () => {
const heading = text( 'Heading', 'User' );
const label = text( 'Label', 'Is author' );
const help = text( 'Help', 'Is the user an author or not?' );
const helpPosition = select(
'align',
{
left: 'left',
center: 'center',
},
'center'
);

return (
<CheckboxControlWithState
heading={ heading }
label={ label }
help={ help }
helpPosition={ helpPosition }
checked
/>
);
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/checkbox-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,16 @@ svg.components-checkbox-control__checked {
user-select: none;
pointer-events: none;
}

.components-checkbox-control__label-container {
display: inline-block;
}

.components-checkbox-control__centered-help-text {
position: fixed;
}

.components-checkbox-control__label-container .components-base-control__help {
margin: 0;
position: fixed;
}