@daryasidorovich/modsen-datepicker 1.0.0 → 1.0.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.
- package/.prettierrc +6 -6
- package/.storybook/main.js +93 -93
- package/.storybook/main.ts +16 -0
- package/.storybook/preview.js +26 -26
- package/.storybook/preview.tsx +18 -18
- package/README.md +5 -5
- package/commitlint.config.js +23 -23
- package/package.json +1 -1
- package/rollup.config.js +65 -65
- package/src/components/BaseCalendar/BaseCalendar.stories.tsx +77 -77
- package/src/components/BaseCalendar/index.tsx +63 -63
- package/src/components/BaseCalendar/styles.module.scss +15 -15
- package/src/components/Button/Button.stories.tsx +16 -0
- package/src/components/Button/Button.tsx +14 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/Button/styles.module.scss +3 -0
- package/src/components/CalendarGrid/CalendarGrid.stories.tsx +136 -136
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +27 -27
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +9 -9
- package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +51 -51
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +36 -36
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +11 -11
- package/src/components/CalendarGrid/index.tsx +19 -19
- package/src/components/CalendarGrid/types.ts +26 -26
- package/src/components/Clear/Clear.stories.tsx +16 -16
- package/src/components/Clear/index.tsx +12 -12
- package/src/components/Clear/styles.module.scss +34 -34
- package/src/components/DatePicker/DatePicker.stories.tsx +127 -127
- package/src/components/DatePicker/index.tsx +72 -72
- package/src/components/DatePicker/styles.module.scss +10 -10
- package/src/components/Day/Day.stories.tsx +75 -75
- package/src/components/Day/index.tsx +95 -95
- package/src/components/Day/styles.module.scss +97 -97
- package/src/components/Input/Input.stories.tsx +37 -37
- package/src/components/Input/index.tsx +64 -64
- package/src/components/Input/styles.module.scss +79 -79
- package/src/components/Modal/CrudModal/index.tsx +43 -43
- package/src/components/Modal/CrudModal/styles.module.scss +44 -44
- package/src/components/Modal/index.tsx +66 -66
- package/src/components/Modal/styles.module.scss +40 -40
- package/src/components/Modal/types.ts +13 -13
- package/src/components/Month/Month.stories.tsx +19 -19
- package/src/components/Month/index.tsx +31 -31
- package/src/components/Month/styles.module.scss +30 -30
- package/src/components/RangePicker/RangePicker.stories.tsx +134 -134
- package/src/components/RangePicker/index.tsx +144 -144
- package/src/components/RangePicker/styles.module.scss +19 -19
- package/src/components/TasksManager/AddModal/index.tsx +62 -62
- package/src/components/TasksManager/DeleteModal/index.tsx +22 -22
- package/src/components/TasksManager/EditModal/index.tsx +96 -96
- package/src/components/TasksManager/index.tsx +112 -112
- package/src/components/TasksManager/styles.module.scss +62 -62
- package/src/components/Week/Week.stories.tsx +49 -49
- package/src/components/Week/index.tsx +68 -68
- package/src/components/Week/styles.module.scss +7 -7
- package/src/components/WeekDay/WeekDay.stories.tsx +38 -38
- package/src/components/WeekDay/index.tsx +35 -35
- package/src/components/WeekDay/styles.module.scss +19 -19
- package/src/constants/dateMask.ts +23 -23
- package/src/constants/firstDayOfWeek.ts +7 -7
- package/src/constants/holidays.ts +32 -32
- package/src/constants/modes.ts +6 -6
- package/src/constants/monthsNames.ts +14 -14
- package/src/constants/weekdaysNames.ts +1 -1
- package/src/hooks/useCalendar.ts +62 -62
- package/src/hooks/useLockBodyScroll.ts +19 -19
- package/src/hooks/useModal.ts +45 -45
- package/src/hooks/useTooltip.ts +41 -41
- package/src/hooks/useValidate.ts +80 -80
- package/src/index.ts +15 -15
- package/src/services/calendarService.ts +62 -62
- package/src/services/decorators/withHolidays.ts +12 -12
- package/src/services/decorators/withMinMax.test.ts +77 -77
- package/src/services/decorators/withMinMax.ts +19 -19
- package/src/services/holidayService.ts +56 -56
- package/src/store/localStorage.ts +33 -33
- package/src/store/tasksStore.tsx +146 -146
- package/src/store/types.ts +22 -22
- package/src/stories/Button.stories.ts +54 -0
- package/src/stories/Button.tsx +37 -0
- package/src/stories/Configure.mdx +388 -0
- package/src/stories/Header.stories.ts +34 -0
- package/src/stories/Header.tsx +56 -0
- package/src/stories/Page.stories.ts +33 -0
- package/src/stories/Page.tsx +73 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +1 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +1 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +1 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +1 -0
- package/src/stories/assets/youtube.svg +1 -0
- package/src/stories/button.css +30 -0
- package/src/stories/header.css +32 -0
- package/src/stories/page.css +68 -0
- package/src/styles/_border.scss +9 -9
- package/src/styles/_colors.scss +53 -53
- package/src/styles/_gap.scss +4 -4
- package/src/styles/_globals.scss +61 -61
- package/src/styles/_grid.scss +9 -9
- package/src/styles/_mixins.scss +6 -6
- package/src/styles/_reset.scss +98 -98
- package/src/styles/_theme-mixins.scss +51 -51
- package/src/styles/_typography.scss +10 -10
- package/src/styles/_variables.scss +8 -8
- package/src/styles/main.scss +3 -3
- package/src/types/types.d.ts +15 -15
- package/src/utils/calendar.test.ts +154 -154
- package/src/utils/calendar.ts +82 -82
- package/src/utils/controlDate.ts +3 -3
- package/src/utils/dateChecks.test.ts +216 -216
- package/src/utils/dateChecks.ts +75 -75
- package/src/utils/formatDate.ts +27 -27
- package/src/utils/schema.test.ts +40 -40
- package/src/utils/schema.ts +8 -8
- package/src/utils/weekdayOrder.test.ts +11 -11
- package/src/utils/weekdayOrder.ts +7 -7
- package/vitest.config.ts +38 -38
- package/vitest.shims.d.ts +1 -1
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
|
|
3
|
-
import { isToday } from '@/utils/dateChecks';
|
|
4
|
-
|
|
5
|
-
import styles from './styles.module.scss';
|
|
6
|
-
|
|
7
|
-
export interface DayProps {
|
|
8
|
-
date: Date;
|
|
9
|
-
isSelected?: boolean;
|
|
10
|
-
isDisabled?: boolean;
|
|
11
|
-
isHoliday?: boolean;
|
|
12
|
-
hasTasks?: boolean;
|
|
13
|
-
isRangeStart?: boolean;
|
|
14
|
-
isRangeEnd?: boolean;
|
|
15
|
-
isRangeMiddle?: boolean;
|
|
16
|
-
isCurrentMonth: boolean;
|
|
17
|
-
onClick?: (e: React.MouseEvent<HTMLButtonElement>, date: Date) => void;
|
|
18
|
-
onDoubleClick?: (date: Date) => void;
|
|
19
|
-
onMouseEnter?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
20
|
-
onMouseLeave?: () => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const Day = ({
|
|
24
|
-
date,
|
|
25
|
-
isSelected = false,
|
|
26
|
-
isCurrentMonth,
|
|
27
|
-
isDisabled = false,
|
|
28
|
-
isHoliday = false,
|
|
29
|
-
hasTasks = false,
|
|
30
|
-
isRangeStart = false,
|
|
31
|
-
isRangeEnd = false,
|
|
32
|
-
isRangeMiddle = false,
|
|
33
|
-
onClick,
|
|
34
|
-
onDoubleClick,
|
|
35
|
-
onMouseEnter,
|
|
36
|
-
onMouseLeave,
|
|
37
|
-
}: DayProps) => {
|
|
38
|
-
const dayNumber = date.getDate();
|
|
39
|
-
let clickTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
40
|
-
|
|
41
|
-
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
42
|
-
if (clickTimeout) {
|
|
43
|
-
clearTimeout(clickTimeout);
|
|
44
|
-
}
|
|
45
|
-
clickTimeout = setTimeout(() => {
|
|
46
|
-
if (!isDisabled && onClick) {
|
|
47
|
-
onClick(e, date);
|
|
48
|
-
}
|
|
49
|
-
clickTimeout = null;
|
|
50
|
-
}, 250);
|
|
51
|
-
};
|
|
52
|
-
const handleDoubleClick = () => {
|
|
53
|
-
if (clickTimeout) {
|
|
54
|
-
clearTimeout(clickTimeout);
|
|
55
|
-
}
|
|
56
|
-
if (!isDisabled && onDoubleClick) {
|
|
57
|
-
onDoubleClick(date);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const handleMouseEnter = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
62
|
-
if (!isDisabled && onMouseEnter) {
|
|
63
|
-
onMouseEnter(e);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const handleMouseLeave = () => {
|
|
68
|
-
if (!isDisabled && onMouseLeave) {
|
|
69
|
-
onMouseLeave();
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<button
|
|
75
|
-
className={classNames(styles.day, {
|
|
76
|
-
[styles.today]: isToday(date),
|
|
77
|
-
[styles.selected]: isSelected,
|
|
78
|
-
[styles.disabled]: isDisabled,
|
|
79
|
-
[styles.holiday]: isHoliday,
|
|
80
|
-
[styles.hasTasks]: hasTasks,
|
|
81
|
-
[styles.rangeStart]: isRangeStart,
|
|
82
|
-
[styles.rangeEnd]: isRangeEnd,
|
|
83
|
-
[styles.rangeMiddle]: isRangeMiddle,
|
|
84
|
-
[styles.otherMonth]: !isCurrentMonth,
|
|
85
|
-
})}
|
|
86
|
-
onClick={handleClick}
|
|
87
|
-
onDoubleClick={handleDoubleClick}
|
|
88
|
-
onMouseEnter={handleMouseEnter}
|
|
89
|
-
onMouseLeave={handleMouseLeave}
|
|
90
|
-
disabled={isDisabled}
|
|
91
|
-
>
|
|
92
|
-
<span className={styles.number}>{dayNumber}</span>
|
|
93
|
-
</button>
|
|
94
|
-
);
|
|
95
|
-
};
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
|
|
3
|
+
import { isToday } from '@/utils/dateChecks';
|
|
4
|
+
|
|
5
|
+
import styles from './styles.module.scss';
|
|
6
|
+
|
|
7
|
+
export interface DayProps {
|
|
8
|
+
date: Date;
|
|
9
|
+
isSelected?: boolean;
|
|
10
|
+
isDisabled?: boolean;
|
|
11
|
+
isHoliday?: boolean;
|
|
12
|
+
hasTasks?: boolean;
|
|
13
|
+
isRangeStart?: boolean;
|
|
14
|
+
isRangeEnd?: boolean;
|
|
15
|
+
isRangeMiddle?: boolean;
|
|
16
|
+
isCurrentMonth: boolean;
|
|
17
|
+
onClick?: (e: React.MouseEvent<HTMLButtonElement>, date: Date) => void;
|
|
18
|
+
onDoubleClick?: (date: Date) => void;
|
|
19
|
+
onMouseEnter?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
20
|
+
onMouseLeave?: () => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const Day = ({
|
|
24
|
+
date,
|
|
25
|
+
isSelected = false,
|
|
26
|
+
isCurrentMonth,
|
|
27
|
+
isDisabled = false,
|
|
28
|
+
isHoliday = false,
|
|
29
|
+
hasTasks = false,
|
|
30
|
+
isRangeStart = false,
|
|
31
|
+
isRangeEnd = false,
|
|
32
|
+
isRangeMiddle = false,
|
|
33
|
+
onClick,
|
|
34
|
+
onDoubleClick,
|
|
35
|
+
onMouseEnter,
|
|
36
|
+
onMouseLeave,
|
|
37
|
+
}: DayProps) => {
|
|
38
|
+
const dayNumber = date.getDate();
|
|
39
|
+
let clickTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
40
|
+
|
|
41
|
+
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
42
|
+
if (clickTimeout) {
|
|
43
|
+
clearTimeout(clickTimeout);
|
|
44
|
+
}
|
|
45
|
+
clickTimeout = setTimeout(() => {
|
|
46
|
+
if (!isDisabled && onClick) {
|
|
47
|
+
onClick(e, date);
|
|
48
|
+
}
|
|
49
|
+
clickTimeout = null;
|
|
50
|
+
}, 250);
|
|
51
|
+
};
|
|
52
|
+
const handleDoubleClick = () => {
|
|
53
|
+
if (clickTimeout) {
|
|
54
|
+
clearTimeout(clickTimeout);
|
|
55
|
+
}
|
|
56
|
+
if (!isDisabled && onDoubleClick) {
|
|
57
|
+
onDoubleClick(date);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const handleMouseEnter = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
62
|
+
if (!isDisabled && onMouseEnter) {
|
|
63
|
+
onMouseEnter(e);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const handleMouseLeave = () => {
|
|
68
|
+
if (!isDisabled && onMouseLeave) {
|
|
69
|
+
onMouseLeave();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<button
|
|
75
|
+
className={classNames(styles.day, {
|
|
76
|
+
[styles.today]: isToday(date),
|
|
77
|
+
[styles.selected]: isSelected,
|
|
78
|
+
[styles.disabled]: isDisabled,
|
|
79
|
+
[styles.holiday]: isHoliday,
|
|
80
|
+
[styles.hasTasks]: hasTasks,
|
|
81
|
+
[styles.rangeStart]: isRangeStart,
|
|
82
|
+
[styles.rangeEnd]: isRangeEnd,
|
|
83
|
+
[styles.rangeMiddle]: isRangeMiddle,
|
|
84
|
+
[styles.otherMonth]: !isCurrentMonth,
|
|
85
|
+
})}
|
|
86
|
+
onClick={handleClick}
|
|
87
|
+
onDoubleClick={handleDoubleClick}
|
|
88
|
+
onMouseEnter={handleMouseEnter}
|
|
89
|
+
onMouseLeave={handleMouseLeave}
|
|
90
|
+
disabled={isDisabled}
|
|
91
|
+
>
|
|
92
|
+
<span className={styles.number}>{dayNumber}</span>
|
|
93
|
+
</button>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
.day {
|
|
2
|
-
@include square(32px);
|
|
3
|
-
|
|
4
|
-
@include themify-modules($themes) {
|
|
5
|
-
background-color: themed('background');
|
|
6
|
-
color: themed('text');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
font-size: $font-size-13;
|
|
10
|
-
padding: $gap-10;
|
|
11
|
-
border-radius: $radius-8;
|
|
12
|
-
display: flex;
|
|
13
|
-
align-items: center;
|
|
14
|
-
justify-content: center;
|
|
15
|
-
font-weight: $font-weight-semibold;
|
|
16
|
-
border: none;
|
|
17
|
-
position: relative;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.holiday {
|
|
21
|
-
@include themify-modules($themes) {
|
|
22
|
-
color: themed('accent');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.today {
|
|
27
|
-
@include themify-modules($themes) {
|
|
28
|
-
color: themed('selected');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.selected {
|
|
33
|
-
@include themify-modules($themes) {
|
|
34
|
-
background-color: themed('selected');
|
|
35
|
-
color: themed('white-color');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.disabled {
|
|
40
|
-
@include themify-modules($themes) {
|
|
41
|
-
color: themed('disabled');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
cursor: not-allowed;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.otherMonth {
|
|
48
|
-
@include themify-modules($themes) {
|
|
49
|
-
color: themed('disabled');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.rangeStart {
|
|
54
|
-
@include themify-modules($themes) {
|
|
55
|
-
color: themed('white-color');
|
|
56
|
-
background-color: themed('middle-blue');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
border-top-right-radius: 0;
|
|
60
|
-
border-bottom-right-radius: 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.rangeMiddle {
|
|
64
|
-
@include themify-modules($themes) {
|
|
65
|
-
color: themed('blue');
|
|
66
|
-
background-color: themed('light-blue');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
border-radius: 0;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.rangeEnd {
|
|
73
|
-
@include themify-modules($themes) {
|
|
74
|
-
color: themed('white-color');
|
|
75
|
-
background-color: themed('selected');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
border-top-left-radius: 0;
|
|
79
|
-
border-bottom-left-radius: 0;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.hasTasks {
|
|
83
|
-
position: relative;
|
|
84
|
-
&::after {
|
|
85
|
-
@include square(4px);
|
|
86
|
-
|
|
87
|
-
@include themify-modules($themes) {
|
|
88
|
-
background-color: themed('marker');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
content: '';
|
|
92
|
-
position: absolute;
|
|
93
|
-
top: 12%;
|
|
94
|
-
right: 12%;
|
|
95
|
-
border-radius: 100%;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
1
|
+
.day {
|
|
2
|
+
@include square(32px);
|
|
3
|
+
|
|
4
|
+
@include themify-modules($themes) {
|
|
5
|
+
background-color: themed('background');
|
|
6
|
+
color: themed('text');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
font-size: $font-size-13;
|
|
10
|
+
padding: $gap-10;
|
|
11
|
+
border-radius: $radius-8;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
font-weight: $font-weight-semibold;
|
|
16
|
+
border: none;
|
|
17
|
+
position: relative;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.holiday {
|
|
21
|
+
@include themify-modules($themes) {
|
|
22
|
+
color: themed('accent');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.today {
|
|
27
|
+
@include themify-modules($themes) {
|
|
28
|
+
color: themed('selected');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.selected {
|
|
33
|
+
@include themify-modules($themes) {
|
|
34
|
+
background-color: themed('selected');
|
|
35
|
+
color: themed('white-color');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.disabled {
|
|
40
|
+
@include themify-modules($themes) {
|
|
41
|
+
color: themed('disabled');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
cursor: not-allowed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.otherMonth {
|
|
48
|
+
@include themify-modules($themes) {
|
|
49
|
+
color: themed('disabled');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.rangeStart {
|
|
54
|
+
@include themify-modules($themes) {
|
|
55
|
+
color: themed('white-color');
|
|
56
|
+
background-color: themed('middle-blue');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
border-top-right-radius: 0;
|
|
60
|
+
border-bottom-right-radius: 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.rangeMiddle {
|
|
64
|
+
@include themify-modules($themes) {
|
|
65
|
+
color: themed('blue');
|
|
66
|
+
background-color: themed('light-blue');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
border-radius: 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.rangeEnd {
|
|
73
|
+
@include themify-modules($themes) {
|
|
74
|
+
color: themed('white-color');
|
|
75
|
+
background-color: themed('selected');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
border-top-left-radius: 0;
|
|
79
|
+
border-bottom-left-radius: 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.hasTasks {
|
|
83
|
+
position: relative;
|
|
84
|
+
&::after {
|
|
85
|
+
@include square(4px);
|
|
86
|
+
|
|
87
|
+
@include themify-modules($themes) {
|
|
88
|
+
background-color: themed('marker');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
content: '';
|
|
92
|
+
position: absolute;
|
|
93
|
+
top: 12%;
|
|
94
|
+
right: 12%;
|
|
95
|
+
border-radius: 100%;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { Input } from '.';
|
|
3
|
-
|
|
4
|
-
const meta: Meta<typeof Input> = {
|
|
5
|
-
component: Input,
|
|
6
|
-
parameters: {
|
|
7
|
-
layout: 'centered',
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export default meta;
|
|
12
|
-
|
|
13
|
-
type Story = StoryObj<typeof Input>;
|
|
14
|
-
|
|
15
|
-
export const Default: Story = {
|
|
16
|
-
args: {
|
|
17
|
-
label: 'Title',
|
|
18
|
-
placeholder: 'Enter title',
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const DefaultDate: Story = {
|
|
23
|
-
args: {
|
|
24
|
-
label: 'Date',
|
|
25
|
-
placeholder: 'Date input...',
|
|
26
|
-
isDateInput: true,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const WithError: Story = {
|
|
31
|
-
args: {
|
|
32
|
-
label: 'Date',
|
|
33
|
-
value: '45',
|
|
34
|
-
error: 'Invalid date',
|
|
35
|
-
isDateInput: true,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Input } from '.';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Input> = {
|
|
5
|
+
component: Input,
|
|
6
|
+
parameters: {
|
|
7
|
+
layout: 'centered',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default meta;
|
|
12
|
+
|
|
13
|
+
type Story = StoryObj<typeof Input>;
|
|
14
|
+
|
|
15
|
+
export const Default: Story = {
|
|
16
|
+
args: {
|
|
17
|
+
label: 'Title',
|
|
18
|
+
placeholder: 'Enter title',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const DefaultDate: Story = {
|
|
23
|
+
args: {
|
|
24
|
+
label: 'Date',
|
|
25
|
+
placeholder: 'Date input...',
|
|
26
|
+
isDateInput: true,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const WithError: Story = {
|
|
31
|
+
args: {
|
|
32
|
+
label: 'Date',
|
|
33
|
+
value: '45',
|
|
34
|
+
error: 'Invalid date',
|
|
35
|
+
isDateInput: true,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import Calendar from '@assets/input/Calendar.svg?react';
|
|
2
|
-
import Clear from '@assets/input/Clear.svg?react';
|
|
3
|
-
import classNames from 'classnames';
|
|
4
|
-
import { InputHTMLAttributes, Ref, useId } from 'react';
|
|
5
|
-
|
|
6
|
-
import styles from './styles.module.scss';
|
|
7
|
-
|
|
8
|
-
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
9
|
-
label?: string;
|
|
10
|
-
error?: string;
|
|
11
|
-
onReset?: () => void;
|
|
12
|
-
ref?: Ref<HTMLInputElement>;
|
|
13
|
-
isDateInput?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const Input = ({
|
|
17
|
-
label,
|
|
18
|
-
error,
|
|
19
|
-
className = '',
|
|
20
|
-
id,
|
|
21
|
-
onReset,
|
|
22
|
-
placeholder,
|
|
23
|
-
type = 'text',
|
|
24
|
-
isDateInput = false,
|
|
25
|
-
ref = null,
|
|
26
|
-
...restProps
|
|
27
|
-
}: InputProps) => {
|
|
28
|
-
const generatedId = useId();
|
|
29
|
-
const inputId = id || `input-${generatedId}`;
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div className={styles.wrapper}>
|
|
33
|
-
{label && (
|
|
34
|
-
<label htmlFor={inputId} className={styles.label}>
|
|
35
|
-
{label}
|
|
36
|
-
</label>
|
|
37
|
-
)}
|
|
38
|
-
|
|
39
|
-
<div
|
|
40
|
-
className={classNames(styles.inputWrapper, {
|
|
41
|
-
[styles.errorWrapper]: error,
|
|
42
|
-
})}
|
|
43
|
-
>
|
|
44
|
-
{isDateInput && <Calendar className={styles.icon} />}
|
|
45
|
-
<input
|
|
46
|
-
id={inputId}
|
|
47
|
-
type={type}
|
|
48
|
-
ref={ref}
|
|
49
|
-
placeholder={placeholder}
|
|
50
|
-
className={classNames(styles.input, className)}
|
|
51
|
-
{...restProps}
|
|
52
|
-
/>
|
|
53
|
-
|
|
54
|
-
{isDateInput && onReset && (
|
|
55
|
-
<button className={styles.clear} onClick={onReset} type="button">
|
|
56
|
-
<Clear className={styles.icon} />
|
|
57
|
-
</button>
|
|
58
|
-
)}
|
|
59
|
-
</div>
|
|
60
|
-
|
|
61
|
-
<span className={styles.error}>{error ?? ''}</span>
|
|
62
|
-
</div>
|
|
63
|
-
);
|
|
64
|
-
};
|
|
1
|
+
import Calendar from '@assets/input/Calendar.svg?react';
|
|
2
|
+
import Clear from '@assets/input/Clear.svg?react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { InputHTMLAttributes, Ref, useId } from 'react';
|
|
5
|
+
|
|
6
|
+
import styles from './styles.module.scss';
|
|
7
|
+
|
|
8
|
+
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
9
|
+
label?: string;
|
|
10
|
+
error?: string;
|
|
11
|
+
onReset?: () => void;
|
|
12
|
+
ref?: Ref<HTMLInputElement>;
|
|
13
|
+
isDateInput?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Input = ({
|
|
17
|
+
label,
|
|
18
|
+
error,
|
|
19
|
+
className = '',
|
|
20
|
+
id,
|
|
21
|
+
onReset,
|
|
22
|
+
placeholder,
|
|
23
|
+
type = 'text',
|
|
24
|
+
isDateInput = false,
|
|
25
|
+
ref = null,
|
|
26
|
+
...restProps
|
|
27
|
+
}: InputProps) => {
|
|
28
|
+
const generatedId = useId();
|
|
29
|
+
const inputId = id || `input-${generatedId}`;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className={styles.wrapper}>
|
|
33
|
+
{label && (
|
|
34
|
+
<label htmlFor={inputId} className={styles.label}>
|
|
35
|
+
{label}
|
|
36
|
+
</label>
|
|
37
|
+
)}
|
|
38
|
+
|
|
39
|
+
<div
|
|
40
|
+
className={classNames(styles.inputWrapper, {
|
|
41
|
+
[styles.errorWrapper]: error,
|
|
42
|
+
})}
|
|
43
|
+
>
|
|
44
|
+
{isDateInput && <Calendar className={styles.icon} />}
|
|
45
|
+
<input
|
|
46
|
+
id={inputId}
|
|
47
|
+
type={type}
|
|
48
|
+
ref={ref}
|
|
49
|
+
placeholder={placeholder}
|
|
50
|
+
className={classNames(styles.input, className)}
|
|
51
|
+
{...restProps}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
{isDateInput && onReset && (
|
|
55
|
+
<button className={styles.clear} onClick={onReset} type="button">
|
|
56
|
+
<Clear className={styles.icon} />
|
|
57
|
+
</button>
|
|
58
|
+
)}
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<span className={styles.error}>{error ?? ''}</span>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
};
|