diff --git a/apps/ui/components/ui/date-picker.tsx b/apps/ui/components/ui/date-picker.tsx index e2e5d77..453992d 100644 --- a/apps/ui/components/ui/date-picker.tsx +++ b/apps/ui/components/ui/date-picker.tsx @@ -19,6 +19,7 @@ import { Description, FieldError, FieldGroup, Label } from "./field" import { Popover } from "./popover" import { composeTailwindRenderProps } from "./primitive" import { RangeCalendar } from "./range-calendar" +import { Typography } from "./typography" interface DatePickerOverlayProps extends Omit, @@ -78,6 +79,8 @@ interface DatePickerProps extends DatePickerPrimitiveProps< label?: string description?: string errorMessage?: string | ((validation: ValidationResult) => string) + leftDescription?: React.ReactNode + rightDescription?: React.ReactNode } const DatePicker = ({ @@ -85,23 +88,42 @@ const DatePicker = ({ className, description, errorMessage, + leftDescription, + rightDescription, ...props }: DatePickerProps) => { return ( - {label && } - + {label && + + + + } + - {description && {description}} - {errorMessage} + {description && + + {description} + + } + + {(leftDescription || errorMessage || rightDescription) && ( + +
+
{errorMessage ? {errorMessage} : leftDescription}
+
{rightDescription}
+
+
+ )} +
) } export type { DatePickerProps, DateValue, ValidationResult } -export { DatePicker, DatePickerIcon, DatePickerOverlay } +export { DatePicker, DatePickerIcon, DatePickerOverlay } \ No newline at end of file diff --git a/apps/ui/components/ui/select.tsx b/apps/ui/components/ui/select.tsx index 137419b..115c818 100644 --- a/apps/ui/components/ui/select.tsx +++ b/apps/ui/components/ui/select.tsx @@ -48,6 +48,8 @@ interface SelectProps extends SelectPrimitiveProps { errorMessage?: string | ((validation: ValidationResult) => string) items?: Iterable className?: string + leftDescription?: React.ReactNode + rightDescription?: React.ReactNode } const Select = ({ @@ -55,19 +57,37 @@ const Select = ({ description, errorMessage, className, + leftDescription, + rightDescription, ...props }: SelectProps) => { return ( {(values) => ( <> - {label && } + {label && + + + + } {typeof props.children === "function" ? props.children(values) : props.children} - {description && {description}} - {errorMessage} + {description && + + {description} + + } + + {(leftDescription || errorMessage || rightDescription) && ( + +
+
{errorMessage ? {errorMessage} : leftDescription}
+
{rightDescription}
+
+
+ )} )}
@@ -149,4 +169,4 @@ Select.Trigger = SelectTrigger Select.List = SelectList export type { SelectProps, SelectTriggerProps } -export { Select } +export { Select } \ No newline at end of file diff --git a/apps/ui/components/ui/textarea.tsx b/apps/ui/components/ui/textarea.tsx index 50b440f..bf91c1c 100644 --- a/apps/ui/components/ui/textarea.tsx +++ b/apps/ui/components/ui/textarea.tsx @@ -8,6 +8,7 @@ import { composeRenderProps, } from "react-aria-components" import { tv } from "tailwind-variants" +import { useState, useEffect } from "react" import { Description, FieldError, Label } from "./field" import { composeTailwindRenderProps, focusStyles } from "./primitive" @@ -15,7 +16,7 @@ import { Typography } from "./typography" const textareaStyles = tv({ extend: focusStyles, - base: "field-sizing-content max-h-96 min-h-16 w-full min-w-0 rounded-lg border border-input px-2.5 py-2 text-base shadow-xs outline-hidden transition duration-200 disabled:opacity-50 sm:text-sm", + base: "field-sizing-content max-h-96 min-h-16 w-full min-w-0 rounded-lg border border-input px-2.5 py-2 pb-6 text-base shadow-xs outline-hidden transition duration-200 disabled:opacity-50 sm:text-sm break-words whitespace-pre-wrap overflow-wrap-anywhere", }) interface TextareaProps extends TextFieldPrimitiveProps { @@ -26,6 +27,8 @@ interface TextareaProps extends TextFieldPrimitiveProps { errorMessage?: string | ((validation: ValidationResult) => string) className?: string ref?: React.Ref + showCharacterCount?: boolean + maxLength?: number } const Textarea = ({ @@ -35,8 +38,23 @@ const Textarea = ({ description, errorMessage, ref, + showCharacterCount, + maxLength, ...props }: TextareaProps) => { + const [currentLength, setCurrentLength] = useState(props.value?.toString().length || 0); + + useEffect(() => { + setCurrentLength(props.value?.toString().length || 0); + }, [props.value]); + + const getCountText = () => { + if (maxLength) { + return `${currentLength}/${maxLength}`; + } + return `${currentLength}字`; + }; + return ( {label && } - - - textareaStyles({ - ...renderProps, - className, - }), - )} - /> - +
+ + + textareaStyles({ + ...renderProps, + className, + }), + )} + style={{ wordWrap: "break-word", overflowWrap: "break-word" }} + /> + + {showCharacterCount && currentLength > 0 && ( +
+ {getCountText()} +
+ )} +
{description && {description}} {errorMessage}