@atlaskit/breadcrumbs
Version:
Breadcrumbs are a navigation system used to show a user's location in a site or app.
147 lines (146 loc) • 9.81 kB
JavaScript
/* step.tsx generated by @compiled/babel-plugin v3.0.2 */
import _extends from "@babel/runtime/helpers/extends";
import "./step.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { forwardRef, Fragment } from 'react';
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next/usePlatformLeafEventHandler';
import { cx } from '@atlaskit/css';
import __noop from '@atlaskit/ds-lib/noop';
import { fg } from '@atlaskit/platform-feature-flags/fg';
import { Anchor, Pressable } from '@atlaskit/primitives/compiled';
import { useBreadcrumbsSize } from './use-breadcrumbs-size';
const analyticsAttributes = {
componentName: 'breadcrumbsItem',
packageName: "@atlaskit/breadcrumbs",
packageVersion: "17.8.3"
};
const noop = __noop;
const styles = {
root: "_11c8fhey _19itglyw _zulp1b66 _2rkolb4i _4bfu1r31 _1hmsglyw _ajmmnqa1 _18zrze3t _bfhksm61 _syaz1rpy _1e0c116y _4cvr1h6o _1a3b1r31 _4fprglyw _5goinqa1 _f8pj1rpy _9oik1r31 _1bnx8stv _jf4cnqa1 _30l31rpy _9h8hi7uo",
rootSmall: "_11c8wadc",
rootRefresh: "_zulpze3t _vchhusvi _4t3i1k8s",
interactiveMotion: "_v564hxmd _1hms8stv _4bfu1j28 _o7kshxmd _9oik1rpy _1ggl87vo _1nrmi7uo",
withoutTruncation: "_1ul9idpf _1o9zkb7n",
withTruncation: "_1ul9idpf",
iconWrapper: "_1reo15vq _18m915vq _1e0c116y _1o9zidpf _1bsb1tcg _4t3i1tcg _4cvr1h6o _1bah1h6o",
iconWrapperSpacing: "_12l2v77o",
iconWrapperSmallSpacing: "_12l2ze3t",
text: "_1reo15vq _18m915vq _1bto1l2s _o5721q9c",
textWithIconAfter: "_12l21b66",
textWithTruncation: "_1ul9idpf _p12f1osq _1o9zkb7n"
};
const unboundedStyles = {
iconWrapperRefresh: "_1bsb1ejb _4t3i1ejb",
iconWrapperSmall: "_w8l57vkz _17527vkz",
iconWrapperSmallRefresh: "_w8l5pxbi _1752pxbi",
iconWrapper: "_syaz1cv2"
};
/**
* __Step__
*
* A button that represents a single step in a breadcrumbs component.
*/
const Step = /*#__PURE__*/forwardRef(({
analyticsContext,
elemBefore,
href,
iconAfter,
iconBefore,
onClick: onClickProvided = noop,
target,
testId,
children,
title,
truncationWidth,
triggerProps,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
'aria-current': ariaCurrent,
'aria-describedby': ariaDescribedBy,
onBlur,
onFocus,
onMouseDown,
onMouseMove,
onMouseOut,
onMouseOver,
...rest
}, ref) => {
var _triggerProps$onMouse5, _triggerProps$onMouse6, _triggerProps$onMouse7, _triggerProps$onMouse8, _triggerProps$onFocus2, _triggerProps$onBlur2, _triggerProps$ariaDe2;
const resolvedElemBefore = elemBefore !== null && elemBefore !== void 0 ? elemBefore : iconBefore;
const breadcrumbsSize = useBreadcrumbsSize();
const isSmall = breadcrumbsSize === 'small';
// Preserve the text/trailing-icon width budget now that the leading icon is inside the control.
const leadingIconWidth = resolvedElemBefore ? `${"var(--ds-space-300, 24px)"} + ${isSmall ? "var(--ds-space-0, 0px)" : "var(--ds-space-025, 2px)"}` : '0px';
const maxWidth = fg('platform_dst_breadcrumbs-refresh') && truncationWidth != null ? `calc(${truncationWidth}px + ${leadingIconWidth})` : truncationWidth;
const handleClick = usePlatformLeafEventHandler({
fn: onClickProvided,
action: 'clicked',
analyticsData: analyticsContext,
...analyticsAttributes
});
const handleTriggerClick = event => {
var _triggerProps$onClick;
triggerProps === null || triggerProps === void 0 ? void 0 : (_triggerProps$onClick = triggerProps.onClick) === null || _triggerProps$onClick === void 0 ? void 0 : _triggerProps$onClick.call(triggerProps, event);
handleClick(event);
};
const controlRef = fg('platform_dst_breadcrumbs-refresh') ? ref : undefined;
const textRef = fg('platform_dst_breadcrumbs-refresh') ? undefined : ref;
const iconElement = resolvedElemBefore && /*#__PURE__*/React.createElement("span", {
"data-testid": testId && `${testId}--icon-before`,
className: ax([styles.iconWrapper, fg('platform_dst_breadcrumbs-refresh') && unboundedStyles.iconWrapperRefresh, unboundedStyles.iconWrapper, fg('platform_dst_breadcrumbs-refresh') && styles.iconWrapperSpacing, isSmall && styles.iconWrapperSmallSpacing, !fg('platform_dst_breadcrumbs-refresh') && isSmall && unboundedStyles.iconWrapperSmall, fg('platform_dst_breadcrumbs-refresh') && isSmall && unboundedStyles.iconWrapperSmallRefresh])
}, resolvedElemBefore);
const content = /*#__PURE__*/React.createElement(Fragment, null, !fg('platform_dst_breadcrumbs-refresh') && !isSmall && resolvedElemBefore, (fg('platform_dst_breadcrumbs-refresh') || isSmall) && iconElement, /*#__PURE__*/React.createElement("span", {
ref: textRef,
className: ax([styles.text, fg('platform_dst_breadcrumbs-refresh') && Boolean(iconAfter) && styles.textWithIconAfter, truncationWidth != null && fg('platform_dst_breadcrumbs-refresh') && styles.textWithTruncation])
}, children), iconAfter);
if (href) {
var _triggerProps$onMouse, _triggerProps$onMouse2, _triggerProps$onMouse3, _triggerProps$onMouse4, _triggerProps$onFocus, _triggerProps$onBlur, _triggerProps$ariaDe;
return /*#__PURE__*/React.createElement(Anchor, _extends({}, rest, {
ref: controlRef,
"aria-current": ariaCurrent,
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledBy,
href: href,
onClick: handleTriggerClick,
onMouseOver: (_triggerProps$onMouse = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onMouseOver) !== null && _triggerProps$onMouse !== void 0 ? _triggerProps$onMouse : onMouseOver,
onMouseOut: (_triggerProps$onMouse2 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onMouseOut) !== null && _triggerProps$onMouse2 !== void 0 ? _triggerProps$onMouse2 : onMouseOut,
onMouseMove: (_triggerProps$onMouse3 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onMouseMove) !== null && _triggerProps$onMouse3 !== void 0 ? _triggerProps$onMouse3 : onMouseMove,
onMouseDown: (_triggerProps$onMouse4 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onMouseDown) !== null && _triggerProps$onMouse4 !== void 0 ? _triggerProps$onMouse4 : onMouseDown,
onFocus: (_triggerProps$onFocus = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onFocus) !== null && _triggerProps$onFocus !== void 0 ? _triggerProps$onFocus : onFocus,
onBlur: (_triggerProps$onBlur = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onBlur) !== null && _triggerProps$onBlur !== void 0 ? _triggerProps$onBlur : onBlur,
"aria-describedby": (_triggerProps$ariaDe = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps['aria-describedby']) !== null && _triggerProps$ariaDe !== void 0 ? _triggerProps$ariaDe : ariaDescribedBy,
target: target,
rel: target === '_blank' ? 'noopener noreferrer' : undefined,
testId: testId,
title: title,
xcss: cx(styles.root, isSmall && styles.rootSmall, fg('platform_dst_breadcrumbs-refresh') && styles.rootRefresh, truncationWidth != null && fg('platform_dst_breadcrumbs-refresh') && styles.withTruncation, truncationWidth == null && styles.withoutTruncation, fg('platform-dst-motion-uplift-list-item') && styles.interactiveMotion),
style: {
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Width depends on the consumer truncationWidth and leading icon.
maxWidth
}
}), content);
}
return /*#__PURE__*/React.createElement(Pressable, _extends({}, rest, {
ref: controlRef,
"aria-current": ariaCurrent,
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledBy,
onClick: handleTriggerClick,
onMouseOver: (_triggerProps$onMouse5 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onMouseOver) !== null && _triggerProps$onMouse5 !== void 0 ? _triggerProps$onMouse5 : onMouseOver,
onMouseOut: (_triggerProps$onMouse6 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onMouseOut) !== null && _triggerProps$onMouse6 !== void 0 ? _triggerProps$onMouse6 : onMouseOut,
onMouseMove: (_triggerProps$onMouse7 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onMouseMove) !== null && _triggerProps$onMouse7 !== void 0 ? _triggerProps$onMouse7 : onMouseMove,
onMouseDown: (_triggerProps$onMouse8 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onMouseDown) !== null && _triggerProps$onMouse8 !== void 0 ? _triggerProps$onMouse8 : onMouseDown,
onFocus: (_triggerProps$onFocus2 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onFocus) !== null && _triggerProps$onFocus2 !== void 0 ? _triggerProps$onFocus2 : onFocus,
onBlur: (_triggerProps$onBlur2 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.onBlur) !== null && _triggerProps$onBlur2 !== void 0 ? _triggerProps$onBlur2 : onBlur,
"aria-describedby": (_triggerProps$ariaDe2 = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps['aria-describedby']) !== null && _triggerProps$ariaDe2 !== void 0 ? _triggerProps$ariaDe2 : ariaDescribedBy,
testId: testId,
title: title,
xcss: cx(styles.root, isSmall && styles.rootSmall, fg('platform_dst_breadcrumbs-refresh') && styles.rootRefresh, truncationWidth != null && fg('platform_dst_breadcrumbs-refresh') && styles.withTruncation, truncationWidth == null && styles.withoutTruncation, fg('platform-dst-motion-uplift-list-item') && styles.interactiveMotion),
style: {
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Width depends on the consumer truncationWidth and leading icon.
maxWidth
}
}), content);
});
export default Step;