Skip to content

Commit 39517eb

Browse files
committed
Create --handle-color variable and improve docs
1 parent 8bf2b79 commit 39517eb

File tree

7 files changed

+45
-15
lines changed

7 files changed

+45
-15
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
# svelte-compare-image
22

3-
A component to compare two images by dragging a slider to reveal the other
4-
image. Find the package on NPM at [svelte-compare-image](https://npmjs.com/package/svelte-compare-image).
3+
A Svelte component to compare two images.
4+
Find the package on NPM at [svelte-compare-image](https://npmjs.com/package/svelte-compare-image).
55

66
An interactive example can be found at https://brianm.me/svelte-compare-image/
77

8+
![screen recording example](https://github.com/BrianMitchL/svelte-compare-image/raw/main/example.gif)
9+
10+
The markup, state logic, and styling were originally adapted from [react-compare-image](https://github.com/junkboy0315/react-compare-image).
11+
812
## Docs
913

1014
The component will display the images and fill available width and height using a ResizeObserver according to the aspect ratios of the images.
1115

12-
To use it, render the component as seen below. The `--slider-width` and `--handle-size` CSS custom property props are optional and default to 0.125rem and 2.5rem, respectfully.
16+
To use it, render the component as seen below, providing image src and alt text for the left and right images.
17+
The following CSS custom properties are optional and can be set to customize the appearance of the slider.
18+
19+
| Property | Default Value |
20+
| ---------------- | ------------- |
21+
| `--handle-size` | `2.5rem` |
22+
| `--slider-color` | `#ffffff` |
23+
| `--slider-width` | `0.125rem` |
1324

1425
```svelte
1526
<script lang="ts">
@@ -21,7 +32,8 @@ To use it, render the component as seen below. The `--slider-width` and `--handl
2132
imageLeftAlt="left"
2233
imageRightSrc="https://via.placeholder.com/600x400/00aaff/ffffff?text=Right"
2334
imageRightAlt="right"
24-
--slider-width="0.125rem"
2535
--handle-size="2.5rem"
36+
--slider-color="#ffffff"
37+
--slider-width="0.125rem"
2638
/>
2739
```

example.gif

1.01 MB
Loading

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"author": "Brian Mitchell",
55
"license": "MIT",
6-
"description": "A component to compare two images by dragging a slider to reveal the other image",
6+
"description": "A Svelte component to compare two images",
77
"keywords": [
88
"svelte",
99
"compare",
@@ -56,6 +56,6 @@
5656
"pre-commit": "npm run prettier-staged"
5757
},
5858
"engines": {
59-
"node": ">16.13.0"
59+
"node": ">=16.13.0"
6060
}
6161
}

src/app.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<meta name="description" content="" />
6-
<link rel="icon" href="/favicon.png" />
75
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<link rel="icon" href="/favicon.png" />
7+
<meta
8+
name="description"
9+
content="A Svelte component to compare two images"
10+
/>
11+
<meta name="author" content="Brian Mitchell" />
12+
<meta property="og:title" content="Svelte Compare Image" />
13+
<meta property="og:type" content="website" />
14+
<meta property="og:url" content="https://brianm.me/svelte-compare-image/" />
15+
<meta property="og:description" content="" />
16+
<meta property="og:locale" content="en_US" />
17+
<meta name="twitter:card" content="summary_large_image" />
18+
<meta name="twitter:site" content="@BrianMitchL" />
19+
<meta name="twitter:title" content="Svelte Compare Image" />
20+
<meta
21+
name="twitter:description"
22+
content="A Svelte component to compare two images"
23+
/>
824
%svelte.head%
925
</head>
1026
<body>

src/components/Example.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@
115115
imageLeftAlt="left"
116116
imageRightSrc="https://via.placeholder.com/{rightWidth}x{rightHeight}/00aaff/ffffff?text=Right"
117117
imageRightAlt="right"
118-
--slider-width="0.125rem"
119118
--handle-size="2.5rem"
119+
--slider-color="#ffffff"
120+
--slider-width="0.125rem"
120121
/>
121122
</div>
122123

src/lib/CompareImage.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
}
218218
219219
.line {
220-
background: #ffffff;
220+
background: var(--slider-color, #ffffff);
221221
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),
222222
0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
223223
flex: 0 1 auto;
@@ -231,7 +231,7 @@
231231
display: flex;
232232
justify-content: center;
233233
align-items: center;
234-
border: var(--slider-width, 0.125rem) solid #ffffff;
234+
border: var(--slider-width, 0.125rem) solid var(--slider-color, #ffffff);
235235
border-radius: 100%;
236236
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),
237237
0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
@@ -242,7 +242,8 @@
242242
.handle::before {
243243
content: "";
244244
border: inset calc(var(--handle-size, 2.5rem) * 0.15) rgba(0, 0, 0, 0);
245-
border-right: calc(var(--handle-size, 2.5rem) * 0.15) solid #ffffff;
245+
border-right: calc(var(--handle-size, 2.5rem) * 0.15) solid
246+
var(--slider-color, #ffffff);
246247
height: 0;
247248
margin-right: calc(var(--handle-size, 2.5rem) * 0.25);
248249
width: 0;
@@ -251,7 +252,8 @@
251252
.handle::after {
252253
content: "";
253254
border: inset calc(var(--handle-size, 2.5rem) * 0.15) rgba(0, 0, 0, 0);
254-
border-left: calc(var(--handle-size, 2.5rem) * 0.15) solid #ffffff;
255+
border-left: calc(var(--handle-size, 2.5rem) * 0.15) solid
256+
var(--slider-color, #ffffff);
255257
height: 0;
256258
width: 0;
257259
}

src/routes/index.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
<h1>Svelte Compare Image</h1>
1010
<p>
11-
A component to compare two images by dragging a slider to reveal the other
12-
image. Find the source on <a
11+
A Svelte component to compare two images. Find the source on <a
1312
href="https://github.com/BrianMitchL/svelte-compare-image">GitHub</a
1413
>
1514
and on NPM at

0 commit comments

Comments
 (0)