@atlaskit/primitives
Version:
Primitives are token-backed low-level building blocks.
95 lines (92 loc) • 3.08 kB
JavaScript
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
/* eslint-disable @repo/internal/styles/no-exported-styles */
/**
* @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';
var flexGrowMap = {
hug: xcss({
flexGrow: 0
}),
fill: xcss({
width: '100%',
flexGrow: 1
})
};
var 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'
});
var Separator = function Separator(_ref) {
var children = _ref.children;
return 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>
* ```
*
*/
var Inline = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref2, ref) {
var as = _ref2.as,
alignInline = _ref2.alignInline,
_ref2$alignBlock = _ref2.alignBlock,
alignItems = _ref2$alignBlock === void 0 ? 'start' : _ref2$alignBlock,
_ref2$shouldWrap = _ref2.shouldWrap,
shouldWrap = _ref2$shouldWrap === void 0 ? false : _ref2$shouldWrap,
spread = _ref2.spread,
grow = _ref2.grow,
space = _ref2.space,
rowSpace = _ref2.rowSpace,
separator = _ref2.separator,
xcss = _ref2.xcss,
testId = _ref2.testId,
role = _ref2.role,
rawChildren = _ref2.children;
var separatorComponent = typeof separator === 'string' ? jsx(Separator, null, separator) : separator;
var children = separatorComponent ? Children.toArray(rawChildren).filter(Boolean).map(function (child, index) {
return jsx(Fragment, {
key: index
}, separator && index > 0 ? separatorComponent : null, child);
}) : rawChildren;
var 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.
var styles = grow ? [flexGrowMap[grow]].concat(_toConsumableArray(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;