MCPcopy Create free account
hub / github.com/adobe/react-spectrum / parseFractionalUnit

Function parseFractionalUnit

packages/react-stately/src/table/TableUtils.ts:21–37  ·  view source on GitHub ↗
(width?: ColumnSize | null)

Source from the content-addressed store, hash-verified

19}
20
21export function parseFractionalUnit(width?: ColumnSize | null): number {
22 if (!width || typeof width === 'number') {
23 return 1;
24 }
25 let match = width.match(/^(.+)(?=fr$)/);
26 // if width is the incorrect format, just default it to a 1fr
27 if (!match) {
28 if (process.env.NODE_ENV !== 'production') {
29 console.warn(
30 `width: ${width} is not a supported format, width should be a number (ex. 150), percentage (ex. '50%') or fr unit (ex. '2fr')`,
31 "defaulting to '1fr'"
32 );
33 }
34 return 1;
35 }
36 return parseFloat(match[0]);
37}
38
39export function parseStaticWidth(width: number | string, tableWidth: number): number {
40 if (typeof width === 'string') {

Callers 1

calculateColumnSizesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected