mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-11 20:21:10 +00:00
types fix
This commit is contained in:
parent
b3b449a63a
commit
07279ea7b0
|
@ -27,7 +27,6 @@ import { openModal, closeModal } from 'mastodon/actions/modal';
|
||||||
import { CircularProgress } from 'mastodon/components/circular_progress';
|
import { CircularProgress } from 'mastodon/components/circular_progress';
|
||||||
import { isUserTouching } from 'mastodon/is_mobile';
|
import { isUserTouching } from 'mastodon/is_mobile';
|
||||||
import type {
|
import type {
|
||||||
DropdownMenu as DropdownMenuType,
|
|
||||||
MenuItem,
|
MenuItem,
|
||||||
ActionMenuItem,
|
ActionMenuItem,
|
||||||
ExternalLinkMenuItem,
|
ExternalLinkMenuItem,
|
||||||
|
@ -55,8 +54,8 @@ const isExternalLinkItem = (item: MenuItem): item is ExternalLinkMenuItem => {
|
||||||
return !!(item as ExternalLinkMenuItem).href;
|
return !!(item as ExternalLinkMenuItem).href;
|
||||||
};
|
};
|
||||||
|
|
||||||
type RenderItemFn = (
|
type RenderItemFn<Item = MenuItem> = (
|
||||||
arg0: MenuItem,
|
arg0: Item,
|
||||||
arg1: number,
|
arg1: number,
|
||||||
arg2: {
|
arg2: {
|
||||||
onClick: (e: React.MouseEvent) => void;
|
onClick: (e: React.MouseEvent) => void;
|
||||||
|
@ -64,18 +63,18 @@ type RenderItemFn = (
|
||||||
},
|
},
|
||||||
) => React.ReactNode;
|
) => React.ReactNode;
|
||||||
|
|
||||||
type RenderHeaderFn = (arg0: DropdownMenuType) => React.ReactNode;
|
interface DropdownMenuProps<Item = MenuItem> {
|
||||||
|
items: Item[];
|
||||||
const DropdownMenu: React.FC<{
|
|
||||||
items?: DropdownMenuType;
|
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
scrollable?: boolean;
|
scrollable?: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
openedViaKeyboard: boolean;
|
openedViaKeyboard: boolean;
|
||||||
renderItem?: RenderItemFn;
|
renderItem?: RenderItemFn<Item>;
|
||||||
renderHeader?: RenderHeaderFn;
|
renderHeader?: (arg0: Item[]) => React.ReactNode;
|
||||||
onItemClick: (e: React.MouseEvent | React.KeyboardEvent) => void;
|
onItemClick: (e: React.MouseEvent | React.KeyboardEvent) => void;
|
||||||
}> = ({
|
}
|
||||||
|
|
||||||
|
const DropdownMenu = <Item = MenuItem,>({
|
||||||
items,
|
items,
|
||||||
loading,
|
loading,
|
||||||
scrollable,
|
scrollable,
|
||||||
|
@ -84,7 +83,7 @@ const DropdownMenu: React.FC<{
|
||||||
renderItem,
|
renderItem,
|
||||||
renderHeader,
|
renderHeader,
|
||||||
onItemClick,
|
onItemClick,
|
||||||
}) => {
|
}: DropdownMenuProps<Item>) => {
|
||||||
const nodeRef = useRef<HTMLDivElement>(null);
|
const nodeRef = useRef<HTMLDivElement>(null);
|
||||||
const focusedItemRef = useRef<HTMLElement | null>(null);
|
const focusedItemRef = useRef<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
@ -279,27 +278,27 @@ const DropdownMenu: React.FC<{
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface DropdownProps {
|
interface DropdownProps<Item = MenuItem> {
|
||||||
children?: React.ReactElement;
|
children?: React.ReactElement;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
iconComponent?: IconProp;
|
iconComponent?: IconProp;
|
||||||
items?: DropdownMenuType;
|
items: Item[];
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
title?: string;
|
title?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
scrollable?: boolean;
|
scrollable?: boolean;
|
||||||
scrollKey?: string;
|
scrollKey?: string;
|
||||||
status?: ImmutableMap<string, unknown>;
|
status?: ImmutableMap<string, unknown>;
|
||||||
renderItem?: RenderItemFn;
|
renderItem?: RenderItemFn<Item>;
|
||||||
renderHeader?: RenderHeaderFn;
|
renderHeader?: (arg0: Item[]) => React.ReactNode;
|
||||||
onOpen?: () => void;
|
onOpen?: () => void;
|
||||||
onItemClick?: (arg0: MenuItem, arg1: number) => void;
|
onItemClick?: (arg0: Item, arg1: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const offset = [5, 5] as OffsetValue;
|
const offset = [5, 5] as OffsetValue;
|
||||||
const popperConfig = { strategy: 'fixed' } as UsePopperOptions;
|
const popperConfig = { strategy: 'fixed' } as UsePopperOptions;
|
||||||
|
|
||||||
export const Dropdown: React.FC<DropdownProps> = ({
|
export const Dropdown = <Item = MenuItem,>({
|
||||||
children,
|
children,
|
||||||
icon,
|
icon,
|
||||||
iconComponent,
|
iconComponent,
|
||||||
|
@ -314,7 +313,7 @@ export const Dropdown: React.FC<DropdownProps> = ({
|
||||||
onOpen,
|
onOpen,
|
||||||
onItemClick,
|
onItemClick,
|
||||||
scrollKey,
|
scrollKey,
|
||||||
}) => {
|
}: DropdownProps<Item>) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const openDropdownId = useAppSelector((state) => state.dropdownMenu.openId);
|
const openDropdownId = useAppSelector((state) => state.dropdownMenu.openId);
|
||||||
const openedViaKeyboard = useAppSelector(
|
const openedViaKeyboard = useAppSelector(
|
||||||
|
@ -424,7 +423,7 @@ export const Dropdown: React.FC<DropdownProps> = ({
|
||||||
const handleItemClick = useCallback(
|
const handleItemClick = useCallback(
|
||||||
(e: React.MouseEvent | React.KeyboardEvent) => {
|
(e: React.MouseEvent | React.KeyboardEvent) => {
|
||||||
const i = Number(e.currentTarget.getAttribute('data-index'));
|
const i = Number(e.currentTarget.getAttribute('data-index'));
|
||||||
const item = items?.[i];
|
const item = items[i];
|
||||||
|
|
||||||
handleClose();
|
handleClose();
|
||||||
|
|
||||||
|
@ -494,7 +493,7 @@ export const Dropdown: React.FC<DropdownProps> = ({
|
||||||
{...arrowProps}
|
{...arrowProps}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DropdownMenu
|
<DropdownMenu<Item>
|
||||||
items={items}
|
items={items}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
scrollable={scrollable}
|
scrollable={scrollable}
|
||||||
|
|
|
@ -108,7 +108,7 @@ export const EditedTimestamp: React.FC<{
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<Dropdown<HistoryItem>
|
||||||
items={items}
|
items={items}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user