1- import { useState } from 'react' ;
1+ import { useRef , useState } from 'react' ;
22import { Content , Root , Trigger } from '@radix-ui/react-tooltip' ;
33import { CallToAction , cn } from '@theguild/components' ;
44import { BookIcon } from '../book-icon' ;
@@ -16,17 +16,36 @@ export function PricingSlider({
1616 const max = 300 ;
1717
1818 const [ popoverOpen , setPopoverOpen ] = useState ( false ) ;
19+ const rootRef = useRef < HTMLLabelElement > ( null ) ;
1920
2021 return (
2122 < label
23+ ref = { rootRef }
2224 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' ,
2426 className ,
2527 ) }
28+ // 10$ base price + 10$ per 1M
29+ style = { { '--ops' : min , '--price' : 'calc(10 + var(--ops) * 10)' } }
2630 { ...rest }
2731 >
2832 < 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" />
3049 </ div >
3150 < div className = "text-green-1000 flex items-center gap-5 pt-12 text-sm" >
3251 < span className = "font-medium" > { min } M</ span >
@@ -36,12 +55,10 @@ export function PricingSlider({
3655 max = { max }
3756 step = { 1 }
3857 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']"
4259 onChange = { event => {
4360 const value = event . currentTarget . valueAsNumber ;
44- event . currentTarget . parentElement ! . style . setProperty ( '--ops' , `${ value } ` ) ;
61+ rootRef . current ! . style . setProperty ( '--ops' , `${ value } ` ) ;
4562 onChange ( value ) ;
4663 } }
4764 />
0 commit comments