({ children, tag, label, code })
| 126 | } |
| 127 | |
| 128 | function CodePanel({ children, tag, label, code }) { |
| 129 | let child = Children.only(children) |
| 130 | |
| 131 | if (isValidElement(child)) { |
| 132 | tag = child.props.tag ?? tag |
| 133 | label = child.props.label ?? label |
| 134 | code = child.props.code ?? code |
| 135 | } |
| 136 | |
| 137 | if (!code) { |
| 138 | throw new Error( |
| 139 | '`CodePanel` requires a `code` prop, or a child with a `code` prop.', |
| 140 | ) |
| 141 | } |
| 142 | |
| 143 | return ( |
| 144 | <div className="group dark:bg-white/2.5"> |
| 145 | <CodePanelHeader tag={tag} label={label} /> |
| 146 | <div className="relative"> |
| 147 | <pre className="overflow-x-auto p-4 text-xs text-white">{children}</pre> |
| 148 | <CopyButton code={code} /> |
| 149 | </div> |
| 150 | </div> |
| 151 | ) |
| 152 | } |
| 153 | |
| 154 | function CodeGroupHeader({ title, children, selectedIndex }) { |
| 155 | let hasTabs = Children.count(children) > 1 |
nothing calls this directly
no outgoing calls
no test coverage detected