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
- pressedControlled?: boolean;
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
- if (!props.pressedControlled) {
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,
@@ -31,7 +31,6 @@
31
31
  'disabled',
32
32
  'pressed',
33
33
  'onPressedChange',
34
- 'pressedControlled',
35
34
  ])(props),
36
35
  );
37
36
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ui-ingredients",
3
3
  "type": "module",
4
4
  "license": "MIT",
5
- "version": "0.2.0",
5
+ "version": "0.3.0",
6
6
  "packageManager": "pnpm@9.7.0",
7
7
  "svelte": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",