@loadsmart/miranda-react 3.0.0-beta.32 → 3.0.0-beta.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { ToggleGroup as WCToggleGroup } from '@loadsmart/miranda-wc';
2
+ import type { SelectionType, SelectionValue } from '@loadsmart/miranda-wc';
2
3
  import type { EventName, WebComponentProps } from '@lit/react';
3
4
  import type { ReactNode, ComponentProps } from 'react';
4
5
  import type { MirandaChangeEvent } from '../../utils/types';
@@ -12,16 +13,39 @@ declare global {
12
13
  declare const WiredToggleGroup: import("@lit/react").ReactWebComponent<WCToggleGroup, {
13
14
  onChange: EventName<MirandaChangeEvent<WCToggleGroup>>;
14
15
  }>;
15
- export type ToggleGroupOption = {
16
- value: string;
16
+ export type ToggleGroupOption<TValue extends string> = {
17
+ value: TValue;
17
18
  label?: string;
18
19
  leading?: ReactNode;
19
20
  disabled?: boolean;
20
21
  };
21
- export type ToggleGroupProps = ComponentProps<typeof WiredToggleGroup> & {
22
- options?: ToggleGroupOption[];
22
+ type SingleProps<OptionValue extends string, TValue = OptionValue | null> = {
23
+ type?: 'single';
24
+ value?: TValue;
25
+ onChange?: OnChangeEvent<TValue>;
23
26
  };
24
- declare function ToggleGroup(props: ToggleGroupProps): import("react/jsx-runtime").JSX.Element;
27
+ type SingleStrictProps<OptionValue extends string, TValue = OptionValue> = {
28
+ type?: 'single-strict';
29
+ value?: TValue;
30
+ onChange?: OnChangeEvent<TValue>;
31
+ };
32
+ type MultipleProps<OptionValue extends string, TValue = Array<OptionValue> | ReadonlyArray<OptionValue> | null> = {
33
+ type?: 'multiple';
34
+ value?: TValue;
35
+ onChange?: OnChangeEvent<TValue>;
36
+ };
37
+ export type OnChangeEvent<T> = (event: MirandaChangeEvent<Omit<WCToggleGroup, 'value'> & {
38
+ value: T;
39
+ }>) => void;
40
+ export type ToggleGroupProps<TSelectionType extends SelectionType = SelectionType, OptionValue extends string = string, TOptions extends ReadonlyArray<ToggleGroupOption<string>> = ReadonlyArray<ToggleGroupOption<OptionValue>>> = Omit<ComponentProps<typeof WiredToggleGroup>, 'type' | 'value' | 'onChange'> & {
41
+ type?: TSelectionType;
42
+ options?: TOptions;
43
+ } & (TSelectionType extends 'single' ? SingleProps<OptionValue> : TSelectionType extends 'single-strict' ? SingleStrictProps<OptionValue> : TSelectionType extends 'multiple' ? MultipleProps<OptionValue> : {
44
+ type?: TSelectionType;
45
+ value?: SelectionValue<OptionValue>;
46
+ onChange?: OnChangeEvent<OptionValue>;
47
+ });
48
+ declare function ToggleGroup<TSelectionType extends SelectionType = SelectionType, OptionValue extends string = string>({ options, children, onChange, ...rest }: ToggleGroupProps<TSelectionType, OptionValue>): import("react/jsx-runtime").JSX.Element;
25
49
  declare namespace ToggleGroup {
26
50
  var Toggle: import("react").ForwardRefExoticComponent<Omit<import("./Toggle").ToggleProps, "ref"> & import("react").RefAttributes<import("@loadsmart/miranda-wc").Toggle>>;
27
51
  }
package/dist/index.js CHANGED
@@ -1205,9 +1205,12 @@ const WiredToggleGroup = createComponent({
1205
1205
  },
1206
1206
  displayName: 'ToggleGroup',
1207
1207
  });
1208
- function ToggleGroup(props) {
1209
- const { options, children, ...rest } = props;
1210
- return (jsx(WiredToggleGroup, { ...rest, children: children !== null && children !== void 0 ? children : (options || []).map(function renderOption(option) {
1208
+ function ToggleGroup({ options, children, onChange, ...rest }) {
1209
+ return (jsx(WiredToggleGroup
1210
+ // @ts-expect-error -- we can't type this properly because of the way the WC is implemented
1211
+ , {
1212
+ // @ts-expect-error -- we can't type this properly because of the way the WC is implemented
1213
+ onChange: onChange, ...rest, children: children !== null && children !== void 0 ? children : (options || []).map(function renderOption(option) {
1211
1214
  const { label, value: optionValue, ...others } = option;
1212
1215
  return (jsx(Toggle, { ...others, value: optionValue, children: label }, optionValue));
1213
1216
  }) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadsmart/miranda-react",
3
- "version": "3.0.0-beta.32",
3
+ "version": "3.0.0-beta.33",
4
4
  "description": "React component library based on Miranda Web Components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -41,8 +41,8 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@loadsmart/miranda-tokens": "4.0.0-beta.32",
45
- "@loadsmart/miranda-wc": "3.0.0-beta.32",
44
+ "@loadsmart/miranda-tokens": "4.0.0-beta.33",
45
+ "@loadsmart/miranda-wc": "3.0.0-beta.33",
46
46
  "@lit/react": "^1.0.5",
47
47
  "react-is": "^18.3.1"
48
48
  },