-
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
Components: Stop re-exporting experimental utilities from @wordpress/components
#62155
base: trunk
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { | ||
Border, | ||
AnyBorder, | ||
Borders, | ||
BorderProp, | ||
BorderSide, | ||
} from './types'; | ||
|
||
const sides: BorderSide[] = [ 'top', 'right', 'bottom', 'left' ]; | ||
const borderProps: BorderProp[] = [ 'color', 'style', 'width' ]; | ||
|
||
const isEmptyBorder = ( border?: Border ) => { | ||
if ( ! border ) { | ||
return true; | ||
} | ||
return ! borderProps.some( ( prop ) => border[ prop ] !== undefined ); | ||
}; | ||
|
||
export const isDefinedBorder = ( border: AnyBorder ) => { | ||
// No border, no worries :) | ||
if ( ! border ) { | ||
return false; | ||
} | ||
|
||
// If we have individual borders per side within the border object we | ||
// need to check whether any of those side borders have been set. | ||
if ( hasSplitBorders( border ) ) { | ||
const allSidesEmpty = sides.every( ( side ) => | ||
isEmptyBorder( ( border as Borders )[ side ] ) | ||
); | ||
|
||
return ! allSidesEmpty; | ||
} | ||
|
||
// If we have a top-level border only, check if that is empty. e.g. | ||
// { color: undefined, style: undefined, width: undefined } | ||
// Border radius can still be set within the border object as it is | ||
// handled separately. | ||
return ! isEmptyBorder( border as Border ); | ||
}; | ||
|
||
export const hasSplitBorders = ( border: AnyBorder = {} ) => { | ||
return Object.keys( border ).some( | ||
( side ) => sides.indexOf( side as BorderSide ) !== -1 | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { CSSProperties } from 'react'; | ||
|
||
export type Border = { | ||
color?: CSSProperties[ 'borderColor' ]; | ||
style?: CSSProperties[ 'borderStyle' ]; | ||
width?: CSSProperties[ 'borderWidth' ]; | ||
}; | ||
|
||
export type Borders = { | ||
top?: Border; | ||
right?: Border; | ||
bottom?: Border; | ||
left?: Border; | ||
}; | ||
|
||
export type AnyBorder = Border | Borders | undefined; | ||
export type BorderProp = keyof Border; | ||
export type BorderSide = keyof Borders; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ export { | |
|
||
export { default as __experimentalStyleProvider } from './style-provider'; | ||
export { default as BaseControl } from './base-control'; | ||
// @todo review this RN export | ||
export { hasSplitBorders as __experimentalHasSplitBorders } from './border-box-control/utils'; | ||
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 don't know much about our RN setup. If we go with the approach in this PR, should we also remove this and copy it over closer to where the native is? I'm not sure if we should also remove it from RN at this point. I did search throughout GB, and it also looks like it's not being used by RN consumers in the codebase, but I'm not sure if it could be used by other third-party RN packages. 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. @dcalhoun @WordPress/native-mobile can you please confirm that it's safe to remove this export? Thank you! 🙏 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. 👋🏻 Thanks for the ping. The mobile unit tests are passing on the CI server, so that is a good sign. 😄 I did not encountering any issues after checking out the proposed changes and "smoke testing" the editor on an iPhone simulator. From quickly reviewing the related code, my perception is that |
||
export { default as TextareaControl } from './textarea-control'; | ||
export { default as PanelBody } from './panel/body'; | ||
|
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.
Would the
packages/block-editor/src/utils
be a better folder instead of thecomponents
folder for these utils?