@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
87 lines • 5.98 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
/**
*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Typography } from '@neo4j-ndl/react';
import classNames from 'classnames';
import { useId, useState } from 'react';
import { ChevronDownIconOutline } from '../../icons/generated/heroIcons/ChevronDownIconOutline';
import { Presence } from '../presence';
import { formatThinkingDuration } from '../thinking/thinking-duration-formatter';
/**
* The component is used to display the reasoning state of an LLM.
* It has an accordion like behavior to show the reasoning steps.
*
* @alpha - Changes to this component may be breaking.
*/
const ReasoningComponent = (_a) => {
var { isThinking = true, thinkingMs = 1000, currentAction = 'Thinking', children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["isThinking", "thinkingMs", "currentAction", "children", "className", "style", "htmlAttributes", "ref"]);
const classes = classNames('ndl-ai-reasoning', className);
const [isExpanded, setIsExpanded] = useState(false);
const shouldShowChildren = isExpanded && isThinking === false;
const buttonId = useId();
const panelId = useId();
const { value: thinkingDuration, unit } = formatThinkingDuration(thinkingMs);
return (_jsxs("div", Object.assign({ ref: ref, className: classes, style: style }, restProps, htmlAttributes, { children: [_jsx(Typography, Object.assign({ variant: "label", className: classNames('ndl-ai-reasoning-header', {
'ndl-expanded': isExpanded,
}) }, (!isThinking
? {
as: 'button',
htmlAttributes: {
'aria-controls': panelId,
'aria-expanded': isExpanded,
id: buttonId,
onClick: () => setIsExpanded(!isExpanded),
type: 'button',
},
}
: { as: 'div', htmlAttributes: { id: buttonId } }), { children: isThinking === true ? (_jsxs(_Fragment, { children: [_jsx(Presence, { isThinking: isThinking, className: "ndl-ai-reasoning-presence" }), _jsxs("span", { className: "ndl-ai-reasoning-header-text", children: [currentAction, "..."] })] })) : (_jsxs(_Fragment, { children: [_jsxs("span", { children: ["Thought for ", thinkingDuration, " ", unit] }), _jsx(ChevronDownIconOutline, { className: classNames('ndl-ai-reasoning-chevron', {
'ndl-expanded': isExpanded,
}) })] })) })), _jsx("div", { className: classNames('ndl-ai-reasoning-content', {
'ndl-expanded': shouldShowChildren,
}), inert: !shouldShowChildren, "aria-hidden": !shouldShowChildren, "aria-labelledby": buttonId, role: "region", id: panelId, children: _jsx("div", { className: "ndl-ai-reasoning-content-inner", children: _jsx("div", { className: "ndl-ai-reasoning-content-inner-2", children: children }) }) })] })));
};
const Section = (_a) => {
var { heading, leadingVisual, children, className, style, htmlAttributes, ref, isExpanded: _isExpanded, isDefaultExpanded: _isDefaultExpanded, onExpandChange: _onExpandChange } = _a, restProps = __rest(_a, ["heading", "leadingVisual", "children", "className", "style", "htmlAttributes", "ref", "isExpanded", "isDefaultExpanded", "onExpandChange"]);
const classes = classNames('ndl-ai-reasoning-section', className);
return (_jsxs("div", Object.assign({ ref: ref, className: classes, style: style }, restProps, htmlAttributes, { children: [_jsxs("div", { className: "ndl-ai-reasoning-section-header", children: [_jsx("div", { className: "ndl-ai-reasoning-section-leading", children: leadingVisual }), _jsx(Typography, { variant: "subheading-small", children: heading })] }), _jsxs("div", { className: "ndl-ai-reasoning-section-content", children: [_jsx("div", { className: "ndl-ai-reasoning-section-content-line-container", children: _jsx("div", { className: "ndl-ai-reasoning-section-content-line" }) }), _jsx("div", { className: "ndl-ai-reasoning-section-content-children", children: children })] })] })));
};
const Footer = (_a) => {
var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["children", "className", "style", "htmlAttributes", "ref"]);
const classes = classNames('ndl-ai-reasoning-footer', className);
return (_jsx(Typography, Object.assign({ as: "div", variant: "body-small", className: classes, style: style, ref: ref }, restProps, htmlAttributes, { children: children })));
};
const Reasoning = Object.assign(ReasoningComponent, {
Footer,
Section,
});
export { Reasoning };
//# sourceMappingURL=Reasoning.js.map