Skip to content

Commit

Permalink
Feat: Date (Range) Picker align prop (#10)
Browse files Browse the repository at this point in the history
* add align prop

* update datpicker prop
  • Loading branch information
severinlandolt authored Apr 11, 2024
1 parent 27cc098 commit 384f4bf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const Calendar = ({
"text-gray-900 dark:text-gray-50",
),
day: cx(
"size-9 rounded text-gray-900 dark:text-gray-50",
"text-sm size-9 rounded text-gray-900 dark:text-gray-50",
"hover:bg-gray-200 hover:dark:bg-gray-700",
focusRing,
),
Expand Down
13 changes: 8 additions & 5 deletions src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Tremor Raw Date Picker [v0.0.0]
// Tremor Raw Date Picker [v0.0.1]

"use client"

Expand Down Expand Up @@ -94,14 +94,14 @@ Trigger.displayName = "DatePicker.Trigger"
const CalendarPopover = React.forwardRef<
React.ElementRef<typeof PopoverPrimitives.Content>,
React.ComponentProps<typeof PopoverPrimitives.Content>
>(({ className, children, ...props }, forwardedRef) => {
>(({ align, className, children, ...props }, forwardedRef) => {
return (
<PopoverPrimitives.Portal>
<PopoverPrimitives.Content
ref={forwardedRef}
sideOffset={10}
side="bottom"
align="center"
align={align}
avoidCollisions
onOpenAutoFocus={(e) => e.preventDefault()}
className={cx(
Expand Down Expand Up @@ -308,6 +308,7 @@ interface PickerProps extends CalendarProps {
id?: string
// Customize the date picker for different languages.
translations?: Translations
align?: "center" | "end" | "start"
"aria-invalid"?: boolean
"aria-label"?: string
"aria-labelledby"?: string
Expand Down Expand Up @@ -339,6 +340,7 @@ const SingleDatePicker = ({
translations,
enableYearNavigation = false,
locale = enUS,
align = "center",
...props
}: SingleProps) => {
const [open, setOpen] = React.useState(false)
Expand Down Expand Up @@ -414,7 +416,7 @@ const SingleDatePicker = ({
>
{formattedDate}
</Trigger>
<CalendarPopover>
<CalendarPopover align={align}>
<div className="flex">
<div className="flex flex-col sm:flex-row sm:items-start">
{presets && presets.length > 0 && (
Expand Down Expand Up @@ -497,6 +499,7 @@ const RangeDatePicker = ({
placeholder = "Select date range",
hasError,
translations,
align = "center",
className,
...props
}: RangeProps) => {
Expand Down Expand Up @@ -575,7 +578,7 @@ const RangeDatePicker = ({
>
{displayRange}
</Trigger>
<CalendarPopover>
<CalendarPopover align={align}>
<div className="flex">
<div className="flex flex-col overflow-x-scroll sm:flex-row sm:items-start">
{presets && presets.length > 0 && (
Expand Down
4 changes: 3 additions & 1 deletion src/components/DatePicker/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Tremor Raw Date Picker Changelog

## 0.0.0
## 0.0.1

### Changes

* New: Align prop to horizontally align the popover ("center" | "end" | "start")
7 changes: 7 additions & 0 deletions src/components/DatePicker/datepicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ const PopoverNested = ({ value, onChange }: PopoverNestedProps) => {
)
}

export const AlignEnd: Story = {
args: {align: "end"},
parameters: {
layout: "centered"
}
}

const PopoverNestedDemo = () => {
const [value, setValue] = React.useState<Date | undefined>(undefined)

Expand Down
7 changes: 7 additions & 0 deletions src/components/DatePicker/daterangepicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ export const Localized: Story = {
},
}

export const AlignEnd: Story = {
args: {align: "end"},
parameters: {
layout: "centered"
}
}

const ControlledRangeDemo = () => {
const [value, setValue] = React.useState<DateRange | undefined>(undefined)

Expand Down

0 comments on commit 384f4bf

Please sign in to comment.