260722_01_ENH: 버그 수정 및 개선 사항 수정
This commit is contained in:
@@ -18,11 +18,13 @@ export interface KriAutoCompleteBaseProps<T> {
|
||||
heightClassName?: string
|
||||
spanClassName?: string
|
||||
badgeClassName?: string
|
||||
badgeLabelClassName?: string
|
||||
className?: string
|
||||
getValue?: (item: T) => string
|
||||
getLabel?: (item: T) => string
|
||||
withInfo?: boolean
|
||||
disabled?: boolean
|
||||
'aria-invalid'?: boolean
|
||||
}
|
||||
|
||||
export interface KriMultiSelectProps<T = unknown> extends KriAutoCompleteBaseProps<T> {
|
||||
@@ -59,11 +61,12 @@ export function KriMultiSelect<T = unknown>({
|
||||
maxCount = 1,
|
||||
maxSelected,
|
||||
hideSelectAll = false,
|
||||
placeholder = 'Select options',
|
||||
placeholder = '옵션을 선택하세요',
|
||||
widthClassName,
|
||||
heightClassName,
|
||||
spanClassName = 'text-base',
|
||||
badgeClassName = 'text-base',
|
||||
badgeLabelClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
@@ -71,6 +74,7 @@ export function KriMultiSelect<T = unknown>({
|
||||
onItemsChange,
|
||||
onOptionsChange,
|
||||
disabled,
|
||||
'aria-invalid': ariaInvalid,
|
||||
}: KriMultiSelectProps<T>) {
|
||||
const options = React.useMemo(
|
||||
() => toOptions(items, getValue, getLabel, withInfo),
|
||||
@@ -78,7 +82,7 @@ export function KriMultiSelect<T = unknown>({
|
||||
)
|
||||
|
||||
return (
|
||||
<div className={cn('flex-none', widthClassName, heightClassName)}>
|
||||
<div className={cn('flex-none min-w-0', widthClassName, heightClassName)}>
|
||||
<MultiSelect<T>
|
||||
options={options}
|
||||
defaultValue={value}
|
||||
@@ -90,6 +94,7 @@ export function KriMultiSelect<T = unknown>({
|
||||
className={cn('bg-background text-base', !widthClassName && 'w-auto', className)}
|
||||
spanClassName={spanClassName}
|
||||
badgeClassName={badgeClassName}
|
||||
badgeLabelClassName={badgeLabelClassName}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
@@ -100,6 +105,7 @@ export function KriMultiSelect<T = unknown>({
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
disabled={disabled}
|
||||
aria-invalid={ariaInvalid}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
@@ -118,34 +124,50 @@ export interface KriSingleSelectProps<T = unknown> extends KriAutoCompleteBasePr
|
||||
showSelectedTooltip?: boolean
|
||||
}
|
||||
|
||||
export function KriSingleSelect<T = unknown>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
defaultSearchValue = '',
|
||||
onSearchValueChange,
|
||||
placeholder = 'Select an option',
|
||||
heightClassName,
|
||||
widthClassName,
|
||||
spanClassName = 'text-base',
|
||||
badgeClassName = 'text-base',
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
withInfo = false,
|
||||
onItemChange,
|
||||
onOptionChange,
|
||||
preventDeselect = false,
|
||||
hideOptionCheck = false,
|
||||
showSelectedTooltip = false,
|
||||
useClear = false,
|
||||
clearLabel = '선택 해제',
|
||||
clearValue = '__CLEAR__',
|
||||
disabled,
|
||||
}: KriSingleSelectProps<T>) {
|
||||
function KriSingleSelectInner<T>(
|
||||
{
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
defaultSearchValue = '',
|
||||
onSearchValueChange,
|
||||
placeholder = '옵션을 선택하세요',
|
||||
heightClassName,
|
||||
widthClassName,
|
||||
spanClassName = 'text-base',
|
||||
badgeClassName = 'text-base',
|
||||
badgeLabelClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
withInfo = false,
|
||||
onItemChange,
|
||||
onOptionChange,
|
||||
preventDeselect = false,
|
||||
hideOptionCheck = false,
|
||||
showSelectedTooltip = false,
|
||||
useClear = false,
|
||||
clearLabel = '선택 해제',
|
||||
clearValue = '__CLEAR__',
|
||||
disabled,
|
||||
'aria-invalid': ariaInvalid,
|
||||
}: KriSingleSelectProps<T>,
|
||||
forwardedRef: React.ForwardedRef<MultiSelectRef>,
|
||||
) {
|
||||
const ref = React.useRef<MultiSelectRef>(null)
|
||||
React.useImperativeHandle(
|
||||
forwardedRef,
|
||||
() => ({
|
||||
reset: () => ref.current?.reset(),
|
||||
getSelectedValues: () => ref.current?.getSelectedValues() ?? [],
|
||||
setSelectedValues: (values) => ref.current?.setSelectedValues(values),
|
||||
clear: () => ref.current?.clear(),
|
||||
focus: () => ref.current?.focus(),
|
||||
}),
|
||||
[],
|
||||
)
|
||||
const options = React.useMemo(() => {
|
||||
const normal = toOptions(items, getValue, getLabel, withInfo)
|
||||
return useClear ? [{ value: clearValue, label: clearLabel }, ...normal] : normal
|
||||
@@ -153,7 +175,7 @@ export function KriSingleSelect<T = unknown>({
|
||||
const selectedLabel = options.find((option) => option.value === value)?.label
|
||||
|
||||
return (
|
||||
<div className={cn('flex-none', widthClassName, heightClassName)}>
|
||||
<div className={cn('flex-none min-w-0', widthClassName, heightClassName)}>
|
||||
<MultiSelect<T>
|
||||
ref={ref}
|
||||
options={options}
|
||||
@@ -186,6 +208,7 @@ export function KriSingleSelect<T = unknown>({
|
||||
className={cn('bg-background text-base', !widthClassName && 'w-auto', className)}
|
||||
spanClassName={spanClassName}
|
||||
badgeClassName={badgeClassName}
|
||||
badgeLabelClassName={badgeLabelClassName ?? 'min-w-0 flex-1'}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
@@ -199,7 +222,12 @@ export function KriSingleSelect<T = unknown>({
|
||||
deduplicateOptions
|
||||
disabled={disabled}
|
||||
title={showSelectedTooltip ? selectedLabel ?? value : undefined}
|
||||
aria-invalid={ariaInvalid}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const KriSingleSelect = React.forwardRef(KriSingleSelectInner) as <T = unknown>(
|
||||
props: KriSingleSelectProps<T> & { ref?: React.ForwardedRef<MultiSelectRef> },
|
||||
) => React.ReactElement
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
'use client'
|
||||
|
||||
import { useId, useMemo, useState } from 'react'
|
||||
import { forwardRef, useId, useImperativeHandle, useMemo, useRef, useState } from 'react'
|
||||
import { CheckIcon, EyeIcon, EyeOffIcon, XIcon } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export const ALLOWED_SPECIALS_TEXT = `! @ # $ % ^ & * ( ) _ + - = { } [ ] : ; " ' < > , . ? /`
|
||||
export const ONLY_ALLOWED_REGEX = /^[A-Za-z\d!@#$%^&*()_+\-={}\[\]:;"'<>,.?/]+$/
|
||||
export const KRI_PW_REGEX = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_+\-={}\[\]:;"'<>,.?/]{8,20}$/
|
||||
import { KRI_PW_REGEX, ONLY_ALLOWED_PW_REGEX } from '@/const/validationConst'
|
||||
|
||||
const requirements = [
|
||||
{ test: (value: string) => /[A-Za-z]/.test(value), text: '영문 1개 이상' },
|
||||
{ test: (value: string) => /\d/.test(value), text: '숫자 1개 이상' },
|
||||
{ test: (value: string) => value.length >= 8 && value.length <= 20, text: '8~20자' },
|
||||
{ test: (value: string) => !value || ONLY_ALLOWED_REGEX.test(value), text: '허용 문자만 사용' },
|
||||
{ test: (value: string) => !value || ONLY_ALLOWED_PW_REGEX.test(value), text: '허용 문자만 사용' },
|
||||
]
|
||||
|
||||
export type KriPasswordRef = {
|
||||
focus: () => void
|
||||
}
|
||||
|
||||
export interface KriPasswordProps {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
@@ -27,9 +28,10 @@ export interface KriPasswordProps {
|
||||
disabled?: boolean
|
||||
className?: string
|
||||
showStrength?: boolean
|
||||
'aria-invalid'?: boolean
|
||||
}
|
||||
|
||||
export function KriPassword({
|
||||
export const KriPassword = forwardRef<KriPasswordRef, KriPasswordProps>(function KriPassword({
|
||||
value,
|
||||
onChange,
|
||||
id,
|
||||
@@ -38,12 +40,17 @@ export function KriPassword({
|
||||
disabled,
|
||||
className,
|
||||
showStrength = true,
|
||||
}: KriPasswordProps) {
|
||||
'aria-invalid': ariaInvalid,
|
||||
}, forwardedRef) {
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
useImperativeHandle(forwardedRef, () => ({
|
||||
focus: () => inputRef.current?.focus(),
|
||||
}), [])
|
||||
const [isVisible, setIsVisible] = useState(false)
|
||||
const autoId = useId()
|
||||
const inputId = id ?? autoId
|
||||
const isValid = useMemo(() => KRI_PW_REGEX.test(value), [value])
|
||||
const hasOnlyAllowedChars = useMemo(() => (value ? ONLY_ALLOWED_REGEX.test(value) : true), [value])
|
||||
const hasOnlyAllowedChars = useMemo(() => (value ? ONLY_ALLOWED_PW_REGEX.test(value) : true), [value])
|
||||
const checks = useMemo(() => requirements.map((item) => ({ met: item.test(value), text: item.text })), [value])
|
||||
const score = checks.filter((item) => item.met).length
|
||||
|
||||
@@ -60,6 +67,7 @@ export function KriPassword({
|
||||
{label ? <Label htmlFor={inputId}>{label}</Label> : null}
|
||||
<div className="relative">
|
||||
<Input
|
||||
ref={inputRef}
|
||||
id={inputId}
|
||||
type={isVisible ? 'text' : 'password'}
|
||||
placeholder={placeholder}
|
||||
@@ -68,6 +76,7 @@ export function KriPassword({
|
||||
className="pr-9"
|
||||
disabled={disabled}
|
||||
autoComplete="new-password"
|
||||
aria-invalid={ariaInvalid}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -113,6 +122,6 @@ export function KriPassword({
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
export default KriPassword
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import type { CSSProperties } from 'react'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { cn } from '@/lib/utils'
|
||||
@@ -9,6 +10,10 @@ export type KriSelectItem = {
|
||||
label: string
|
||||
}
|
||||
|
||||
export type KriSelectRef = {
|
||||
focus: () => void
|
||||
}
|
||||
|
||||
export type KriSelectProps<T> = {
|
||||
items: T[]
|
||||
value: string
|
||||
@@ -24,6 +29,7 @@ export type KriSelectProps<T> = {
|
||||
getLabel?: (item: T) => string
|
||||
useAll?: boolean
|
||||
disabled?: boolean
|
||||
'aria-invalid'?: boolean
|
||||
}
|
||||
|
||||
const HEIGHT_CLASS_VALUE: Record<string, CSSProperties['height']> = {
|
||||
@@ -34,22 +40,34 @@ const HEIGHT_CLASS_VALUE: Record<string, CSSProperties['height']> = {
|
||||
'h-10': '2.5rem',
|
||||
}
|
||||
|
||||
export function KriSelect<T>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
onChangeOption,
|
||||
placeholder,
|
||||
className,
|
||||
heightClassName,
|
||||
triggerTextClassName,
|
||||
contentClassName,
|
||||
itemClassName,
|
||||
getValue,
|
||||
getLabel,
|
||||
useAll = true,
|
||||
disabled,
|
||||
}: KriSelectProps<T>) {
|
||||
function KriSelectInner<T>(
|
||||
{
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
onChangeOption,
|
||||
placeholder,
|
||||
className,
|
||||
heightClassName,
|
||||
triggerTextClassName,
|
||||
contentClassName,
|
||||
itemClassName,
|
||||
getValue,
|
||||
getLabel,
|
||||
useAll = true,
|
||||
disabled,
|
||||
'aria-invalid': ariaInvalid,
|
||||
}: KriSelectProps<T>,
|
||||
forwardedRef: React.ForwardedRef<KriSelectRef>,
|
||||
) {
|
||||
const triggerRef = React.useRef<HTMLButtonElement>(null)
|
||||
React.useImperativeHandle(
|
||||
forwardedRef,
|
||||
() => ({
|
||||
focus: () => triggerRef.current?.focus(),
|
||||
}),
|
||||
[],
|
||||
)
|
||||
const extractValue = (item: T) => (getValue ? getValue(item) : String(item))
|
||||
const extractLabel = (item: T) => (getLabel ? getLabel(item) : String(item))
|
||||
const triggerStyle: CSSProperties | undefined = heightClassName
|
||||
@@ -70,9 +88,11 @@ export function KriSelect<T>({
|
||||
}}
|
||||
>
|
||||
<SelectTrigger
|
||||
ref={triggerRef}
|
||||
className={cn('w-fit whitespace-nowrap bg-white', triggerTextClassName, heightClassName, className)}
|
||||
style={triggerStyle}
|
||||
aria-label={placeholder ?? 'select'}
|
||||
aria-invalid={ariaInvalid}
|
||||
>
|
||||
<SelectValue placeholder={placeholder} />
|
||||
</SelectTrigger>
|
||||
@@ -96,3 +116,7 @@ export function KriSelect<T>({
|
||||
</Select>
|
||||
)
|
||||
}
|
||||
|
||||
export const KriSelect = React.forwardRef(KriSelectInner) as <T = unknown>(
|
||||
props: KriSelectProps<T> & { ref?: React.ForwardedRef<KriSelectRef> },
|
||||
) => React.ReactElement
|
||||
|
||||
@@ -18,7 +18,7 @@ function MultiSelectInner<T>(
|
||||
defaultValue = [],
|
||||
stickySelectedOptions = [],
|
||||
onStickySelectedOptionsChange,
|
||||
placeholder = 'Select options',
|
||||
placeholder = '옵션을 선택하세요',
|
||||
maxCount = 3,
|
||||
maxSelected,
|
||||
selectionMode = 'multiple',
|
||||
@@ -27,6 +27,7 @@ function MultiSelectInner<T>(
|
||||
className,
|
||||
spanClassName,
|
||||
badgeClassName,
|
||||
badgeLabelClassName,
|
||||
hideSelectAll = false,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
@@ -181,6 +182,7 @@ function MultiSelectInner<T>(
|
||||
variant={variant}
|
||||
spanClassName={spanClassName}
|
||||
badgeClassName={badgeClassName}
|
||||
badgeLabelClassName={badgeLabelClassName}
|
||||
onRemove={(value) => emit(selectedValues.filter((selected) => selected !== value))}
|
||||
onClear={() => emit([])}
|
||||
className={cn(autoSize && 'w-auto', className)}
|
||||
|
||||
@@ -19,6 +19,7 @@ interface MultiSelectTriggerProps<T> extends Omit<React.ButtonHTMLAttributes<HTM
|
||||
variant: MultiSelectVariant
|
||||
spanClassName?: string
|
||||
badgeClassName?: string
|
||||
badgeLabelClassName?: string
|
||||
onRemove: (value: string) => void
|
||||
onClear: () => void
|
||||
}
|
||||
@@ -35,6 +36,7 @@ export const MultiSelectTrigger = React.forwardRef(function MultiSelectTriggerIn
|
||||
variant,
|
||||
spanClassName,
|
||||
badgeClassName,
|
||||
badgeLabelClassName,
|
||||
className,
|
||||
disabled,
|
||||
onRemove,
|
||||
@@ -84,7 +86,7 @@ export const MultiSelectTrigger = React.forwardRef(function MultiSelectTriggerIn
|
||||
style={{ background: option.style?.gradient ?? option.style?.badgeColor }}
|
||||
>
|
||||
{!hideIcons && Icon ? <Icon className="size-3.5" /> : null}
|
||||
<span className="max-w-48 truncate">{option.label}</span>
|
||||
<span className={cn('truncate', badgeLabelClassName ?? 'max-w-48')}>{option.label}</span>
|
||||
{!preventDeselect ? (
|
||||
<span
|
||||
role="button"
|
||||
|
||||
@@ -61,6 +61,7 @@ export interface MultiSelectProps<T = unknown>
|
||||
variant?: MultiSelectVariant
|
||||
spanClassName?: string
|
||||
badgeClassName?: string
|
||||
badgeLabelClassName?: string
|
||||
hideSelectAll?: boolean
|
||||
searchable?: boolean
|
||||
searchMode?: 'filter' | 'inputOnly'
|
||||
|
||||
Reference in New Issue
Block a user