Skip to content

Commit 5c3ac41

Browse files
author
Dan Costello
committed
Definition overlay
1 parent 596c31e commit 5c3ac41

6 files changed

Lines changed: 117 additions & 0 deletions

File tree

app/components/Glossary.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import Popover from './Popover';
3+
import { glossaryDefinitions } from './glossary-definitions';
4+
5+
type GlossaryProps = {
6+
children: string;
7+
};
8+
9+
const Glossary = ({ children }: GlossaryProps) => {
10+
const term = children.trim();
11+
console.log(term);
12+
const definition = glossaryDefinitions[term] || 'No definition found.';
13+
return (
14+
<Popover content={definition}>
15+
<span style={{ textDecoration: 'underline dotted', cursor: 'help' }}>{term}</span>
16+
</Popover>
17+
);
18+
};
19+
20+
export default Glossary;

app/components/Popover.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use client';
2+
3+
import React, { useState, useRef, useEffect } from 'react';
4+
5+
const Popover = ({ children, content }: { children: React.ReactNode, content: React.ReactNode }) => {
6+
const [isVisible, setIsVisible] = useState(false);
7+
const popoverRef = useRef<HTMLDivElement>(null);
8+
const triggerRef = useRef<HTMLButtonElement>(null);
9+
10+
const toggleVisibility = () => setIsVisible(v => !v);
11+
12+
useEffect(() => {
13+
const handleClickOutside = (event: MouseEvent) => {
14+
if (
15+
popoverRef.current &&
16+
!popoverRef.current.contains(event.target as Node) &&
17+
triggerRef.current &&
18+
!triggerRef.current.contains(event.target as Node)
19+
) {
20+
setIsVisible(false);
21+
}
22+
};
23+
document.addEventListener('mousedown', handleClickOutside);
24+
return () => document.removeEventListener('mousedown', handleClickOutside);
25+
}, []);
26+
27+
return (
28+
<span className="popover-container">
29+
<button
30+
ref={triggerRef}
31+
onClick={toggleVisibility}
32+
className="popover-trigger"
33+
aria-haspopup="true"
34+
aria-expanded={isVisible}
35+
aria-controls="popover-content"
36+
type="button"
37+
>
38+
{children}
39+
</button>
40+
{isVisible && (
41+
<div
42+
id="popover-content"
43+
ref={popoverRef}
44+
className="popover-content"
45+
role="dialog"
46+
aria-modal="true"
47+
>
48+
{content}
49+
</div>
50+
)}
51+
</span>
52+
);
53+
};
54+
55+
export default Popover;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const glossaryDefinitions: Record<string, string> = {
2+
accessor: "A function or method that retrieves data from a source.",
3+
mutator: "A function or method that modifies data.",
4+
token: "A secure, opaque reference to sensitive data.",
5+
// Add more terms as needed
6+
};

app/global.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,37 @@
5555
);
5656
background-repeat: no-repeat;
5757
}
58+
59+
/* Popover styles */
60+
.popover-container {
61+
position: relative;
62+
display: inline-block;
63+
}
64+
65+
.popover-trigger {
66+
background: none;
67+
color: inherit;
68+
border: none;
69+
padding: 0;
70+
font: inherit;
71+
cursor: pointer;
72+
text-decoration: underline dotted;
73+
}
74+
75+
.popover-content {
76+
position: absolute;
77+
top: 100%;
78+
left: 50%;
79+
transform: translateX(-50%);
80+
margin-top: 10px;
81+
background-color: var(--color-fd-popover, white);
82+
color: var(--color-fd-popover-foreground, black);
83+
border: 1px solid var(--color-fd-border, #ccc);
84+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
85+
border-radius: 4px;
86+
padding: 15px;
87+
z-index: 1000;
88+
white-space: normal;
89+
min-width: 200px;
90+
max-width: 320px;
91+
}

content/docs/data-access/definitions/access-policies.md renamed to content/docs/data-access/definitions/access-policies.mdx

File renamed without changes.

mdx-components.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import defaultMdxComponents from 'fumadocs-ui/mdx';
22
import type { MDXComponents } from 'mdx/types';
3+
import Glossary from './app/components/Glossary';
34

45
// use this function to get MDX components, you will need it for rendering MDX
56
export function getMDXComponents(components?: MDXComponents): MDXComponents {
67
return {
78
...defaultMdxComponents,
9+
glossary: Glossary,
810
...components,
911
};
1012
}

0 commit comments

Comments
 (0)