-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Borders: Add BorderBoxControl component (#38876)
- Loading branch information
1 parent
ddbb8c3
commit b9d579f
Showing
23 changed files
with
1,732 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
50 changes: 50 additions & 0 deletions
50
packages/components/src/border-box-control/border-box-control-linked-button/component.tsx
This file contains 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,50 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { link, linkOff } from '@wordpress/icons'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Button from '../../button'; | ||
import Tooltip from '../../tooltip'; | ||
import { View } from '../../view'; | ||
import { contextConnect, WordPressComponentProps } from '../../ui/context'; | ||
import { useBorderBoxControlLinkedButton } from './hook'; | ||
|
||
import type { LinkedButtonProps } from '../types'; | ||
|
||
const BorderBoxControlLinkedButton = ( | ||
props: WordPressComponentProps< LinkedButtonProps, 'div' >, | ||
forwardedRef: React.ForwardedRef< any > | ||
) => { | ||
const { | ||
className, | ||
isLinked, | ||
...buttonProps | ||
} = useBorderBoxControlLinkedButton( props ); | ||
const label = isLinked ? __( 'Unlink sides' ) : __( 'Link sides' ); | ||
|
||
return ( | ||
<Tooltip text={ label }> | ||
<View className={ className }> | ||
<Button | ||
{ ...buttonProps } | ||
variant={ isLinked ? 'primary' : 'secondary' } | ||
isSmall | ||
icon={ isLinked ? link : linkOff } | ||
iconSize={ 16 } | ||
aria-label={ label } | ||
ref={ forwardedRef } | ||
/> | ||
</View> | ||
</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 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 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'; |
85 changes: 85 additions & 0 deletions
85
packages/components/src/border-box-control/border-box-control-split-controls/component.tsx
This file contains 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,85 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BorderBoxControlVisualizer from '../border-box-control-visualizer'; | ||
import { BorderControl } from '../../border-control'; | ||
import { Grid } from '../../grid'; | ||
import { contextConnect, WordPressComponentProps } from '../../ui/context'; | ||
import { useBorderBoxControlSplitControls } from './hook'; | ||
|
||
import type { SplitControlsProps } from '../types'; | ||
|
||
const BorderBoxControlSplitControls = ( | ||
props: WordPressComponentProps< SplitControlsProps, 'div' >, | ||
forwardedRef: React.ForwardedRef< 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 ( | ||
<Grid { ...otherProps } ref={ forwardedRef } gap={ 4 }> | ||
<BorderBoxControlVisualizer value={ value } /> | ||
<BorderControl | ||
className={ centeredClassName } | ||
hideLabelFromVision={ true } | ||
label={ __( 'Top border' ) } | ||
onChange={ ( newBorder ) => onChange( newBorder, 'top' ) } | ||
value={ value?.top } | ||
{ ...sharedBorderControlProps } | ||
/> | ||
<BorderControl | ||
hideLabelFromVision={ true } | ||
label={ __( 'Left border' ) } | ||
onChange={ ( newBorder ) => onChange( newBorder, 'left' ) } | ||
value={ value?.left } | ||
{ ...sharedBorderControlProps } | ||
/> | ||
<BorderControl | ||
hideLabelFromVision={ true } | ||
label={ __( 'Right border' ) } | ||
onChange={ ( newBorder ) => onChange( newBorder, 'right' ) } | ||
value={ value?.right } | ||
{ ...sharedBorderControlProps } | ||
/> | ||
<BorderControl | ||
className={ centeredClassName } | ||
hideLabelFromVision={ true } | ||
label={ __( 'Bottom border' ) } | ||
onChange={ ( newBorder ) => onChange( newBorder, 'bottom' ) } | ||
value={ value?.bottom } | ||
{ ...sharedBorderControlProps } | ||
/> | ||
</Grid> | ||
); | ||
}; | ||
|
||
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 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, rtl } from '../../utils/'; | ||
|
||
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, rtl.watch() ] ); | ||
|
||
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 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'; |
28 changes: 28 additions & 0 deletions
28
packages/components/src/border-box-control/border-box-control-visualizer/component.tsx
This file contains 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,28 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { View } from '../../view'; | ||
import { contextConnect, WordPressComponentProps } from '../../ui/context'; | ||
import { useBorderBoxControlVisualizer } from './hook'; | ||
|
||
import type { VisualizerProps } from '../types'; | ||
|
||
const BorderBoxControlVisualizer = ( | ||
props: WordPressComponentProps< VisualizerProps, 'div' >, | ||
forwardedRef: React.ForwardedRef< any > | ||
) => { | ||
const { value, ...otherProps } = useBorderBoxControlVisualizer( props ); | ||
|
||
return <View { ...otherProps } ref={ forwardedRef } />; | ||
}; | ||
|
||
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 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, rtl } from '../../utils'; | ||
|
||
import type { VisualizerProps } from '../types'; | ||
|
||
export function useBorderBoxControlVisualizer( | ||
props: WordPressComponentProps< VisualizerProps, 'div' > | ||
) { | ||
const { className, value, ...otherProps } = useContextSystem( | ||
props, | ||
'BorderBoxControlVisualizer' | ||
); | ||
|
||
// Generate class names. | ||
const cx = useCx(); | ||
const classes = useMemo( () => { | ||
return cx( styles.BorderBoxControlVisualizer( value ), className ); | ||
}, [ className, value, rtl.watch() ] ); | ||
|
||
return { ...otherProps, className: classes, value }; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/components/src/border-box-control/border-box-control-visualizer/index.ts
This file contains 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.