({ metadata }: InstallCodeProps)
| 229 | }; |
| 230 | |
| 231 | const StaticSimple = ({ metadata }: InstallCodeProps) => { |
| 232 | const [isActive, setActive] = useState<Record<string, boolean>>({ |
| 233 | 400: true, |
| 234 | }); |
| 235 | const keys = Object.keys(isActive); |
| 236 | const handleActive = (value: string | number) => { |
| 237 | setActive((prev) => toggleKeyKeepOne(prev, value)); |
| 238 | }; |
| 239 | |
| 240 | const [isItal, setIsItal] = useState(false); |
| 241 | const generateImports = () => { |
| 242 | let imports = ''; |
| 243 | if (keys.length === 1 && isActive[400]) { |
| 244 | if (isItal) return `import '@fontsource/${metadata.id}/400-italic.css';`; |
| 245 | return `import '@fontsource/${metadata.id}';`; |
| 246 | } |
| 247 | |
| 248 | for (const weight of keys) { |
| 249 | imports += isItal |
| 250 | ? `import '@fontsource/${metadata.id}/${weight}-italic.css';\n` |
| 251 | : `import '@fontsource/${metadata.id}/${weight}.css';\n`; |
| 252 | } |
| 253 | return imports.trim(); |
| 254 | }; |
| 255 | |
| 256 | return ( |
| 257 | <> |
| 258 | <Group> |
| 259 | {metadata.weights.map((weight) => ( |
| 260 | <Badge |
| 261 | key={weight} |
| 262 | className={classes.badge} |
| 263 | onClick={() => { |
| 264 | handleActive(weight); |
| 265 | }} |
| 266 | data-active={Boolean(isActive[weight])} |
| 267 | > |
| 268 | {weight} |
| 269 | </Badge> |
| 270 | ))} |
| 271 | {metadata.styles.includes('italic') && ( |
| 272 | <Badge |
| 273 | className={classes.badge} |
| 274 | onClick={() => { |
| 275 | setIsItal((prev) => !prev); |
| 276 | }} |
| 277 | data-active={isItal} |
| 278 | > |
| 279 | italic |
| 280 | </Badge> |
| 281 | )} |
| 282 | </Group> |
| 283 | <Code language="jsx">{generateImports()}</Code> |
| 284 | <Title order={3} mt="xl" mb="md"> |
| 285 | CSS |
| 286 | </Title> |
| 287 | <Text> |
| 288 | Include the CSS in your project by adding the following line to your |
nothing calls this directly
no test coverage detected