@bmunozg/react-image-area

中文文档
1.2.0发布于 2026/03/06MITTypeScriptESM + CJS零依赖近 30 天下载 6719

React component to select multiple areas/regions of images.

原始使用文档
文档目录11 节
  1. :books: Table of Contents
  2. :package: Installation
  3. :rocket: Usage
  4. :key: Features
  5. :notebook: Docs
  6. Required Props
  7. Default Props
  8. Optional Props
  9. :hammer_and_wrench: Support
  10. :memo: Contributing
  11. :scroll: License

react-image-area

react language license

React component to select multiple areas/regions of images.

Live Example

:books: Table of Contents

:package: Installation

npm i @bmunozg/react-image-area

Peer dependencies: React 17, 18, and 19 are all supported.

:rocket: Usage

Usage with types

import { AreaSelector, IArea } from '@bmunozg/react-image-area'

const ExampleComponent = () => {
    const [areas, setAreas] = useState<IArea[]>([]);

    const onChangeHandler = (areas: IArea[]) => {
        setAreas(areas);
    }

    return (
        <AreaSelector
            areas={areas}
            onChange={onChangeHandler}
        >
            <img src='my-image.jpg' alt='my image'/>
        </AreaSelector>
    )
}

:key: Features

  • Responsive (you can use pixels or percentages).
  • Touch enabled.
  • Min/max area size.
  • Custom area render

:notebook: Docs

  • Required Props

    • areas: IArea[]

      Starting with no areas:

      // ...
      const [areas,setAreas] = useState<IArea[]>([])
      // ...
      return (
          <AreaSelector
              areas={areas}
          >
              <img src='my-image.jpg' alt='my image'/>
          </AreaSelector>
      )
      // ...
      
    • onChange: (areas: IArea[]) => void

      A callback which happens for every change on the selection area.

      // ...
      const [areas,setAreas] = useState<IArea[]>()
      // ...
      return (
          <AreaSelector
              onChange={setAreas}
          >
              <img src='my-image.jpg' alt='my image'/>
          </AreaSelector>
      )
      // ...
      
  • Default Props

    • maxAreas: number

      Default: Infinity

      Set the maximum areas that can be drawn, by default there are no limit.

    • unit: 'pixel' | 'percentage'

      Default: pixel

      Set the unit you want to work with.

    • minWidth: number

      Default: 0

      Min width of the areas.

    • minHeight: number

      Default: 0

      Min height of the areas.

    • debug: boolean

      Default: false

      Display info of the current areas.

  • Optional Props

    • maxWidth: number

      Max width of the areas.

    • maxHeight: number

      Max height of the areas.

    • wrapperStyle: CSSProperties

      Apply styles to the wrapper element.

      Omited Styles: touchAction | boxSizing

      wrapperStyle={{
          border: '2px solid black'
      }}
      
    • globalAreaStyle: CSSProperties

      Apply global styles to the areas.

      Omited Styles: position | touchAction | top | left | width | height | boxSizing

      globalAreaStyle={{
          border: '1.5px dashed blue',
          backgroundColor: 'lightblue',
          opacity: '0.5'
      }}
      
    • customAreaRenderer: (areaProps: IAreaRendererProps) => ReactNode

      Custom render function to display info inside the areas. Remember to add a key

      import { AreaSelector, IAreaRendererProps } from '@bmunozg/react-image-area'
      // ...
      const customRender = (areaProps: IAreaRendererProps) => {
          if (!areaProps.isChanging) {
              return (
                  <div key={areaProps.areaNumber}>
                      {areaProps.areaNumber}
                  </div>
              );
          }
      };
      // ...
      return (
          <AreaSelector
              {/*...*/}
              customAreaRenderer={customRender}
          >
              <img src='my-image.jpg' />
          </AreaSelector>
      );
      // ...
      
    • mediaWrapperClassName: string

      Classname to apply to the media wrapper (image passed as children).

      // ...
      return (
          <AreaSelector>
              <img src="my-image.jpg" />
          </AreaSelector>
      );
      // ...
      

      inside the component :arrow_down:

      // ...
      return (
          <div {/*wrapperStyle*/}>
              <div className={mediaWrapperClassName}>
                  {/*image passed as children*/}
              </div>
              {/*...Areas*/}
          </div>
      )
      //...
      

:hammer_and_wrench: Support

Please open an issue for support.

:memo: Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

:scroll: License

MIT © ByronMunozG

版本与发布记录

@bmunozg/react-image-area 共发布 8 个版本,首次发布于 2022/04/16;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.2.0latest2026/03/068 个月前
1.1.02022/07/284 年前
1.1.0-beta.2beta2022/07/284 年前
1.1.0-beta.12022/07/284 年前
1.0.22022/05/094 年前
1.0.12022/05/094 年前

关于 @bmunozg/react-image-area 的常见问题

@bmunozg/react-image-area 是什么?

React component to select multiple areas/regions of images.

如何安装 @bmunozg/react-image-area?

在项目目录运行 npm install @bmunozg/react-image-area,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@types/react(^17.0.0 || ^18.0.0 || ^19.0.0)、react(^17.0.0 || ^18.0.0 || ^19.0.0)、react-dom(^17.0.0 || ^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bmunozg/react-image-area 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bmunozg/react-image-area 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bmunozg/react-image-area 可以商用吗?

@bmunozg/react-image-area 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bmunozg/react-image-area 的下载量有多少?

根据 npm 官方下载统计,@bmunozg/react-image-area 在 2026/10/09 – 2026/11/07 这 30 天内被下载 6,719 次,日均约 224 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bmunozg/react-image-area 还在维护吗?

最新版本 1.2.0 发布于 2026/03/06(8 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 1 个;首次发布于 2022/04/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。