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

[EuiDatePicker] Add compressed input styling #7218

Merged
merged 4 commits into from
Sep 22, 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
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}
Comment on lines +297 to +298
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this will be DRY'ed our more when this component is converted to Emotion, but seeing this conditon inline is helpful!

Copy link
Member Author

@cee-chen cee-chen Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this actually won't be DRY'd out to Emotion since it's a prop being passed to another component 😅 (but it DRYs out needing extra unnecessary CSS unsets, I guess?)

clear={selected && onClear ? { onClick: onClear } : undefined}
isLoading={isLoading}
isInvalid={isInvalid}
Expand Down