UNPKG

@flatbiz/antd

Version:
91 lines (87 loc) 2.66 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { classNames } from '@dimjs/utils/class-names/class-names'; import { a as _slicedToArray } from './_rollupPluginBabelHelpers-BYm17lo8.js'; import { useState, useRef } from 'react'; import { Anchor, Steps } from 'antd'; import { G as Gap } from './gap-C1UNo7Wz.js'; import { jsxs, jsx } from 'react/jsx-runtime'; function isElement(node) { var ELEMENT_NODE_TYPE = 1; return node.tagName !== 'HTML' && node.tagName !== 'BODY' && node.nodeType === ELEMENT_NODE_TYPE; } function getParentScroll(el) { var node = el; while (node && isElement(node)) { var _window$getComputedSt = window.getComputedStyle(node), overflowY = _window$getComputedSt.overflowY; if (/scroll|auto/i.test(overflowY)) { return node; } node = node.parentNode; } return undefined; } /** * 锚点步骤组件 * @param props * @returns */ var AnchorSteps = function AnchorSteps(props) { var _useState = useState(), _useState2 = _slicedToArray(_useState, 2), activeKey = _useState2[0], setActiveKey = _useState2[1]; var rootNode = useRef(); var onChange = function onChange(link) { if (link) { setActiveKey(link.replace('#vas-', '')); } }; var getContainer = function getContainer() { return getParentScroll(rootNode.current) || window; }; var refHandle = function refHandle(node) { if (node) { rootNode.current = node; } }; return /*#__PURE__*/jsxs("div", { className: classNames('v-anchor-steps', props.className), ref: refHandle, children: [/*#__PURE__*/jsx(Anchor, { onChange: onChange, className: "v-fixed-anchor", onClick: function onClick(e) { e.preventDefault(); }, affix: false, getContainer: getContainer, children: /*#__PURE__*/jsx(Steps, { size: "small", direction: "vertical", current: props.steps.findIndex(function (item) { return item.id === activeKey; }), items: props.steps.map(function (item) { return { title: /*#__PURE__*/jsx(Anchor.Link, { href: "#vas-".concat(item.id), title: item.title }), description: /*#__PURE__*/jsx(Gap, { height: 20 }), status: item.id === activeKey ? 'process' : 'wait' }; }) }) }), props.steps.map(function (item) { return /*#__PURE__*/jsx("div", { id: "vas-".concat(item.id), children: item.content }, item.id); })] }); }; export { AnchorSteps as A }; //# sourceMappingURL=anchor-steps-BQK32Pbd.js.map