Skip to content

Commit 610a53e

Browse files
committed
Fix display from compare-content
1 parent ce552e7 commit 610a53e

3 files changed

Lines changed: 42 additions & 23 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@atomico/components",
33
"description": "Generic and utility webcomponents created with Atomico",
4-
"version": "2.4.4",
4+
"version": "2.4.5",
55
"type": "module",
66
"workspaces": [
77
"src/**/*"

src/components/compare-content/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@atomico/compare-content",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"type": "module",
55
"publishConfig": {
66
"access": "public"

src/components/compare-content/src/elements.tsx

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,36 @@ function compareContent({ value, vertical }: Props<typeof compareContent>) {
77
const refDrag = useRef();
88
const slots = useProxySlot<HTMLElement>(ref);
99
const [, x, y] = useDragResize(refDrag, [value, value]);
10+
let v = vertical ? y : x;
11+
v = v > 1 ? 1 : v < 0 ? 0 : v;
1012
return (
1113
<host shadowDom>
1214
<slot name="content" ref={ref}></slot>
13-
<div class="mask" style={`--v:${vertical ? y : x};`}>
15+
<div class="mask">
1416
{slots.map((child, i) => (
1517
<div class={i ? "last" : "first"} staticNode>
1618
<slot name={(child.slot = `content-${i}`)} />
1719
</div>
1820
))}
19-
<button class="drag" ref={refDrag} staticNode>
20-
<div class="drag-icon" part="icon">
21-
<slot name="icon">
22-
<svg
23-
width="12.001"
24-
height="7.999"
25-
viewBox="0 0 12.001 7.999"
26-
>
27-
<path
28-
d="M-6775-1004l4,4-4,4Zm-8,4,4-4v8Z"
29-
transform="translate(6783.001 1004)"
30-
fill="var(--icon-fill)"
31-
/>
32-
</svg>
33-
</slot>
34-
</div>
35-
</button>
3621
</div>
22+
<button class="drag" ref={refDrag} staticNode>
23+
<div class="drag-icon" part="icon">
24+
<slot name="icon">
25+
<svg
26+
width="12.001"
27+
height="7.999"
28+
viewBox="0 0 12.001 7.999"
29+
>
30+
<path
31+
d="M-6775-1004l4,4-4,4Zm-8,4,4-4v8Z"
32+
transform="translate(6783.001 1004)"
33+
fill="var(--icon-fill)"
34+
/>
35+
</svg>
36+
</slot>
37+
</div>
38+
</button>
39+
<style>{`:host{--v:${v} !important;}`}</style>
3740
</host>
3841
);
3942
}
@@ -48,17 +51,24 @@ compareContent.styles = css`
4851
4952
:host {
5053
display: inline-block;
51-
overflow: hidden;
54+
position: relative;
5255
--v: 0.5;
5356
--cursor: col-resize;
5457
--icon-rotate: 0deg;
58+
--percent: calc(100% * var(--v));
5559
}
5660
.mask {
5761
position: relative;
58-
--percent: calc(100% * var(--v));
62+
overflow: hidden;
5963
}
6064
.first {
6165
position: relative;
66+
clip-path: polygon(
67+
0% 0%,
68+
var(--percent) 0%,
69+
var(--percent) 100%,
70+
0% 100%
71+
);
6272
}
6373
.last {
6474
width: 100%;
@@ -72,6 +82,7 @@ compareContent.styles = css`
7282
var(--percent) 100%
7383
);
7484
}
85+
7586
.drag {
7687
all: unset;
7788
position: absolute;
@@ -110,7 +121,6 @@ compareContent.styles = css`
110121
top: var(--percent);
111122
transform: translateY(-50%);
112123
}
113-
114124
:host([vertical]) .last {
115125
clip-path: polygon(
116126
0% var(--percent),
@@ -119,8 +129,17 @@ compareContent.styles = css`
119129
0% 100%
120130
);
121131
}
132+
:host([vertical]) .first {
133+
clip-path: polygon(
134+
0% 0%,
135+
100% 0%,
136+
100% var(--percent),
137+
0% var(--percent)
138+
);
139+
}
122140
::slotted(img) {
123141
pointer-events: none;
142+
display: block;
124143
}
125144
::slotted(*) {
126145
max-width: 100%;

0 commit comments

Comments
 (0)