MCPcopy Create free account
hub / github.com/fontsource/fontsource / VariableSimple

Function VariableSimple

website/app/components/preview/InstallCode.tsx:63–123  ·  view source on GitHub ↗
({ metadata, variable }: InstallCodeProps)

Source from the content-addressed store, hash-verified

61);
62
63const VariableSimple = ({ metadata, variable }: InstallCodeProps) => {
64 const [isActive, setActive] = useState<Record<string, boolean>>({
65 wght: true,
66 });
67
68 if (!variable) return null;
69
70 const isItal = isActive.ital;
71
72 const importComment =
73 metadata.weights.length === 1
74 ? `// Supports only weight ${metadata.weights[0]}\n`
75 : `// Supports weights ${metadata.weights[0]}-${
76 metadata.weights.at(-1) ?? 400
77 }\n`;
78
79 const generateImports = () => {
80 const activeAxisTags = Object.keys(isActive).filter(
81 (axis) => isActive[axis],
82 );
83 const importSpecifier = getVariableImport(
84 metadata,
85 variable,
86 activeAxisTags,
87 isItal ? 'italic' : 'normal',
88 );
89 return `import '${importSpecifier}';`;
90 };
91
92 const handleActive = (value: string | number) => {
93 setActive((prev) => toggleVariableAxis(prev, value));
94 };
95
96 return (
97 <>
98 {variable && (
99 <BadgeGroup
100 items={Object.keys(variable.axes)}
101 onClick={handleActive}
102 isActive={(value) => isActive[value]}
103 mt="xs"
104 />
105 )}
106 <Code language="jsx">{importComment + generateImports()}</Code>
107 <Title order={3} mt="xl" mb="md">
108 CSS
109 </Title>
110 <Text>
111 Include the CSS in your project by adding the following line to your
112 project:
113 </Text>
114 <Code language="css">
115 {`body {
116 font-family: '${metadata.family} Variable', ${
117 categoryMap[metadata.category] ?? 'sans-serif'
118 };
119}`}
120 </Code>

Callers

nothing calls this directly

Calls 1

generateImportsFunction · 0.85

Tested by

no test coverage detected