Skip to content

Commit 2d7a050

Browse files
committed
feat: add MessagePlacementSelector
1 parent cb198e5 commit 2d7a050

File tree

12 files changed

+240
-83
lines changed

12 files changed

+240
-83
lines changed

src/shared/components/Button.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export function Button({
7878
}: ButtonProps) {
7979
const { theme } = useTheme();
8080

81-
// 缓存计算结果以避免重复计算
8281
const variantStyles = (() => {
8382
const variantConfig = buttonVariants[variant];
8483
return typeof variantConfig === "function" ? variantConfig(theme) : variantConfig;

src/shared/components/LanguageSelector.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ export function LanguageSelector({ className, style }: LanguageSelectorProps) {
1919
{ value: "en", label: "English" },
2020
];
2121

22-
const handleLanguageChange = (value: string) => {
23-
setLocale(value as Locale);
24-
};
25-
2622
return (
2723
<div
2824
className={className}
@@ -38,7 +34,7 @@ export function LanguageSelector({ className, style }: LanguageSelectorProps) {
3834
>
3935
{t("common.language")}:
4036
</label>
41-
<Select value={locale} options={languages} onChange={handleLanguageChange} />
37+
<Select value={locale} options={languages} onChange={(value) => setLocale(value as Locale)} />
4238
</div>
4339
);
4440
}

src/shared/components/Message.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,24 @@ const MessageContainer = styled("div")`
3434
}
3535
3636
&.message-success {
37-
background-color: rgba(34, 197, 94, 0.4);
38-
border: 1px solid rgba(34, 197, 94, 0.7);
37+
--msg-color: 34, 197, 94;
3938
}
4039
4140
&.message-error {
42-
background-color: rgba(239, 68, 68, 0.4);
43-
border: 1px solid rgba(239, 68, 68, 0.7);
41+
--msg-color: 239, 68, 68;
4442
}
4543
4644
&.message-warning {
47-
background-color: rgba(245, 158, 11, 0.4);
48-
border: 1px solid rgba(245, 158, 11, 0.7);
45+
--msg-color: 245, 158, 11;
4946
}
5047
5148
&.message-info {
52-
background-color: rgba(59, 130, 246, 0.4);
53-
border: 1px solid rgba(59, 130, 246, 0.7);
49+
--msg-color: 59, 130, 246;
50+
}
51+
52+
&[class*="message-"] {
53+
background-color: rgba(var(--msg-color), 0.4);
54+
border: 1px solid rgba(var(--msg-color), 0.7);
5455
}
5556
`;
5657

@@ -123,9 +124,9 @@ export function Message({
123124
<MessageContainer
124125
className={`message-${type} ${className || ""}`}
125126
style={style}
126-
onClick={() => onClose?.()}
127-
onMouseEnter={() => pauseTimer()}
128-
onMouseLeave={() => resumeTimer()}
127+
onClick={onClose}
128+
onMouseEnter={pauseTimer}
129+
onMouseLeave={resumeTimer}
129130
>
130131
{content}
131132
<CloseIcon>×</CloseIcon>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { useTheme } from "../hooks/useTheme";
2+
import { useI18n } from "../i18n";
3+
import { Select } from "./Select";
4+
5+
export type MessagePlacement =
6+
| "top"
7+
| "bottom"
8+
| "top-left"
9+
| "top-right"
10+
| "bottom-left"
11+
| "bottom-right";
12+
13+
interface MessagePlacementSelectorProps {
14+
value: MessagePlacement;
15+
onChange: (placement: MessagePlacement) => void;
16+
className?: string;
17+
style?: {
18+
[key: string]: string | number;
19+
};
20+
}
21+
22+
export function MessagePlacementSelector({
23+
value,
24+
onChange,
25+
className,
26+
style,
27+
}: MessagePlacementSelectorProps) {
28+
const { theme } = useTheme();
29+
const { t } = useI18n();
30+
31+
const placements = [
32+
{ value: "top", label: t("common.messagePlacement.top") },
33+
{ value: "bottom", label: t("common.messagePlacement.bottom") },
34+
{ value: "top-left", label: t("common.messagePlacement.topLeft") },
35+
{ value: "top-right", label: t("common.messagePlacement.topRight") },
36+
{ value: "bottom-left", label: t("common.messagePlacement.bottomLeft") },
37+
{ value: "bottom-right", label: t("common.messagePlacement.bottomRight") },
38+
];
39+
40+
const handlePlacementChange = (newValue: string) => {
41+
onChange(newValue as MessagePlacement);
42+
};
43+
44+
return (
45+
<div
46+
className={className}
47+
style={{ display: "flex", alignItems: "center", gap: "8px", ...style }}
48+
>
49+
<label
50+
style={{
51+
fontSize: "14px",
52+
fontWeight: 500,
53+
color: theme.textColor,
54+
marginBottom: "0",
55+
}}
56+
>
57+
{t("common.messagePlacement.label")}:
58+
</label>
59+
<Select value={value} options={placements} onChange={handlePlacementChange} />
60+
</div>
61+
);
62+
}

src/shared/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export { Checkbox } from "./Checkbox";
33
export { Input } from "./Input";
44
export { LanguageSelector } from "./LanguageSelector";
55
export { Message } from "./Message";
6+
export { MessagePlacementSelector } from "./MessagePlacementSelector";
67
export { Modal } from "./Modal";
78
export { Select } from "./Select";

src/shared/i18n/locales/en.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ export const enTranslations: LocaleData = {
1313
warning: "Warning",
1414
info: "Info",
1515
language: "Language",
16+
messagePlacement: {
17+
label: "Message Placement",
18+
top: "Top Center",
19+
bottom: "Bottom Center",
20+
topLeft: "Top Left",
21+
topRight: "Top Right",
22+
bottomLeft: "Bottom Left",
23+
bottomRight: "Bottom Right",
24+
},
1625
},
1726
button: {
1827
download: "Download",

src/shared/i18n/locales/zh.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ export const zhTranslations: LocaleData = {
1313
warning: "警告",
1414
info: "信息",
1515
language: "语言",
16+
messagePlacement: {
17+
label: "消息弹窗位置",
18+
top: "顶部居中",
19+
bottom: "底部居中",
20+
topLeft: "左上角",
21+
topRight: "右上角",
22+
bottomLeft: "左下角",
23+
bottomRight: "右下角",
24+
},
1625
},
1726
button: {
1827
download: "下载",

src/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ export { Modal } from "./components/Modal";
2020
export { Input } from "./components/Input";
2121
export { Checkbox } from "./components/Checkbox";
2222
export { LanguageSelector } from "./components/LanguageSelector";
23+
export { MessagePlacementSelector } from "./components/MessagePlacementSelector";
2324
export { Select } from "./components/Select";

src/shared/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ export interface DownloaderSettings extends BaseSettings {
5555
readonly showVideoDownloadButton: boolean;
5656
readonly showUniversalDownloadButton: boolean;
5757
readonly autoLikeOnDownload: boolean;
58+
readonly messagePlacement:
59+
| "top"
60+
| "bottom"
61+
| "top-left"
62+
| "top-right"
63+
| "bottom-left"
64+
| "bottom-right";
5865
}
5966

6067
// === 组件通用类型 ===

0 commit comments

Comments
 (0)