Skip to content

Commit 2ad5382

Browse files
committed
Core DatePicker Input Component
1 parent 9752ee6 commit 2ad5382

File tree

8 files changed

+255
-2
lines changed

8 files changed

+255
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.196",
3+
"version": "1.0.197",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {
@@ -150,6 +150,7 @@
150150
"prosemirror-state": "1.4.3",
151151
"react-colorful": "5.6.1",
152152
"react-copy-to-clipboard": "5.1.0",
153+
"react-datepicker": "7.5.0",
153154
"react-image-crop": "11.0.5",
154155
"react-select": "5.8.0",
155156
"react-select-async-paginate": "0.7.3",

pnpm-lock.yaml

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useState } from "react";
2+
3+
import DatePicker from ".";
4+
5+
export default {
6+
title: "Input/DatePicker",
7+
component: DatePicker,
8+
parameters: {
9+
layout: "centered"
10+
},
11+
argTypes: {
12+
onChange: { action: "changed" }
13+
}
14+
};
15+
16+
export const Default = () => {
17+
const [date, setDate] = useState(new Date());
18+
19+
return (
20+
<DatePicker
21+
name='datetime'
22+
selected={date}
23+
showTimeSelect
24+
timeCaption='Time'
25+
onChange={input => {
26+
if (!input.datetime) {
27+
return;
28+
}
29+
30+
setDate(input.datetime);
31+
}}
32+
/>
33+
);
34+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { FC } from "react";
2+
import BaseDatePicker from "react-datepicker";
3+
import "react-datepicker/dist/react-datepicker.css";
4+
5+
import InputHeader from "../Common/InputHeader";
6+
import "./style.css";
7+
import { IDatePickerProps } from "./types";
8+
9+
const DatePicker: FC<IDatePickerProps> = props => {
10+
const {
11+
selected = undefined,
12+
onChange,
13+
name,
14+
showTimeSelect,
15+
timeFormat = "HH:mm",
16+
timeCaption = "time",
17+
timeIntervals = 15,
18+
dateFormat = "MMMM d, yyyy h:mm aa"
19+
} = props;
20+
21+
const handleChange = (date: Date | null) => {
22+
if (!onChange) {
23+
throw new Error(`💣 Input is missing "onChange" handler 💣`);
24+
}
25+
26+
if (!name) {
27+
throw new Error('💣 Input is missing a "name" prop 💣');
28+
}
29+
30+
onChange?.({ [name]: date });
31+
};
32+
33+
return (
34+
<div className='yl-bg-primary-background-color'>
35+
<InputHeader {...props} />
36+
<BaseDatePicker
37+
selected={selected}
38+
onChange={handleChange}
39+
showTimeSelect={showTimeSelect}
40+
timeFormat={timeFormat}
41+
timeIntervals={timeIntervals}
42+
timeCaption={timeCaption}
43+
dateFormat={dateFormat}
44+
showPopperArrow={false}
45+
/>
46+
</div>
47+
);
48+
};
49+
50+
export default DatePicker;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* Global Rules -- Avoid Declaring These Globally */
2+
.react-datepicker * {
3+
/*
4+
This degrades the performance and accessibility of the date picker.
5+
TODO: Remove this line and explicitly target specific elements for hover, focus, etc.
6+
*/
7+
@apply yl-outline-none !important;
8+
}
9+
10+
/* Main Datepicker Container */
11+
.react-datepicker {
12+
@apply yl-select-none yl-border-2 yl-border-primary-text-color/20 yl-bg-primary-background-color yl-font-sans yl-shadow-lg !important;
13+
}
14+
15+
.react-datepicker,
16+
.react-datepicker__day {
17+
@apply yl-text-primary-text-color !important;
18+
}
19+
20+
/* Header Section */
21+
.react-datepicker__header {
22+
@apply yl-border-0 yl-bg-primary-background-color !important;
23+
}
24+
25+
.react-datepicker__current-month,
26+
.react-datepicker__day-name,
27+
.react-datepicker-time__header {
28+
@apply yl-text-primary-text-color !important;
29+
}
30+
31+
/* Month Container */
32+
.react-datepicker__month-container {
33+
@apply yl-bg-primary-background-color !important;
34+
}
35+
36+
/* Day Cell Styles */
37+
.react-datepicker__day:not([aria-disabled="true"]):hover {
38+
@apply yl-bg-primary yl-text-white !important;
39+
}
40+
41+
.react-datepicker__day--selected {
42+
@apply yl-bg-primary yl-text-white !important;
43+
}
44+
45+
.react-datepicker__day--keyboard-selected {
46+
@apply yl-bg-primary/70 yl-text-white !important;
47+
}
48+
49+
.react-datepicker__day--keyboard-selected:focus-visible {
50+
@apply yl-text-white yl-outline-primary-text-color !important;
51+
}
52+
53+
/* Time Picker Section */
54+
.react-datepicker__time-container {
55+
@apply yl-border-l-primary-text-color/20 yl-px-0 !important;
56+
}
57+
58+
.react-datepicker__time-container .react-datepicker__time {
59+
@apply yl-bg-primary-background-color !important;
60+
}
61+
62+
.react-datepicker__time-box {
63+
@apply yl-pl-1 !important;
64+
}
65+
66+
.react-datepicker__time-list-item--selected {
67+
@apply yl-bg-primary yl-font-normal yl-text-white !important;
68+
}
69+
70+
li.react-datepicker__time-list-item {
71+
@apply hover:yl-bg-primary hover:yl-text-white !important;
72+
}
73+
74+
/* Scrollbar Styles */
75+
.react-datepicker__time-list::-webkit-scrollbar {
76+
width: 5px;
77+
}
78+
79+
.react-datepicker__time-list::-webkit-scrollbar-track {
80+
background: "##";
81+
}
82+
83+
.react-datepicker__time-list::-webkit-scrollbar-thumb {
84+
background: rgb(var(--text-color));
85+
}
86+
87+
.react-datepicker__time-list::-webkit-scrollbar-thumb:hover {
88+
background: rgb(var(--text-color));
89+
}
90+
91+
/* Input Styles */
92+
.react-datepicker__input-container input {
93+
@apply yl-w-full yl-appearance-none yl-rounded-md yl-border-2 yl-border-primary-text-color yl-bg-transparent yl-p-2 yl-text-primary-text-color hover:yl-cursor-pointer hover:yl-border-primary focus:yl-border-primary focus:yl-outline-none focus:yl-ring-transparent !important;
94+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { InputHeaderProps } from "../Common/InputHeader/types";
2+
3+
export interface IDatePickerProps extends InputHeaderProps {
4+
selected?: Date;
5+
onChange: (value: Record<string, Date | null>) => void;
6+
timeFormat?: string;
7+
timeIntervals?: number;
8+
timeCaption?: string;
9+
dateFormat?: string;
10+
showTimeSelect?: boolean;
11+
}

src/Components/Inputs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export { default as Textarea } from "./Textarea";
1111
export { default as Tiptap } from "./Tiptap";
1212
export { default as TiptapToHTML } from "./Tiptap/TiptapToHTML";
1313
export { default as TiptapUtils } from "./Tiptap/TiptapUtils";
14+
export { default as DatePicker } from "./DatePicker";

src/Components/Inputs/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as AsyncSelectTypes from "./AsyncSelect/types";
22
import * as CheckboxTypes from "./Checkbox/types";
33
import * as CommonTypes from "./Common/types";
4+
import * as DatePickerTypes from "./DatePicker/types";
45
import * as DomainInputTypes from "./DomainInput/types";
56
import * as InputTypes from "./Input/types";
67
import * as SelectTypes from "./Select/types";
@@ -17,5 +18,6 @@ export {
1718
SelectTypes,
1819
SwitchTypes,
1920
TextareaTypes,
20-
TiptapTypes
21+
TiptapTypes,
22+
DatePickerTypes
2123
};

0 commit comments

Comments
 (0)