|
| 1 | +/** |
| 2 | + * Internal dependencies |
| 3 | + */ |
| 4 | +import { withNext } from '../ui/context'; |
| 5 | +import { |
| 6 | + Flex as NextFlex, |
| 7 | + FlexItem as NextFlexItem, |
| 8 | + FlexBlock as NextFlexBlock, |
| 9 | +} from '../ui/flex'; |
| 10 | + |
| 11 | +const Flex = process.env.COMPONENT_SYSTEM_PHASE === 1 ? NextFlex : undefined; |
| 12 | +const FlexBlock = |
| 13 | + process.env.COMPONENT_SYSTEM_PHASE === 1 ? NextFlexBlock : undefined; |
| 14 | +const FlexItem = |
| 15 | + process.env.COMPONENT_SYSTEM_PHASE === 1 ? NextFlexItem : undefined; |
| 16 | + |
| 17 | +/** |
| 18 | + * @param {import('./index').Props} props Current props. |
| 19 | + * @return {import('../ui/flex/types').FlexProps} Next props. |
| 20 | + */ |
| 21 | +const flexAdapter = ( { isReversed, ...restProps } ) => ( { |
| 22 | + // There's no equivalent for `direction` on the original component so we can just translate `isReversed` to it |
| 23 | + direction: isReversed ? 'row-reverse' : 'row', |
| 24 | + ...restProps, |
| 25 | + // There's an HTML attribute named `wrap` that will exist in `restProps` so we need to set it to undefined so the default behavior of the next component takes over |
| 26 | + wrap: undefined, |
| 27 | +} ); |
| 28 | + |
| 29 | +/** |
| 30 | + * @param {import('./item').Props} props Current props. |
| 31 | + * @return {import('../ui/flex/types').FlexItemProps} Next props. |
| 32 | + */ |
| 33 | +const flexItemAdapter = ( props ) => ( { |
| 34 | + ...props, |
| 35 | + // ensure these are undefined so the default takes over |
| 36 | + isBlock: undefined, |
| 37 | + display: undefined, |
| 38 | +} ); |
| 39 | + |
| 40 | +/** |
| 41 | + * @param {import('./block').Props} props Current props. |
| 42 | + * @return {import('../ui/flex/types').FlexBlockProps} Next props. |
| 43 | + */ |
| 44 | +const flexBlockAdapter = ( props ) => ( { |
| 45 | + ...props, |
| 46 | + // ensure this is undefined so the default takes over |
| 47 | + display: undefined, |
| 48 | +} ); |
| 49 | + |
| 50 | +/* eslint-disable jsdoc/valid-types */ |
| 51 | +/** |
| 52 | + * @param {import('react').ForwardRefExoticComponent<import('./index').Props>} Current |
| 53 | + */ |
| 54 | +/* eslint-enable jsdoc/valid-types */ |
| 55 | +export function withNextFlex( Current ) { |
| 56 | + return withNext( Current, Flex, 'WPComponentsFlex', flexAdapter ); |
| 57 | +} |
| 58 | + |
| 59 | +/* eslint-disable jsdoc/valid-types */ |
| 60 | +/** |
| 61 | + * @param {import('react').ForwardRefExoticComponent<import('./item').Props>} Current |
| 62 | + */ |
| 63 | +/* eslint-enable jsdoc/valid-types */ |
| 64 | +export function withNextFlexItem( Current ) { |
| 65 | + return withNext( Current, FlexItem, 'WPComponentsFlex', flexItemAdapter ); |
| 66 | +} |
| 67 | + |
| 68 | +/* eslint-disable jsdoc/valid-types */ |
| 69 | +/** |
| 70 | + * @param {import('react').ForwardRefExoticComponent<import('./block').Props>} Current |
| 71 | + */ |
| 72 | +/* eslint-enable jsdoc/valid-types */ |
| 73 | +export function withNextFlexBlock( Current ) { |
| 74 | + return withNext( Current, FlexBlock, 'WPComponentsFlex', flexBlockAdapter ); |
| 75 | +} |
0 commit comments