ui-ingredients 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,11 @@
|
|
1
1
|
import type { HTMLButtonAttributes } from 'svelte/elements';
|
2
|
+
interface PressedChangeDetails {
|
3
|
+
pressed: boolean;
|
4
|
+
}
|
2
5
|
export interface CreateToggleProps {
|
3
6
|
disabled?: boolean;
|
4
7
|
pressed?: boolean;
|
5
|
-
|
6
|
-
onPressedChange?: (pressed: boolean) => void;
|
8
|
+
onPressedChange?: (detail: PressedChangeDetails) => void;
|
7
9
|
}
|
8
10
|
export interface CreateToggleReturn {
|
9
11
|
pressed: boolean;
|
@@ -11,3 +13,4 @@ export interface CreateToggleReturn {
|
|
11
13
|
getRootProps: () => HTMLButtonAttributes;
|
12
14
|
}
|
13
15
|
export declare function createToggle(props: CreateToggleProps): any;
|
16
|
+
export {};
|
@@ -4,10 +4,8 @@ import { parts } from './anatomy.js';
|
|
4
4
|
export function createToggle(props) {
|
5
5
|
let pressed = $state(props.pressed ?? false);
|
6
6
|
function setPressed(value) {
|
7
|
-
props.onPressedChange?.(value);
|
8
|
-
|
9
|
-
pressed = value;
|
10
|
-
}
|
7
|
+
props.onPressedChange?.({ pressed: value });
|
8
|
+
pressed = value;
|
11
9
|
}
|
12
10
|
function getRootProps() {
|
13
11
|
return {
|
@@ -24,11 +22,6 @@ export function createToggle(props) {
|
|
24
22
|
...parts.root.attrs,
|
25
23
|
};
|
26
24
|
}
|
27
|
-
$effect(() => {
|
28
|
-
if (props.pressedControlled) {
|
29
|
-
pressed = props.pressed ?? false;
|
30
|
-
}
|
31
|
-
});
|
32
25
|
return reflect(() => ({
|
33
26
|
pressed,
|
34
27
|
setPressed,
|