Skip to content

Commit 8084e3a

Browse files
committed
fix: code
1 parent 8c07f2a commit 8084e3a

5 files changed

Lines changed: 60 additions & 34 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767

6868
- name: Build the components registry and website
6969
run: |
70-
yarn registry:build
70+
yarn registry
7171
./node_modules/.bin/interact build --confPath=${{ env.APP_DIR }}
7272
7373
# actions/deploy-pages expect a zip

apps/site/pages/components/page-menu-button.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ The `PageMenuButton` component is a component that permits to:
2020
* show or copy an alternate version of your pages such as [Markdown](../reference/ai.md#markdown-format-for-all-pages)
2121
* open your page in a [AI chatbot](../reference/ai.md)
2222

23-
This component is used by default in the [Hero partial](../reference/layout.md#partials).
2423

2524
## Variants
2625

@@ -98,3 +97,10 @@ An action component to be used as trigger or menu item should accepts the `hideS
9897
| `render` | A anchor or button element to render as button |
9998
| `query` | The query to send to the chatbot |
10099
| `variant` | The variant (`default` or `split`) |
100+
101+
## Usage and Distribution
102+
103+
This component is used by default in the [Hero partial](../reference/layout.md#partials).
104+
105+
You can install it for customization from our [shadcn registry](../reference/registry.md) with the name `@interact/PageMenuButton`.
106+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"site": "cd ../../gerardnico/com-gerardnico && node_modules/@combostrap/interact/src/interact/cli/dev.js start",
1818
"ssg": "src/interact/cli/dev.js build --confPath=apps/site",
1919
"preview": "src/interact/cli/dev.js preview --confPath=apps/site",
20-
"registry:build": "shadcn build --output apps/site/public/r"
20+
"registry": "shadcn build --output apps/site/public/r"
2121
},
2222
"files": [
2323
"dist/interact/**/*",

registry.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@
6161
]
6262
}
6363
]
64+
},
65+
{
66+
"name": "PageMenuButton",
67+
"title": "Page Menu Button",
68+
"type": "registry:component",
69+
"description": "Page Menu Button that permits to Copy as, Open In Chat",
70+
"files": [
71+
{
72+
"path": "src/resources/components/interact/PageMenuButton.tsx",
73+
"target": "components/interact/PageMenuButton.tsx",
74+
"type": "registry:component"
75+
}
76+
]
6477
}
6578
]
6679
}

src/resources/components/interact/Code.tsx

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React, {useState, useEffect, useRef, useCallback} from "react";
44
import clsx from "clsx";
55
import styles from "./code.module.css"
6+
import {cn} from "@/lib/utils";
67

78
declare global {
89
interface Window {
@@ -227,7 +228,7 @@ export default function Code({
227228
const [lineNums, setLineNums] = useState(lineNumbers);
228229
const [wrap, setWrap] = useState(wordWrap);
229230
const [copied, setCopied] = useState(false);
230-
const [ready, setReady] = useState(false);
231+
const [ready, setReady] = useState(false); // loaded?
231232

232233
const codeRef = useRef<HTMLElement>(null);
233234

@@ -246,26 +247,29 @@ export default function Code({
246247

247248
// Load Prism + plugins + language, then highlight
248249
const highlight = useCallback(async () => {
249-
await loadPrismCore();
250+
let prismLoaded = codeRef.current && window.Prism;
251+
if (!prismLoaded) {
252+
await loadPrismCore();
250253

251-
// autoloader is needed to load the language dependencies
252-
// example: tsx depends on ts
253-
await loadPrismPlugin("autoloader", false);
254+
// autoloader is needed to load the language dependencies
255+
// example: tsx depends on ts
256+
await loadPrismPlugin("autoloader", false);
254257

255-
if (lineNums) await loadPrismPlugin("line-numbers");
256-
257-
if (codeRef.current && window.Prism) {
258-
setReady(true);
259-
// Small tick so DOM is painted with new class
260-
requestAnimationFrame(() => {
261-
if (codeRef.current) window.Prism.highlightElement(codeRef.current);
262-
});
258+
if (lineNums) await loadPrismPlugin("line-numbers");
263259
}
260+
261+
setReady(true);
262+
263+
// Small tick so DOM is painted with new class
264+
requestAnimationFrame(() => {
265+
if (codeRef.current) window.Prism.highlightElement(codeRef.current);
266+
});
264267
}, [currentLang, lineNums]);
265268

269+
let currentHref = typeof window !== "undefined" ? window.location.href : undefined;
266270
useEffect(() => {
267-
highlight();
268-
}, [highlight]);
271+
highlight().then(() => "");
272+
}, [highlight, currentHref]); // should trigger for every new page
269273

270274

271275
let code: string | null = null;
@@ -298,7 +302,6 @@ export default function Code({
298302

299303
const shell: React.CSSProperties = {
300304
fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace",
301-
borderRadius: "12px",
302305
overflow: "hidden",
303306
border: isLight ? "1px solid #e2e8f0" : "1px solid rgba(255,255,255,0.07)",
304307
background: isLight ? "#f8fafc" : "#0d1117",
@@ -418,7 +421,7 @@ export default function Code({
418421
letterSpacing: "0.02em",
419422
};
420423

421-
424+
let roundedValue = "xl"
422425
return (
423426
<>
424427
{/* Google Font for JetBrains Mono */}
@@ -428,7 +431,7 @@ export default function Code({
428431
/>
429432

430433
<div className={
431-
clsx("position-relative",
434+
cn("relative", `rounded-${roundedValue}`,
432435
styles["shell"]
433436
)} style={shell} {...rest}>
434437
{/* ── Toolbar ── */}
@@ -487,29 +490,33 @@ export default function Code({
487490
</div>
488491
</>
489492
)}
490-
<div className={
491-
clsx(
492-
"position-absolute top-0 end-0 p-2 print:hidden",
493-
styles["showOnHover"]
494-
)}
495-
>
496-
<span style={langBadge}>{currentLang}</span>
497-
<button style={copyBtnStyle} onClick={handleCopy}>{copied ? "✓ Copied" : "⎘ Copy"}</button>
498-
</div>
499493
{/* ── Code Block ── */}
500494
<pre
501495
className={clsx(
502496
lineNums ?? "line-numbers",
503-
styles["preStyle"]
497+
styles["preStyle"],
498+
"relative",
504499
)}
505500
>
506-
<code
501+
<div className={
502+
cn(
503+
"absolute top-0 end-0 p-2 print:hidden bg-background",
504+
`rounded-tr-${roundedValue}`,
505+
`rounded-bl-${roundedValue}`,
506+
roundedValue,
507+
styles["showOnHover"],
508+
)}
509+
>
510+
<span style={langBadge}>{currentLang}</span>
511+
<button style={copyBtnStyle} onClick={handleCopy}>{copied ? "✓ Copied" : "⎘ Copy"}</button>
512+
</div>
513+
<code
507514
ref={codeRef}
508515
className={`language-${currentLang}`}
509516
style={{opacity: ready ? 1 : 0.4, transition: "opacity 0.2s"}}
510-
>
517+
>
511518
{code}
512-
</code>
519+
</code>
513520
</pre>
514521
</div>
515522
</>

0 commit comments

Comments
 (0)