Skip to content

Commit

Permalink
[EuiDatePicker] Add compressed input styling (#7218)
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored Sep 22, 2023
1 parent 1aab41d commit 3122e51
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src-docs/src/views/date_picker/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default () => {
return (
/* DisplayToggles wrapper for Docs only */
<div>
<DisplayToggles canCompressed={false}>
<DisplayToggles>
<EuiDatePicker
showTimeSelect
selected={startDate}
Expand Down
6 changes: 6 additions & 0 deletions src/components/date_picker/date_picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('EuiDatePicker', () => {
expect(container.firstChild).toMatchSnapshot();
});

test('compressed', () => {
const { container } = render(<EuiDatePicker compressed />);
// TODO: Should probably be a visual snapshot test
expect(container.innerHTML).toContain('--compressed');
});

// TODO: These tests/snapshots don't really do anything in Jest without
// the corresponding popover opening. Should be switched to an E2E test instead
describe.skip('popoverPlacement', () => {
Expand Down
17 changes: 12 additions & 5 deletions src/components/date_picker/date_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ interface EuiExtendedDatePickerProps
dayClassName?: (date: Moment) => string | null;

/**
* Makes the input full width
* Renders the input as full width
*/
fullWidth?: boolean;
/**
* Renders the input with compressed height and sizing
*/
compressed?: boolean;

/**
* ref for the ReactDatePicker instance
Expand Down Expand Up @@ -147,6 +151,7 @@ export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
adjustDateOnChange = true,
calendarClassName,
className,
compressed,
controlOnly,
customInput,
dateFormat = euiDatePickerDefaultDateFormat,
Expand Down Expand Up @@ -199,11 +204,12 @@ export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
'euiDatePicker',
'euiFieldText',
numIconsClass,
{
!inline && {
'euiFieldText--fullWidth': fullWidth,
'euiFieldText-isLoading': isLoading,
'euiFieldText--withIcon': !inline && showIcon,
'euiFieldText--isClearable': !inline && selected && onClear,
'euiFieldText--compressed': compressed,
'euiFieldText--withIcon': showIcon,
'euiFieldText--isClearable': selected && onClear,
},
className
);
Expand Down Expand Up @@ -288,7 +294,8 @@ export const EuiDatePicker: FunctionComponent<EuiDatePickerProps> = ({
<span className={classes}>
<EuiFormControlLayout
icon={optionalIcon}
fullWidth={fullWidth}
fullWidth={!inline && fullWidth}
compressed={!inline && compressed}
clear={selected && onClear ? { onClick: onClear } : undefined}
isLoading={isLoading}
isInvalid={isInvalid}
Expand Down
1 change: 1 addition & 0 deletions upcoming_changelogs/7218.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Updated `EuiDatePicker` to support `compressed` input styling

0 comments on commit 3122e51

Please sign in to comment.