feat(Picker): item-height support rem unit (#6462)

This commit is contained in:
neverland
2020-06-05 09:25:19 +08:00
committed by GitHub
parent 76c9e7ef1e
commit 2f2760aba6
12 changed files with 126 additions and 36 deletions
+21
View File
@@ -9,3 +9,24 @@ export function addUnit(value?: string | number): string | undefined {
value = String(value);
return isNumeric(value) ? `${value}px` : value;
}
function convertRem(value: string) {
const rootStyle = window.getComputedStyle(document.documentElement);
const rootFontSize = parseFloat(rootStyle.fontSize);
value = value.replace(/rem/g, '');
return +value * rootFontSize;
}
export function unitToPx(value: string | number): number {
if (typeof value === 'number') {
return value;
}
if (value.indexOf('rem') !== -1) {
return convertRem(value);
}
return parseFloat(value);
}