@hanzo/ui 4.3.6 → 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 +1 -3
- package/primitives/form.tsx +1 -2
- package/tsconfig.json +1 -6
- package/util/format-to-max-char.ts +20 -3
- package/util/number-abbreviate.ts +100 -0
- package/declare.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/ui",
|
|
3
|
-
"version": "4.3.
|
|
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",
|
|
@@ -82,7 +81,6 @@
|
|
|
82
81
|
"lodash.isplainobject": "^4.0.6",
|
|
83
82
|
"lodash.merge": "^4.6.2",
|
|
84
83
|
"markdown-to-jsx": "^7.4.7",
|
|
85
|
-
"number-abbreviate": "^2.0.0",
|
|
86
84
|
"postcss-selector-parser": "^6.0.16",
|
|
87
85
|
"react-day-picker": "^8.10.1",
|
|
88
86
|
"react-intersection-observer": "^9.8.2",
|
package/primitives/form.tsx
CHANGED
|
@@ -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,
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import Abbr from 'number-abbreviate'
|
|
1
|
+
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
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// cf: https://github.com/domharrington/js-number-abbreviate/blob/master/index.js
|
|
2
|
+
|
|
3
|
+
const DEF_ABBREVIATIONS = ['K', 'M', 'B', 'T']
|
|
4
|
+
|
|
5
|
+
class NumberAbbreviator {
|
|
6
|
+
|
|
7
|
+
private _units: string[]
|
|
8
|
+
|
|
9
|
+
constructor(units?: string[]) {
|
|
10
|
+
this._units = units ?? DEF_ABBREVIATIONS
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
private _abbreviate = (n: number, decPlaces: number): string => {
|
|
14
|
+
|
|
15
|
+
const _decPlaces = Math.pow(10, decPlaces)
|
|
16
|
+
let _n = n
|
|
17
|
+
|
|
18
|
+
let _unit
|
|
19
|
+
for (let i = this._units.length - 1; i >= 0; i--) {
|
|
20
|
+
const size = Math.pow(10, (i + 1) * 3)
|
|
21
|
+
if (size <= _n) {
|
|
22
|
+
_n = Math.round(_n * _decPlaces / size) / _decPlaces
|
|
23
|
+
if ((_n === 1000) && (i < this._units.length - 1)) {
|
|
24
|
+
_n = 1
|
|
25
|
+
i++
|
|
26
|
+
}
|
|
27
|
+
_unit = this._units[i]
|
|
28
|
+
break
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return _n.toString() + (_unit ?? '')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
abbreviate = (n: number, decPlaces: number) => {
|
|
35
|
+
const abbreviatedNumber = this._abbreviate(Math.abs(n), decPlaces || 0)
|
|
36
|
+
return n < 0 ? '-' + abbreviatedNumber : abbreviatedNumber
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export default NumberAbbreviator
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
(function(root){
|
|
45
|
+
'use strict';
|
|
46
|
+
|
|
47
|
+
function NumberAbbreviate() {
|
|
48
|
+
var units
|
|
49
|
+
if (!(this instanceof NumberAbbreviate)) {
|
|
50
|
+
// function usage: abbrev(n, decPlaces, units)
|
|
51
|
+
var n = arguments[0]
|
|
52
|
+
var decPlaces = arguments[1]
|
|
53
|
+
units = arguments[2]
|
|
54
|
+
var ab = new NumberAbbreviate(units)
|
|
55
|
+
return ab.abbreviate(n, decPlaces)
|
|
56
|
+
}
|
|
57
|
+
// class usage: new NumberAbbreviate(units)
|
|
58
|
+
units = arguments[0]
|
|
59
|
+
this.units = units == null ? ['k', 'm', 'b', 't'] : units
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
NumberAbbreviate.prototype._abbreviate = function(number, decPlaces) {
|
|
63
|
+
decPlaces = Math.pow(10, decPlaces)
|
|
64
|
+
|
|
65
|
+
for (var i = this.units.length - 1; i >= 0; i--) {
|
|
66
|
+
|
|
67
|
+
var size = Math.pow(10, (i + 1) * 3)
|
|
68
|
+
|
|
69
|
+
if (size <= number) {
|
|
70
|
+
number = Math.round(number * decPlaces / size) / decPlaces
|
|
71
|
+
|
|
72
|
+
if ((number === 1000) && (i < this.units.length - 1)) {
|
|
73
|
+
number = 1
|
|
74
|
+
i++
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
number += this.units[i]
|
|
78
|
+
|
|
79
|
+
break
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return number
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
NumberAbbreviate.prototype.abbreviate = function(number, decPlaces) {
|
|
87
|
+
var isNegative = number < 0
|
|
88
|
+
var abbreviatedNumber = this._abbreviate(Math.abs(number), decPlaces || 0)
|
|
89
|
+
|
|
90
|
+
return isNegative ? '-' + abbreviatedNumber : abbreviatedNumber;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
94
|
+
module.exports = NumberAbbreviate
|
|
95
|
+
} else {
|
|
96
|
+
root.NumberAbbreviate = NumberAbbreviate
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
})(this);
|
|
100
|
+
*/
|
package/declare.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'number-abbreviate'
|