UNPKG

4.63 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5exports.__esModule = true;
6exports["default"] = exports.ProgressLabel = void 0;
7
8var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
10var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));
13
14var _core = require("@emotion/core");
15
16var _ColorModeProvider = require("../ColorModeProvider");
17
18var _Box = _interopRequireDefault(require("../Box"));
19
20var _colorsUtils = require("../theme/colors-utils");
21
22var _Slider = require("../Slider");
23
24function _templateObject2() {
25 var data = (0, _taggedTemplateLiteralLoose2["default"])(["\n animation: ", " 1s linear infinite;\n"]);
26
27 _templateObject2 = function _templateObject2() {
28 return data;
29 };
30
31 return data;
32}
33
34function _templateObject() {
35 var data = (0, _taggedTemplateLiteralLoose2["default"])(["\n from { background-position: 1rem 0}\n to { background-position: 0 0 }\n"]);
36
37 _templateObject = function _templateObject() {
38 return data;
39 };
40
41 return data;
42}
43
44var stripe = (0, _core.keyframes)(_templateObject());
45var stripeAnimation = (0, _core.css)(_templateObject2(), stripe);
46
47var ProgressLabel = function ProgressLabel(props) {
48 return (0, _core.jsx)(_Box["default"], (0, _extends2["default"])({
49 textAlign: "center",
50 width: "100%"
51 }, props));
52};
53
54exports.ProgressLabel = ProgressLabel;
55
56var ProgressIndicator = function ProgressIndicator(_ref) {
57 var isIndeterminate = _ref.isIndeterminate,
58 min = _ref.min,
59 max = _ref.max,
60 value = _ref.value,
61 rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref, ["isIndeterminate", "min", "max", "value"]);
62 var percent = (0, _Slider.valueToPercent)(value, min, max);
63 return (0, _core.jsx)(_Box["default"], (0, _extends2["default"])({
64 height: "100%",
65 "aria-valuemax": max,
66 "aria-valuemin": min,
67 "aria-valuenow": isIndeterminate ? null : value,
68 role: "progressbar",
69 transition: "all 0.3s",
70 width: percent + "%"
71 }, rest));
72};
73
74var progressbarSizes = {
75 lg: "1rem",
76 md: "0.75rem",
77 sm: "0.5rem"
78};
79
80var ProgressTrack = function ProgressTrack(_ref2) {
81 var size = _ref2.size,
82 rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, ["size"]);
83 return (0, _core.jsx)(_Box["default"], (0, _extends2["default"])({
84 pos: "relative",
85 height: progressbarSizes[size],
86 overflow: "hidden"
87 }, rest));
88};
89
90var Progress = function Progress(_ref3) {
91 var _ref3$color = _ref3.color,
92 color = _ref3$color === void 0 ? "blue" : _ref3$color,
93 _ref3$value = _ref3.value,
94 value = _ref3$value === void 0 ? 63 : _ref3$value,
95 _ref3$min = _ref3.min,
96 min = _ref3$min === void 0 ? 0 : _ref3$min,
97 _ref3$max = _ref3.max,
98 max = _ref3$max === void 0 ? 100 : _ref3$max,
99 _ref3$size = _ref3.size,
100 size = _ref3$size === void 0 ? "md" : _ref3$size,
101 hasStripe = _ref3.hasStripe,
102 isAnimated = _ref3.isAnimated,
103 borderRadius = _ref3.borderRadius,
104 rounded = _ref3.rounded,
105 children = _ref3.children,
106 isIndeterminate = _ref3.isIndeterminate,
107 rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref3, ["color", "value", "min", "max", "size", "hasStripe", "isAnimated", "borderRadius", "rounded", "children", "isIndeterminate"]);
108
109 var _borderRadius = rounded || borderRadius;
110
111 var _useColorMode = (0, _ColorModeProvider.useColorMode)(),
112 colorMode = _useColorMode.colorMode;
113
114 var trackColor = {
115 light: "gray.100",
116 dark: "whiteAlpha.300"
117 };
118 var indicatorColor = {
119 light: color + ".500",
120 dark: color + ".200"
121 };
122 var stripeStyle = {
123 light: (0, _colorsUtils.generateStripe)({}),
124 dark: (0, _colorsUtils.generateStripe)({
125 color: "rgba(0,0,0,0.1)"
126 })
127 };
128 return (0, _core.jsx)(ProgressTrack, (0, _extends2["default"])({
129 size: size,
130 bg: trackColor[colorMode],
131 borderRadius: _borderRadius
132 }, rest), (0, _core.jsx)(ProgressIndicator, (0, _extends2["default"])({
133 min: min,
134 max: max,
135 value: value,
136 bg: indicatorColor[colorMode],
137 borderRadius: _borderRadius
138 }, isIndeterminate && {
139 width: "100%",
140 position: "absolute",
141 top: 0,
142 left: 0,
143 bottom: 0,
144 willChange: "left, right"
145 }, {
146 css: [hasStripe && stripeStyle[colorMode], hasStripe && isAnimated && stripeAnimation]
147 })));
148};
149
150var _default = Progress;
151exports["default"] = _default;
\No newline at end of file