From c69f54ce4a02b4fb438125378367ffd86d0093c7 Mon Sep 17 00:00:00 2001 From: heswell Date: Thu, 4 Aug 2022 17:15:26 +0100 Subject: [PATCH] List refactor, Dropdown refactor, ComboBox refactor, Tabs refactor, Toolbar refactor, Tree component (#10) --- internal/CalendarNavigation.tsx | 54 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/internal/CalendarNavigation.tsx b/internal/CalendarNavigation.tsx index 48d91f216..54b626700 100644 --- a/internal/CalendarNavigation.tsx +++ b/internal/CalendarNavigation.tsx @@ -16,7 +16,8 @@ import { SyntheticEvent, } from "react"; import { Dropdown, DropdownProps } from "../../dropdown"; -import { IndexedListItemProps, ListItemBase, useListItem } from "../../list"; +import { ListItem, ListItemProps, ListItemType } from "../../list"; + import { useCalendarContext } from "./CalendarContext"; import dayjs from "./dayjs"; @@ -114,42 +115,31 @@ function useCalendarNavigation() { const ListItemWithTooltip = forwardRef< HTMLDivElement, - IndexedListItemProps + ListItemProps >((props, ref) => { - const { item, itemProps, itemToString } = useListItem(props); + const { item, label } = props; const { getTooltipProps, getTriggerProps } = useTooltip({ placement: "right", - disabled: !item.disabled, + disabled: !item?.disabled, }); const { ref: triggerRef, ...triggerProps } = - getTriggerProps(itemProps); + getTriggerProps(props); const handleRef = useForkRef(triggerRef, ref); return ( - <> - - - + + {label} - + ); -}); +}) as ListItemType; export const CalendarNavigation = forwardRef< HTMLDivElement, @@ -186,13 +176,19 @@ export const CalendarNavigation = forwardRef< moveToNextMonth(event); }; - const handleMonthSelect: dateDropdownProps["onChange"] = (event, month) => { + const handleMonthSelect: dateDropdownProps["onSelectionChange"] = ( + event, + month + ) => { if (month) { moveToMonth(event, month.value); } }; - const handleYearSelect: dateDropdownProps["onChange"] = (event, year) => { + const handleYearSelect: dateDropdownProps["onSelectionChange"] = ( + event, + year + ) => { if (year) { moveToMonth(event, year.value); } @@ -201,12 +197,14 @@ export const CalendarNavigation = forwardRef< const monthDropdownId = useId(MonthDropdownProps?.id); const monthDropdownLabelledBy = cx( MonthDropdownProps?.["aria-labelledby"], - monthDropdownId + // TODO need a prop on Dropdown to aloow buttonId to be passed, should not make assumptions about internal + // id assignment like this + `${monthDropdownId}-control` ); const yearDropdownId = useId(YearDropdownProps?.id); const yearDropdownLabelledBy = cx( YearDropdownProps?.["aria-labelledby"], - yearDropdownId + `${yearDropdownId}-control` ); const defaultItemToMonth = (date: DropdownItem) => { @@ -249,9 +247,9 @@ export const CalendarNavigation = forwardRef< aria-label="Month Dropdown" {...MonthDropdownProps} ListItem={ListItemWithTooltip} - selectedItem={selectedMonth} + selected={selectedMonth} itemToString={defaultItemToMonth} - onChange={handleMonthSelect} + onSelectionChange={handleMonthSelect} fullWidth /> {!hideYearDropdown && ( @@ -262,8 +260,8 @@ export const CalendarNavigation = forwardRef< aria-label="Year Dropdown" {...YearDropdownProps} ListItem={ListItemWithTooltip} - selectedItem={selectedYear} - onChange={handleYearSelect} + selected={selectedYear} + onSelectionChange={handleYearSelect} itemToString={defaultItemToYear} fullWidth />