Skip to content

Commit

Permalink
fix: number units can be symbols such as % (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbismut authored Jun 27, 2022
1 parent c0cce67 commit 61f88f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-pants-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'leva': patch
---

[number]: unit can be symbols such as '%' (#349)
9 changes: 3 additions & 6 deletions packages/leva/src/components/Number/number-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ export const format = (v: any, { pad = 0, suffix }: InternalNumberSettings) => {
export const normalize = ({ value, ...settings }: NumberInput) => {
const { min = -Infinity, max = Infinity, ..._settings } = settings

const _value = clamp(parseFloat(value as string), min, max)
let suffix
if (!Number.isFinite(value)) {
const match = String(value).match(/[A-Z]+/i)
if (match) suffix = match[0]
}
let _value = parseFloat(value as string)
const suffix = typeof value === 'string' ? value.substring(('' + _value).length) : undefined
_value = clamp(_value, min, max)

// ideally:
// 3 -> 3.0
Expand Down

1 comment on commit 61f88f7

@vercel
Copy link

@vercel vercel bot commented on 61f88f7 Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

leva – ./

leva.vercel.app
leva-pmndrs.vercel.app
leva-git-main-pmndrs.vercel.app
leva.pmnd.rs

Please sign in to comment.