Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Switch border control dropdown to popoverProps
  • Loading branch information
aaronrobertshaw committed May 5, 2022
commit 49d1f652774bc8edde9e822a591dc6087b1a5ff5
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const BorderControlDropdown = (
onReset,
onColorChange,
onStyleChange,
popoverClassName,
popoverProps,
popoverControlsClassName,
resetButtonClassName,
showDropdownHeader,
Expand Down Expand Up @@ -236,7 +236,7 @@ const BorderControlDropdown = (
<Dropdown
renderToggle={ renderToggle }
renderContent={ renderContent }
popoverProps={ { className: popoverClassName } }
popoverProps={ popoverProps }
{ ...otherProps }
ref={ forwardedRef }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export function useBorderControlDropdown(
border,
className,
colors,
contentClassName,
onChange,
popoverProps,
previousStyleSelection,
...otherProps
} = useContextSystem( props, 'BorderControlDropdown' );
Expand Down Expand Up @@ -65,8 +65,8 @@ export function useBorderControlDropdown(
}, [ border, cx ] );

const popoverClassName = useMemo( () => {
return cx( styles.borderControlPopover, contentClassName );
}, [ cx, contentClassName ] );
return cx( styles.borderControlPopover, popoverProps?.className );
}, [ cx, popoverProps?.className ] );

const popoverControlsClassName = useMemo( () => {
return cx( styles.borderControlPopoverControls );
Expand All @@ -86,7 +86,7 @@ export function useBorderControlDropdown(
onColorChange,
onStyleChange,
onReset,
popoverClassName,
popoverProps: { ...popoverProps, className: popoverClassName },
popoverControlsClassName,
resetButtonClassName,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ const BorderControl = (
<BorderControlDropdown
border={ border }
colors={ colors }
contentClassName={ popoverContentClassName }
disableCustomColors={ disableCustomColors }
enableAlpha={ enableAlpha }
enableStyle={ enableStyle }
onChange={ onBorderChange }
popoverProps={ { className: popoverContentClassName } }
previousStyleSelection={ previousStyleSelection }
showDropdownHeader={ showDropdownHeader }
__experimentalHasMultipleOrigins={
Expand Down
28 changes: 23 additions & 5 deletions packages/components/src/border-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,31 @@ export type BorderControlProps = ColorProps &
withSlider?: boolean;
};

/**
* Represents the available props that can be passed through the border control
* dropdown's `popoverProps`. This should be replaced once the Dropdown or
* Popover components are typed.
*/
type DropdownPopoverProps = {
className?: string;
focusOnMount?: boolean;
position?: string;
onClose?: () => void;
onFocusOutside?: () => void;
expandOnMobile?: boolean;
headerTitle?: string;
noArrow?: boolean;
anchorRect?: DOMRect;
getAnchorRect?: ( ref: HTMLAnchorElement ) => DOMRect;
};

export type DropdownProps = ColorProps & {
/**
* An object representing a border or `undefined`. This component will
* extract the border color and style selections from this object to use as
* values for its popover controls.
*/
border?: Border;
/**
* A custom CSS class name to be assigned to the border control's
* dropdown popover content.
*/
contentClassName?: string;
/**
* This controls whether to render border style options.
*
Expand All @@ -138,6 +151,11 @@ export type DropdownProps = ColorProps & {
* A callback invoked when the border color or style selections change.
*/
onChange: ( newBorder?: Border ) => void;
/**
* Properties of the `popoverProps` object will be passed as props to the
* border control's dropdown popover.
*/
popoverProps?: DropdownPopoverProps;
/**
* Any previous style selection made by the user. This can be used to
* reapply that previous selection when, for example, a zero border width is
Expand Down