Skip to content

Commit

Permalink
FocalPointControl: Add flag to remove bottom margin (#43996)
Browse files Browse the repository at this point in the history
* FocalPointPicker: Add flag to remove bottom margin

* Maintain current bottom margin if there is help text

* Add changelog
  • Loading branch information
mirka authored Sep 12, 2022
1 parent 77b940d commit c1c046e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

- `ToggleControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43717](https://github.com/WordPress/gutenberg/pull/43717)).
- `CheckboxControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43720](https://github.com/WordPress/gutenberg/pull/43720)).
- `FocalPointControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43996](https://github.com/WordPress/gutenberg/pull/43996)).
- `TextControl`, `TextareaControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43782](https://github.com/WordPress/gutenberg/pull/43782)).
- `Flex`: Remove margin-based polyfill implementation of flex `gap` ([#43995](https://github.com/WordPress/gutenberg/pull/43995)).
- `RangeControl`: Tweak dark gray marking color to be consistent with the grays in `@wordpress/base-styles` ([#43773](https://github.com/WordPress/gutenberg/pull/43773)).
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/focal-point-picker/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const TEXTCONTROL_MAX = 100;
const noop = () => {};

export default function FocalPointPickerControls( {
__nextHasNoMarginBottom,
hasHelpText,
onChange = noop,
point = {
x: 0.5,
Expand All @@ -45,7 +47,11 @@ export default function FocalPointPickerControls( {
};

return (
<ControlWrapper className="focal-point-picker__controls">
<ControlWrapper
className="focal-point-picker__controls"
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
hasHelpText={ hasHelpText }
>
<FocalPointUnitControl
label={ __( 'Left' ) }
value={ [ valueX, '%' ].join( '' ) }
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/focal-point-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const GRID_OVERLAY_TIMEOUT = 600;
* ```
*/
export function FocalPointPicker( {
__nextHasNoMarginBottom,
autoPlay = true,
className,
help,
Expand Down Expand Up @@ -239,6 +240,7 @@ export function FocalPointPicker( {
return (
<BaseControl
{ ...restProps }
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
label={ label }
id={ id }
help={ help }
Expand Down Expand Up @@ -270,6 +272,8 @@ export function FocalPointPicker( {
</MediaContainer>
</MediaWrapper>
<Controls
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
hasHelpText={ !! help }
point={ { x, y } }
onChange={ ( value ) => {
onChange?.( getFinalValue( value ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { css } from '@emotion/react';
import styled from '@emotion/styled';

/**
Expand All @@ -9,6 +10,7 @@ import styled from '@emotion/styled';
import { Flex } from '../../flex';
import UnitControl from '../../unit-control';
import { COLORS } from '../../utils';
import type { FocalPointPickerControlsProps } from '../types';
import { INITIAL_BOUNDS } from '../utils';

export const MediaWrapper = styled.div`
Expand Down Expand Up @@ -54,9 +56,32 @@ export const StyledUnitControl = styled( UnitControl )`
width: 100px;
`;

const deprecatedBottomMargin = ( {
__nextHasNoMarginBottom,
}: FocalPointPickerControlsProps ) => {
return ! __nextHasNoMarginBottom
? css`
padding-bottom: 1em;
`
: undefined;
};

const extraHelpTextMargin = ( {
hasHelpText = false,
}: FocalPointPickerControlsProps ) => {
return hasHelpText
? css`
padding-bottom: 1em;
`
: undefined;
};

export const ControlWrapper = styled( Flex )`
max-width: 320px;
padding: 1em 0;
padding-top: 1em;
${ extraHelpTextMargin }
${ deprecatedBottomMargin }
`;

export const GridView = styled.div`
Expand Down
12 changes: 12 additions & 0 deletions packages/components/src/focal-point-picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export type FocalPointPickerProps = Pick<
BaseControlProps,
'help' | 'hideLabelFromVision' | 'label'
> & {
/**
* Start opting into the new margin-free styles that will become the default in a future version.
*
* @default false
*/
__nextHasNoMarginBottom?: boolean;
/**
* Autoplays HTML5 video. This only applies to video sources (`url`).
*
Expand Down Expand Up @@ -55,6 +61,12 @@ export type FocalPointPickerProps = Pick<
};

export type FocalPointPickerControlsProps = {
__nextHasNoMarginBottom?: boolean;
/**
* A bit of extra bottom margin will be added if a `help` text
* needs to be rendered under it.
*/
hasHelpText: boolean;
onChange?: ( value: FocalPoint ) => void;
point?: FocalPoint;
};
Expand Down

0 comments on commit c1c046e

Please sign in to comment.