@inf-monkeys-tech/monkeys-design 2.0.439 → 2.0.440
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{I18nSubMenu-MDIVPB3E.mjs → I18nSubMenu-7S5TO2WP.mjs} +1 -1
- package/dist/{I18nSubMenu-RTTG52OF.mjs → I18nSubMenu-G3GNE6ZR.mjs} +1 -1
- package/dist/{I18nSubMenu-BY5IGIDZ.js → I18nSubMenu-KKGFUUP4.js} +1 -1
- package/dist/I18nSubMenu-ZBYCK4XW.js +1 -0
- package/dist/{chunk-XMSQGUUG.mjs → chunk-2V4F4RF6.mjs} +1 -1
- package/dist/{chunk-7642OAHR.js → chunk-C3AKQ57B.js} +1 -1
- package/dist/chunk-ICHXWGKE.js +1 -0
- package/dist/chunk-IIAHYZLC.mjs +1 -0
- package/dist/{chunk-2VPEGVKU.mjs → chunk-M5WO5C64.mjs} +1 -1
- package/dist/{chunk-WYV5KVTD.js → chunk-P2CNUNQD.js} +1 -1
- package/dist/components/assembly/index.js +1 -1
- package/dist/components/assembly/index.mjs +1 -1
- package/dist/components/assembly/runtime.js +1 -1
- package/dist/components/assembly/runtime.mjs +1 -1
- package/dist/components/assembly/validation.js +1 -1
- package/dist/components/assembly/validation.mjs +1 -1
- package/dist/components/toolbar/index.d.mts +10 -14
- package/dist/components/toolbar/index.d.ts +10 -14
- package/dist/components/toolbar/index.js +18 -10
- package/dist/components/toolbar/index.js.map +1 -1
- package/dist/components/toolbar/index.mjs +16 -6
- package/dist/components/toolbar/index.mjs.map +1 -1
- package/dist/index.js +249 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -19
- package/dist/index.mjs.map +1 -1
- package/dist/sources/3d0ca7e865e271c3c07d8e989171cec7aa332e58e3be65528a48505551b74e4c.tsx +132 -0
- package/dist/sources/f77b4bc374bfc17968c1cba04c235fb96c18fe47f7a9f656e01c04ff064a27dd.tsx +131 -0
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/dist/I18nSubMenu-COEFAU6S.js +0 -1
- package/dist/chunk-L4JHU5HD.js +0 -1
- package/dist/chunk-TJWWFSDW.mjs +0 -1
- package/dist/sources/8239c27056c1a7c1d308d0f576e5580306a697197a7056adbd8a57ce8b89a660.tsx +0 -174
- package/dist/sources/e12214d74e4f69bbcc7ca180b77a4e64caeed5ffa953eb30d6343f11b9adeede.tsx +0 -241
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inf-monkeys-tech/monkeys-design",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.440",
|
|
4
4
|
"description": "Monkeys Design Components Library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -380,5 +380,5 @@
|
|
|
380
380
|
],
|
|
381
381
|
"license": "MIT",
|
|
382
382
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
|
|
383
|
-
"monkeysReleaseCommit": "
|
|
383
|
+
"monkeysReleaseCommit": "4d5747f50a0bb14033b44304eaf7b495aa8f98f6"
|
|
384
384
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var chunkL4JHU5HD_js=require('./chunk-L4JHU5HD.js');Object.defineProperty(exports,"default",{enumerable:true,get:function(){return chunkL4JHU5HD_js.g}});Object.defineProperty(exports,"exports",{enumerable:true,get:function(){return chunkL4JHU5HD_js.e}});Object.defineProperty(exports,"id",{enumerable:true,get:function(){return chunkL4JHU5HD_js.b}});Object.defineProperty(exports,"props",{enumerable:true,get:function(){return chunkL4JHU5HD_js.f}});Object.defineProperty(exports,"source",{enumerable:true,get:function(){return chunkL4JHU5HD_js.d}});Object.defineProperty(exports,"stateBindings",{enumerable:true,get:function(){return chunkL4JHU5HD_js.a}});Object.defineProperty(exports,"version",{enumerable:true,get:function(){return chunkL4JHU5HD_js.c}});
|
package/dist/chunk-L4JHU5HD.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var n=[],r="I18nSubMenu",e=1,t="src/components/toolbar/I18nSelector.tsx",s=[{entrypoint:"./components/toolbar",export:"I18nSubMenu"}],c=["prop6880","prop90","prop6881","prop6882"],i={stateBindings:n,id:r,version:e,source:t,exports:s,props:c};exports.a=n;exports.b=r;exports.c=e;exports.d=t;exports.e=s;exports.f=c;exports.g=i;
|
package/dist/chunk-TJWWFSDW.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var n=[],r="I18nSubMenu",e=1,t="src/components/toolbar/I18nSelector.tsx",s=[{entrypoint:"./components/toolbar",export:"I18nSubMenu"}],c=["prop6880","prop90","prop6881","prop6882"],i={stateBindings:n,id:r,version:e,source:t,exports:s,props:c};export{n as a,r as b,e as c,t as d,s as e,c as f,i as g};
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
|
|
3
|
-
import * as Tooltip from '@radix-ui/react-tooltip';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
useMonkeysComponentAttributes,
|
|
7
|
-
useMonkeysLocale,
|
|
8
|
-
} from '../../provider/context';
|
|
9
|
-
|
|
10
|
-
function cn(...inputs: (string | undefined | null | false)[]): string {
|
|
11
|
-
return inputs.filter(Boolean).join(' ');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// ---------- Inline SVG Icon ----------
|
|
15
|
-
|
|
16
|
-
function GlobeIcon({ className }: { className?: string }) {
|
|
17
|
-
return (
|
|
18
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}>
|
|
19
|
-
<circle cx="12" cy="12" r="10" />
|
|
20
|
-
<path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" />
|
|
21
|
-
<path d="M2 12h20" />
|
|
22
|
-
</svg>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// ---------- Component ----------
|
|
27
|
-
|
|
28
|
-
export interface I18nLanguage {
|
|
29
|
-
code: string;
|
|
30
|
-
label: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface I18nSelectorProps {
|
|
34
|
-
languages: I18nLanguage[];
|
|
35
|
-
currentLanguage: string;
|
|
36
|
-
onLanguageChange: (code: string) => void;
|
|
37
|
-
tooltip?: string;
|
|
38
|
-
className?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function I18nSelector({
|
|
42
|
-
languages,
|
|
43
|
-
currentLanguage,
|
|
44
|
-
onLanguageChange,
|
|
45
|
-
tooltip,
|
|
46
|
-
className,
|
|
47
|
-
}: I18nSelectorProps) {
|
|
48
|
-
const locale = useMonkeysLocale();
|
|
49
|
-
const componentAttributes = useMonkeysComponentAttributes();
|
|
50
|
-
const trigger = (
|
|
51
|
-
<DropdownMenu.Trigger asChild>
|
|
52
|
-
<button
|
|
53
|
-
{...componentAttributes}
|
|
54
|
-
className={cn(
|
|
55
|
-
'inline-flex h-8 w-8 items-center justify-center rounded-md text-[hsl(var(--foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] transition-colors focus-visible:outline-hidden',
|
|
56
|
-
className,
|
|
57
|
-
)}
|
|
58
|
-
>
|
|
59
|
-
<GlobeIcon />
|
|
60
|
-
<span className="sr-only">
|
|
61
|
-
{tooltip ?? locale.messages.toolbar.language.switch}
|
|
62
|
-
</span>
|
|
63
|
-
</button>
|
|
64
|
-
</DropdownMenu.Trigger>
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<DropdownMenu.Root>
|
|
69
|
-
{tooltip ? (
|
|
70
|
-
<Tooltip.Provider delayDuration={300}>
|
|
71
|
-
<Tooltip.Root>
|
|
72
|
-
<Tooltip.Trigger asChild>{trigger}</Tooltip.Trigger>
|
|
73
|
-
<Tooltip.Portal>
|
|
74
|
-
<Tooltip.Content
|
|
75
|
-
className="rounded-md bg-[hsl(var(--popover))] px-3 py-1.5 text-xs text-[hsl(var(--popover-foreground))] shadow-md border border-[hsl(var(--border))] animate-in fade-in-0 zoom-in-95"
|
|
76
|
-
sideOffset={5}
|
|
77
|
-
>
|
|
78
|
-
{tooltip}
|
|
79
|
-
<Tooltip.Arrow className="fill-[hsl(var(--popover))]" />
|
|
80
|
-
</Tooltip.Content>
|
|
81
|
-
</Tooltip.Portal>
|
|
82
|
-
</Tooltip.Root>
|
|
83
|
-
</Tooltip.Provider>
|
|
84
|
-
) : (
|
|
85
|
-
trigger
|
|
86
|
-
)}
|
|
87
|
-
|
|
88
|
-
<DropdownMenu.Portal>
|
|
89
|
-
<DropdownMenu.Content
|
|
90
|
-
className="z-50 min-w-[8rem] rounded-md border border-[hsl(var(--border))] bg-[hsl(var(--popover))] p-1 text-[hsl(var(--popover-foreground))] shadow-md animate-in fade-in-0 zoom-in-95"
|
|
91
|
-
sideOffset={5}
|
|
92
|
-
align="end"
|
|
93
|
-
>
|
|
94
|
-
{languages.map(({ code, label }) => (
|
|
95
|
-
<DropdownMenu.Item
|
|
96
|
-
key={code}
|
|
97
|
-
className={cn(
|
|
98
|
-
'relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))]',
|
|
99
|
-
currentLanguage === code && 'bg-[hsl(var(--accent))]',
|
|
100
|
-
)}
|
|
101
|
-
onSelect={() => onLanguageChange(code)}
|
|
102
|
-
>
|
|
103
|
-
{label}
|
|
104
|
-
</DropdownMenu.Item>
|
|
105
|
-
))}
|
|
106
|
-
</DropdownMenu.Content>
|
|
107
|
-
</DropdownMenu.Portal>
|
|
108
|
-
</DropdownMenu.Root>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ---------- Sub-menu variant (for embedding in user dropdown) ----------
|
|
113
|
-
|
|
114
|
-
export interface I18nSubMenuProps {
|
|
115
|
-
languages: I18nLanguage[];
|
|
116
|
-
currentLanguage: string;
|
|
117
|
-
onLanguageChange: (code: string) => void;
|
|
118
|
-
label?: string;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* A DropdownMenuSub component for embedding language selector
|
|
123
|
-
* inside a Radix DropdownMenu (e.g. user avatar menu).
|
|
124
|
-
* Must be rendered as a child of DropdownMenu.Group / DropdownMenu.Content.
|
|
125
|
-
*/
|
|
126
|
-
export function I18nSubMenu({
|
|
127
|
-
languages,
|
|
128
|
-
currentLanguage,
|
|
129
|
-
onLanguageChange,
|
|
130
|
-
label,
|
|
131
|
-
}: I18nSubMenuProps) {
|
|
132
|
-
const locale = useMonkeysLocale();
|
|
133
|
-
const componentAttributes = useMonkeysComponentAttributes();
|
|
134
|
-
const fallbackLabel = locale.provided
|
|
135
|
-
? locale.messages.toolbar.language.label
|
|
136
|
-
: '语言';
|
|
137
|
-
const currentLabel = languages.find((l) => l.code === currentLanguage)?.label ?? currentLanguage;
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<DropdownMenu.Sub>
|
|
141
|
-
<DropdownMenu.SubTrigger
|
|
142
|
-
{...componentAttributes}
|
|
143
|
-
className="relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] data-[state=open]:bg-[hsl(var(--accent))]"
|
|
144
|
-
>
|
|
145
|
-
<GlobeIcon className="h-4 w-4" />
|
|
146
|
-
<span>{label ?? fallbackLabel}</span>
|
|
147
|
-
<span className="ml-auto text-xs text-[hsl(var(--muted-foreground))]">{currentLabel}</span>
|
|
148
|
-
</DropdownMenu.SubTrigger>
|
|
149
|
-
<DropdownMenu.Portal>
|
|
150
|
-
<DropdownMenu.SubContent
|
|
151
|
-
className="z-50 min-w-[8rem] rounded-md border border-[hsl(var(--border))] bg-[hsl(var(--popover))] p-1 text-[hsl(var(--popover-foreground))] shadow-md animate-in fade-in-0 zoom-in-95"
|
|
152
|
-
sideOffset={8}
|
|
153
|
-
>
|
|
154
|
-
{languages.map(({ code, label: langLabel }) => (
|
|
155
|
-
<DropdownMenu.CheckboxItem
|
|
156
|
-
key={code}
|
|
157
|
-
checked={currentLanguage === code}
|
|
158
|
-
disabled={currentLanguage === code}
|
|
159
|
-
className={cn(
|
|
160
|
-
'relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 pl-7 text-sm outline-hidden transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
161
|
-
)}
|
|
162
|
-
onCheckedChange={() => onLanguageChange(code)}
|
|
163
|
-
>
|
|
164
|
-
<DropdownMenu.ItemIndicator className="absolute left-2 inline-flex items-center justify-center">
|
|
165
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M20 6 9 17l-5-5"/></svg>
|
|
166
|
-
</DropdownMenu.ItemIndicator>
|
|
167
|
-
{langLabel}
|
|
168
|
-
</DropdownMenu.CheckboxItem>
|
|
169
|
-
))}
|
|
170
|
-
</DropdownMenu.SubContent>
|
|
171
|
-
</DropdownMenu.Portal>
|
|
172
|
-
</DropdownMenu.Sub>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
|
|
3
|
-
import * as Tooltip from '@radix-ui/react-tooltip';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
useMonkeysComponentAttributes,
|
|
7
|
-
useMonkeysLocale,
|
|
8
|
-
} from '../../provider/context';
|
|
9
|
-
|
|
10
|
-
function cn(...inputs: (string | undefined | null | false)[]): string {
|
|
11
|
-
return inputs.filter(Boolean).join(' ');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// ---------- Inline SVG Icons ----------
|
|
15
|
-
|
|
16
|
-
function SunIcon({ className }: { className?: string }) {
|
|
17
|
-
return (
|
|
18
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}>
|
|
19
|
-
<circle cx="12" cy="12" r="4" />
|
|
20
|
-
<path d="M12 2v2" /><path d="M12 20v2" />
|
|
21
|
-
<path d="m4.93 4.93 1.41 1.41" /><path d="m17.66 17.66 1.41 1.41" />
|
|
22
|
-
<path d="M2 12h2" /><path d="M20 12h2" />
|
|
23
|
-
<path d="m6.34 17.66-1.41 1.41" /><path d="m19.07 4.93-1.41 1.41" />
|
|
24
|
-
</svg>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function MoonIcon({ className }: { className?: string }) {
|
|
29
|
-
return (
|
|
30
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}>
|
|
31
|
-
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
|
32
|
-
</svg>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function MonitorIcon({ className }: { className?: string }) {
|
|
37
|
-
return (
|
|
38
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}>
|
|
39
|
-
<rect width="20" height="14" x="2" y="3" rx="2" />
|
|
40
|
-
<line x1="8" x2="16" y1="21" y2="21" />
|
|
41
|
-
<line x1="12" x2="12" y1="17" y2="21" />
|
|
42
|
-
</svg>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ---------- Component ----------
|
|
47
|
-
|
|
48
|
-
export type DarkModeValue = 'auto' | 'light' | 'dark';
|
|
49
|
-
|
|
50
|
-
export interface DarkModeSelectorProps {
|
|
51
|
-
mode: DarkModeValue;
|
|
52
|
-
onModeChange: (mode: DarkModeValue) => void;
|
|
53
|
-
labels?: { auto?: string; light?: string; dark?: string };
|
|
54
|
-
tooltip?: string;
|
|
55
|
-
className?: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const triggerIconMap: Record<DarkModeValue, React.FC<{ className?: string }>> = {
|
|
59
|
-
light: SunIcon,
|
|
60
|
-
dark: MoonIcon,
|
|
61
|
-
auto: MonitorIcon,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export function DarkModeSelector({
|
|
65
|
-
mode,
|
|
66
|
-
onModeChange,
|
|
67
|
-
labels = {},
|
|
68
|
-
tooltip,
|
|
69
|
-
className,
|
|
70
|
-
}: DarkModeSelectorProps) {
|
|
71
|
-
const locale = useMonkeysLocale();
|
|
72
|
-
const componentAttributes = useMonkeysComponentAttributes();
|
|
73
|
-
const localeLabels = locale.messages.toolbar.theme;
|
|
74
|
-
const TriggerIcon = triggerIconMap[mode];
|
|
75
|
-
const resolvedLabels = {
|
|
76
|
-
auto: labels.auto ?? localeLabels.auto,
|
|
77
|
-
light: labels.light ?? localeLabels.light,
|
|
78
|
-
dark: labels.dark ?? localeLabels.dark,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const options: { value: DarkModeValue; label: string; Icon: React.FC<{ className?: string }> }[] = [
|
|
82
|
-
{ value: 'auto', label: resolvedLabels.auto, Icon: MonitorIcon },
|
|
83
|
-
{ value: 'light', label: resolvedLabels.light, Icon: SunIcon },
|
|
84
|
-
{ value: 'dark', label: resolvedLabels.dark, Icon: MoonIcon },
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
const trigger = (
|
|
88
|
-
<DropdownMenu.Trigger asChild>
|
|
89
|
-
<button
|
|
90
|
-
{...componentAttributes}
|
|
91
|
-
className={cn(
|
|
92
|
-
'inline-flex h-8 w-8 items-center justify-center rounded-md text-[hsl(var(--foreground))] hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] transition-colors focus-visible:outline-hidden',
|
|
93
|
-
className,
|
|
94
|
-
)}
|
|
95
|
-
>
|
|
96
|
-
<TriggerIcon />
|
|
97
|
-
<span className="sr-only">{tooltip ?? localeLabels.toggle}</span>
|
|
98
|
-
</button>
|
|
99
|
-
</DropdownMenu.Trigger>
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
return (
|
|
103
|
-
<DropdownMenu.Root>
|
|
104
|
-
{tooltip ? (
|
|
105
|
-
<Tooltip.Provider delayDuration={300}>
|
|
106
|
-
<Tooltip.Root>
|
|
107
|
-
<Tooltip.Trigger asChild>{trigger}</Tooltip.Trigger>
|
|
108
|
-
<Tooltip.Portal>
|
|
109
|
-
<Tooltip.Content
|
|
110
|
-
className="rounded-md bg-[hsl(var(--popover))] px-3 py-1.5 text-xs text-[hsl(var(--popover-foreground))] shadow-md border border-[hsl(var(--border))] animate-in fade-in-0 zoom-in-95"
|
|
111
|
-
sideOffset={5}
|
|
112
|
-
>
|
|
113
|
-
{tooltip}
|
|
114
|
-
<Tooltip.Arrow className="fill-[hsl(var(--popover))]" />
|
|
115
|
-
</Tooltip.Content>
|
|
116
|
-
</Tooltip.Portal>
|
|
117
|
-
</Tooltip.Root>
|
|
118
|
-
</Tooltip.Provider>
|
|
119
|
-
) : (
|
|
120
|
-
trigger
|
|
121
|
-
)}
|
|
122
|
-
|
|
123
|
-
<DropdownMenu.Portal>
|
|
124
|
-
<DropdownMenu.Content
|
|
125
|
-
className="z-50 min-w-[8rem] rounded-md border border-[hsl(var(--border))] bg-[hsl(var(--popover))] p-1 text-[hsl(var(--popover-foreground))] shadow-md animate-in fade-in-0 zoom-in-95"
|
|
126
|
-
sideOffset={5}
|
|
127
|
-
align="end"
|
|
128
|
-
>
|
|
129
|
-
{options.map(({ value, label, Icon }) => (
|
|
130
|
-
<DropdownMenu.Item
|
|
131
|
-
key={value}
|
|
132
|
-
className={cn(
|
|
133
|
-
'relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))]',
|
|
134
|
-
mode === value && 'bg-[hsl(var(--accent))]',
|
|
135
|
-
)}
|
|
136
|
-
onSelect={() => onModeChange(value)}
|
|
137
|
-
>
|
|
138
|
-
<Icon className="h-4 w-4" />
|
|
139
|
-
{label}
|
|
140
|
-
</DropdownMenu.Item>
|
|
141
|
-
))}
|
|
142
|
-
</DropdownMenu.Content>
|
|
143
|
-
</DropdownMenu.Portal>
|
|
144
|
-
</DropdownMenu.Root>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// ---------- Sub-menu variant (for embedding in user dropdown) ----------
|
|
149
|
-
|
|
150
|
-
function SunMoonIcon({ className }: { className?: string }) {
|
|
151
|
-
return (
|
|
152
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" className={className}>
|
|
153
|
-
<path d="M12 8a2.83 2.83 0 0 0 4 4 4 4 0 1 1-4-4" />
|
|
154
|
-
<path d="M12 2v2" /><path d="M12 20v2" />
|
|
155
|
-
<path d="m4.9 4.9 1.4 1.4" /><path d="m17.7 17.7 1.4 1.4" />
|
|
156
|
-
<path d="M2 12h2" /><path d="M20 12h2" />
|
|
157
|
-
<path d="m6.3 17.7-1.4 1.4" /><path d="m19.1 4.9-1.4 1.4" />
|
|
158
|
-
</svg>
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export interface DarkModeSubMenuProps {
|
|
163
|
-
mode: DarkModeValue;
|
|
164
|
-
onModeChange: (mode: DarkModeValue) => void;
|
|
165
|
-
label?: string;
|
|
166
|
-
labels?: { auto?: string; light?: string; dark?: string };
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* A DropdownMenuSub component for embedding dark mode selector
|
|
171
|
-
* inside a Radix DropdownMenu (e.g. user avatar menu).
|
|
172
|
-
* Must be rendered as a child of DropdownMenu.Group / DropdownMenu.Content.
|
|
173
|
-
*/
|
|
174
|
-
export function DarkModeSubMenu({
|
|
175
|
-
mode,
|
|
176
|
-
onModeChange,
|
|
177
|
-
label,
|
|
178
|
-
labels = {},
|
|
179
|
-
}: DarkModeSubMenuProps) {
|
|
180
|
-
const locale = useMonkeysLocale();
|
|
181
|
-
const componentAttributes = useMonkeysComponentAttributes();
|
|
182
|
-
const localeLabels = locale.messages.toolbar.theme;
|
|
183
|
-
const fallbackLabels = locale.provided
|
|
184
|
-
? localeLabels
|
|
185
|
-
: {
|
|
186
|
-
label: '外观',
|
|
187
|
-
auto: '跟随系统',
|
|
188
|
-
light: '浅色模式',
|
|
189
|
-
dark: '深色模式',
|
|
190
|
-
};
|
|
191
|
-
const resolvedLabels = {
|
|
192
|
-
auto: labels.auto ?? fallbackLabels.auto,
|
|
193
|
-
light: labels.light ?? fallbackLabels.light,
|
|
194
|
-
dark: labels.dark ?? fallbackLabels.dark,
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const currentLabel = mode === 'auto' ? resolvedLabels.auto : mode === 'dark' ? resolvedLabels.dark : resolvedLabels.light;
|
|
198
|
-
|
|
199
|
-
const options: { value: DarkModeValue; label: string; Icon: React.FC<{ className?: string }> }[] = [
|
|
200
|
-
{ value: 'auto', label: resolvedLabels.auto, Icon: MonitorIcon },
|
|
201
|
-
{ value: 'light', label: resolvedLabels.light, Icon: SunIcon },
|
|
202
|
-
{ value: 'dark', label: resolvedLabels.dark, Icon: MoonIcon },
|
|
203
|
-
];
|
|
204
|
-
|
|
205
|
-
return (
|
|
206
|
-
<DropdownMenu.Sub>
|
|
207
|
-
<DropdownMenu.SubTrigger
|
|
208
|
-
{...componentAttributes}
|
|
209
|
-
className="relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] data-[state=open]:bg-[hsl(var(--accent))]"
|
|
210
|
-
>
|
|
211
|
-
<SunMoonIcon className="h-4 w-4" />
|
|
212
|
-
<span>{label ?? fallbackLabels.label}</span>
|
|
213
|
-
<span className="ml-auto text-xs text-[hsl(var(--muted-foreground))]">{currentLabel}</span>
|
|
214
|
-
</DropdownMenu.SubTrigger>
|
|
215
|
-
<DropdownMenu.Portal>
|
|
216
|
-
<DropdownMenu.SubContent
|
|
217
|
-
className="z-50 min-w-[8rem] rounded-md border border-[hsl(var(--border))] bg-[hsl(var(--popover))] p-1 text-[hsl(var(--popover-foreground))] shadow-md animate-in fade-in-0 zoom-in-95"
|
|
218
|
-
sideOffset={8}
|
|
219
|
-
>
|
|
220
|
-
{options.map(({ value, label: optLabel, Icon }) => (
|
|
221
|
-
<DropdownMenu.CheckboxItem
|
|
222
|
-
key={value}
|
|
223
|
-
checked={mode === value}
|
|
224
|
-
disabled={mode === value}
|
|
225
|
-
className={cn(
|
|
226
|
-
'relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 pl-7 text-sm outline-hidden transition-colors hover:bg-[hsl(var(--accent))] hover:text-[hsl(var(--accent-foreground))] data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
227
|
-
)}
|
|
228
|
-
onCheckedChange={() => onModeChange(value)}
|
|
229
|
-
>
|
|
230
|
-
<DropdownMenu.ItemIndicator className="absolute left-2 inline-flex items-center justify-center">
|
|
231
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M20 6 9 17l-5-5"/></svg>
|
|
232
|
-
</DropdownMenu.ItemIndicator>
|
|
233
|
-
<Icon className="h-4 w-4" />
|
|
234
|
-
{optLabel}
|
|
235
|
-
</DropdownMenu.CheckboxItem>
|
|
236
|
-
))}
|
|
237
|
-
</DropdownMenu.SubContent>
|
|
238
|
-
</DropdownMenu.Portal>
|
|
239
|
-
</DropdownMenu.Sub>
|
|
240
|
-
);
|
|
241
|
-
}
|