@winchsa/ui 0.1.60 → 0.1.62

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.
@@ -15,12 +15,12 @@ type __VLS_Slots = {} & {
15
15
  default?: (props: typeof __VLS_76) => any;
16
16
  };
17
17
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
18
- collapsed: (isContentCollapsed: boolean) => any;
19
18
  refresh: (hideOverlay: () => void) => any;
19
+ collapsed: (isContentCollapsed: boolean) => any;
20
20
  trash: () => any;
21
21
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
22
- onCollapsed?: ((isContentCollapsed: boolean) => any) | undefined;
23
22
  onRefresh?: ((hideOverlay: () => void) => any) | undefined;
23
+ onCollapsed?: ((isContentCollapsed: boolean) => any) | undefined;
24
24
  onTrash?: (() => any) | undefined;
25
25
  }>, {
26
26
  title: string;
@@ -15,12 +15,12 @@ type __VLS_Slots = {} & {
15
15
  default?: (props: typeof __VLS_76) => any;
16
16
  };
17
17
  declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
18
- collapsed: (isContentCollapsed: boolean) => any;
19
18
  refresh: (hideOverlay: () => void) => any;
19
+ collapsed: (isContentCollapsed: boolean) => any;
20
20
  trash: () => any;
21
21
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
22
- onCollapsed?: ((isContentCollapsed: boolean) => any) | undefined;
23
22
  onRefresh?: ((hideOverlay: () => void) => any) | undefined;
23
+ onCollapsed?: ((isContentCollapsed: boolean) => any) | undefined;
24
24
  onTrash?: (() => any) | undefined;
25
25
  }>, {
26
26
  title: string;
@@ -80,8 +80,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
80
80
  "onUpdate:model-value"?: ((value: unknown) => any) | undefined;
81
81
  }>, {
82
82
  isLoading: boolean;
83
- hideDetails: boolean;
84
83
  clearable: boolean;
84
+ hideDetails: boolean;
85
85
  hideSelected: boolean;
86
86
  querySearchParam: string;
87
87
  descriptionKey: string;
@@ -213,7 +213,7 @@ watch([() => props.trackByValue, defaultOptions], async ([trackByValue, _default
213
213
  }
214
214
  const optionsToSelect = loadedValues.map((value2) => items.find((item) => item?.[props.trackBy] == value2)).filter(Boolean);
215
215
  if (optionsToSelect.length > 0) {
216
- emits("update:model-value", optionsToSelect);
216
+ emits("update:model-value", props.multiple ? optionsToSelect : optionsToSelect[0]);
217
217
  }
218
218
  }, { immediate: true });
219
219
  watch(() => props.errorMessages, (newErrorMessages) => {
@@ -80,8 +80,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
80
80
  "onUpdate:model-value"?: ((value: unknown) => any) | undefined;
81
81
  }>, {
82
82
  isLoading: boolean;
83
- hideDetails: boolean;
84
83
  clearable: boolean;
84
+ hideDetails: boolean;
85
85
  hideSelected: boolean;
86
86
  querySearchParam: string;
87
87
  descriptionKey: string;
@@ -17,7 +17,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {},
17
17
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
18
18
  "onUpdate:modelValue"?: ((value: string[] | null) => any) | undefined;
19
19
  }>, {
20
- validateOn: "input" | "submit" | "blur lazy" | "input lazy" | "lazy" | "lazy blur" | "lazy input" | "lazy submit" | "submit lazy" | "blur";
20
+ validateOn: "input" | "submit" | "blur" | "blur lazy" | "input lazy" | "lazy" | "lazy blur" | "lazy input" | "lazy submit" | "submit lazy";
21
21
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
22
22
  declare const _default: typeof __VLS_export;
23
23
  export default _default;
@@ -17,7 +17,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {},
17
17
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
18
18
  "onUpdate:modelValue"?: ((value: string[] | null) => any) | undefined;
19
19
  }>, {
20
- validateOn: "input" | "submit" | "blur lazy" | "input lazy" | "lazy" | "lazy blur" | "lazy input" | "lazy submit" | "submit lazy" | "blur";
20
+ validateOn: "input" | "submit" | "blur" | "blur lazy" | "input lazy" | "lazy" | "lazy blur" | "lazy input" | "lazy submit" | "submit lazy";
21
21
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
22
22
  declare const _default: typeof __VLS_export;
23
23
  export default _default;
@@ -16,7 +16,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
16
16
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
17
17
  "onUpdate:model-value"?: ((value: string) => any) | undefined;
18
18
  }>, {
19
- validateOn: "input" | "submit" | "blur lazy" | "input lazy" | "lazy" | "lazy blur" | "lazy input" | "lazy submit" | "submit lazy" | "blur";
19
+ validateOn: "input" | "submit" | "blur" | "blur lazy" | "input lazy" | "lazy" | "lazy blur" | "lazy input" | "lazy submit" | "submit lazy";
20
20
  customId: string;
21
21
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
22
22
  declare const _default: typeof __VLS_export;
@@ -16,7 +16,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
16
16
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
17
17
  "onUpdate:model-value"?: ((value: string) => any) | undefined;
18
18
  }>, {
19
- validateOn: "input" | "submit" | "blur lazy" | "input lazy" | "lazy" | "lazy blur" | "lazy input" | "lazy submit" | "submit lazy" | "blur";
19
+ validateOn: "input" | "submit" | "blur" | "blur lazy" | "input lazy" | "lazy" | "lazy blur" | "lazy input" | "lazy submit" | "submit lazy";
20
20
  customId: string;
21
21
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
22
22
  declare const _default: typeof __VLS_export;
@@ -8,5 +8,5 @@ export declare const extractDate: (dateString: string | Date | null, format?: st
8
8
  month: string;
9
9
  year: string;
10
10
  } | null;
11
- export declare const formatNumber: (number: number | undefined | string, withCurrency?: boolean) => string;
11
+ export declare const formatNumber: (number?: number | string | null, withCurrency?: boolean) => string;
12
12
  export declare const formatNumberColor: (number: number | string | undefined) => string;
@@ -47,27 +47,24 @@ const extractDate = (dateString, format = "DD/MM/YYYY", hasTime = true) => {
47
47
  };
48
48
  };
49
49
  exports.extractDate = extractDate;
50
+ const RIYAL_SYMBOL = String.fromCharCode(59392);
51
+ const NO_BREAK_SPACE = String.fromCharCode(160);
52
+ const LEFT_TO_RIGHT_ISOLATE = String.fromCharCode(8294);
53
+ const POP_DIRECTIONAL_ISOLATE = String.fromCharCode(8297);
50
54
  const formatNumber = (number, withCurrency = false) => {
51
- const locale = localStorage.getItem("winch-lang") ?? "ar";
52
- const currency = withCurrency ? String.fromCharCode(59392) : "";
53
- if (number === void 0 || number === null || number === "" || number === 0) {
54
- return locale !== "ar" ? `${currency} 0` : `0 ${currency}`;
55
- }
56
- if (typeof number === "string") {
57
- number = parseFloat(number);
58
- }
59
- const needsTwoDecimalPlaces = number % 1 !== 0;
60
- const options = {
61
- minimumFractionDigits: needsTwoDecimalPlaces ? 2 : 0,
62
- maximumFractionDigits: needsTwoDecimalPlaces ? 2 : 0
63
- };
64
- const formatted = Math.abs(number).toLocaleString("en-US", options);
65
- return locale !== "ar" ? `${currency} ${number < 0 ? `${formatted}-` : formatted}` : `${number < 0 ? `-${formatted}` : formatted} ${currency}`;
55
+ const value = Number(number || 0);
56
+ const absolute = Math.abs(value).toLocaleString("en-US", {
57
+ minimumFractionDigits: 2,
58
+ maximumFractionDigits: 2
59
+ }).replace(/\.00$/, "");
60
+ const formatted = value < 0 && absolute !== "0" ? `-${absolute}` : absolute;
61
+ const amount = withCurrency ? `${RIYAL_SYMBOL}${NO_BREAK_SPACE}${formatted}` : formatted;
62
+ return `${LEFT_TO_RIGHT_ISOLATE}${amount}${POP_DIRECTIONAL_ISOLATE}`;
66
63
  };
67
64
  exports.formatNumber = formatNumber;
68
65
  const formatNumberColor = number => {
69
66
  const parsedNumber = typeof number === "string" ? parseFloat(number) : number;
70
- if (parsedNumber === void 0 || parsedNumber === null || parsedNumber === 0 || isNaN(parsedNumber)) {
67
+ if (parsedNumber === void 0 || parsedNumber === null || isNaN(parsedNumber) || Math.abs(parsedNumber) < 0.01) {
71
68
  return "";
72
69
  }
73
70
  return parsedNumber > 0 ? "success" : "red";
@@ -29,26 +29,20 @@ export const extractDate = (dateString, format = "DD/MM/YYYY", hasTime = true) =
29
29
  const [, day, month, year] = match;
30
30
  return { day, month, year };
31
31
  };
32
+ const RIYAL_SYMBOL = String.fromCharCode(59392);
33
+ const NO_BREAK_SPACE = String.fromCharCode(160);
34
+ const LEFT_TO_RIGHT_ISOLATE = String.fromCharCode(8294);
35
+ const POP_DIRECTIONAL_ISOLATE = String.fromCharCode(8297);
32
36
  export const formatNumber = (number, withCurrency = false) => {
33
- const locale = localStorage.getItem("winch-lang") ?? "ar";
34
- const currency = withCurrency ? String.fromCharCode(59392) : "";
35
- if (number === void 0 || number === null || number === "" || number === 0) {
36
- return locale !== "ar" ? `${currency} 0` : `0 ${currency}`;
37
- }
38
- if (typeof number === "string") {
39
- number = parseFloat(number);
40
- }
41
- const needsTwoDecimalPlaces = number % 1 !== 0;
42
- const options = {
43
- minimumFractionDigits: needsTwoDecimalPlaces ? 2 : 0,
44
- maximumFractionDigits: needsTwoDecimalPlaces ? 2 : 0
45
- };
46
- const formatted = Math.abs(number).toLocaleString("en-US", options);
47
- return locale !== "ar" ? `${currency} ${number < 0 ? `${formatted}-` : formatted}` : `${number < 0 ? `-${formatted}` : formatted} ${currency}`;
37
+ const value = Number(number || 0);
38
+ const absolute = Math.abs(value).toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 }).replace(/\.00$/, "");
39
+ const formatted = value < 0 && absolute !== "0" ? `-${absolute}` : absolute;
40
+ const amount = withCurrency ? `${RIYAL_SYMBOL}${NO_BREAK_SPACE}${formatted}` : formatted;
41
+ return `${LEFT_TO_RIGHT_ISOLATE}${amount}${POP_DIRECTIONAL_ISOLATE}`;
48
42
  };
49
43
  export const formatNumberColor = (number) => {
50
44
  const parsedNumber = typeof number === "string" ? parseFloat(number) : number;
51
- if (parsedNumber === void 0 || parsedNumber === null || parsedNumber === 0 || isNaN(parsedNumber)) {
45
+ if (parsedNumber === void 0 || parsedNumber === null || isNaN(parsedNumber) || Math.abs(parsedNumber) < 0.01) {
52
46
  return "";
53
47
  }
54
48
  return parsedNumber > 0 ? "success" : "red";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winchsa/ui",
3
- "version": "0.1.60",
3
+ "version": "0.1.62",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {
package/dist/.DS_Store DELETED
Binary file