-
Notifications
You must be signed in to change notification settings - Fork 843
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
[Docs] Update EuiDatePicker types #5318
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,6 @@ import { Moment } from 'moment'; // eslint-disable-line import/named | |
import { EuiFormControlLayout, EuiValidatableControl } from '../form'; | ||
import { EuiFormControlLayoutIconsProps } from '../form/form_control_layout/form_control_layout_icons'; | ||
|
||
import { EuiErrorBoundary } from '../error_boundary'; | ||
|
||
import { EuiI18nConsumer } from '../context'; | ||
import { ApplyClassComponentDefaults, CommonProps } from '../common'; | ||
|
||
|
@@ -28,7 +26,38 @@ export const euiDatePickerDefaultTimeFormat = 'hh:mm A'; | |
|
||
const DatePicker = _ReactDatePicker as typeof ReactDatePicker; | ||
|
||
interface EuiExtendedDatePickerProps extends ReactDatePickerProps { | ||
// EuiDatePicker only supports a subset of props from react-datepicker. | ||
const unsupportedProps = [ | ||
// We don't want to show multiple months next to each other | ||
'monthsShown', | ||
// There is no need to show week numbers | ||
'showWeekNumbers', | ||
// Our css adapts to height, no need to fix it | ||
'fixedHeight', | ||
// We force the month / year selection UI. No need to configure it | ||
'dropdownMode', | ||
// Short month is unnecessary. Our UI has plenty of room for full months | ||
'useShortMonthInDropdown', | ||
// The today button is not needed. This should always be external to the calendar | ||
'todayButton', | ||
// We hide the time caption, so there is no need to overwrite its text | ||
'timeCaption', | ||
// We always want keyboard accessibility on | ||
'disabledKeyboardNavigation', | ||
// This is easy enough to do. It can conflict with isLoading state | ||
'isClearable', | ||
// There is no reason to launch the datepicker in its own modal. Can always build these ourselves | ||
'withPortal', | ||
// Causes Error: Cannot read property 'clone' of undefined | ||
'showMonthYearDropdown', | ||
// We overridde this with `popoverPlacement` | ||
'popperPlacement', | ||
] as const; | ||
|
||
type UnsupportedProps = typeof unsupportedProps[number]; | ||
|
||
interface EuiExtendedDatePickerProps | ||
extends Omit<ReactDatePickerProps, UnsupportedProps> { | ||
/** | ||
* Applies classes to the numbered days provided. Check docs for example. | ||
*/ | ||
|
@@ -85,7 +114,7 @@ interface EuiExtendedDatePickerProps extends ReactDatePickerProps { | |
iconType?: EuiFormControlLayoutIconsProps['icon']; | ||
|
||
/** | ||
* Sets the placement of the popover. It accepts: `"bottom"`, `"bottom-end"`, `"bottom-start"`, `"left"`, `"left-end"`, `"left-start"`, `"right"`, `"right-end"`, `"right-start"`, `"top"`, `"top-end"`, `"top-start"` | ||
* Sets the placement of the popover | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super nice cleanup! |
||
*/ | ||
popoverPlacement?: ReactDatePickerProps['popperPlacement']; | ||
} | ||
|
@@ -187,44 +216,6 @@ export class EuiDatePicker extends Component<_EuiDatePickerProps> { | |
fullDateFormat = `${dateFormat} ${timeFormat}`; | ||
} | ||
|
||
// EuiDatePicker only supports a subset of props from react-datepicker. Using any of | ||
// the unsupported props below will spit out an error. | ||
const PropNotSupported = () => { | ||
throw new Error(`You are using a prop from react-datepicker that EuiDatePicker | ||
does not support. Please check the EUI documentation for more information.`); | ||
}; | ||
|
||
if ( | ||
// We don't want to show multiple months next to each other | ||
this.props.monthsShown || | ||
// There is no need to show week numbers | ||
this.props.showWeekNumbers || | ||
// Our css adapts to height, no need to fix it | ||
this.props.fixedHeight || | ||
// We force the month / year selection UI. No need to configure it | ||
this.props.dropdownMode || | ||
// Short month is unnecessary. Our UI has plenty of room for full months | ||
this.props.useShortMonthInDropdown || | ||
// The today button is not needed. This should always be external to the calendar | ||
this.props.todayButton || | ||
// We hide the time caption, so there is no need to overwrite its text | ||
this.props.timeCaption || | ||
// We always want keyboard accessibility on | ||
this.props.disabledKeyboardNavigation || | ||
// This is easy enough to do. It can conflict with isLoading state | ||
this.props.isClearable || | ||
// There is no reason to launch the datepicker in its own modal. Can always build these ourselves | ||
this.props.withPortal || | ||
// Causes Error: Cannot read property 'clone' of undefined | ||
this.props.showMonthYearDropdown | ||
) { | ||
return ( | ||
<EuiErrorBoundary> | ||
<PropNotSupported /> | ||
</EuiErrorBoundary> | ||
); | ||
} | ||
|
||
return ( | ||
<span className={classes}> | ||
<EuiFormControlLayout | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice a11y catch! ❤️