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: add weekStartsOn to DatePicker and DateRangePicker #643

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/input-elements/Calendar/Calendar.tsx
Expand Up @@ -26,6 +26,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
disabled,
enableYearNavigation,
classNames,
weekStartsOn = 0,
...other
}: T & { enableYearNavigation: boolean }) {
return (
Expand All @@ -37,6 +38,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
onSelect={onSelect as any}
locale={locale}
disabled={disabled}
weekStartsOn={weekStartsOn}
classNames={{
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
month: "space-y-4",
Expand Down
3 changes: 3 additions & 0 deletions src/components/input-elements/DatePicker/DatePicker.tsx
Expand Up @@ -34,6 +34,7 @@ export interface DatePickerProps
locale?: Locale;
enableClear?: boolean;
enableYearNavigation?: boolean;
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
children?: React.ReactElement[] | React.ReactElement;
}

Expand All @@ -50,6 +51,7 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>((props, ref
enableClear = true,
className,
enableYearNavigation = false,
weekStartsOn = 0,
...other
} = props;

Expand Down Expand Up @@ -163,6 +165,7 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>((props, ref
mode="single"
defaultMonth={defaultMonth}
selected={selectedValue}
weekStartsOn={weekStartsOn}
onSelect={
((v: Date) => {
onValueChange?.(v);
Expand Down
Expand Up @@ -48,6 +48,7 @@ export interface DateRangePickerProps
locale?: Locale;
enableClear?: boolean;
enableYearNavigation?: boolean;
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
children?: React.ReactElement[] | React.ReactElement;
}

Expand All @@ -67,6 +68,7 @@ const DateRangePicker = React.forwardRef<HTMLDivElement, DateRangePickerProps>((
children,
className,
enableYearNavigation = false,
weekStartsOn = 0,
...other
} = props;

Expand Down Expand Up @@ -275,6 +277,7 @@ const DateRangePicker = React.forwardRef<HTMLDivElement, DateRangePickerProps>((
day_range_end:
"rounded-l-none rounded-r-tremor-small aria-selected:text-tremor-brand-inverted dark:aria-selected:text-dark-tremor-brand-inverted",
}}
weekStartsOn={weekStartsOn}
{...props}
/>
</Popover.Panel>
Expand Down
6 changes: 6 additions & 0 deletions src/stories/input-elements/DatePicker.stories.tsx
Expand Up @@ -91,3 +91,9 @@ UncontrolledWithoutAllowClear.args = {
defaultValue: new Date(2022, 10, 1),
enableClear: false,
};

export const UncontrolledWithWeekStartsOnWednesday = UncontrolledTemplate.bind({});
UncontrolledWithWeekStartsOnWednesday.args = {
defaultValue: new Date(2022, 10, 1),
weekStartsOn: 3,
};
6 changes: 6 additions & 0 deletions src/stories/input-elements/DateRangePicker.stories.tsx
Expand Up @@ -199,3 +199,9 @@ UncontrolledWithoutAllowClear.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date() },
enableClear: false,
};

export const UncontrolledWithWeekStartsOnTuesday = UncontrolledTemplate.bind({});
UncontrolledWithWeekStartsOnTuesday.args = {
defaultValue: { from: new Date(2022, 10, 1), to: new Date() },
weekStartsOn: 2,
};