1
- import { useState } from 'react' ;
1
+ import { useRef , useState } from 'react' ;
2
2
import { Content , Root , Trigger } from '@radix-ui/react-tooltip' ;
3
3
import { CallToAction , cn } from '@theguild/components' ;
4
4
import { BookIcon } from '../book-icon' ;
@@ -16,17 +16,36 @@ export function PricingSlider({
16
16
const max = 300 ;
17
17
18
18
const [ popoverOpen , setPopoverOpen ] = useState ( false ) ;
19
+ const rootRef = useRef < HTMLLabelElement > ( null ) ;
19
20
20
21
return (
21
22
< label
23
+ ref = { rootRef }
22
24
className = { cn (
23
- 'relative isolate block rounded-3xl border border-green-400 p-4 sm:p-8' ,
25
+ 'relative isolate block select-none rounded-3xl border border-green-400 p-4 [counter-set:ops_calc(var(--ops))_price_calc(var(--price))] sm:p-8' ,
24
26
className ,
25
27
) }
28
+ // 10$ base price + 10$ per 1M
29
+ style = { { '--ops' : min , '--price' : 'calc(10 + var(--ops) * 10)' } }
26
30
{ ...rest }
27
31
>
28
32
< div className = "text-green-1000 items-center text-2xl font-medium md:flex md:h-12 md:w-[calc(100%-260px)]" >
29
- How many operations per month do you need?
33
+ < div className = "relative max-w-[clamp(calc(60.95px+14.47px*round(down,log(max(var(--ops),1),10),1)),(2-var(--ops))*111px,111px)] shrink grow motion-safe:transition-all" >
34
+ < div
35
+ aria-hidden
36
+ className = "flex w-full whitespace-pre rounded-[40px] bg-blue-300 px-3 py-1 tabular-nums leading-8 opacity-[calc(var(--ops)-1)] [transition-duration:calc(clamp(0,var(--ops)-1,1)*350ms)] before:tracking-[-0.12em] before:content-[''_counter(ops)_'_'] motion-safe:transition-all"
37
+ >
38
+ M
39
+ </ div >
40
+ < div className = "absolute left-0 top-0 whitespace-pre leading-10 opacity-[calc(2-var(--ops))] [transition-duration:calc(clamp(0,2-var(--ops),1)*350ms)] motion-safe:transition" >
41
+ How many
42
+ </ div >
43
+ </ div >
44
+ < div className = "whitespace-pre" > operations per month </ div >
45
+ < div className = "whitespace-pre opacity-[calc(2-var(--ops))] [transition-duration:350ms] motion-safe:transition" >
46
+ do you need?
47
+ </ div >
48
+ < div className = "grow-[1.5] ease-in motion-safe:transition-all" />
30
49
</ div >
31
50
< div className = "text-green-1000 flex items-center gap-5 pt-12 text-sm" >
32
51
< span className = "font-medium" > { min } M</ span >
@@ -36,12 +55,10 @@ export function PricingSlider({
36
55
max = { max }
37
56
step = { 1 }
38
57
defaultValue = { min }
39
- // 10$ base price + 10$ per 1M
40
- style = { { '--ops' : min , '--price' : 'calc(10 + var(--ops) * 10)' } }
41
- counter = "after:content-[''_counter(ops)_'M_ops,_$'_counter(price)_'_/_month'] after:[counter-set:ops_calc(var(--ops))_price_calc(var(--price))]"
58
+ counter = "after:content-['$'_counter(price)_'_/_month']"
42
59
onChange = { event => {
43
60
const value = event . currentTarget . valueAsNumber ;
44
- event . currentTarget . parentElement ! . style . setProperty ( '--ops' , `${ value } ` ) ;
61
+ rootRef . current ! . style . setProperty ( '--ops' , `${ value } ` ) ;
45
62
onChange ( value ) ;
46
63
} }
47
64
/>
0 commit comments