revite/src/components/common/Tooltip.tsx

61 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-07-05 06:23:23 -04:00
import Tippy, { TippyProps } from "@tippyjs/react";
import styled from "styled-components";
2021-07-05 06:23:23 -04:00
import { Text } from "preact-i18n";
2021-06-19 13:46:05 -04:00
import { Children } from "../../types/Preact";
2021-07-05 06:23:23 -04:00
type Props = Omit<TippyProps, "children"> & {
2021-07-05 06:25:20 -04:00
children: Children;
content: Children;
2021-07-05 06:23:23 -04:00
};
2021-06-19 13:46:05 -04:00
export default function Tooltip(props: Props) {
2021-07-05 06:25:20 -04:00
const { children, content, ...tippyProps } = props;
2021-07-05 06:25:20 -04:00
return (
<Tippy content={content} {...tippyProps}>
{/*
2021-08-05 09:47:00 -04:00
// @ts-expect-error Type mis-match. */}
2021-08-04 05:51:53 -04:00
<div style={`display: flex;`}>{children}</div>
2021-07-05 06:25:20 -04:00
</Tippy>
);
2021-06-19 13:46:05 -04:00
}
const PermissionTooltipBase = styled.div`
2021-07-05 06:25:20 -04:00
display: flex;
align-items: center;
flex-direction: column;
span {
font-weight: 700;
text-transform: uppercase;
color: var(--secondary-foreground);
font-size: 11px;
}
code {
font-family: var(--monospace-font);
2021-07-05 06:25:20 -04:00
}
`;
2021-07-05 06:23:23 -04:00
export function PermissionTooltip(
2021-07-05 06:25:20 -04:00
props: Omit<Props, "content"> & { permission: string },
2021-07-05 06:23:23 -04:00
) {
2021-07-05 06:25:20 -04:00
const { permission, ...tooltipProps } = props;
return (
<Tooltip
content={
<PermissionTooltipBase>
<span>
<Text id="app.permissions.required" />
</span>
<code>{permission}</code>
</PermissionTooltipBase>
}
{...tooltipProps}
/>
);
}