-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathmod-loader-cards.tsx
More file actions
129 lines (122 loc) Β· 3.89 KB
/
mod-loader-cards.tsx
File metadata and controls
129 lines (122 loc) Β· 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import {
BoxProps,
Card,
Flex,
Grid,
HStack,
Icon,
IconButton,
Image,
Text,
VStack,
} from "@chakra-ui/react";
import { useTranslation } from "react-i18next";
import { LuChevronRight, LuX } from "react-icons/lu";
import { useLauncherConfig } from "@/contexts/config";
import { ModLoaderType } from "@/enums/instance";
import { useThemedCSSStyle } from "@/hooks/themed-css";
import { parseModLoaderVersion } from "@/utils/instance";
interface ModLoaderCardsProps extends BoxProps {
currentType: ModLoaderType;
currentVersion?: string;
displayMode: "entry" | "selector";
loading?: boolean;
onTypeSelect?: (type: ModLoaderType) => void;
expandedType?: ModLoaderType | null;
}
const ModLoaderCards: React.FC<ModLoaderCardsProps> = ({
currentType,
currentVersion,
displayMode,
loading = false,
onTypeSelect,
expandedType,
...boxProps
}) => {
const { t } = useTranslation();
const { config } = useLauncherConfig();
const primaryColor = config.appearance.theme.primaryColor;
const themedStyles = useThemedCSSStyle();
const borderWidth = "1px";
const basePadding = boxProps.padding || "12px";
const selectedPadding = `calc(${basePadding} - ${borderWidth})`;
const loaderTypes: ModLoaderType[] = [
ModLoaderType.Fabric,
ModLoaderType.Forge,
ModLoaderType.NeoForge,
];
const renderCard = (type: ModLoaderType) => {
const isSelected =
type === currentType && currentType !== ModLoaderType.Unknown;
return (
<Card
key={type}
className={themedStyles.card["card-front"]}
pr={1.5}
variant={isSelected ? "outline" : "elevated"}
borderColor={isSelected ? `${primaryColor}.500` : "transparent"}
borderWidth={isSelected ? borderWidth : 0}
p={isSelected ? selectedPadding : basePadding}
>
<Flex justify="space-between" alignItems="center">
<HStack spacing={2}>
<Image
src={`/images/icons/${type}.png`}
alt={type}
boxSize="28px"
style={{ borderRadius: "4px" }}
/>
<VStack spacing={0} alignItems="start">
<Text
fontSize="xs-sm"
fontWeight={isSelected ? "bold" : "normal"}
color={isSelected ? `${primaryColor}.600` : "inherit"}
mt={displayMode === "entry" && isSelected ? -0.5 : 0}
>
{type}
</Text>
<Text fontSize="xs" className="secondary-text">
{displayMode === "entry"
? isSelected
? `${t("ModLoaderCards.installed")} ${parseModLoaderVersion(currentVersion || "")}`
: t("ModLoaderCards.unInstalled")
: isSelected
? currentVersion || t("ModLoaderCards.versionNotSelected")
: currentType === "Unknown"
? t("ModLoaderCards.versionNotSelected")
: t("ModLoaderCards.notCompatibleWith", {
modLoader: currentType,
})}
</Text>
</VStack>
</HStack>
{displayMode === "selector" && expandedType && !isSelected ? null : (
<IconButton
aria-label={type}
icon={
<Icon
as={
displayMode === "selector" && isSelected
? LuX
: LuChevronRight
}
boxSize={3.5}
/>
}
variant="ghost"
size="xs"
disabled={loading}
onClick={() => onTypeSelect?.(type)}
/>
)}
</Flex>
</Card>
);
};
return (
<Grid templateColumns="repeat(3, 1fr)" gap={3.5} {...boxProps}>
{loaderTypes.map(renderCard)}
</Grid>
);
};
export default ModLoaderCards;