ish-ui 1.0.30 → 1.0.32

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.
@@ -25,6 +25,7 @@ import InputAdornment from '@mui/material/InputAdornment';
25
25
  import EditInPlaceField from './EditInPlaceField';
26
26
  import { stubFunction } from '../utils';
27
27
  function EditInPlaceFileField(_a) {
28
+ var _b;
28
29
  var { input } = _a, restProps = __rest(_a, ["input"]);
29
30
  const inputRef = useRef();
30
31
  const fileRef = useRef();
@@ -48,7 +49,7 @@ function EditInPlaceFileField(_a) {
48
49
  onFocus: stubFunction,
49
50
  onBlur: stubFunction
50
51
  }, InputProps: {
51
- startAdornment: React.createElement(InputAdornment, { position: "start" },
52
+ startAdornment: React.createElement(InputAdornment, { position: "start", className: (_b = restProps.fieldClasses) === null || _b === void 0 ? void 0 : _b.text },
52
53
  React.createElement(AttachmentIcon, null)),
53
54
  onFocus,
54
55
  inputProps: {
@@ -5,5 +5,5 @@ interface Props<InputProps, MetaProps> extends EditInPlaceFieldProps<InputProps,
5
5
  currencySymbol: string;
6
6
  dispatch?: Dispatch;
7
7
  }
8
- declare function EditInPlaceMoneyField<IP, MP>({ InputProps, currencySymbol, dispatch, className, ...restProps }: Props<IP, MP>): React.JSX.Element;
8
+ declare function EditInPlaceMoneyField<IP, MP>({ InputProps, currencySymbol, className, ...restProps }: Props<IP, MP>): React.JSX.Element;
9
9
  export default EditInPlaceMoneyField;
@@ -31,7 +31,8 @@ const NumberFormatCustom = React.forwardRef((props, ref) => {
31
31
  });
32
32
  const preformatDisplayValue = value => value || value === 0 ? formatCurrency(value, '') : value;
33
33
  function EditInPlaceMoneyField(_a) {
34
- var { InputProps, currencySymbol, dispatch, className } = _a, restProps = __rest(_a, ["InputProps", "currencySymbol", "dispatch", "className"]);
35
- return (React.createElement(EditInPlaceField, Object.assign({}, restProps, { preformatDisplayValue: preformatDisplayValue, InputProps: Object.assign(Object.assign({}, InputProps), { startAdornment: React.createElement(InputAdornment, { position: "start" }, currencySymbol), inputComponent: NumberFormatCustom }), className: clsx('money', className) })));
34
+ var _b;
35
+ var { InputProps, currencySymbol, className } = _a, restProps = __rest(_a, ["InputProps", "currencySymbol", "className"]);
36
+ return (React.createElement(EditInPlaceField, Object.assign({}, restProps, { preformatDisplayValue: preformatDisplayValue, InputProps: Object.assign(Object.assign({}, InputProps), { startAdornment: React.createElement(InputAdornment, { position: "start", className: (_b = restProps.fieldClasses) === null || _b === void 0 ? void 0 : _b.text }, currencySymbol), inputComponent: NumberFormatCustom }), className: clsx('money', className) })));
36
37
  }
37
38
  export default EditInPlaceMoneyField;
@@ -62,8 +62,9 @@ const NumberFormatCustom = React.forwardRef((props, ref) => {
62
62
  return (React.createElement(NumberFormat, Object.assign({}, other, { getInputRef: getInputRef, onKeyPress: onKeyPress, prefix: prefix, onValueChange: onValueChange, format: format, type: "text" })));
63
63
  });
64
64
  function EditInPlacePhoneField(_a) {
65
+ var _b;
65
66
  var { InputProps, className } = _a, restProps = __rest(_a, ["InputProps", "className"]);
66
- return (React.createElement(EditInPlaceField, Object.assign({}, restProps, { InputProps: Object.assign(Object.assign({}, InputProps), { startAdornment: React.createElement(InputAdornment, { position: "start" },
67
+ return (React.createElement(EditInPlaceField, Object.assign({}, restProps, { InputProps: Object.assign(Object.assign({}, InputProps), { startAdornment: React.createElement(InputAdornment, { position: "start", className: (_b = restProps.fieldClasses) === null || _b === void 0 ? void 0 : _b.text },
67
68
  React.createElement(PhoneIcon, null)), inputComponent: NumberFormatCustom }), className: className })));
68
69
  }
69
70
  export default EditInPlacePhoneField;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { DateArgFunction } from '../../model';
2
3
  interface Props {
3
4
  day: number;
4
5
  isToday?: boolean;
@@ -8,8 +9,15 @@ interface Props {
8
9
  selectedMonthSessionDays: number[];
9
10
  disabled: boolean;
10
11
  theme?: any;
11
- targetDay?: any;
12
- setTargetDay?: any;
12
+ targetDay?: Date;
13
+ setTargetDay?: DateArgFunction;
14
+ customClasses?: {
15
+ root?: string;
16
+ hasSession?: string;
17
+ today?: string;
18
+ selected?: string;
19
+ disabled?: string;
20
+ };
13
21
  }
14
22
  declare const CalendarDay: React.MemoExoticComponent<(props: Props) => React.JSX.Element>;
15
23
  export default CalendarDay;
@@ -5,13 +5,12 @@
5
5
  *
6
6
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
7
7
  */
8
- import React, { useMemo } from 'react';
8
+ import React, { useMemo, memo } from 'react';
9
9
  import { Button } from '@mui/material';
10
10
  import { isSameDay } from 'date-fns';
11
11
  import clsx from 'clsx';
12
12
  import { alpha } from '@mui/material/styles';
13
13
  import { makeAppStyles } from '../../styles';
14
- import { useAppTheme } from '../../themes';
15
14
  const useStyles = makeAppStyles(theme => ({
16
15
  root: {
17
16
  padding: 0,
@@ -39,26 +38,34 @@ const useStyles = makeAppStyles(theme => ({
39
38
  border: `2px solid ${theme.palette.text.primary}`
40
39
  }
41
40
  },
42
- same: {}
41
+ same: {},
42
+ hasSession: ({ dayIndexValue }) => {
43
+ const backgroundColor = alpha(theme.palette.primary.main, dayIndexValue);
44
+ return {
45
+ backgroundColor,
46
+ color: theme.palette.getContrastText(backgroundColor),
47
+ '&:hover': {
48
+ backgroundColor,
49
+ color: theme.palette.getContrastText(backgroundColor)
50
+ }
51
+ };
52
+ },
53
+ isToday: {
54
+ fontWeight: 900
55
+ }
43
56
  }));
44
- const CalendarDay = React.memo((props) => {
45
- const { day, status, date, disabled, targetDay, setTargetDay, selectedMonthSessionDays } = props;
46
- const classes = useStyles();
47
- const theme = useAppTheme();
57
+ const CalendarDay = memo((props) => {
58
+ const { customClasses = {}, day, status, date, disabled, targetDay, setTargetDay, selectedMonthSessionDays } = props;
48
59
  const isSame = isSameDay(targetDay, date);
49
60
  const isToday = isSameDay(new Date(), date);
50
- const style = useMemo(() => {
51
- let result;
52
- const dayIndexValue = selectedMonthSessionDays[day - 1];
53
- if (selectedMonthSessionDays.length && status === 'current' && dayIndexValue !== 0) {
54
- const backgroundColor = alpha(theme.palette.primary.main, dayIndexValue);
55
- result = Object.assign(Object.assign({}, result || {}), { backgroundColor, color: theme.palette.getContrastText(backgroundColor) });
56
- }
57
- if (isToday) {
58
- result = Object.assign(Object.assign({}, result || {}), { fontWeight: '900' });
59
- }
60
- return result;
61
- }, [isToday, status, selectedMonthSessionDays, day, theme]);
62
- return (React.createElement(Button, { className: clsx(classes.root, isSame && classes.same), onClick: () => setTargetDay(date), disabled: disabled, style: style }, day));
61
+ const dayIndexValue = selectedMonthSessionDays[day - 1];
62
+ const hasSession = useMemo(() => selectedMonthSessionDays.length && status === 'current' && dayIndexValue !== 0, [selectedMonthSessionDays, dayIndexValue, status]);
63
+ const classes = useStyles({ dayIndexValue, hasSession, isToday });
64
+ return (React.createElement(Button, { className: clsx(classes.root, customClasses.root, isSame && clsx(classes.same, customClasses.selected), {
65
+ [customClasses.hasSession || classes.hasSession]: hasSession,
66
+ [customClasses.today || classes.isToday]: isToday
67
+ }), onClick: () => setTargetDay(date), classes: {
68
+ disabled: customClasses.disabled
69
+ }, disabled: disabled }, day));
63
70
  });
64
71
  export default CalendarDay;
@@ -1,10 +1,16 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
  interface Props {
3
3
  month: string;
4
4
  year: number;
5
5
  previousMonth: () => void;
6
6
  nextMonth: () => void;
7
7
  classes?: any;
8
+ customClasses?: {
9
+ root?: string;
10
+ leftButton?: string;
11
+ rightbutton?: string;
12
+ selectedMonth?: string;
13
+ };
8
14
  }
9
- declare const _default: React.JSXElementConstructor<Omit<Props, "classes"> & import("@mui/styles").StyledComponentProps<never>>;
10
- export default _default;
15
+ declare const CalendarHeader: ({ month, year, previousMonth, nextMonth, customClasses }: Props) => React.JSX.Element;
16
+ export default CalendarHeader;
@@ -1,22 +1,26 @@
1
- import React from "react";
2
- import { IconButton, Typography } from "@mui/material";
3
- import { createStyles, withStyles } from "@mui/styles";
4
- import { KeyboardArrowLeft, KeyboardArrowRight } from "@mui/icons-material";
5
- const styles = createStyles(theme => ({
1
+ import React from 'react';
2
+ import { IconButton, Typography } from '@mui/material';
3
+ import { KeyboardArrowLeft, KeyboardArrowRight } from '@mui/icons-material';
4
+ import clsx from 'clsx';
5
+ import { makeAppStyles } from '../../styles';
6
+ const useStyles = makeAppStyles(theme => ({
6
7
  root: {
7
- display: "flex",
8
- justifyContent: "space-between",
9
- alignItems: "center",
8
+ display: 'flex',
9
+ justifyContent: 'space-between',
10
+ alignItems: 'center',
10
11
  padding: theme.spacing(0, 1)
11
12
  }
12
13
  }));
13
- const CalendarHeader = ({ classes, month, year, previousMonth, nextMonth }) => (React.createElement("div", { className: classes.root },
14
- React.createElement(IconButton, { onClick: previousMonth },
15
- React.createElement(KeyboardArrowLeft, null)),
16
- React.createElement(Typography, { align: "center" },
17
- month,
18
- " ",
19
- year),
20
- React.createElement(IconButton, { onClick: nextMonth },
21
- React.createElement(KeyboardArrowRight, null))));
22
- export default withStyles(styles)(CalendarHeader);
14
+ const CalendarHeader = ({ month, year, previousMonth, nextMonth, customClasses = {} }) => {
15
+ const classes = useStyles();
16
+ return React.createElement("div", { className: clsx(classes.root, customClasses.root) },
17
+ React.createElement(IconButton, { onClick: previousMonth, className: customClasses.leftButton },
18
+ React.createElement(KeyboardArrowLeft, null)),
19
+ React.createElement(Typography, { align: "center", className: customClasses.selectedMonth },
20
+ month,
21
+ " ",
22
+ year),
23
+ React.createElement(IconButton, { onClick: nextMonth, className: customClasses.rightbutton },
24
+ React.createElement(KeyboardArrowRight, null)));
25
+ };
26
+ export default CalendarHeader;
@@ -1,8 +1,9 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
  interface Props {
3
- classes?: any;
4
- switchWeekDays: (dayId: number) => void;
5
- selectedWeekDays: boolean[];
3
+ switchWeekDays?: (dayId: number) => void;
4
+ selectedWeekDays?: boolean[];
5
+ className?: string;
6
+ dayClass?: string;
6
7
  }
7
- declare const _default: React.JSXElementConstructor<Omit<Props, "classes"> & import("@mui/styles").StyledComponentProps<"root">>;
8
- export default _default;
8
+ declare const CalendarWeekPanel: ({ className, dayClass, switchWeekDays, selectedWeekDays }: Props) => React.JSX.Element;
9
+ export default CalendarWeekPanel;
@@ -1,18 +1,20 @@
1
- import React from "react";
2
- import { createStyles, withStyles } from "@mui/styles";
3
- import WeekDay from "./WeekDay";
4
- const styles = theme => createStyles({
1
+ import React from 'react';
2
+ import WeekDay from './WeekDay';
3
+ import clsx from 'clsx';
4
+ import { makeAppStyles } from '../../styles';
5
+ const useStyles = makeAppStyles(theme => ({
5
6
  root: {
6
- display: "grid",
7
+ display: 'grid',
7
8
  gridTemplateColumns: `repeat(7, ${theme.spacing(4)})`,
8
- gridColumnGap: 1,
9
+ gap: 1,
9
10
  padding: theme.spacing(0, 1),
10
11
  marginBottom: theme.spacing(1),
11
- justifyContent: "center"
12
+ justifyContent: 'center'
12
13
  }
13
- });
14
- const week = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
15
- const CalendarWeekPanel = ({ classes, switchWeekDays, selectedWeekDays }) => {
16
- return (React.createElement("div", { className: classes.root }, week.map((el, id) => (React.createElement(WeekDay, { key: id, id: id, name: el, selected: selectedWeekDays[id], click: switchWeekDays })))));
14
+ }));
15
+ const week = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
16
+ const CalendarWeekPanel = ({ className, dayClass, switchWeekDays, selectedWeekDays = [] }) => {
17
+ const classes = useStyles();
18
+ return (React.createElement("div", { className: clsx(classes.root, className) }, week.map((el, id) => (React.createElement(WeekDay, { key: id, id: id, name: el, selected: selectedWeekDays[id], click: switchWeekDays, className: dayClass })))));
17
19
  };
18
- export default withStyles(styles)(CalendarWeekPanel);
20
+ export default CalendarWeekPanel;
@@ -1,10 +1,10 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
  interface Props {
3
- name: string;
4
- selected: boolean;
5
- click: (id: any) => void;
6
3
  id: number;
7
- classes?: any;
4
+ name: string;
5
+ selected?: boolean;
6
+ click?: (id: any) => void;
7
+ className?: string;
8
8
  }
9
- declare const _default: React.JSXElementConstructor<Omit<Props, "classes"> & import("@mui/styles").StyledComponentProps<"weekButton" | "selectedWeekDay" | "weekDayText">>;
10
- export default _default;
9
+ declare const WeekDay: ({ name, selected, click, id, className }: Props) => React.JSX.Element;
10
+ export default WeekDay;
@@ -1,25 +1,30 @@
1
- import React from "react";
2
- import { Button, Typography } from "@mui/material";
3
- import { createStyles, withStyles } from "@mui/styles";
4
- import clsx from "clsx";
5
- const styles = theme => createStyles({
1
+ import React from 'react';
2
+ import { Button, Typography } from '@mui/material';
3
+ import clsx from 'clsx';
4
+ import { makeAppStyles } from '../../styles';
5
+ const useStyles = makeAppStyles(theme => ({
6
6
  weekButton: {
7
7
  padding: theme.spacing(0.5),
8
- minWidth: "initial",
9
- textTransform: "capitalize"
8
+ minWidth: 'initial',
9
+ textTransform: 'capitalize'
10
10
  },
11
11
  selectedWeekDay: {
12
- boxShadow: "none",
13
- "&:active": {
14
- boxShadow: "none"
12
+ boxShadow: 'none',
13
+ '&:active': {
14
+ boxShadow: 'none'
15
15
  }
16
16
  },
17
17
  weekDayText: {
18
18
  color: theme.palette.common.white
19
19
  }
20
- });
21
- const WeekDay = ({ classes, name, selected, click, id }) => (React.createElement(Button, { className: clsx(classes.weekButton, {
22
- [classes.selectedWeekDay]: selected
23
- }), onClick: () => click(id), variant: selected ? "contained" : "text", color: selected ? "primary" : "inherit" },
24
- React.createElement(Typography, { variant: "caption", align: "center", className: selected ? classes.weekDayText : "" }, name)));
25
- export default withStyles(styles)(WeekDay);
20
+ }));
21
+ const DivRoot = props => React.createElement("div", { className: props.className });
22
+ const WeekDay = ({ name, selected, click, id, className }) => {
23
+ const classes = useStyles();
24
+ const Root = click ? Button : DivRoot;
25
+ return React.createElement(Root, { className: clsx(classes.weekButton, {
26
+ [classes.selectedWeekDay]: selected
27
+ }, className), onClick: () => click(id), variant: selected ? 'contained' : 'text', color: selected ? 'primary' : 'inherit', disableElevation: true },
28
+ React.createElement(Typography, { variant: "caption", align: "center", className: selected ? classes.weekDayText : '' }, name));
29
+ };
30
+ export default WeekDay;
@@ -1,4 +1,4 @@
1
- export declare const getCalendarDays: (today: any) => {
1
+ export declare const getCalendarDays: (date: Date) => {
2
2
  day: number;
3
3
  date: Date;
4
4
  status: any;
@@ -13,12 +13,12 @@ const generateOneMonth = (today, status) => Array(getDaysInMonth(today))
13
13
  date: new Date(today.getFullYear(), today.getMonth(), id + 1),
14
14
  status
15
15
  }));
16
- export const getCalendarDays = today => {
17
- const currentMonth = generateOneMonth(today, 'current');
18
- const previousMonth = generateOneMonth(new Date(today.getFullYear(), today.getMonth() - 1), 'previous');
19
- const nextMonth = generateOneMonth(new Date(today.getFullYear(), today.getMonth() + 1), 'next');
20
- const firstDayIndex = getDay(new Date(today.getFullYear(), today.getMonth(), 1));
21
- const lastDayIndex = getDay(lastDayOfMonth(today));
16
+ export const getCalendarDays = (date) => {
17
+ const currentMonth = generateOneMonth(date, 'current');
18
+ const previousMonth = generateOneMonth(new Date(date.getFullYear(), date.getMonth() - 1), 'previous');
19
+ const nextMonth = generateOneMonth(new Date(date.getFullYear(), date.getMonth() + 1), 'next');
20
+ const firstDayIndex = getDay(new Date(date.getFullYear(), date.getMonth(), 1));
21
+ const lastDayIndex = getDay(lastDayOfMonth(date));
22
22
  const binaryCalendarState = (firstDayIndex, lastDayIndex) => parseInt(String(+!!firstDayIndex) + +(lastDayIndex < 6), 2);
23
23
  switch (binaryCalendarState(firstDayIndex, lastDayIndex)) {
24
24
  case 0:
@@ -7,3 +7,4 @@ export * from './dates';
7
7
  export * from './fields';
8
8
  export * from './hooks';
9
9
  export * from './events';
10
+ export * from './validation';
@@ -14,3 +14,4 @@ export * from './dates';
14
14
  export * from './fields';
15
15
  export * from './hooks';
16
16
  export * from './events';
17
+ export * from './validation';
@@ -0,0 +1,2 @@
1
+ export declare const validateMinMaxDate: (value: string, minDate: string, maxDate: string, minErrMsg?: string, maxErrMsg?: string) => any;
2
+ export declare const validateDate: (value: any) => boolean;
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright ish group pty ltd 2023.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
5
+ *
6
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
7
+ */
8
+ export const validateMinMaxDate = (value, minDate, maxDate, minErrMsg = 'Date is beyond minimum limit', maxErrMsg = 'Date is beyond maximum limit') => {
9
+ let result;
10
+ if (value) {
11
+ const valueTime = new Date(value).getTime();
12
+ if (minDate) {
13
+ const minDateTime = new Date(minDate).getTime();
14
+ result = valueTime >= minDateTime ? undefined : minErrMsg;
15
+ }
16
+ if (maxDate) {
17
+ const maxDateTime = new Date(maxDate).getTime();
18
+ result = valueTime <= maxDateTime ? undefined : maxErrMsg;
19
+ }
20
+ }
21
+ return result;
22
+ };
23
+ export const validateDate = value => !Number.isNaN(new Date(value).getTime());
@@ -0,0 +1 @@
1
+ export * from './datesValidation';
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright ish group pty ltd 2023.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
5
+ *
6
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
7
+ */
8
+ export * from './datesValidation';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ish-ui",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "UI elements for onCourse and other ish apps",
5
5
  "main": "main.ts",
6
6
  "devDependencies": {