|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import '@ui5/webcomponents-ai/dist/Input.js'; |
| 4 | +import { withWebComponent } from '@ui5/webcomponents-react-base'; |
| 5 | +import type { CommonProps, Ui5CustomEvent, Ui5DomRef, UI5WCSlotsNode } from '@ui5/webcomponents-react-base'; |
| 6 | + |
| 7 | +interface InputAttributes { |
| 8 | + /** |
| 9 | + * Indicates the index of the currently displayed version. |
| 10 | + * @default 0 |
| 11 | + */ |
| 12 | + currentVersion?: number; |
| 13 | + |
| 14 | + /** |
| 15 | + * Defines whether the AI Writing Assistant is currently loading. |
| 16 | + * |
| 17 | + * When `true`, indicates that an AI action is in progress. |
| 18 | + * @default false |
| 19 | + */ |
| 20 | + loading?: boolean; |
| 21 | + |
| 22 | + /** |
| 23 | + * Indicates the total number of result versions available. |
| 24 | + * |
| 25 | + * When not set or set to 0, the versioning will be hidden. |
| 26 | + * @default 0 |
| 27 | + */ |
| 28 | + totalVersions?: number; |
| 29 | +} |
| 30 | + |
| 31 | +interface InputDomRef extends Required<InputAttributes>, Ui5DomRef {} |
| 32 | + |
| 33 | +interface InputPropTypes |
| 34 | + extends InputAttributes, |
| 35 | + Omit<CommonProps, keyof InputAttributes | 'actions' | 'onButtonClick' | 'onStopGeneration' | 'onVersionChange'> { |
| 36 | + /** |
| 37 | + * Defines the items of the menu for the component. |
| 38 | + * |
| 39 | + * __Note:__ The content of the prop will be rendered into a [<slot>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot) by assigning the respective [slot](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/slot) attribute (`slot="actions"`). |
| 40 | + * Since you can't change the DOM order of slots when declaring them within a prop, it might prove beneficial to manually mount them as part of the component's children, especially when facing problems with the reading order of screen readers. |
| 41 | + * |
| 42 | + * __Note:__ When passing a custom React component to this prop, you have to make sure your component reads the `slot` prop and appends it to the most outer element of your component. |
| 43 | + * Learn more about it [here](https://ui5.github.io/webcomponents-react/v2/?path=/docs/knowledge-base-handling-slots--docs). |
| 44 | + * |
| 45 | + * __Supported Node Type/s:__ `Array<HTMLElement>` |
| 46 | + */ |
| 47 | + actions?: UI5WCSlotsNode; |
| 48 | + /** |
| 49 | + * Fired when the user selects the AI button. |
| 50 | + * |
| 51 | + * **Note:** Call `event.preventDefault()` inside the handler of this event to prevent its default action/s. |
| 52 | + * |
| 53 | + * | cancelable | bubbles | |
| 54 | + * | :--------: | :-----: | |
| 55 | + * | ✅|❌| |
| 56 | + */ |
| 57 | + onButtonClick?: (event: Ui5CustomEvent<InputDomRef>) => void; |
| 58 | + |
| 59 | + /** |
| 60 | + * Fired when the user selects the "Stop" button to stop ongoing AI text generation. |
| 61 | + * |
| 62 | + * | cancelable | bubbles | |
| 63 | + * | :--------: | :-----: | |
| 64 | + * | ❌|❌| |
| 65 | + */ |
| 66 | + onStopGeneration?: (event: Ui5CustomEvent<InputDomRef>) => void; |
| 67 | + |
| 68 | + /** |
| 69 | + * Fired when the user selects the version navigation buttons. |
| 70 | + * |
| 71 | + * | cancelable | bubbles | |
| 72 | + * | :--------: | :-----: | |
| 73 | + * | ❌|❌| |
| 74 | + */ |
| 75 | + onVersionChange?: (event: Ui5CustomEvent<InputDomRef>) => void; |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * The `Input` component extends the standard `ui5-input` with **AI Writing Assistant** capabilities. |
| 80 | + * |
| 81 | + * ### Structure |
| 82 | + * |
| 83 | + * The `Input` consists of the following main parts: |
| 84 | + * |
| 85 | + * - **Input Field** – Inherits all standard Input behaviors. |
| 86 | + * - **AI Action Button** – Appears when focused or loading, providing access to AI-related actions or stopping generation. |
| 87 | + * |
| 88 | + * The component automatically determines which elements to render based on its internal state: |
| 89 | + * - The AI Button is only shown when there are available `actions`. |
| 90 | + * - The version navigation appears only when `totalVersions > 1`. |
| 91 | + * |
| 92 | + * ### Keyboard Support |
| 93 | + * |
| 94 | + * - **Shift + F4** — Opens the AI menu. |
| 95 | + * - **Ctrl + Shift + Z / Y** — Navigates backward/forward between AI-generated versions. |
| 96 | + * |
| 97 | + * |
| 98 | + * |
| 99 | + * __Note:__ This is a UI5 Web Component! [Input UI5 Web Component Documentation](https://ui5.github.io/webcomponents/components/ai/Input) | [Repository](https://github.com/UI5/webcomponents) |
| 100 | + * |
| 101 | + * @since [2.16.0](https://github.com/UI5/webcomponents/releases/tag/v2.16.0) of __@ui5/webcomponents-ai__. |
| 102 | + * @experimental The **@ui5/webcomponents-ai** package is under active development and considered experimental. Component APIs are subject to change. |
| 103 | + */ |
| 104 | +const Input = withWebComponent<InputPropTypes, InputDomRef>( |
| 105 | + 'ui5-ai-input', |
| 106 | + ['currentVersion', 'totalVersions'], |
| 107 | + ['loading'], |
| 108 | + ['actions'], |
| 109 | + ['button-click', 'stop-generation', 'version-change'], |
| 110 | +); |
| 111 | + |
| 112 | +Input.displayName = 'Input'; |
| 113 | + |
| 114 | +export { Input }; |
| 115 | +export type { InputDomRef, InputPropTypes }; |
0 commit comments