@instructure/ui-color-picker 8.25.1-snapshot-20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +46 -0
  3. package/es/ColorContrast/ColorContrastLocator.js +54 -0
  4. package/es/ColorContrast/index.js +174 -0
  5. package/es/ColorContrast/props.js +40 -0
  6. package/es/ColorContrast/styles.js +99 -0
  7. package/es/ColorContrast/theme.js +55 -0
  8. package/es/ColorIndicator/ColorIndicatorLocator.js +40 -0
  9. package/es/ColorIndicator/index.js +91 -0
  10. package/es/ColorIndicator/props.js +31 -0
  11. package/es/ColorIndicator/styles.js +70 -0
  12. package/es/ColorIndicator/theme.js +53 -0
  13. package/es/ColorMixer/ColorMixerLocator.js +27 -0
  14. package/es/ColorMixer/ColorPalette/index.js +258 -0
  15. package/es/ColorMixer/ColorPalette/props.js +37 -0
  16. package/es/ColorMixer/ColorPalette/styles.js +81 -0
  17. package/es/ColorMixer/ColorPalette/theme.js +48 -0
  18. package/es/ColorMixer/RGBAInput/index.js +148 -0
  19. package/es/ColorMixer/RGBAInput/props.js +39 -0
  20. package/es/ColorMixer/RGBAInput/styles.js +63 -0
  21. package/es/ColorMixer/RGBAInput/theme.js +43 -0
  22. package/es/ColorMixer/Slider/index.js +218 -0
  23. package/es/ColorMixer/Slider/props.js +38 -0
  24. package/es/ColorMixer/Slider/styles.js +95 -0
  25. package/es/ColorMixer/Slider/theme.js +53 -0
  26. package/es/ColorMixer/index.js +232 -0
  27. package/es/ColorMixer/props.js +40 -0
  28. package/es/ColorMixer/styles.js +49 -0
  29. package/es/ColorMixer/utils/shallowCompare.js +32 -0
  30. package/es/ColorPicker/ColorPickerLocator.js +137 -0
  31. package/es/ColorPicker/index.js +487 -0
  32. package/es/ColorPicker/props.js +47 -0
  33. package/es/ColorPicker/styles.js +119 -0
  34. package/es/ColorPicker/theme.js +76 -0
  35. package/es/ColorPreset/ColorPresetLocator.js +27 -0
  36. package/es/ColorPreset/index.js +268 -0
  37. package/es/ColorPreset/props.js +36 -0
  38. package/es/ColorPreset/styles.js +102 -0
  39. package/es/ColorPreset/theme.js +53 -0
  40. package/es/index.js +28 -0
  41. package/lib/ColorContrast/ColorContrastLocator.js +66 -0
  42. package/lib/ColorContrast/index.js +169 -0
  43. package/lib/ColorContrast/props.js +51 -0
  44. package/lib/ColorContrast/styles.js +107 -0
  45. package/lib/ColorContrast/theme.js +63 -0
  46. package/lib/ColorIndicator/ColorIndicatorLocator.js +51 -0
  47. package/lib/ColorIndicator/index.js +82 -0
  48. package/lib/ColorIndicator/props.js +42 -0
  49. package/lib/ColorIndicator/styles.js +78 -0
  50. package/lib/ColorIndicator/theme.js +63 -0
  51. package/lib/ColorMixer/ColorMixerLocator.js +37 -0
  52. package/lib/ColorMixer/ColorPalette/index.js +252 -0
  53. package/lib/ColorMixer/ColorPalette/props.js +48 -0
  54. package/lib/ColorMixer/ColorPalette/styles.js +90 -0
  55. package/lib/ColorMixer/ColorPalette/theme.js +57 -0
  56. package/lib/ColorMixer/RGBAInput/index.js +142 -0
  57. package/lib/ColorMixer/RGBAInput/props.js +50 -0
  58. package/lib/ColorMixer/RGBAInput/styles.js +71 -0
  59. package/lib/ColorMixer/RGBAInput/theme.js +51 -0
  60. package/lib/ColorMixer/Slider/index.js +211 -0
  61. package/lib/ColorMixer/Slider/props.js +49 -0
  62. package/lib/ColorMixer/Slider/styles.js +103 -0
  63. package/lib/ColorMixer/Slider/theme.js +62 -0
  64. package/lib/ColorMixer/index.js +226 -0
  65. package/lib/ColorMixer/props.js +51 -0
  66. package/lib/ColorMixer/styles.js +57 -0
  67. package/lib/ColorMixer/utils/shallowCompare.js +40 -0
  68. package/lib/ColorPicker/ColorPickerLocator.js +151 -0
  69. package/lib/ColorPicker/index.js +500 -0
  70. package/lib/ColorPicker/props.js +58 -0
  71. package/lib/ColorPicker/styles.js +127 -0
  72. package/lib/ColorPicker/theme.js +85 -0
  73. package/lib/ColorPreset/ColorPresetLocator.js +37 -0
  74. package/lib/ColorPreset/index.js +274 -0
  75. package/lib/ColorPreset/props.js +47 -0
  76. package/lib/ColorPreset/styles.js +110 -0
  77. package/lib/ColorPreset/theme.js +61 -0
  78. package/lib/index.js +45 -0
  79. package/lib/package.json +1 -0
  80. package/package.json +62 -0
  81. package/src/ColorContrast/ColorContrastLocator.ts +51 -0
  82. package/src/ColorContrast/README.md +111 -0
  83. package/src/ColorContrast/index.tsx +189 -0
  84. package/src/ColorContrast/props.ts +140 -0
  85. package/src/ColorContrast/styles.ts +102 -0
  86. package/src/ColorContrast/theme.ts +62 -0
  87. package/src/ColorIndicator/ColorIndicatorLocator.ts +41 -0
  88. package/src/ColorIndicator/README.md +76 -0
  89. package/src/ColorIndicator/index.tsx +89 -0
  90. package/src/ColorIndicator/props.ts +68 -0
  91. package/src/ColorIndicator/styles.ts +88 -0
  92. package/src/ColorIndicator/theme.ts +58 -0
  93. package/src/ColorMixer/ColorMixerLocator.ts +29 -0
  94. package/src/ColorMixer/ColorPalette/index.tsx +250 -0
  95. package/src/ColorMixer/ColorPalette/props.ts +87 -0
  96. package/src/ColorMixer/ColorPalette/styles.ts +94 -0
  97. package/src/ColorMixer/ColorPalette/theme.ts +52 -0
  98. package/src/ColorMixer/README.md +98 -0
  99. package/src/ColorMixer/RGBAInput/index.tsx +172 -0
  100. package/src/ColorMixer/RGBAInput/props.ts +93 -0
  101. package/src/ColorMixer/RGBAInput/styles.ts +69 -0
  102. package/src/ColorMixer/RGBAInput/theme.ts +48 -0
  103. package/src/ColorMixer/Slider/index.tsx +242 -0
  104. package/src/ColorMixer/Slider/props.ts +94 -0
  105. package/src/ColorMixer/Slider/styles.ts +114 -0
  106. package/src/ColorMixer/Slider/theme.ts +59 -0
  107. package/src/ColorMixer/index.tsx +221 -0
  108. package/src/ColorMixer/props.ts +169 -0
  109. package/src/ColorMixer/styles.ts +51 -0
  110. package/src/ColorMixer/utils/shallowCompare.ts +35 -0
  111. package/src/ColorPicker/ColorPickerLocator.ts +124 -0
  112. package/src/ColorPicker/README.md +420 -0
  113. package/src/ColorPicker/index.tsx +609 -0
  114. package/src/ColorPicker/props.ts +293 -0
  115. package/src/ColorPicker/styles.ts +131 -0
  116. package/src/ColorPicker/theme.ts +80 -0
  117. package/src/ColorPreset/ColorPresetLocator.ts +29 -0
  118. package/src/ColorPreset/README.md +121 -0
  119. package/src/ColorPreset/index.tsx +328 -0
  120. package/src/ColorPreset/props.ts +162 -0
  121. package/src/ColorPreset/styles.ts +107 -0
  122. package/src/ColorPreset/theme.ts +58 -0
  123. package/src/index.ts +34 -0
  124. package/tsconfig.build.json +36 -0
  125. package/tsconfig.build.tsbuildinfo +1 -0
  126. package/types/ColorContrast/ColorContrastLocator.d.ts +592 -0
  127. package/types/ColorContrast/ColorContrastLocator.d.ts.map +1 -0
  128. package/types/ColorContrast/index.d.ts +61 -0
  129. package/types/ColorContrast/index.d.ts.map +1 -0
  130. package/types/ColorContrast/props.d.ts +62 -0
  131. package/types/ColorContrast/props.d.ts.map +1 -0
  132. package/types/ColorContrast/styles.d.ts +76 -0
  133. package/types/ColorContrast/styles.d.ts.map +1 -0
  134. package/types/ColorContrast/theme.d.ts +10 -0
  135. package/types/ColorContrast/theme.d.ts.map +1 -0
  136. package/types/ColorIndicator/ColorIndicatorLocator.d.ts +577 -0
  137. package/types/ColorIndicator/ColorIndicatorLocator.d.ts.map +1 -0
  138. package/types/ColorIndicator/index.d.ts +35 -0
  139. package/types/ColorIndicator/index.d.ts.map +1 -0
  140. package/types/ColorIndicator/props.d.ts +25 -0
  141. package/types/ColorIndicator/props.d.ts.map +1 -0
  142. package/types/ColorIndicator/styles.d.ts +15 -0
  143. package/types/ColorIndicator/styles.d.ts.map +1 -0
  144. package/types/ColorIndicator/theme.d.ts +11 -0
  145. package/types/ColorIndicator/theme.d.ts.map +1 -0
  146. package/types/ColorMixer/ColorMixerLocator.d.ts +566 -0
  147. package/types/ColorMixer/ColorMixerLocator.d.ts.map +1 -0
  148. package/types/ColorMixer/ColorPalette/index.d.ts +70 -0
  149. package/types/ColorMixer/ColorPalette/index.d.ts.map +1 -0
  150. package/types/ColorMixer/ColorPalette/props.d.ts +29 -0
  151. package/types/ColorMixer/ColorPalette/props.d.ts.map +1 -0
  152. package/types/ColorMixer/ColorPalette/styles.d.ts +15 -0
  153. package/types/ColorMixer/ColorPalette/styles.d.ts.map +1 -0
  154. package/types/ColorMixer/ColorPalette/theme.d.ts +10 -0
  155. package/types/ColorMixer/ColorPalette/theme.d.ts.map +1 -0
  156. package/types/ColorMixer/RGBAInput/index.d.ts +51 -0
  157. package/types/ColorMixer/RGBAInput/index.d.ts.map +1 -0
  158. package/types/ColorMixer/RGBAInput/props.d.ts +28 -0
  159. package/types/ColorMixer/RGBAInput/props.d.ts.map +1 -0
  160. package/types/ColorMixer/RGBAInput/styles.d.ts +15 -0
  161. package/types/ColorMixer/RGBAInput/styles.d.ts.map +1 -0
  162. package/types/ColorMixer/RGBAInput/theme.d.ts +10 -0
  163. package/types/ColorMixer/RGBAInput/theme.d.ts.map +1 -0
  164. package/types/ColorMixer/Slider/index.d.ts +64 -0
  165. package/types/ColorMixer/Slider/index.d.ts.map +1 -0
  166. package/types/ColorMixer/Slider/props.d.ts +26 -0
  167. package/types/ColorMixer/Slider/props.d.ts.map +1 -0
  168. package/types/ColorMixer/Slider/styles.d.ts +15 -0
  169. package/types/ColorMixer/Slider/styles.d.ts.map +1 -0
  170. package/types/ColorMixer/Slider/theme.d.ts +10 -0
  171. package/types/ColorMixer/Slider/theme.d.ts.map +1 -0
  172. package/types/ColorMixer/index.d.ts +59 -0
  173. package/types/ColorMixer/index.d.ts.map +1 -0
  174. package/types/ColorMixer/props.d.ts +91 -0
  175. package/types/ColorMixer/props.d.ts.map +1 -0
  176. package/types/ColorMixer/styles.d.ts +14 -0
  177. package/types/ColorMixer/styles.d.ts.map +1 -0
  178. package/types/ColorMixer/utils/shallowCompare.d.ts +3 -0
  179. package/types/ColorMixer/utils/shallowCompare.d.ts.map +1 -0
  180. package/types/ColorPicker/ColorPickerLocator.d.ts +4113 -0
  181. package/types/ColorPicker/ColorPickerLocator.d.ts.map +1 -0
  182. package/types/ColorPicker/index.d.ts +158 -0
  183. package/types/ColorPicker/index.d.ts.map +1 -0
  184. package/types/ColorPicker/props.d.ts +166 -0
  185. package/types/ColorPicker/props.d.ts.map +1 -0
  186. package/types/ColorPicker/styles.d.ts +17 -0
  187. package/types/ColorPicker/styles.d.ts.map +1 -0
  188. package/types/ColorPicker/theme.d.ts +10 -0
  189. package/types/ColorPicker/theme.d.ts.map +1 -0
  190. package/types/ColorPreset/ColorPresetLocator.d.ts +566 -0
  191. package/types/ColorPreset/ColorPresetLocator.d.ts.map +1 -0
  192. package/types/ColorPreset/index.d.ts +100 -0
  193. package/types/ColorPreset/index.d.ts.map +1 -0
  194. package/types/ColorPreset/props.d.ts +87 -0
  195. package/types/ColorPreset/props.d.ts.map +1 -0
  196. package/types/ColorPreset/styles.d.ts +77 -0
  197. package/types/ColorPreset/styles.d.ts.map +1 -0
  198. package/types/ColorPreset/theme.d.ts +10 -0
  199. package/types/ColorPreset/theme.d.ts.map +1 -0
  200. package/types/index.d.ts +11 -0
  201. package/types/index.d.ts.map +1 -0
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.propTypes = exports.allowedProps = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ /*
13
+ * The MIT License (MIT)
14
+ *
15
+ * Copyright (c) 2015 - present Instructure, Inc.
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ * of this software and associated documentation files (the "Software"), to deal
19
+ * in the Software without restriction, including without limitation the rights
20
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ * copies of the Software, and to permit persons to whom the Software is
22
+ * furnished to do so, subject to the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be included in all
25
+ * copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ * SOFTWARE.
34
+ */
35
+ const propTypes = {
36
+ disabled: _propTypes.default.bool,
37
+ label: _propTypes.default.string,
38
+ width: _propTypes.default.number.isRequired,
39
+ value: _propTypes.default.object.isRequired,
40
+ onChange: _propTypes.default.func.isRequired,
41
+ withAlpha: _propTypes.default.bool,
42
+ rgbRedInputScreenReaderLabel: _propTypes.default.string.isRequired,
43
+ rgbGreenInputScreenReaderLabel: _propTypes.default.string.isRequired,
44
+ rgbBlueInputScreenReaderLabel: _propTypes.default.string.isRequired,
45
+ rgbAlphaInputScreenReaderLabel: _propTypes.default.string.isRequired,
46
+ elementRef: _propTypes.default.func
47
+ };
48
+ exports.propTypes = propTypes;
49
+ const allowedProps = ['disabled', 'label', 'width', 'value', 'onChange', 'withAlpha', 'rgbRedInputScreenReaderLabel', 'rgbGreenInputScreenReaderLabel', 'rgbBlueInputScreenReaderLabel', 'rgbAlphaInputScreenReaderLabel', 'elementRef'];
50
+ exports.allowedProps = allowedProps;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * ---
34
+ * private: true
35
+ * ---
36
+ * Generates the style object from the theme and provided additional information
37
+ * @param {Object} componentTheme The theme variable object.
38
+ * @param {Object} props the props of the component, the style is applied to
39
+ * @param {Object} state the state of the component, the style is applied to
40
+ * @return {Object} The final style object, which will be used in the component
41
+ */
42
+ const generateStyle = (componentTheme, props) => {
43
+ return {
44
+ RGBAInput: {
45
+ label: 'RGBAInput',
46
+ marginTop: componentTheme.rgbaInputTopMargin,
47
+ width: `${props.width / 16}rem`
48
+ },
49
+ label: {
50
+ label: 'RGBAInput__label',
51
+ fontWeight: componentTheme.labelFontWeight
52
+ },
53
+ inputContainer: {
54
+ label: 'RGBAInput__inputContainer',
55
+ display: 'flex',
56
+ marginTop: componentTheme.inputContainerTopMargin
57
+ },
58
+ rgbInput: {
59
+ label: 'RGBAInput__rgbInput',
60
+ marginInlineEnd: componentTheme.tgbInputTopMargin,
61
+ flex: 7
62
+ },
63
+ aInput: {
64
+ label: 'RGBAInput__aInput',
65
+ flex: 10
66
+ }
67
+ };
68
+ };
69
+
70
+ var _default = generateStyle;
71
+ exports.default = _default;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * Generates the theme object for the component from the theme and provided additional information
34
+ * @param {Object} theme The actual theme object.
35
+ * @return {Object} The final theme object with the overrides and component variables
36
+ */
37
+ const generateComponentTheme = theme => {
38
+ const spacing = theme.spacing,
39
+ typography = theme.typography;
40
+ const componentVariables = {
41
+ labelFontWeight: typography.fontWeightBold,
42
+ inputContainerTopMargin: spacing.xSmall,
43
+ tgbInputTopMargin: spacing.xSmall,
44
+ rgbaInputTopMargin: spacing.medium
45
+ };
46
+ return { ...componentVariables
47
+ };
48
+ };
49
+
50
+ var _default = generateComponentTheme;
51
+ exports.default = _default;
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = void 0;
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
15
+
16
+ var _emotion = require("@instructure/emotion");
17
+
18
+ var _View = require("@instructure/ui-view/lib/View");
19
+
20
+ var _props = require("./props");
21
+
22
+ var _styles = _interopRequireDefault(require("./styles"));
23
+
24
+ var _theme = _interopRequireDefault(require("./theme"));
25
+
26
+ var _dec, _class, _class2;
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * @tsProps
33
+ **/
34
+ let Slider = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_class2 = class Slider extends _react.Component {
35
+ constructor() {
36
+ super(...arguments);
37
+ this.ref = null;
38
+ this._sliderRef = null;
39
+ this._mouseMoveListener = void 0;
40
+ this._mouseUpListener = void 0;
41
+
42
+ this.handleRef = el => {
43
+ const elementRef = this.props.elementRef;
44
+ this.ref = el;
45
+
46
+ if (typeof elementRef === 'function') {
47
+ elementRef(el);
48
+ }
49
+ };
50
+
51
+ this.handleChange = e => {
52
+ if (this.props.disabled) return;
53
+ const clientX = e.clientX;
54
+ const newPosition = this.calcSliderPositionFromCursorPosition(clientX, this._sliderRef);
55
+ this.props.onChange(this.calcValueFromSliderPosition(newPosition));
56
+ };
57
+
58
+ this.handleMouseUp = () => {
59
+ this.removeEventListeners();
60
+ };
61
+
62
+ this.calcSliderPositionFromCursorPosition = (clientX, _sliderRef) => {
63
+ if (this.props.isColorSlider) {
64
+ const _sliderRef$getBoundin = _sliderRef.getBoundingClientRect(),
65
+ x = _sliderRef$getBoundin.x;
66
+
67
+ const newPosition = clientX - x;
68
+ return newPosition < 0 ? 0 : newPosition > this.props.width ? this.props.width - 1 : newPosition;
69
+ } else {
70
+ const _sliderRef$getBoundin2 = _sliderRef.getBoundingClientRect(),
71
+ x = _sliderRef$getBoundin2.x;
72
+
73
+ return clientX - x;
74
+ }
75
+ };
76
+
77
+ this.calcSliderPositionFromValue = value => {
78
+ if (this.props.isColorSlider) {
79
+ return value / 360 * this.props.width;
80
+ } else {
81
+ return this.props.width - (1 - value) * this.props.width;
82
+ }
83
+ };
84
+
85
+ this.calcValueFromSliderPosition = position => {
86
+ if (this.props.isColorSlider) {
87
+ return position / this.props.width * 360;
88
+ } else {
89
+ const positionWithBoundaries = position < 0 ? 0 : position > this.props.width ? this.props.width : position;
90
+ return Math.round(positionWithBoundaries * 100 / this.props.width);
91
+ }
92
+ };
93
+ }
94
+
95
+ componentDidMount() {
96
+ var _this$props$makeStyle, _this$props;
97
+
98
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStylesProps);
99
+ }
100
+
101
+ componentDidUpdate() {
102
+ var _this$props$makeStyle2, _this$props2;
103
+
104
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStylesProps);
105
+ }
106
+
107
+ componentWillUnmount() {
108
+ this.removeEventListeners();
109
+ }
110
+
111
+ removeEventListeners() {
112
+ var _this$_mouseMoveListe, _this$_mouseUpListene;
113
+
114
+ (_this$_mouseMoveListe = this._mouseMoveListener) === null || _this$_mouseMoveListe === void 0 ? void 0 : _this$_mouseMoveListe.remove();
115
+ (_this$_mouseUpListene = this._mouseUpListener) === null || _this$_mouseUpListene === void 0 ? void 0 : _this$_mouseUpListene.remove();
116
+ }
117
+
118
+ get sliderPositionFromValue() {
119
+ return this.calcSliderPositionFromValue(this.props.value);
120
+ }
121
+
122
+ get roundedValue() {
123
+ const _this$props3 = this.props,
124
+ value = _this$props3.value,
125
+ maxValue = _this$props3.maxValue;
126
+
127
+ if (maxValue <= 1) {
128
+ return Math.round(value * 100);
129
+ } else {
130
+ return Math.round(value);
131
+ }
132
+ }
133
+
134
+ get makeStylesProps() {
135
+ return {
136
+ sliderPositionFromValue: this.sliderPositionFromValue
137
+ };
138
+ }
139
+
140
+ handleMouseDown(e) {
141
+ this.handleChange(e);
142
+ this._mouseMoveListener = (0, _addEventListener.addEventListener)(window, 'mousemove', this.handleChange);
143
+ this._mouseUpListener = (0, _addEventListener.addEventListener)(window, 'mouseup', this.handleMouseUp);
144
+ }
145
+
146
+ applyBoundaries(x) {
147
+ if (x > this.props.width) return this.props.width;
148
+ if (x < 0) return 0;
149
+ return x;
150
+ }
151
+
152
+ handleKeyDown(e) {
153
+ const key = e.key;
154
+ if (key === 'Tab') return;
155
+ e.preventDefault();
156
+ let deltaX = 0;
157
+
158
+ if (key === 'ArrowLeft' || key === 'a') {
159
+ deltaX = -2;
160
+ }
161
+
162
+ if (key === 'ArrowRight' || key === 'd') {
163
+ deltaX = 2;
164
+ }
165
+
166
+ const newPosition = this.applyBoundaries(this.sliderPositionFromValue + deltaX);
167
+ this.props.onChange(this.calcValueFromSliderPosition(newPosition));
168
+ }
169
+
170
+ render() {
171
+ var _this$props$styles, _this$props$styles2, _this$props$styles3, _this$props$styles4;
172
+
173
+ return (0, _emotion.jsx)(_View.View, {
174
+ elementRef: this.handleRef,
175
+ disabled: this.props.disabled,
176
+ position: "relative",
177
+ background: "transparent",
178
+ margin: "small 0 0 0",
179
+ display: "inline-block",
180
+ borderRadius: "medium",
181
+ borderWidth: "0",
182
+ padding: "0",
183
+ as: "div",
184
+ onKeyDown: e => this.handleKeyDown(e),
185
+ onMouseDown: e => this.handleMouseDown(e),
186
+ tabIndex: this.props.disabled ? void 0 : 0,
187
+ "aria-label": this.props.navigationExplanationScreenReaderLabel // TODO: check RangeInput and ProgressBar to see how the slider role can be handled well
188
+ // role="slider"
189
+ // aria-valuemin={this.props.minValue}
190
+ // aria-valuemax={this.props.maxValue}
191
+ // aria-valuenow={this.roundedValue}
192
+
193
+ }, (0, _emotion.jsx)("div", {
194
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.indicator
195
+ }), this.props.disabled && (0, _emotion.jsx)("div", {
196
+ css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.disabledOverlay
197
+ }), (0, _emotion.jsx)("div", {
198
+ ref: ref => {
199
+ this._sliderRef = ref;
200
+ },
201
+ css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.sliderBackground
202
+ }, (0, _emotion.jsx)("div", {
203
+ css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.slider
204
+ })));
205
+ }
206
+
207
+ }, _class2.displayName = "Slider", _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.componentId = 'ColorMixer.Slider', _class2.defaultProps = {
208
+ isColorSlider: false
209
+ }, _class2)) || _class);
210
+ var _default = Slider;
211
+ exports.default = _default;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.propTypes = exports.allowedProps = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ /*
13
+ * The MIT License (MIT)
14
+ *
15
+ * Copyright (c) 2015 - present Instructure, Inc.
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ * of this software and associated documentation files (the "Software"), to deal
19
+ * in the Software without restriction, including without limitation the rights
20
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ * copies of the Software, and to permit persons to whom the Software is
22
+ * furnished to do so, subject to the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be included in all
25
+ * copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ * SOFTWARE.
34
+ */
35
+ const propTypes = {
36
+ isColorSlider: _propTypes.default.bool,
37
+ onChange: _propTypes.default.func.isRequired,
38
+ width: _propTypes.default.number.isRequired,
39
+ value: _propTypes.default.number.isRequired,
40
+ minValue: _propTypes.default.number.isRequired,
41
+ maxValue: _propTypes.default.number.isRequired,
42
+ indicatorRadius: _propTypes.default.number.isRequired,
43
+ height: _propTypes.default.number.isRequired,
44
+ elementRef: _propTypes.default.func,
45
+ navigationExplanationScreenReaderLabel: _propTypes.default.string.isRequired
46
+ };
47
+ exports.propTypes = propTypes;
48
+ const allowedProps = ['isColorSlider', 'onChange', 'width', 'value', 'minValue', 'maxValue', 'indicatorRadius', 'height', 'elementRef', 'navigationExplanationScreenReaderLabel'];
49
+ exports.allowedProps = allowedProps;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * ---
34
+ * private: true
35
+ * ---
36
+ * Generates the style object from the theme and provided additional information
37
+ * @param {Object} componentTheme The theme variable object.
38
+ * @param {Object} props the props of the component, the style is applied to
39
+ * @param {Object} state the state of the component, the style is applied to
40
+ * @return {Object} The final style object, which will be used in the component
41
+ */
42
+ const generateStyle = (componentTheme, props, state) => {
43
+ var _props$color;
44
+
45
+ const sliderBackground = props.isColorSlider ? {
46
+ background: 'linear-gradient(to right, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%)'
47
+ } : {
48
+ background: componentTheme.checkerboardBackgroundImage,
49
+ backgroundSize: componentTheme.checkerboardBackgroundSize,
50
+ backgroundPosition: componentTheme.checkerboardBackgroundPosition
51
+ };
52
+ return {
53
+ colorSlider: {
54
+ label: 'colorMixerSlider'
55
+ },
56
+ indicator: {
57
+ label: 'colorMixerSlider__indicator',
58
+ width: `${props.indicatorRadius / 8}rem`,
59
+ height: `${props.indicatorRadius / 8}rem`,
60
+ borderRadius: `${props.indicatorRadius / 8}rem`,
61
+ background: 'white',
62
+ position: 'absolute',
63
+ borderStyle: 'solid',
64
+ borderWidth: componentTheme.indicatorBorderWidth,
65
+ borderColor: componentTheme.indicatorBorderColor,
66
+ top: `-0.1875rem`,
67
+ left: `${((state === null || state === void 0 ? void 0 : state.sliderPositionFromValue) - props.indicatorRadius) / 16}rem`,
68
+ zIndex: componentTheme.indicatorZIndex
69
+ },
70
+ sliderBackground: {
71
+ label: 'colorMixerSlider__sliderBackground',
72
+ borderRadius: `${props.height / 16}rem`,
73
+ width: `${props.width / 16}rem`,
74
+ height: `${props.height / 16}rem`,
75
+ boxSizing: 'border-box',
76
+ ...sliderBackground
77
+ },
78
+ slider: {
79
+ label: 'colorMixerSlider__slider',
80
+ width: `${props.width / 16}rem`,
81
+ height: `${props.height / 16}rem`,
82
+ background: props.isColorSlider ? 'transparent' : `linear-gradient(to right, rgba(255,0,0,0), ${(_props$color = props.color) === null || _props$color === void 0 ? void 0 : _props$color.slice(0, -2)})`,
83
+ borderRadius: `${props.height / 16}rem`,
84
+ boxSizing: 'border-box',
85
+ borderStyle: 'solid',
86
+ borderColor: componentTheme.colorIndicatorBorderColor,
87
+ borderWidth: componentTheme.sliderBorderWidth
88
+ },
89
+ disabledOverlay: {
90
+ label: 'colorMixerSlider__disabledOverlay',
91
+ background: 'rgba(255,255,255,.5)',
92
+ zIndex: componentTheme.disabledOverlayZIndex,
93
+ width: `${props.width / 16 + 1}rem`,
94
+ height: `${props.height / 16 + 1}rem`,
95
+ position: 'absolute',
96
+ top: '-.5rem',
97
+ left: '-.5rem'
98
+ }
99
+ };
100
+ };
101
+
102
+ var _default = generateStyle;
103
+ exports.default = _default;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _theme = require("../../ColorIndicator/theme");
9
+
10
+ /*
11
+ * The MIT License (MIT)
12
+ *
13
+ * Copyright (c) 2015 - present Instructure, Inc.
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ */
33
+
34
+ /**
35
+ * Generates the theme object for the component from the theme and provided additional information
36
+ * @param {Object} theme The actual theme object.
37
+ * @return {Object} The final theme object with the overrides and component variables
38
+ */
39
+ const generateComponentTheme = theme => {
40
+ const colors = theme.colors,
41
+ borders = theme.borders,
42
+ stacking = theme.stacking;
43
+ const componentVariables = {
44
+ indicatorBorderColor: colors.licorice,
45
+ checkerboardBackgroundImage: `linear-gradient(45deg, ${colors.tiara} 25%, transparent 25%),
46
+ linear-gradient(-45deg, ${colors.tiara} 25%, transparent 25%),
47
+ linear-gradient(45deg, transparent 75%, ${colors.tiara} 75%),
48
+ linear-gradient(-45deg, transparent 75%, ${colors.tiara} 75%)`,
49
+ checkerboardBackgroundSize: '.5rem .5rem',
50
+ checkerboardBackgroundPosition: '0 0, 0 .25rem, .25rem -0.25rem, -0.25rem 0px',
51
+ colorIndicatorBorderColor: _theme.colorIndicatorBorderColor,
52
+ indicatorBorderWidth: borders.widthSmall,
53
+ sliderBorderWidth: borders.widthSmall,
54
+ indicatorZIndex: stacking.above,
55
+ disabledOverlayZIndex: stacking.topmost
56
+ };
57
+ return { ...componentVariables
58
+ };
59
+ };
60
+
61
+ var _default = generateComponentTheme;
62
+ exports.default = _default;