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

feat (DateIinput3): added left element prop to date input 3 #6775

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions packages/datetime/src/components/date-input/dateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ export interface DateInputProps extends DatePickerBaseProps, DateFormatProps, Da
*/
rightElement?: React.JSX.Element;

/**
* Element to render on left side of input.
*/
leftElement?: React.JSX.Element;

/**
* Whether the bottom bar displaying "Today" and "Clear" buttons should be shown below the calendar.
*
Expand Down
3 changes: 3 additions & 0 deletions packages/datetime2/src/components/date-input3/dateInput3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const DateInput3: React.FC<DateInput3Props> = React.memo(function _DateIn
popoverProps = {},
popoverRef,
rightElement,
leftElement,
showTimezoneSelect,
timePrecision,
timezone: controlledTimezone,
Expand Down Expand Up @@ -502,6 +503,7 @@ export const DateInput3: React.FC<DateInput3Props> = React.memo(function _DateIn
className={classNames(targetProps.className, inputProps.className)}
intent={shouldShowErrorStyling && isErrorState ? "danger" : "none"}
placeholder={placeholder}
leftElement={leftElement}
rightElement={
<>
{rightElement}
Expand Down Expand Up @@ -545,6 +547,7 @@ export const DateInput3: React.FC<DateInput3Props> = React.memo(function _DateIn
popoverId,
popoverProps.targetTagName,
rightElement,
leftElement,
shouldShowErrorStyling,
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface DateInput3ExampleState {
reverseMonthAndYearMenus: boolean;
shortcuts: boolean;
showActionsBar: boolean;
showLeftElement: boolean;
showRightElement: boolean;
showTimePickerArrows: boolean;
showTimezoneSelect: boolean;
Expand All @@ -58,6 +59,7 @@ export class DateInput3Example extends React.PureComponent<ExampleProps, DateInp
reverseMonthAndYearMenus: false,
shortcuts: false,
showActionsBar: false,
showLeftElement: false,
showRightElement: false,
showTimePickerArrows: false,
showTimezoneSelect: true,
Expand All @@ -83,6 +85,8 @@ export class DateInput3Example extends React.PureComponent<ExampleProps, DateInp

private toggleReverseMenus = handleBooleanChange(reverse => this.setState({ reverseMonthAndYearMenus: reverse }));

private toggleLeftElement = handleBooleanChange(showLeftElement => this.setState({ showLeftElement }));

private toggleRightElement = handleBooleanChange(showRightElement => this.setState({ showRightElement }));

private toggleTimePickerArrows = handleBooleanChange(showTimePickerArrows =>
Expand All @@ -102,7 +106,8 @@ export class DateInput3Example extends React.PureComponent<ExampleProps, DateInp
);

public render() {
const { date, localeCode, showRightElement, showTimePickerArrows, useAmPm, ...spreadProps } = this.state;
const { date, localeCode, showRightElement, showLeftElement, showTimePickerArrows, useAmPm, ...spreadProps } =
this.state;

return (
<Example options={this.renderOptions()} {...this.props}>
Expand All @@ -114,6 +119,11 @@ export class DateInput3Example extends React.PureComponent<ExampleProps, DateInp
rightElement={
showRightElement && <Icon icon="globe" intent="primary" style={{ padding: "7px 5px" }} />
}
leftElement={
showLeftElement ? (
<Icon icon="calendar" intent="primary" style={{ padding: "0px 2px" }} />
) : undefined
}
timePickerProps={
this.state.timePrecision === undefined
? undefined
Expand All @@ -136,6 +146,7 @@ export class DateInput3Example extends React.PureComponent<ExampleProps, DateInp
reverseMonthAndYearMenus: reverse,
shortcuts,
showActionsBar,
showLeftElement,
showRightElement,
showTimePickerArrows,
showTimezoneSelect,
Expand Down Expand Up @@ -187,6 +198,15 @@ export class DateInput3Example extends React.PureComponent<ExampleProps, DateInp
<PropCodeTooltip snippet={`fill={${fill.toString()}}`}>
<Switch label="Fill container width" checked={fill} onChange={this.toggleFill} />
</PropCodeTooltip>
<PropCodeTooltip
content={
<>
<Code>leftElement</Code> is {showLeftElement ? "defined" : "undefined"}
</>
}
>
<Switch label="Show left element" checked={showLeftElement} onChange={this.toggleLeftElement} />
</PropCodeTooltip>
<PropCodeTooltip
content={
<>
Expand Down