Skip to content

Commit

Permalink
fix: x, y, z not accepting relative units (#195)
Browse files Browse the repository at this point in the history
* fix: `x`, `y`, `z` not accepting relative units

* chore: fix lint errors

* refactor: use `getValueAsType` function

* test: add relative unit test
  • Loading branch information
BobbieGoede authored May 30, 2024
1 parent 049e8a0 commit 0abe4d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/reactiveTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export function reactiveTransform(props: TransformProperties = {}, enableHardwar
// Use translate3d by default has a better GPU optimization
// And corrects scaling discrete behaviors
if (enableHardwareAcceleration && (newVal.x || newVal.y || newVal.z)) {
const str = [newVal.x || 0, newVal.y || 0, newVal.z || 0].map(px.transform as any).join(',')
const str = [newVal.x || 0, newVal.y || 0, newVal.z || 0]
.map(val => getValueAsType(val, px))
.join(',')

result += `translate3d(${str}) `

Expand Down
2 changes: 1 addition & 1 deletion src/utils/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const valueTypes: ValueTypeMap = {
export const getValueType = (key: string) => valueTypes[key]

/**
* Transform the value using its value type, or return the value.
* Transform the value using its value type if value is a `number`, otherwise return the value.
*
* @param value
* @param type
Expand Down
11 changes: 11 additions & 0 deletions tests/reactiveTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,15 @@ describe('reactiveTransform', () => {

expect(transform.value).toBe('rotateX(90deg) translateZ(0px)')
})

it('accepts relative units when hardware acceleration is enabled', () => {
const { transform } = reactiveTransform(
{
y: '100%',
},
true,
)

expect(transform.value).toBe('translate3d(0px,100%,0px)')
})
})

0 comments on commit 0abe4d0

Please sign in to comment.