Skip to content

Commit

Permalink
[datetime] fix layout of TimePicker with second/ms precision (#5544)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Sep 23, 2022
1 parent 6e7deef commit 7feccb3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/datetime/src/_daterangepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
.#{$ns}-daterangepicker-calendars {
display: flex;
flex-direction: row;
justify-content: space-evenly;
justify-content: space-around;
width: 100%;
}

Expand Down
3 changes: 0 additions & 3 deletions packages/datetime/src/_timepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@import "./common";

$timepicker-input-row-height: $pt-grid-size * 3 !default;
$timepicker-row-width: $pt-grid-size * 8 !default;
// subtract two because of inset shadow
$timepicker-input-row-inner-height: $timepicker-input-row-height - 2 !default;
// helps focus states of inputs line up correctly
Expand All @@ -19,7 +18,6 @@ $timepicker-control-width: $pt-grid-size * 3.3 !default;

.#{$ns}-timepicker-arrow-row {
padding: $timepicker-row-padding;
width: $timepicker-row-width;
}

.#{$ns}-timepicker-arrow-button {
Expand Down Expand Up @@ -47,7 +45,6 @@ $timepicker-control-width: $pt-grid-size * 3.3 !default;
line-height: $timepicker-input-row-inner-height;
padding: $timepicker-row-padding;
vertical-align: middle;
width: $timepicker-row-width;
}

.#{$ns}-timepicker-divider-text {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@
* limitations under the License.
*/

import classNames from "classnames";
import * as React from "react";

import { Classes, HTMLSelect } from "@blueprintjs/core";
import { TimePrecision } from "@blueprintjs/datetime";

export interface PrecisionSelectProps {
/**
* Whether the select is disabled.
*
* @default false
*/
disabled?: boolean;

/**
* The precision-string option to display as selected.
*/
Expand All @@ -44,13 +52,17 @@ export interface PrecisionSelectProps {
}

export const PrecisionSelect: React.FC<PrecisionSelectProps> = props => (
<label className={Classes.LABEL}>
{props.label ?? "Precision"}
<HTMLSelect value={props.value} onChange={props.onChange}>
<label className={classNames(Classes.LABEL, { [Classes.DISABLED]: props.disabled })}>
{props.label}
<HTMLSelect value={props.value} onChange={props.onChange} disabled={props.disabled}>
{props.allowNone && <option value="none">None</option>}
<option value={TimePrecision.MINUTE}>Minute</option>
<option value={TimePrecision.SECOND}>Second</option>
<option value={TimePrecision.MILLISECOND}>Millisecond</option>
</HTMLSelect>
</label>
);
PrecisionSelect.defaultProps = {
disabled: false,
label: "Precision",
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import * as React from "react";
import { Callout, Code, H5, Switch } from "@blueprintjs/core";
import { DateFormatProps, DateRange, TimePrecision } from "@blueprintjs/datetime";
import { DateRangeInput2 } from "@blueprintjs/datetime2";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";

import { PrecisionSelect } from "../datetime-examples/common/precisionSelect";
import { DateFnsDateRange } from "./dateFnsDate";
import { DATE_FNS_FORMATS, DateFnsFormatSelector } from "./dateFnsFormatSelector";

Expand All @@ -45,6 +46,7 @@ export interface DateRangeInput2ExampleState {
showFooterElement: boolean;
showTimeArrowButtons: boolean;
singleMonthOnly: boolean;
timePrecision: TimePrecision | undefined;
}

export class DateRangeInput2Example extends React.PureComponent<ExampleProps, DateRangeInput2ExampleState> {
Expand All @@ -62,6 +64,7 @@ export class DateRangeInput2Example extends React.PureComponent<ExampleProps, Da
showFooterElement: false,
showTimeArrowButtons: false,
singleMonthOnly: false,
timePrecision: TimePrecision.MINUTE,
};

private toggleContiguous = handleBooleanChange(contiguous => {
Expand Down Expand Up @@ -92,8 +95,20 @@ export class DateRangeInput2Example extends React.PureComponent<ExampleProps, Da
this.setState({ showTimeArrowButtons }),
);

private handleTimePrecisionChange = handleValueChange((timePrecision: TimePrecision | "none") =>
this.setState({ timePrecision: timePrecision === "none" ? undefined : timePrecision }),
);

public render() {
const { enableTimePicker, format, range, showFooterElement, showTimeArrowButtons, ...spreadProps } = this.state;
const {
enableTimePicker,
format,
range,
showFooterElement,
showTimeArrowButtons,
timePrecision,
...spreadProps
} = this.state;
return (
<Example options={this.renderOptions()} {...this.props}>
<DateRangeInput2
Expand All @@ -103,7 +118,7 @@ export class DateRangeInput2Example extends React.PureComponent<ExampleProps, Da
footerElement={showFooterElement ? exampleFooterElement : undefined}
timePickerProps={
enableTimePicker
? { precision: TimePrecision.MINUTE, showArrowButtons: showTimeArrowButtons }
? { precision: timePrecision, showArrowButtons: showTimeArrowButtons }
: undefined
}
/>
Expand Down Expand Up @@ -164,6 +179,13 @@ export class DateRangeInput2Example extends React.PureComponent<ExampleProps, Da
label="Show timepicker arrow buttons"
onChange={this.toggleTimepickerArrowButtons}
/>
<PrecisionSelect
allowNone={false}
disabled={!this.state.enableTimePicker}
label="Time precision"
onChange={this.handleTimePrecisionChange}
value={this.state.timePrecision}
/>
<DateFnsFormatSelector key="Format" format={this.state.format} onChange={this.handleFormatChange} />
</>
);
Expand Down

1 comment on commit 7feccb3

@blueprint-bot
Copy link

Choose a reason for hiding this comment

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

[datetime] fix layout of TimePicker with second/ms precision (#5544)

Previews: documentation | landing | table | demo

Please sign in to comment.