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

CheckboxControl: Add flag to remove bottom margin #43720

Merged
merged 2 commits into from
Aug 31, 2022
Merged
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
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- `Popover`: enable auto-updating every animation frame ([#43617](https://github.com/WordPress/gutenberg/pull/43617)).
- `Popover`: improve the component's performance and reactivity to prop changes by reworking its internals ([#43335](https://github.com/WordPress/gutenberg/pull/43335)).

### Enhancements

- `CheckboxControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43720](https://github.com/WordPress/gutenberg/pull/43720)).

### Internal

- Remove unused `normalizeArrowKey` utility function ([#43640](https://github.com/WordPress/gutenberg/pull/43640/)).
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/checkbox-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function CheckboxControl(
props: WordPressComponentProps< CheckboxControlProps, 'input', false >
) {
const {
__nextHasNoMarginBottom,
label,
className,
heading,
Expand Down Expand Up @@ -87,6 +88,7 @@ export function CheckboxControl(

return (
<BaseControl
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
label={ heading }
id={ id }
help={ help }
Expand Down
8 changes: 6 additions & 2 deletions packages/components/src/checkbox-control/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useState } from '@wordpress/element';
* Internal dependencies
*/
import CheckboxControl from '..';
import { VStack } from '../../v-stack';

const meta: ComponentMeta< typeof CheckboxControl > = {
component: CheckboxControl,
Expand Down Expand Up @@ -71,7 +72,7 @@ export const Indeterminate: ComponentStory< typeof CheckboxControl > = ( {
Object.values( fruits ).some( Boolean ) && ! isAllChecked;

return (
<>
<VStack>
<CheckboxControl
{ ...args }
checked={ isAllChecked }
Expand All @@ -85,6 +86,7 @@ export const Indeterminate: ComponentStory< typeof CheckboxControl > = ( {
} }
/>
<CheckboxControl
__nextHasNoMarginBottom
label="Apple"
checked={ fruits.apple }
onChange={ ( apple ) =>
Expand All @@ -95,6 +97,7 @@ export const Indeterminate: ComponentStory< typeof CheckboxControl > = ( {
}
/>
<CheckboxControl
__nextHasNoMarginBottom
label="Orange"
checked={ fruits.orange }
onChange={ ( orange ) =>
Expand All @@ -104,9 +107,10 @@ export const Indeterminate: ComponentStory< typeof CheckboxControl > = ( {
} ) )
}
/>
</>
</VStack>
);
};
Indeterminate.args = {
label: 'Select all',
__nextHasNoMarginBottom: true,
};
5 changes: 4 additions & 1 deletion packages/components/src/checkbox-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import type { ReactNode } from 'react';
*/
import type { BaseControlProps } from '../base-control/types';

export type CheckboxControlProps = Pick< BaseControlProps, 'help' > & {
export type CheckboxControlProps = Pick<
BaseControlProps,
'help' | '__nextHasNoMarginBottom'
> & {
/**
* A function that receives the checked state (boolean) as input.
*/
Expand Down