Skip to content
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"publish:click-ui": "yarn test && yarn build && yarn npm publish",
"storybook": "storybook dev -p 6006",
"test": "vitest",
"typecheck": "tsc --noEmit",
"watch": "vitest --watch"
"test:watch": "DEBUG_PRINT_LIMIT=100000 vitest --watch",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@h6s/calendar": "2.0.1",
Expand Down
119 changes: 112 additions & 7 deletions src/components/DatePicker/Common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ import { Container } from "../Container/Container";
import { useCalendar, UseCalendarOptions } from "@h6s/calendar";
import { IconButton } from "../IconButton/IconButton";
import { Text } from "../Typography/Text/Text";
import { headerDateFormatter, selectedDateFormatter, weekdayFormatter } from "./utils";
import {
headerDateFormatter,
selectedDateFormatter,
selectedDateTimeFormatter,
weekdayFormatter,
} from "./utils";

const explicitWidth = "250px";

const HighlightedInputWrapper = styled(InputWrapper)<{ $isActive: boolean }>`
${({ $isActive, theme }) => {
const HighlightedInputWrapper = styled(InputWrapper)<{
$isActive: boolean;
$width?: string;
}>`
${({ $isActive, $width, theme }) => {
return `border: ${theme.click.datePicker.dateOption.stroke} solid ${
$isActive
? theme.click.datePicker.dateOption.color.stroke.active
: theme.click.field.color.stroke.default
};`;
};
width: ${$width ? $width : explicitWidth};
${$width && `min-width: ${explicitWidth};`}
`;
}}

width: ${explicitWidth};
}`;

interface DatePickerInputProps {
Expand Down Expand Up @@ -131,6 +140,102 @@ export const DateRangePickerInput = ({
);
};

interface DateTimePickerInputProps {
isActive: boolean;
disabled: boolean;
id?: string;
placeholder?: string;
selectedEndDate?: Date;
selectedStartDate?: Date;
}

export const DateTimePickerInput = ({
isActive,
disabled,
id,
placeholder,
selectedEndDate,
selectedStartDate,
}: DateTimePickerInputProps) => {
const defaultId = useId();

let formattedValue = (
<Text
color="muted"
component="span"
>
{placeholder ?? ""}
</Text>
);
if (selectedStartDate) {
if (selectedEndDate) {
formattedValue = (
<span>
{selectedDateTimeFormatter
.format(selectedStartDate)
.replace("AM", "am")
.replace("PM", "pm")}{" "}
–{" "}
{selectedDateTimeFormatter
.format(selectedEndDate)
.replace("AM", "am")
.replace("PM", "pm")}
</span>
);
} else {
formattedValue = (
<span>
{selectedDateTimeFormatter
.format(selectedStartDate)
.replace("AM", "am")
.replace("PM", "pm")}{" "}
<Text
color="muted"
component="span"
>
– end date
</Text>
</span>
);
}
} else if (selectedEndDate) {
formattedValue = (
<span>
<Text
color="muted"
component="span"
>
start date –{" "}
</Text>
{selectedDateTimeFormatter
.format(selectedEndDate)
.replace("AM", "am")
.replace("PM", "pm")}
</span>
);
}

return (
<HighlightedInputWrapper
$isActive={isActive}
disabled={disabled}
id={id ?? defaultId}
$width="max-content"
>
<InputStartContent>
<Icon name="calendar" />
</InputStartContent>
<InputElement
$hasStartContent
as="div"
data-testid="datetimepicker-input"
>
{formattedValue}
</InputElement>
</HighlightedInputWrapper>
);
};

const DatePickerContainer = styled(Container)`
background: ${({ theme }) =>
theme.click.datePicker.dateOption.color.background.default};
Expand Down Expand Up @@ -198,7 +303,7 @@ export const DateTableCell = styled.td<{
${({ $isSelected, theme }) =>
$isSelected &&
`
background: ${theme.click.datePicker.dateOption.color.background.active};
background: ${theme.click.datePicker.dateOption.color.background.active} !important;
color: ${theme.click.datePicker.dateOption.color.label.active};
`}

Expand Down
6 changes: 3 additions & 3 deletions src/components/DatePicker/DateRangePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe("DateRangePicker", () => {

await userEvent.click(getByTestId("daterangepicker-input"));

expect(getByText("Jul 01, 2020 - Jul 04, 2020")).toBeInTheDocument();
expect(getByText("Jul 01, 2020 Jul 04, 2020")).toBeInTheDocument();
expect(getByText("Jun 2020")).toBeInTheDocument();
expect(getByText("May 2020")).toBeInTheDocument();
expect(getByText("Apr 2020")).toBeInTheDocument();
Expand Down Expand Up @@ -315,7 +315,7 @@ describe("DateRangePicker", () => {

await userEvent.click(getByTestId("daterangepicker-input"));

await userEvent.click(getByTestId("Jul 01, 2020 - Jul 04, 2020"));
await userEvent.click(getByTestId("Jul 01, 2020 Jul 04, 2020"));
expect(getByText("Jul 01, 2020 – Jul 04, 2020")).toBeInTheDocument();
});

Expand Down Expand Up @@ -374,7 +374,7 @@ describe("DateRangePicker", () => {

await userEvent.click(getByTestId("daterangepicker-input"));

expect(getByText("Mar 01, 2020 - Mar 04, 2020")).toBeInTheDocument();
expect(getByText("Mar 01, 2020 Mar 04, 2020")).toBeInTheDocument();
expect(getByText("Feb 2020")).toBeInTheDocument();
expect(getByText("Jan 2020")).toBeInTheDocument();
expect(getByText("Dec 2019")).toBeInTheDocument();
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatePicker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const PredefinedDates = ({
? monthFormatter.format(startDate)
: `${selectedDateFormatter.format(
startDate
)} - ${selectedDateFormatter.format(endDate)}`.trim();
)} ${selectedDateFormatter.format(endDate)}`.trim();

return (
<StyledDropdownItem
Expand Down
Loading
Loading