Files
gsfdc/demo-dify/dify/web/app/components/tools/parameters/tool-date-range-picker.tsx
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

53 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use client'
import type { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { ToolDatePicker } from './tool-date-picker'
import { parseToolDateRangeValue, stringifyToolDateRangeValue } from './tool-date-range-value'
type Props = {
label: string
value: unknown
onChange: (next: string) => void
readOnly?: boolean
}
export const ToolDateRangePicker: FC<Props> = ({ label, value, onChange, readOnly = false }) => {
const { t } = useTranslation(['workflow', 'common'])
const startLabel = t(($) => $['nodes.tool.dateRange.startPlaceholder'], { ns: 'workflow' })
const endLabel = t(($) => $['nodes.tool.dateRange.endPlaceholder'], { ns: 'workflow' })
const clearLabel = t(($) => $['operation.clear'], { ns: 'common' })
const parsed = parseToolDateRangeValue(value)
const patch = (partial: Partial<{ start?: string; end?: string }>) => {
const next = { ...parsed, ...partial }
if (!next.start) delete next.start
if (!next.end) delete next.end
onChange(stringifyToolDateRangeValue(next))
}
return (
<div role="group" aria-label={label} className="flex min-w-0 items-center gap-1">
<ToolDatePicker
aria-label={startLabel}
clearLabel={`${startLabel}: ${clearLabel}`}
value={parsed.start}
onChange={(start) => patch({ start: start || undefined })}
readOnly={readOnly}
maxDate={parsed.end || undefined}
placeholder={startLabel}
/>
<span aria-hidden="true">–</span>
<ToolDatePicker
aria-label={endLabel}
clearLabel={`${endLabel}: ${clearLabel}`}
value={parsed.end}
onChange={(end) => patch({ end: end || undefined })}
readOnly={readOnly}
minDate={parsed.start || undefined}
placeholder={endLabel}
/>
</div>
)
}