@soul-refiner/design-system 0.2.113 → 0.2.114
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.
|
@@ -17,6 +17,7 @@ export interface CoursesSelectionProps extends NativeProps, React.PropsWithChild
|
|
|
17
17
|
courseIsSelected: Record<string, boolean>;
|
|
18
18
|
setCourseIsSelected: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
|
|
19
19
|
subtitle: string;
|
|
20
|
+
onlyOneCanBeSelected: boolean;
|
|
20
21
|
}
|
|
21
|
-
export declare const CoursesSelection: ({ closeOnChange, closeOnBlur, disabled, offset, sx, containerSx, courses, label, courseIsSelected, setCourseIsSelected, subtitle, ...rest }: CoursesSelectionProps) => React.JSX.Element;
|
|
22
|
+
export declare const CoursesSelection: ({ closeOnChange, closeOnBlur, disabled, offset, sx, containerSx, courses, label, courseIsSelected, setCourseIsSelected, subtitle, onlyOneCanBeSelected, ...rest }: CoursesSelectionProps) => React.JSX.Element;
|
|
22
23
|
export {};
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import { Button, P, Box, H } from '../..';
|
|
5
5
|
import { GraduationCap, Search as SearchIcon, Plus, Close, } from '../../../icons';
|
|
6
|
-
export const CoursesSelection = ({ closeOnChange = true, closeOnBlur = true, disabled = false, offset = [0, 0], sx, containerSx, courses, label, courseIsSelected, setCourseIsSelected, subtitle, ...rest }) => {
|
|
6
|
+
export const CoursesSelection = ({ closeOnChange = true, closeOnBlur = true, disabled = false, offset = [0, 0], sx, containerSx, courses, label, courseIsSelected, setCourseIsSelected, subtitle, onlyOneCanBeSelected = false, ...rest }) => {
|
|
7
7
|
const wrapperRef = React.useRef(null);
|
|
8
8
|
const [open, setOpen] = React.useState(false);
|
|
9
9
|
React.useEffect(() => {
|
|
@@ -33,10 +33,14 @@ export const CoursesSelection = ({ closeOnChange = true, closeOnBlur = true, dis
|
|
|
33
33
|
React.createElement(P, { "$color": "grey-4", "$fontSize": 14, sx: "margin-top: 32px;" }, subtitle),
|
|
34
34
|
React.createElement(Button, { type: "dropdown", isDropdownOpen: open, onClick: handleOpen, customDropdownIcon: SearchIcon, sx: "margin-top: 32px;" }, label),
|
|
35
35
|
open && (React.createElement(Container, { "$offset": offset, "$sx": containerSx }, courses.map((course) => (React.createElement(OptionWrapper, { key: course.id, "$disabled": disabled, onClick: () => {
|
|
36
|
-
setCourseIsSelected(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
setCourseIsSelected(onlyOneCanBeSelected
|
|
37
|
+
? {
|
|
38
|
+
[course.id]: true,
|
|
39
|
+
}
|
|
40
|
+
: {
|
|
41
|
+
...courseIsSelected,
|
|
42
|
+
[course.id]: true,
|
|
43
|
+
});
|
|
40
44
|
if (closeOnChange) {
|
|
41
45
|
setOpen(false);
|
|
42
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface CalendarInputProps {
|
|
3
|
-
selectedDate: Date;
|
|
3
|
+
selectedDate: Date | null;
|
|
4
4
|
onSelect: (value: Date) => void;
|
|
5
5
|
}
|
|
6
6
|
export declare const CalendarInput: ({ selectedDate, onSelect: parentOnSelect, }: CalendarInputProps) => React.JSX.Element;
|
|
@@ -15,10 +15,10 @@ export const CalendarInput = ({ selectedDate, onSelect: parentOnSelect, }) => {
|
|
|
15
15
|
firstOfMonth.setDate(1);
|
|
16
16
|
const pickerRef = React.useRef(null);
|
|
17
17
|
const [show, setShow] = React.useState(false);
|
|
18
|
-
const [displayDate, setDisplayDate] = React.useState(() => selectedDate.toDateString());
|
|
19
|
-
const [componentSelectedDate, setComponentSelectedDate] = React.useState(() => selectedDate.toDateString());
|
|
18
|
+
const [displayDate, setDisplayDate] = React.useState(() => selectedDate?.toDateString() || new Date().toDateString());
|
|
19
|
+
const [componentSelectedDate, setComponentSelectedDate] = React.useState(() => selectedDate?.toDateString() || new Date().toDateString());
|
|
20
20
|
React.useEffect(() => {
|
|
21
|
-
setComponentSelectedDate(selectedDate.toDateString());
|
|
21
|
+
setComponentSelectedDate(selectedDate?.toDateString() || new Date().toDateString());
|
|
22
22
|
}, [selectedDate]);
|
|
23
23
|
const handleShow = () => setShow((prev) => !prev);
|
|
24
24
|
const handleBlur = (event) => {
|
|
@@ -56,11 +56,11 @@ export const CalendarInput = ({ selectedDate, onSelect: parentOnSelect, }) => {
|
|
|
56
56
|
onSelect(new Date(`${month}-${day}-${year}`));
|
|
57
57
|
};
|
|
58
58
|
const handleCancel = () => {
|
|
59
|
-
setComponentSelectedDate(selectedDate.toDateString());
|
|
59
|
+
setComponentSelectedDate(selectedDate?.toDateString() || new Date().toDateString());
|
|
60
60
|
setShow(false);
|
|
61
61
|
};
|
|
62
62
|
const calendar = buildCalendar(new Date(displayDate).getMonth() + 1, new Date(displayDate).getFullYear());
|
|
63
|
-
const [month, day, year] = selectedDate
|
|
63
|
+
const [month, day, year] = (selectedDate || new Date())
|
|
64
64
|
.toLocaleString('default', {
|
|
65
65
|
year: '2-digit',
|
|
66
66
|
month: '2-digit',
|
|
@@ -69,7 +69,7 @@ export const CalendarInput = ({ selectedDate, onSelect: parentOnSelect, }) => {
|
|
|
69
69
|
.split('/');
|
|
70
70
|
return (React.createElement(Wrapper, { onBlurCapture: handleBlur, ref: pickerRef, tabIndex: 0 },
|
|
71
71
|
React.createElement(InputWrapper, null,
|
|
72
|
-
React.createElement(Input, { value: `${month} / ${day} / ${year}
|
|
72
|
+
React.createElement(Input, { value: selectedDate ? `${month} / ${day} / ${year}` : '', onFocus: handleShow, style: { letterSpacing: '1px', fontSize: '16px' }, readOnly: true }),
|
|
73
73
|
React.createElement(CalendarIcon, null)),
|
|
74
74
|
show && (React.createElement(DateSelector, null,
|
|
75
75
|
React.createElement(InnerWrapper, null,
|