Skip to content
Snippets Groups Projects
Tooltip.tsx 1.22 KiB
Newer Older
import { Text } from "preact-i18n";
import styled from "styled-components";
insert's avatar
insert committed
import { Children } from "../../types/Preact";
import Tippy, { TippyProps } from '@tippyjs/react';
type Props = Omit<TippyProps, 'children'> & {
insert's avatar
insert committed
    children: Children;
    content: Children;
}

export default function Tooltip(props: Props) {
    const { children, content, ...tippyProps } = props;

insert's avatar
insert committed
    return (
        <Tippy content={content} {...tippyProps}>
            {/*
            // @ts-expect-error */}
            <div>{ children }</div>
        </Tippy>

const PermissionTooltipBase = styled.div`
    display: flex;
    align-items: center;
    flex-direction: column;
nizune's avatar
nizune committed
    span {
        font-weight: 700;
        text-transform: uppercase;
        color: var(--secondary-foreground);
        font-size: 11px;
    }
    code {
        font-family: 'Fira Mono';
    }
`;

export function PermissionTooltip(props: Omit<Props, 'content'> & { permission: string }) {
    const { permission, ...tooltipProps } = props;

    return (
        <Tooltip content={<PermissionTooltipBase>
nizune's avatar
nizune committed
            <span><Text id="app.permissions.required" /></span>
            <code>{ permission }</code>
        </PermissionTooltipBase>} {...tooltipProps} />
    )
}