import React from "react"; import { useColorMode } from "@docusaurus/theme-common"; import { devices } from "../config"; import type { DeviceConfig } from "../config"; import styles from "../styles.module.css"; interface Props { selectedId: string; onSelect: (id: string) => void; } /** * Determine the icon type from the icon string: * - Starts with " tag. */ function hasBackgroundProps(style: React.CSSProperties | undefined): boolean { if (!style) return false; return Object.keys(style).some((key) => { const k = key.toLowerCase().replace(/-/g, ""); return k === "backgroundsize" || k === "backgroundposition" || k === "backgroundrepeat" || k === "backgroundimage"; }); } /** * Convert a style object to CSS custom properties (e.g. { width: "24px" } → { "--svg-width": "24px" }) * so they can be consumed by CSS rules targeting child elements like . */ function toCssVars(style: React.CSSProperties | undefined, prefix: string): React.CSSProperties { if (!style) return {}; const vars: Record = {}; for (const [key, value] of Object.entries(style)) { const cssKey = key.replace(/([A-Z])/g, "-$1").toLowerCase(); vars[`--${prefix}-${cssKey}`] = value; } return vars as React.CSSProperties; } function DeviceIcon({ device }: { device: DeviceConfig }) { const { isDarkTheme } = useColorMode(); const iconStr = isDarkTheme && device.iconDark ? device.iconDark : device.icon; const iconStyle = (isDarkTheme && device.iconDarkStyle ? device.iconDarkStyle : device.iconStyle) as React.CSSProperties | undefined; const svgStyle = (isDarkTheme && device.svgDarkStyle ? device.svgDarkStyle : device.svgStyle) as React.CSSProperties | undefined; const iconType = getIconType(iconStr); if (iconType === "svg") { return (
); } if (iconType === "image") { // When iconStyle contains background-* properties, render as background-image // on the container div instead of an tag, enabling background-size/position control. if (hasBackgroundProps(iconStyle)) { return (
); } return (
{device.name}
); } return (
{iconStr}
); } function DeviceCard({ device, active, onClick, }: { device: DeviceConfig; active: boolean; onClick: () => void; }) { return (
{ if (e.key === "Enter" || e.key === " ") onClick(); }} >
{device.name}
{device.description}
); } export default function DeviceSelector({ selectedId, onSelect }: Props) { return (

Device Type

{devices.map((d) => ( onSelect(d.id)} /> ))}
); }