( ref: RefObject<HTMLElement | null>, style?: CSSProperties | ((renderProps: R) => CSSProperties) )
| 34 | * `style` prop. |
| 35 | */ |
| 36 | export function pressScale<R extends {isPressed: boolean}>( |
| 37 | ref: RefObject<HTMLElement | null>, |
| 38 | style?: CSSProperties | ((renderProps: R) => CSSProperties) |
| 39 | ): (renderProps: R) => CSSProperties { |
| 40 | return composeRenderProps(style, (style, renderProps: R) => { |
| 41 | if (renderProps.isPressed && ref.current) { |
| 42 | let {width = 0, height = 0} = ref.current.getBoundingClientRect() ?? {}; |
| 43 | return { |
| 44 | ...style, |
| 45 | willChange: `${style?.willChange ?? ''} transform`, |
| 46 | transform: `${style?.transform ?? ''} perspective(${Math.max(height, width / 3, 24)}px) translate3d(0, 0, -2px)` |
| 47 | }; |
| 48 | } else { |
| 49 | return { |
| 50 | ...style, |
| 51 | willChange: `${style?.willChange ?? ''} transform` |
| 52 | }; |
| 53 | } |
| 54 | }); |
| 55 | } |
no test coverage detected