@pautena/react-design-system 0.8.2 → 0.10.0
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/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/drawers/drawer-subheader/drawer-subheader.d.ts +1 -1
- package/dist/cjs/types/components/inputs/date-range-calendar/date-range-calendar.d.ts +7 -0
- package/dist/cjs/types/components/inputs/date-range-calendar/index.d.ts +1 -0
- package/dist/cjs/types/components/inputs/date-range-picker/date-range-picker.d.ts +11 -0
- package/dist/cjs/types/components/inputs/date-range-picker/index.d.ts +1 -0
- package/dist/cjs/types/components/inputs/index.d.ts +2 -0
- package/dist/cjs/types/components/inputs/select/select.d.ts +2 -2
- package/dist/cjs/types/components/navigation/link/link.d.ts +1 -1
- package/dist/cjs/types/generators/generators.mock.d.ts +0 -1
- package/dist/cjs/types/generators/generators.model.d.ts +2 -0
- package/dist/cjs/types/generators/model-form/model-form-field.d.ts +10 -0
- package/dist/cjs/types/generators/model-form/model-form.d.ts +2 -1
- package/dist/cjs/types/utils/arrays.d.ts +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/drawers/drawer-subheader/drawer-subheader.d.ts +1 -1
- package/dist/esm/types/components/inputs/date-range-calendar/date-range-calendar.d.ts +7 -0
- package/dist/esm/types/components/inputs/date-range-calendar/index.d.ts +1 -0
- package/dist/esm/types/components/inputs/date-range-picker/date-range-picker.d.ts +11 -0
- package/dist/esm/types/components/inputs/date-range-picker/index.d.ts +1 -0
- package/dist/esm/types/components/inputs/index.d.ts +2 -0
- package/dist/esm/types/components/inputs/select/select.d.ts +2 -2
- package/dist/esm/types/components/navigation/link/link.d.ts +1 -1
- package/dist/esm/types/generators/generators.mock.d.ts +0 -1
- package/dist/esm/types/generators/generators.model.d.ts +2 -0
- package/dist/esm/types/generators/model-form/model-form-field.d.ts +10 -0
- package/dist/esm/types/generators/model-form/model-form.d.ts +2 -1
- package/dist/esm/types/utils/arrays.d.ts +1 -1
- package/dist/index.d.ts +26 -5
- package/package.json +54 -51
- package/src/components/inputs/autocomplete/autocomplete.stories.tsx +1 -1
- package/src/components/inputs/autocomplete/autocomplete.test.tsx +1 -1
- package/src/components/inputs/date-range-calendar/date-range-calendar.stories.tsx +19 -0
- package/src/components/inputs/date-range-calendar/date-range-calendar.test.tsx +150 -0
- package/src/components/inputs/date-range-calendar/date-range-calendar.tsx +118 -0
- package/src/components/inputs/date-range-calendar/index.ts +1 -0
- package/src/components/inputs/date-range-picker/date-range-picker.stories.tsx +32 -0
- package/src/components/inputs/date-range-picker/date-range-picker.test.tsx +165 -0
- package/src/components/inputs/date-range-picker/date-range-picker.tsx +67 -0
- package/src/components/inputs/date-range-picker/index.ts +1 -0
- package/src/components/inputs/index.ts +2 -0
- package/src/components/inputs/inputs.stories.mdx +2 -0
- package/src/components/inputs/select/select.stories.tsx +1 -1
- package/src/components/inputs/text-field/text-field.stories.tsx +1 -1
- package/src/components/inputs/text-field/text-field.test.tsx +1 -1
- package/src/generators/generators.mock.ts +6 -15
- package/src/generators/generators.model.test.ts +0 -3
- package/src/generators/generators.model.ts +2 -0
- package/src/generators/model-form/model-form-field.tsx +269 -0
- package/src/generators/model-form/model-form.stories.tsx +9 -0
- package/src/generators/model-form/model-form.test.tsx +32 -18
- package/src/generators/model-form/model-form.tsx +19 -224
- package/src/generators/model-router/model-router.test.tsx +21 -37
- package/src/tests/assertions.ts +2 -7
- package/src/tests/testing-library.tsx +9 -2
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Box, BoxProps, styled } from "@mui/material";
|
|
2
|
+
import { DateCalendar, PickersDay, PickersDayProps } from "@mui/x-date-pickers";
|
|
3
|
+
import { endOfWeek, format, isAfter, isSameDay, startOfWeek } from "date-fns";
|
|
4
|
+
import { isBefore } from "date-fns/esm";
|
|
5
|
+
import React, { useState } from "react";
|
|
6
|
+
|
|
7
|
+
type DateRange = [Date, Date | undefined];
|
|
8
|
+
|
|
9
|
+
interface CustomPickerDayProps extends BoxProps {
|
|
10
|
+
dayIsBetween: boolean;
|
|
11
|
+
isFirstDay: boolean;
|
|
12
|
+
isLastDay: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const CustomPickersDayBackground = styled(Box, {
|
|
16
|
+
shouldForwardProp: (prop) =>
|
|
17
|
+
prop !== "dayIsBetween" &&
|
|
18
|
+
prop !== "isFirstDay" &&
|
|
19
|
+
prop !== "isLastDay" &&
|
|
20
|
+
prop !== "isStartOfWeek" &&
|
|
21
|
+
prop !== "isEndOfWeek",
|
|
22
|
+
})<CustomPickerDayProps>(({ theme, dayIsBetween, isFirstDay, isLastDay }) => {
|
|
23
|
+
return {
|
|
24
|
+
...((isFirstDay || isLastDay || dayIsBetween) && {
|
|
25
|
+
borderRadius: 0,
|
|
26
|
+
backgroundColor: `${theme.palette.primary.light}40`,
|
|
27
|
+
margin: 0,
|
|
28
|
+
}),
|
|
29
|
+
...(isFirstDay && {
|
|
30
|
+
borderTopLeftRadius: "50%",
|
|
31
|
+
borderBottomLeftRadius: "50%",
|
|
32
|
+
}),
|
|
33
|
+
...(isLastDay && {
|
|
34
|
+
borderTopRightRadius: "50%",
|
|
35
|
+
borderBottomRightRadius: "50%",
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
}) as React.ComponentType<CustomPickerDayProps>;
|
|
39
|
+
|
|
40
|
+
const Day = (props: PickersDayProps<Date> & { dateRange?: DateRange | null }) => {
|
|
41
|
+
const { day, dateRange, ...other } = props;
|
|
42
|
+
|
|
43
|
+
if (dateRange == null) {
|
|
44
|
+
return <PickersDay day={day} {...other} />;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const [start, end] = dateRange;
|
|
48
|
+
|
|
49
|
+
const dayIsBetween = !!end && isAfter(day, start) && isBefore(day, end);
|
|
50
|
+
const isFirstDay = isSameDay(day, start);
|
|
51
|
+
const isLastDay = !!end && isSameDay(day, end);
|
|
52
|
+
const isStartOfWeek = isSameDay(day, startOfWeek(day));
|
|
53
|
+
const isEndOfWeek = isSameDay(day, endOfWeek(day));
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<CustomPickersDayBackground
|
|
57
|
+
dayIsBetween={dayIsBetween}
|
|
58
|
+
isFirstDay={isFirstDay || (dayIsBetween && isStartOfWeek)}
|
|
59
|
+
isLastDay={isLastDay || (dayIsBetween && isEndOfWeek)}
|
|
60
|
+
aria-label={format(day, "yyyy-MM-dd")}
|
|
61
|
+
aria-selected={dayIsBetween || isFirstDay || isLastDay}
|
|
62
|
+
role="gridcell"
|
|
63
|
+
>
|
|
64
|
+
<PickersDay {...other} day={day} selected={isFirstDay || isLastDay} />
|
|
65
|
+
</CustomPickersDayBackground>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export interface DateRangeCalendarProps {
|
|
70
|
+
defaultValue: DateRange;
|
|
71
|
+
onValueChange: (value: DateRange, updatedIndex: number) => void;
|
|
72
|
+
}
|
|
73
|
+
export const DateRangeCalendar = ({ defaultValue, onValueChange }: DateRangeCalendarProps) => {
|
|
74
|
+
const [value, setValue] = useState(defaultValue);
|
|
75
|
+
const [index, setIndex] = useState(0);
|
|
76
|
+
|
|
77
|
+
const setValueRange = (newRange: DateRange, index: number, newIndex: number) => {
|
|
78
|
+
setValue(newRange);
|
|
79
|
+
onValueChange(newRange, index);
|
|
80
|
+
setIndex(newIndex);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const handleChange = (newValue: Date | null) => {
|
|
84
|
+
if (!newValue) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// If is the end date and is minor than the start date
|
|
89
|
+
if (index === 1 && newValue < value[0]) {
|
|
90
|
+
return setValueRange([newValue, undefined], 0, 1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// If is the start date and is bigger than the end date
|
|
94
|
+
if (index === 0 && value[1] && newValue > value[1]) {
|
|
95
|
+
return setValueRange([newValue, undefined], 0, 1);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Default case
|
|
99
|
+
setValueRange(
|
|
100
|
+
[index === 0 ? newValue : value[0], index === 1 ? newValue : value[1]],
|
|
101
|
+
index,
|
|
102
|
+
index === 0 ? 1 : 0,
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
return (
|
|
106
|
+
<DateCalendar
|
|
107
|
+
value={null}
|
|
108
|
+
onChange={handleChange}
|
|
109
|
+
slots={{ day: Day }}
|
|
110
|
+
slotProps={{
|
|
111
|
+
day: {
|
|
112
|
+
dateRange: value,
|
|
113
|
+
} as any,
|
|
114
|
+
}}
|
|
115
|
+
aria-label="calendar range picker"
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./date-range-calendar";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { withContainer, withLocalizationProvider } from "~/storybook";
|
|
3
|
+
import { DateRangePicker } from "./date-range-picker";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: "Components/Inputs/DateRangePicker",
|
|
7
|
+
component: DateRangePicker,
|
|
8
|
+
decorators: [withLocalizationProvider, withContainer({ width: 300 })],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: "centered",
|
|
11
|
+
},
|
|
12
|
+
} satisfies Meta<typeof DateRangePicker>;
|
|
13
|
+
type Story = StoryObj<typeof DateRangePicker>;
|
|
14
|
+
|
|
15
|
+
export const Default: Story = {
|
|
16
|
+
args: {
|
|
17
|
+
label: "Select your date range",
|
|
18
|
+
defaultValue: [new Date(2023, 4, 9), new Date(2023, 4, 18)],
|
|
19
|
+
format: "yyyy/MM/dd",
|
|
20
|
+
fullWidth: true,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const Small: Story = {
|
|
25
|
+
args: {
|
|
26
|
+
label: "Select your date range",
|
|
27
|
+
defaultValue: [new Date(2023, 4, 9), new Date(2023, 4, 18)],
|
|
28
|
+
format: "yyyy/MM/dd",
|
|
29
|
+
fullWidth: true,
|
|
30
|
+
size: "small",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fireEvent,
|
|
3
|
+
render,
|
|
4
|
+
screen,
|
|
5
|
+
waitFor,
|
|
6
|
+
waitForElementToBeRemoved,
|
|
7
|
+
} from "~/tests/testing-library";
|
|
8
|
+
import { DateRangePicker } from "./date-range-picker";
|
|
9
|
+
import { vi } from "vitest";
|
|
10
|
+
import React from "react";
|
|
11
|
+
import userEvent from "@testing-library/user-event";
|
|
12
|
+
|
|
13
|
+
describe("DateRangePicker", () => {
|
|
14
|
+
const renderComponent = () => {
|
|
15
|
+
const onValueChange = vi.fn();
|
|
16
|
+
const startDate = new Date(2023, 4, 2);
|
|
17
|
+
const endDate = new Date(2023, 4, 24);
|
|
18
|
+
render(
|
|
19
|
+
<DateRangePicker
|
|
20
|
+
label="lorem ipsum"
|
|
21
|
+
format="yyyy-MM-dd"
|
|
22
|
+
defaultValue={[startDate, endDate]}
|
|
23
|
+
onValueChange={onValueChange}
|
|
24
|
+
/>,
|
|
25
|
+
);
|
|
26
|
+
return { startDate, endDate, onValueChange };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
vi.useFakeTimers();
|
|
31
|
+
vi.setSystemTime(new Date(2023, 4, 26));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
vi.useRealTimers();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should render an input with a label", () => {
|
|
39
|
+
renderComponent();
|
|
40
|
+
|
|
41
|
+
expect(screen.getByRole("textbox", { name: /lorem ipsum/i })).toBeVisible();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should render the value inside the input with the correct format", () => {
|
|
45
|
+
renderComponent();
|
|
46
|
+
|
|
47
|
+
expect(screen.getByRole("textbox")).toHaveValue("2023-05-02 - 2023-05-24");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should open a date selector if the calendar icon is clicked", () => {
|
|
51
|
+
renderComponent();
|
|
52
|
+
|
|
53
|
+
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
54
|
+
|
|
55
|
+
expect(screen.getByLabelText(/calendar range picker/i)).toBeVisible();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("date selection", () => {
|
|
59
|
+
it("should call onValueChange when the first date is selected with the first value changed", () => {
|
|
60
|
+
const { endDate, onValueChange } = renderComponent();
|
|
61
|
+
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
62
|
+
|
|
63
|
+
fireEvent.click(
|
|
64
|
+
screen.getByRole("gridcell", {
|
|
65
|
+
name: "4",
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
70
|
+
expect(onValueChange).toHaveBeenCalledWith([new Date(2023, 4, 4), endDate], 0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("second value selected", () => {
|
|
74
|
+
it("should call onValueChange when the second date is selected with the second value changed", () => {
|
|
75
|
+
const { onValueChange } = renderComponent();
|
|
76
|
+
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
77
|
+
|
|
78
|
+
fireEvent.click(
|
|
79
|
+
screen.getByRole("gridcell", {
|
|
80
|
+
name: "4",
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
fireEvent.click(
|
|
84
|
+
screen.getByRole("gridcell", {
|
|
85
|
+
name: "12",
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(onValueChange).toHaveBeenCalledTimes(2);
|
|
90
|
+
expect(onValueChange).toHaveBeenLastCalledWith(
|
|
91
|
+
[new Date(2023, 4, 4), new Date(2023, 4, 12)],
|
|
92
|
+
1,
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe(" when a second date minor than the initial date", () => {
|
|
98
|
+
it("should call onValueChange changing the first value with end date as undefined", () => {
|
|
99
|
+
const { onValueChange } = renderComponent();
|
|
100
|
+
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
101
|
+
|
|
102
|
+
fireEvent.click(
|
|
103
|
+
screen.getByRole("gridcell", {
|
|
104
|
+
name: "12",
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
fireEvent.click(
|
|
108
|
+
screen.getByRole("gridcell", {
|
|
109
|
+
name: "6",
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
expect(onValueChange).toHaveBeenCalledTimes(2);
|
|
114
|
+
expect(onValueChange).toHaveBeenLastCalledWith([new Date(2023, 4, 6), undefined], 0);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should show the date format as end date", () => {
|
|
118
|
+
renderComponent();
|
|
119
|
+
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
120
|
+
|
|
121
|
+
fireEvent.click(
|
|
122
|
+
screen.getByRole("gridcell", {
|
|
123
|
+
name: "12",
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
fireEvent.click(
|
|
127
|
+
screen.getByRole("gridcell", {
|
|
128
|
+
name: "6",
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect(screen.getByRole("textbox")).toHaveValue("2023-05-06 - YYYY-MM-DD");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("when the first date is bigger than the end date", () => {
|
|
137
|
+
it("should call onValueChange changing the firest value with the end date as undefined", () => {
|
|
138
|
+
const { onValueChange } = renderComponent();
|
|
139
|
+
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
140
|
+
|
|
141
|
+
fireEvent.click(
|
|
142
|
+
screen.getByRole("gridcell", {
|
|
143
|
+
name: "28",
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
148
|
+
expect(onValueChange).toHaveBeenCalledWith([new Date(2023, 4, 28), undefined], 0);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should show the date format as end date", () => {
|
|
152
|
+
renderComponent();
|
|
153
|
+
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
154
|
+
|
|
155
|
+
fireEvent.click(
|
|
156
|
+
screen.getByRole("gridcell", {
|
|
157
|
+
name: "28",
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(screen.getByRole("textbox")).toHaveValue("2023-05-28 - YYYY-MM-DD");
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { format } from "date-fns";
|
|
3
|
+
import {
|
|
4
|
+
Box,
|
|
5
|
+
Button,
|
|
6
|
+
Collapse,
|
|
7
|
+
Grid,
|
|
8
|
+
IconButton,
|
|
9
|
+
InputAdornment,
|
|
10
|
+
Paper,
|
|
11
|
+
TextField,
|
|
12
|
+
} from "@mui/material";
|
|
13
|
+
import EventIcon from "@mui/icons-material/Event";
|
|
14
|
+
import { DateRangeCalendar } from "../date-range-calendar";
|
|
15
|
+
|
|
16
|
+
type DateRange = [Date, Date | undefined];
|
|
17
|
+
export interface DateRangePickerProps {
|
|
18
|
+
label: string;
|
|
19
|
+
defaultValue: DateRange;
|
|
20
|
+
format: string;
|
|
21
|
+
fullWidth?: boolean;
|
|
22
|
+
size?: "small" | "medium";
|
|
23
|
+
onValueChange: (value: DateRange, index: number) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const DateRangePicker = ({
|
|
27
|
+
defaultValue,
|
|
28
|
+
format: fmt,
|
|
29
|
+
label,
|
|
30
|
+
fullWidth,
|
|
31
|
+
onValueChange,
|
|
32
|
+
size = "medium",
|
|
33
|
+
}: DateRangePickerProps) => {
|
|
34
|
+
const [isPopoverOpened, setIsPopoverOpened] = useState(false);
|
|
35
|
+
const [value, setValue] = useState(defaultValue);
|
|
36
|
+
|
|
37
|
+
const handleValueChange = (newValue: DateRange, index: number) => {
|
|
38
|
+
setValue(newValue);
|
|
39
|
+
onValueChange(newValue, index);
|
|
40
|
+
setIsPopoverOpened(index < 1);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<TextField
|
|
46
|
+
label={label}
|
|
47
|
+
fullWidth={fullWidth}
|
|
48
|
+
size={size}
|
|
49
|
+
value={`${format(value[0], fmt)} - ${value[1] ? format(value[1], fmt) : fmt.toUpperCase()}`}
|
|
50
|
+
InputProps={{
|
|
51
|
+
endAdornment: (
|
|
52
|
+
<InputAdornment position="end">
|
|
53
|
+
<IconButton onClick={() => setIsPopoverOpened((o) => !o)} aria-label="open calendar">
|
|
54
|
+
<EventIcon />
|
|
55
|
+
</IconButton>
|
|
56
|
+
</InputAdornment>
|
|
57
|
+
),
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
<Paper>
|
|
61
|
+
<Collapse in={isPopoverOpened} aria-label="calendar collapse">
|
|
62
|
+
<DateRangeCalendar defaultValue={defaultValue} onValueChange={handleValueChange} />
|
|
63
|
+
</Collapse>
|
|
64
|
+
</Paper>
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./date-range-picker";
|
|
@@ -11,4 +11,6 @@ import LinkTo from '@storybook/addon-links/react';
|
|
|
11
11
|
<li><LinkTo kind="Components/Inputs/Autocomplete">Autocomplete</LinkTo></li>
|
|
12
12
|
<li><LinkTo kind="Components/Inputs/TextField">TextField</LinkTo></li>
|
|
13
13
|
<li><LinkTo kind="Components/Inputs/SearchInput">SearchInput</LinkTo></li>
|
|
14
|
+
<li><LinkTo kind="Components/Inputs/DateRangePicker">DateRangePicker</LinkTo></li>
|
|
15
|
+
<li><LinkTo kind="Components/Inputs/DateRangePicker">DateRangeCalendar</LinkTo></li>
|
|
14
16
|
</ul>
|
|
@@ -12,7 +12,7 @@ const baseArgs = {
|
|
|
12
12
|
fetching: false,
|
|
13
13
|
loading: false,
|
|
14
14
|
fullWidth: true,
|
|
15
|
-
options: faker.definitions.vehicle
|
|
15
|
+
options: [...faker.definitions.vehicle.model],
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
interface TemplateProps<T extends ReactNode> extends SelectProps<T> {
|
|
@@ -16,7 +16,7 @@ export default {
|
|
|
16
16
|
} satisfies Meta<typeof TextField>;
|
|
17
17
|
type Story = StoryObj<typeof TextField>;
|
|
18
18
|
|
|
19
|
-
const options
|
|
19
|
+
const options = faker.definitions.vehicle?.model || [];
|
|
20
20
|
|
|
21
21
|
export const Default: Story = {
|
|
22
22
|
args: {
|
|
@@ -6,7 +6,7 @@ import userEvent from "@testing-library/user-event";
|
|
|
6
6
|
import { expectProgressIndicator } from "~/tests/assertions";
|
|
7
7
|
import { vi } from "vitest";
|
|
8
8
|
|
|
9
|
-
const options
|
|
9
|
+
const options = faker.definitions.vehicle?.model || [];
|
|
10
10
|
|
|
11
11
|
describe("TextField", () => {
|
|
12
12
|
const renderComponent = ({
|
|
@@ -17,6 +17,7 @@ export const mockModel: Model = {
|
|
|
17
17
|
sm: 6,
|
|
18
18
|
md: 4,
|
|
19
19
|
listable: false,
|
|
20
|
+
updatable: false,
|
|
20
21
|
},
|
|
21
22
|
{
|
|
22
23
|
id: "firstName",
|
|
@@ -37,6 +38,7 @@ export const mockModel: Model = {
|
|
|
37
38
|
sm: 6,
|
|
38
39
|
md: 4,
|
|
39
40
|
listable: true,
|
|
41
|
+
required: false,
|
|
40
42
|
},
|
|
41
43
|
{
|
|
42
44
|
id: "lastName",
|
|
@@ -48,16 +50,6 @@ export const mockModel: Model = {
|
|
|
48
50
|
md: 4,
|
|
49
51
|
listable: true,
|
|
50
52
|
},
|
|
51
|
-
{
|
|
52
|
-
id: "gender",
|
|
53
|
-
type: "enum",
|
|
54
|
-
value: faker.definitions.name?.gender || [],
|
|
55
|
-
description: "User gender",
|
|
56
|
-
name: "Gender",
|
|
57
|
-
xs: 12,
|
|
58
|
-
sm: 6,
|
|
59
|
-
md: 3,
|
|
60
|
-
},
|
|
61
53
|
{
|
|
62
54
|
id: "age",
|
|
63
55
|
type: "number",
|
|
@@ -67,6 +59,7 @@ export const mockModel: Model = {
|
|
|
67
59
|
sm: 6,
|
|
68
60
|
md: 3,
|
|
69
61
|
listable: false,
|
|
62
|
+
required: false,
|
|
70
63
|
},
|
|
71
64
|
{
|
|
72
65
|
id: "birthDate",
|
|
@@ -90,7 +83,7 @@ export const mockModel: Model = {
|
|
|
90
83
|
{
|
|
91
84
|
id: "model",
|
|
92
85
|
type: "enum",
|
|
93
|
-
value: faker.definitions.vehicle
|
|
86
|
+
value: [...faker.definitions.vehicle.model],
|
|
94
87
|
description: "Lorem ipsum",
|
|
95
88
|
name: "Model",
|
|
96
89
|
xs: 12,
|
|
@@ -99,7 +92,7 @@ export const mockModel: Model = {
|
|
|
99
92
|
{
|
|
100
93
|
id: "manufacturer",
|
|
101
94
|
type: "enum",
|
|
102
|
-
value: faker.definitions.vehicle
|
|
95
|
+
value: [...faker.definitions.vehicle.manufacturer],
|
|
103
96
|
description: "Lorem ipsum",
|
|
104
97
|
name: "Manufacturer",
|
|
105
98
|
xs: 12,
|
|
@@ -116,7 +109,7 @@ export const mockModel: Model = {
|
|
|
116
109
|
{
|
|
117
110
|
id: "type",
|
|
118
111
|
type: "multienum",
|
|
119
|
-
value: faker.definitions.vehicle
|
|
112
|
+
value: [...faker.definitions.vehicle.type],
|
|
120
113
|
description: "Lorem ipsum",
|
|
121
114
|
name: "Type",
|
|
122
115
|
xs: 12,
|
|
@@ -209,7 +202,6 @@ export interface MockInstance {
|
|
|
209
202
|
firstName: string;
|
|
210
203
|
middleName: string;
|
|
211
204
|
lastName: string;
|
|
212
|
-
gender: string;
|
|
213
205
|
age: number;
|
|
214
206
|
birthDate: Date;
|
|
215
207
|
car: {
|
|
@@ -235,7 +227,6 @@ const mockFieldValue: Record<string, () => FieldType> = {
|
|
|
235
227
|
firstName: faker.name.firstName,
|
|
236
228
|
middleName: faker.name.middleName,
|
|
237
229
|
lastName: faker.name.lastName,
|
|
238
|
-
gender: faker.name.gender,
|
|
239
230
|
age: () => faker.datatype.number({ min: 20, max: 60 }),
|
|
240
231
|
birthDate: () => new Date(2019, 3, 2),
|
|
241
232
|
returnTime: () => new Date(2022, 10, 2, 11, 0),
|
|
@@ -21,7 +21,6 @@ describe("utilities", () => {
|
|
|
21
21
|
},
|
|
22
22
|
currency: "",
|
|
23
23
|
firstName: "",
|
|
24
|
-
gender: "",
|
|
25
24
|
id: "",
|
|
26
25
|
lastName: "",
|
|
27
26
|
middleName: "",
|
|
@@ -49,7 +48,6 @@ describe("utilities", () => {
|
|
|
49
48
|
type: ["sub", "sport"],
|
|
50
49
|
},
|
|
51
50
|
available: true,
|
|
52
|
-
gender: "female",
|
|
53
51
|
identifiers: ["1", "2"],
|
|
54
52
|
});
|
|
55
53
|
|
|
@@ -68,7 +66,6 @@ describe("utilities", () => {
|
|
|
68
66
|
},
|
|
69
67
|
currency: "EUR",
|
|
70
68
|
firstName: "",
|
|
71
|
-
gender: "female",
|
|
72
69
|
id: "1",
|
|
73
70
|
lastName: "",
|
|
74
71
|
middleName: "",
|