@hanzo/ui 4.4.0 → 4.4.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/ui",
3
- "version": "4.4.0",
3
+ "version": "4.4.1",
4
4
  "description": "Library that contains shared UI primitives, support for a common design system, and other boilerplate support.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -15,7 +15,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
15
15
  className={cn(
16
16
  'flex h-10 w-full rounded-md border border-muted-3 bg-inherit px-3 py-2 text-sm ring-offset-background ' +
17
17
  'file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-2 ' +
18
- 'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 ' +
18
+ //'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 ' +
19
19
  'first-letter:disabled:cursor-not-allowed disabled:opacity-50',
20
20
  className
21
21
  )}
@@ -5,6 +5,17 @@ interface FormatThreshold {
5
5
  use: QuantityAbbrSymbol
6
6
  }
7
7
 
8
+ const usdFormatter = Intl.NumberFormat('en-US', {
9
+ style: 'currency',
10
+ currency: 'USD',
11
+ minimumFractionDigits: 2,
12
+ })
13
+
14
+ const formatAsUSCurrency = (n: number) => {
15
+ let result = usdFormatter.format(n)
16
+ return result.endsWith('.00') ? result.slice(0, -3) : result
17
+ }
18
+
8
19
  const formatAndAbbreviateAsCurrency = (
9
20
  n: number | null,
10
21
  thresholds: FormatThreshold[] = [{
@@ -31,12 +42,7 @@ const formatAndAbbreviateAsCurrency = (
31
42
  }
32
43
  }
33
44
 
34
- const usdFormatter = Intl.NumberFormat('en-US', {
35
- style: 'currency',
36
- currency: 'USD',
37
- minimumFractionDigits: 0
38
- })
39
- const formatted = usdFormatter.format(n)
45
+ const formatted = formatAsUSCurrency(n)
40
46
 
41
47
  if (n < thresholds[0].from) {
42
48
  return {
@@ -49,9 +55,9 @@ const formatAndAbbreviateAsCurrency = (
49
55
  // Get operative FormatThreshold pair...
50
56
  let threshold: FormatThreshold
51
57
  for (
52
- let i = 0, threshold = thresholds[0];
53
- i < thresholds.length, n >= thresholds[i].from;
54
- i++
58
+ let i = 0;
59
+ i < thresholds.length && n >= thresholds[i].from;
60
+ threshold = thresholds[i], i++
55
61
  ) {}
56
62
 
57
63
  // Build up units array to all units
@@ -67,18 +73,18 @@ const formatAndAbbreviateAsCurrency = (
67
73
 
68
74
  const abbreviator = new Abbr(units)
69
75
 
70
- // Use thresholdFrom as a guide to how many chars are available
76
+ // Use threshold.from as a guide to how many chars are available:
71
77
  // first digit + comma = 2
72
78
  // Possible trailing cents: '.xx'.length = 3
73
79
  // 3 - 2 = 1
74
- const charsAvail = usdFormatter.format(threshold!.from).length + 1
80
+ const charsAvail = formatAsUSCurrency(threshold!.from).length + 1
75
81
  const abbr = abbreviator.abbreviate(n, charsAvail) // arbitrary, but good approx
76
82
  const numStr = abbr.slice(0, -1)
77
83
  const abbreviation = abbr.slice(-1)
78
84
  const numerical = parseFloat(numStr)
79
85
 
80
86
  const integral = Math.floor(numerical)
81
- const integralString = usdFormatter.format(integral)
87
+ const integralString = formatAsUSCurrency(integral)
82
88
  const commas = integralString.split(',').length - 1
83
89
 
84
90
  // minus abbr, dec point, dollar sign, and roundingAdds / tilda,
@@ -89,7 +95,7 @@ const formatAndAbbreviateAsCurrency = (
89
95
  // remove trailing zeros, if any
90
96
  const roundedNumerical = parseFloat(roundedString)
91
97
  const roundedIntegral = Math.trunc(roundedNumerical)
92
- const roundedIntegralString = usdFormatter.format(roundedIntegral)
98
+ const roundedIntegralString = formatAsUSCurrency(roundedIntegral)
93
99
 
94
100
  let decimalPortion = roundedNumerical - roundedIntegral
95
101
  let result