Open History to see the last commit
1import type { ManagedPolicySummary } from "@t3tools/contracts";
2import { T, Var } from "gt-react";
3import { BuildingIcon } from "lucide-react";
4import type { ReactNode } from "react";
5import { SharedTooltipTrigger } from "./ui/shared-tooltip";
6
7/**
8 * A control an administrator's policy turns off: shown inert, with the policy's reason on hover
9 * and focus. Without a reason it renders the control untouched.
10 */
11export function ManagedControl({
12 reason,
13 children,
14}: {
15 reason: string | undefined;
16 children: ReactNode;
17}) {
18 if (reason === undefined) return children;
19 return (
20 <SharedTooltipTrigger
21 render={
22 <span
23 tabIndex={0}
24 role="group"
25 aria-disabled="true"
26 aria-label={reason}
27 className="inline-flex rounded-md outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
28 />
29 }
30 label={reason}
31 >
32 <span inert className="inline-flex opacity-50">
33 {children}
34 </span>
35 </SharedTooltipTrigger>
36 );
37}
38
39/** One line of policy text with the building mark, for places a whole feature is managed. */
40export function ManagedNotice({ children }: { children: ReactNode }) {
41 return (
42 <p className="flex items-start gap-2 text-muted-foreground text-xs leading-relaxed">
43 <BuildingIcon aria-hidden="true" className="mt-0.5 size-3.5 shrink-0" />
44 <span>{children}</span>
45 </p>
46 );
47}
48
49/** "This environment is managed by <organization>", linking the support page when there is one. */
50export function ManagedByOrganization({ policy }: { policy: ManagedPolicySummary }) {
51 return (
52 <ManagedNotice>
53 <T>
54 This environment is managed by <Var>{policy.organization}</Var>.
55 </T>
56 {policy.supportUrl ? (
57 <>
58 {" "}
59 <a
60 href={policy.supportUrl}
61 target="_blank"
62 rel="noreferrer"
63 className="text-foreground underline underline-offset-2"
64 >
65 <T>Get help</T>
66 </a>
67 </>
68 ) : null}
69 </ManagedNotice>
70 );
71}