diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb0dd26c6d..d450414b735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ ## [`master`](https://github.com/elastic/eui/tree/master) +<<<<<<< HEAD +- Allow `EuiFlexGroup` to accept a `ref` ([#2223](https://github.com/elastic/eui/pull/2223)) + +**Bug fixes** +======= - Fixed `EuiSuperDatePicker` to update `asyncInterval.isStopped` on a `isPaused` prop change. ([#2250](https://github.com/elastic/eui/pull/2250)) - Converted table, popover, buttons, pagination, outside click detector, focus trap, context menu, and panel to TypeScript ([#2212](https://github.com/elastic/eui/pull/2212)) ## [`13.5.0`](https://github.com/elastic/eui/tree/v13.5.0) +>>>>>>> master - Fixed `logoCloudEnterprise`, `logoLogging`, and `logoSecurity` SVGs in `EuiIcon` to be center aligned ([#2246](https://github.com/elastic/eui/pull/2246)) - Added locking behavior of `EuiNavDrawer` expanded state inluding the following props `isLocked`, `onIsLockedUpdate` ([#2247](https://github.com/elastic/eui/pull/2247)) diff --git a/src/components/flex/flex_group.tsx b/src/components/flex/flex_group.tsx index 00070311090..69ee61ae20a 100644 --- a/src/components/flex/flex_group.tsx +++ b/src/components/flex/flex_group.tsx @@ -1,4 +1,4 @@ -import React, { HTMLAttributes, FunctionComponent } from 'react'; +import React, { HTMLAttributes, Ref, forwardRef } from 'react'; import classNames from 'classnames'; import { CommonProps, keysOf } from '../common'; @@ -59,38 +59,69 @@ const directionToClassNameMap = { export const DIRECTIONS = keysOf(directionToClassNameMap); -export const EuiFlexGroup: FunctionComponent< +const isValidElement = ( + component: string +): component is FlexGroupComponentType => { + return ['div', 'span'].includes(component); +}; + +const EuiFlexGroup = forwardRef< + HTMLDivElement | HTMLSpanElement, CommonProps & HTMLAttributes & EuiFlexGroupProps -> = ({ - children, - className, - gutterSize = 'l', - alignItems = 'stretch', - responsive = true, - justifyContent = 'flexStart', - direction = 'row', - wrap = false, - component: Component = 'div', - ...rest -}) => { - const classes = classNames( - 'euiFlexGroup', - gutterSize ? gutterSizeToClassNameMap[gutterSize] : undefined, - alignItems ? alignItemsToClassNameMap[alignItems] : undefined, - justifyContent ? justifyContentToClassNameMap[justifyContent] : undefined, - direction ? directionToClassNameMap[direction] : undefined, +>( + ( { - 'euiFlexGroup--responsive': responsive, - 'euiFlexGroup--wrap': wrap, + children, + className, + gutterSize = 'l', + alignItems = 'stretch', + responsive = true, + justifyContent = 'flexStart', + direction = 'row', + wrap = false, + component = 'div', + ...rest }, - className - ); + ref: Ref | Ref + ) => { + const classes = classNames( + 'euiFlexGroup', + gutterSizeToClassNameMap[gutterSize as FlexGroupGutterSize], + alignItemsToClassNameMap[alignItems as FlexGroupAlignItems], + justifyContentToClassNameMap[justifyContent as FlexGroupJustifyContent], + directionToClassNameMap[direction as FlexGroupDirection], + { + 'euiFlexGroup--responsive': responsive, + 'euiFlexGroup--wrap': wrap, + }, + className + ); - return ( - - {children} - - ); -}; + if (!isValidElement(component)) { + throw new Error( + `${component} is not a valid element type. Use \`div\` or \`span\`.` + ); + } + + return component === 'span' ? ( + } + {...rest as HTMLAttributes}> + {children} + + ) : ( +
} + {...rest as HTMLAttributes}> + {children} +
+ ); + } +); +EuiFlexGroup.displayName = 'EuiFlexGroup'; + +export { EuiFlexGroup };