UNPKG

@elastic/eui

Version:

Elastic UI Component Library

87 lines (80 loc) 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveWidthPropsAsStyle = exports.WARNING_MESSAGE_WIDTH = exports.WARNING_MESSAGE_NOT_RECOMMENDED_UNIT = exports.WARNING_MESSAGE_MIN_WIDTH = exports.WARNING_MESSAGE_MAX_WIDTH = void 0; /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ /** * @internal */ var WARNING_MESSAGE_WIDTH = exports.WARNING_MESSAGE_WIDTH = 'Two `width` properties were provided. Provide only one of `style.width` or `width` to avoid conflicts.'; /** * @internal */ var WARNING_MESSAGE_MIN_WIDTH = exports.WARNING_MESSAGE_MIN_WIDTH = 'Two `minWidth` properties were provided. Provide only one of `style.minWidth` or `minWidth` to avoid conflicts.'; /** * @internal */ var WARNING_MESSAGE_MAX_WIDTH = exports.WARNING_MESSAGE_MAX_WIDTH = 'Two `maxWidth` properties were provided. Provide only one of `style.maxWidth` or `maxWidth` to avoid conflicts.'; /** * @internal */ var WARNING_MESSAGE_NOT_RECOMMENDED_UNIT = exports.WARNING_MESSAGE_NOT_RECOMMENDED_UNIT = 'Detected not recommended unit (%, vw, cqw, cqi) in cell width settings. Adjust the `width`, `minWidth` and `maxWidth` values to use absolute length units like `em` for text cells or `px` for static elements like icons or plots.'; var normalizeValue = function normalizeValue(value) { if (value === undefined || Number.isNaN(value)) { return undefined; } if (typeof value === 'number') { return "".concat(value, "px"); } return value; }; var UNIT_VALIDATOR_REGEX = /%|vw|cqw|cqi/; var shouldWarnAboutNotRecommendedUnit = function shouldWarnAboutNotRecommendedUnit(value) { if (typeof value === 'string') { return UNIT_VALIDATOR_REGEX.test(value); } return false; }; /** * @internal */ var resolveWidthPropsAsStyle = exports.resolveWidthPropsAsStyle = function resolveWidthPropsAsStyle() { var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var _ref = arguments.length > 1 ? arguments[1] : undefined, rawWidth = _ref.width, rawMinWidth = _ref.minWidth, rawMaxWidth = _ref.maxWidth; var widthProp = normalizeValue(rawWidth); var minWidthProp = normalizeValue(rawMinWidth); var maxWidthProp = normalizeValue(rawMaxWidth); var width = widthProp !== null && widthProp !== void 0 ? widthProp : style.width; var minWidth = minWidthProp !== null && minWidthProp !== void 0 ? minWidthProp : style.minWidth; var maxWidth = maxWidthProp !== null && maxWidthProp !== void 0 ? maxWidthProp : style.maxWidth; // Value validation block if (process.env.NODE_ENV !== 'production') { if (style.width && widthProp !== undefined) { console.warn(WARNING_MESSAGE_WIDTH); } if (style.minWidth && minWidthProp !== undefined) { console.warn(WARNING_MESSAGE_MIN_WIDTH); } if (style.maxWidth && maxWidthProp !== undefined) { console.warn(WARNING_MESSAGE_MAX_WIDTH); } if (shouldWarnAboutNotRecommendedUnit(width) || shouldWarnAboutNotRecommendedUnit(minWidth) || shouldWarnAboutNotRecommendedUnit(maxWidth)) { console.warn(WARNING_MESSAGE_NOT_RECOMMENDED_UNIT); } } return { width: width, minWidth: minWidth, maxWidth: maxWidth }; };