Skip to content

Commit 95ce282

Browse files
committed
feat(shared): adjust ripple styles
1 parent 20a5435 commit 95ce282

File tree

4 files changed

+47
-31
lines changed

4 files changed

+47
-31
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./useRipple";
22
export * from "./types";
3+
export * from "./utils";
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import type { Component } from "vue";
1+
import type { Component, HTMLAttributes } from "vue";
22

33
export type HTMLNextUIVueProps<T extends keyof HTMLElementTagNameMap = "div"> =
44
{
55
as?: Component | T | (string & {});
6-
};
6+
} & /* @vue-ignore */ HTMLAttributes;
7+
8+
/**
9+
* Flattens a complex intersection type into a single object type for better readability.
10+
*/
11+
export type Prettify<T> = {
12+
[K in keyof T]: T[K];
13+
} & {};
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
import { onBeforeMount, ref } from 'vue'
2-
import { type MaybeRefOrGetter, useEventListener } from '@vueuse/core'
1+
import { onBeforeMount, ref } from "vue";
2+
import { type MaybeRefOrGetter, useEventListener } from "@vueuse/core";
33

4-
const rippleElement = ref()
4+
const rippleElement = ref();
55

66
function setCSSStyle(el: HTMLElement, style: CSSStyleDeclaration) {
77
for (const [key, value] of Object.entries(style)) {
8-
el.style[key as any] = value
8+
el.style[key as any] = value;
99
}
1010
}
1111

1212
function ripple(event: MouseEvent) {
13-
const target = event.currentTarget as HTMLElement
14-
const { x, y, width, height } = target.getBoundingClientRect()
15-
const { clientX, clientY } = event
13+
const target = event.currentTarget as HTMLElement;
14+
const { x, y, width, height } = target.getBoundingClientRect();
15+
const { clientX, clientY } = event;
1616

17-
const newElement = rippleElement.value?.cloneNode() as HTMLSpanElement
17+
const newElement = rippleElement.value?.cloneNode() as HTMLSpanElement;
1818
const style = {
19-
position: 'absolute',
19+
position: "absolute",
2020
left: `${clientX - x}px`,
2121
top: `${clientY - y}px`,
22-
borderRadius: '50%',
23-
background: 'white',
22+
borderRadius: "50%",
23+
backgroundColor: "currentColor",
2424
transform: `translate(-50%, -50%)`,
25-
pointerEvents: 'none',
26-
} as CSSStyleDeclaration
25+
pointerEvents: "none",
26+
} as CSSStyleDeclaration;
2727

28-
setCSSStyle(newElement, style)
28+
setCSSStyle(newElement, style);
2929

30-
const radius = Math.round(Math.hypot(width, height)) * 2
30+
const radius = Math.round(Math.hypot(width, height)) * 2;
3131
const animate = newElement.animate(
3232
{
33-
opacity: [0.5, 0],
34-
width: ['0', `${radius}px`],
35-
height: ['0', `${radius}px`],
33+
opacity: [0.35, 0],
34+
width: ["0", `${radius}px`],
35+
height: ["0", `${radius}px`],
3636
},
3737
{
3838
duration: 450,
39-
easing: 'ease-in',
40-
fill: 'forwards',
39+
easing: "ease-in",
40+
fill: "forwards",
4141
},
42-
)
43-
animate.addEventListener('finish', () => {
44-
target.removeChild(newElement)
45-
})
46-
target.appendChild(newElement)
42+
);
43+
animate.addEventListener("finish", () => {
44+
target.removeChild(newElement);
45+
});
46+
target.appendChild(newElement);
4747
}
4848

4949
export function useRipple(
5050
target: MaybeRefOrGetter<HTMLElement | null | undefined>,
5151
) {
5252
onBeforeMount(() => {
53-
rippleElement.value = document.createElement('span')
54-
})
55-
useEventListener(target, 'click', ripple)
53+
rippleElement.value = document.createElement("span");
54+
});
55+
useEventListener(target, "click", ripple);
5656
}
5757

58-
export default useRipple
58+
export default useRipple;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function pureObject(obj: Record<string, any>): Record<string, any> {
2+
return Object.entries(obj).reduce((acc, [key, value]) => {
3+
if (value !== undefined && value !== null) {
4+
acc[key] = value;
5+
}
6+
return acc;
7+
}, Object.create(null));
8+
}

0 commit comments

Comments
 (0)