Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复 CSS 变量的数字会被加上单位的问题 (#1870)
Browse files Browse the repository at this point in the history
fix #1869
  • Loading branch information
yesmeck authored Mar 29, 2022
1 parent 7d2e826 commit 0df4c76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/remax-runtime/src/__tests__/utils/plainStyle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ describe('plainStyle pxToRpx', () => {
style = plainStyle({ width: '100.55555px' });
expect(style.indexOf('100.56rpx') > -1).toBeTruthy();
});

it('does not transform css variable', () => {
const style = plainStyle({ '--column': 1 });
expect(style).toMatchInlineSnapshot(`"--column:1;"`);
});
});
5 changes: 2 additions & 3 deletions packages/remax-runtime/src/utils/plainStyle/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CSSProperties } from 'react';
import { isUnitlessNumber } from './CSSProperty';
import { find, RuntimeOptions } from '@remax/framework-shared';

Expand Down Expand Up @@ -39,12 +38,12 @@ const transformPx = (value: string) => {
});
};

const plainStyle = (style: CSSProperties) => {
const plainStyle = (style: Record<string, string | number>) => {
return Object.keys(style)
.reduce((acc: string[], key) => {
let value = (style as any)[key];

if (!Number.isNaN(Number(value)) && !isUnitlessNumber[key]) {
if (!Number.isNaN(Number(value)) && !isUnitlessNumber[key] && !key?.startsWith('--')) {
value = value + 'rpx';
}

Expand Down

0 comments on commit 0df4c76

Please sign in to comment.