soda-heroui 0.11.2 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -23
- package/dist/components/FormCalendar.d.ts +1 -0
- package/dist/components/FormDateInput.d.ts +1 -0
- package/dist/components/FormDatePicker.d.ts +1 -0
- package/dist/components/FormDateRangePicker.d.ts +1 -0
- package/dist/components/FormRangeCalendar.d.ts +1 -0
- package/package.json +4 -4
- package/src/components/AutoRefresh.tsx +36 -36
- package/src/components/ErrorMessage.tsx +34 -34
- package/src/components/FormAutocomplete.tsx +27 -27
- package/src/components/FormCalendar.tsx +41 -41
- package/src/components/FormCheckbox.tsx +34 -34
- package/src/components/FormCheckboxGroup.tsx +34 -34
- package/src/components/FormDateInput.tsx +41 -41
- package/src/components/FormDatePicker.tsx +49 -49
- package/src/components/FormDateRangePicker.tsx +56 -56
- package/src/components/FormInput.tsx +34 -34
- package/src/components/FormInputOtp.tsx +34 -34
- package/src/components/FormNumberInput.tsx +34 -34
- package/src/components/FormPagination.tsx +34 -34
- package/src/components/FormProvider.tsx +32 -32
- package/src/components/FormRadioGroup.tsx +34 -34
- package/src/components/FormRangeCalendar.tsx +56 -56
- package/src/components/FormSwitch.tsx +34 -34
- package/src/components/FormTextarea.tsx +34 -34
- package/src/components/FormTimeInput.tsx +42 -42
- package/src/types/index.ts +1 -1
- package/src/utils/addBetterToast.ts +44 -44
- package/src/utils/getFieldProps.tsx +30 -30
- package/src/utils/getTimeValue.ts +30 -30
- package/src/utils/parseTime.ts +24 -24
- package/src/utils/range.ts +80 -80
- package/src/utils/time.ts +50 -50
- package/tsconfig.json +16 -16
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# soda-tanstack-form
|
|
2
|
-
|
|
3
|
-
[](https://npmjs.com/package/soda-tanstack-form)
|
|
4
|
-
[](https://npmjs.com/package/soda-tanstack-form)
|
|
5
|
-
|
|
6
|
-
## Install
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
$ pnpm install
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
$ npm run dev
|
|
14
|
-
$ npm run build
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Options
|
|
18
|
-
|
|
19
|
-
TODO
|
|
20
|
-
|
|
21
|
-
## LICENSE
|
|
22
|
-
|
|
23
|
-
MIT
|
|
1
|
+
# soda-tanstack-form
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/soda-tanstack-form)
|
|
4
|
+
[](https://npmjs.com/package/soda-tanstack-form)
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
$ pnpm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
$ npm run dev
|
|
14
|
+
$ npm run build
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Options
|
|
18
|
+
|
|
19
|
+
TODO
|
|
20
|
+
|
|
21
|
+
## LICENSE
|
|
22
|
+
|
|
23
|
+
MIT
|
|
@@ -14,3 +14,4 @@ export interface FormCalendarProps<ValueMode extends TimeValueMode = "date", Fie
|
|
|
14
14
|
component?: <T extends DateValue>(props: CalendarProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormCalendar<ValueMode extends TimeValueMode = "date", FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined>({ field, valueMode, emptyValue, dateMode, defaultTime, component: Calendar2, ...rest }: FormCalendarProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
+
ctNode;
|
|
@@ -14,3 +14,4 @@ export interface FormDateInputProps<ValueMode extends TimeValueMode = "date", Fi
|
|
|
14
14
|
component?: <T extends DateValue>(props: DateInputProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormDateInput<ValueMode extends TimeValueMode = "date", FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined>({ field, valueMode, emptyValue, dateMode, defaultTime, component: DateInput2, ...rest }: FormDateInputProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
+
ctNode;
|
|
@@ -14,3 +14,4 @@ export interface FormDatePickerProps<ValueMode extends TimeValueMode = "date", F
|
|
|
14
14
|
component?: <T extends DateValue>(props: DatePickerProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormDatePicker<ValueMode extends TimeValueMode = "date", FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined>({ field, valueMode, emptyValue, dateMode, defaultTime, component: DatePicker2, ...rest }: FormDatePickerProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
+
ctNode;
|
|
@@ -14,3 +14,4 @@ export interface FormDateRangePickerProps<ValueMode extends TimeValueMode = "dat
|
|
|
14
14
|
component?: <T extends DateValue>(props: DateRangePickerProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormDateRangePicker<ValueMode extends TimeValueMode = "date", FieldValue extends [TimeValueModeMap<ValueMode>, TimeValueModeMap<ValueMode>] | null | undefined = [TimeValueModeMap<ValueMode>, TimeValueModeMap<ValueMode>] | null | undefined>({ field: _field, valueMode, emptyValue, dateMode, defaultTime, component: DateRangePicker2, ...rest }: FormDateRangePickerProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
+
ctNode;
|
|
@@ -14,3 +14,4 @@ export interface FormRangeCalendarProps<ValueMode extends TimeValueMode = "date"
|
|
|
14
14
|
component?: <T extends DateValue>(props: RangeCalendarProps<T>) => ReactNode;
|
|
15
15
|
}
|
|
16
16
|
export declare function FormRangeCalendar<ValueMode extends TimeValueMode = "date", FieldValue extends [TimeValueModeMap<ValueMode>, TimeValueModeMap<ValueMode>] | null | undefined = [TimeValueModeMap<ValueMode>, TimeValueModeMap<ValueMode>] | null | undefined>({ field: _field, valueMode, emptyValue, dateMode, defaultTime, component: RangeCalendar2, ...rest }: FormRangeCalendarProps<ValueMode, FieldValue>): ReactNode;
|
|
17
|
+
ctNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soda-heroui",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@internationalized/date": "^3.8.2",
|
|
39
39
|
"@tanstack/react-form": "^1.19.0",
|
|
40
40
|
"deepsea-tools": "5.40.4",
|
|
41
|
-
"soda-hooks": "6.
|
|
42
|
-
"soda-
|
|
43
|
-
"soda-
|
|
41
|
+
"soda-hooks": "6.13.0",
|
|
42
|
+
"soda-type": "6.3.1",
|
|
43
|
+
"soda-tanstack-form": "0.2.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@ianvs/prettier-plugin-sort-imports": "^4.6.0",
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { FC, ReactNode } from "react"
|
|
2
|
-
import { Button, PressEvent, addToast } from "@heroui/react"
|
|
3
|
-
import { useAutoRefresh } from "soda-hooks"
|
|
4
|
-
import { FirstParameter } from "soda-type"
|
|
5
|
-
|
|
6
|
-
export interface AutoRefreshProps extends FirstParameter<typeof addToast> {
|
|
7
|
-
onRefresh?: () => void
|
|
8
|
-
children?: ReactNode
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const AutoRefresh: FC<AutoRefreshProps> = ({ children, onRefresh, ...rest }) => {
|
|
12
|
-
if (process.env.NODE_ENV === "development") return children
|
|
13
|
-
|
|
14
|
-
function onPress(e: PressEvent) {
|
|
15
|
-
const closeButton = e.target.parentElement?.querySelector(`[aria-label="关闭"]`) as HTMLButtonElement
|
|
16
|
-
closeButton?.click()
|
|
17
|
-
onRefresh?.()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
useAutoRefresh(() =>
|
|
21
|
-
addToast({
|
|
22
|
-
title: "检测到页面更新",
|
|
23
|
-
description: "为了最佳的体验,请刷新页面",
|
|
24
|
-
color: "warning",
|
|
25
|
-
timeout: Infinity,
|
|
26
|
-
endContent: (
|
|
27
|
-
<Button color="warning" size="sm" variant="flat" onPress={onPress}>
|
|
28
|
-
刷新
|
|
29
|
-
</Button>
|
|
30
|
-
),
|
|
31
|
-
...rest,
|
|
32
|
-
}),
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
return children
|
|
36
|
-
}
|
|
1
|
+
import { FC, ReactNode } from "react"
|
|
2
|
+
import { Button, PressEvent, addToast } from "@heroui/react"
|
|
3
|
+
import { useAutoRefresh } from "soda-hooks"
|
|
4
|
+
import { FirstParameter } from "soda-type"
|
|
5
|
+
|
|
6
|
+
export interface AutoRefreshProps extends FirstParameter<typeof addToast> {
|
|
7
|
+
onRefresh?: () => void
|
|
8
|
+
children?: ReactNode
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const AutoRefresh: FC<AutoRefreshProps> = ({ children, onRefresh, ...rest }) => {
|
|
12
|
+
if (process.env.NODE_ENV === "development") return children
|
|
13
|
+
|
|
14
|
+
function onPress(e: PressEvent) {
|
|
15
|
+
const closeButton = e.target.parentElement?.querySelector(`[aria-label="关闭"]`) as HTMLButtonElement
|
|
16
|
+
closeButton?.click()
|
|
17
|
+
onRefresh?.()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
useAutoRefresh(() =>
|
|
21
|
+
addToast({
|
|
22
|
+
title: "检测到页面更新",
|
|
23
|
+
description: "为了最佳的体验,请刷新页面",
|
|
24
|
+
color: "warning",
|
|
25
|
+
timeout: Infinity,
|
|
26
|
+
endContent: (
|
|
27
|
+
<Button color="warning" size="sm" variant="flat" onPress={onPress}>
|
|
28
|
+
刷新
|
|
29
|
+
</Button>
|
|
30
|
+
),
|
|
31
|
+
...rest,
|
|
32
|
+
}),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return children
|
|
36
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { ComponentProps, FC } from "react"
|
|
4
|
-
import { isNonNullable } from "deepsea-tools"
|
|
5
|
-
|
|
6
|
-
export interface ErrorMessageItem {
|
|
7
|
-
message: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface ErrorMessageProps extends Omit<ComponentProps<"div">, "children"> {
|
|
11
|
-
data: (ErrorMessageItem | undefined)[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function getErrorMessage(error: ErrorMessageItem | string | undefined): string[] {
|
|
15
|
-
if (!isNonNullable(error)) return []
|
|
16
|
-
if (typeof error === "string") return [error]
|
|
17
|
-
if ("errors" in error && Array.isArray(error.errors)) return error.errors.map(e => e.message).filter((item, index, array) => array.indexOf(item) === index)
|
|
18
|
-
return [error.message]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const ErrorMessage: FC<ErrorMessageProps> = props => {
|
|
22
|
-
const { data, ...rest } = props
|
|
23
|
-
const errors = data.flatMap(getErrorMessage).filter((item, index, array) => array.indexOf(item) === index)
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
errors.length > 0 && (
|
|
27
|
-
<div {...rest}>
|
|
28
|
-
{errors.map((item, index) => (
|
|
29
|
-
<div key={index}>{item}</div>
|
|
30
|
-
))}
|
|
31
|
-
</div>
|
|
32
|
-
)
|
|
33
|
-
)
|
|
34
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { ComponentProps, FC } from "react"
|
|
4
|
+
import { isNonNullable } from "deepsea-tools"
|
|
5
|
+
|
|
6
|
+
export interface ErrorMessageItem {
|
|
7
|
+
message: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ErrorMessageProps extends Omit<ComponentProps<"div">, "children"> {
|
|
11
|
+
data: (ErrorMessageItem | undefined)[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getErrorMessage(error: ErrorMessageItem | string | undefined): string[] {
|
|
15
|
+
if (!isNonNullable(error)) return []
|
|
16
|
+
if (typeof error === "string") return [error]
|
|
17
|
+
if ("errors" in error && Array.isArray(error.errors)) return error.errors.map(e => e.message).filter((item, index, array) => array.indexOf(item) === index)
|
|
18
|
+
return [error.message]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const ErrorMessage: FC<ErrorMessageProps> = props => {
|
|
22
|
+
const { data, ...rest } = props
|
|
23
|
+
const errors = data.flatMap(getErrorMessage).filter((item, index, array) => array.indexOf(item) === index)
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
errors.length > 0 && (
|
|
27
|
+
<div {...rest}>
|
|
28
|
+
{errors.map((item, index) => (
|
|
29
|
+
<div key={index}>{item}</div>
|
|
30
|
+
))}
|
|
31
|
+
</div>
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { Key, ReactNode } from "react"
|
|
4
|
-
import { Autocomplete, AutocompleteProps } from "@heroui/react"
|
|
5
|
-
import { FieldComponentProps } from "soda-tanstack-form"
|
|
6
|
-
|
|
7
|
-
import { getFieldProps } from "../utils/getFieldProps"
|
|
8
|
-
|
|
9
|
-
export interface FormAutocompleteProps<FieldValue extends string | null | undefined = string | null | undefined, RenderItem extends object = object>
|
|
10
|
-
extends FieldComponentProps<typeof Autocomplete<RenderItem>, FieldValue> {
|
|
11
|
-
component?: <T extends object>(props: AutocompleteProps<T>) => ReactNode
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function FormAutocomplete<FieldValue extends string | null | undefined = string | null | undefined, RenderItem extends object = object>({
|
|
15
|
-
field,
|
|
16
|
-
component: Autocomplete2 = Autocomplete,
|
|
17
|
-
...rest
|
|
18
|
-
}: FormAutocompleteProps<FieldValue, RenderItem>): ReactNode {
|
|
19
|
-
return (
|
|
20
|
-
<Autocomplete2<RenderItem>
|
|
21
|
-
selectedKey={field.state.value ?? ""}
|
|
22
|
-
onSelectionChange={field.handleChange as (value: Key | null) => void}
|
|
23
|
-
{...getFieldProps(field)}
|
|
24
|
-
{...rest}
|
|
25
|
-
/>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { Key, ReactNode } from "react"
|
|
4
|
+
import { Autocomplete, AutocompleteProps } from "@heroui/react"
|
|
5
|
+
import { FieldComponentProps } from "soda-tanstack-form"
|
|
6
|
+
|
|
7
|
+
import { getFieldProps } from "../utils/getFieldProps"
|
|
8
|
+
|
|
9
|
+
export interface FormAutocompleteProps<FieldValue extends string | null | undefined = string | null | undefined, RenderItem extends object = object>
|
|
10
|
+
extends FieldComponentProps<typeof Autocomplete<RenderItem>, FieldValue> {
|
|
11
|
+
component?: <T extends object>(props: AutocompleteProps<T>) => ReactNode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function FormAutocomplete<FieldValue extends string | null | undefined = string | null | undefined, RenderItem extends object = object>({
|
|
15
|
+
field,
|
|
16
|
+
component: Autocomplete2 = Autocomplete,
|
|
17
|
+
...rest
|
|
18
|
+
}: FormAutocompleteProps<FieldValue, RenderItem>): ReactNode {
|
|
19
|
+
return (
|
|
20
|
+
<Autocomplete2<RenderItem>
|
|
21
|
+
selectedKey={field.state.value ?? ""}
|
|
22
|
+
onSelectionChange={field.handleChange as (value: Key | null) => void}
|
|
23
|
+
{...getFieldProps(field)}
|
|
24
|
+
{...rest}
|
|
25
|
+
/>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { ReactNode, useContext } from "react"
|
|
4
|
-
import { Calendar, CalendarProps, DateValue } from "@heroui/react"
|
|
5
|
-
import { FieldComponentProps } from "soda-tanstack-form"
|
|
6
|
-
import { StrictOmit } from "soda-type"
|
|
7
|
-
|
|
8
|
-
import { EmptyValue, FormContext } from "@/components/FormProvider"
|
|
9
|
-
|
|
10
|
-
import { getFieldProps } from "@/utils/getFieldProps"
|
|
11
|
-
import { DefaultTime } from "@/utils/getTimeValue"
|
|
12
|
-
import { DateMode } from "@/utils/parseTime"
|
|
13
|
-
import { TimeValueMode, TimeValueModeMap, getFieldValue, getOnChange } from "@/utils/time"
|
|
14
|
-
|
|
15
|
-
export interface FormCalendarProps<
|
|
16
|
-
ValueMode extends TimeValueMode = "date",
|
|
17
|
-
FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined,
|
|
18
|
-
> extends StrictOmit<FieldComponentProps<typeof Calendar, FieldValue>, never> {
|
|
19
|
-
valueMode?: ValueMode
|
|
20
|
-
emptyValue?: EmptyValue
|
|
21
|
-
dateMode?: DateMode
|
|
22
|
-
defaultTime?: DefaultTime | (() => DefaultTime)
|
|
23
|
-
component?: <T extends DateValue>(props: CalendarProps<T>) => ReactNode
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function FormCalendar<
|
|
27
|
-
ValueMode extends TimeValueMode = "date",
|
|
28
|
-
FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined,
|
|
29
|
-
>({ field, valueMode, emptyValue, dateMode, defaultTime, component: Calendar2 = Calendar, ...rest }: FormCalendarProps<ValueMode, FieldValue>): ReactNode {
|
|
30
|
-
const context = useContext(FormContext)
|
|
31
|
-
emptyValue ??= context.emptyValue
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<Calendar2
|
|
35
|
-
focusedValue={getFieldValue(field, dateMode)}
|
|
36
|
-
onFocusChange={getOnChange({ field, valueMode, emptyValue, defaultTime })}
|
|
37
|
-
{...getFieldProps(field)}
|
|
38
|
-
{...rest}
|
|
39
|
-
/>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { ReactNode, useContext } from "react"
|
|
4
|
+
import { Calendar, CalendarProps, DateValue } from "@heroui/react"
|
|
5
|
+
import { FieldComponentProps } from "soda-tanstack-form"
|
|
6
|
+
import { StrictOmit } from "soda-type"
|
|
7
|
+
|
|
8
|
+
import { EmptyValue, FormContext } from "@/components/FormProvider"
|
|
9
|
+
|
|
10
|
+
import { getFieldProps } from "@/utils/getFieldProps"
|
|
11
|
+
import { DefaultTime } from "@/utils/getTimeValue"
|
|
12
|
+
import { DateMode } from "@/utils/parseTime"
|
|
13
|
+
import { TimeValueMode, TimeValueModeMap, getFieldValue, getOnChange } from "@/utils/time"
|
|
14
|
+
|
|
15
|
+
export interface FormCalendarProps<
|
|
16
|
+
ValueMode extends TimeValueMode = "date",
|
|
17
|
+
FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined,
|
|
18
|
+
> extends StrictOmit<FieldComponentProps<typeof Calendar, FieldValue>, never> {
|
|
19
|
+
valueMode?: ValueMode
|
|
20
|
+
emptyValue?: EmptyValue
|
|
21
|
+
dateMode?: DateMode
|
|
22
|
+
defaultTime?: DefaultTime | (() => DefaultTime)
|
|
23
|
+
component?: <T extends DateValue>(props: CalendarProps<T>) => ReactNode
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function FormCalendar<
|
|
27
|
+
ValueMode extends TimeValueMode = "date",
|
|
28
|
+
FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined,
|
|
29
|
+
>({ field, valueMode, emptyValue, dateMode, defaultTime, component: Calendar2 = Calendar, ...rest }: FormCalendarProps<ValueMode, FieldValue>): ReactNode {
|
|
30
|
+
const context = useContext(FormContext)
|
|
31
|
+
emptyValue ??= context.emptyValue
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Calendar2
|
|
35
|
+
focusedValue={getFieldValue(field, dateMode)}
|
|
36
|
+
onFocusChange={getOnChange({ field, valueMode, emptyValue, defaultTime })}
|
|
37
|
+
{...getFieldProps(field)}
|
|
38
|
+
{...rest}
|
|
39
|
+
/>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { ComponentPropsWithoutRef, ReactNode } from "react"
|
|
4
|
-
import { As, Checkbox, CheckboxProps, MergeWithAs } from "@heroui/react"
|
|
5
|
-
import { Field } from "soda-tanstack-form"
|
|
6
|
-
|
|
7
|
-
import { getFieldProps } from "../utils/getFieldProps"
|
|
8
|
-
|
|
9
|
-
export type FormCheckboxProps<FieldValue extends boolean | null | undefined = boolean | null | undefined, AsComponent extends As = "input"> = MergeWithAs<
|
|
10
|
-
ComponentPropsWithoutRef<"input">,
|
|
11
|
-
ComponentPropsWithoutRef<AsComponent>,
|
|
12
|
-
CheckboxProps,
|
|
13
|
-
AsComponent
|
|
14
|
-
> & {
|
|
15
|
-
field: Field<FieldValue>
|
|
16
|
-
component?: <AsComponent extends As = "input">(
|
|
17
|
-
props: MergeWithAs<ComponentPropsWithoutRef<"input">, ComponentPropsWithoutRef<AsComponent>, CheckboxProps, AsComponent>,
|
|
18
|
-
) => ReactNode
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function FormCheckbox<FieldValue extends boolean | null | undefined = boolean | null | undefined, AsComponent extends As = "input">({
|
|
22
|
-
field,
|
|
23
|
-
component: Checkbox2 = Checkbox,
|
|
24
|
-
...rest
|
|
25
|
-
}: FormCheckboxProps<FieldValue, AsComponent>): ReactNode {
|
|
26
|
-
return (
|
|
27
|
-
<Checkbox2<AsComponent>
|
|
28
|
-
isSelected={field.state.value ?? false}
|
|
29
|
-
onValueChange={field.handleChange as (value: boolean) => void}
|
|
30
|
-
{...getFieldProps(field, true)}
|
|
31
|
-
{...rest}
|
|
32
|
-
/>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react"
|
|
4
|
+
import { As, Checkbox, CheckboxProps, MergeWithAs } from "@heroui/react"
|
|
5
|
+
import { Field } from "soda-tanstack-form"
|
|
6
|
+
|
|
7
|
+
import { getFieldProps } from "../utils/getFieldProps"
|
|
8
|
+
|
|
9
|
+
export type FormCheckboxProps<FieldValue extends boolean | null | undefined = boolean | null | undefined, AsComponent extends As = "input"> = MergeWithAs<
|
|
10
|
+
ComponentPropsWithoutRef<"input">,
|
|
11
|
+
ComponentPropsWithoutRef<AsComponent>,
|
|
12
|
+
CheckboxProps,
|
|
13
|
+
AsComponent
|
|
14
|
+
> & {
|
|
15
|
+
field: Field<FieldValue>
|
|
16
|
+
component?: <AsComponent extends As = "input">(
|
|
17
|
+
props: MergeWithAs<ComponentPropsWithoutRef<"input">, ComponentPropsWithoutRef<AsComponent>, CheckboxProps, AsComponent>,
|
|
18
|
+
) => ReactNode
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function FormCheckbox<FieldValue extends boolean | null | undefined = boolean | null | undefined, AsComponent extends As = "input">({
|
|
22
|
+
field,
|
|
23
|
+
component: Checkbox2 = Checkbox,
|
|
24
|
+
...rest
|
|
25
|
+
}: FormCheckboxProps<FieldValue, AsComponent>): ReactNode {
|
|
26
|
+
return (
|
|
27
|
+
<Checkbox2<AsComponent>
|
|
28
|
+
isSelected={field.state.value ?? false}
|
|
29
|
+
onValueChange={field.handleChange as (value: boolean) => void}
|
|
30
|
+
{...getFieldProps(field, true)}
|
|
31
|
+
{...rest}
|
|
32
|
+
/>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { ComponentPropsWithoutRef, ReactNode } from "react"
|
|
4
|
-
import { As, CheckboxGroup, CheckboxGroupProps, MergeWithAs } from "@heroui/react"
|
|
5
|
-
import { Field } from "soda-tanstack-form"
|
|
6
|
-
|
|
7
|
-
import { getFieldProps } from "../utils/getFieldProps"
|
|
8
|
-
|
|
9
|
-
export type FormCheckboxGroupProps<FieldValue extends string[] | null | undefined = string[] | null | undefined, AsComponent extends As = "div"> = MergeWithAs<
|
|
10
|
-
ComponentPropsWithoutRef<"div">,
|
|
11
|
-
ComponentPropsWithoutRef<AsComponent>,
|
|
12
|
-
CheckboxGroupProps,
|
|
13
|
-
AsComponent
|
|
14
|
-
> & {
|
|
15
|
-
field: Field<FieldValue>
|
|
16
|
-
component?: <AsComponent extends As = "div">(
|
|
17
|
-
props: MergeWithAs<ComponentPropsWithoutRef<"div">, ComponentPropsWithoutRef<AsComponent>, CheckboxGroupProps, AsComponent>,
|
|
18
|
-
) => ReactNode
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function FormCheckboxGroup<FieldValue extends string[] | null | undefined = string[] | null | undefined, AsComponent extends As = "div">({
|
|
22
|
-
field,
|
|
23
|
-
component: CheckboxGroup2 = CheckboxGroup,
|
|
24
|
-
...rest
|
|
25
|
-
}: FormCheckboxGroupProps<FieldValue, AsComponent>): ReactNode {
|
|
26
|
-
return (
|
|
27
|
-
<CheckboxGroup2<AsComponent>
|
|
28
|
-
value={field.state.value ?? []}
|
|
29
|
-
onValueChange={field.handleChange as (value: string[]) => void}
|
|
30
|
-
{...getFieldProps(field)}
|
|
31
|
-
{...rest}
|
|
32
|
-
/>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { ComponentPropsWithoutRef, ReactNode } from "react"
|
|
4
|
+
import { As, CheckboxGroup, CheckboxGroupProps, MergeWithAs } from "@heroui/react"
|
|
5
|
+
import { Field } from "soda-tanstack-form"
|
|
6
|
+
|
|
7
|
+
import { getFieldProps } from "../utils/getFieldProps"
|
|
8
|
+
|
|
9
|
+
export type FormCheckboxGroupProps<FieldValue extends string[] | null | undefined = string[] | null | undefined, AsComponent extends As = "div"> = MergeWithAs<
|
|
10
|
+
ComponentPropsWithoutRef<"div">,
|
|
11
|
+
ComponentPropsWithoutRef<AsComponent>,
|
|
12
|
+
CheckboxGroupProps,
|
|
13
|
+
AsComponent
|
|
14
|
+
> & {
|
|
15
|
+
field: Field<FieldValue>
|
|
16
|
+
component?: <AsComponent extends As = "div">(
|
|
17
|
+
props: MergeWithAs<ComponentPropsWithoutRef<"div">, ComponentPropsWithoutRef<AsComponent>, CheckboxGroupProps, AsComponent>,
|
|
18
|
+
) => ReactNode
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function FormCheckboxGroup<FieldValue extends string[] | null | undefined = string[] | null | undefined, AsComponent extends As = "div">({
|
|
22
|
+
field,
|
|
23
|
+
component: CheckboxGroup2 = CheckboxGroup,
|
|
24
|
+
...rest
|
|
25
|
+
}: FormCheckboxGroupProps<FieldValue, AsComponent>): ReactNode {
|
|
26
|
+
return (
|
|
27
|
+
<CheckboxGroup2<AsComponent>
|
|
28
|
+
value={field.state.value ?? []}
|
|
29
|
+
onValueChange={field.handleChange as (value: string[]) => void}
|
|
30
|
+
{...getFieldProps(field)}
|
|
31
|
+
{...rest}
|
|
32
|
+
/>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { ReactNode, useContext } from "react"
|
|
4
|
-
import { DateInput, DateInputProps, DateValue } from "@heroui/react"
|
|
5
|
-
import { FieldComponentProps } from "soda-tanstack-form"
|
|
6
|
-
import { StrictOmit } from "soda-type"
|
|
7
|
-
|
|
8
|
-
import { EmptyValue, FormContext } from "@/components/FormProvider"
|
|
9
|
-
|
|
10
|
-
import { getFieldProps } from "@/utils/getFieldProps"
|
|
11
|
-
import { DefaultTime } from "@/utils/getTimeValue"
|
|
12
|
-
import { DateMode } from "@/utils/parseTime"
|
|
13
|
-
import { TimeValueMode, TimeValueModeMap, getFieldValue, getOnChange } from "@/utils/time"
|
|
14
|
-
|
|
15
|
-
export interface FormDateInputProps<
|
|
16
|
-
ValueMode extends TimeValueMode = "date",
|
|
17
|
-
FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined,
|
|
18
|
-
> extends StrictOmit<FieldComponentProps<typeof DateInput, FieldValue>, never> {
|
|
19
|
-
valueMode?: ValueMode
|
|
20
|
-
emptyValue?: EmptyValue
|
|
21
|
-
dateMode?: DateMode
|
|
22
|
-
defaultTime?: DefaultTime | (() => DefaultTime)
|
|
23
|
-
component?: <T extends DateValue>(props: DateInputProps<T>) => ReactNode
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function FormDateInput<
|
|
27
|
-
ValueMode extends TimeValueMode = "date",
|
|
28
|
-
FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined,
|
|
29
|
-
>({ field, valueMode, emptyValue, dateMode, defaultTime, component: DateInput2 = DateInput, ...rest }: FormDateInputProps<ValueMode, FieldValue>): ReactNode {
|
|
30
|
-
const context = useContext(FormContext)
|
|
31
|
-
emptyValue ??= context.emptyValue
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<DateInput2
|
|
35
|
-
value={getFieldValue(field, dateMode)}
|
|
36
|
-
onChange={getOnChange({ field, valueMode, emptyValue, defaultTime })}
|
|
37
|
-
{...getFieldProps(field)}
|
|
38
|
-
{...rest}
|
|
39
|
-
/>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { ReactNode, useContext } from "react"
|
|
4
|
+
import { DateInput, DateInputProps, DateValue } from "@heroui/react"
|
|
5
|
+
import { FieldComponentProps } from "soda-tanstack-form"
|
|
6
|
+
import { StrictOmit } from "soda-type"
|
|
7
|
+
|
|
8
|
+
import { EmptyValue, FormContext } from "@/components/FormProvider"
|
|
9
|
+
|
|
10
|
+
import { getFieldProps } from "@/utils/getFieldProps"
|
|
11
|
+
import { DefaultTime } from "@/utils/getTimeValue"
|
|
12
|
+
import { DateMode } from "@/utils/parseTime"
|
|
13
|
+
import { TimeValueMode, TimeValueModeMap, getFieldValue, getOnChange } from "@/utils/time"
|
|
14
|
+
|
|
15
|
+
export interface FormDateInputProps<
|
|
16
|
+
ValueMode extends TimeValueMode = "date",
|
|
17
|
+
FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined,
|
|
18
|
+
> extends StrictOmit<FieldComponentProps<typeof DateInput, FieldValue>, never> {
|
|
19
|
+
valueMode?: ValueMode
|
|
20
|
+
emptyValue?: EmptyValue
|
|
21
|
+
dateMode?: DateMode
|
|
22
|
+
defaultTime?: DefaultTime | (() => DefaultTime)
|
|
23
|
+
component?: <T extends DateValue>(props: DateInputProps<T>) => ReactNode
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function FormDateInput<
|
|
27
|
+
ValueMode extends TimeValueMode = "date",
|
|
28
|
+
FieldValue extends TimeValueModeMap<ValueMode> | null | undefined = TimeValueModeMap<ValueMode> | null | undefined,
|
|
29
|
+
>({ field, valueMode, emptyValue, dateMode, defaultTime, component: DateInput2 = DateInput, ...rest }: FormDateInputProps<ValueMode, FieldValue>): ReactNode {
|
|
30
|
+
const context = useContext(FormContext)
|
|
31
|
+
emptyValue ??= context.emptyValue
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<DateInput2
|
|
35
|
+
value={getFieldValue(field, dateMode)}
|
|
36
|
+
onChange={getOnChange({ field, valueMode, emptyValue, defaultTime })}
|
|
37
|
+
{...getFieldProps(field)}
|
|
38
|
+
{...rest}
|
|
39
|
+
/>
|
|
40
|
+
)
|
|
41
|
+
}
|