Skip to content

Commit

Permalink
Percentage number values can contain fractions (#78)
Browse files Browse the repository at this point in the history
* Percentages can be floats

* `as const` allows for better types
  • Loading branch information
albinkong authored Jul 31, 2024
1 parent 4b3c559 commit 50888b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ export const CSS_COLOR_NAMES = {
whitesmoke: 0xf5f5f5,
yellowgreen: 0x9acd32,
black: 0x000000,
};
} as const;

export const LOREM_TEXT = `Lorem ipsum dolor, sit amet consectetur adipisicing elit.
export const LOREM_TEXT = `Lorem ipsum dolor, sit amet consectetur adipisicing elit.
Ab praesentium velit minima unde beatae. Illo earum, rem iure unde nemo,
Ab praesentium velit minima unde beatae. Illo earum, rem iure unde nemo,
exercitationem nesciunt et voluptas nisi adipisci, provident cupiditate veritatis magnam?`;

export const DISPLAY = ['block', 'inline-block', 'inline'];
export const DISPLAY = ['block', 'inline-block', 'inline'] as const;

export const OVERFLOW = ['visible', 'hidden'];
export const OVERFLOW = ['visible', 'hidden'] as const;

export const POSITION = [
'center',
Expand Down Expand Up @@ -186,7 +186,7 @@ export const POSITION = [
'bottomCenter',
'leftCenter',
'rightCenter',
];
] as const;

export const ALIGN: TextStyleAlign[] = ['center', 'left', 'right', 'justify'];
export const VERTICAL_ALIGN = ['middle', 'top', 'bottom'];
export const ALIGN: TextStyleAlign[] = ['center', 'left', 'right', 'justify'] as const;
export const VERTICAL_ALIGN = ['middle', 'top', 'bottom'] as const;
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function getNumber(value: FlexNumber, maxPercentValue?: number): number
}
else if (value.endsWith('%'))
{
const val = parseInt(value.slice(0, -1), 10);
const val = parseFloat(value.slice(0, -1));

return Math.floor(maxPercentValue ? (maxPercentValue / 100) * val : val);
}
Expand Down

0 comments on commit 50888b7

Please sign in to comment.