/*
* Kyoo - A portable and vast media library solution.
* Copyright (c) Kyoo.
*
* See AUTHORS.md and LICENSE file in the project root for full license information.
*
* Kyoo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Kyoo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kyoo. If not, see .
*/
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
import { ComponentProps, ComponentType, forwardRef, ReactElement, ReactNode } from "react";
import Link from "next/link";
import { PressableProps } from "react-native";
import { useYoshiki } from "yoshiki/web";
import { useYoshiki as useNativeYoshiki } from "yoshiki/native";
import { P } from "./text";
import { ContrastArea, SwitchVariant } from "./themes";
import { Icon } from "./icons";
import Dot from "@material-symbols/svg-400/rounded/fiber_manual_record-fill.svg";
import { focusReset, ts } from "./utils";
import { SvgProps } from "react-native-svg";
type YoshikiFunc = (props: ReturnType) => T;
const YoshikiProvider = ({ children }: { children: YoshikiFunc }) => {
const yoshiki = useYoshiki();
return <>{children(yoshiki)}>;
};
const InternalTriger = forwardRef(function _Triger(
{ Component, ComponentProps, ...props },
ref,
) {
return (
);
});
const Menu = ({
Trigger,
onMenuOpen,
onMenuClose,
children,
isOpen,
setOpen,
...props
}: {
Trigger: ComponentType;
children: ReactNode | ReactNode[] | null;
onMenuOpen?: () => void;
onMenuClose?: () => void;
isOpen?: boolean;
setOpen?: (v: boolean) => void;
} & Omit) => {
return (
{
if (setOpen) setOpen(newOpen);
if (newOpen) onMenuOpen?.call(null);
else onMenuClose?.call(null);
}}
>
{({ css, theme }) => (
e.stopImmediatePropagation()}
{...css({
bg: (theme) => theme.background,
overflow: "auto",
minWidth: "220px",
borderRadius: "8px",
boxShadow:
"0px 10px 38px -10px rgba(22, 23, 24, 0.35), 0px 10px 20px -15px rgba(22, 23, 24, 0.2)",
zIndex: 2,
maxHeight: "calc(var(--radix-dropdown-menu-content-available-height) * 0.8)",
})}
>
{children}
)}
);
};
const Item = forwardRef<
HTMLDivElement,
ComponentProps & { href?: string }
>(function _Item({ children, href, onSelect, ...props }, ref) {
if (href) {
return (
{children}
);
}
return (
{children}
);
});
const MenuItem = forwardRef<
HTMLDivElement,
{
label: string;
icon?: ComponentType;
left?: ReactElement;
disabled?: boolean;
selected?: boolean;
} & ({ onSelect: () => void; href?: undefined } | { href: string; onSelect?: undefined })
>(function MenuItem({ label, icon, left, selected, onSelect, href, disabled, ...props }, ref) {
const { css: nCss } = useNativeYoshiki();
const { css, theme } = useYoshiki();
const icn = (icon || selected) && (
);
return (
<>
-
{left && left}
{!left && icn && icn}
{label}
{left && icn && icn}
>
);
});
Menu.Item = MenuItem;
const Sub = ({
children,
disabled,
...props
}: {
label: string;
selected?: boolean;
left?: ReactElement;
disabled?: boolean;
icon?: ComponentType;
children: ReactNode | ReactNode[] | null;
} & AsProps) => {
const { css, theme } = useYoshiki();
return (
e.stopImmediatePropagation()}
{...css({
bg: (theme) => theme.background,
overflow: "auto",
minWidth: "220px",
borderRadius: "8px",
boxShadow:
"0px 10px 38px -10px rgba(22, 23, 24, 0.35), 0px 10px 20px -15px rgba(22, 23, 24, 0.2)",
zIndex: 2,
maxHeight: "calc(var(--radix-dropdown-menu-content-available-height) * 0.8)",
})}
>
{children}
);
};
Menu.Sub = Sub;
export { Menu };