* Recursively searches React children for a component of the given type * and returns its props. Returns null if not found.
(children, targetType)
| 33 | * and returns its props. Returns null if not found. |
| 34 | */ |
| 35 | function findChildProps(children, targetType) { |
| 36 | let result = null; |
| 37 | React.Children.forEach(children, child => { |
| 38 | if (result || !child || !child.props) return; |
| 39 | if (child.type === targetType) { |
| 40 | result = child.props; |
| 41 | return; |
| 42 | } |
| 43 | if (child.props.children) { |
| 44 | result = findChildProps(child.props.children, targetType); |
| 45 | } |
| 46 | }); |
| 47 | return result; |
| 48 | } |
| 49 | |
| 50 | function getActiveCode(codeObject, lang, style) { |
| 51 | if (!codeObject) return { source: '', label: '', css: '' }; |