@edu-tosel/design 1.0.83 → 1.0.85

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,5 +1,5 @@
1
1
  import { Replace } from "./Action";
2
- import { OnClick, Titles } from "./Property";
2
+ import { Click, OnClick, Titles } from "./Property";
3
3
  export interface DataPackage<T> {
4
4
  dataField: DataField<T>;
5
5
  dataSet: Omit<DataSet<T>, "renderItem">;
@@ -40,10 +40,10 @@ declare function isDataSelectRoll(obj: any): obj is DataSelectRoll;
40
40
  type DataButton<T> = {
41
41
  type: "button";
42
42
  onClick: OnClick<T>;
43
- hoverTitle?: ((item: T) => string) | string;
43
+ hoverTitle?: Click<T, string> | string;
44
44
  option?: {
45
- text?: string;
46
- background?: string;
45
+ text?: Click<T, string> | string;
46
+ background?: Click<T, string> | string;
47
47
  };
48
48
  };
49
49
  declare function isDataButton<T>(obj: any): obj is DataButton<T>;
@@ -41,6 +41,7 @@ export type Size = "5xs" | "4xs" | "3xs" | "2xs" | "xs" | "sm" | "md" | "lg" | "
41
41
  * @property {"full"} full - Full size
42
42
  */
43
43
  export type ImageSize = "sub" | "full";
44
+ export type Click<REQ = unknown, RES = any> = (prop?: REQ) => RES;
44
45
  export type OnClick<Request = unknown, Response = unknown> = (prop?: Request) => Response | ((prop?: Request) => Promise<Response>);
45
46
  export interface Button extends LabelWidget {
46
47
  }
@@ -45,9 +45,15 @@ function RowElement(props) {
45
45
  return _jsx(SelectRoll, { item: item, entry: props.entry, data: data });
46
46
  }
47
47
  if (isDataButton(data)) {
48
- return (_jsx(Label.Button, { title: item[key], hoverTitle: typeof data.hoverTitle === "string"
49
- ? data.hoverTitle
50
- : data.hoverTitle?.(item), onClick: () => data.onClick(item), option: { ...data.option, width: "xs", height: "xs" } }));
48
+ const { onClick, hoverTitle, option } = data;
49
+ const { background, text } = option ?? {};
50
+ return (_jsx(Label.Button, { title: item[key], hoverTitle: typeof hoverTitle === "string" ? hoverTitle : hoverTitle?.(item), onClick: () => onClick(item), option: {
51
+ ...data.option,
52
+ background: typeof background === "string" ? background : background?.(item),
53
+ text: typeof text === "string" ? text : text?.(item),
54
+ width: "xs",
55
+ height: "xs",
56
+ } }));
51
57
  }
52
58
  return _jsx(_Fragment, { children: item[key] });
53
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edu-tosel/design",
3
- "version": "1.0.83",
3
+ "version": "1.0.85",
4
4
  "description": "UI components for International TOSEL Committee",
5
5
  "keywords": [
6
6
  "jsx",
package/store/index.d.ts CHANGED
@@ -23,7 +23,7 @@ interface ActionProps<T = any> {
23
23
  setDark: () => void;
24
24
  items: T[];
25
25
  setItems: (prop: T[]) => void;
26
- updateItem: (prop: T, key: string) => void;
26
+ updateItem: (prop: T, key: string | string[]) => void;
27
27
  }
28
28
  export declare const useActionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ActionProps<any>>>;
29
29
  export {};
package/store/index.js CHANGED
@@ -70,6 +70,17 @@ export const useActionStore = create((set) => ({
70
70
  items: [],
71
71
  setItems: (prop) => set({ items: prop }),
72
72
  updateItem: (item, key) => set((state) => ({
73
- items: state.items.map((prevItem) => prevItem.id === item.id ? { ...prevItem, [key]: item[key] } : prevItem),
73
+ items: state.items.map((prevItem) => {
74
+ if (typeof key === "string")
75
+ return prevItem.id === item.id
76
+ ? { ...prevItem, [key]: item[key] }
77
+ : prevItem;
78
+ return prevItem.id === item.id
79
+ ? {
80
+ ...prevItem,
81
+ ...key.reduce((acc, cur) => ({ ...acc, [cur]: item[cur] }), {}),
82
+ }
83
+ : prevItem;
84
+ }),
74
85
  })),
75
86
  }));
package/version.txt CHANGED
@@ -1 +1 @@
1
- 1.0.83
1
+ 1.0.85