Skip to content

Commit dc9d10d

Browse files
committed
Add rounded attribute
1 parent 0fe6684 commit dc9d10d

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

readme.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ $ npm install --save @github/image-crop-element
1616
<image-crop src="/avatar.jpg"></image-crop>
1717
```
1818

19+
### Rounded crop area
20+
21+
```html
22+
<image-crop src="/avatar.jpg" rounded></image-crop>
23+
```
24+
1925
### With loading state
2026

2127
```html
2228
<image-crop src="/avatar.jpg">
23-
<img src="spinner.gif" alt="" data-loading-slot>
29+
<img src="spinner.gif" alt="" data-loading-slot />
2430
</image-crop>
2531
```
2632

src/index.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,13 @@ class ImageCropElement extends HTMLElement {
206206
const shadowRoot = this.attachShadow({mode: 'open'})
207207
shadowRoot.innerHTML = `
208208
<style>
209-
:host {
210-
touch-action: none;
211-
display: block;
212-
}
209+
:host { touch-action: none; display: block; }
213210
:host(.nesw) { cursor: nesw-resize; }
214211
:host(.nwse) { cursor: nwse-resize; }
215-
:host(.nesw) .crop-box,
216-
:host(.nwse) .crop-box {
217-
cursor: inherit;
218-
}
212+
:host(.nesw) .crop-box, :host(.nwse) .crop-box { cursor: inherit; }
219213
:host([loaded]) .crop-image { display: block; }
220-
:host([loaded]) ::slotted([data-loading-slot]),
221-
.crop-image {
222-
display: none;
223-
}
214+
:host([loaded]) ::slotted([data-loading-slot]), .crop-image { display: none; }
215+
224216
.crop-wrapper {
225217
position: relative;
226218
font-size: 0;
@@ -237,12 +229,21 @@ class ImageCropElement extends HTMLElement {
237229
width: 100%;
238230
height: 100%;
239231
}
232+
233+
:host([rounded]) .crop-box {
234+
border-radius: 50%;
235+
box-shadow: 0 0 0 500px rgba(0, 0, 0, 0.3);
236+
}
240237
.crop-box {
241238
position: absolute;
242239
border: 1px dashed #fff;
243240
box-sizing: border-box;
244241
cursor: move;
245242
}
243+
244+
:host([rounded]) .crop-outline {
245+
outline: none;
246+
}
246247
.crop-outline {
247248
position: absolute;
248249
top: 0;
@@ -251,7 +252,9 @@ class ImageCropElement extends HTMLElement {
251252
right: 0;
252253
outline: 4000px solid rgba(0, 0, 0, .3);
253254
}
255+
254256
.handle { position: absolute; }
257+
:host([rounded]) .handle::before { border-radius: 50%; }
255258
.handle:before {
256259
position: absolute;
257260
display: block;

0 commit comments

Comments
 (0)