trithuc-mvc-react 1.5.2 → 1.5.4

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.
@@ -31,7 +31,7 @@ function EditorDialog({ open, onClose = () => {}, defaultValues = {}, fields = [
31
31
  };
32
32
  const submitRef = useRef();
33
33
  return (
34
- <Dialog open={open} onClose={onClose} maxWidth="lg" fullWidth={true} scroll={'body'}>
34
+ <Dialog open={open} onClose={onClose} maxWidth="md" fullWidth={true} scroll={'body'}>
35
35
  <DialogTitle>
36
36
  {defaultValues?.Id ? "Cập nhật" : "Thêm mới"}
37
37
  <IconButton
@@ -48,7 +48,7 @@ function EditorDialog({ open, onClose = () => {}, defaultValues = {}, fields = [
48
48
  </IconButton>
49
49
  </DialogTitle>
50
50
  <DialogContent dividers={true}>
51
- <EditorForm fields={fields} submitRef={submitRef} />
51
+ <EditorForm fields={fields} submitRef={submitRef} />
52
52
  </DialogContent>
53
53
  <DialogActions>
54
54
  <Button onClick={onClose}>Đóng</Button>
@@ -1,4 +1,4 @@
1
- import { Box } from "@mui/material";
1
+ import { Box, useTheme, useMediaQuery } from "@mui/material";
2
2
  import { FormProvider, useForm } from "react-hook-form";
3
3
  import Grid from "@mui/material/Unstable_Grid2"; // Grid version 2
4
4
  import PropTypes from "prop-types";
@@ -15,12 +15,14 @@ import { yupResolver } from "@hookform/resolvers/yup";
15
15
  EditorForm.propTypes = {
16
16
  fields: PropTypes.array
17
17
  };
18
- function EditorForm({ fields, elementSize = "medium", submitRef }) {
18
+ function EditorForm({ fields, submitRef }) {
19
19
  const queryClient = useQueryClient();
20
20
  const { tableName, selectedEditItem, setOpenEditorDialog, validationSchema } = useDataTable();
21
21
 
22
22
  const methods = useForm({ defaultValues: {}, resolver: yupResolver(validationSchema) });
23
-
23
+ const theme = useTheme();
24
+ const downXl = useMediaQuery(theme.breakpoints.down("xl"));
25
+ const elementSize = downXl ? "small": "medium";
24
26
  useEffect(() => {
25
27
  if (selectedEditItem) {
26
28
  methods.setValue("Id", selectedEditItem.Id);
@@ -90,12 +92,13 @@ function EditorForm({ fields, elementSize = "medium", submitRef }) {
90
92
  };
91
93
  return (
92
94
  <FormProvider {...methods}>
93
- <Box component={"form"} sx={{ pt: 2 }} onSubmit={methods.handleSubmit(onSubmit)}>
95
+ <Box component={"form"} onSubmit={methods.handleSubmit(onSubmit)}>
94
96
  <Grid container spacing={2}>
95
97
  {fields.map(
96
98
  ({
97
99
  field,
98
100
  type = "text",
101
+ size,
99
102
  label,
100
103
  childrenFields,
101
104
  datas,
@@ -106,20 +109,8 @@ function EditorForm({ fields, elementSize = "medium", submitRef }) {
106
109
  keyValueLabel,
107
110
  required
108
111
  }) => {
109
- let sizes = {
110
- xs: 12,
111
- sm: 6,
112
- md: 4
113
- };
114
- if (type == "textarea") {
115
- sizes = {
116
- xs: 12,
117
- sm: 12,
118
- md: 12
119
- };
120
- }
121
112
  return (
122
- <Grid {...sizes} key={field}>
113
+ <Grid item md={size?.md} xs={size?.xs} sm={size?.sm} key={field}>
123
114
  <FormField
124
115
  type={type}
125
116
  label={label}
@@ -17,15 +17,15 @@ export const FilterGod = ({ filters, elementSize = "small" }) => {
17
17
  onSubmit={handleSubmit(onSubmit)}
18
18
  sx={{
19
19
  px: 1,
20
- my: elementSize == "small" ? 0 : 2,
20
+ my: elementSize == "small" ? 1 : 2,
21
21
  display: "flex",
22
22
  alignItems: "center"
23
23
  }}
24
24
  >
25
25
  <Grid
26
26
  container
27
- rowSpacing={2}
28
- columnSpacing={{ xs: 2 }}
27
+ spacing={{xs:1, xl:2}}
28
+
29
29
  sx={{
30
30
  px: 1,
31
31
  flex: 1
@@ -220,7 +220,8 @@ function FormField({
220
220
  textField: {
221
221
  fullWidth: true,
222
222
  error: Boolean(error),
223
- helperText: error?.message
223
+ helperText: error?.message,
224
+ size: size
224
225
  },
225
226
  popper: {
226
227
  disablePortal: false,
@@ -1,30 +1,29 @@
1
- import { Checkbox, TableRow, TableCell, TableHead as MuiTableHead } from "@mui/material";
1
+ import { Checkbox, TableRow, TableCell, TableHead as MuiTableHead, useTheme, useMediaQuery } from "@mui/material";
2
2
  import { useDataTable, usePermission } from "./hooks";
3
3
  export function TableHead({ numSelected, rowCount, onSelectAllClick, headLabel }) {
4
4
  const { canEdit } = usePermission();
5
5
  const { disableStatus } = useDataTable();
6
+ const theme = useTheme();
7
+ const downXl = useMediaQuery(theme.breakpoints.down("xl"));
6
8
  return (
7
9
  <MuiTableHead sx={{ height: 56, visibility: numSelected > 0 ? "hidden" : "visible" }}>
8
10
  <TableRow>
9
11
  <TableCell padding="checkbox">
10
12
  <Checkbox
11
13
  indeterminate={numSelected > 0 && numSelected < rowCount}
14
+ size={downXl?"small":"medium"}
12
15
  checked={rowCount > 0 && numSelected === rowCount}
13
16
  onChange={onSelectAllClick}
14
17
  />
15
18
  </TableCell>
16
19
  <TableCell sx={{ textAlign: "center" }}>STT</TableCell>
17
20
  {headLabel.map((headCell) => (
18
- <TableCell
19
- key={headCell.field}
20
- align={headCell.alignRight ? "right" : "left"}
21
- sx={{ textAlign: "center" }}
22
- >
21
+ <TableCell key={headCell.field} align={headCell.alignRight ? "right" : "left"} sx={{ textAlign: "center" }}>
23
22
  {headCell.label}
24
23
  </TableCell>
25
24
  ))}
26
- {!disableStatus && canEdit && <TableCell sx={{ textAlign: "center"} }>Kích hoạt</TableCell>}
27
- <TableCell sx={{ minWidth: "136px", textAlign: "center" }} >Thao tác</TableCell>
25
+ {!disableStatus && canEdit && <TableCell sx={{ textAlign: "center" }}>Kích hoạt</TableCell>}
26
+ <TableCell sx={{ minWidth: "136px", textAlign: "center" }}>Thao tác</TableCell>
28
27
  </TableRow>
29
28
  </MuiTableHead>
30
29
  );
@@ -1,10 +1,10 @@
1
- import { Checkbox, IconButton, Switch, TableCell, TableRow, Tooltip, Toolbar } from "@mui/material";
1
+ import { Checkbox, IconButton, Switch, TableCell, TableRow, Tooltip, Toolbar, useMediaQuery } from "@mui/material";
2
2
  import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
3
3
  import { EditOutlined } from "@mui/icons-material";
4
4
  import { useDataTable, usePermission } from "./hooks";
5
5
 
6
6
  // material
7
- import { styled } from "@mui/material/styles";
7
+ import { styled, useTheme } from "@mui/material/styles";
8
8
  import MoreMenu from "../MoreMenu";
9
9
  import { useMemo } from "react";
10
10
 
@@ -26,24 +26,29 @@ export const TableRowRender = ({ index, row, selected, onSelect, onChangeStatus,
26
26
  const tableActionsOnMoreMenu = tableActionsAfterFilter.filter(({ isOnTable = false }) => !isOnTable);
27
27
  return { tableActionsOnTable, tableActionsOnMoreMenu };
28
28
  }, [canView, canAction, tableActions]);
29
-
29
+ const theme = useTheme();
30
+ const downXl = useMediaQuery(theme.breakpoints.down("xl"));
30
31
  return (
31
32
  <TableRow hover key={row[selectedField]} selected={selected}>
32
33
  <TableCell padding="checkbox">
33
- <Checkbox checked={selected} onChange={(event) => onSelect(event, row[selectedField])} />
34
+ <Checkbox
35
+ checked={selected}
36
+ size={downXl ? "small" : "medium"}
37
+ onChange={(event) => onSelect(event, row[selectedField])}
38
+ />
34
39
  </TableCell>
35
40
  <TableCell align="center">{index + 1}</TableCell>
36
41
  {columns.map(
37
42
  ({
38
43
  field,
39
- type="text",
44
+ type = "text",
40
45
  valueGetter = (row) => {
41
46
  return row[field];
42
47
  },
43
48
  renderCell,
44
49
  valueFormat = (e) => e
45
50
  }) => {
46
- let align = ( type=="image" || type == "number" || type =="date"|| type == "datetime") ? "right" : "left";
51
+ let align = type == "image" || type == "number" || type == "date" || type == "datetime" ? "right" : "left";
47
52
  return (
48
53
  <TableCell key={`${row[selectedField]}-${field}`} align={align}>
49
54
  {renderCell ? renderCell(row) : valueFormat(valueGetter(row))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"