-
-
Notifications
You must be signed in to change notification settings - Fork 505
/
config_ctx.tsx
47 lines (42 loc) · 1.4 KB
/
config_ctx.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from "react";
import {
MuiConfig, MuiWidgets, AsyncFetchListValuesResult, ConfigContext, FieldProps
} from "@react-awesome-query-builder/mui";
import merge from "lodash/merge";
import { ukUA } from "@mui/material/locale";
//import { ukUA } from "@mui/x-date-pickers/locales"; // todo: throws "TypeError: date.clone is not a function"
//import "moment/locale/ru";
const { MuiFieldAutocomplete, MuiFieldSelect } = MuiWidgets;
// Config context for `DemoQueryBuilder` component
const autocompleteFetch = async (search: string | null, offset: number): Promise<AsyncFetchListValuesResult> => {
const response = await fetch("/api/autocomplete?" + new URLSearchParams({
search: search || "",
offset: offset ? String(offset) : "",
}).toString());
const result = await response.json() as AsyncFetchListValuesResult;
return result;
};
const SliderMark: React.FC<{ pct: number }> = ({ pct }) => {
return <strong><span>{pct}</span><span>%</span></strong>;
};
export default merge(
{},
MuiConfig.ctx,
{
validateFirstName: (val: string) => {
return (val.length < 10);
},
autocompleteFetch,
myRenderField: (props: FieldProps, _ctx: ConfigContext) => {
if (props?.customProps?.["showSearch"]) {
return <MuiFieldAutocomplete {...props}/>;
} else {
return <MuiFieldSelect {...props}/>;
}
},
ukUA,
components: {
SliderMark
}
}
);