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

Add isDisabled prop to EuiSuperDatePicker #2139

Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added support for negated or clauses to `EuiSearchBar` ([#2140](https://github.com/elastic/eui/pull/2140))
- Added `transition` utility services to help create timeouts that account for CSS transition durations and delays ([#2136](https://github.com/elastic/eui/pull/2136))
- Removed `EuiFlexGroup` dependency from `EuiAccordion` ([#2143](https://github.com/elastic/eui/pull/2143))
- Added `isDisabled` prop & styles to `EuiSuperDatePicker` ([#2139](https://github.com/elastic/eui/pull/2139))

**Bug fixes**

Expand Down
14 changes: 14 additions & 0 deletions src-docs/src/views/date_picker/super_date_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function MyCustomQuickSelectPanel({ applyTime }) {
export default class extends Component {
state = {
recentlyUsedRanges: [],
isDiasabled: false,
isLoading: false,
showUpdateButton: true,
isAutoRefreshOnly: false,
Expand Down Expand Up @@ -87,6 +88,12 @@ export default class extends Component {
});
};

toggleDisabled = () => {
this.setState(prevState => ({
isDisabled: !prevState.isDisabled,
}));
};

toggleShowApplyButton = () => {
this.setState(prevState => ({
showUpdateButton: !prevState.showUpdateButton,
Expand Down Expand Up @@ -162,8 +169,15 @@ export default class extends Component {
onChange={this.toggleShowCustomQuickSelectPanel}
checked={this.state.showCustomQuickSelectPanel}
/>
 
<EuiSwitch
label="Is disabled"
onChange={this.toggleDisabled}
checked={this.state.isDisabled}
/>
<EuiSpacer />
<EuiSuperDatePicker
isDisabled={this.state.isDisabled}
isLoading={this.state.isLoading}
start={this.state.start}
end={this.state.end}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`EuiSuperDatePicker is rendered 1`] = `
<EuiFlexItem>
<EuiFormControlLayout
className="euiSuperDatePicker"
isDisabled={false}
prepend={
<EuiQuickSelectPopover
applyRefreshInterval={null}
Expand Down Expand Up @@ -60,6 +61,7 @@ exports[`EuiSuperDatePicker is rendered 1`] = `
dateFormat="MMM D, YYYY @ HH:mm:ss.SSS"
end="now"
isAutoRefreshOnly={false}
isDisabled={false}
isPaused={true}
recentlyUsedRanges={Array []}
refreshInterval={0}
Expand All @@ -77,6 +79,7 @@ exports[`EuiSuperDatePicker is rendered 1`] = `
<button
className="euiSuperDatePicker__prettyFormat"
data-test-subj="superDatePickerShowDatesButton"
disabled={false}
onClick={[Function]}
>
Last 15 minutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,24 @@
justify-content: space-between;
text-align: left;

&:hover,
&:not(:disabled):hover,
&:focus {
text-decoration: none;

.euiSuperDatePicker__prettyFormatLink {
text-decoration: underline;
}
}

&:disabled {
background-color: $euiFormBackgroundDisabledColor;
color: $euiColorDarkShade;
cursor: not-allowed;

.euiSuperDatePicker__prettyFormatLink {
display: none;
}
}
}

.euiSuperDatePicker__prettyFormatLink {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
background-image: euiFormControlGradient($euiColorDanger);
}
}

&:disabled {
background-color: $euiFormBackgroundDisabledColor;
color: $euiColorDarkShade;
cursor: default;
}
}

.euiDatePopoverButton--start {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EuiDatePopoverContent } from './date_popover_content';
export function EuiDatePopoverButton(props) {
const {
position,
isDisabled,
isInvalid,
needsUpdating,
value,
Expand All @@ -30,6 +31,7 @@ export function EuiDatePopoverButton(props) {
'euiDatePopoverButton-isSelected': isOpen,
'euiDatePopoverButton-isInvalid': isInvalid,
'euiDatePopoverButton-needsUpdating': needsUpdating,
'euiDatePopoverButton-disabled': isDisabled,
},
]);

Expand All @@ -45,6 +47,7 @@ export function EuiDatePopoverButton(props) {
onClick={onPopoverToggle}
className={classes}
title={title}
disabled={isDisabled}
data-test-subj={`superDatePicker${position}DatePopoverButton`}
{...buttonProps}>
{formatTimeString(value, dateFormat, roundUp)}
Expand Down Expand Up @@ -75,6 +78,7 @@ export function EuiDatePopoverButton(props) {
EuiDatePopoverButton.propTypes = {
position: PropTypes.oneOf(['start', 'end']),
isInvalid: PropTypes.bool,
isDisabled: PropTypes.bool,
needsUpdating: PropTypes.bool,
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`EuiQuickSelectPopover is rendered 1`] = `
data-test-subj="superDatePickerToggleQuickMenuButton"
iconSide="right"
iconType="arrowDown"
isDisabled={false}
onClick={[Function]}
size="xs"
textProps={
Expand Down Expand Up @@ -97,6 +98,7 @@ exports[`EuiQuickSelectPopover isAutoRefreshOnly 1`] = `
data-test-subj="superDatePickerToggleQuickMenuButton"
iconSide="right"
iconType="arrowDown"
isDisabled={false}
onClick={[Function]}
size="xs"
textProps={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class EuiQuickSelectPopover extends Component {
size="xs"
iconType="arrowDown"
iconSide="right"
isDisabled={this.props.isDisabled}
data-test-subj="superDatePickerToggleQuickMenuButton">
<EuiIcon
type={
Expand Down Expand Up @@ -145,12 +146,12 @@ EuiQuickSelectPopover.propTypes = {
start: PropTypes.string.isRequired,
end: PropTypes.string.isRequired,
applyRefreshInterval: PropTypes.func,
isDisabled: PropTypes.bool.isRequired,
isPaused: PropTypes.bool.isRequired,
refreshInterval: PropTypes.number.isRequired,
commonlyUsedRanges: PropTypes.arrayOf(commonlyUsedRangeShape).isRequired,
dateFormat: PropTypes.string.isRequired,
recentlyUsedRanges: PropTypes.arrayOf(recentlyUsedRangeShape).isRequired,
isAutoRefreshOnly: PropTypes.bool.isRequired,
isAutoRefreshOnly: PropTypes.bool.isRequired,
customQuickSelectPanels: PropTypes.arrayOf(quickSelectPanelShape),
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const defaultProps = {
applyRefreshInterval: noop,
start: 'now-15m',
end: 'now',
isDisabled: false,
isPaused: true,
refreshInterval: 0,
commonlyUsedRanges: [{ start: 'now/d', end: 'now/d', label: 'Today' }],
Expand Down
14 changes: 12 additions & 2 deletions src/components/date_picker/super_date_picker/super_date_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function isRangeInvalid(start, end) {
export class EuiSuperDatePicker extends Component {
static propTypes = {
isLoading: PropTypes.bool,
isDisabled: PropTypes.bool,
/**
* String as either datemath (e.g.: now, now-15m, now-15m/m) or
* absolute date in the format 'YYYY-MM-DDTHH:mm:ss.SSSZ'
Expand Down Expand Up @@ -110,6 +111,7 @@ export class EuiSuperDatePicker extends Component {
start: 'now-15m',
end: 'now',
isPaused: true,
isDisabled: false,
refreshInterval: 0,
commonlyUsedRanges: commonDurationRanges,
dateFormat: 'MMM D, YYYY @ HH:mm:ss.SSS',
Expand Down Expand Up @@ -279,6 +281,7 @@ export class EuiSuperDatePicker extends Component {

renderDatePickerRange = () => {
const { start, end, hasChanged, isInvalid } = this.state;
const { isDisabled } = this.props;

if (this.props.isAutoRefreshOnly) {
return (
Expand Down Expand Up @@ -309,8 +312,11 @@ export class EuiSuperDatePicker extends Component {
startDateControl={<div />}
endDateControl={<div />}>
<button
className="euiSuperDatePicker__prettyFormat"
className={classNames('euiSuperDatePicker__prettyFormat', {
'euiSuperDatePicker__prettyFormat--disabled': isDisabled,
})}
data-test-subj="superDatePickerShowDatesButton"
disabled={isDisabled}
onClick={this.hidePrettyDuration}>
{prettyDuration(
start,
Expand All @@ -336,6 +342,7 @@ export class EuiSuperDatePicker extends Component {
position="start"
needsUpdating={hasChanged}
isInvalid={isInvalid}
isDisabled={isDisabled}
onChange={this.setStart}
value={start}
dateFormat={this.props.dateFormat}
Expand All @@ -349,6 +356,7 @@ export class EuiSuperDatePicker extends Component {
position="end"
needsUpdating={hasChanged}
isInvalid={isInvalid}
isDisabled={isDisabled}
onChange={this.setEnd}
value={end}
dateFormat={this.props.dateFormat}
Expand Down Expand Up @@ -381,7 +389,7 @@ export class EuiSuperDatePicker extends Component {
<EuiSuperUpdateButton
needsUpdate={this.state.hasChanged}
isLoading={this.props.isLoading}
isDisabled={this.state.isInvalid}
isDisabled={this.props.isDisabled || this.state.isInvalid}
onClick={this.handleClickUpdateButton}
data-test-subj="superDatePickerApplyTimeButton"
/>
Expand All @@ -398,6 +406,7 @@ export class EuiSuperDatePicker extends Component {
applyRefreshInterval={
this.props.onRefreshChange ? this.onRefreshChange : null
}
isDisabled={this.props.isDisabled}
isPaused={this.props.isPaused}
refreshInterval={this.props.refreshInterval}
commonlyUsedRanges={this.props.commonlyUsedRanges}
Expand All @@ -423,6 +432,7 @@ export class EuiSuperDatePicker extends Component {
<EuiFlexItem>
<EuiFormControlLayout
className="euiSuperDatePicker"
isDisabled={this.props.isDisabled}
prepend={quickSelect}>
{this.renderDatePickerRange()}
</EuiFormControlLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@
}
}
}

.euiFormControlLayout-isDisabled,
.euiFormControlLayout-isDisabled .euiDatePickerRange--inGroup {
background-color: $euiFormBackgroundDisabledColor;
color: $euiColorDarkShade;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type EuiFormControlLayoutProps = CommonProps &
clear?: EuiFormControlLayoutIconsProps['clear'];
fullWidth?: boolean;
isLoading?: boolean;
isDisabled?: boolean;
className?: string;
compressed?: boolean;
readOnly?: boolean;
Expand All @@ -72,6 +73,7 @@ export class EuiFormControlLayout extends Component<EuiFormControlLayoutProps> {
clear,
fullWidth,
isLoading,
isDisabled,
compressed,
className,
prepend,
Expand All @@ -87,6 +89,7 @@ export class EuiFormControlLayout extends Component<EuiFormControlLayoutProps> {
'euiFormControlLayout--compressed': compressed,
'euiFormControlLayout--readOnly': readOnly,
'euiFormControlLayout--group': prepend || append,
'euiFormControlLayout-isDisabled': isDisabled,
},
className
);
Expand Down