-
Notifications
You must be signed in to change notification settings - Fork 186
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
[SHIBA-2119] Added Optional Height Prop for Scrollable Calendar #3057
Changes from 2 commits
eb1466a
4550052
6b7c29e
f0ffeb2
fa77fb8
b48ac34
38b97de
581fa96
492c58c
8cec8cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,20 +35,6 @@ import { getMonthsArray, getMonthItemHeights } from './utils'; | |
|
||
const getClassName = cssModules(STYLES); | ||
|
||
// These constants are here to facilitate calculating the height | ||
// Row and month item heights are defined in rem to support text scaling | ||
const ROW_HEIGHT = 2.75; | ||
// This is the additional height of each grid without any rows. | ||
const BASE_MONTH_ITEM_HEIGHT = 8.125; | ||
const COLUMN_COUNT = 7; | ||
// Most browsers have by default 16px root font size | ||
const DEFAULT_ROOT_FONT_SIZE = 16; | ||
// Most calendar grids have 5 rows. Calculate height in px as this is what react-window expects. | ||
const ESTIMATED_MONTH_ITEM_HEIGHT = | ||
(BASE_MONTH_ITEM_HEIGHT + 5 * ROW_HEIGHT) * DEFAULT_ROOT_FONT_SIZE; | ||
// Minimum month item width (useful for server-side rendering. This value will be overridden with an accurate width after mounting) | ||
const ESTIMATED_MONTH_ITEM_WIDTH = BASE_MONTH_ITEM_HEIGHT * 7 * DEFAULT_ROOT_FONT_SIZE; | ||
|
||
type Props = Partial<BpkCalendarGridProps> & { | ||
minDate: Date; | ||
maxDate: Date; | ||
|
@@ -60,13 +46,15 @@ type Props = Partial<BpkCalendarGridProps> & { | |
focusedDate?: Date | null; | ||
selectionConfiguration?: SelectionConfiguration; | ||
className?: string | null; | ||
monthHeight?: number; | ||
}; | ||
|
||
const BpkScrollableCalendarGridList = (props: Props) => { | ||
const { | ||
className = null, | ||
focusedDate = null, | ||
minDate, | ||
monthHeight = 8.125, | ||
selectionConfiguration, | ||
...rest | ||
} = props; | ||
|
@@ -75,6 +63,20 @@ const BpkScrollableCalendarGridList = (props: Props) => { | |
const endDate = startOfDay(startOfMonth(rest.maxDate)); | ||
const monthsCount = DateUtils.differenceInCalendarMonths(endDate, startDate); | ||
|
||
// These constants are here to facilitate calculating the height | ||
// Row and month item heights are defined in rem to support text scaling | ||
const ROW_HEIGHT = 2.75; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this down, so it can be assigned by the optional prop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if we need to move any constants within the component and having this run with every render, we need to be careful what we move and also we shouldn't be using capital letters for these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, makes sense. With us now updating the We will be in a middle state though where some dimension properties are still constant whilst others are not. |
||
// This is the additional height of each grid without any rows. | ||
const BASE_MONTH_ITEM_HEIGHT = monthHeight; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm this constant actually represents the additional height of the grid month so the white spaces around and between rows. I think it might get confusing if we use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. I've updated it so that we're passing a prop for |
||
const COLUMN_COUNT = 7; | ||
// Most browsers have by default 16px root font size | ||
const DEFAULT_ROOT_FONT_SIZE = 16; | ||
// Most calendar grids have 5 rows. Calculate height in px as this is what react-window expects. | ||
const ESTIMATED_MONTH_ITEM_HEIGHT = | ||
(BASE_MONTH_ITEM_HEIGHT + 5 * ROW_HEIGHT) * DEFAULT_ROOT_FONT_SIZE; | ||
// Minimum month item width (useful for server-side rendering. This value will be overridden with an accurate width after mounting) | ||
const ESTIMATED_MONTH_ITEM_WIDTH = BASE_MONTH_ITEM_HEIGHT * 7 * DEFAULT_ROOT_FONT_SIZE; | ||
|
||
const getInitialRootFontSize = () => | ||
parseFloat(getComputedStyle(document.documentElement).fontSize) || | ||
DEFAULT_ROOT_FONT_SIZE; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to specify this prop specifically as the
<Calendar>
component passes the rest of the props via{...calendarProps}
See here