Skip to content

Commit

Permalink
List refactor, Dropdown refactor, ComboBox refactor, Tabs refactor, T…
Browse files Browse the repository at this point in the history
…oolbar refactor, Tree component (finos#10)
  • Loading branch information
heswell authored and junaidzm13 committed Jan 5, 2024
1 parent 7ce74ab commit c69f54c
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions internal/CalendarNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -114,42 +115,31 @@ function useCalendarNavigation() {

const ListItemWithTooltip = forwardRef<
HTMLDivElement,
IndexedListItemProps<DropdownItem>
ListItemProps<DropdownItem>
>((props, ref) => {
const { item, itemProps, itemToString } = useListItem<DropdownItem>(props);
const { item, label } = props;

const { getTooltipProps, getTriggerProps } = useTooltip({
placement: "right",
disabled: !item.disabled,
disabled: !item?.disabled,
});

const { ref: triggerRef, ...triggerProps } =
getTriggerProps<typeof ListItemBase>(itemProps);
getTriggerProps<typeof ListItem>(props);

const handleRef = useForkRef(triggerRef, ref);

return (
<>
<ListItemBase ref={handleRef} {...triggerProps}>
<label
style={{
width: "100%",
height: "100%",
display: "flex",
alignItems: "center",
}}
>
{itemToString(item)}
</label>
</ListItemBase>
<ListItem ref={handleRef} {...triggerProps}>
{label}
<Tooltip
{...getTooltipProps({
title: "Out of range",
})}
/>
</>
</ListItem>
);
});
}) as ListItemType<DropdownProps>;

export const CalendarNavigation = forwardRef<
HTMLDivElement,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) => {
Expand Down Expand Up @@ -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 && (
Expand All @@ -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
/>
Expand Down

0 comments on commit c69f54c

Please sign in to comment.