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