Skip to content

Commit

Permalink
[EuiDatePickerRange] Add inline display behavior; [EuiDatePicker] I…
Browse files Browse the repository at this point in the history
…mprove `inline` display behavior (#6795)

* [EuiDatePicker] Remove unused CSS

- `.react-datepicker-popper` is no longer a class being set anywhere

- shadow styles don't use a border

* [EuiDatePicker] Improve `inline` display

- fix `disabled` and `readOnly` styling & behavior - should match inputs and no longer be interactable

- render form control icons below the datepicker

- better docs

- write tests (e2e for now, should likely be storybook)

* [EuiDatePickerRange] Convert to emotion

+ remove unnecessary height style - appears to already work as-is thanks to `.euiFormControlLayoutDelimited`

* [EuiDatePickerRange] Remove unused modifier classes & syntax cleanup

* [EuiDatePickerRange] Use `span` wrapper to match EuiDatePicker

- helps separate form control and date picker range concerns

* [EuiDatePickerRange] Fix now non-working `isLoading` behavior/display toggle
- due to new `span`

`isLoading` needs to be specified via typescript + pulled out of `...rest`

tests
- reorganize w/ `describe`
- add missing props tests

docs
- convert to TSX
- fix bad `isInvalid` use from min test
- remove non-working `isInvalid` from `range.tsx` - the display toggle is overriding that prop

* [EuiDatePickerRange] Add `inline` and `shadow` support

- use separate styles fn, since display is so different and has many extra conditions - requires a lot of resets and layout fixes

- update docs examples with toggles & snippet

- add unit test - but most permutations should likely be storybooks

* [EuiDatePickerRange] When `inline`, remove `iconType`, `fullWidth`, and `prepend/append` display

- they don't make sense to render, and the single datepicker doesn't render them either

* [setup] Upgrade `@emotion` dependencies to latest

- to get `@container` query support, which I'll want to use for responsive `inline` behavior

* [EuiDatePickerRange] Use container queries for better `inline` responsiveness

(sadly, jsdom errors on this, so we have to add another console error exclusion)

* Fix `inline` snapshot to not change literally every day lol

* [PR feedback] Unset `.euiFormControlLayoutDelimited`'s 1px padding

* [PR feedback] Finetune container queries
  • Loading branch information
cee-chen authored May 25, 2023
1 parent 353fd12 commit 43c9bc5
Show file tree
Hide file tree
Showing 23 changed files with 1,932 additions and 494 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@
"@cypress/webpack-dev-server": "^1.7.0",
"@elastic/charts": "^53.1.1",
"@elastic/datemath": "^5.0.3",
"@emotion/babel-preset-css-prop": "^11.10.0",
"@emotion/cache": "^11.10.3",
"@emotion/css": "^11.10.0",
"@emotion/eslint-plugin": "^11.10.0",
"@emotion/jest": "^11.10.0",
"@emotion/react": "^11.10.4",
"@emotion/babel-preset-css-prop": "^11.11.0",
"@emotion/cache": "^11.11.0",
"@emotion/css": "^11.11.0",
"@emotion/eslint-plugin": "^11.11.0",
"@emotion/jest": "^11.11.0",
"@emotion/react": "^11.11.0",
"@faker-js/faker": "^7.6.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
"@svgr/core": "5.5.0",
Expand Down
12 changes: 11 additions & 1 deletion scripts/jest/setup/throw_on_console_error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from 'util'
import { format } from 'util';

// Fail if a test ends up `console.error`-ing, e.g. if React logs because of a
// failed prop types check.
Expand All @@ -16,5 +16,15 @@ console.error = (message, ...rest) => {
return;
}

// @see https://github.com/jsdom/jsdom/issues/2177
// JSDOM doesn't yet know how to parse @container CSS queries -
// all we can do is silence its errors for now
if (
typeof message === 'string' &&
message.startsWith('Error: Could not parse CSS stylesheet')
) {
return;
}

throw new Error(format(message, ...rest));
};
21 changes: 14 additions & 7 deletions src-docs/src/views/date_picker/date_picker_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,19 @@ const utcSnippet = `<EuiDatePicker
customInput={customInput}
/>`;

const inlineSnippet = `<EuiDatePicker
const inlineSnippet = [
`<EuiDatePicker
selected={startDate}
onChange={handleChange}
showTimeSelect
inline
shadow={false}
/>`;
/>`,
`<EuiDatePickerRange
inline
startDateControl={<EuiDatePicker />}
endDateControl={<EuiDatePicker />}
/>`,
];

const classesSnippet = `<EuiDatePicker
selected={startDate}
Expand Down Expand Up @@ -408,10 +414,11 @@ export const DatePickerExample = {
text: (
<p>
Use the <EuiCode>inline</EuiCode> prop to display the date picker
directly in the page. If you do not need the shadows / popover effect
to the date picker then also apply the{' '}
<EuiCode language="js">shadow=false</EuiCode> prop as shown in the
second example.
directly in the page instead of inside a popover. This prop works for
both <strong>EuiDatePicker</strong> as well as{' '}
<strong>EuiDatePickerRange</strong>. If you do not need the default
inline shadow effect, apply the{' '}
<EuiCode language="js">{'shadow={false}'}</EuiCode> prop.
</p>
),
snippet: inlineSnippet,
Expand Down
31 changes: 0 additions & 31 deletions src-docs/src/views/date_picker/inline.js

This file was deleted.

75 changes: 75 additions & 0 deletions src-docs/src/views/date_picker/inline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { useState } from 'react';

import moment from 'moment';

import {
EuiDatePicker,
EuiDatePickerRange,
EuiFlexGroup,
EuiSwitch,
EuiSpacer,
} from '../../../../src/components';

import { DisplayToggles } from '../form_controls/display_toggles';

export default () => {
const [shadow, setShadow] = useState(true);
const [showTimeSelect, setShowTimeSelect] = useState(true);

const [startDate, setStartDate] = useState(moment());
const [endDate, setEndDate] = useState(moment().add(11, 'd'));

return (
<>
<EuiFlexGroup>
<EuiSwitch
label="Show shadow"
checked={shadow}
onChange={() => setShadow((toggle) => !toggle)}
/>
<EuiSwitch
label="Show time select"
checked={showTimeSelect}
onChange={() => setShowTimeSelect((toggle) => !toggle)}
/>
</EuiFlexGroup>
<EuiSpacer />
<DisplayToggles spacerSize="s" canCompressed={false} canFullWidth={false}>
<EuiDatePicker
selected={startDate}
onChange={(date) => date && setStartDate(date)}
inline
showTimeSelect={showTimeSelect}
shadow={shadow}
/>
</DisplayToggles>
<EuiSpacer />
<DisplayToggles spacerSize="s" canCompressed={false} canFullWidth={false}>
<EuiDatePickerRange
inline
shadow={shadow}
startDateControl={
<EuiDatePicker
aria-label="Start date"
selected={startDate}
onChange={(date) => date && setStartDate(date)}
startDate={startDate}
endDate={endDate}
showTimeSelect={showTimeSelect}
/>
}
endDateControl={
<EuiDatePicker
aria-label="End date"
selected={endDate}
onChange={(date) => date && setEndDate(date)}
startDate={startDate}
endDate={endDate}
showTimeSelect={showTimeSelect}
/>
}
/>
</DisplayToggles>
</>
);
};
3 changes: 1 addition & 2 deletions src-docs/src/views/date_picker/range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export default () => {

return (
/* DisplayToggles wrapper for Docs only */
<DisplayToggles canCompressed={false}>
<DisplayToggles canCompressed={false} canPrepend={true} canAppend={true}>
<EuiDatePickerRange
isInvalid={startDate > endDate}
startDateControl={
<EuiDatePicker
selected={startDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@ export default () => {

return (
<EuiDatePickerRange
isInvalid={isInvalid}
startDateControl={
<EuiDatePicker
selected={startDate}
onChange={setStartDate}
onChange={(date) => date && setStartDate(date)}
startDate={startDate}
endDate={endDate}
minDate={minDate}
maxDate={endDate}
isInvalid={isInvalid}
aria-label="Start date"
showTimeSelect
/>
}
endDateControl={
<EuiDatePicker
selected={endDate}
onChange={setEndDate}
onChange={(date) => date && setEndDate(date)}
startDate={startDate}
endDate={endDate}
minDate={startDate}
maxDate={maxDate}
isInvalid={isInvalid}
aria-label="End date"
showTimeSelect
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`EuiDatePicker is rendered 1`] = `
<span
className="euiDatePicker euiDatePicker--shadow"
className="euiDatePicker"
>
<EuiFormControlLayout
fullWidth={false}
Expand Down Expand Up @@ -60,10 +60,10 @@ exports[`EuiDatePicker is rendered 2`] = `

exports[`EuiDatePicker localization accepts the locale prop 1`] = `
<span
class="euiDatePicker euiDatePicker--shadow euiDatePicker--inline"
class="euiDatePicker euiDatePicker--inline euiDatePicker--shadow"
>
<div
class="euiFormControlLayout"
class="euiFormControlLayout euiFormControlLayoutDelimited"
>
<div
class="euiFormControlLayout__childrenWrapper"
Expand Down Expand Up @@ -463,10 +463,10 @@ exports[`EuiDatePicker localization accepts the locale prop 1`] = `

exports[`EuiDatePicker localization inherits locale from context 1`] = `
<span
class="euiDatePicker euiDatePicker--shadow euiDatePicker--inline"
class="euiDatePicker euiDatePicker--inline euiDatePicker--shadow"
>
<div
class="euiFormControlLayout"
class="euiFormControlLayout euiFormControlLayoutDelimited"
>
<div
class="euiFormControlLayout__childrenWrapper"
Expand Down Expand Up @@ -872,7 +872,7 @@ exports[`EuiDatePicker popoverPlacement upRight is rendered 1`] = `
popoverPlacement="upRight"
>
<span
className="euiDatePicker euiDatePicker--shadow"
className="euiDatePicker"
>
<EuiFormControlLayout
fullWidth={false}
Expand Down
Loading

0 comments on commit 43c9bc5

Please sign in to comment.