Home / File/ IndexableDisplayName.js — react Source File

IndexableDisplayName.js — react Source File

Architecture documentation for IndexableDisplayName.js, a javascript file in the react codebase. 5 imports, 3 dependents.

File javascript BabelCompiler Validation 5 imports 3 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  9e753c35_ccc6_2061_a942_6e9b10c9177c["IndexableDisplayName.js"]
  d7b27d30_728f_ba37_ed97_d371fbd3de62["utils.js"]
  9e753c35_ccc6_2061_a942_6e9b10c9177c --> d7b27d30_728f_ba37_ed97_d371fbd3de62
  7edde25d_7a4e_2a08_9aa5_35235e4ca8a7["createRegExp"]
  9e753c35_ccc6_2061_a942_6e9b10c9177c --> 7edde25d_7a4e_2a08_9aa5_35235e4ca8a7
  2d59b0f9_9ad6_da4d_0264_d98f193ab3fd["TreeContext.js"]
  9e753c35_ccc6_2061_a942_6e9b10c9177c --> 2d59b0f9_9ad6_da4d_0264_d98f193ab3fd
  5a81d86f_6a8c_9985_ddb8_5ba82a404c8b["Element.css"]
  9e753c35_ccc6_2061_a942_6e9b10c9177c --> 5a81d86f_6a8c_9985_ddb8_5ba82a404c8b
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  9e753c35_ccc6_2061_a942_6e9b10c9177c --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  9930e8cf_03b4_86c0_be04_47b410246b71["Element.js"]
  9930e8cf_03b4_86c0_be04_47b410246b71 --> 9e753c35_ccc6_2061_a942_6e9b10c9177c
  7f77861c_2ca5_7fd9_4b5c_fa236449c0d3["ForgetBadge.js"]
  7f77861c_2ca5_7fd9_4b5c_fa236449c0d3 --> 9e753c35_ccc6_2061_a942_6e9b10c9177c
  0c2aa36f_2bfd_0e20_42bf_2839b3e43e73["IndexableElementBadges.js"]
  0c2aa36f_2bfd_0e20_42bf_2839b3e43e73 --> 9e753c35_ccc6_2061_a942_6e9b10c9177c
  style 9e753c35_ccc6_2061_a942_6e9b10c9177c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import * as React from 'react';

import {createRegExp} from '../utils';

import {TreeStateContext} from './TreeContext';
import styles from './Element.css';

const {useMemo, useContext} = React;

type Props = {
  displayName: string | null,
  id: number,
};

function IndexableDisplayName({displayName, id}: Props): React.Node {
  const {searchIndex, searchResults, searchText} = useContext(TreeStateContext);
  const isSearchResult = useMemo(() => {
    return searchResults.includes(id);
  }, [id, searchResults]);
  const isCurrentResult =
    searchIndex !== null && id === searchResults[searchIndex];

  if (!isSearchResult || displayName === null) {
    return displayName;
  }

  const match = createRegExp(searchText).exec(displayName);

  if (match === null) {
    return displayName;
  }

  const startIndex = match.index;
  const stopIndex = startIndex + match[0].length;

  const children = [];
  if (startIndex > 0) {
    children.push(<span key="begin">{displayName.slice(0, startIndex)}</span>);
  }
  children.push(
    <mark
      key="middle"
      className={isCurrentResult ? styles.CurrentHighlight : styles.Highlight}>
      {displayName.slice(startIndex, stopIndex)}
    </mark>,
  );
  if (stopIndex < displayName.length) {
    children.push(<span key="end">{displayName.slice(stopIndex)}</span>);
  }

  return children;
}

export default IndexableDisplayName;

Domain

Subdomains

Frequently Asked Questions

What does IndexableDisplayName.js do?
IndexableDisplayName.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in IndexableDisplayName.js?
IndexableDisplayName.js defines 1 function(s): IndexableDisplayName.
What does IndexableDisplayName.js depend on?
IndexableDisplayName.js imports 5 module(s): Element.css, TreeContext.js, createRegExp, react, utils.js.
What files import IndexableDisplayName.js?
IndexableDisplayName.js is imported by 3 file(s): Element.js, ForgetBadge.js, IndexableElementBadges.js.
Where is IndexableDisplayName.js in the architecture?
IndexableDisplayName.js is located at packages/react-devtools-shared/src/devtools/views/Components/IndexableDisplayName.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/devtools/views/Components).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free