Home / File/ resolveBoxStyle.js — react Source File

resolveBoxStyle.js — react Source File

Architecture documentation for resolveBoxStyle.js, a javascript file in the react codebase. 1 imports, 1 dependents.

File javascript BabelCompiler Validation 1 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  895b64ec_6219_126e_b7be_a2d6f2c8d780["resolveBoxStyle.js"]
  a20e28a6_49e7_d981_96eb_f6f2ef1589af["types.js"]
  895b64ec_6219_126e_b7be_a2d6f2c8d780 --> a20e28a6_49e7_d981_96eb_f6f2ef1589af
  000d0fc2_7992_5e09_af69_667403fcc410["setupNativeStyleEditor.js"]
  000d0fc2_7992_5e09_af69_667403fcc410 --> 895b64ec_6219_126e_b7be_a2d6f2c8d780
  style 895b64ec_6219_126e_b7be_a2d6f2c8d780 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 type {BoxStyle} from './types';

/**
 * This mirrors react-native/Libraries/Inspector/resolveBoxStyle.js (but without RTL support).
 *
 * Resolve a style property into it's component parts, e.g.
 *
 * resolveBoxStyle('margin', {margin: 5, marginBottom: 10})
 * -> {top: 5, left: 5, right: 5, bottom: 10}
 */
export default function resolveBoxStyle(
  prefix: string,
  style: Object,
): BoxStyle | null {
  let hasParts = false;
  const result = {
    bottom: 0,
    left: 0,
    right: 0,
    top: 0,
  };

  const styleForAll = style[prefix];
  if (styleForAll != null) {
    // eslint-disable-next-line no-for-of-loops/no-for-of-loops
    for (const key of Object.keys(result)) {
      result[key] = styleForAll;
    }
    hasParts = true;
  }

  const styleForHorizontal = style[prefix + 'Horizontal'];
  if (styleForHorizontal != null) {
    result.left = styleForHorizontal;
    result.right = styleForHorizontal;
    hasParts = true;
  } else {
    const styleForLeft = style[prefix + 'Left'];
    if (styleForLeft != null) {
      result.left = styleForLeft;
      hasParts = true;
    }

    const styleForRight = style[prefix + 'Right'];
    if (styleForRight != null) {
      result.right = styleForRight;
      hasParts = true;
    }

    const styleForEnd = style[prefix + 'End'];
    if (styleForEnd != null) {
      // TODO RTL support
      result.right = styleForEnd;
      hasParts = true;
    }
    const styleForStart = style[prefix + 'Start'];
    if (styleForStart != null) {
      // TODO RTL support
      result.left = styleForStart;
      hasParts = true;
    }
  }

  const styleForVertical = style[prefix + 'Vertical'];
  if (styleForVertical != null) {
    result.bottom = styleForVertical;
    result.top = styleForVertical;
    hasParts = true;
  } else {
    const styleForBottom = style[prefix + 'Bottom'];
    if (styleForBottom != null) {
      result.bottom = styleForBottom;
      hasParts = true;
    }

    const styleForTop = style[prefix + 'Top'];
    if (styleForTop != null) {
      result.top = styleForTop;
      hasParts = true;
    }
  }

  return hasParts ? result : null;
}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does resolveBoxStyle.js do?
resolveBoxStyle.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 resolveBoxStyle.js?
resolveBoxStyle.js defines 1 function(s): resolveBoxStyle.
What does resolveBoxStyle.js depend on?
resolveBoxStyle.js imports 1 module(s): types.js.
What files import resolveBoxStyle.js?
resolveBoxStyle.js is imported by 1 file(s): setupNativeStyleEditor.js.
Where is resolveBoxStyle.js in the architecture?
resolveBoxStyle.js is located at packages/react-devtools-shared/src/backend/NativeStyleEditor/resolveBoxStyle.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/backend/NativeStyleEditor).

Analyze Your Own Codebase

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

Try Supermodel Free