11'use client' ;
22
3- import { ActionButton , Menu , MenuItem , MenuTrigger , Text , ToastQueue } from '@react-spectrum/s2' ;
3+ import { ActionButton , Menu , MenuItem , MenuSection , MenuTrigger , SubmenuTrigger , Text , ToastQueue } from '@react-spectrum/s2' ;
44import CheckmarkCircle from '@react-spectrum/s2/icons/CheckmarkCircle' ;
5+ import { type ColorSchemePreference , useSettings } from './SettingsContext' ;
6+ import Contrast from '@react-spectrum/s2/icons/Contrast' ;
57import Copy from '@react-spectrum/s2/icons/Copy' ;
8+ import DeviceDesktop from '@react-spectrum/s2/icons/DeviceDesktop' ;
69import { getLibraryFromUrl , getLibraryLabel } from './library' ;
10+ import Lighten from '@react-spectrum/s2/icons/Lighten' ;
711import More from '@react-spectrum/s2/icons/More' ;
812import React , { useCallback , useEffect , useRef , useState } from 'react' ;
913import { style } from '@react-spectrum/s2/style' with { type : 'macro' } ;
1014
15+ const colorSchemeLabels : Record < ColorSchemePreference , string > = {
16+ system : 'System' ,
17+ light : 'Light' ,
18+ dark : 'Dark'
19+ } ;
20+
1121interface MarkdownMenuProps {
1222 name : string ,
1323 url : string | undefined
@@ -18,6 +28,7 @@ export function MarkdownMenu({name, url}: MarkdownMenuProps) {
1828 let [ isCopied , setIsCopied ] = useState ( false ) ;
1929 let [ isPending , setPending ] = useState ( false ) ;
2030 let timeout = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
31+ let { colorScheme, setColorScheme} = useSettings ( ) ;
2132
2233 let pageUrl = typeof window !== 'undefined' && url ? new URL ( url , window . location . origin ) . href : url ?? '' ;
2334 let fullMdUrl = typeof window !== 'undefined' && mdUrl ? new URL ( mdUrl , window . location . origin ) . href : mdUrl ;
@@ -26,6 +37,8 @@ export function MarkdownMenu({name, url}: MarkdownMenuProps) {
2637 let chatGptUrl = `https://chatgpt.com/?q=${ encodeURIComponent ( aiPrompt ) } ` ;
2738 let claudeUrl = `https://claude.ai/new?q=${ encodeURIComponent ( aiPrompt ) } ` ;
2839
40+ let colorSchemeLabel = colorSchemeLabels [ colorScheme ] ;
41+
2942 useEffect ( ( ) => {
3043 return ( ) => {
3144 if ( timeout . current ) {
@@ -67,15 +80,42 @@ export function MarkdownMenu({name, url}: MarkdownMenuProps) {
6780 < More />
6881 </ ActionButton >
6982 < Menu >
70- < MenuItem id = "view" href = { mdUrl } target = "_blank" >
71- View as Markdown
72- </ MenuItem >
73- < MenuItem id = "chatgpt" href = { chatGptUrl } target = "_blank" >
74- Open in ChatGPT
75- </ MenuItem >
76- < MenuItem id = "claude" href = { claudeUrl } target = "_blank" >
77- Open in Claude
78- </ MenuItem >
83+ < MenuSection >
84+ < MenuItem id = "view" href = { mdUrl } target = "_blank" >
85+ View as Markdown
86+ </ MenuItem >
87+ < MenuItem id = "chatgpt" href = { chatGptUrl } target = "_blank" >
88+ Open in ChatGPT
89+ </ MenuItem >
90+ < MenuItem id = "claude" href = { claudeUrl } target = "_blank" >
91+ Open in Claude
92+ </ MenuItem >
93+ </ MenuSection >
94+ < MenuSection >
95+ < SubmenuTrigger >
96+ < MenuItem >
97+ < Text slot = "label" > Color Scheme</ Text >
98+ < Text slot = "value" > { colorSchemeLabel } </ Text >
99+ </ MenuItem >
100+ < Menu
101+ selectionMode = "single"
102+ selectedKeys = { [ colorScheme ] }
103+ onSelectionChange = { ( keys ) => setColorScheme ( [ ...keys ] [ 0 ] as ColorSchemePreference ) } >
104+ < MenuItem id = "system" >
105+ < DeviceDesktop />
106+ < Text slot = "label" > System</ Text >
107+ </ MenuItem >
108+ < MenuItem id = "light" >
109+ < Lighten />
110+ < Text slot = "label" > Light</ Text >
111+ </ MenuItem >
112+ < MenuItem id = "dark" >
113+ < Contrast />
114+ < Text slot = "label" > Dark</ Text >
115+ </ MenuItem >
116+ </ Menu >
117+ </ SubmenuTrigger >
118+ </ MenuSection >
79119 </ Menu >
80120 </ MenuTrigger >
81121 </ div >
0 commit comments