UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 3.53 kB
{"version":3,"file":"Decades.mjs","sources":["../../../../../src/components/Datepicker/Views/Decades.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { mergeDeep } from \"../../../helpers/merge-deep\";\nimport { useDatePickerContext } from \"../DatepickerContext\";\nimport { addYears, isDateInDecade, isDateInRange, startOfYearPeriod, Views } from \"../helpers\";\n\nexport interface FlowbiteDatepickerViewsDecadesTheme {\n items: {\n base: string;\n item: {\n base: string;\n selected: string;\n disabled: string;\n };\n };\n}\n\nexport interface DatepickerViewsDecadesProps {\n theme?: FlowbiteDatepickerViewsDecadesTheme;\n}\n\nexport const DatepickerViewsDecades: FC<DatepickerViewsDecadesProps> = ({ theme: customTheme = {} }) => {\n const { theme: rootTheme, selectedDate, viewDate, setViewDate, setView } = useDatePickerContext();\n\n const theme = mergeDeep(rootTheme.views.decades, customTheme);\n\n return (\n <div className={theme.items.base}>\n {[...Array(12)].map((_year, index) => {\n const first = startOfYearPeriod(viewDate, 100);\n const year = first - 10 + index * 10;\n const firstDate = new Date(year, 0, 1);\n const lastDate = addYears(firstDate, 9);\n\n const isSelected = isDateInDecade(viewDate, year);\n const isDisabled = !isDateInRange(viewDate, firstDate, lastDate);\n\n return (\n <button\n disabled={isDisabled}\n key={index}\n type=\"button\"\n className={twMerge(\n theme.items.item.base,\n isSelected && theme.items.item.selected,\n isDisabled && theme.items.item.disabled,\n )}\n onClick={() => {\n if (isDisabled) return;\n\n setViewDate(addYears(viewDate, year - selectedDate.getFullYear()));\n setView(Views.Years);\n }}\n >\n {year}\n </button>\n );\n })}\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;AAMY,MAAC,sBAAsB,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,GAAG,EAAE,EAAE,KAAK;AACvE,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE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