@hanzo/ui 4.3.7 → 4.3.8

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.3.7",
3
+ "version": "4.3.8",
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/",
@@ -14,7 +14,6 @@
14
14
  "url": "git+https://github.com/hanzoai/react-sdk.git",
15
15
  "directory": "pkg/ui"
16
16
  },
17
- "types": "./declare.d.ts",
18
17
  "keywords": [
19
18
  "components",
20
19
  "ecommerce",
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  'use client'
3
2
  import * as React from "react"
4
3
  import * as LabelPrimitive from "@radix-ui/react-label"
@@ -7,7 +6,7 @@ import { Slot } from "@radix-ui/react-slot"
7
6
  import {
8
7
  Controller,
9
8
  type ControllerProps,
10
- FieldPath,
9
+ type FieldPath,
11
10
  type FieldValues,
12
11
  FormProvider,
13
12
  useFormContext,
@@ -2,6 +2,21 @@ import Abbr from './number-abbreviate'
2
2
 
3
3
  const abbr = new Abbr(['K', 'M', 'B', 'T'])
4
4
 
5
+ const isPowerOf10 = (n: number) => {
6
+ if (n <= 0) {
7
+ return false
8
+ }
9
+
10
+ while (n > 1) {
11
+ if (n % 10 !== 0) {
12
+ return false
13
+ }
14
+ n /= 10
15
+ }
16
+
17
+ return true
18
+ }
19
+
5
20
  const formatToMaxChar = (
6
21
  n: number | null,
7
22
  maxChars: number,
@@ -13,7 +28,7 @@ const formatToMaxChar = (
13
28
  roundingAdds: number = 1
14
29
  ): {
15
30
  result: string
16
- change: 'rounded' | 'none' | 'empty'
31
+ change: 'rounded' | 'none' | 'abbr' | 'empty'
17
32
  } => {
18
33
  if (n === null) {
19
34
  return {
@@ -40,10 +55,12 @@ const formatToMaxChar = (
40
55
  }
41
56
  }
42
57
  else {
58
+
43
59
  const str = abbr.abbreviate(n, maxChars)
44
60
  const numStr = str.slice(0, -1)
45
61
  const abbreviation = str.slice(-1)
46
62
  const numerical = parseFloat(numStr)
63
+
47
64
  // minus abbr, dec point, and roundingAdds / tilda,
48
65
  // (1 + 1 + roundingAdds)
49
66
  // ("precision" does NOT include the decimal point itself,
@@ -53,7 +70,7 @@ const formatToMaxChar = (
53
70
  const roundedNumerical = parseFloat(roundedString)
54
71
  return {
55
72
  result: roundedNumerical.toString() + abbreviation,
56
- change: 'rounded'
73
+ change: roundedNumerical === numerical ? 'abbr' : 'rounded'
57
74
  }
58
75
  }
59
76
  }