diff --git a/packages/chat/src/index.ts b/packages/chat/src/index.ts index 0f320c52a2..feee1d659e 100644 --- a/packages/chat/src/index.ts +++ b/packages/chat/src/index.ts @@ -3,3 +3,5 @@ export * from './bubbles' export * as ChatBubble from './chat-bubble' export * from './chat' export * from './utils' +export * from './navbar' +export * from './input-area' diff --git a/packages/chat/src/input-area/elements.ts b/packages/chat/src/input-area/elements.ts new file mode 100644 index 0000000000..0addf28e56 --- /dev/null +++ b/packages/chat/src/input-area/elements.ts @@ -0,0 +1,72 @@ +import styled from 'styled-components' +import { Container } from '@titicaca/core-elements' + +export const MainContainer = styled(Container)` + position: sticky; + bottom: 0; + display: flex; + align-items: flex-end; + gap: 12px; + border-top: 1px solid var(--color-gray100); + padding: 10px 12px; + background-color: var(--color-white); +` + +export const InputArea = styled(Container)` + display: flex; + align-items: flex-end; + gap: 20px; + width: 100%; + border-radius: 15px; + border: 1px solid var(--color-gray100); + background-color: var(--color-gray20); + padding: 10px 15px; +` + +export const UploadImageButton = styled.label` + width: 26px; + height: 26px; + margin-bottom: 8px; + background: url('https://assets.triple.guide/images/img-review-select-photo@3x.png') + no-repeat 0 0; + background-size: 26px 26px; +` + +export const FileInput = styled.input` + position: absolute; + visibility: hidden; + width: 260px; +` + +export const TextArea = styled.textarea` + width: 100%; + height: 20px; + min-height: 20px; + color: var(--color-black); + font-size: 15px; + background-color: transparent; + overflow-y: scroll; + line-height: 20px; + resize: none; + border: none; + outline: none; + box-shadow: none; + + ::placeholder { + color: var(--color-gray300); + } + + ::-webkit-scrollbar { + display: none; + } +` + +export const SendMessageButton = styled.button<{ color?: 'mint' | 'blue' }>` + flex-shrink: 0; + background: transparent; + color: ${({ color }) => + color === 'mint' ? 'var(--color-mint)' : 'var(--color-blue)'}; + font-size: 15px; + font-weight: 700; + outline: none; +` diff --git a/packages/chat/src/input-area/index.tsx b/packages/chat/src/input-area/index.tsx new file mode 100644 index 0000000000..586c9366d1 --- /dev/null +++ b/packages/chat/src/input-area/index.tsx @@ -0,0 +1,99 @@ +import { + ChangeEventHandler, + KeyboardEventHandler, + SyntheticEvent, + useRef, +} from 'react' + +import { + FileInput, + InputArea, + MainContainer, + SendMessageButton, + TextArea, + UploadImageButton, +} from './elements' + +const MIN_TEXTAREA_HEIGHT = 20 +const MAX_TEXTAREA_HEIGHT = 100 +const MAX_TEXT_LENGTH = 2000 + +export interface InputAreaUIProps { + inputValue: string + placeholder?: string + setInputValue: (value: string) => void + onImageUpload: ChangeEventHandler + onSendMessage: () => void + onInputClick?: () => void + onInputKeydown?: KeyboardEventHandler + buttonColor?: 'mint' | 'blue' + buttonText?: string + buttonDisabled?: boolean + maxTextLength?: number +} + +export function InputAreaUI({ + buttonColor = 'blue', + buttonText, + buttonDisabled, + inputValue, + setInputValue, + placeholder, + onImageUpload, + onSendMessage, + onInputClick, + onInputKeydown, + maxTextLength = MAX_TEXT_LENGTH, + ...props +}: InputAreaUIProps) { + const textareaRef = useRef(null) + + return ( + + + + + +