({ children }: CodeExampleProps)
| 8 | }; |
| 9 | |
| 10 | export function CodeExamples({ children }: CodeExampleProps) { |
| 11 | const [activeChildIdx, setActiveChildIdx] = useState(0); |
| 12 | |
| 13 | // Convert children to an array |
| 14 | const childrenArray = React.Children.toArray(children); |
| 15 | |
| 16 | // Use index for identifying active child instead of title search. |
| 17 | const handleActiveCodeBlock = (index: number) => { |
| 18 | setActiveChildIdx(index); |
| 19 | }; |
| 20 | |
| 21 | return ( |
| 22 | <div> |
| 23 | <div className="isolate grid w-full auto-rows-auto grid-cols-4 rounded-md shadow-sm"> |
| 24 | {childrenArray.map((child: any, index: number) => ( |
| 25 | <div |
| 26 | className={clsx( |
| 27 | 'group relative inline-flex w-full min-w-[100px] items-center justify-center bg-muted px-2 py-1 text-center text-[12px] font-semibold uppercase tracking-wide ring-1 ring-inset ring-muted-foreground/5 transition-colors hover:cursor-pointer hover:bg-foreground hover:text-background focus:z-10 focus:outline ', |
| 28 | activeChildIdx === index |
| 29 | ? 'bg-muted-foreground text-background' |
| 30 | : 'text-muted-foreground', |
| 31 | index === 0 && 'rounded-tl-md rounded-bl-md', |
| 32 | index === childrenArray.length - 1 && |
| 33 | 'rounded-tr-md rounded-br-md' |
| 34 | )} |
| 35 | key={child.props.exampleTitle} |
| 36 | onClick={() => handleActiveCodeBlock(index)} |
| 37 | > |
| 38 | <span>{child.props.exampleTitle}</span> |
| 39 | </div> |
| 40 | ))} |
| 41 | </div> |
| 42 | {childrenArray[activeChildIdx]} |
| 43 | </div> |
| 44 | ); |
| 45 | } |
nothing calls this directly
no test coverage detected