Skip to content

Commit 3ac910b

Browse files
chore: improves datepicker styles and functionality (#2347)
Co-authored-by: Jarrod Flesch <[email protected]>
1 parent 60fca40 commit 3ac910b

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

src/admin/components/elements/DatePicker/DatePicker.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const DateTime: React.FC<Props> = (props) => {
1717
value,
1818
onChange,
1919
displayFormat,
20-
pickerAppearance,
20+
pickerAppearance = "dayOnly",
2121
minDate,
2222
maxDate,
2323
monthsToShow = 1,
@@ -98,6 +98,9 @@ const DateTime: React.FC<Props> = (props) => {
9898
enabled: true,
9999
},
100100
]}
101+
showMonthDropdown
102+
showYearDropdown
103+
dropdownMode="select"
101104
/>
102105
</div>
103106
</div>

src/admin/components/elements/DatePicker/index.scss

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ $cal-icon-width: 18px;
9999

100100
.react-datepicker {
101101
@include shadow-lg;
102+
border: 1px solid var(--theme-elevation-100);
102103
background: var(--theme-input-bg);
103104
display: inline-flex;
104-
border: none;
105105
font-family: var(--font-body);
106106
font-weight: 100;
107107
border-radius: 0;
@@ -169,8 +169,12 @@ $cal-icon-width: 18px;
169169
}
170170

171171
&__current-month {
172+
display: none;
173+
}
174+
175+
&__header__dropdown, &-year-header {
172176
padding: 10px 0;
173-
font-weight: 600;
177+
font-weight: bold;
174178
}
175179

176180
&__month-container {
@@ -185,6 +189,20 @@ $cal-icon-width: 18px;
185189
border-left: none;
186190
}
187191

192+
&__month-text {
193+
&:hover {
194+
background: var(--theme-elevation-100);
195+
}
196+
}
197+
198+
&__month-select,
199+
&__year-select {
200+
min-width: 70px;
201+
border: none;
202+
background: none;
203+
outline: none;
204+
cursor: pointer;
205+
}
188206

189207
&__day-names {
190208
background-color: var(--theme-elevation-100);
@@ -239,6 +257,10 @@ $cal-icon-width: 18px;
239257
border: none;
240258
}
241259

260+
.react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box ul.react-datepicker__time-list {
261+
max-height: 100%;
262+
}
263+
242264
.react-datepicker__day--keyboard-selected,
243265
.react-datepicker__month-text--keyboard-selected,
244266
.react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box ul.react-datepicker__time-list li.react-datepicker__time-list-item--selected {
@@ -281,7 +303,40 @@ $cal-icon-width: 18px;
281303
font-size: base(.5);
282304
}
283305

306+
&__appearance--dayOnly,
307+
&__appearance--monthOnly {
308+
.react-datepicker {
309+
&__month-container {
310+
border-right: none;
311+
}
312+
}
313+
}
314+
284315
@include small-break {
316+
.react-datepicker {
317+
flex-direction: column;
318+
}
319+
.react-datepicker__month-container {
320+
border-right: 0;
321+
}
322+
.react-datepicker__time-container {
323+
width: auto;
324+
}
325+
.react-datepicker__header--time {
326+
background-color: var(--theme-elevation-100);
327+
padding: 8px 0;
328+
border-bottom: none;
329+
}
330+
.react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box {
331+
height: 120px;
332+
width: unset;
333+
> ul {
334+
height: 120px;
335+
}
336+
}
337+
.react-datepicker__navigation--next--with-time:not(.react-datepicker__navigation--next--with-today-button) {
338+
right: 0px;
339+
}
285340
&__input-wrapper {
286341
.icon {
287342
top: calc(50% - #{base(.25)});

test/fields/collections/Date/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ const DateFields: CollectionConfig = {
1616
{
1717
name: 'timeOnly',
1818
type: 'date',
19+
admin: {
20+
date: {
21+
pickerAppearance: 'timeOnly',
22+
},
23+
},
24+
},
25+
{
26+
name: 'timeOnlyWithCustomFormat',
27+
type: 'date',
1928
admin: {
2029
date: {
2130
pickerAppearance: 'timeOnly',
@@ -56,6 +65,7 @@ const DateFields: CollectionConfig = {
5665
export const dateDoc = {
5766
default: '2022-08-12T10:00:00.000+00:00',
5867
timeOnly: '2022-08-12T10:00:00.157+00:00',
68+
timeOnlyWithCustomFormat: '2022-08-12T10:00:00.157+00:00',
5969
dayOnly: '2022-08-11T22:00:00.000+00:00',
6070
dayAndTime: '2022-08-12T10:00:00.052+00:00',
6171
monthOnly: '2022-07-31T22:00:00.000+00:00',

0 commit comments

Comments
 (0)