Skip to content

Commit b9956bc

Browse files
added input format option in date/dateRange picker and table's date/dateTime columns
1 parent dcaa670 commit b9956bc

File tree

7 files changed

+66
-24
lines changed

7 files changed

+66
-24
lines changed

client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const commonChildren = {
7070
label: LabelControl,
7171
placeholder: withDefault(StringControl, trans("date.placeholder")),
7272
format: StringControl,
73+
inputFormat: withDefault(StringControl, DATE_FORMAT),
7374
disabled: BoolCodeControl,
7475
onEvent: eventHandlerControl(EventOptions),
7576
showTime: BoolControl,
@@ -92,7 +93,7 @@ const commonChildren = {
9293
type CommonChildrenType = RecordConstructorToComp<typeof commonChildren>;
9394

9495
const datePickerProps = (props: RecordConstructorToView<typeof commonChildren>) =>
95-
_.pick(props, "format", "showTime", "use12Hours", "hourStep", "minuteStep", "secondStep", "placeholder");
96+
_.pick(props, "format", "inputFormat", "showTime", "use12Hours", "hourStep", "minuteStep", "secondStep", "placeholder");
9697

9798
const timeFields = (children: CommonChildrenType, isMobile?: boolean) => [
9899
children.showTime.propertyView({ label: trans("date.showTime") }),
@@ -154,6 +155,7 @@ export type DateCompViewProps = Pick<
154155
RecordConstructorToView<typeof childrenMap>,
155156
| "disabled"
156157
| "format"
158+
| "inputFormat"
157159
| "minDate"
158160
| "maxDate"
159161
| "suffixIcon"
@@ -279,7 +281,7 @@ const DatePickerTmpCmp = new UICompBuilder(childrenMap, (props) => {
279281

280282
{(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && (
281283
<Section name={sectionNames.layout}>
282-
{formatPropertyView({ children })}
284+
{formatPropertyView({ children, placeholder: DATE_FORMAT })}
283285
{children.placeholder.propertyView({ label: trans("date.placeholderText") })}
284286
</Section>
285287
)}

client/packages/lowcoder/src/comps/comps/dateComp/dateRangeUIView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export const DateRangeUIView = (props: DateRangeUIViewProps) => {
6161
return useUIView(
6262
<DateRangeMobileUIView {...props} />,
6363
<RangePickerStyled
64-
{...omit(props, "onChange" , "format")}
64+
{...omit(props, "onChange" , "format", "inputFormat")}
65+
format={props.inputFormat}
6566
ref={props.viewRef as any}
6667
value={[props.start, props.end]}
6768
disabledDate={(current: any) => disabledDate(current, props.minDate, props.maxDate)}

client/packages/lowcoder/src/comps/comps/dateComp/dateUIView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ export const DateUIView = (props: DataUIViewProps) => {
5353
return useUIView(
5454
<DateMobileUIView {...props} />,
5555
<DatePickerStyled
56-
{...omit(props, "format")}
56+
{...omit(props, "format", "inputFormat")}
5757
multiple={false}
58+
format={props.inputFormat}
5859
ref={props.viewRef as any}
5960
minDate={props.minDate ? dayjs(props.minDate, DateParser) : undefined}
6061
maxDate={props.maxDate ? dayjs(props.maxDate, DateParser) : undefined}

client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/columnDateComp.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,19 @@ export function formatDate(date: string, format: string) {
137137
const childrenMap = {
138138
text: StringControl,
139139
format: withDefault(StringControl, DATE_FORMAT),
140+
inputFormat: withDefault(StringControl, DATE_FORMAT),
140141
};
141142

143+
let inputFormat = DATE_FORMAT;
144+
142145
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, string, string> = (props) => props.text;
143146

144147
type DateEditProps = {
145148
value: string;
146149
onChange: (value: string) => void;
147150
onChangeEnd: () => void;
148151
showTime: boolean;
152+
inputFormat: string;
149153
};
150154

151155
export const DateEdit = (props: DateEditProps) => {
@@ -183,6 +187,7 @@ export const DateEdit = (props: DateEditProps) => {
183187
nextIcon={<IconNext />}
184188
superNextIcon={<IconSuperNext />}
185189
superPrevIcon={<SuperPrevIcon />}
190+
format={props.inputFormat}
186191
allowClear={true}
187192
variant="borderless"
188193
autoFocus
@@ -210,6 +215,7 @@ export const DateComp = (function () {
210215
return new ColumnTypeCompBuilder(
211216
childrenMap,
212217
(props, dispatch) => {
218+
inputFormat = props.inputFormat;
213219
const value = props.changeValue ?? getBaseValue(props, dispatch);
214220
return formatDate(value, props.format);
215221
},
@@ -222,6 +228,7 @@ export const DateComp = (function () {
222228
onChange={props.onChange}
223229
onChangeEnd={props.onChangeEnd}
224230
showTime={false}
231+
inputFormat={inputFormat}
225232
/>
226233
))
227234
.setPropertyViewFn((children) => (

client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/columnDateTimeComp.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ import { DateEdit, formatDate } from "./columnDateComp";
1313
const childrenMap = {
1414
text: StringControl,
1515
format: withDefault(StringControl, DATE_TIME_FORMAT),
16+
inputFormat: withDefault(StringControl, DATE_TIME_FORMAT),
1617
};
1718

19+
let inputFormat = DATE_TIME_FORMAT;
20+
1821
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, string, string> = (props) => props.text;
1922

2023
export const DateTimeComp = (function () {
2124
return new ColumnTypeCompBuilder(
2225
childrenMap,
2326
(props, dispatch) => {
27+
inputFormat = props.inputFormat;
2428
const value = props.changeValue ?? getBaseValue(props, dispatch);
2529
return formatDate(value, props.format);
2630
},
@@ -33,6 +37,7 @@ export const DateTimeComp = (function () {
3337
onChange={props.onChange}
3438
onChangeEnd={props.onChangeEnd}
3539
showTime={true}
40+
inputFormat={inputFormat}
3641
/>
3742
))
3843
.setPropertyViewFn((children) => (

client/packages/lowcoder/src/comps/utils/propertyUtils.tsx

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,49 @@ export const showLabelPropertyView = (children: { showLabel: InstanceType<typeof
9999
children.showLabel.propertyView({ label: trans("prop.showLabel") });
100100

101101
export const formatPropertyView = (params: {
102-
children: { format: InstanceType<typeof StringControl> };
102+
children: {
103+
format: InstanceType<typeof StringControl>,
104+
inputFormat: InstanceType<typeof StringControl>
105+
};
103106
placeholder?: string;
104-
}) =>
105-
params.children.format.propertyView({
106-
label: trans("date.format"),
107-
placeholder: params.placeholder,
108-
tooltip: (
109-
<>
110-
{trans("date.reference")} &nbsp;
111-
<a
112-
href={`${
113-
language === "zh" ? "https://day.js.org/docs/zh-CN" : "https://day.js.org/docs/en"
114-
}/display/format`}
115-
target={"_blank"}
116-
rel="noreferrer"
117-
>
118-
dayjs format
119-
</a>
120-
</>
121-
),
122-
}); // FIXME: need verification
107+
}) => {
108+
return [
109+
params.children.format.propertyView({
110+
label: trans("date.format"),
111+
placeholder: params.placeholder,
112+
tooltip: (
113+
<>
114+
{trans("date.reference")} &nbsp;
115+
<a
116+
href={`${
117+
language === "zh" ? "https://day.js.org/docs/zh-CN" : "https://day.js.org/docs/en"
118+
}/display/format`}
119+
target={"_blank"}
120+
rel="noreferrer"
121+
>
122+
dayjs format
123+
</a>
124+
</>
125+
),
126+
}), // FIXME: need verification
127+
params.children.inputFormat.propertyView({
128+
label: trans("date.inputFormat"),
129+
placeholder: params.placeholder,
130+
tooltip: (
131+
<>
132+
{trans("date.reference")} &nbsp;
133+
<a
134+
href={`${
135+
language === "zh" ? "https://day.js.org/docs/zh-CN" : "https://day.js.org/docs/en"
136+
}/display/format`}
137+
target={"_blank"}
138+
rel="noreferrer"
139+
>
140+
dayjs format
141+
</a>
142+
</>
143+
),
144+
})
145+
]
146+
}
147+

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,7 @@ export const en = {
18091809
},
18101810
"date": {
18111811
"format": "Format",
1812+
"inputFormat": "Input Format",
18121813
"formatTip": "Support: 'YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD', 'Timestamp'",
18131814
"reference": "Please Refer to",
18141815
"showTime": "Show Time",

0 commit comments

Comments
 (0)