@atlaskit/navigation-system
Version:
The latest navigation system for Atlassian apps.
19 lines • 940 B
JavaScript
/**
* Returns the `fallbackWidth` if the provided `defaultWidthProp` is not an integer value.
*/
export function useSafeDefaultWidth(_ref) {
var defaultWidthProp = _ref.defaultWidthProp,
fallbackDefaultWidth = _ref.fallbackDefaultWidth,
slotName = _ref.slotName;
// If the provided `defaultWidth` is invalid then we use our fallback.
// We are using a runtime check because some invalid numbers like `NaN` are not caught by types,
// and we saw some issues in products where our experience broke due to this.
if (!Number.isInteger(defaultWidthProp)) {
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.error("The defaultWidth value must be an integer, but '".concat(defaultWidthProp, "' was provided to ").concat(slotName, ". Falling back to ").concat(fallbackDefaultWidth, "px instead."));
}
return fallbackDefaultWidth;
}
return defaultWidthProp;
}