261023_01_ENH: 자동완성 옵션 툴팁 추가 및 문자 편집기 LMS·MMS 분리와 UTF-8 바이트 계산 적용
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
import * as React from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { MultiSelect } from '@/components/common/multi-select'
|
||||
import type { MultiSelectOption, MultiSelectRef } from '@/components/common/multi-select'
|
||||
import type { MultiSelectOption, MultiSelectOptionTooltip, MultiSelectRef } from '@/components/common/multi-select'
|
||||
|
||||
export type { MultiSelectOption, MultiSelectRef } from '@/components/common/multi-select'
|
||||
export type { MultiSelectOption, MultiSelectOptionTooltip, MultiSelectRef } from '@/components/common/multi-select'
|
||||
|
||||
export interface KriAutoCompleteBaseProps<T> {
|
||||
items: T[]
|
||||
@@ -26,6 +26,8 @@ export interface KriAutoCompleteBaseProps<T> {
|
||||
disabled?: boolean
|
||||
'aria-invalid'?: boolean
|
||||
modalPopover?: boolean
|
||||
optionTooltip?: MultiSelectOptionTooltip
|
||||
optionTooltipClassName?: string
|
||||
}
|
||||
|
||||
export interface KriMultiSelectProps<T = unknown> extends KriAutoCompleteBaseProps<T> {
|
||||
@@ -77,6 +79,8 @@ export function KriMultiSelect<T = unknown>({
|
||||
disabled,
|
||||
'aria-invalid': ariaInvalid,
|
||||
modalPopover = true,
|
||||
optionTooltip,
|
||||
optionTooltipClassName,
|
||||
}: KriMultiSelectProps<T>) {
|
||||
const options = React.useMemo(
|
||||
() => toOptions(items, getValue, getLabel, withInfo),
|
||||
@@ -110,6 +114,8 @@ export function KriMultiSelect<T = unknown>({
|
||||
disabled={disabled}
|
||||
aria-invalid={ariaInvalid}
|
||||
modalPopover={modalPopover}
|
||||
optionTooltip={optionTooltip}
|
||||
optionTooltipClassName={optionTooltipClassName}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
@@ -157,6 +163,8 @@ function KriSingleSelectInner<T>({
|
||||
disabled,
|
||||
'aria-invalid': ariaInvalid,
|
||||
modalPopover = true,
|
||||
optionTooltip,
|
||||
optionTooltipClassName,
|
||||
}: KriSingleSelectProps<T>, forwardedRef: React.ForwardedRef<MultiSelectRef>) {
|
||||
const ref = React.useRef<MultiSelectRef>(null)
|
||||
React.useImperativeHandle(
|
||||
@@ -227,6 +235,8 @@ function KriSingleSelectInner<T>({
|
||||
aria-invalid={ariaInvalid}
|
||||
title={showSelectedTooltip ? selectedLabel ?? value : undefined}
|
||||
modalPopover={modalPopover}
|
||||
optionTooltip={optionTooltip}
|
||||
optionTooltipClassName={optionTooltipClassName}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useTextareaInsert } from './hooks/useTextareaInsert'
|
||||
type SmsEditorProps = Omit<KriEditorProps, 'mode'> & { mode: 'sms' }
|
||||
|
||||
function calculateBytes(value: string): number {
|
||||
return Array.from(value).reduce((total, character) => total + (character.charCodeAt(0) > 127 ? 2 : 1), 0)
|
||||
return new TextEncoder().encode(value).byteLength
|
||||
}
|
||||
|
||||
export function KriEditorSms({
|
||||
@@ -33,12 +33,12 @@ export function KriEditorSms({
|
||||
const [text, setText] = React.useState(value || '')
|
||||
const textareaRef = React.useRef<HTMLTextAreaElement | null>(null)
|
||||
const latestTextRef = React.useRef(text)
|
||||
const lastTypeRef = React.useRef<'SMS' | 'LMS' | null>(null)
|
||||
const lastTypeRef = React.useRef<'SMS' | 'LMS' | 'MMS' | null>(null)
|
||||
const { scheduleChange, flushChange } = useDebouncedChange(onChange, debounceMs)
|
||||
const textareaInsert = useTextareaInsert(textareaRef)
|
||||
const previewText = smsPreviewSuffix ? `${text}\n${smsPreviewSuffix}` : text
|
||||
const byteSize = React.useMemo(() => calculateBytes(previewText), [previewText])
|
||||
const messageType: 'SMS' | 'LMS' = byteSize > smsMaxBytes || Boolean(smsTitle) || smsHasAttachment ? 'LMS' : 'SMS'
|
||||
const messageType: 'SMS' | 'LMS' | 'MMS' = smsHasAttachment ? 'MMS' : byteSize >= smsMaxBytes || Boolean(smsTitle) ? 'LMS' : 'SMS'
|
||||
const maxBytes = messageType === 'SMS' ? smsMaxBytes : lmsMaxBytes
|
||||
|
||||
const commitText = React.useCallback((next: string, immediate = false) => {
|
||||
@@ -89,8 +89,8 @@ export function KriEditorSms({
|
||||
<div className="flex h-full flex-col bg-gray-50 px-4 pt-8 pb-4">
|
||||
<div className="mb-3 flex items-center justify-between px-2">
|
||||
<span className="text-xs font-medium text-gray-600">{byteSize}/{maxBytes}byte</span>
|
||||
<span className={cn('rounded-md px-3 py-1 text-xs font-bold text-white', messageType === 'LMS' ? 'bg-blue-500' : 'bg-red-500')}>
|
||||
{messageType === 'LMS' ? 'LMS/MMS' : 'SMS'}
|
||||
<span className={cn('rounded-md px-3 py-1 text-xs font-bold text-white', messageType === 'SMS' ? 'bg-red-500' : 'bg-blue-500')}>
|
||||
{messageType}
|
||||
</span>
|
||||
</div>
|
||||
<div className={cn('flex flex-1 flex-col rounded-2xl bg-white shadow-sm', smsImages.length > 0 ? 'overflow-y-auto' : 'overflow-hidden')}>
|
||||
|
||||
@@ -80,12 +80,13 @@ export type KriEditorProps = {
|
||||
onImageUploadError?: (error: unknown) => void
|
||||
debounceMs?: number
|
||||
smsTitle?: string
|
||||
changeSmsType?: (type: 'SMS' | 'LMS') => void
|
||||
/** Preview only; consumers must handle MMS. Actual delivery type is determined by the server. */
|
||||
changeSmsType?: (type: 'SMS' | 'LMS' | 'MMS') => void
|
||||
isSmsReadOnly?: boolean
|
||||
smsMaxBytes?: number
|
||||
lmsMaxBytes?: number
|
||||
smsPreviewSuffix?: string
|
||||
/** 첨부파일이 있으면 길이·제목과 무관하게 LMS/MMS로 판정한다. */
|
||||
/** 첨부파일이 있으면 길이·제목과 무관하게 MMS로 판정한다. */
|
||||
smsHasAttachment?: boolean
|
||||
/** 문자 미리보기의 제목과 본문 사이에 표시할 첨부 이미지 */
|
||||
smsImages?: KriEditorSmsImage[]
|
||||
|
||||
@@ -46,6 +46,8 @@ function MultiSelectInner<T>(
|
||||
closeOnSelect = false,
|
||||
preventDeselect = false,
|
||||
hideOptionCheck = false,
|
||||
optionTooltip,
|
||||
optionTooltipClassName,
|
||||
style,
|
||||
...buttonProps
|
||||
}: MultiSelectProps<T>,
|
||||
@@ -205,6 +207,8 @@ function MultiSelectInner<T>(
|
||||
onSearchValueChange={handleSearchChange}
|
||||
hideSelectAll={hideSelectAll}
|
||||
hideOptionCheck={hideOptionCheck}
|
||||
optionTooltip={optionTooltip}
|
||||
optionTooltipClassName={optionTooltipClassName}
|
||||
selectionMode={selectionMode}
|
||||
emptyIndicator={emptyIndicator}
|
||||
onToggleOption={toggleOption}
|
||||
|
||||
@@ -11,8 +11,9 @@ import {
|
||||
CommandList,
|
||||
CommandSeparator,
|
||||
} from '@/components/ui/command'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { MultiSelectGroup, MultiSelectOption, MultiSelectOptions } from './types'
|
||||
import type { MultiSelectGroup, MultiSelectOption, MultiSelectOptionTooltip, MultiSelectOptions } from './types'
|
||||
import { isGroupedOptions } from './utils'
|
||||
|
||||
interface MultiSelectContentProps<T> {
|
||||
@@ -25,26 +26,35 @@ interface MultiSelectContentProps<T> {
|
||||
onSearchValueChange: (value: string) => void
|
||||
hideSelectAll: boolean
|
||||
hideOptionCheck: boolean
|
||||
optionTooltip?: MultiSelectOptionTooltip
|
||||
optionTooltipClassName?: string
|
||||
selectionMode: 'single' | 'multiple'
|
||||
emptyIndicator: React.ReactNode
|
||||
onToggleOption: (option: MultiSelectOption<T>) => void
|
||||
onToggleAll: () => void
|
||||
}
|
||||
|
||||
interface OptionTooltipSettings {
|
||||
mode: MultiSelectOptionTooltip
|
||||
className?: string
|
||||
}
|
||||
|
||||
function OptionItem<T>({
|
||||
option,
|
||||
selected,
|
||||
hideOptionCheck,
|
||||
tooltip,
|
||||
onToggle,
|
||||
}: {
|
||||
option: MultiSelectOption<T>
|
||||
selected: boolean
|
||||
hideOptionCheck: boolean
|
||||
tooltip?: OptionTooltipSettings
|
||||
onToggle: () => void
|
||||
}) {
|
||||
const Icon = option.icon
|
||||
|
||||
return (
|
||||
const item = (
|
||||
<CommandItem
|
||||
value={`${option.label} ${option.value}`}
|
||||
disabled={option.disabled}
|
||||
@@ -65,17 +75,39 @@ function OptionItem<T>({
|
||||
<span className="truncate">{option.label}</span>
|
||||
</CommandItem>
|
||||
)
|
||||
|
||||
if (!tooltip) return item
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{item}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="right"
|
||||
className={cn(
|
||||
'break-words',
|
||||
tooltip.mode === 'wrap'
|
||||
? 'max-w-[min(28rem,var(--radix-tooltip-content-available-width))]'
|
||||
: 'max-w-[var(--radix-tooltip-content-available-width)]',
|
||||
tooltip.className,
|
||||
)}
|
||||
>
|
||||
{option.label}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
function OptionsGroup<T>({
|
||||
group,
|
||||
selectedValues,
|
||||
hideOptionCheck,
|
||||
tooltip,
|
||||
onToggleOption,
|
||||
}: {
|
||||
group: MultiSelectGroup<T>
|
||||
selectedValues: string[]
|
||||
hideOptionCheck: boolean
|
||||
tooltip?: OptionTooltipSettings
|
||||
onToggleOption: (option: MultiSelectOption<T>) => void
|
||||
}) {
|
||||
return (
|
||||
@@ -86,6 +118,7 @@ function OptionsGroup<T>({
|
||||
option={option}
|
||||
selected={selectedValues.includes(option.value)}
|
||||
hideOptionCheck={hideOptionCheck}
|
||||
tooltip={tooltip}
|
||||
onToggle={() => onToggleOption(option)}
|
||||
/>
|
||||
))}
|
||||
@@ -103,6 +136,8 @@ export function MultiSelectContent<T>({
|
||||
onSearchValueChange,
|
||||
hideSelectAll,
|
||||
hideOptionCheck,
|
||||
optionTooltip,
|
||||
optionTooltipClassName,
|
||||
selectionMode,
|
||||
emptyIndicator,
|
||||
onToggleOption,
|
||||
@@ -123,8 +158,9 @@ export function MultiSelectContent<T>({
|
||||
const flatOptions = grouped ? options.flatMap((group) => group.options) : options
|
||||
const selectableOptions = flatOptions.filter((option) => !option.disabled)
|
||||
const allSelected = selectableOptions.length > 0 && selectableOptions.every((option) => selectedValues.includes(option.value))
|
||||
const tooltip = optionTooltip ? { mode: optionTooltip, className: optionTooltipClassName } : undefined
|
||||
|
||||
return (
|
||||
const content = (
|
||||
<Command shouldFilter={searchMode === 'filter'}>
|
||||
{searchable ? (
|
||||
<CommandInput
|
||||
@@ -161,6 +197,7 @@ export function MultiSelectContent<T>({
|
||||
group={group}
|
||||
selectedValues={selectedValues}
|
||||
hideOptionCheck={hideOptionCheck}
|
||||
tooltip={tooltip}
|
||||
onToggleOption={onToggleOption}
|
||||
/>
|
||||
))
|
||||
@@ -172,6 +209,7 @@ export function MultiSelectContent<T>({
|
||||
option={option}
|
||||
selected={selectedValues.includes(option.value)}
|
||||
hideOptionCheck={hideOptionCheck}
|
||||
tooltip={tooltip}
|
||||
onToggle={() => onToggleOption(option)}
|
||||
/>
|
||||
))}
|
||||
@@ -180,4 +218,6 @@ export function MultiSelectContent<T>({
|
||||
</CommandList>
|
||||
</Command>
|
||||
)
|
||||
|
||||
return tooltip ? <TooltipProvider delayDuration={0}>{content}</TooltipProvider> : content
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ export type {
|
||||
AnimationConfig,
|
||||
MultiSelectGroup,
|
||||
MultiSelectOption,
|
||||
MultiSelectOptionTooltip,
|
||||
MultiSelectOptions,
|
||||
MultiSelectProps,
|
||||
MultiSelectRef,
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface MultiSelectGroup<T = unknown> {
|
||||
export type MultiSelectOptions<T = unknown> = MultiSelectOption<T>[] | MultiSelectGroup<T>[]
|
||||
export type MultiSelectSelectionMode = 'single' | 'multiple'
|
||||
export type MultiSelectVariant = 'default' | 'secondary' | 'destructive' | 'inverted'
|
||||
export type MultiSelectOptionTooltip = 'singleLine' | 'wrap'
|
||||
|
||||
export interface MultiSelectResponsiveSettings {
|
||||
maxCount?: number
|
||||
@@ -79,6 +80,8 @@ export interface MultiSelectProps<T = unknown>
|
||||
closeOnSelect?: boolean
|
||||
preventDeselect?: boolean
|
||||
hideOptionCheck?: boolean
|
||||
optionTooltip?: MultiSelectOptionTooltip
|
||||
optionTooltipClassName?: string
|
||||
}
|
||||
|
||||
export interface MultiSelectRef {
|
||||
|
||||
@@ -205,7 +205,8 @@
|
||||
"badge",
|
||||
"button",
|
||||
"command",
|
||||
"popover"
|
||||
"popover",
|
||||
"tooltip"
|
||||
],
|
||||
"dependencies": [
|
||||
"lucide-react"
|
||||
|
||||
Reference in New Issue
Block a user