No description
  • TypeScript 83.1%
  • JavaScript 16.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Marie Lucca 8541e056d5
Merge pull request #71 from github/dependabot/npm_and_yarn/npm_and_yarn-6aaed2ab8e
Bump the npm_and_yarn group across 1 directory with 1 update
2026-07-15 21:56:13 -04:00
.github/workflows Update publish workflow to include provenance flag 2026-05-05 15:25:43 -07: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
custom-elements.json upgrade to new web component standards 2023-06-08 17:11:17 +01:00
LICENSE Update license 2018-06-22 14:39:12 -07:00
package-lock.json Bump the npm_and_yarn group across 1 directory with 1 update 2026-07-16 00:39:59 +00:00
package.json Bump the npm_and_yarn group across 1 directory with 2 updates 2026-06-13 08:27:36 +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

<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