项目作者: raunofreiberg

项目描述 :
Pixel perfect layout inspection.
高级语言: TypeScript
项目地址: git://github.com/raunofreiberg/inspx.git
创建时间: 2021-04-23T14:11:28Z
项目社区:https://github.com/raunofreiberg/inspx

开源协议:MIT License

下载


image

inspx

npm

Pixel perfect layout inspection.

Built for React as a proof of concept.

Setup

Install the package:

  1. npm install inspx --save-dev

Wrap the root of your application or arbitrary component trees:

  1. import Inspect from 'inspx';
  2. <Inspect>
  3. <App ></App>
  4. </Inspect>

Usage

Inspect elements by hovering an element and holding Option (⌥) simultaneously.

demo

By default, any element with padding, margin, or width and height is inspectable.

You can disable certain properties:

  1. <Inspect
  2. margin
  3. size={false}
  4. padding={false}
  5. >
  6. <App ></App>
  7. </Inspect>

Configuration

By default, the component will only be enabled in the development environment.

You can configure this behavior with the disabled prop:

  1. <Inspect
  2. disabled={
  3. process.env.NODE_ENV === 'staging' ||
  4. process.env.NODE_ENV === 'production'
  5. }
  6. >
  7. <App ></App>
  8. </Inspect>

Optionally, you can leverage code splitting by wrapping the exported component and using your own instead.

The library is lightweight enough for this to likely be a premature and insignificant optimization.

  1. import * as React from 'react';
  2. import { InspectProps } from 'inspx';
  3. const Inspect = React.lazy(() => import('inspx'));
  4. export default function Loader(props: InspectProps) {
  5. if (process.env.NODE_ENV === 'production') {
  6. return props.children;
  7. }
  8. return (
  9. <React.Suspense fallback={null}>
  10. <Inspect disabled={false} {...props} ></Inspect>
  11. </React.Suspense>
  12. );
  13. }