A custom element for cropping a square image. Returns x, y, width, and height.
Перейти к файлу
Siddharth Kshetrapal 1b5c9b749f
Merge pull request #54 from github/dependabot/npm_and_yarn/npm_and_yarn-0627b2084d
Bump the npm_and_yarn group with 6 updates
2024-09-27 12:20:45 +02:00
.github/workflows upgrade to new web component standards 2023-06-08 17:11:17 +01:00
examples Remove wrapper class 2021-04-08 14:54:59 +01:00
src upgrade to new web component standards 2023-06-08 17:11:17 +01:00
test upgrade to new web component standards 2023-06-08 17:11:17 +01:00
.eslintrc.json upgrade to new web component standards 2023-06-08 17:11:17 +01:00
.gitattributes Set eol=lf 2021-03-15 10:24:50 +00:00
.gitignore Ignore build files 2017-11-16 16:08:15 +08:00
CODEOWNERS move AOR to primer 2022-09-23 18:41:37 +01:00
LICENSE Update license 2018-06-22 14:39:12 -07:00
custom-elements.json upgrade to new web component standards 2023-06-08 17:11:17 +01:00
package-lock.json Bump the npm_and_yarn group with 6 updates 2024-09-26 15:36:55 +00:00
package.json Bump the npm_and_yarn group with 6 updates 2024-09-26 15:36:55 +00:00
readme.md Add `rounded` attribute 2021-04-16 10:56:40 +01:00
tsconfig.json upgrade to new web component standards 2023-06-08 17:11:17 +01:00
web-test-runner.config.js upgrade to new web component standards 2023-06-08 17:11:17 +01:00

readme.md

<image-crop-element>

This loads an image and creates a crop area that user can modify. An event is fired with x, y, width, and height as the crop area changes.

Installation

$ npm install --save @github/image-crop-element

Usage

Plain

<image-crop src="/avatar.jpg"></image-crop>

Rounded crop area

<image-crop src="/avatar.jpg" rounded></image-crop>

With loading state

<image-crop src="/avatar.jpg">
  <img src="spinner.gif" alt="" data-loading-slot />
</image-crop>

With autoupdate inputs

<image-crop src="/avatar.jpg">
  <input type="hidden" data-image-crop-input="x" name="x">
  <input type="hidden" data-image-crop-input="y" name="y">
  <input type="hidden" data-image-crop-input="width" name="width">
  <input type="hidden" data-image-crop-input="height" name="height">
</image-crop>

Listen to the change event

document.addEventListener('image-crop-change', function (event){
  console.log(
    'Crop area changed.',
    event.detail.x,
    event.detail.y,
    event.detail.width,
    event.detail.height
  )
})

CSS encapsulation

The elements HTML structure is initialized in a Shadow DOM, so it is impossible to apply CSS to it. If you need to change the element's default style for any reason, you should open up a new issue (or a pull request!), describing your use case, and we'll work with you on solving the problem.

Browser support

Browsers without native custom element support require a polyfill. Legacy browsers require various other polyfills. See examples/index.html for details.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge