UNPKG

@mantine/dates

Version:

Calendars, date and time pickers based on Mantine components

1 lines 6.89 kB
{"version":3,"file":"YearLevelGroup.mjs","names":[],"sources":["../../../src/components/YearLevelGroup/YearLevelGroup.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport { useRef } from 'react';\nimport { BoxProps, ElementProps, factory, Factory, StylesApiProps, useProps } from '@mantine/core';\nimport { DateStringValue } from '../../types';\nimport { handleControlKeyDown } from '../../utils';\nimport { LevelsGroup, LevelsGroupStylesNames } from '../LevelsGroup';\nimport { YearLevel, YearLevelSettings, YearLevelStylesNames } from '../YearLevel';\n\nexport type YearLevelGroupStylesNames = YearLevelStylesNames | LevelsGroupStylesNames;\n\nexport interface YearLevelGroupProps\n extends\n BoxProps,\n Omit<YearLevelSettings, 'withPrevious' | 'withNext' | '__onControlKeyDown' | '__getControlRef'>,\n Omit<StylesApiProps<YearLevelGroupFactory>, 'classNames' | 'styles'>,\n ElementProps<'div'> {\n classNames?: Partial<Record<string, string>>;\n styles?: Partial<Record<string, React.CSSProperties>>;\n __staticSelector?: string;\n\n /** Number of columns displayed next to each other */\n numberOfColumns?: number;\n\n /** Displayed year */\n year: DateStringValue;\n\n /** Function that returns level control `aria-label` */\n levelControlAriaLabel?: ((year: DateStringValue) => string) | string;\n\n /** Determines whether the calendar should take the full width of its container @default false */\n fullWidth?: boolean;\n}\n\nexport type YearLevelGroupFactory = Factory<{\n props: YearLevelGroupProps;\n ref: HTMLDivElement;\n stylesNames: YearLevelGroupStylesNames;\n}>;\n\nconst defaultProps = {\n numberOfColumns: 1,\n} satisfies Partial<YearLevelGroupProps>;\n\nexport const YearLevelGroup = factory<YearLevelGroupFactory>((_props) => {\n const props = useProps('YearLevelGroup', defaultProps, _props);\n const {\n // YearLevel settings\n year,\n locale,\n minDate,\n maxDate,\n monthsListFormat,\n getMonthControlProps,\n __onControlClick,\n __onControlMouseEnter,\n withCellSpacing,\n\n // CalendarHeader settings\n __preventFocus,\n nextIcon,\n previousIcon,\n nextLabel,\n previousLabel,\n onNext,\n onPrevious,\n onLevelClick,\n nextDisabled,\n previousDisabled,\n hasNextLevel,\n headerControlsOrder,\n\n // Other settings\n classNames,\n styles,\n unstyled,\n __staticSelector,\n __stopPropagation,\n numberOfColumns,\n levelControlAriaLabel,\n yearLabelFormat,\n size,\n fullWidth,\n vars,\n attributes,\n ...others\n } = props;\n\n const controlsRef = useRef<HTMLButtonElement[][][]>([]);\n\n const years = Array(numberOfColumns)\n .fill(0)\n .map((_, yearIndex) => {\n const currentYear = dayjs(year).add(yearIndex, 'years').format('YYYY-MM-DD');\n\n return (\n <YearLevel\n key={yearIndex}\n size={size}\n monthsListFormat={monthsListFormat}\n year={currentYear}\n withNext={yearIndex === numberOfColumns - 1}\n withPrevious={yearIndex === 0}\n yearLabelFormat={yearLabelFormat}\n __stopPropagation={__stopPropagation}\n __onControlClick={__onControlClick}\n __onControlMouseEnter={__onControlMouseEnter}\n __onControlKeyDown={(event, payload) =>\n handleControlKeyDown({\n levelIndex: yearIndex,\n rowIndex: payload.rowIndex,\n cellIndex: payload.cellIndex,\n event,\n controlsRef,\n })\n }\n __getControlRef={(rowIndex, cellIndex, node) => {\n if (!Array.isArray(controlsRef.current[yearIndex])) {\n controlsRef.current[yearIndex] = [];\n }\n\n if (!Array.isArray(controlsRef.current[yearIndex][rowIndex])) {\n controlsRef.current[yearIndex][rowIndex] = [];\n }\n\n controlsRef.current[yearIndex][rowIndex][cellIndex] = node;\n }}\n levelControlAriaLabel={\n typeof levelControlAriaLabel === 'function'\n ? levelControlAriaLabel(currentYear)\n : levelControlAriaLabel\n }\n locale={locale}\n minDate={minDate}\n maxDate={maxDate}\n __preventFocus={__preventFocus}\n nextIcon={nextIcon}\n previousIcon={previousIcon}\n nextLabel={nextLabel}\n previousLabel={previousLabel}\n onNext={onNext}\n onPrevious={onPrevious}\n onLevelClick={onLevelClick}\n nextDisabled={nextDisabled}\n previousDisabled={previousDisabled}\n hasNextLevel={hasNextLevel}\n getMonthControlProps={getMonthControlProps}\n classNames={classNames}\n styles={styles}\n unstyled={unstyled}\n __staticSelector={__staticSelector || 'YearLevelGroup'}\n withCellSpacing={withCellSpacing}\n headerControlsOrder={headerControlsOrder}\n fullWidth={fullWidth}\n attributes={attributes}\n />\n );\n });\n\n return (\n <LevelsGroup\n classNames={classNames}\n styles={styles}\n __staticSelector={__staticSelector || 'YearLevelGroup'}\n size={size}\n unstyled={unstyled}\n fullWidth={fullWidth}\n attributes={attributes}\n {...others}\n >\n {years}\n </LevelsGroup>\n );\n});\n\nYearLevelGroup.classes = { ...YearLevel.classes, ...LevelsGroup.classes };\nYearLevelGroup.displayName = '@mantine/dates/YearLevelGroup';\n"],"mappings":";;;;;;;;;AAuCA,MAAM,eAAe,EACnB,iBAAiB,EACnB;AAEA,MAAa,iBAAiB,SAAgC,WAAW;CAEvE,MAAM,EAEJ,MACA,QACA,SACA,SACA,kBACA,sBACA,kBACA,uBACA,iBAGA,gBACA,UACA,cACA,WACA,eACA,QACA,YACA,cACA,cACA,kBACA,cACA,qBAGA,YACA,QACA,UACA,kBACA,mBACA,iBACA,uBACA,iBACA,MACA,WACA,MACA,YACA,GAAG,WAxCS,SAAS,kBAAkB,cAAc,MAyC/C;CAER,MAAM,cAAc,OAAgC,CAAC,CAAC;CAEtD,MAAM,QAAQ,MAAM,eAAe,CAAC,CACjC,KAAK,CAAC,CAAC,CACP,KAAK,GAAG,cAAc;EACrB,MAAM,cAAc,MAAM,IAAI,CAAC,CAAC,IAAI,WAAW,OAAO,CAAC,CAAC,OAAO,YAAY;EAE3E,OACE,oBAAC,WAAD;GAEQ;GACY;GAClB,MAAM;GACN,UAAU,cAAc,kBAAkB;GAC1C,cAAc,cAAc;GACX;GACE;GACD;GACK;GACvB,qBAAqB,OAAO,YAC1B,qBAAqB;IACnB,YAAY;IACZ,UAAU,QAAQ;IAClB,WAAW,QAAQ;IACnB;IACA;GACF,CAAC;GAEH,kBAAkB,UAAU,WAAW,SAAS;IAC9C,IAAI,CAAC,MAA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