UNPKG

@material-ui/core

Version:

React components that implement Google's Material Design.

1,592 lines (1,415 loc) 1.06 MB
/** @license Material-UI v3.2.0 * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) : typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) : (factory((global['material-ui'] = {}),global.React,global.ReactDOM)); }(this, (function (exports,React,ReactDOM) { 'use strict'; React = React && React.hasOwnProperty('default') ? React['default'] : React; ReactDOM = ReactDOM && ReactDOM.hasOwnProperty('default') ? ReactDOM['default'] : ReactDOM; var common = { black: '#000', white: '#fff' }; var red = { 50: '#ffebee', 100: '#ffcdd2', 200: '#ef9a9a', 300: '#e57373', 400: '#ef5350', 500: '#f44336', 600: '#e53935', 700: '#d32f2f', 800: '#c62828', 900: '#b71c1c', A100: '#ff8a80', A200: '#ff5252', A400: '#ff1744', A700: '#d50000' }; var pink = { 50: '#fce4ec', 100: '#f8bbd0', 200: '#f48fb1', 300: '#f06292', 400: '#ec407a', 500: '#e91e63', 600: '#d81b60', 700: '#c2185b', 800: '#ad1457', 900: '#880e4f', A100: '#ff80ab', A200: '#ff4081', A400: '#f50057', A700: '#c51162' }; var purple = { 50: '#f3e5f5', 100: '#e1bee7', 200: '#ce93d8', 300: '#ba68c8', 400: '#ab47bc', 500: '#9c27b0', 600: '#8e24aa', 700: '#7b1fa2', 800: '#6a1b9a', 900: '#4a148c', A100: '#ea80fc', A200: '#e040fb', A400: '#d500f9', A700: '#aa00ff' }; var deepPurple = { 50: '#ede7f6', 100: '#d1c4e9', 200: '#b39ddb', 300: '#9575cd', 400: '#7e57c2', 500: '#673ab7', 600: '#5e35b1', 700: '#512da8', 800: '#4527a0', 900: '#311b92', A100: '#b388ff', A200: '#7c4dff', A400: '#651fff', A700: '#6200ea' }; var indigo = { 50: '#e8eaf6', 100: '#c5cae9', 200: '#9fa8da', 300: '#7986cb', 400: '#5c6bc0', 500: '#3f51b5', 600: '#3949ab', 700: '#303f9f', 800: '#283593', 900: '#1a237e', A100: '#8c9eff', A200: '#536dfe', A400: '#3d5afe', A700: '#304ffe' }; var blue = { 50: '#e3f2fd', 100: '#bbdefb', 200: '#90caf9', 300: '#64b5f6', 400: '#42a5f5', 500: '#2196f3', 600: '#1e88e5', 700: '#1976d2', 800: '#1565c0', 900: '#0d47a1', A100: '#82b1ff', A200: '#448aff', A400: '#2979ff', A700: '#2962ff' }; var lightBlue = { 50: '#e1f5fe', 100: '#b3e5fc', 200: '#81d4fa', 300: '#4fc3f7', 400: '#29b6f6', 500: '#03a9f4', 600: '#039be5', 700: '#0288d1', 800: '#0277bd', 900: '#01579b', A100: '#80d8ff', A200: '#40c4ff', A400: '#00b0ff', A700: '#0091ea' }; var cyan = { 50: '#e0f7fa', 100: '#b2ebf2', 200: '#80deea', 300: '#4dd0e1', 400: '#26c6da', 500: '#00bcd4', 600: '#00acc1', 700: '#0097a7', 800: '#00838f', 900: '#006064', A100: '#84ffff', A200: '#18ffff', A400: '#00e5ff', A700: '#00b8d4' }; var teal = { 50: '#e0f2f1', 100: '#b2dfdb', 200: '#80cbc4', 300: '#4db6ac', 400: '#26a69a', 500: '#009688', 600: '#00897b', 700: '#00796b', 800: '#00695c', 900: '#004d40', A100: '#a7ffeb', A200: '#64ffda', A400: '#1de9b6', A700: '#00bfa5' }; var green = { 50: '#e8f5e9', 100: '#c8e6c9', 200: '#a5d6a7', 300: '#81c784', 400: '#66bb6a', 500: '#4caf50', 600: '#43a047', 700: '#388e3c', 800: '#2e7d32', 900: '#1b5e20', A100: '#b9f6ca', A200: '#69f0ae', A400: '#00e676', A700: '#00c853' }; var lightGreen = { 50: '#f1f8e9', 100: '#dcedc8', 200: '#c5e1a5', 300: '#aed581', 400: '#9ccc65', 500: '#8bc34a', 600: '#7cb342', 700: '#689f38', 800: '#558b2f', 900: '#33691e', A100: '#ccff90', A200: '#b2ff59', A400: '#76ff03', A700: '#64dd17' }; var lime = { 50: '#f9fbe7', 100: '#f0f4c3', 200: '#e6ee9c', 300: '#dce775', 400: '#d4e157', 500: '#cddc39', 600: '#c0ca33', 700: '#afb42b', 800: '#9e9d24', 900: '#827717', A100: '#f4ff81', A200: '#eeff41', A400: '#c6ff00', A700: '#aeea00' }; var yellow = { 50: '#fffde7', 100: '#fff9c4', 200: '#fff59d', 300: '#fff176', 400: '#ffee58', 500: '#ffeb3b', 600: '#fdd835', 700: '#fbc02d', 800: '#f9a825', 900: '#f57f17', A100: '#ffff8d', A200: '#ffff00', A400: '#ffea00', A700: '#ffd600' }; var amber = { 50: '#fff8e1', 100: '#ffecb3', 200: '#ffe082', 300: '#ffd54f', 400: '#ffca28', 500: '#ffc107', 600: '#ffb300', 700: '#ffa000', 800: '#ff8f00', 900: '#ff6f00', A100: '#ffe57f', A200: '#ffd740', A400: '#ffc400', A700: '#ffab00' }; var orange = { 50: '#fff3e0', 100: '#ffe0b2', 200: '#ffcc80', 300: '#ffb74d', 400: '#ffa726', 500: '#ff9800', 600: '#fb8c00', 700: '#f57c00', 800: '#ef6c00', 900: '#e65100', A100: '#ffd180', A200: '#ffab40', A400: '#ff9100', A700: '#ff6d00' }; var deepOrange = { 50: '#fbe9e7', 100: '#ffccbc', 200: '#ffab91', 300: '#ff8a65', 400: '#ff7043', 500: '#ff5722', 600: '#f4511e', 700: '#e64a19', 800: '#d84315', 900: '#bf360c', A100: '#ff9e80', A200: '#ff6e40', A400: '#ff3d00', A700: '#dd2c00' }; var brown = { 50: '#efebe9', 100: '#d7ccc8', 200: '#bcaaa4', 300: '#a1887f', 400: '#8d6e63', 500: '#795548', 600: '#6d4c41', 700: '#5d4037', 800: '#4e342e', 900: '#3e2723', A100: '#d7ccc8', A200: '#bcaaa4', A400: '#8d6e63', A700: '#5d4037' }; var grey = { 50: '#fafafa', 100: '#f5f5f5', 200: '#eeeeee', 300: '#e0e0e0', 400: '#bdbdbd', 500: '#9e9e9e', 600: '#757575', 700: '#616161', 800: '#424242', 900: '#212121', A100: '#d5d5d5', A200: '#aaaaaa', A400: '#303030', A700: '#616161' }; var blueGrey = { 50: '#eceff1', 100: '#cfd8dc', 200: '#b0bec5', 300: '#90a4ae', 400: '#78909c', 500: '#607d8b', 600: '#546e7a', 700: '#455a64', 800: '#37474f', 900: '#263238', A100: '#cfd8dc', A200: '#b0bec5', A400: '#78909c', A700: '#455a64' }; var index = /*#__PURE__*/Object.freeze({ common: common, red: red, pink: pink, purple: purple, deepPurple: deepPurple, indigo: indigo, blue: blue, lightBlue: lightBlue, cyan: cyan, teal: teal, green: green, lightGreen: lightGreen, lime: lime, yellow: yellow, amber: amber, orange: orange, deepOrange: deepOrange, brown: brown, grey: grey, blueGrey: blueGrey }); var global$1 = (typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); // shim for using process in browser // based off https://github.com/defunctzombie/node-process/blob/master/browser.js function defaultSetTimout() { throw new Error('setTimeout has not been defined'); } function defaultClearTimeout () { throw new Error('clearTimeout has not been defined'); } var cachedSetTimeout = defaultSetTimout; var cachedClearTimeout = defaultClearTimeout; if (typeof global$1.setTimeout === 'function') { cachedSetTimeout = setTimeout; } if (typeof global$1.clearTimeout === 'function') { cachedClearTimeout = clearTimeout; } function runTimeout(fun) { if (cachedSetTimeout === setTimeout) { //normal enviroments in sane situations return setTimeout(fun, 0); } // if setTimeout wasn't available but was latter defined if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { cachedSetTimeout = setTimeout; return setTimeout(fun, 0); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); } catch(e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedSetTimeout.call(null, fun, 0); } catch(e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error return cachedSetTimeout.call(this, fun, 0); } } } function runClearTimeout(marker) { if (cachedClearTimeout === clearTimeout) { //normal enviroments in sane situations return clearTimeout(marker); } // if clearTimeout wasn't available but was latter defined if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { cachedClearTimeout = clearTimeout; return clearTimeout(marker); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); } catch (e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedClearTimeout.call(null, marker); } catch (e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. // Some versions of I.E. have different rules for clearTimeout vs setTimeout return cachedClearTimeout.call(this, marker); } } } var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { if (!draining || !currentQueue) { return; } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); } else { queueIndex = -1; } if (queue.length) { drainQueue(); } } function drainQueue() { if (draining) { return; } var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; runClearTimeout(timeout); } function nextTick(fun) { var args = new Array(arguments.length - 1); if (arguments.length > 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } } // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; var title = 'browser'; var platform = 'browser'; var browser = true; var env = {}; var argv = []; var version = ''; // empty string to avoid regexp issues var versions = {}; var release = {}; var config = {}; function noop() {} var on = noop; var addListener = noop; var once = noop; var off = noop; var removeListener = noop; var removeAllListeners = noop; var emit = noop; function binding(name) { throw new Error('process.binding is not supported'); } function cwd () { return '/' } function chdir (dir) { throw new Error('process.chdir is not supported'); }function umask() { return 0; } // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js var performance$1 = global$1.performance || {}; var performanceNow = performance$1.now || performance$1.mozNow || performance$1.msNow || performance$1.oNow || performance$1.webkitNow || function(){ return (new Date()).getTime() }; // generate timestamp or delta // see http://nodejs.org/api/process.html#process_process_hrtime function hrtime(previousTimestamp){ var clocktime = performanceNow.call(performance$1)*1e-3; var seconds = Math.floor(clocktime); var nanoseconds = Math.floor((clocktime%1)*1e9); if (previousTimestamp) { seconds = seconds - previousTimestamp[0]; nanoseconds = nanoseconds - previousTimestamp[1]; if (nanoseconds<0) { seconds--; nanoseconds += 1e9; } } return [seconds,nanoseconds] } var startTime = new Date(); function uptime() { var currentTime = new Date(); var dif = currentTime - startTime; return dif / 1000; } var process = { nextTick: nextTick, title: title, browser: browser, env: env, argv: argv, version: version, versions: versions, on: on, addListener: addListener, once: once, off: off, removeListener: removeListener, removeAllListeners: removeAllListeners, emit: emit, binding: binding, cwd: cwd, chdir: chdir, umask: umask, hrtime: hrtime, platform: platform, release: release, config: config, uptime: uptime }; var warning = function() {}; { var printWarning = function printWarning(format, args) { var len = arguments.length; args = new Array(len > 2 ? len - 2 : 0); for (var key = 2; key < len; key++) { args[key - 2] = arguments[key]; } var argIndex = 0; var message = 'Warning: ' + format.replace(/%s/g, function() { return args[argIndex++]; }); if (typeof console !== 'undefined') { console.error(message); } try { // --- Welcome to debugging React --- // This error was thrown as a convenience so that you can use this stack // to find the callsite that caused this warning to fire. throw new Error(message); } catch (x) {} }; warning = function(condition, format, args) { var len = arguments.length; args = new Array(len > 2 ? len - 2 : 0); for (var key = 2; key < len; key++) { args[key - 2] = arguments[key]; } if (format === undefined) { throw new Error( '`warning(condition, format, ...args)` requires a warning ' + 'message argument' ); } if (!condition) { printWarning.apply(null, [format].concat(args)); } }; } var warning_1 = warning; var escapeRegex = /([[\].#*$><+~=|^:(),"'`\s])/g; function safePrefix(classNamePrefix) { var prefix = String(classNamePrefix); warning_1(prefix.length < 256, "Material-UI: the class name prefix is too long: ".concat(prefix, ".")); // Sanitize the string as will be used to prefix the generated class name. return prefix.replace(escapeRegex, '-'); } // Returns a function which generates unique class names based on counters. // When new generator function is created, rule counter is reset. // We need to reset the rule counter for SSR for each request. // // It's inspired by // https://github.com/cssinjs/jss/blob/4e6a05dd3f7b6572fdd3ab216861d9e446c20331/src/utils/createGenerateClassName.js function createGenerateClassName() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var _options$dangerouslyU = options.dangerouslyUseGlobalCSS, dangerouslyUseGlobalCSS = _options$dangerouslyU === void 0 ? false : _options$dangerouslyU, _options$productionPr = options.productionPrefix, _options$seed = options.seed, seed = _options$seed === void 0 ? '' : _options$seed; var ruleCounter = 0; return function (rule, styleSheet) { ruleCounter += 1; warning_1(ruleCounter < 1e10, ['Material-UI: you might have a memory leak.', 'The ruleCounter is not supposed to grow that much.'].join('')); // Code branch the whole block at the expense of more code. if (dangerouslyUseGlobalCSS) { if (styleSheet) { if (styleSheet.options.name) { return "".concat(styleSheet.options.name, "-").concat(rule.key); } if (styleSheet.options.classNamePrefix && "development" !== 'production') { var prefix = safePrefix(styleSheet.options.classNamePrefix); return "".concat(prefix, "-").concat(rule.key, "-").concat(seed).concat(ruleCounter); } } return "".concat(rule.key, "-").concat(seed).concat(ruleCounter); } if (styleSheet && styleSheet.options.classNamePrefix) { var _prefix = safePrefix(styleSheet.options.classNamePrefix); return "".concat(_prefix, "-").concat(rule.key, "-").concat(seed).concat(ruleCounter); } return "".concat(rule.key, "-").concat(seed).concat(ruleCounter); }; } function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var _extends_1 = createCommonjsModule(function (module) { function _extends() { module.exports = _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } module.exports = _extends; }); function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var objectWithoutPropertiesLoose = _objectWithoutPropertiesLoose; function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } var objectWithoutProperties = _objectWithoutProperties; var isMergeableObject = function isMergeableObject(value) { return isNonNullObject(value) && !isSpecial(value) }; function isNonNullObject(value) { return !!value && typeof value === 'object' } function isSpecial(value) { var stringValue = Object.prototype.toString.call(value); return stringValue === '[object RegExp]' || stringValue === '[object Date]' || isReactElement(value) } // see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25 var canUseSymbol = typeof Symbol === 'function' && Symbol.for; var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7; function isReactElement(value) { return value.$$typeof === REACT_ELEMENT_TYPE } function emptyTarget(val) { return Array.isArray(val) ? [] : {} } function cloneUnlessOtherwiseSpecified(value, options) { return (options.clone !== false && options.isMergeableObject(value)) ? deepmerge(emptyTarget(value), value, options) : value } function defaultArrayMerge(target, source, options) { return target.concat(source).map(function(element) { return cloneUnlessOtherwiseSpecified(element, options) }) } function mergeObject(target, source, options) { var destination = {}; if (options.isMergeableObject(target)) { Object.keys(target).forEach(function(key) { destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); }); } Object.keys(source).forEach(function(key) { if (!options.isMergeableObject(source[key]) || !target[key]) { destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); } else { destination[key] = deepmerge(target[key], source[key], options); } }); return destination } function deepmerge(target, source, options) { options = options || {}; options.arrayMerge = options.arrayMerge || defaultArrayMerge; options.isMergeableObject = options.isMergeableObject || isMergeableObject; var sourceIsArray = Array.isArray(source); var targetIsArray = Array.isArray(target); var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; if (!sourceAndTargetTypesMatch) { return cloneUnlessOtherwiseSpecified(source, options) } else if (sourceIsArray) { return options.arrayMerge(target, source, options) } else { return mergeObject(target, source, options) } } deepmerge.all = function deepmergeAll(array, options) { if (!Array.isArray(array)) { throw new Error('first argument should be an array') } return array.reduce(function(prev, next) { return deepmerge(prev, next, options) }, {}) }; var deepmerge_1 = deepmerge; /*! * isobject <https://github.com/jonschlinkert/isobject> * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ var isobject = function isObject(val) { return val != null && typeof val === 'object' && Array.isArray(val) === false; }; function isObjectObject(o) { return isobject(o) === true && Object.prototype.toString.call(o) === '[object Object]'; } var isPlainObject = function isPlainObject(o) { var ctor,prot; if (isObjectObject(o) === false) return false; // If has modified constructor ctor = o.constructor; if (typeof ctor !== 'function') return false; // If has modified prototype prot = ctor.prototype; if (isObjectObject(prot) === false) return false; // If constructor does not have an Object-specific method if (prot.hasOwnProperty('isPrototypeOf') === false) { return false; } // Most likely a plain Object return true; }; // Sorted ASC by size. That's important. // It can't be configured as it's used statically for propTypes. var keys = ['xs', 'sm', 'md', 'lg', 'xl']; // Keep in mind that @media is inclusive by the CSS specification. function createBreakpoints(breakpoints) { var _breakpoints$values = breakpoints.values, values = _breakpoints$values === void 0 ? { xs: 0, sm: 600, md: 960, lg: 1280, xl: 1920 } : _breakpoints$values, _breakpoints$unit = breakpoints.unit, unit = _breakpoints$unit === void 0 ? 'px' : _breakpoints$unit, _breakpoints$step = breakpoints.step, step = _breakpoints$step === void 0 ? 5 : _breakpoints$step, other = objectWithoutProperties(breakpoints, ["values", "unit", "step"]); function up(key) { var value = typeof values[key] === 'number' ? values[key] : key; return "@media (min-width:".concat(value).concat(unit, ")"); } function down(key) { var endIndex = keys.indexOf(key) + 1; var upperbound = values[keys[endIndex]]; if (endIndex === keys.length) { // xl down applies to all sizes return up('xs'); } var value = typeof upperbound === 'number' && endIndex > 0 ? upperbound : key; return "@media (max-width:".concat(value - step / 100).concat(unit, ")"); } function between(start, end) { var endIndex = keys.indexOf(end) + 1; if (endIndex === keys.length) { return up(start); } return "@media (min-width:".concat(values[start]).concat(unit, ") and ") + "(max-width:".concat(values[keys[endIndex]] - step / 100).concat(unit, ")"); } function only(key) { return between(key, key); } function width(key) { return values[key]; } return _extends_1({ keys: keys, values: values, up: up, down: down, between: between, only: only, width: width }, other); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var defineProperty = _defineProperty; function createMixins(breakpoints, spacing, mixins) { var _toolbar; return _extends_1({ gutters: function gutters() { var styles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return _extends_1({ paddingLeft: spacing.unit * 2, paddingRight: spacing.unit * 2 }, styles, defineProperty({}, breakpoints.up('sm'), _extends_1({ paddingLeft: spacing.unit * 3, paddingRight: spacing.unit * 3 }, styles[breakpoints.up('sm')]))); }, toolbar: (_toolbar = { minHeight: 56 }, defineProperty(_toolbar, "".concat(breakpoints.up('xs'), " and (orientation: landscape)"), { minHeight: 48 }), defineProperty(_toolbar, breakpoints.up('sm'), { minHeight: 64 }), _toolbar) }, mixins); } /** * Returns a number whose value is limited to the given range. * * @param {number} value The value to be clamped * @param {number} min The lower boundary of the output range * @param {number} max The upper boundary of the output range * @returns {number} A number in the range [min, max] */ function clamp(value) { var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; warning_1(value >= min && value <= max, "Material-UI: the value provided ".concat(value, " is out of range [").concat(min, ", ").concat(max, "].")); if (value < min) { return min; } if (value > max) { return max; } return value; } /** * Converts a color from CSS hex format to CSS rgb format. * * @param {string} color - Hex color, i.e. #nnn or #nnnnnn * @returns {string} A CSS rgb color string */ function convertHexToRGB(color) { color = color.substr(1); var re = new RegExp(".{1,".concat(color.length / 3, "}"), 'g'); var colors = color.match(re); if (colors && colors[0].length === 1) { colors = colors.map(function (n) { return n + n; }); } return colors ? "rgb(".concat(colors.map(function (n) { return parseInt(n, 16); }).join(', '), ")") : ''; } /** * Returns an object with the type and values of a color. * * Note: Does not support rgb % values. * * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla() * @returns {object} - A MUI color object: {type: string, values: number[]} */ function decomposeColor(color) { if (color.charAt(0) === '#') { return decomposeColor(convertHexToRGB(color)); } var marker = color.indexOf('('); var type = color.substring(0, marker); var values = color.substring(marker + 1, color.length - 1).split(','); values = values.map(function (value) { return parseFloat(value); }); { if (['rgb', 'rgba', 'hsl', 'hsla'].indexOf(type) === -1) { throw new Error(["Material-UI: unsupported `".concat(color, "` color."), 'We support the following formats: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla().'].join('\n')); } } return { type: type, values: values }; } /** * Converts a color object with type and values to a string. * * @param {object} color - Decomposed color * @param {string} color.type - One of: 'rgb', 'rgba', 'hsl', 'hsla' * @param {array} color.values - [n,n,n] or [n,n,n,n] * @returns {string} A CSS color string */ function recomposeColor(color) { var type = color.type; var values = color.values; if (type.indexOf('rgb') !== -1) { // Only convert the first 3 values to int (i.e. not alpha) values = values.map(function (n, i) { return i < 3 ? parseInt(n, 10) : n; }); } if (type.indexOf('hsl') !== -1) { values[1] = "".concat(values[1], "%"); values[2] = "".concat(values[2], "%"); } return "".concat(color.type, "(").concat(values.join(', '), ")"); } /** * Calculates the contrast ratio between two colors. * * Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests * * @param {string} foreground - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla() * @param {string} background - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla() * @returns {number} A contrast ratio value in the range 0 - 21. */ function getContrastRatio(foreground, background) { var lumA = getLuminance(foreground); var lumB = getLuminance(background); return (Math.max(lumA, lumB) + 0.05) / (Math.min(lumA, lumB) + 0.05); } /** * The relative brightness of any point in a color space, * normalized to 0 for darkest black and 1 for lightest white. * * Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests * * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla() * @returns {number} The relative brightness of the color in the range 0 - 1 */ function getLuminance(color) { var decomposedColor = decomposeColor(color); if (decomposedColor.type.indexOf('rgb') !== -1) { var rgb = decomposedColor.values.map(function (val) { val /= 255; // normalized return val <= 0.03928 ? val / 12.92 : Math.pow((val + 0.055) / 1.055, 2.4); }); // Truncate at 3 digits return Number((0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]).toFixed(3)); } // else if (decomposedColor.type.indexOf('hsl') !== -1) return decomposedColor.values[2] / 100; } /** * Darken or lighten a colour, depending on its luminance. * Light colors are darkened, dark colors are lightened. * * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla() * @param {number} coefficient=0.15 - multiplier in the range 0 - 1 * @returns {string} A CSS color string. Hex input values are returned as rgb */ function emphasize(color) { var coefficient = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.15; return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient); } /** * Set the absolute transparency of a color. * Any existing alpha values are overwritten. * * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla() * @param {number} value - value to set the alpha channel to in the range 0 -1 * @returns {string} A CSS color string. Hex input values are returned as rgb */ function fade(color, value) { warning_1(color, "Material-UI: missing color argument in fade(".concat(color, ", ").concat(value, ").")); if (!color) return color; color = decomposeColor(color); value = clamp(value); if (color.type === 'rgb' || color.type === 'hsl') { color.type += 'a'; } color.values[3] = value; return recomposeColor(color); } /** * Darkens a color. * * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla() * @param {number} coefficient - multiplier in the range 0 - 1 * @returns {string} A CSS color string. Hex input values are returned as rgb */ function darken(color, coefficient) { warning_1(color, "Material-UI: missing color argument in darken(".concat(color, ", ").concat(coefficient, ").")); if (!color) return color; color = decomposeColor(color); coefficient = clamp(coefficient); if (color.type.indexOf('hsl') !== -1) { color.values[2] *= 1 - coefficient; } else if (color.type.indexOf('rgb') !== -1) { for (var i = 0; i < 3; i += 1) { color.values[i] *= 1 - coefficient; } } return recomposeColor(color); } /** * Lightens a color. * * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla() * @param {number} coefficient - multiplier in the range 0 - 1 * @returns {string} A CSS color string. Hex input values are returned as rgb */ function lighten(color, coefficient) { warning_1(color, "Material-UI: missing color argument in lighten(".concat(color, ", ").concat(coefficient, ").")); if (!color) return color; color = decomposeColor(color); coefficient = clamp(coefficient); if (color.type.indexOf('hsl') !== -1) { color.values[2] += (100 - color.values[2]) * coefficient; } else if (color.type.indexOf('rgb') !== -1) { for (var i = 0; i < 3; i += 1) { color.values[i] += (255 - color.values[i]) * coefficient; } } return recomposeColor(color); } var light = { // The colors used to style the text. text: { // The most important text. primary: 'rgba(0, 0, 0, 0.87)', // Secondary text. secondary: 'rgba(0, 0, 0, 0.54)', // Disabled text have even lower visual prominence. disabled: 'rgba(0, 0, 0, 0.38)', // Text hints. hint: 'rgba(0, 0, 0, 0.38)' }, // The color used to divide different elements. divider: 'rgba(0, 0, 0, 0.12)', // The background colors used to style the surfaces. // Consistency between these values is important. background: { paper: common.white, default: grey[50] }, // The colors used to style the action elements. action: { // The color of an active action like an icon button. active: 'rgba(0, 0, 0, 0.54)', // The color of an hovered action. hover: 'rgba(0, 0, 0, 0.08)', hoverOpacity: 0.08, // The color of a selected action. selected: 'rgba(0, 0, 0, 0.14)', // The color of a disabled action. disabled: 'rgba(0, 0, 0, 0.26)', // The background color of a disabled action. disabledBackground: 'rgba(0, 0, 0, 0.12)' } }; var dark = { text: { primary: common.white, secondary: 'rgba(255, 255, 255, 0.7)', disabled: 'rgba(255, 255, 255, 0.5)', hint: 'rgba(255, 255, 255, 0.5)', icon: 'rgba(255, 255, 255, 0.5)' }, divider: 'rgba(255, 255, 255, 0.12)', background: { paper: grey[800], default: '#303030' }, action: { active: common.white, hover: 'rgba(255, 255, 255, 0.1)', hoverOpacity: 0.1, selected: 'rgba(255, 255, 255, 0.2)', disabled: 'rgba(255, 255, 255, 0.3)', disabledBackground: 'rgba(255, 255, 255, 0.12)' } }; function addLightOrDark(intent, direction, shade, tonalOffset) { if (!intent[direction]) { if (intent.hasOwnProperty(shade)) { intent[direction] = intent[shade]; } else if (direction === 'light') { intent.light = lighten(intent.main, tonalOffset); } else if (direction === 'dark') { intent.dark = darken(intent.main, tonalOffset * 1.5); } } } function createPalette(palette) { var _palette$primary = palette.primary, primary = _palette$primary === void 0 ? { light: indigo[300], main: indigo[500], dark: indigo[700] } : _palette$primary, _palette$secondary = palette.secondary, secondary = _palette$secondary === void 0 ? { light: pink.A200, main: pink.A400, dark: pink.A700 } : _palette$secondary, _palette$error = palette.error, error = _palette$error === void 0 ? { light: red[300], main: red[500], dark: red[700] } : _palette$error, _palette$type = palette.type, type = _palette$type === void 0 ? 'light' : _palette$type, _palette$contrastThre = palette.contrastThreshold, contrastThreshold = _palette$contrastThre === void 0 ? 3 : _palette$contrastThre, _palette$tonalOffset = palette.tonalOffset, tonalOffset = _palette$tonalOffset === void 0 ? 0.2 : _palette$tonalOffset, other = objectWithoutProperties(palette, ["primary", "secondary", "error", "type", "contrastThreshold", "tonalOffset"]); function getContrastText(background) { // Use the same logic as // Bootstrap: https://github.com/twbs/bootstrap/blob/1d6e3710dd447de1a200f29e8fa521f8a0908f70/scss/_functions.scss#L59 // and material-components-web https://github.com/material-components/material-components-web/blob/ac46b8863c4dab9fc22c4c662dc6bd1b65dd652f/packages/mdc-theme/_functions.scss#L54 var contrastText = getContrastRatio(background, dark.text.primary) >= contrastThreshold ? dark.text.primary : light.text.primary; { var contrast = getContrastRatio(background, contrastText); warning_1(contrast >= 3, ["Material-UI: the contrast ratio of ".concat(contrast, ":1 for ").concat(contrastText, " on ").concat(background), 'falls below the WACG recommended absolute minimum contrast ratio of 3:1.', 'https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast'].join('\n')); } return contrastText; } function augmentColor(color) { var mainShade = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500; var lightShade = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 300; var darkShade = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 700; if (!color.main && color[mainShade]) { color.main = color[mainShade]; } if (!color.main) { throw new Error(['Material-UI: the color provided to augmentColor(color) is invalid.', "The color object needs to have a `main` property or a `".concat(mainShade, "` property.")].join('\n')); } addLightOrDark(color, 'light', lightShade, tonalOffset); addLightOrDark(color, 'dark', darkShade, tonalOffset); if (!color.contrastText) { color.contrastText = getContrastText(color.main); } } augmentColor(primary); augmentColor(secondary, 'A400', 'A200', 'A700'); augmentColor(error); var types = { dark: dark, light: light }; warning_1(types[type], "Material-UI: the palette type `".concat(type, "` is not supported.")); var paletteOutput = deepmerge_1(_extends_1({ // A collection of common colors. common: common, // The palette type, can be light or dark. type: type, // The colors used to represent primary interface elements for a user. primary: primary, // The colors used to represent secondary interface elements for a user. secondary: secondary, // The colors used to represent interface elements that the user should be made aware of. error: error, // The grey colors. grey: grey, // Used by `getContrastText()` to maximize the contrast between the background and // the text. contrastThreshold: contrastThreshold, // Take a background color and return the color of the text to maximize the contrast. getContrastText: getContrastText, // Generate a rich color object. augmentColor: augmentColor, // Used by the functions below to shift a color's luminance by approximately // two indexes within its tonal palette. // E.g., shift from Red 500 to Red 300 or Red 700. tonalOffset: tonalOffset }, types[type]), other, { clone: false // No need to clone deep }); return paletteOutput; } var typographyMigration = { // these variants will be removed in the next major deprecatedVariants: ['display4', 'display3', 'display2', 'display1', 'headline', 'title', 'subheading'], // these variants will change appearance in the next major // to get the new style use set `useNewVariants` in Typography props restyledVariants: ['body1', 'body2', 'caption', 'button'], migrationGuideMessage: '\nPlease read the migration guide under https://material-ui.com/style/typography#migration-to-typography-v2' }; function round(value) { return Math.round(value * 1e5) / 1e5; } var caseAllCaps = { textTransform: 'uppercase' }; var defaultFontFamiliy = '"Roboto", "Helvetica", "Arial", sans-serif'; /** * @see @link{https://material.io/design/typography/the-type-system.html} * @see @link{https://material.io/design/typography/understanding-typography.html} */ function createTypography(palette, typography) { var _ref = typeof typography === 'function' ? typography(palette) : typography, _ref$fontFamily = _ref.fontFamily, fontFamily = _ref$fontFamily === void 0 ? defaultFontFamiliy : _ref$fontFamily, _ref$fontSize = _ref.fontSize, fontSize = _ref$fontSize === void 0 ? 14 : _ref$fontSize, _ref$fontWeightLight = _ref.fontWeightLight, fontWeightLight = _ref$fontWeightLight === void 0 ? 300 : _ref$fontWeightLight, _ref$fontWeightRegula = _ref.fontWeightRegular, fontWeightRegular = _ref$fontWeightRegula === void 0 ? 400 : _ref$fontWeightRegula, _ref$fontWeightMedium = _ref.fontWeightMedium, fontWeightMedium = _ref$fontWeightMedium === void 0 ? 500 : _ref$fontWeightMedium, _ref$htmlFontSize = _ref.htmlFontSize, htmlFontSize = _ref$htmlFontSize === void 0 ? 16 : _ref$htmlFontSize, _ref$suppressDeprecat = _ref.suppressDeprecationWarnings, suppressDeprecationWarnings = _ref$suppressDeprecat === void 0 ? process.env.MUI_SUPPRESS_DEPRECATION_WARNINGS : _ref$suppressDeprecat, _ref$useNextVariants = _ref.useNextVariants, useNextVariants = _ref$useNextVariants === void 0 ? false : _ref$useNextVariants, allVariants = _ref.allVariants, other = objectWithoutProperties(_ref, ["fontFamily", "fontSize", "fontWeightLight", "fontWeightRegular", "fontWeightMedium", "htmlFontSize", "suppressDeprecationWarnings", "useNextVariants", "allVariants"]); warning_1(!Object.keys(other).some(function (variant) { return typographyMigration.deprecatedVariants.includes(variant); }), 'Material-UI: You are passing a deprecated variant to ' + "createTypography. ".concat(typographyMigration.migrationGuideMessage)); warning_1(useNextVariants || !Object.keys(other).some(function (variant) { return typographyMigration.restyledVariants.includes(variant); }), 'Material-UI: You are passing a variant to createTypography ' + 'that will be restyled in the next major release, without indicating that you ' + "are using typography v2 (set `useNextVariants` to true. ".concat(typographyMigration.migrationGuideMessage)); var coef = fontSize / 14; var pxToRem = function pxToRem(size) { return "".concat(size / htmlFontSize * coef, "rem"); }; var buildVariant = function buildVariant(fontWeight, size, lineHeight, letterSpacing, casing) { return _extends_1({ color: palette.text.primary, fontFamily: fontFamily, fontWeight: fontWeight, fontSize: pxToRem(size), // Unitless following http://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/ lineHeight: lineHeight }, fontFamily === defaultFontFamiliy ? { letterSpacing: "".concat(round(letterSpacing / size), "em") } : {}, casing, allVariants); }; var nextVariants = { h1: buildVariant(fontWeightLight, 96, 1, -1.5), h2: buildVariant(fontWeightLight, 60, 1, -0.5), h3: buildVariant(fontWeightRegular, 48, 1.04, 0), h4: buildVariant(fontWeightRegular, 34, 1.17, 0.25), h5: buildVariant(fontWeightRegular, 24, 1.33, 0), h6: buildVariant(fontWeightMedium, 20, 1.6, 0.15), subtitle1: buildVariant(fontWeightRegular, 16, 1.75, 0.15), subtitle2: buildVariant(fontWeightMedium, 14, 1.57, 0.1), body1Next: buildVariant(fontWeightRegular, 16, 1.5, 0.15), body2Next: buildVariant(fontWeightRegular, 14, 1.5, 0.15), buttonNext: buildVariant(fontWeightMedium, 14, 1.5, 0.4, caseAllCaps), captionNext: buildVariant(fontWeightRegular, 12, 1.66, 0.4), overline: buildVariant(fontWeightRegular, 12, 2.66, 1, caseAllCaps) }; // To remove in v4 var oldVariants = { display4: _extends_1({ fontSize: pxToRem(112), fontWeight: fontWeightLight, fontFamily: fontFamily, letterSpacing: '-.04em', lineHeight: "".concat(round(128 / 112), "em"), marginLeft: '-.04em', color: palette.text.secondary }, allVariants), display3: _extends_1({ fontSize: pxToRem(56), fontWeight: fontWeightRegular, fontFamily: fontFamily, letterSpacing: '-.02em', lineHeight: "".concat(round(73 / 56), "em"), marginLeft: '-.02em', color: palette.text.secondary }, allVariants), display2: _extends_1({ fontSize: pxToRem(45), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(51 / 45), "em"), marginLeft: '-.02em', color: palette.text.secondary }, allVariants), display1: _extends_1({ fontSize: pxToRem(34), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(41 / 34), "em"), color: palette.text.secondary }, allVariants), headline: _extends_1({ fontSize: pxToRem(24), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(32.5 / 24), "em"), color: palette.text.primary }, allVariants), title: _extends_1({ fontSize: pxToRem(21), fontWeight: fontWeightMedium, fontFamily: fontFamily, lineHeight: "".concat(round(24.5 / 21), "em"), color: palette.text.primary }, allVariants), subheading: _extends_1({ fontSize: pxToRem(16), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(24 / 16), "em"), color: palette.text.primary }, allVariants), body2: _extends_1({ fontSize: pxToRem(14), fontWeight: fontWeightMedium, fontFamily: fontFamily, lineHeight: "".concat(round(24 / 14), "em"), color: palette.text.primary }, allVariants), body1: _extends_1({ fontSize: pxToRem(14), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(20.5 / 14), "em"), color: palette.text.primary }, allVariants), caption: _extends_1({ fontSize: pxToRem(12), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(16.5 / 12), "em"), color: palette.text.secondary }, allVariants), button: _extends_1({ fontSize: pxToRem(14), textTransform: 'uppercase', fontWeight: fontWeightMedium, fontFamily: fontFamily, color: palette.text.primary }, allVariants) }; return deepmerge_1(_extends_1({ pxToRem: pxToRem, round: round, fontFamily: fontFamily, fontSize: fontSize, fontWeightLight: fontWeightLight, fontWeightRegular: fontWeightRegular, fontWeightMedium: fontWeightMedium }, oldVariants, useNextVariants ? _extends_1({}, nextVariants, { body1: nextVariants.body1Next, body2: nextVariants.body2Next, button: nextVariants.buttonNext, caption: nextVariants.captionNext }) : nextVariants, { suppressDeprecationWarnings: suppressDeprecationWarnings, useNextVariants: useNextVariants }), other, { clone: false // No need to clone deep }); } var shadowKeyUmbraOpacity = 0.2; var shadowKeyPenumbraOpacity = 0.14; var shadowAmbientShadowOpacity = 0.12; function createShadow() { return ["".concat(arguments.length <= 0 ? undefined : arguments[0], "px ").concat(arguments.length <= 1 ? undefined : arguments[1], "px ").concat(arguments.length <= 2 ? undefined : arguments[2], "px ").concat(arguments.length <= 3 ? undefined : arguments[3], "px rgba(0, 0, 0, ").concat(shadowKeyUmbraOpacity, ")"), "".concat(arguments.length <= 4 ? undefined : arguments[4], "px ").concat(arguments.length <= 5 ? undefined : arguments[5], "px ").concat(arguments.length <= 6 ? undefined : arguments[6], "px ").concat(arguments.length <= 7 ? undefined : arguments[7], "px rgba(0, 0, 0, ").concat(shadowKeyPenumbraOpacity, ")"), "".concat(arguments.length <= 8 ? undefined : arguments[8], "px ").concat(arguments.length <= 9 ? undefined : arguments[9], "px ").concat(arguments.length <= 10 ? undefined : arguments[10], "px ").concat(arguments.length <= 11 ? undefined : arguments[11], "px rgba(0, 0, 0, ").concat(shadowAmbientShadowOpacity, ")")].join(','); } var shadows = ['none', createShadow(0,