Skip to content

Commit

Permalink
add option to display inline
Browse files Browse the repository at this point in the history
  • Loading branch information
noahwaldner committed Jan 24, 2025
1 parent 964730a commit aa12d5a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-weeks-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frontify/fondue": patch
---

fix: add inline variant to `DatePicker`
47 changes: 21 additions & 26 deletions packages/fondue/src/components/DatePicker/DatePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useRef, useState } from 'react';
import { Badge, BadgeEmphasis, BadgeStyle } from '@components/Badge';
import { Button } from '@components/Button';
import { FormControl } from '@components/FormControl';
import { SegmentedControls } from '@components/SegmentedControls';
import IconCalendar16 from '@foundation/Icon/Generated/IconCalendar16';
import { Validation } from '@utilities/validation';

Expand Down Expand Up @@ -61,31 +60,6 @@ const TemplateWithFormControl: StoryFn<DatePickerProps> = (args: DatePickerProps
/>
</FormControl>
</div>
<div className="tw-px-5 tw-py-3 tw-flex tw-flex-col tw-gap-3">
<FormControl>
<DatePicker
{...args}
variant="single"
startDate={null}
endDate={null}
value={selectedDate as Date}
onChange={(date) => setSelectedDate(date)}
/>
</FormControl>
</div>
</div>
<div className="tw-px-5 tw-py-3 tw-flex tw-flex-col tw-gap-3">
<FormControl>
<SegmentedControls
activeItemId="a"
items={[
{ id: 'a', value: 'abc' },
{ id: 'b', value: 'def' },
{ id: 'c', value: 'ghi' },
]}
onChange={() => {}}
/>
</FormControl>
</div>
</div>
);
Expand Down Expand Up @@ -199,3 +173,24 @@ const TemplateDateRange: StoryFn<DatePickerProps> = () => {
};

export const DateRange = TemplateDateRange.bind({});

const WithWrapperDiv: StoryFn<DatePickerProps> = (args: DatePickerProps) => {
const [selectedDate, setSelectedDate] = useState<Date | null>();

return (
<div className="tw-bg-red-50 tw-p-8 tw-w-[500px]">
<DatePicker
{...args}
variant="single"
startDate={null}
endDate={null}
value={selectedDate as Date}
onChange={(date) => setSelectedDate(date)}
/>
</div>
);
};
export const Inline = WithWrapperDiv.bind({});
Inline.args = {
inline: true,
};
5 changes: 4 additions & 1 deletion packages/fondue/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type DatePickerProps = {
children?: ReactNode;
hasPopperArrow?: boolean;
preventOpenOnFocus?: boolean;
inline?: boolean;
filterDate?: (date: Date) => boolean;
onOpen?: () => void;
onClose?: () => void;
Expand Down Expand Up @@ -91,6 +92,7 @@ export const DatePicker = forwardRef<ReactDatePickerRef, DatePickerProps>(
children,
hasPopperArrow = true,
preventOpenOnFocus = false,
inline = false,
filterDate = () => true,
variant = 'single',
'data-test-id': dataTestId = 'date-picker',
Expand All @@ -112,7 +114,8 @@ export const DatePicker = forwardRef<ReactDatePickerRef, DatePickerProps>(
return (
<div data-test-id={dataTestId}>
<ReactDatePickerComponent
calendarClassName="tw-rounded-sm tw-border tw-border-line-x-strong react-datepicker-wrap tw-pointer-events-auto"
calendarClassName={`tw-rounded-sm tw-border tw-border-line-x-strong react-datepicker-wrap tw-pointer-events-auto${inline ? ' react-datepicker-inline' : ''}`}
inline={inline}
selected={value}
startDate={startDate}
endDate={endDate}
Expand Down
5 changes: 5 additions & 0 deletions packages/fondue/src/components/DatePicker/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
box-shadow: 0 3px 10px 0 rgba(8, 8, 8, 0.3);
}

.react-datepicker-wrap.react-datepicker-inline {
border: none;
box-shadow: none;
}

.react-datepicker-popper .react-datepicker__triangle {
z-index: 1;
}
Expand Down

0 comments on commit aa12d5a

Please sign in to comment.