pcm-shared-components 2.0.40 → 2.0.42
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/README.md +3 -0
- package/dist/components/Buttons/DropdownButton/index.js +1 -1
- package/dist/components/Buttons/TillButton/index.js +1 -1
- package/dist/components/Cards/EventCard/components/OpenEventCardDialog.js +97 -0
- package/dist/components/Cards/EventCard/components/OpenEventViewAllImageDialog.js +54 -0
- package/dist/components/Cards/EventCard/index.js +101 -0
- package/dist/components/Date/{DateRangeCalendar → DatePickerReactStyled/DateCalendar}/css/style.css +5 -0
- package/dist/components/Date/DatePickerReactStyled/DateCalendar/index.js +174 -0
- package/dist/components/Date/DatePickerReactStyled/DateCalendar/storybook/index.docs.mdx +122 -0
- package/dist/components/Date/DatePickerReactStyled/DateCalendar/storybook/index.stories.js +74 -0
- package/dist/components/Date/DatePickerReactStyled/DateRangeCalendar/css/style.css +119 -0
- package/dist/components/Date/{DateRangeCalendar → DatePickerReactStyled/DateRangeCalendar}/index.js +4 -21
- package/dist/components/Date/DatePickerReactStyled/DateRangeCalendar/storybook/index.docs.mdx +122 -0
- package/dist/components/Date/DatePickerReactStyled/DateRangeCalendar/storybook/index.stories.js +74 -0
- package/dist/components/Date/DatePickerReactStyled/common/theme.js +49 -0
- package/dist/components/Date/FancyDate/index.js +28 -0
- package/dist/components/Date/PricingCalendar/css/style.css +210 -0
- package/dist/components/Date/PricingCalendar/index.js +124 -0
- package/dist/components/Dialogs/GenericAppBar/components/GenericAppBarSubMenu.js +0 -1
- package/dist/components/Drawing/ImageCanvasDraw/components/Controls.js +0 -1
- package/dist/components/Icons/ImageAssets/index.js +61 -0
- package/dist/components/Images/HorizontalImageTile/index.js +110 -0
- package/dist/components/Images/VerticalImageTile/index.js +55 -0
- package/dist/components/Layout/SimpleTab/index.js +1 -3
- package/dist/components/Menus/ReusablePopupMenu/index.js +1 -1
- package/dist/components/NEW_COMPONENT/index.js +8 -2
- package/dist/components/NEW_COMPONENT/storybook/index.stories.js +1 -1
- package/dist/components/Platform/PlatformPaymentPlans/index.js +1 -1
- package/dist/index.js +9 -2
- package/dist/languages/en/translations.json +375 -20
- package/dist/languages/es/translations.json +374 -19
- package/dist/languages/fr/translations.json +375 -20
- package/dist/locals/i18n.js +0 -1
- package/dist/styles/tailwind.css +1 -1
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -26,4 +26,7 @@ Manually deploying is faster then committing the code as it doesn't need to crea
|
|
|
26
26
|
# Update the library in other projects by running the following
|
|
27
27
|
> npm install pcm-shared-components@latest
|
|
28
28
|
|
|
29
|
+
# Or run the following to do it all in one go!
|
|
30
|
+
sh ./publish.sh
|
|
31
|
+
|
|
29
32
|
```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
2
|
import React, { memo } from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
2
|
import React, { memo } from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Dialog, DialogContent } from '@mui/material';
|
|
3
|
+
import HorizontalImageTile from "../../../Images/HorizontalImageTile";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import moment from "moment";
|
|
6
|
+
import OpenEventViewAllImageDialog from "./OpenEventViewAllImageDialog";
|
|
7
|
+
import { IconButton } from '@mui/material';
|
|
8
|
+
import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew';
|
|
9
|
+
const OpenEventCardDialog = props => {
|
|
10
|
+
const {
|
|
11
|
+
id,
|
|
12
|
+
campground_event_pages_id,
|
|
13
|
+
state_id,
|
|
14
|
+
display_on_booking_page,
|
|
15
|
+
title,
|
|
16
|
+
description,
|
|
17
|
+
event_date,
|
|
18
|
+
pictures,
|
|
19
|
+
open,
|
|
20
|
+
closeDialog,
|
|
21
|
+
view_all_images_str
|
|
22
|
+
} = props;
|
|
23
|
+
const [openEventViewAllImageDialog, setOpenEventViewAllImageDialog] = useState(false);
|
|
24
|
+
const handleOnClose = () => {
|
|
25
|
+
setOpenEventViewAllImageDialog(false);
|
|
26
|
+
};
|
|
27
|
+
const handleOnImageClick = () => {
|
|
28
|
+
setOpenEventViewAllImageDialog(true);
|
|
29
|
+
};
|
|
30
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dialog, {
|
|
31
|
+
classes: {
|
|
32
|
+
paper: "m-24"
|
|
33
|
+
},
|
|
34
|
+
open: open,
|
|
35
|
+
onClose: closeDialog,
|
|
36
|
+
fullWidth: true,
|
|
37
|
+
maxWidth: "md"
|
|
38
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
39
|
+
className: "flex justify-start w-full p-10 "
|
|
40
|
+
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
41
|
+
className: "shadow-2",
|
|
42
|
+
onClick: closeDialog,
|
|
43
|
+
size: "small"
|
|
44
|
+
}, /*#__PURE__*/React.createElement(ArrowBackIosNewIcon, null))), /*#__PURE__*/React.createElement(DialogContent, null, /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
className: "flex flex-col"
|
|
46
|
+
}, /*#__PURE__*/React.createElement(HorizontalImageTile, {
|
|
47
|
+
pictures: pictures,
|
|
48
|
+
event_date: event_date,
|
|
49
|
+
onImageClick: handleOnImageClick,
|
|
50
|
+
view_all_images_str: view_all_images_str
|
|
51
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
52
|
+
className: "flex flex-col m-6"
|
|
53
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
54
|
+
className: "w-full flex flex-row justify-between"
|
|
55
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
56
|
+
className: "font-800 capitalize text-24 mt-12"
|
|
57
|
+
}, title), /*#__PURE__*/React.createElement("div", {
|
|
58
|
+
className: "font-500 text-24 mt-12 text-grey-800"
|
|
59
|
+
}, moment(event_date).format('dddd MMMM Do'))), /*#__PURE__*/React.createElement("div", {
|
|
60
|
+
className: "ml-0 md:ml-12 my-12",
|
|
61
|
+
dangerouslySetInnerHTML: {
|
|
62
|
+
__html: description
|
|
63
|
+
}
|
|
64
|
+
}))))), /*#__PURE__*/React.createElement(OpenEventViewAllImageDialog, {
|
|
65
|
+
open: openEventViewAllImageDialog,
|
|
66
|
+
closeDialog: handleOnClose,
|
|
67
|
+
pictures: pictures
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
OpenEventCardDialog.defaultProps = {
|
|
71
|
+
id: -1,
|
|
72
|
+
campground_event_pages_id: -1,
|
|
73
|
+
state_id: 1,
|
|
74
|
+
display_on_booking_page: false,
|
|
75
|
+
title: "",
|
|
76
|
+
description: "",
|
|
77
|
+
event_date: moment().format('YYYY-MM-DD'),
|
|
78
|
+
pictures: [],
|
|
79
|
+
open: false,
|
|
80
|
+
closeDialog: () => {},
|
|
81
|
+
view_all_images_str: "View All Images"
|
|
82
|
+
};
|
|
83
|
+
OpenEventCardDialog.propTypes = {
|
|
84
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
85
|
+
campground_event_pages_id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
86
|
+
state_id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
87
|
+
display_on_booking_page: PropTypes.bool.isRequired,
|
|
88
|
+
title: PropTypes.string.isRequired,
|
|
89
|
+
description: PropTypes.string.isRequired,
|
|
90
|
+
event_date: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string]).isRequired,
|
|
91
|
+
pictures: PropTypes.array.isRequired,
|
|
92
|
+
type: PropTypes.string,
|
|
93
|
+
open: PropTypes.bool,
|
|
94
|
+
closeDialog: PropTypes.func,
|
|
95
|
+
view_all_images_str: PropTypes.string
|
|
96
|
+
};
|
|
97
|
+
export default OpenEventCardDialog;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Dialog, DialogContent } from '@mui/material';
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import VerticalImageTile from "../../../Images/VerticalImageTile";
|
|
6
|
+
import Slide from '@mui/material/Slide';
|
|
7
|
+
import { IconButton } from '@mui/material';
|
|
8
|
+
import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew';
|
|
9
|
+
const Transition = /*#__PURE__*/React.forwardRef(function Transition(props, ref) {
|
|
10
|
+
return /*#__PURE__*/React.createElement(Slide, _extends({
|
|
11
|
+
direction: "up",
|
|
12
|
+
ref: ref
|
|
13
|
+
}, props));
|
|
14
|
+
});
|
|
15
|
+
const OpenEventViewAllImageDialog = props => {
|
|
16
|
+
const {
|
|
17
|
+
pictures,
|
|
18
|
+
open,
|
|
19
|
+
closeDialog
|
|
20
|
+
} = props;
|
|
21
|
+
return /*#__PURE__*/React.createElement(Dialog, {
|
|
22
|
+
open: open,
|
|
23
|
+
onClose: closeDialog,
|
|
24
|
+
fullScreen: true,
|
|
25
|
+
TransitionComponent: Transition
|
|
26
|
+
}, /*#__PURE__*/React.createElement(DialogContent, {
|
|
27
|
+
classes: {
|
|
28
|
+
root: "p-24"
|
|
29
|
+
}
|
|
30
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
31
|
+
className: "flex justify-start w-full m-10"
|
|
32
|
+
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
33
|
+
className: "shadow-2 ",
|
|
34
|
+
onClick: closeDialog,
|
|
35
|
+
size: "small"
|
|
36
|
+
}, /*#__PURE__*/React.createElement(ArrowBackIosNewIcon, {
|
|
37
|
+
className: "material-icons text-32"
|
|
38
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
39
|
+
className: "mt-12 w-3/4 mx-auto"
|
|
40
|
+
}, /*#__PURE__*/React.createElement(VerticalImageTile, {
|
|
41
|
+
pictures: pictures
|
|
42
|
+
}))));
|
|
43
|
+
};
|
|
44
|
+
OpenEventViewAllImageDialog.defaultProps = {
|
|
45
|
+
pictures: [],
|
|
46
|
+
open: false,
|
|
47
|
+
closeDialog: () => {}
|
|
48
|
+
};
|
|
49
|
+
OpenEventViewAllImageDialog.propTypes = {
|
|
50
|
+
pictures: PropTypes.array.isRequired,
|
|
51
|
+
open: PropTypes.bool,
|
|
52
|
+
closeDialog: PropTypes.func
|
|
53
|
+
};
|
|
54
|
+
export default OpenEventViewAllImageDialog;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import React, { useState, useEffect, useCallback } from "react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import moment from "moment";
|
|
5
|
+
import Button from '@mui/material/Button';
|
|
6
|
+
import OpenEventCardDialog from './components/OpenEventCardDialog';
|
|
7
|
+
import FancyDate from '../../Date/FancyDate';
|
|
8
|
+
export const EventCard = ({
|
|
9
|
+
event,
|
|
10
|
+
view_all_images_str
|
|
11
|
+
}) => {
|
|
12
|
+
const pictures = event.pictures || [];
|
|
13
|
+
const [currentImage, setCurrentImage] = useState(0);
|
|
14
|
+
const [openEventCardDialog, setOpenEventCardDialog] = useState(false);
|
|
15
|
+
|
|
16
|
+
//---------------------------------------------------
|
|
17
|
+
// Use Effect
|
|
18
|
+
//---------------------------------------------------
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (pictures.length > 1) {
|
|
21
|
+
const interval = setInterval(() => {
|
|
22
|
+
if (!openEventCardDialog) {
|
|
23
|
+
setCurrentImage(currentImage => {
|
|
24
|
+
const randomIndex = Math.floor(Math.random() * pictures.length);
|
|
25
|
+
return randomIndex !== currentImage ? randomIndex : (randomIndex + 1) % pictures.length;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}, 5000 + Math.floor(Math.random() * 3000));
|
|
29
|
+
|
|
30
|
+
// Clear interval when openEventCardDialog becomes true
|
|
31
|
+
if (openEventCardDialog) {
|
|
32
|
+
clearInterval(interval);
|
|
33
|
+
}
|
|
34
|
+
return () => clearInterval(interval);
|
|
35
|
+
}
|
|
36
|
+
}, [event, openEventCardDialog]);
|
|
37
|
+
const backgroundImage = pictures.length > 0 ? `url(${pictures[currentImage]})` : "";
|
|
38
|
+
const hasImages = pictures.length > 0;
|
|
39
|
+
|
|
40
|
+
//---------------------------------------------------
|
|
41
|
+
// Local Functions
|
|
42
|
+
//---------------------------------------------------
|
|
43
|
+
function isDatePassed(dateString) {
|
|
44
|
+
const date = moment(dateString);
|
|
45
|
+
return date.isBefore();
|
|
46
|
+
}
|
|
47
|
+
const getRandomTransition = useCallback(() => {
|
|
48
|
+
const randomSeconds = Math.floor(Math.random() * 2) + 1;
|
|
49
|
+
const randomEase = ["ease-in-out", "ease-in", "ease-out", "linear", "cubic-bezier(0.25, 0.1, 0.25, 1)", "ease-in-back", "ease-out-back", "ease-in-out-back", "ease-in-elastic", "ease-out-elastic", "ease-in-out-elastic", "cubic-bezier(0.68, -0.55, 0.265, 1.55)", "cubic-bezier(0.42, 0, 0.58, 1)"][Math.floor(Math.random() * 13)];
|
|
50
|
+
return `background-image ${randomSeconds}s ${randomEase}`;
|
|
51
|
+
}, []);
|
|
52
|
+
const handleCloseDialog = useCallback(() => {
|
|
53
|
+
setOpenEventCardDialog(false);
|
|
54
|
+
}, []);
|
|
55
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
|
56
|
+
key: event.id,
|
|
57
|
+
className: "relative rounded overflow-hidden shadow min-h-224 bg-cover cursor-pointer w-full",
|
|
58
|
+
style: {
|
|
59
|
+
backgroundImage,
|
|
60
|
+
transition: getRandomTransition(),
|
|
61
|
+
backgroundPosition: 'center',
|
|
62
|
+
backgroundRepeat: 'no-repeat',
|
|
63
|
+
backgroundSize: 'cover'
|
|
64
|
+
},
|
|
65
|
+
onClick: () => {
|
|
66
|
+
setOpenEventCardDialog(true);
|
|
67
|
+
}
|
|
68
|
+
}, !hasImages && /*#__PURE__*/React.createElement("div", {
|
|
69
|
+
className: "absolute inset-0 flex justify-center items-center text-gray-300 font-bold bg-gray-800"
|
|
70
|
+
}, /*#__PURE__*/React.createElement(FancyDate, {
|
|
71
|
+
date: event.event_date
|
|
72
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
73
|
+
className: "absolute bottom-0 left-0 right-0 normal-case text-white px-6 py-4 ",
|
|
74
|
+
style: {
|
|
75
|
+
background: 'rgba(0,0,0,0.5)'
|
|
76
|
+
}
|
|
77
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
78
|
+
className: "font-bold text-xl mb-2 capitalize overflow-ellipsis overflow-hidden whitespace-nowrap text-left"
|
|
79
|
+
}, event.title), /*#__PURE__*/React.createElement("div", {
|
|
80
|
+
className: "text-gray-300 normal-case text-base overflow-ellipsis overflow-hidden whitespace-nowrap pr-6 text-left max-h-32"
|
|
81
|
+
}, event.description.replace(/<[^>]+>/g, '')), /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
className: "flex flex-row justify-end mt-4"
|
|
83
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
84
|
+
className: "inline-block normal-case text-16 font-800 text-white overflow-ellipsis overflow-hidden whitespace-nowrap"
|
|
85
|
+
}, moment(event.event_date).format('dddd MMMM Do'))))), /*#__PURE__*/React.createElement(OpenEventCardDialog, _extends({}, event, {
|
|
86
|
+
open: openEventCardDialog,
|
|
87
|
+
closeDialog: handleCloseDialog,
|
|
88
|
+
view_all_images_str: view_all_images_str
|
|
89
|
+
})));
|
|
90
|
+
};
|
|
91
|
+
EventCard.propTypes = {
|
|
92
|
+
event: PropTypes.shape({
|
|
93
|
+
title: PropTypes.string.isRequired,
|
|
94
|
+
description: PropTypes.string.isRequired,
|
|
95
|
+
pictures: PropTypes.arrayOf(PropTypes.string),
|
|
96
|
+
event_date: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string]).isRequired,
|
|
97
|
+
state_id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired
|
|
98
|
+
}),
|
|
99
|
+
view_all_images_str: PropTypes.string
|
|
100
|
+
};
|
|
101
|
+
export default EventCard;
|
package/dist/components/Date/{DateRangeCalendar → DatePickerReactStyled/DateCalendar}/css/style.css
RENAMED
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
background: linear-gradient(to right, rgb(70, 83, 52) 0%, #526B33 100%) !important;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/* Override the grid drop down so it's not long when in vertical mode so the next calendar button are always near the bottom of the dropdown */
|
|
15
|
+
[data-testid="MonthGrid"] {
|
|
16
|
+
height: 100% !important; /* Adjust as necessary */
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
|
|
15
20
|
.back_blocks_small{
|
|
16
21
|
background-color:#f1632f;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { green } from '@mui/material/colors';
|
|
4
|
+
import { Datepicker } from '@datepicker-react/styled';
|
|
5
|
+
import { ThemeProvider } from 'styled-components';
|
|
6
|
+
import './css/style.css';
|
|
7
|
+
import { commonCalendarTheme } from '../common/theme';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* example with styling https://codesandbox.io/s/react-date-picker-rangeinput-jw726?from-embed=&file=/src/index.js:2503-2537
|
|
11
|
+
*
|
|
12
|
+
* Same component as DateRangeCalendar but without the range input and the user can't select a range of dates.
|
|
13
|
+
* Usefull for showing a calendar with the available dates for booking.
|
|
14
|
+
*
|
|
15
|
+
* ## Importing the component in your project
|
|
16
|
+
*
|
|
17
|
+
```js
|
|
18
|
+
import {DateCalendar} from 'pcm-shared-components';
|
|
19
|
+
```
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export const DateCalendar = props => {
|
|
23
|
+
const {
|
|
24
|
+
minBookingDate,
|
|
25
|
+
numberOfMonthsVisible,
|
|
26
|
+
dateFormat,
|
|
27
|
+
minBookingDays,
|
|
28
|
+
onDayRender,
|
|
29
|
+
isDateBlocked,
|
|
30
|
+
focusedInput,
|
|
31
|
+
onDatesChange,
|
|
32
|
+
startDate,
|
|
33
|
+
endDate,
|
|
34
|
+
variant,
|
|
35
|
+
vertical,
|
|
36
|
+
showSelectedDates,
|
|
37
|
+
zIndex,
|
|
38
|
+
i18next,
|
|
39
|
+
daySize,
|
|
40
|
+
datepickerPadding
|
|
41
|
+
} = props;
|
|
42
|
+
const handleOnDayRender = date => {
|
|
43
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, onDayRender ? /*#__PURE__*/React.createElement(React.Fragment, null, onDayRender(date)) : /*#__PURE__*/React.createElement("span", {
|
|
44
|
+
className: ""
|
|
45
|
+
}, new Date(date).getDate()));
|
|
46
|
+
};
|
|
47
|
+
const handleIsDateBlocked = date => {
|
|
48
|
+
try {
|
|
49
|
+
if (typeof isDateBlocked === 'function') {
|
|
50
|
+
return isDateBlocked(date);
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error(error);
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
const handleOnDatesChange = data => {
|
|
58
|
+
try {
|
|
59
|
+
if (typeof onDatesChange === 'function') {
|
|
60
|
+
onDatesChange(data);
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(error);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const overrideCalendarTheme = {};
|
|
67
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
68
|
+
className: `m-auto pt-0 md:pt-0 ${variant === 'standard' ? 'bottom_border' : undefined}`,
|
|
69
|
+
style: {
|
|
70
|
+
zIndex: 100
|
|
71
|
+
}
|
|
72
|
+
}, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
73
|
+
theme: commonCalendarTheme({
|
|
74
|
+
...props
|
|
75
|
+
},
|
|
76
|
+
// Main configuration object
|
|
77
|
+
{
|
|
78
|
+
colors: {
|
|
79
|
+
primaryColor: green[300],
|
|
80
|
+
accessibility: green[300],
|
|
81
|
+
selectedDay: green[300],
|
|
82
|
+
selectedDayHover: green[300]
|
|
83
|
+
// normalDayHover: 'transparent',
|
|
84
|
+
}
|
|
85
|
+
} // Additional theme configuration
|
|
86
|
+
)
|
|
87
|
+
}, /*#__PURE__*/React.createElement(Datepicker, {
|
|
88
|
+
phrases: {
|
|
89
|
+
datepickerStartDateLabel: i18next.t('common.app.arrival_date'),
|
|
90
|
+
datepickerEndDateLabel: i18next.t('common.app.departure_date'),
|
|
91
|
+
resetDates: i18next.t('common.app.reset'),
|
|
92
|
+
close: i18next.t('common.app.close'),
|
|
93
|
+
datepickerStartDatePlaceholder: i18next.t('common.app.arrival_date'),
|
|
94
|
+
datepickerEndDatePlaceholder: i18next.t('common.app.departure_date'),
|
|
95
|
+
startDateAriaLabel: i18next.t('common.app.arrival_date'),
|
|
96
|
+
endDateAriaLabel: i18next.t('common.app.departure_date'),
|
|
97
|
+
startDatePlaceholder: i18next.t('common.app.arrival_date'),
|
|
98
|
+
endDatePlaceholder: i18next.t('common.app.departure_date')
|
|
99
|
+
},
|
|
100
|
+
showSelectedDates: showSelectedDates,
|
|
101
|
+
showResetDates: false,
|
|
102
|
+
showClose: false,
|
|
103
|
+
onDayRender: handleOnDayRender,
|
|
104
|
+
isDateBlocked: handleIsDateBlocked,
|
|
105
|
+
firstDayOfWeek: 0,
|
|
106
|
+
minBookingDays: minBookingDays,
|
|
107
|
+
minBookingDate: minBookingDate,
|
|
108
|
+
vertical: vertical,
|
|
109
|
+
numberOfMonths: numberOfMonthsVisible,
|
|
110
|
+
onDatesChange: handleOnDatesChange,
|
|
111
|
+
startDate: startDate // Date or null
|
|
112
|
+
,
|
|
113
|
+
endDate: endDate // Date or null
|
|
114
|
+
,
|
|
115
|
+
focusedInput: focusedInput,
|
|
116
|
+
displayFormat: dateFormat
|
|
117
|
+
})));
|
|
118
|
+
};
|
|
119
|
+
export default DateCalendar;
|
|
120
|
+
DateCalendar.defaultProps = {
|
|
121
|
+
minBookingDate: new Date(new Date().setDate(new Date().getDate() + 1)),
|
|
122
|
+
numberOfMonthsVisible: 2,
|
|
123
|
+
dateFormat: 'MMM d, yyyy',
|
|
124
|
+
minBookingDays: 1,
|
|
125
|
+
onDayRender: undefined,
|
|
126
|
+
isDateBlocked: undefined,
|
|
127
|
+
onDatesChange: undefined,
|
|
128
|
+
startDate: null,
|
|
129
|
+
endDate: null,
|
|
130
|
+
focusedInput: null,
|
|
131
|
+
variant: 'standard',
|
|
132
|
+
vertical: false,
|
|
133
|
+
zIndex: 1000,
|
|
134
|
+
i18next: undefined,
|
|
135
|
+
daySize: 40,
|
|
136
|
+
datepickerPadding: 25,
|
|
137
|
+
showSelectedDates: false
|
|
138
|
+
};
|
|
139
|
+
DateCalendar.propTypes = {
|
|
140
|
+
/** Used to provide the minimum booking date. To allow date selection past todays date simply pas it an old past date example 'new Date('1999-10-02')' */
|
|
141
|
+
minBookingDate: PropTypes.instanceOf(Date),
|
|
142
|
+
/** Number of calendar months to display.*/
|
|
143
|
+
numberOfMonthsVisible: PropTypes.number,
|
|
144
|
+
/** Date format to use when displaying the selected dates in the text boxes.*/
|
|
145
|
+
dateFormat: PropTypes.string,
|
|
146
|
+
/** Min booking days allowing the user to select a valid date range.*/
|
|
147
|
+
minBookingDays: PropTypes.number,
|
|
148
|
+
/** Provides a (date:date) props to the function and expects a React.ReactNode component to be returned */
|
|
149
|
+
onDayRender: PropTypes.func,
|
|
150
|
+
/** Provides a (date:date) props to the function and expects a boolean value returned which tells the calendar to either block or not that day*/
|
|
151
|
+
isDateBlocked: PropTypes.func,
|
|
152
|
+
/** Provides a (data) props to the function and doesn't expect any return value*/
|
|
153
|
+
onDatesChange: PropTypes.func,
|
|
154
|
+
/** The stat date of the calendar */
|
|
155
|
+
startDate: PropTypes.instanceOf(Date),
|
|
156
|
+
/** The end date of the calendar */
|
|
157
|
+
endDate: PropTypes.instanceOf(Date),
|
|
158
|
+
/** Determines on which input the calendar will be focused on. Null = nothing meaning the calendar should be closed if null*/
|
|
159
|
+
focusedInput: PropTypes.oneOf(['startDate', 'endDate', null]),
|
|
160
|
+
/** Controls the type of border to display around the date input boxes*/
|
|
161
|
+
variant: PropTypes.oneOf(['outlined', 'standard', 'none']),
|
|
162
|
+
/** Controls the orientation of the calendar */
|
|
163
|
+
vertical: PropTypes.bool,
|
|
164
|
+
/** Controls the z-index of the calendar dropdown date selection */
|
|
165
|
+
zIndex: PropTypes.number,
|
|
166
|
+
/** i18next localization to use for the component. Don't use the library localization or else it won't load properly on the consuming application */
|
|
167
|
+
i18next: PropTypes.any,
|
|
168
|
+
/** Controls the size of the day in the calendar */
|
|
169
|
+
daySize: PropTypes.number,
|
|
170
|
+
/** Controls the padding of the datepicker */
|
|
171
|
+
datepickerPadding: PropTypes.number,
|
|
172
|
+
/** Controls the visibility of the selected dates in the calendar */
|
|
173
|
+
showSelectedDates: PropTypes.bool
|
|
174
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from "@storybook/addon-docs";
|
|
2
|
+
import Datepicker from '..'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Datepicker
|
|
6
|
+
|
|
7
|
+
## Importing the component in your project.
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import {Datepicker} from 'pcm-shared-components';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Usage
|
|
14
|
+
Check out the index.stories.jsx file DateRangeCalendarComp to see a full simple example of how it whould be used in.
|
|
15
|
+
|
|
16
|
+
#### Minimum REQUIRED setup NEEDED to get the Datepicker working:
|
|
17
|
+
```js
|
|
18
|
+
import React, {useState} from 'react'
|
|
19
|
+
import {Datepicker } from 'pcm-shared-components';
|
|
20
|
+
|
|
21
|
+
function App() {
|
|
22
|
+
|
|
23
|
+
//States
|
|
24
|
+
const [state, setState] = useState({ startDate: null, endDate: null, focusedInput: 'startDate' })
|
|
25
|
+
|
|
26
|
+
//Functions
|
|
27
|
+
const handleDatesChange = (data) => {
|
|
28
|
+
setState(data)
|
|
29
|
+
}
|
|
30
|
+
const handleOnFocusChange = (data) =>{
|
|
31
|
+
setState((previousState)=>{return{...previousState,focusedInput:data}});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Datepicker
|
|
36
|
+
onDatesChange={handleDatesChange}
|
|
37
|
+
onFocusChange={handleOnFocusChange}
|
|
38
|
+
startDate={state.startDate} // Date or null
|
|
39
|
+
endDate={state.endDate} // Date or null
|
|
40
|
+
focusedInput={state.focusedInput} // START_DATE, END_DATE or null
|
|
41
|
+
i18next={i18next}
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
### See a Codesandbox example with styling
|
|
47
|
+
https://codesandbox.io/s/react-date-picker-rangeinput-jw726?from-embed=&file=/src/index.js:2503-2537
|
|
48
|
+
|
|
49
|
+
### Styling Props
|
|
50
|
+
The following are the theme props taken form the codesandbox from above so I have a local copy of the possible props.
|
|
51
|
+
```js
|
|
52
|
+
<ThemeProvider
|
|
53
|
+
theme={{
|
|
54
|
+
breakpoints: ["32em", "48em", "64em"],
|
|
55
|
+
reactDatepicker: {
|
|
56
|
+
daySize: [36, 36],
|
|
57
|
+
fontFamily: "system-ui, -apple-system",
|
|
58
|
+
colors: {
|
|
59
|
+
primaryColor: "#4B35D2",
|
|
60
|
+
accessibility: "#4B35D2",
|
|
61
|
+
selectedDay: "#EEEDFD",
|
|
62
|
+
selectedDayHover: "#faf9fd",
|
|
63
|
+
normalDayHover: "#faf9fd"
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
dayLabelFontSize: 10,
|
|
67
|
+
dayLabelColor: "#8F8B9B",
|
|
68
|
+
|
|
69
|
+
selectDateLabelFontSize: 10,
|
|
70
|
+
selectDateLabelColor: "#D0CED5",
|
|
71
|
+
selectDateDateFontSize: 14,
|
|
72
|
+
selectDateDateColor: "#34323A",
|
|
73
|
+
selectDateBorderColor: "#4B35D2",
|
|
74
|
+
|
|
75
|
+
navButtonBorder: "none",
|
|
76
|
+
|
|
77
|
+
monthLabelFontSize: 16,
|
|
78
|
+
monthLabelFontWeight: 600,
|
|
79
|
+
|
|
80
|
+
dayBackground: "#ffffff",
|
|
81
|
+
dayBorderColor: "transparent",
|
|
82
|
+
dayColor: "#34323A",
|
|
83
|
+
dayFontSize: 15,
|
|
84
|
+
daySelectedBorderColor: "transparent",
|
|
85
|
+
daySelectedColor: "#34323A",
|
|
86
|
+
daySelectedHoverColor: "#000000",
|
|
87
|
+
dayHoverColor: "#000000",
|
|
88
|
+
dayHoverBackground: "#EEEDFD",
|
|
89
|
+
//dayHoverRangeColor: "#000000", // attention
|
|
90
|
+
dayHoverRangeBackground: "#EEEDFD",
|
|
91
|
+
dayAccessibilityBorderColor: "none",
|
|
92
|
+
|
|
93
|
+
inputLabelDisplay: "flex",
|
|
94
|
+
inputLabelBorder: "none",
|
|
95
|
+
inputLabelMargin: 0,
|
|
96
|
+
inputPadding: 0,
|
|
97
|
+
inputBorder: "none",
|
|
98
|
+
inputFontSize: 14,
|
|
99
|
+
inputColor: "#34323A",
|
|
100
|
+
inputActiveBoxShadow: "none",
|
|
101
|
+
inputBackground: "none",
|
|
102
|
+
|
|
103
|
+
datepickerZIndex: 1,
|
|
104
|
+
datepickerBoxShadow: "0px 5px 15px #28128733",
|
|
105
|
+
datepickerBorderRadius: 5,
|
|
106
|
+
datepickerPadding: 25,
|
|
107
|
+
datepickerPosition: "absolute",
|
|
108
|
+
datepickerMonthsGridGap: 10,
|
|
109
|
+
|
|
110
|
+
dateRangeBorder: "none",
|
|
111
|
+
dateRangeArrowIconColor: "#34323A",
|
|
112
|
+
dateRangeStartDateInputPadding: 0,
|
|
113
|
+
dateRangeEndDateInputPadding: 0,
|
|
114
|
+
dateRangeDatepickerWrapperLeft: 30,
|
|
115
|
+
dateRangeDatepickerWrapperTop: 80
|
|
116
|
+
}
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
<ArgsTable of={Datepicker} />
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import DateCalendar from '..';
|
|
4
|
+
import IndexDocs from './index.docs.mdx';
|
|
5
|
+
import i18next from 'i18next';
|
|
6
|
+
const DateCalendarComp = props => {
|
|
7
|
+
//State
|
|
8
|
+
const startDate = new Date();
|
|
9
|
+
const endDate = new Date();
|
|
10
|
+
endDate.setDate(startDate.getDate() + 14);
|
|
11
|
+
const [state, setState] = useState({
|
|
12
|
+
startDate,
|
|
13
|
+
endDate,
|
|
14
|
+
focusedInput: null
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
//Functions
|
|
18
|
+
const handleOnDayRender = date => {
|
|
19
|
+
if (new Date(date).getDate() == 20 || new Date(date).getDate() == 21) {
|
|
20
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
21
|
+
className: "flex flex-col =h-full w-full m-auto"
|
|
22
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
23
|
+
className: " relative -top-2 text-green-700"
|
|
24
|
+
}, "\u2713"), /*#__PURE__*/React.createElement("span", {
|
|
25
|
+
className: "relative -top-6 h-full text-center m-auto "
|
|
26
|
+
}, new Date(date).getDate()));
|
|
27
|
+
} else {
|
|
28
|
+
return /*#__PURE__*/React.createElement("span", null, new Date(date).getDate());
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const handleIsDateBlocked = date => {
|
|
32
|
+
try {
|
|
33
|
+
return new Date(date).getDate() == 16;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(error);
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
const handleOnDatesChange = data => {
|
|
40
|
+
setState(data);
|
|
41
|
+
};
|
|
42
|
+
return /*#__PURE__*/React.createElement(DateCalendar, _extends({
|
|
43
|
+
onDayRender: date => handleOnDayRender(date),
|
|
44
|
+
isDateBlocked: handleIsDateBlocked,
|
|
45
|
+
onDatesChange: handleOnDatesChange,
|
|
46
|
+
startDate: state.startDate,
|
|
47
|
+
endDate: state.endDate,
|
|
48
|
+
focusedInput: state.focusedInput,
|
|
49
|
+
minBookingDays: 2,
|
|
50
|
+
i18next: i18next,
|
|
51
|
+
daySize: 40,
|
|
52
|
+
datepickerPadding: 25
|
|
53
|
+
}, props));
|
|
54
|
+
};
|
|
55
|
+
export default {
|
|
56
|
+
title: 'Date/DateCalendar',
|
|
57
|
+
component: DateCalendarComp,
|
|
58
|
+
argTypes: {},
|
|
59
|
+
parameters: {
|
|
60
|
+
docs: {
|
|
61
|
+
// inlineStories: true,
|
|
62
|
+
page: IndexDocs
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const DateCalendarTemplate = args => /*#__PURE__*/React.createElement(DateCalendarComp, args);
|
|
67
|
+
export const DateCalendarExample = DateCalendarTemplate.bind({});
|
|
68
|
+
DateCalendarExample.args = {
|
|
69
|
+
Help: 'Note not all props listed see docs for full list...',
|
|
70
|
+
variant: 'standard',
|
|
71
|
+
numberOfMonthsVisible: 2,
|
|
72
|
+
daySize: 40,
|
|
73
|
+
datepickerPadding: 25
|
|
74
|
+
};
|