-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Borders: Add BorderBoxControl component #38876
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ac742b3
Add BorderBoxControl component
aaronrobertshaw d318d89
Add RTL styles for split border controls
aaronrobertshaw 21757a4
Use ForwardRef for typing instead of Ref
aaronrobertshaw 9062684
Move inline visualizer styles to dynamic class
aaronrobertshaw d325422
Add RTL styles for BorderBoxControlVisualizer
aaronrobertshaw ad3f0e2
Avoid using hardcoded DOM element
aaronrobertshaw 1ac2425
Use Grid for split controls layout
aaronrobertshaw 821d780
Prevent application of value prop on visualizer element
aaronrobertshaw 263f3a1
Refactor clamped and shorthand border style generation
aaronrobertshaw 804ec2a
Update BorderBoxControl tests to match latest aria labels
aaronrobertshaw ca889df
Add visually hidden labels for split border controls
aaronrobertshaw 1aeb812
Add SlotFill provider as wrapper to storybook example
aaronrobertshaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add BorderBoxControl component
This provides a component through which you can configure separate borders for individual sides.
- Loading branch information
commit ac742b3a1ae0ae7049c7dfc52e8d8ad597036982
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/components/src/border-box-control/border-box-control-linked-button/component.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { link, linkOff } from '@wordpress/icons'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import Button from '../../button'; | ||
| import Tooltip from '../../tooltip'; | ||
| import { contextConnect, WordPressComponentProps } from '../../ui/context'; | ||
| import { useBorderBoxControlLinkedButton } from './hook'; | ||
|
|
||
| import type { LinkedButtonProps } from '../types'; | ||
|
|
||
| const BorderBoxControlLinkedButton = ( | ||
| props: WordPressComponentProps< LinkedButtonProps, 'div' >, | ||
| forwardedRef: React.Ref< any > | ||
| ) => { | ||
| const { | ||
| className, | ||
| isLinked, | ||
| ...buttonProps | ||
| } = useBorderBoxControlLinkedButton( props ); | ||
| const label = isLinked ? __( 'Unlink sides' ) : __( 'Link sides' ); | ||
|
|
||
| return ( | ||
| <Tooltip text={ label }> | ||
| <div className={ className }> | ||
| <Button | ||
| { ...buttonProps } | ||
| variant={ isLinked ? 'primary' : 'secondary' } | ||
| isSmall | ||
| icon={ isLinked ? link : linkOff } | ||
| iconSize={ 16 } | ||
| aria-label={ label } | ||
| ref={ forwardedRef } | ||
| /> | ||
| </div> | ||
| </Tooltip> | ||
| ); | ||
| }; | ||
|
|
||
| const ConnectedBorderBoxControlLinkedButton = contextConnect( | ||
| BorderBoxControlLinkedButton, | ||
| 'BorderBoxControlLinkedButton' | ||
| ); | ||
| export default ConnectedBorderBoxControlLinkedButton; |
30 changes: 30 additions & 0 deletions
30
packages/components/src/border-box-control/border-box-control-linked-button/hook.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useMemo } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import * as styles from '../styles'; | ||
| import { useContextSystem, WordPressComponentProps } from '../../ui/context'; | ||
| import { useCx } from '../../utils/hooks/use-cx'; | ||
|
|
||
| import type { LinkedButtonProps } from '../types'; | ||
|
|
||
| export function useBorderBoxControlLinkedButton( | ||
| props: WordPressComponentProps< LinkedButtonProps, 'div' > | ||
| ) { | ||
| const { className, ...otherProps } = useContextSystem( | ||
| props, | ||
| 'BorderBoxControlLinkedButton' | ||
| ); | ||
|
|
||
| // Generate class names. | ||
| const cx = useCx(); | ||
| const classes = useMemo( () => { | ||
| return cx( styles.BorderBoxControlLinkedButton, className ); | ||
| }, [ className ] ); | ||
|
|
||
| return { ...otherProps, className: classes }; | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/components/src/border-box-control/border-box-control-linked-button/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './component'; |
77 changes: 77 additions & 0 deletions
77
packages/components/src/border-box-control/border-box-control-split-controls/component.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import BorderBoxControlVisualizer from '../border-box-control-visualizer'; | ||
| import { BorderControl } from '../../border-control'; | ||
| import { View } from '../../view'; | ||
| import { contextConnect, WordPressComponentProps } from '../../ui/context'; | ||
| import { useBorderBoxControlSplitControls } from './hook'; | ||
|
|
||
| import type { SplitControlsProps } from '../types'; | ||
|
|
||
| const BorderBoxControlSplitControls = ( | ||
| props: WordPressComponentProps< SplitControlsProps, 'div' >, | ||
| forwardedRef: React.Ref< any > | ||
| ) => { | ||
| const { | ||
| centeredClassName, | ||
| colors, | ||
| disableCustomColors, | ||
| enableAlpha, | ||
| enableStyle, | ||
| onChange, | ||
| value, | ||
| __experimentalHasMultipleOrigins, | ||
| __experimentalIsRenderedInSidebar, | ||
| ...otherProps | ||
| } = useBorderBoxControlSplitControls( props ); | ||
|
|
||
| const sharedBorderControlProps = { | ||
| colors, | ||
| disableCustomColors, | ||
| enableAlpha, | ||
| enableStyle, | ||
| isCompact: true, | ||
| __experimentalHasMultipleOrigins, | ||
| __experimentalIsRenderedInSidebar, | ||
| }; | ||
|
|
||
| return ( | ||
| <View { ...otherProps } ref={ forwardedRef }> | ||
| <BorderBoxControlVisualizer value={ value } /> | ||
| <BorderControl | ||
| className={ centeredClassName } | ||
| onChange={ ( newBorder ) => onChange( newBorder, 'top' ) } | ||
| value={ value?.top } | ||
| { ...sharedBorderControlProps } | ||
| /> | ||
| <BorderControl | ||
| onChange={ ( newBorder ) => onChange( newBorder, 'left' ) } | ||
| value={ value?.left } | ||
| { ...sharedBorderControlProps } | ||
| /> | ||
| <BorderControl | ||
| onChange={ ( newBorder ) => onChange( newBorder, 'right' ) } | ||
| value={ value?.right } | ||
| { ...sharedBorderControlProps } | ||
| /> | ||
| <BorderControl | ||
| className={ centeredClassName } | ||
| onChange={ ( newBorder ) => onChange( newBorder, 'bottom' ) } | ||
| value={ value?.bottom } | ||
| { ...sharedBorderControlProps } | ||
| /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| const ConnectedBorderBoxControlSplitControls = contextConnect( | ||
| BorderBoxControlSplitControls, | ||
| 'BorderBoxControlSplitControls' | ||
| ); | ||
| export default ConnectedBorderBoxControlSplitControls; | ||
34 changes: 34 additions & 0 deletions
34
packages/components/src/border-box-control/border-box-control-split-controls/hook.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useMemo } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import * as styles from '../styles'; | ||
| import { useContextSystem, WordPressComponentProps } from '../../ui/context'; | ||
| import { useCx } from '../../utils/hooks/use-cx'; | ||
|
|
||
| import type { SplitControlsProps } from '../types'; | ||
|
|
||
| export function useBorderBoxControlSplitControls( | ||
| props: WordPressComponentProps< SplitControlsProps, 'div' > | ||
| ) { | ||
| const { className, ...otherProps } = useContextSystem( | ||
| props, | ||
| 'BorderBoxControlSplitControls' | ||
| ); | ||
|
|
||
| // Generate class names. | ||
| const cx = useCx(); | ||
| const classes = useMemo( () => { | ||
| return cx( styles.BorderBoxControlSplitControls, className ); | ||
| }, [ className ] ); | ||
|
|
||
| const centeredClassName = useMemo( () => { | ||
| return cx( styles.CenteredBorderControl, className ); | ||
| }, [] ); | ||
|
|
||
| return { ...otherProps, centeredClassName, className: classes }; | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/components/src/border-box-control/border-box-control-split-controls/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './component'; |
35 changes: 35 additions & 0 deletions
35
packages/components/src/border-box-control/border-box-control-visualizer/component.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { View } from '../../view'; | ||
| import { contextConnect, WordPressComponentProps } from '../../ui/context'; | ||
| import { getClampedWidthBorderStyle } from '../utils'; | ||
| import { useBorderBoxControlVisualizer } from './hook'; | ||
|
|
||
| import type { VisualizerProps } from '../types'; | ||
|
|
||
| const BorderBoxControlVisualizer = ( | ||
| props: WordPressComponentProps< VisualizerProps, 'div' >, | ||
| forwardedRef: React.Ref< any > | ||
| ) => { | ||
| const { value, ...otherProps } = useBorderBoxControlVisualizer( props ); | ||
| const styles = { | ||
| borderTop: getClampedWidthBorderStyle( value?.top ), | ||
| borderRight: getClampedWidthBorderStyle( value?.right ), | ||
| borderBottom: getClampedWidthBorderStyle( value?.bottom ), | ||
| borderLeft: getClampedWidthBorderStyle( value?.left ), | ||
| }; | ||
aaronrobertshaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return <View { ...otherProps } ref={ forwardedRef } style={ styles } />; | ||
aaronrobertshaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const ConnectedBorderBoxControlVisualizer = contextConnect( | ||
| BorderBoxControlVisualizer, | ||
| 'BorderBoxControlVisualizer' | ||
| ); | ||
| export default ConnectedBorderBoxControlVisualizer; | ||
30 changes: 30 additions & 0 deletions
30
packages/components/src/border-box-control/border-box-control-visualizer/hook.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useMemo } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import * as styles from '../styles'; | ||
| import { useContextSystem, WordPressComponentProps } from '../../ui/context'; | ||
| import { useCx } from '../../utils/hooks/use-cx'; | ||
|
|
||
| import type { VisualizerProps } from '../types'; | ||
|
|
||
| export function useBorderBoxControlVisualizer( | ||
| props: WordPressComponentProps< VisualizerProps, 'div' > | ||
| ) { | ||
| const { className, ...otherProps } = useContextSystem( | ||
| props, | ||
| 'BorderBoxControlVisualizer' | ||
| ); | ||
|
|
||
| // Generate class names. | ||
| const cx = useCx(); | ||
| const classes = useMemo( () => { | ||
| return cx( styles.BorderBoxControlVisualizer, className ); | ||
| }, [ className ] ); | ||
|
|
||
| return { ...otherProps, className: classes }; | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/components/src/border-box-control/border-box-control-visualizer/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './component'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.