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

Function StaticAdvanced

website/app/components/preview/InstallCode.tsx:302–441  ·  view source on GitHub ↗
({ metadata }: InstallCodeProps)

Source from the content-addressed store, hash-verified

300};
301
302const StaticAdvanced = ({ metadata }: InstallCodeProps) => {
303 // Active weights
304 const [isActiveWeight, setActiveWeight] = useState<Record<string, boolean>>({
305 400: true,
306 });
307 const handleActiveWeight = (value: string | number) => {
308 setActiveWeight((prev) => toggleKeyKeepOne(prev, value));
309 };
310
311 // Active italics
312 const [isItal, setIsItal] = useState(false);
313
314 // Displays
315 const [displayCurrent, setDisplay] = useState('swap');
316 const handleDisplay = (value: string) => {
317 setDisplay(value);
318 };
319
320 // Active subsets
321 const [subsets, setSubsets] = useState<string[]>([metadata.defSubset]);
322 const handleActiveSubset = (value: string) => {
323 if (subsets.length === 1 && subsets.includes(value)) return;
324
325 setSubsets((prev) => {
326 if (prev.includes(value)) {
327 return prev.filter((subset) => subset !== value);
328 }
329
330 return [...prev, value];
331 });
332 };
333
334 // Choose formats
335 const FORMATS = ['woff2', 'woff'] as const;
336 const [formats, setFormat] = useState<(typeof FORMATS)[number][]>([
337 'woff2',
338 'woff',
339 ]);
340 const handleFormat = (value: string) => {
341 if (!FORMATS.includes(value as (typeof FORMATS)[number])) return;
342 const selectedFormat = value as (typeof FORMATS)[number];
343
344 if (formats.length === 1 && formats.includes(selectedFormat)) return;
345
346 setFormat((prev) => {
347 if (prev.includes(selectedFormat)) {
348 return prev.filter((item) => item !== selectedFormat);
349 }
350
351 return [...prev, selectedFormat];
352 });
353 };
354
355 const css = buildStaticPreviewCSS(metadata, {
356 subsets,
357 weights: Object.keys(isActiveWeight).map((weight) => Number(weight)),
358 style: isItal ? 'italic' : 'normal',
359 formats,

Callers

nothing calls this directly

Calls 2

buildStaticPreviewCSSFunction · 0.90
handleActiveWeightFunction · 0.70

Tested by

no test coverage detected