-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
BorderControls: Alternate approach to handling popover positioning #40874
Changes from all commits
3621019
495b61d
a813973
3aea82f
5a62136
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { useMemo } from '@wordpress/element'; | |
import * as styles from '../styles'; | ||
import { parseQuantityAndUnitFromRawValue } from '../../unit-control/utils'; | ||
import { useContextSystem, WordPressComponentProps } from '../../ui/context'; | ||
import { useResponsiveValue } from '../../ui/utils/use-responsive-value'; | ||
import { useCx } from '../../utils/hooks/use-cx'; | ||
|
||
import type { DropdownProps } from '../types'; | ||
|
@@ -20,9 +21,10 @@ export function useBorderControlDropdown( | |
border, | ||
className, | ||
colors, | ||
contentClassName, | ||
onChange, | ||
previousStyleSelection, | ||
__experimentalIsRenderedInSidebar, | ||
__experimentalSide, | ||
...otherProps | ||
} = useContextSystem( props, 'BorderControlDropdown' ); | ||
|
||
|
@@ -64,18 +66,26 @@ export function useBorderControlDropdown( | |
return cx( styles.colorIndicatorWrapper( border ) ); | ||
}, [ border, cx ] ); | ||
|
||
// We only want to apply adjusted popover content styles when on desktop. | ||
const responsiveSide = useResponsiveValue( [ | ||
undefined, | ||
undefined, | ||
__experimentalSide, | ||
] ); | ||
Comment on lines
+69
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find the |
||
|
||
const popoverClassName = useMemo( () => { | ||
return cx( styles.borderControlPopover, contentClassName ); | ||
}, [ cx, contentClassName ] ); | ||
return cx( | ||
styles.borderControlPopover( | ||
__experimentalIsRenderedInSidebar, | ||
responsiveSide | ||
) | ||
); | ||
}, [ cx, __experimentalIsRenderedInSidebar, responsiveSide ] ); | ||
|
||
const popoverControlsClassName = useMemo( () => { | ||
return cx( styles.borderControlPopoverControls ); | ||
}, [ cx ] ); | ||
|
||
const popoverContentClassName = useMemo( () => { | ||
return cx( styles.borderControlPopoverContent ); | ||
}, [ cx ] ); | ||
|
||
const resetButtonClassName = useMemo( () => { | ||
return cx( styles.resetButton ); | ||
}, [ cx ] ); | ||
|
@@ -90,9 +100,9 @@ export function useBorderControlDropdown( | |
onColorChange, | ||
onStyleChange, | ||
onReset, | ||
popoverClassName, | ||
popoverContentClassName, | ||
popoverProps: { className: popoverClassName }, | ||
popoverControlsClassName, | ||
resetButtonClassName, | ||
__experimentalIsRenderedInSidebar, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ import Popover from '../../popover'; | |
export default { | ||
title: 'Components (Experimental)/BorderControl', | ||
component: BorderControl, | ||
argTypes: { | ||
__experimentalSide: { | ||
options: [ undefined, 'all', 'left', 'top', 'right', 'bottom' ], | ||
}, | ||
}, | ||
Comment on lines
+21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tweaking the I wonder if we should disable the interactive controls for the story and/or create an ad-hoc story to showcase the "render in sidebar" scenario? |
||
}; | ||
|
||
// Available border colors. | ||
|
@@ -111,6 +116,7 @@ Default.args = { | |
withSlider: true, | ||
__experimentalIsRenderedInSidebar: false, | ||
__experimentalHasMultipleOrigins: false, | ||
__experimentalSide: undefined, | ||
}; | ||
|
||
const WrapperView = styled.div` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found while testing this the alignment of the right border control was out of whack when on tablet or mobile viewports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make a note to apply this fix even in case this PR doesn't get merged.