@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
71 lines • 5.47 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 { CleanIconButton, Typography } from '@neo4j-ndl/react';
import { ChevronDownIconOutline } from '@neo4j-ndl/react/icons';
import classNames from 'classnames';
import { useState } from 'react';
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 { value: thinkingDuration, unit } = formatThinkingDuration(thinkingMs);
return (_jsxs("div", Object.assign({ ref: ref, className: classes, style: style }, restProps, htmlAttributes, { children: [_jsx(Typography, { variant: "label", className: "ndl-ai-reasoning-header", children: isThinking === true ? (_jsxs(_Fragment, { children: [_jsx(Presence, { isThinking: isThinking, className: "n-size-token-24" }), _jsxs("span", { className: "ndl-ai-reasoning-header-text", children: [currentAction, "..."] })] })) : (_jsxs(_Fragment, { children: [_jsxs("span", { children: ["Thought for ", thinkingDuration, " ", unit] }), _jsx(CleanIconButton, { size: "small", variant: "neutral", onClick: () => setIsExpanded(!isExpanded), description: isExpanded ? 'Collapse' : 'Expand', className: classNames('ndl-ai-reasoning-expand-button', {
'ndl-expanded': isExpanded,
}), children: _jsx(ChevronDownIconOutline, {}) })] })) }), _jsx("div", { className: classNames('ndl-ai-reasoning-content', {
'ndl-expanded': shouldShowChildren,
}), inert: !shouldShowChildren, 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 } = _a, restProps = __rest(_a, ["heading", "leadingVisual", "children", "className", "style", "htmlAttributes", "ref"]);
const classes = classNames('ndl-ai-reasoning-section', className);
const [isExpanded, setIsExpanded] = useState(false);
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 }), _jsx(CleanIconButton, { description: isExpanded ? 'Collapse' : 'Expand', size: "small", variant: "neutral", className: classNames('ndl-ai-reasoning-expand-button', {
'ndl-expanded': isExpanded,
}), onClick: () => setIsExpanded(!isExpanded), children: _jsx(ChevronDownIconOutline, {}) })] }), _jsx("div", { className: classNames('ndl-ai-reasoning-section-content', {
'ndl-expanded': isExpanded,
}), inert: !isExpanded, children: _jsx("div", { className: "ndl-ai-reasoning-section-content-inner", children: _jsxs("div", { className: "ndl-ai-reasoning-section-content-inner-2", 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 Reasoning = Object.assign(ReasoningComponent, {
Section,
});
export { Reasoning };
//# sourceMappingURL=Reasoning.js.map