MCPcopy Index your code
hub / github.com/TanStack/ai / ChatInput

Function ChatInput

packages/ai-solid-ui/src/chat-input.tsx:59–165  ·  view source on GitHub ↗
(props: ChatInputProps)

Source from the content-addressed store, hash-verified

57 * ```
58 */
59export function ChatInput(props: ChatInputProps) {
60 const { sendMessage, isLoading } = useChatContext()
61 const [value, setValue] = createSignal('')
62
63 const disabled = () => props.disabled || isLoading()
64
65 const handleSubmit = () => {
66 if (!value().trim() || disabled()) return
67 void sendMessage(value())
68 setValue('')
69 }
70
71 const renderProps = (): ChatInputRenderProps => ({
72 value: value(),
73 onChange: setValue,
74 onSubmit: handleSubmit,
75 isLoading: isLoading(),
76 disabled: disabled(),
77
78 ref: () => {},
79 })
80
81 // Render prop pattern
82 if (props.children) {
83 return <>{props.children(renderProps())}</>
84 }
85
86 // Default implementation
87 return (
88 <div
89 class={props.class}
90 data-chat-input
91 style={{
92 display: 'flex',
93 gap: '0.75rem',
94 'align-items': 'center',
95 width: '100%',
96 }}
97 >
98 <input
99 type="text"
100 value={value()}
101 onInput={(e) => setValue(e.currentTarget.value)}
102 onKeyDown={(e) => {
103 if ((props.submitOnEnter ?? true) && e.key === 'Enter') {
104 e.preventDefault()
105 handleSubmit()
106 }
107 }}
108 placeholder={props.placeholder ?? 'Type a message...'}
109 disabled={disabled()}
110 data-chat-textarea
111 style={{
112 flex: 1,
113 padding: '0.75rem 1rem',
114 'font-size': '0.875rem',
115 border: '1px solid rgba(255, 255, 255, 0.1)',
116 'border-radius': '0.75rem',

Callers

nothing calls this directly

Calls 5

useChatContextFunction · 0.90
disabledFunction · 0.85
renderPropsFunction · 0.70
handleSubmitFunction · 0.70
isLoadingFunction · 0.50

Tested by

no test coverage detected