@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
90 lines (89 loc) • 4.29 kB
JavaScript
'use client';
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { Anchor, Collapse, ConfigProvider } from 'antd';
import { PanelTopClose, PanelTopOpen } from 'lucide-react';
import { memo, useMemo } from 'react';
import useControlledState from 'use-merge-value';
import ActionIcon from "../ActionIcon";
import { useStyles } from "./style";
import { mapItems } from "./utils";
import { jsx as _jsx } from "react/jsx-runtime";
var TocMobile = /*#__PURE__*/memo(function (_ref) {
var items = _ref.items,
activeKey = _ref.activeKey,
onChange = _ref.onChange,
getContainer = _ref.getContainer,
_ref$headerHeight = _ref.headerHeight,
headerHeight = _ref$headerHeight === void 0 ? 64 : _ref$headerHeight,
_ref$tocWidth = _ref.tocWidth,
tocWidth = _ref$tocWidth === void 0 ? 176 : _ref$tocWidth;
var _useControlledState = useControlledState('', {
onChange: onChange,
value: activeKey
}),
_useControlledState2 = _slicedToArray(_useControlledState, 2),
activeLink = _useControlledState2[0],
setActiveLink = _useControlledState2[1];
var _useStyles = useStyles({
headerHeight: headerHeight,
tocWidth: tocWidth
}),
styles = _useStyles.styles;
var activeAnchor = items.find(function (item) {
return item.id === activeLink;
});
var tocItems = useMemo(function () {
return mapItems(items);
}, [items]);
return /*#__PURE__*/_jsx(ConfigProvider, {
theme: {
token: {
fontSize: 12,
sizeStep: 3
}
},
children: /*#__PURE__*/_jsx("section", {
className: styles.mobileCtn,
children: /*#__PURE__*/_jsx(Collapse, {
bordered: false,
className: styles.expand,
expandIcon: function expandIcon(_ref2) {
var isActive = _ref2.isActive;
return /*#__PURE__*/_jsx(ActionIcon, {
icon: isActive ? PanelTopClose : PanelTopOpen,
size: 'small'
});
},
expandIconPosition: 'end',
ghost: true,
children: /*#__PURE__*/_jsx(Collapse.Panel, {
forceRender: true,
header: activeAnchor ? activeAnchor.title : 'TOC',
children: /*#__PURE__*/_jsx(ConfigProvider, {
theme: {
token: {
fontSize: 14,
sizeStep: 4
}
},
children: /*#__PURE__*/_jsx(Anchor, {
getContainer: getContainer,
items: tocItems,
onChange: function onChange(currentLink) {
setActiveLink(currentLink.replace('#', ''));
},
targetOffset: headerHeight + 48
})
})
}, 'toc')
})
})
});
});
TocMobile.displayName = 'TocMobile';
export default TocMobile;