Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datepicker #42

Merged
merged 39 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
467a5b2
WIP DatePicker
nighto Nov 27, 2024
ce1663b
Overwriting react-datepicker styling with global selector
nighto Nov 28, 2024
edd1712
Improve calendar layout matching Figma; missing hover styles and some…
nighto Dec 2, 2024
1f7bb96
Update colors
nighto Dec 3, 2024
e5e749e
Fix hover styling, add range story
nighto Dec 5, 2024
6ddde14
Use out Input component as DatePicker's Input
nighto Dec 6, 2024
b7c83d6
Remove type ComponentPropsWithoutRef
nighto Dec 6, 2024
6c1ea5a
Separate DatePicker and DatePickerRange
nighto Dec 6, 2024
1f22ccb
fix datepicker story onChange signature
nighto Dec 6, 2024
2c51a63
add date output to stories
nighto Dec 10, 2024
9dd613a
Merge branch 'master' into datepicker
nighto Dec 10, 2024
0ec4aa1
TimePicker component
nighto Dec 10, 2024
46f77cc
Add override for react-datepicker peer dependencies.
Dec 10, 2024
5c8a844
Update DatePicker: fix type errors.
Dec 10, 2024
1402ad5
Code Review fixes + linting
nighto Dec 10, 2024
5f98a61
build fix
nighto Dec 10, 2024
a59b77c
add missing export to lib.ts
nighto Dec 10, 2024
d5aa79d
Simplify timepicker to use string and fix typing
nighto Dec 10, 2024
49a248d
new component DateTimePicker
nighto Dec 11, 2024
55523ad
Adding JSDoc
nighto Dec 11, 2024
8e9132d
Merge branch 'master' into datepicker
nighto Dec 11, 2024
660a0e3
adds calendar icon
nighto Dec 12, 2024
f7d3568
Adds caret to DatePicker
nighto Dec 12, 2024
6b6affd
Minor CSS adjustments on the three elements
nighto Dec 12, 2024
5d9240b
fix stylelint minor issue
nighto Dec 12, 2024
5434d41
Code Review fixes
nighto Dec 12, 2024
b248aa0
Code Review fixes
nighto Dec 13, 2024
7d63e83
Code Review: refactor CSS classes to kebab-case
nighto Dec 13, 2024
7c05944
Code Review: add dateFormat and placeholderText as variables
nighto Dec 13, 2024
3401552
Code Review: wrap the function body in a block
nighto Dec 13, 2024
2f12069
Code Review: remove unused color rule
nighto Dec 13, 2024
1273330
Code Review: move z-index variable to variables.scss
nighto Dec 13, 2024
409cda8
Click on caret to open and close the date picker
nighto Dec 16, 2024
6ff5e22
Workaround on a react-datepicker bug
nighto Dec 17, 2024
0d1b496
Separate components and global rules
nighto Dec 17, 2024
8b45337
Code Review: dateFormat and placeholderText should be optional
nighto Dec 18, 2024
47d7a99
Change TimePicker width to rem
nighto Dec 18, 2024
351d0a8
Fix datepicker caret image url
nighto Dec 18, 2024
7ac4cd4
Define rem-from-px function and use it on all pickers
nighto Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ export { SubmitButton } from '../src/components/forms/context/SubmitButton/Submi

// Forms > Controls
export { Checkbox } from '../src/components/forms/controls/Checkbox/Checkbox.tsx';
export { DatePicker } from '../src/components/forms/controls/DatePicker/DatePicker.tsx';
export { DatePickerRange } from '../src/components/forms/controls/DatePicker/DatePickerRange.tsx';
export { Input } from '../src/components/forms/controls/Input/Input.tsx';
export { Radio } from '../src/components/forms/controls/Radio/Radio.tsx';
export { SegmentedControl } from '../src/components/forms/controls/SegmentedControl/SegmentedControl.tsx';
export { Select } from '../src/components/forms/controls/Select/Select.tsx';
export { Switch } from '../src/components/forms/controls/Switch/Switch.tsx';
export { TimePicker } from '../src/components/forms/controls/TimePicker/TimePicker.tsx';

// Forms > Fields
export { CheckboxField } from '../src/components/forms/fields/CheckboxField/CheckboxField.tsx';
export { CheckboxGroup } from '../src/components/forms/fields/CheckboxGroup/CheckboxGroup.tsx';
export { InputField } from '../src/components/forms/fields/InputField/InputField.tsx';
export { InputFieldWithTags } from '../src/components/forms/fields/InputFieldWithTags/InputFieldWithTags.tsx';
export { RadioField } from '../src/components/forms/fields/RadioField/RadioField.tsx';
export { RadioGroup } from '../src/components/forms/fields/RadioGroup/RadioGroup.tsx';

Expand Down
49 changes: 45 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"react-toastify": "^10.0.6",
"effect": "^3.11.3",
"react-hook-form": "^7.54.0",
"optics-ts": "^2.4.1"
"optics-ts": "^2.4.1",
"react-datepicker": "^7.5.0"
},
"peerDependencies": {
"react": ">= 19.0.0",
Expand All @@ -119,6 +120,10 @@
"@storybook/icons": {
"react": "$react",
"react-dom": "$react-dom"
},
"react-datepicker": {
"react": "$react",
"react-dom": "$react-dom"
}
}
}
6 changes: 6 additions & 0 deletions package.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const packageConfig = {
'react-hook-form': '^7.54.0',

'optics-ts': '^2.4.1',
"react-datepicker": "^7.5.0",
},
peerDependencies: {
'react': '>= 19.0.0',
Expand All @@ -172,6 +173,11 @@ const packageConfig = {
'react': '$react',
'react-dom': '$react-dom',
},
// Issue: https://github.com/Hacker0x01/react-datepicker/issues/5273
'react-datepicker': {
'react': '$react',
'react-dom': '$react-dom',
},
},
};

Expand Down
213 changes: 213 additions & 0 deletions src/components/forms/controls/DatePicker/DatePicker.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/* Copyright (c) Fortanix, Inc.
|* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
|* the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@use '../../../../styling/defs.scss' as bk;

// TODO: copied manually from old Baklava, where should we put this?
$z-index-date-picker: 100;
nighto marked this conversation as resolved.
Show resolved Hide resolved

// DATEPICKER override react-datepicker styles
// Note: Sass do not support using suffixes (i.e. &__suffix) when using global selector
:global(.react-datepicker-popper) {
z-index: $z-index-date-picker;
}

:global(.react-datepicker) {
width: 284px;
text-align: center;
padding: 22px 26px 30px;
background-color: bk.$theme-card-background-default;
border-radius: 6px;
border: 1px solid bk.$theme-card-border-default;
font-family: bk.$font-family-body;
font-size: bk.$font-size-m;
font-weight: bk.$font-weight-regular;
}

:global(.react-datepicker__triangle),
:global(.react-datepicker__triangle::before) {
display: none;
}

:global(.react-datepicker__header) {
background: transparent;
border: 0;
color: #081353; // TODO hardcoded color
nighto marked this conversation as resolved.
Show resolved Hide resolved
font-family: bk.$font-family-display;
font-weight: bk.$font-weight-regular;
}

:global(.react-datepicker__month-container) {
display: inline-block;
width: 100%;
float: none;
}

:global(.react-datepicker__current-month) {
color: bk.$theme-text-heading-default;
font-family: bk.$font-family-display;
font-size: 16px;
font-style: normal;
font-weight: bk.$font-weight-semibold;
text-transform: uppercase;
}

:global(.react-datepicker__navigation) {
position: absolute;
width: 3rem;
border: none;
text-indent: -999em;
mask: url('../../../../assets/icons/caret-down.svg') no-repeat center center;
mask-size: 32px;
background: bk.$theme-date-picker-text-default;
top: 1.8rem;
}
$navigation-distance: 1rem;
:global(.react-datepicker__navigation--previous) {
left: $navigation-distance;
transform: rotate(90deg);
}
:global(.react-datepicker__navigation--next) {
right: $navigation-distance;
transform: rotate(-90deg);
}
:global(.react-datepicker__navigation:hover) {
opacity: 0.7;
}
:global(.react-datepicker__navigation-icon) {
// original icon
display: none;
}

:global(.react-datepicker__day-names) {
border-bottom: 0.1rem solid bk.$theme-date-picker-rule-default;
}

:global(.react-datepicker__day-name),
:global(.react-datepicker__day) {
display: inline-block;
width: 30px;
line-height: 30px;
margin: 5px 0;
color: bk.$theme-date-picker-text-default;
}

:global(.react-datepicker__day--today) {
font-weight: bk.$font-weight-semibold;
}

:global(.react-datepicker__day--outside-month),
:global(.react-datepicker__day--disabled) {
color: bk.$theme-date-picker-text-disabled;
}

:global(.react-datepicker__day--outside-month.react-datepicker__day--disabled) {
color: bk.$theme-date-picker-text-unavailable;
}

:global(.react-datepicker__day--selected),
:global(.react-datepicker__day--keyboard-selected) {
background: bk.$theme-date-picker-background-selected;
border-radius: bk.$border-radius-circle;
color: bk.$theme-date-picker-text-selected;
}

:global(.react-datepicker__day:not([aria-disabled="true"]):hover),
:global(.react-datepicker__day--selected:not([aria-disabled="true"]):hover),
:global(.react-datepicker__day--keyboard-selected:not([aria-disabled="true"]):hover) {
background: bk.$theme-date-picker-background-hover;
border-radius: bk.$border-radius-circle;
color: bk.$theme-date-picker-text-hover;
}

:global(.react-datepicker__day--in-range),
:global(.react-datepicker__day--in-selecting-range:not(
.react-datepicker__month-text--in-range,
.react-datepicker__quarter-text--in-range,
.react-datepicker__year-text--in-range
)) {
background: bk.$theme-date-picker-background-selected;
border-radius: 0;
color: bk.$theme-date-picker-text-selected;
}
:global(.react-datepicker__day--in-range:not([aria-disabled="true"]):hover),
:global(.react-datepicker__day--in-selecting-range:not([aria-disabled="true"]):hover) {
background: bk.$theme-date-picker-background-hover;
border-radius: 0;
color: bk.$theme-date-picker-text-hover;
}

:global(.react-datepicker__day--range-start),
:global(.react-datepicker__day--selecting-range-start),
:global(.react-datepicker__day--range-start:not([aria-disabled="true"]):hover) {
border-radius: bk.$border-radius-circle 0 0 bk.$border-radius-circle;
}

:global(.react-datepicker__day--range-end),
:global(.react-datepicker__day--selecting-range-end),
:global(.react-datepicker__day--range-end:not([aria-disabled="true"]):hover) {
border-radius: 0 bk.$border-radius-circle bk.$border-radius-circle 0;
}

:global(.react-datepicker__day--range-start.react-datepicker__day--range-end),
:global(.react-datepicker__day--range-start.react-datepicker__day--range-end:not([aria-disabled="true"]):hover) {
border-radius: bk.$border-radius-circle;
}

/* stylelint-disable-next-line */
:global(.react-datepicker__day:not(&--selected):hover) {
nighto marked this conversation as resolved.
Show resolved Hide resolved
background: rgba(bk.$color-blueberry-500, 0.5); // TODO use proper variable
border-radius: 50%;
}

:global(.react-datepicker-popper[data-placement^="bottom"]) {
margin-top: 0;
}

:global(.react-datepicker-popper[data-placement^="top"]) {
margin-bottom: 0;
}

:global(.react-datepicker__month--selecting-range .react-datepicker__day--in-range:not(.react-datepicker__day--in-selecting-range)),
:global(.react-datepicker__month--selecting-range .react-datepicker__day--in-selecting-range:not(.react-datepicker__day--in-range)) {
background: transparent;
background-color: transparent;
border-radius: 0;
color: bk.$theme-date-picker-text-default;
}

:global(.react-datepicker__input-container .react-datepicker__calendar-icon) {
width: 14px;
height: 14px;
bottom: 4px;
}

:global(.react-datepicker__view-calendar-icon input) {
padding: 6px 10px 0 25px;
}

@layer baklava.components {
$caret-width: 18px;

.bk-datepicker {
@include bk.component-base(bk-datepicker);
display: flex;
flex-direction: row;
align-items: center;
margin-right: -$caret-width;
}

.bk-datepicker--input {
width: 121px;
color: bk.$theme-form-text-default;
}

.bk-datepicker--caret {
width: $caret-width;
height: $caret-width;
position: relative;
left: -$caret-width;
top: -1px;
}
}
Loading
Loading