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

refactor: migrate Datepicker to popper positioning engine #378

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
33 changes: 0 additions & 33 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
"date-fns": "^2.11.1",
"nanoid": "^3.1.23",
"react-popper": "^2.3.0",
"react-tether": "^2.0.7",
"react-transition-group": "^4.3.0",
"react-windowed-select": "^4.0.0",
"styled-system": "^5.1.5",
Expand Down
22 changes: 4 additions & 18 deletions src/components/Datepicker/Datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import React, { FC, RefObject } from 'react';
import { useDatepicker, MonthType, UseDatepickerProps } from '@datepicker-react/hooks';
import styled from 'styled-components';

import { Colors, MediaQueries } from '../../essentials';
import { Elevation, MediaQueries, SemanticColors } from '../../essentials';
import { ChevronLeftIcon, ChevronRightIcon } from '../../icons';
import { Month } from './Month';
import { DatepickerContext } from './DatepickerContext';
import { GlobalDatepickerStyle } from './GlobalDatepickerStyle';

const DatepickerWrapper = styled.div<{
activeMonths: MonthType[];
Expand All @@ -20,22 +19,10 @@ const DatepickerWrapper = styled.div<{
const DatepickerContainer = styled.div`
display: flex;
padding: 0.5rem;
margin: 0.9375rem 0;
margin-left: -0.5rem;
box-shadow: 0 0 0.5rem 0.1875rem rgba(0, 0, 0, 0.08);

z-index: ${Elevation.DATEPICKER};
position: relative;
background: ${Colors.WHITE};

&::before {
content: '';
position: absolute;
transform: rotate(45deg);
width: 1.25rem;
height: 1.25rem;
background: ${Colors.WHITE};
box-shadow: -0.25rem -0.25rem 0.5rem -0.125rem rgba(0, 0, 0, 0.08);
}
background: ${SemanticColors.forms.datePicker.calendar.background};

${MediaQueries.small} {
padding: 1.5rem;
Expand Down Expand Up @@ -66,7 +53,7 @@ interface BaseDatepickerProps extends UseDatepickerProps {
locale: Locale;
}

export const BaseDatepicker: FC<BaseDatepickerProps> = ({
const BaseDatepicker: FC<BaseDatepickerProps> = ({
martimalek marked this conversation as resolved.
Show resolved Hide resolved
forwardedRef,
focusedInput,
locale,
Expand Down Expand Up @@ -105,7 +92,6 @@ export const BaseDatepicker: FC<BaseDatepickerProps> = ({
onDateHover
}}
>
<GlobalDatepickerStyle />
<DatepickerContainer
ref={forwardedRef}
onMouseDown={e => {
Expand Down
40 changes: 40 additions & 0 deletions src/components/Datepicker/DatepickerContentElements.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import styled, { css } from 'styled-components';
import { SemanticColors } from '../../essentials';

const baseArrowStyles = css`
width: 1.25rem;
height: 1.25rem;
position: absolute;
background: inherit;
`;

export const Arrow = styled.div`
visibility: hidden;
${baseArrowStyles};

&::before {
${baseArrowStyles};
visibility: visible;
content: '';
transform: rotate(45deg);
}
`;

export const DatepickerContentContainer = styled.div`
background: ${SemanticColors.forms.datePicker.calendar.background};
box-shadow: 0 0 0.5rem 0.1875rem rgba(0, 0, 0, 0.08);

&[data-popper-placement^='top'] > ${Arrow} {
bottom: -0.625rem;
&::before {
box-shadow: 0.25rem 0.25rem 0.5rem -0.125rem rgba(0, 0, 0, 0.08);
}
}

&[data-popper-placement^='bottom'] > ${Arrow} {
top: -0.625rem;
&::before {
box-shadow: -0.25rem -0.25rem 0.5rem -0.125rem rgba(0, 0, 0, 0.08);
}
}
`;
Loading