UNPKG

@atlaskit/primitives

Version:

Primitives are token-backed low-level building blocks.

91 lines (88 loc) 2.52 kB
/** * @jsxRuntime classic * @jsx jsx */ import React, { Children, forwardRef, Fragment, memo } from 'react'; // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 import { css, jsx } from '@emotion/react'; import { xcss } from '../xcss/xcss'; import Flex from './flex'; const flexGrowMap = { hug: xcss({ flexGrow: 0 }), fill: xcss({ width: '100%', flexGrow: 1 }) }; const separatorStyles = css({ color: "var(--ds-text-subtle, #42526E)", marginBlock: "var(--ds-space-0, 0px)", marginInline: `${"var(--ds-space-negative-025, -2px)"}`, pointerEvents: 'none', userSelect: 'none' }); const Separator = ({ children }) => jsx("span", { css: separatorStyles }, children); /** * __Inline__ * * Inline is a primitive component based on CSS Flexbox that manages the horizontal layout of direct children. * * @example * ```tsx * <Inline> * <Box padding="space.100" backgroundColor="neutral"></Box> * <Box padding="space.100" backgroundColor="neutral"></Box> * </Inline> * ``` * */ const Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({ as, alignInline, alignBlock: alignItems = 'start', shouldWrap = false, spread, grow, space, rowSpace, separator, xcss, testId, role, children: rawChildren }, ref) => { const separatorComponent = typeof separator === 'string' ? jsx(Separator, null, separator) : separator; const children = separatorComponent ? Children.toArray(rawChildren).filter(Boolean).map((child, index) => { return jsx(Fragment, { key: index }, separator && index > 0 ? separatorComponent : null, child); }) : rawChildren; const justifyContent = spread || alignInline; // We're type coercing this as Compiled styles in an array isn't supported by the types // But the runtime accepts it none-the-wiser. We can remove this entire block and replace // it with cx(defaultStyles, focusRingStyles, xcssStyles) when we've moved away from Emotion. const styles = grow ? [flexGrowMap[grow], ...(Array.isArray(xcss) ? xcss : [xcss])] : xcss; return jsx(Flex, { as: as, role: role, alignItems: alignItems, justifyContent: justifyContent, direction: "row", gap: space, rowGap: rowSpace, wrap: shouldWrap ? 'wrap' : undefined // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage , xcss: styles, testId: testId, ref: ref }, children); })); Inline.displayName = 'Inline'; export default Inline;