Caroa UI

ChatInput

チャット入力コンポーネント。テキスト入力と送信ボタンを組み合わせたUIです。

インポート

import { ChatInput } from '@caroainc/ui-components/client'

基本的な使い方

Loading...
'use client'
import { useState } from 'react'
import { ChatInput } from '@caroainc/ui-components/client'
 
function ChatDemo() {
  const [input, setInput] = useState('')
 
  const handleSend = () => {
    console.log('送信:', input)
    setInput('')
  }
 
  return (
    <ChatInput
      value={input}
      onChange={setInput}
      onSend={handleSend}
      placeholder="メッセージを入力..."
    />
  )
}

ツールバー付き

toolbarLeftプロパティで、送信ボタンの左側にカスタム要素を追加できます。

Loading...
<ChatInput
  value={input}
  onChange={setInput}
  onSend={handleSend}
  toolbarLeft={
    <div className="flex gap-1">
      <Button size="sm" shape="square" variant="ghost">
        <Icon name="Paperclip" size="sm" />
      </Button>
      <Button size="sm" shape="square" variant="ghost">
        <Icon name="Image" size="sm" />
      </Button>
    </div>
  }
/>

無効状態

Loading...
<ChatInput
  value={input}
  onChange={setInput}
  onSend={handleSend}
  disabled
  placeholder="入力できません"
/>

キーボードショートカット

  • Cmd+Enter (Mac) / Ctrl+Enter (Windows): メッセージを送信

Props

PropTypeDefaultDescription
value*string-入力値
onChange*(value: string) => void-入力変更ハンドラ
onSend*() => void-送信ハンドラ
placeholderstring'メッセージ...'プレースホルダー
maxLengthnumber500最大文字数
maxRowsnumber5最大行数(超えるとスクロール)
toolbarLeftReact.ReactNode-ツールバー左側に表示する要素
disabledbooleanfalse無効状態

On this page