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

[Emotion] Convert EuiDatePicker #7937

Merged
merged 21 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
09101af
Delete unused CSS
cee-chen Jul 31, 2024
2191e37
Convert inline SVG CSS to direct EuiButtonIcon use
cee-chen Jul 30, 2024
46e0b54
Convert `datePickerCaret` inline SVG to direct EuiIcon usage
cee-chen Jul 30, 2024
b0154c7
Convert `display: none` css to simply deleting the rendered JSX entirely
cee-chen Jul 31, 2024
98aae1e
Convert form control/`EuiDatePicker` wrapper styles
cee-chen Jul 31, 2024
0ba20df
Convert `react-datepicker` styles to vanilla Emotion
cee-chen Jul 31, 2024
f86783e
Set up date picker variables + convert absolutely positioned header e…
cee-chen Jul 31, 2024
639e839
Convert time select styles
cee-chen Jul 31, 2024
1d13e92
Convert day calendar styles
cee-chen Aug 1, 2024
9724407
Convert month/year dropdown styles
cee-chen Aug 1, 2024
c1853d6
Final VRT update
cee-chen Aug 1, 2024
c7d71cd
Delete last Sass variable
cee-chen Aug 1, 2024
26b178b
Delete all date picker Sass files
cee-chen Aug 1, 2024
a802a2b
stylelint shenanigans
cee-chen Aug 1, 2024
cd5a188
changelog
cee-chen Aug 1, 2024
1947d05
[tests] `shouldRenderCustomStyles` + remove Enzyme
cee-chen Aug 1, 2024
32b03ab
Fix EuiDatePickerRange arrow not getting correct responsive styles on…
cee-chen Aug 1, 2024
25b80b3
Fix failing Cypress tests due to removed modifier classes
cee-chen Aug 1, 2024
48480f1
Fix bug with time select height on mobile
cee-chen Aug 1, 2024
e5d56b2
Fix time select to correctly scroll to the selected/pre-selected opti…
cee-chen Aug 1, 2024
8ec68e3
Merge branch 'main' into emotion/react-date-picker
cee-chen Aug 1, 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions packages/eui/src/components/date_picker/date_picker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,27 @@ export const TimeSelectOnly: Story = {
args: { ...TimeSelect.args, showTimeSelectOnly: true },
};

export const RestrictedDaySelect: Story = {
parameters: {
controls: {
include: [
'minDate',
'maxDate',
'includeDates',
'excludeDates',
'filterDate',
'highlightDates',
],
},
},
args: {
autoFocus: true, // Open the datepicker automatically for Lok VRT,
selected: moment('01/02/1970'),
maxDate: moment('01/01/1970'),
minDate: moment('12/31/1969'),
},
};

const StatefulDatePicker = ({
selected,
onChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React, { useState } from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import moment from 'moment';

import { enableFunctionToggleControls } from '../../../.storybook/utils';
import {
Expand Down Expand Up @@ -35,7 +36,6 @@ const meta: Meta<EuiDatePickerRangeProps> = {
prepend: '',
},
};
enableFunctionToggleControls(meta, ['onFocus', 'onBlur']);

export default meta;
type Story = StoryObj<EuiDatePickerRangeProps>;
Expand All @@ -52,27 +52,82 @@ export const Playground: Story = {
},
render: (args) => <StatefulPlayground {...args} />,
};
enableFunctionToggleControls(Playground, ['onFocus', 'onBlur']);

export const Inline: Story = {
parameters: {
controls: {
include: [
'inline',
'shadow',
'disabled',
'readOnly',
'isInvalid',
'isLoading',
],
},
},
args: {
startDateControl: (
<EuiDatePicker showTimeSelect={true} selected={moment('01/01/1970')} />
),
endDateControl: (
<EuiDatePicker showTimeSelect={true} selected={moment('01/07/1970')} />
),
inline: true,
},
render: (args) => <StatefulPlayground {...args} />,
};

export const RestrictedSelection: Story = {
parameters: {
controls: {
include: [],
},
},
args: {
startDateControl: (
<EuiDatePicker
selected={moment('01/01/1970')}
maxDate={moment('01/04/1970')}
highlightDates={[moment('12/30/1969')]}
/>
),
endDateControl: (
<EuiDatePicker
selected={moment('01/07/1970')}
maxDate={moment('01/04/1970')}
/>
),
inline: true,
},
render: (args) => <StatefulPlayground {...args} />,
};

const StatefulPlayground = ({
startDateControl,
endDateControl,
...rest
}: EuiDatePickerRangeProps) => {
const [selectedStartDate, setSelectedStartDate] = useState<
moment.Moment | null | undefined
>();
const [selectedEndDate, setSelectedEndDate] = useState<
moment.Moment | null | undefined
>();
const [selectedStartDate, setSelectedStartDate] = useState<moment.Moment>(
startDateControl.props.selected
);
const [selectedEndDate, setSelectedEndDate] = useState<moment.Moment>(
endDateControl.props.selected
);

const startControl = React.cloneElement(startDateControl, {
selected: selectedStartDate,
onChange: setSelectedStartDate,
startDate: selectedStartDate,
endDate: selectedEndDate,
});

const endControl = React.cloneElement(endDateControl, {
selected: selectedEndDate,
onChange: setSelectedEndDate,
startDate: selectedStartDate,
endDate: selectedEndDate,
});

return (
Expand Down
131 changes: 131 additions & 0 deletions packages/eui/src/components/date_picker/react_date_picker.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
mathWithUnits,
} from '../../global_styling';
import {
euiButtonColor,
euiButtonEmptyColor,
euiButtonFillColor,
} from '../../themes/amsterdam/global_styling/mixins';
Expand Down Expand Up @@ -130,11 +131,141 @@ export const euiReactDatePickerStyles = (euiThemeContext: UseEuiTheme) => {
}
}

${_dayCalendarStyles(euiThemeContext)}
${_timeSelectStyles(euiThemeContext)}
`,
};
};

export const _dayCalendarStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;
const { gapSize } = euiDatePickerVariables(euiThemeContext);

const daySize = euiTheme.size.xl;
const dayMargin = mathWithUnits(gapSize, (x) => x / 2);
const rangeBackgroundColor = euiButtonColor(
euiThemeContext,
'primary'
).backgroundColor;
const rangeMarginOffset = mathWithUnits(dayMargin, (x) => x * 1.5);

const animationSpeed = euiTheme.animation.fast;

return css`
.react-datepicker__day-names,
.react-datepicker__week {
display: flex;
justify-content: space-between;
flex-grow: 1;
color: ${euiTheme.colors.subduedText};
}

.react-datepicker__day-name,
.react-datepicker__day {
display: inline-block;
${logicalCSS('width', daySize)}
line-height: ${daySize};
margin: ${dayMargin};
font-weight: ${euiTheme.font.weight.medium};
text-align: center;
}

.react-datepicker__day {
color: ${euiTheme.colors.title};
border-radius: ${euiTheme.border.radius.small};

${euiCanAnimate} {
transition: transform ${animationSpeed} ease-in-out,
background-color ${animationSpeed} ease-in;
}

&:hover {
${euiButtonColor(euiThemeContext, 'primary')}
text-decoration: underline;
cursor: pointer;

/* Setting the transform under can animate because its jarring */
${euiCanAnimate} {
transform: scale(1.1);
}
}

&--today {
color: ${euiTheme.colors.primary};
font-weight: ${euiTheme.font.weight.bold};
}

&--outside-month {
color: ${euiTheme.colors.subduedText};
}

&--highlighted,
&--highlighted:hover {
${euiButtonColor(euiThemeContext, 'success')};
}

&--in-range,
&--in-range:hover {
${euiButtonColor(euiThemeContext, 'primary')};
}

/* Ranges use 2 side box-shadows that are the same as the button
* background to fill the gap between margins */
&--in-range:not(&--selected):not(:hover):not(&--disabled) {
box-shadow: -${rangeMarginOffset} 0 ${rangeBackgroundColor},
${rangeMarginOffset} 0 ${rangeBackgroundColor};
border-radius: 0;

&:first-child {
box-shadow: ${rangeMarginOffset} 0 ${rangeBackgroundColor};
}

&:last-child {
box-shadow: -${rangeMarginOffset} 0 ${rangeBackgroundColor};
}
}
/* Animate smoothly on hover */
&--in-range:not(&--selected) {
${euiCanAnimate} {
transition: transform ${animationSpeed} ease-in-out,
box-shadow ${animationSpeed} ease-in-out,
border-radius ${animationSpeed} ease-in-out,
background-color ${animationSpeed} ease-in;
}
}

&--selected,
&--selected:hover,
&--in-selecting-range,
&--in-selecting-range:hover {
${euiButtonFillColor(euiThemeContext, 'primary')}
}

&--disabled,
&--disabled:hover {
${euiButtonColor(euiThemeContext, 'disabled')}
cursor: not-allowed;
text-decoration: none;
transform: none;
}

&--disabled.react-datepicker__day--in-range:not(&--selected) {
&,
&:hover {
background-color: ${euiButtonEmptyColor(euiThemeContext, 'primary')
.backgroundColor};
}
}

&--in-selecting-range:not(&--in-range),
&--disabled.react-datepicker__day--selected,
&--disabled.react-datepicker__day--selected:hover {
${euiButtonColor(euiThemeContext, 'danger')}
}
}
`;
};

export const _timeSelectStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;
const { gapSize } = euiDatePickerVariables(euiThemeContext);
Expand Down
Loading