Skip to content

Commit 2ebe9aa

Browse files
committed
feat: add multiple date selection mode to Calendar component
1 parent 7e8e8a0 commit 2ebe9aa

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/components/experimental/Calendar/Calendar.styled.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,11 @@ export const DayButton = styled.button`
239239
&[data-selected-single='true'] {
240240
border-radius: 50%;
241241
}
242+
243+
/* Multiple selected days */
244+
&[data-selected-multiple='true'] {
245+
border-radius: 50%;
246+
background: ${getSemanticValue('interactive-container')};
247+
color: ${getSemanticValue('on-interactive-container')};
248+
}
242249
`;

src/components/experimental/Calendar/Calendar.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ChevronRightIcon from '../../../icons/arrows/ChevronRightIcon';
77
import * as Styled from './Calendar.styled';
88

99
type Props = React.ComponentProps<typeof DayPicker> & {
10-
selectionType?: 'single' | 'range';
10+
selectionType?: 'single' | 'range' | 'multiple';
1111
visibleMonths?: 1 | 2 | 3;
1212
};
1313

@@ -45,12 +45,20 @@ function Calendar({
4545
}
4646
} satisfies Omit<React.ComponentProps<typeof DayPicker>, 'mode'>;
4747

48+
const modeProps = (() => {
49+
switch (selectionType) {
50+
case 'range':
51+
return { mode: 'range' } as const;
52+
case 'multiple':
53+
return { mode: 'multiple' } as const;
54+
default:
55+
return { mode: 'single' } as const;
56+
}
57+
})();
58+
4859
return (
4960
<Styled.Container className={className}>
50-
<DayPicker
51-
{...common}
52-
{...(selectionType === 'range' ? ({ mode: 'range' } as const) : ({ mode: 'single' } as const))}
53-
/>
61+
<DayPicker {...common} {...modeProps} />
5462
</Styled.Container>
5563
);
5664
}
@@ -74,6 +82,9 @@ function CalendarDayButton({ day, modifiers, ...props }: React.ComponentProps<ty
7482
data-selected-single={
7583
modifiers.selected && !modifiers.range_start && !modifiers.range_end && !modifiers.range_middle
7684
}
85+
data-selected-multiple={
86+
modifiers.selected && !modifiers.range_start && !modifiers.range_end && !modifiers.range_middle
87+
}
7788
data-selected={modifiers.selected}
7889
data-today={modifiers.today}
7990
data-outside={modifiers.outside}

src/components/experimental/Calendar/docs/Calendar.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ export const RangeSelection: Story = {
3939
defaultMonth: TODAY
4040
}
4141
};
42+
43+
export const MultipleSelection: Story = {
44+
args: {
45+
selectionType: 'multiple',
46+
defaultMonth: TODAY
47+
}
48+
};

0 commit comments

Comments
 (0)