revite/src/components/common/Tooltip.tsx

61 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-07-05 11:23:23 +01:00
import Tippy, { TippyProps } from "@tippyjs/react";
import styled from "styled-components";
2021-07-05 11:23:23 +01:00
import { Text } from "preact-i18n";
2021-06-19 18:46:05 +01:00
import { Children } from "../../types/Preact";
2021-07-05 11:23:23 +01:00
type Props = Omit<TippyProps, "children"> & {
2021-07-05 11:25:20 +01:00
children: Children;
content: Children;
2021-07-05 11:23:23 +01:00
};
2021-06-19 18:46:05 +01:00
export default function Tooltip(props: Props) {
2021-07-05 11:25:20 +01:00
const { children, content, ...tippyProps } = props;
2021-07-05 11:25:20 +01:00
return (
<Tippy content={content} {...tippyProps}>
{/*
// @ts-expect-error */}
2021-08-04 11:51:53 +02:00
<div style={`display: flex;`}>{children}</div>
2021-07-05 11:25:20 +01:00
</Tippy>
);
2021-06-19 18:46:05 +01:00
}
const PermissionTooltipBase = styled.div`
2021-07-05 11:25:20 +01: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 11:25:20 +01:00
}
`;
2021-07-05 11:23:23 +01:00
export function PermissionTooltip(
2021-07-05 11:25:20 +01:00
props: Omit<Props, "content"> & { permission: string },
2021-07-05 11:23:23 +01:00
) {
2021-07-05 11:25:20 +01:00
const { permission, ...tooltipProps } = props;
return (
<Tooltip
content={
<PermissionTooltipBase>
<span>
<Text id="app.permissions.required" />
</span>
<code>{permission}</code>
</PermissionTooltipBase>
}
{...tooltipProps}
/>
);
}