Skip to content

Commit

Permalink
ui-core: add close button to pickers
Browse files Browse the repository at this point in the history
- use the Modal component to display the calendar picker to harmonize with tolerance and time picker
- add a modal.css file with the modal base styles to avoid repeating the code
- add a close button to the Modal component

Signed-off-by: SharglutDev <[email protected]>
  • Loading branch information
SharglutDev committed Dec 19, 2024
1 parent b13f117 commit ab0f830
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 39 deletions.
5 changes: 5 additions & 0 deletions ui-core/src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useEffect, useRef } from 'react';

import { X } from '@osrd-project/ui-icons';

Check warning on line 3 in ui-core/src/components/Modal.tsx

View workflow job for this annotation

GitHub Actions / build

Unable to resolve path to module '@osrd-project/ui-icons'

Check warning on line 3 in ui-core/src/components/Modal.tsx

View workflow job for this annotation

GitHub Actions / build

Unable to resolve path to module '@osrd-project/ui-icons'

Check warning on line 3 in ui-core/src/components/Modal.tsx

View workflow job for this annotation

GitHub Actions / publish

Unable to resolve path to module '@osrd-project/ui-icons'

Check warning on line 3 in ui-core/src/components/Modal.tsx

View workflow job for this annotation

GitHub Actions / publish

Unable to resolve path to module '@osrd-project/ui-icons'

import { useModalPosition } from '../hooks/useModalPosition';
import useOutsideClick from '../hooks/useOutsideClick';

Expand Down Expand Up @@ -31,6 +33,9 @@ const InputModal = ({ inputRef, isOpen, onClose, children }: ModalProps) => {
className="modal-content"
style={{ top: modalPosition.top, left: modalPosition.left }}
>
<button className="close-button" onClick={onClose}>
<X size="lg" />
</button>
{children}
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions ui-core/src/components/inputs/datePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cx from 'classnames';
import { type CalendarSlot } from '.';
import CalendarPicker, { type CalendarPickerPublicProps } from './CalendarPicker';
import useDatePicker from './useDatePicker';
import InputModal from '../../Modal';
import Input, { type InputProps } from '../Input';

type BaseDatePickerProps = {
Expand Down Expand Up @@ -69,7 +70,7 @@ export const DatePicker = (props: DatePickerProps) => {
statusWithMessage={statusWithMessage}
/>
</div>
{showPicker && (
<InputModal inputRef={inputRef} isOpen={showPicker} onClose={() => setShowPicker(false)}>
<div className="calendar-picker-wrapper">
<CalendarPicker
{...props.calendarPickerProps}
Expand All @@ -80,7 +81,7 @@ export const DatePicker = (props: DatePickerProps) => {
selectableSlot={selectableSlot}
/>
</div>
)}
</InputModal>
</div>
);
};
Expand Down
7 changes: 0 additions & 7 deletions ui-core/src/styles/inputs/datePicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@
}

.calendar-picker {
position: absolute;
width: fit-content;
border-radius: 0.5rem;
box-shadow:
0 0.813rem 0.938rem -0.438rem rgba(31, 27, 23, 0.1),
0 0.188rem 0.375rem rgba(31, 27, 23, 0.2);
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
@apply bg-white-100;

.calendar-navigation-btn {
width: 2rem;
Expand Down
1 change: 1 addition & 0 deletions ui-core/src/styles/inputs/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
@import './timePicker.css';
@import './tokenInput.css';
@import './tolerancePicker.css';
@import './modal.css';
33 changes: 33 additions & 0 deletions ui-core/src/styles/inputs/modal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
}

.modal-content {
background-color: theme('colors.white.100');
border-radius: 0.5rem;
box-shadow:
0px 1px 0px rgba(255, 255, 255, 1) inset,
0px 4px 7px -3px rgba(24, 68, 239, 0.19),
0px 1px 3px rgba(49, 46, 43, 0.2);
position: absolute;

.close-button {
position: absolute;
top: 16px;
right: 16px;
color: theme('colors.grey.50');

&:hover {
color: theme('colors.grey.90');
}

&:active {
color: theme('colors.grey.20');
}
}
}
16 changes: 0 additions & 16 deletions ui-core/src/styles/inputs/timePicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,8 @@
display: none;
}

.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
}

.modal-content {
background-color: #fff;
padding: 4.563rem;
border-radius: 0.313rem;
box-shadow:
0px 1px 0px rgba(255, 255, 255, 1) inset,
0px 4px 7px -3px rgba(24, 68, 239, 0.19),
0px 1px 3px rgba(49, 46, 43, 0.2);
position: absolute;
}

.time-picker-container {
Expand Down
14 changes: 0 additions & 14 deletions ui-core/src/styles/inputs/tolerancePicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
}

.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;

.tolerance-picker-section {
display: flex;
gap: 1rem;
Expand Down Expand Up @@ -56,14 +49,7 @@
}

.modal-content {
background-color: #fff;
padding: 1.25rem;
border-radius: 0.313rem;
box-shadow:
0px 1px 0px rgba(255, 255, 255, 1) inset,
0px 4px 7px -3px rgba(24, 68, 239, 0.19),
0px 1px 3px rgba(49, 46, 43, 0.2);
position: absolute;
}

.time-picker-container {
Expand Down

0 comments on commit ab0f830

Please sign in to comment.