()
| 133 | }, [inputValue]); |
| 134 | |
| 135 | let commit = () => { |
| 136 | // Set to empty state if input value is empty |
| 137 | if (!inputValue.length) { |
| 138 | safelySetColorValue(null); |
| 139 | if (value === undefined || colorValue === null) { |
| 140 | setInputValue(''); |
| 141 | } else { |
| 142 | setInputValue(colorValue.toString('hex')); |
| 143 | } |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | // if it failed to parse, then reset input to formatted version of current number |
| 148 | if (parsedValue == null) { |
| 149 | setInputValue(colorValue ? colorValue.toString('hex') : ''); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | safelySetColorValue(parsedValue); |
| 154 | // in a controlled state, the numberValue won't change, so we won't go back to our old input without help |
| 155 | let newColorValue = ''; |
| 156 | if (colorValue) { |
| 157 | newColorValue = colorValue.toString('hex'); |
| 158 | } |
| 159 | setInputValue(newColorValue); |
| 160 | validation.commitValidation(); |
| 161 | }; |
| 162 | |
| 163 | let increment = () => { |
| 164 | let newValue = addColorValue(parsedValue, step); |
no test coverage detected