Skip to content

Commit 8db8685

Browse files
committed
responsive calendar
1 parent 3397670 commit 8db8685

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

packages/@react-spectrum/s2/src/Calendar.tsx

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ const calendarStyles = style({
7575
flexDirection: 'column',
7676
gap: 24,
7777
width: 'fit',
78-
disableTapHighlight: true
78+
disableTapHighlight: true,
79+
'--cell-gap': {
80+
type: 'paddingStart',
81+
value: 4
82+
},
83+
'--cell-min-width': {
84+
type: 'width',
85+
value: 32
86+
}
7987
}, getAllowedOverrides());
8088

8189
const headerStyles = style({
@@ -119,10 +127,7 @@ const headerCellStyles = style({
119127

120128
const cellStyles = style({
121129
outlineStyle: 'none',
122-
'--cell-gap': {
123-
type: 'paddingStart',
124-
value: 4
125-
},
130+
boxSizing: 'content-box',
126131
paddingStart: {
127132
default: 4,
128133
isFirstChild: 0
@@ -140,15 +145,20 @@ const cellStyles = style({
140145
isLastWeek: 0
141146
},
142147
position: 'relative',
143-
width: 32,
144-
height: 32,
145148
display: {
146149
default: 'flex',
147150
isOutsideMonth: 'none'
148151
},
149152
alignItems: 'center',
150153
justifyContent: 'center',
151-
disableTapHighlight: true
154+
disableTapHighlight: true,
155+
'--cell-min-width': {
156+
type: 'width',
157+
value: 32
158+
},
159+
width: '[min(var(--cell-min-width), calc((100cqw / 7) - var(--cell-gap)))]',
160+
aspectRatio: 'square',
161+
height: 'auto'
152162
});
153163

154164
const cellInnerStyles = style<CalendarCellRenderProps & {selectionMode: 'single' | 'range'}>({
@@ -172,7 +182,7 @@ const cellInnerStyles = style<CalendarCellRenderProps & {selectionMode: 'single'
172182
font: 'body-sm',
173183
cursor: 'default',
174184
width: 'full',
175-
height: 32,
185+
height: 'full',
176186
borderRadius: 'full',
177187
display: 'flex',
178188
alignItems: 'center',
@@ -448,7 +458,20 @@ export const Calendar = /*#__PURE__*/ (forwardRef as forwardRefType)(function Ca
448458
alignItems: 'start'
449459
})}>
450460
{Array.from({length: visibleMonths}).map((_, i) => (
451-
<CalendarGrid months={i} key={i} />
461+
<div
462+
key={i}
463+
style={{'--visible-months': visibleMonths} as React.CSSProperties}
464+
className={style({
465+
containerType: 'inline-size',
466+
flexGrow: 1,
467+
flexShrink: 0,
468+
flexBasis: '0%',
469+
minWidth: 0,
470+
width: 'calc(7 * var(--cell-min-width) + var(--cell-gap) * 12)',
471+
maxWidth: 'calc(100% / var(--visible-months))'
472+
})}>
473+
<CalendarGrid months={i} />
474+
</div>
452475
))}
453476
</div>
454477
{isInvalid && (
@@ -474,7 +497,8 @@ export const CalendarGrid = (props: Omit<AriaCalendarGridProps, 'children'> & Pr
474497
className={style({
475498
borderCollapse: 'collapse',
476499
borderSpacing: 0,
477-
isolation: 'isolate'
500+
isolation: 'isolate',
501+
width: 'full'
478502
})}
479503
offset={{months: props.months}}>
480504
<CalendarGridHeader className="">
@@ -646,11 +670,8 @@ const CalendarCellInner = (props: Omit<CalendarCellProps, 'children'> & {isRange
646670
<div
647671
className={style({
648672
position: 'relative',
649-
width: 32,
650-
'--cell-width': {
651-
type: 'width',
652-
value: '[self(width)]'
653-
}
673+
width: 'full',
674+
height: 'full'
654675
})}>
655676
<div
656677
ref={ref}

0 commit comments

Comments
 (0)