-
-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand skeleton height config #1156
Changes from 34 commits
d769fa3
b803eb3
5317db0
67e2941
125f27e
cf8f6c6
48d330a
f5bf2e2
abc534e
aded461
07f2f63
587cb97
1b91d7f
bd2cfd1
95de93d
49fd367
a1a428e
85c0199
71d383d
fa2d634
f3430d5
6b6c64a
8694ab0
92b7449
714ba74
62c5960
b35d094
30870bb
10b02d4
e8b3825
c7fc21c
16d2c6b
9277e66
7527467
8610109
6bc4676
1b3ae81
a041370
fb3ac98
f274bad
84b0bc9
bb02160
3afc977
4f4b2c6
7707017
acc38b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { Control, Controller } from 'react-hook-form'; | ||
import { Button } from './Button'; | ||
import { Typography } from './Typography'; | ||
import { useCallback, useMemo } from 'react'; | ||
import { useLocaleConfig } from '@/i18n/config'; | ||
|
||
export function NumberSelector({ | ||
label, | ||
|
@@ -10,7 +12,9 @@ export function NumberSelector({ | |
min, | ||
max, | ||
step, | ||
doubleStep, | ||
disabled = false, | ||
showButtonWithNumber = false, | ||
}: { | ||
label?: string; | ||
valueLabelFormat?: (value: number) => string; | ||
|
@@ -19,14 +23,36 @@ export function NumberSelector({ | |
min: number; | ||
max: number; | ||
step: number | ((value: number, add: boolean) => number); | ||
doubleStep?: number; | ||
disabled?: boolean; | ||
showButtonWithNumber?: boolean; | ||
}) { | ||
const { currentLocales } = useLocaleConfig(); | ||
|
||
const stepFn = | ||
typeof step === 'function' | ||
? step | ||
: (value: number, add: boolean) => | ||
+(add ? value + step : value - step).toFixed(2); | ||
|
||
const doubleStepFn = useCallback( | ||
(value: number, add: boolean) => | ||
doubleStep === undefined | ||
? 0 | ||
: +(add ? value + doubleStep : value - doubleStep).toFixed(2), | ||
[doubleStep] | ||
); | ||
|
||
const decimalFormat = useMemo( | ||
() => | ||
new Intl.NumberFormat(currentLocales, { | ||
style: 'decimal', | ||
maximumFractionDigits: 2, | ||
signDisplay: 'exceptZero', | ||
}), | ||
[currentLocales] | ||
); | ||
|
||
return ( | ||
<Controller | ||
control={control} | ||
|
@@ -35,7 +61,19 @@ export function NumberSelector({ | |
<div className="flex flex-col gap-1 w-full"> | ||
<Typography bold>{label}</Typography> | ||
<div className="flex gap-5 bg-background-60 p-2 rounded-lg"> | ||
<div className="flex"> | ||
<div className="flex gap-1"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standard gap is usually 2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah but |
||
{doubleStep !== undefined && ( | ||
<Button | ||
variant="tertiary" | ||
rounded | ||
onClick={() => onChange(doubleStepFn(value, false))} | ||
disabled={doubleStepFn(value, false) < min || disabled} | ||
> | ||
{showButtonWithNumber | ||
? decimalFormat.format(-doubleStep) | ||
: '--'} | ||
</Button> | ||
)} | ||
<Button | ||
variant="tertiary" | ||
rounded | ||
|
@@ -48,7 +86,7 @@ export function NumberSelector({ | |
<div className="flex flex-grow justify-center items-center w-10 text-standard"> | ||
{valueLabelFormat ? valueLabelFormat(value) : value} | ||
</div> | ||
<div className="flex"> | ||
<div className="flex gap-1"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standard gap is usually 2 |
||
<Button | ||
variant="tertiary" | ||
rounded | ||
|
@@ -57,6 +95,18 @@ export function NumberSelector({ | |
> | ||
+ | ||
</Button> | ||
{doubleStep !== undefined && ( | ||
<Button | ||
variant="tertiary" | ||
rounded | ||
onClick={() => onChange(doubleStepFn(value, true))} | ||
disabled={doubleStepFn(value, true) > max || disabled} | ||
> | ||
{showButtonWithNumber | ||
? decimalFormat.format(doubleStep) | ||
: '++'} | ||
</Button> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standard gap is usually 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didnt edit this