@gateweb/react-utils 2.2.0 → 2.3.0

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.
@@ -463,14 +463,14 @@ type ScenesList<T extends Record<string, {
463
463
  type NormalReturn<T extends Record<string, any>, VK extends string> = {
464
464
  Enum: EnumMap<T, VK>;
465
465
  List: NormalList<T>;
466
- getLabel: (value: ValueAtKey<T, VK>) => string;
466
+ getLabel: (value: ValueAtKey<T, VK>, keep?: boolean) => string | undefined;
467
467
  };
468
468
  type ScenesReturn<T extends Record<string, {
469
469
  scenes: Record<string, Record<string, any>>;
470
470
  }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string> = {
471
471
  Enum: EnumMap<T, VK>;
472
472
  List: ScenesList<T, Scene, VK>;
473
- getLabel: (value: ValueAtKey<T, VK>) => string;
473
+ getLabel: (value: ValueAtKey<T, VK>, keep?: boolean) => string | undefined;
474
474
  };
475
475
  type AsNamed<R, N extends string> = {
476
476
  [K in keyof R as K extends 'Enum' ? `Enum${N}` : K extends 'List' ? `${N}List` : K extends 'getLabel' ? `get${N}Label` : never]: R[K];
package/dist/cjs/index.js CHANGED
@@ -274,9 +274,10 @@ function createEnumLikeObject(obj, options) {
274
274
  ...item
275
275
  }));
276
276
  }
277
- function getLabel(value) {
277
+ function getLabel(value, keep = true) {
278
278
  const targetItem = list.find((item)=>// 如果 list 項目內含有 valueKey 對應欄位,優先以該欄位比對;否則以 value 欄位比對
279
279
  valueKey in item ? item[valueKey] === value : item.value === value);
280
+ if (!targetItem && !keep) return undefined;
280
281
  if (!targetItem) return String(value);
281
282
  if ('label' in targetItem) return targetItem.label;
282
283
  return String(value);
@@ -463,14 +463,14 @@ type ScenesList<T extends Record<string, {
463
463
  type NormalReturn<T extends Record<string, any>, VK extends string> = {
464
464
  Enum: EnumMap<T, VK>;
465
465
  List: NormalList<T>;
466
- getLabel: (value: ValueAtKey<T, VK>) => string;
466
+ getLabel: (value: ValueAtKey<T, VK>, keep?: boolean) => string | undefined;
467
467
  };
468
468
  type ScenesReturn<T extends Record<string, {
469
469
  scenes: Record<string, Record<string, any>>;
470
470
  }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string> = {
471
471
  Enum: EnumMap<T, VK>;
472
472
  List: ScenesList<T, Scene, VK>;
473
- getLabel: (value: ValueAtKey<T, VK>) => string;
473
+ getLabel: (value: ValueAtKey<T, VK>, keep?: boolean) => string | undefined;
474
474
  };
475
475
  type AsNamed<R, N extends string> = {
476
476
  [K in keyof R as K extends 'Enum' ? `Enum${N}` : K extends 'List' ? `${N}List` : K extends 'getLabel' ? `get${N}Label` : never]: R[K];
package/dist/es/index.mjs CHANGED
@@ -268,9 +268,10 @@ function createEnumLikeObject(obj, options) {
268
268
  ...item
269
269
  }));
270
270
  }
271
- function getLabel(value) {
271
+ function getLabel(value, keep = true) {
272
272
  const targetItem = list.find((item)=>// 如果 list 項目內含有 valueKey 對應欄位,優先以該欄位比對;否則以 value 欄位比對
273
273
  valueKey in item ? item[valueKey] === value : item.value === value);
274
+ if (!targetItem && !keep) return undefined;
274
275
  if (!targetItem) return String(value);
275
276
  if ('label' in targetItem) return targetItem.label;
276
277
  return String(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gateweb/react-utils",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "React Utils for GateWeb",
5
5
  "homepage": "https://github.com/GatewebSolutions/react-utils",
6
6
  "files": [