| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import * as React from 'react'; |
| 11 | import KeyValue from './KeyValue'; |
| 12 | import Store from '../../store'; |
| 13 | import sharedStyles from './InspectedElementSharedStyles.css'; |
| 14 | import styles from './InspectedElementStyleXPlugin.css'; |
| 15 | import {enableStyleXFeatures} from 'react-devtools-feature-flags'; |
| 16 | |
| 17 | import type {InspectedElement} from 'react-devtools-shared/src/frontend/types'; |
| 18 | import type {FrontendBridge} from 'react-devtools-shared/src/bridge'; |
| 19 | import type {Element} from 'react-devtools-shared/src/frontend/types'; |
| 20 | |
| 21 | type Props = { |
| 22 | bridge: FrontendBridge, |
| 23 | element: Element, |
| 24 | inspectedElement: InspectedElement, |
| 25 | store: Store, |
| 26 | }; |
| 27 | |
| 28 | export default function InspectedElementStyleXPlugin({ |
| 29 | bridge, |
| 30 | element, |
| 31 | inspectedElement, |
| 32 | store, |
| 33 | }: Props): React.Node { |
| 34 | if (!enableStyleXFeatures) { |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | const styleXPlugin = inspectedElement.plugins.stylex; |
| 39 | if (styleXPlugin == null) { |
| 40 | return null; |
| 41 | } |
| 42 | |
| 43 | const {resolvedStyles, sources} = styleXPlugin; |
| 44 | |
| 45 | return ( |
| 46 | <div> |
| 47 | <div className={sharedStyles.HeaderRow}> |
| 48 | <div className={sharedStyles.Header}>stylex</div> |
| 49 | </div> |
| 50 | {sources.map(source => ( |
| 51 | <div key={source} className={styles.Source}> |
| 52 | {source} |
| 53 | </div> |
| 54 | ))} |
| 55 | {Object.entries(resolvedStyles).map(([name, value]) => ( |
| 56 | <KeyValue |
| 57 | key={name} |
| 58 | alphaSort={true} |
| 59 | bridge={bridge} |
| 60 | canDeletePaths={false} |
| 61 | canEditValues={false} |
| 62 | canRenamePaths={false} |
| 63 | depth={1} |
| 64 | element={element} |
| 65 | hidden={false} |
| 66 | inspectedElement={inspectedElement} |
| 67 | name={name} |
| 68 | path={[name]} |
| 69 | pathRoot="stylex" |
| 70 | store={store} |
| 71 | value={value} |
| 72 | /> |
| 73 | ))} |
| 74 | </div> |
| 75 | ); |
| 76 | } |