import { Card, Space, Tag, Typography } from 'antd'; import { forwardRef, useImperativeHandle, useRef } from 'react'; import { resolveWidgetFeatures } from './registry/widget-features'; import type { WidgetHandle, WidgetShellProps } from './types/widget'; const { Title } = Typography; export const WidgetShell = forwardRef(function WidgetShell( { id, title, features = [], featureSlot, cardWrapper = true, children }, ref, ) { const wrapperRef = useRef(null); const resolvedFeatures = resolveWidgetFeatures(features); const hasHeader = Boolean(title) || resolvedFeatures.length > 0 || Boolean(featureSlot); useImperativeHandle( ref, () => ({ focus: () => { wrapperRef.current?.focus(); }, scrollIntoView: (options) => { wrapperRef.current?.scrollIntoView(options); }, getId: () => id, getFeatures: () => features, }), [features, id], ); const content = ( {hasHeader ? (
{title} {resolvedFeatures.map((feature) => ( {feature.label} ))} {featureSlot}
) : null}
{children}
); if (!cardWrapper) { return (
{content}
); } return ( {content} ); });