@hyphen/hyphen-components 6.14.0 → 7.0.0-beta.1

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.
Files changed (34) hide show
  1. package/dist/components/Calendar/Calendar.d.ts +5 -0
  2. package/dist/components/Calendar/Calendar.stories.d.ts +12 -0
  3. package/dist/components/Modal/components/ModalHeader/ModalHeader.d.ts +6 -1
  4. package/dist/css/index.css +2 -3
  5. package/dist/css/utilities.css +8 -0
  6. package/dist/hyphen-components.cjs.development.js +633 -788
  7. package/dist/hyphen-components.cjs.development.js.map +1 -1
  8. package/dist/hyphen-components.cjs.production.min.js +1 -1
  9. package/dist/hyphen-components.cjs.production.min.js.map +1 -1
  10. package/dist/hyphen-components.esm.js +634 -787
  11. package/dist/hyphen-components.esm.js.map +1 -1
  12. package/dist/index.d.ts +1 -2
  13. package/package.json +2 -3
  14. package/src/components/Calendar/Calendar.mdx +28 -0
  15. package/src/components/Calendar/Calendar.stories.tsx +217 -0
  16. package/src/components/Calendar/Calendar.tsx +117 -0
  17. package/src/components/Formik/Formik.stories.tsx +10 -21
  18. package/src/components/Modal/Modal.stories.tsx +3 -1
  19. package/src/components/Modal/components/ModalHeader/ModalHeader.tsx +27 -9
  20. package/src/index.ts +1 -2
  21. package/src/styles/utilities.scss +8 -0
  22. package/dist/components/DateInput/DateInput.d.ts +0 -57
  23. package/dist/components/DateInput/DateInput.stories.d.ts +0 -11
  24. package/dist/components/DatePicker/DatePicker.d.ts +0 -86
  25. package/dist/components/DatePicker/DatePicker.stories.d.ts +0 -13
  26. package/src/components/DateInput/DateInput.mdx +0 -61
  27. package/src/components/DateInput/DateInput.stories.tsx +0 -168
  28. package/src/components/DateInput/DateInput.test.tsx +0 -176
  29. package/src/components/DateInput/DateInput.tsx +0 -212
  30. package/src/components/DatePicker/DatePicker.mdx +0 -52
  31. package/src/components/DatePicker/DatePicker.module.scss +0 -603
  32. package/src/components/DatePicker/DatePicker.stories.tsx +0 -199
  33. package/src/components/DatePicker/DatePicker.test.tsx +0 -26
  34. package/src/components/DatePicker/DatePicker.tsx +0 -138
@@ -1,199 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { DatePicker } from './DatePicker';
3
- import type { Meta } from '@storybook/react-vite';
4
- import { Box } from '../Box/Box';
5
- import { Heading } from '../Heading/Heading';
6
-
7
- const meta: Meta<typeof DatePicker> = {
8
- title: 'Components/DatePicker',
9
- component: DatePicker,
10
- };
11
-
12
- export default meta;
13
-
14
- export const BasicExample = () => {
15
- const [selectedDate, setSelectedDate] = useState<Date>(new Date(2019, 11, 3));
16
- return (
17
- <Box gap="md">
18
- <DatePicker
19
- onChange={(date) => setSelectedDate(date as Date)}
20
- selected={selectedDate}
21
- />
22
- <p>Selected Date: {selectedDate.toISOString()}</p>
23
- </Box>
24
- );
25
- };
26
-
27
- export const DateRange = () => {
28
- const [startDate, setStartDate] = useState<Date>(new Date(2019, 11, 3));
29
- const [endDate, setEndDate] = useState<Date>(new Date(2019, 11, 28));
30
- const setDate = ([startDate, endDate]: [Date, Date]) => {
31
- setStartDate(startDate);
32
- setEndDate(endDate);
33
- };
34
- return (
35
- <Box gap="md">
36
- <DatePicker
37
- onChange={(date) => setDate(date as [Date, Date])}
38
- selected={startDate}
39
- startDate={startDate}
40
- endDate={endDate}
41
- selectsRange
42
- />
43
- <p>
44
- {`Selected Date Range: ${startDate && startDate.toISOString()} - ${
45
- endDate && endDate.toISOString()
46
- }`}
47
- </p>
48
- </Box>
49
- );
50
- };
51
-
52
- export const MinAndMaxDates = () => {
53
- const [startDate, setStartDate] = useState<Date>(new Date(2019, 11, 18));
54
- const min = new Date(2019, 11, 18);
55
- min.setDate(min.getDate() - 5);
56
- const max = new Date(2019, 11, 18);
57
- max.setDate(max.getDate() + 5);
58
- return (
59
- <Box gap="md">
60
- <DatePicker
61
- selected={startDate}
62
- onChange={(date) => setStartDate(date as Date)}
63
- minDate={min}
64
- maxDate={max}
65
- />
66
- <p>Selected Date: {startDate.toISOString()}</p>
67
- </Box>
68
- );
69
- };
70
-
71
- export const MonthPicker = () => {
72
- const [startDateOne, setStartDateOne] = useState<Date>(new Date(2019, 10));
73
- const [startDateTwo, setStartDateTwo] = useState<Date>(new Date(2019, 10));
74
- const [startDateThree, setStartDateThree] = useState<Date>(
75
- new Date(2019, 10)
76
- );
77
- return (
78
- <Box display="flex" direction="row" gap="md">
79
- <Box
80
- gap="md"
81
- display="flex"
82
- direction="column"
83
- alignItems="center"
84
- width="33"
85
- >
86
- <Heading size="md">Default</Heading>
87
- <DatePicker
88
- selected={startDateOne}
89
- onChange={(date) => setStartDateOne(date as Date)}
90
- showMonthYearPicker
91
- />
92
- <p>{startDateOne.toISOString()}</p>
93
- </Box>
94
- <Box
95
- gap="md"
96
- display="flex"
97
- direction="column"
98
- alignItems="center"
99
- width="33"
100
- >
101
- <Heading size="md">With full month name</Heading>
102
- <DatePicker
103
- selected={startDateTwo}
104
- onChange={(date) => setStartDateTwo(date as Date)}
105
- showMonthYearPicker
106
- showFullMonthYearPicker
107
- />
108
- <p>{startDateTwo.toISOString()}</p>
109
- </Box>
110
- <Box
111
- gap="md"
112
- display="flex"
113
- direction="column"
114
- alignItems="center"
115
- width="33"
116
- >
117
- <Heading size="md">With Two-column layout</Heading>
118
- <DatePicker
119
- selected={startDateThree}
120
- onChange={(date) => setStartDateThree(date as Date)}
121
- showMonthYearPicker
122
- showFullMonthYearPicker
123
- showTwoColumnMonthYearPicker
124
- />
125
- <p>{startDateThree.toISOString()}</p>
126
- </Box>
127
- </Box>
128
- );
129
- };
130
-
131
- export const ShowMultipleMonths = () => {
132
- const [startDate, setStartDate] = useState<Date>(new Date(2019, 11, 3));
133
- const [endDate, setEndDate] = useState<Date>(new Date(2019, 12, 20));
134
- const setDate = ([startDate, endDate]: [Date, Date]) => {
135
- setStartDate(startDate);
136
- setEndDate(endDate);
137
- };
138
- return (
139
- <Box gap="md">
140
- <DatePicker
141
- onChange={(date) => setDate(date as [Date, Date])}
142
- selected={startDate}
143
- startDate={startDate}
144
- endDate={endDate}
145
- selectsRange
146
- monthsShown={2}
147
- />
148
- <p>Start Date: {startDate && startDate.toISOString()}</p>
149
- <p>End Date: {endDate && endDate.toISOString()}</p>
150
- </Box>
151
- );
152
- };
153
-
154
- export const WithTimePicker = () => {
155
- const [startDate, setStartDate] = useState<Date>(new Date('1993/09/28'));
156
- return (
157
- <Box gap="md">
158
- <DatePicker
159
- selected={startDate}
160
- onChange={(date) => setStartDate(date as Date)}
161
- showTimeSelect
162
- timeIntervals={15}
163
- timeCaption="Time"
164
- />
165
- <p>Selected Date: {startDate && startDate.toISOString()}</p>
166
- </Box>
167
- );
168
- };
169
-
170
- export const OpenByDefaultOnASpecificDate = () => {
171
- const [startDate, setStartDate] = useState<Date>(new Date('1993/09/28'));
172
- return (
173
- <Box gap="md">
174
- <DatePicker
175
- onChange={(date) => setStartDate(date as Date)}
176
- selected={startDate}
177
- openToDate={new Date('1993/09/28')}
178
- />
179
- <p>Selected Date: {startDate && startDate.toISOString()}</p>
180
- </Box>
181
- );
182
- };
183
-
184
- export const WithChildren = () => {
185
- const [selectedDate, setSelectedDate] = useState<Date>(new Date(2019, 11, 3));
186
- return (
187
- <Box gap="md">
188
- <DatePicker
189
- onChange={(date) => setSelectedDate(date as Date)}
190
- selected={selectedDate}
191
- >
192
- <Box display="block" style={{ textAlign: 'center' }} color="base">
193
- It will be sunny out today!
194
- </Box>
195
- </DatePicker>
196
- <p>Selected Date: {selectedDate.toISOString()}</p>
197
- </Box>
198
- );
199
- };
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render, screen } from '@testing-library/react';
3
- import { DatePicker } from './DatePicker';
4
-
5
- describe('DatePicker', () => {
6
- describe('Default', () => {
7
- it('renders a datepicker with default props', () => {
8
- const mockedOnChange = jest.fn();
9
- const { container } = render(<DatePicker onChange={mockedOnChange} />);
10
- const datePicker = container.querySelector('.react-datepicker');
11
- expect(datePicker).toBeInTheDocument();
12
- });
13
- });
14
-
15
- describe('Callbacks', () => {
16
- it('Fires the expected callback when date is selected', () => {
17
- const openToDate = new Date('1995, 11, 14');
18
- const mockedOnChange = jest.fn();
19
- render(<DatePicker onChange={mockedOnChange} openToDate={openToDate} />);
20
- const fourteenth = screen.getByText('14');
21
- expect(fourteenth).toBeInTheDocument();
22
- fireEvent.click(fourteenth);
23
- expect(mockedOnChange).toHaveBeenCalledTimes(1);
24
- });
25
- });
26
- });
@@ -1,138 +0,0 @@
1
- import React, { FC, SyntheticEvent, ReactNode } from 'react';
2
- import classNames from 'classnames';
3
- import ReactDatePicker, { ReactDatePickerProps } from 'react-datepicker';
4
- import styles from './DatePicker.module.scss';
5
-
6
- export interface DatePickerProps extends ReactDatePickerProps<any, any> {
7
- /**
8
- * React children (to be rendered below the calendar dates).
9
- */
10
- children?: ReactNode;
11
- /**
12
- * Custom classname to be applied to the DatePicker container.
13
- */
14
- className?: string;
15
- /**
16
- * Callback that fires when a date is changed/selected.
17
- */
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- onChange: (
20
- date: Date | [Date, Date] | null,
21
- event?: React.SyntheticEvent<any> | undefined
22
- ) => void;
23
- /**
24
- * Callback that fires when a date is clicked.
25
- */
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- onSelect?:
28
- | ((date: Date, event: SyntheticEvent<any, Event> | undefined) => void)
29
- | undefined;
30
- /**
31
- * Custom Class to be applied to a single day element based on a date.
32
- */
33
- dayClassName?: ((date: Date) => string | null) | undefined;
34
- /**
35
- * Custom Class to be applied to a single week element based on a date.
36
- */
37
- weekClassName?: ((date: Date) => string | null) | undefined;
38
- /**
39
- * Custom Class to be applied to a single month element based on a date.
40
- */
41
- monthClassName?: ((date: Date) => string | null) | undefined;
42
- /**
43
- * Custom Class to be applied to a specific time.
44
- */
45
- timeClassName?: ((date: Date) => string | null) | undefined;
46
- /**
47
- * Custom format for weekday.
48
- */
49
- formatWeekDay?: (formattedDate: string) => string;
50
- /**
51
- * Last allowable/shown date
52
- */
53
- maxDate?: Date | null;
54
- /**
55
- * First allowable/shown date
56
- */
57
- minDate?: Date | null;
58
- /**
59
- * Months to be shown at one time
60
- */
61
- monthsShown?: number;
62
- /**
63
- * Date that the calendar will open to by default.
64
- */
65
- openToDate?: Date;
66
- /**
67
- * Currently selected date.
68
- */
69
- selected?: Date | null;
70
- /**
71
- * Whether or not the picker will return a range of dates.
72
- */
73
- selectsRange?: boolean;
74
- /**
75
- * Start date in a range
76
- */
77
- startDate?: Date | null;
78
- /**
79
- * Show month picker in two columns
80
- */
81
- showTwoColumnMonthYearPicker?: boolean;
82
- /**
83
- * See full month name in the month picker
84
- */
85
- showFullMonthYearPicker?: boolean;
86
- /**
87
- * Use the month picker
88
- */
89
- showMonthYearPicker?: boolean;
90
- /**
91
- * Additional props to be spread to rendered element
92
- */
93
- [x: string]: any; // eslint-disable-line
94
- }
95
-
96
- export const DatePicker: FC<DatePickerProps> = ({
97
- children = null,
98
- dayClassName = undefined,
99
- maxDate = undefined,
100
- minDate = undefined,
101
- monthsShown = undefined,
102
- openToDate = undefined,
103
- startDate = undefined,
104
- selected = undefined,
105
- selectsRange = undefined,
106
- showTwoColumnMonthYearPicker = false,
107
- showFullMonthYearPicker = false,
108
- showMonthYearPicker = false,
109
- className = undefined,
110
- formatWeekDay = (formattedDate) => formattedDate[0], // Make days show as 1 character.
111
- ...restProps
112
- }) => {
113
- const datePickerClasses = classNames(styles['react-datepicker'], className);
114
-
115
- return (
116
- <ReactDatePicker
117
- inline
118
- calendarClassName={datePickerClasses}
119
- formatWeekDay={formatWeekDay}
120
- maxDate={maxDate}
121
- minDate={minDate}
122
- monthsShown={monthsShown}
123
- openToDate={openToDate}
124
- selected={selected}
125
- startDate={startDate}
126
- selectsRange={selectsRange}
127
- showTwoColumnMonthYearPicker={showTwoColumnMonthYearPicker}
128
- showFullMonthYearPicker={showFullMonthYearPicker}
129
- showMonthYearPicker={showMonthYearPicker}
130
- dayClassName={dayClassName}
131
- {...restProps}
132
- >
133
- {children}
134
- </ReactDatePicker>
135
- );
136
- };
137
-
138
- export default DatePicker;