Skip to content

Commit 6b64e12

Browse files
author
Robert He
committed
MAGETWO-89659: Address comments / feedback from review
- fix bugs and stylings
1 parent ea4b71a commit 6b64e12

File tree

12 files changed

+86
-81
lines changed

12 files changed

+86
-81
lines changed

app/code/Magento/Ui/Component/Form/Element/ColorPicker.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1515

1616
/**
17+
* Class ColorPicker
18+
*
1719
* @api
1820
*/
1921
class ColorPicker extends AbstractElement

app/code/Magento/Ui/Model/ColorPicker/ColorModesProvider.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Magento\Ui\Model\ColorPicker;
1010

11+
/**
12+
* Class ColorModesProvider
13+
*/
1114
class ColorModesProvider
1215
{
1316
private $colorModes;
@@ -22,7 +25,12 @@ public function __construct(
2225
$this->objectManager = $objectManager;
2326
}
2427

25-
public function getModes()
28+
/**
29+
* Return all available modes and their configuration
30+
*
31+
* @return array
32+
*/
33+
public function getModes(): array
2634
{
2735
$config = [];
2836
foreach ($this->colorModes as $modeName => $className) {
@@ -36,9 +44,9 @@ public function getModes()
3644
* Create mode provider
3745
*
3846
* @param string $instance
39-
* @return ConfigInterface
47+
* @return ModeInterface
4048
*/
41-
private function createModeProvider($instance)
49+
private function createModeProvider(string $instance): ModeInterface
4250
{
4351
if (!is_subclass_of(
4452
$instance,

app/code/Magento/Ui/Model/ColorPicker/FullMode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FullMode implements ModeInterface
1818
*
1919
* @return array
2020
*/
21-
public function getConfig()
21+
public function getConfig(): array
2222
{
2323
return [
2424
'showInput' => true,

app/code/Magento/Ui/Model/ColorPicker/NoAlphaMode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Ui\Model\ColorPicker;
1010

1111
/**
12-
* Returns config parameters for full mode
12+
* Returns config parameters for noalpha mode
1313
*/
1414
class NoAlphaMode implements ModeInterface
1515
{
@@ -18,7 +18,7 @@ class NoAlphaMode implements ModeInterface
1818
*
1919
* @return array
2020
*/
21-
public function getConfig()
21+
public function getConfig(): array
2222
{
2323
return [
2424
'showInput' => true,

app/code/Magento/Ui/Model/ColorPicker/PaletteOnlyMode.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Ui\Model\ColorPicker;
1010

1111
/**
12-
* Returns config parameters for full mode
12+
* Returns config parameters for paletteonly mode
1313
*/
1414
class PaletteOnlyMode implements ModeInterface
1515
{
@@ -18,14 +18,15 @@ class PaletteOnlyMode implements ModeInterface
1818
*
1919
* @return array
2020
*/
21-
public function getConfig()
21+
public function getConfig(): array
2222
{
2323
return [
2424
'showInput' => false,
2525
'showInitial' => false,
2626
'showPalette' => true,
27+
'showPaletteOnly' => true,
2728
'showAlpha' => false,
28-
'showSelectionPalette' => true
29+
'showSelectionPalette' => false
2930
];
3031
}
3132
}

app/code/Magento/Ui/Model/ColorPicker/SimpleMode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Ui\Model\ColorPicker;
1010

1111
/**
12-
* Returns config parameters for full mode
12+
* Returns config parameters for simple mode
1313
*/
1414
class SimpleMode implements ModeInterface
1515
{
@@ -18,7 +18,7 @@ class SimpleMode implements ModeInterface
1818
*
1919
* @return array
2020
*/
21-
public function getConfig()
21+
public function getConfig(): array
2222
{
2323
return [
2424
'showInput' => false,

app/code/Magento/Ui/etc/ui_configuration.xsd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@
455455
<xs:element name="colorPicker" type="componentColorPicker">
456456
<xs:annotation>
457457
<xs:documentation>
458-
The ColorPicker component utilizes the Spectrum js library to allow user greater flexibility in entering
459-
color values.
458+
The ColorPicker component uses the Spectrum and tinycolor .js libraries to make it easier to choose and
459+
implement color values.
460460
</xs:documentation>
461461
</xs:annotation>
462462
</xs:element>

app/code/Magento/Ui/view/base/ui_component/etc/definition.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
<initialMediaGalleryOpenSubpath>wysiwyg</initialMediaGalleryOpenSubpath>
150150
</settings>
151151
</imageUploader>
152-
<colorPicker class="Magento\Ui\Component\Form\Element\ColorPicker" component="Magento_Ui/js/form/element/colorPicker" template="ui/form/field">
152+
<colorPicker class="Magento\Ui\Component\Form\Element\ColorPicker" component="Magento_Ui/js/form/element/color-picker" template="ui/form/field">
153153
<settings>
154154
<elementTmpl>ui/form/element/colorPicker</elementTmpl>
155155
<colorFormat>rgb</colorFormat>

app/code/Magento/Ui/view/base/web/js/form/element/colorPicker.js renamed to app/code/Magento/Ui/view/base/web/js/form/element/color-picker.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15

26
/**
37
* @api
48
*/
59
define([
6-
'jquery',
7-
'underscore',
8-
'uiLayout',
910
'mage/translate',
10-
'Magento_Ui/js/form/element/abstract',
11-
'spectrum'
12-
], function ($, _, layout, $t, Abstract, spectrum) {
11+
'Magento_Ui/js/form/element/abstract'
12+
], function ($t, Abstract) {
1313
'use strict';
1414

1515
var defaultColorPalette = [
@@ -43,17 +43,10 @@ define([
4343
*/
4444
initialize: function () {
4545
this._super();
46+
4647
this.colorPickerConfig.value = this.value;
47-
// $(document).on('click', '.sp-replacer', function () {
48-
// this.focused(true);
49-
// });
5048
return this;
51-
},
52-
53-
// setFocus: function () {
54-
// this.focused(true);
55-
// }
56-
49+
}
5750
});
5851
});
5952

app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/colorPicker.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ define([
66
'ko',
77
'jquery',
88
'../template/renderer',
9-
'spectrum'
10-
], function (ko, $, renderer, spectrum) {
9+
'spectrum',
10+
'tinycolor'
11+
], function (ko, $, renderer, spectrum, tinycolor) {
1112
'use strict';
1213

1314
ko.bindingHandlers.colorPicker = {
@@ -22,24 +23,40 @@ define([
2223
*/
2324
init: function (element, valueAccessor, allBindings, viewModel) {
2425
var config = valueAccessor();
25-
config.change = function (value) {
26-
if (value == null) {
27-
value = '';
28-
}
29-
config.value(value.toString());
30-
};
31-
config.hide = function (value) {
32-
if (value == null) {
33-
value = '';
34-
}
35-
config.value(value.toString());
36-
};
37-
$(element).spectrum(config);
26+
27+
if (!viewModel.disabled()) {
28+
config.change = function (value) {
29+
if (value == null) {
30+
value = '';
31+
}
32+
config.value(value.toString());
33+
};
34+
35+
config.hide = function (value) {
36+
if (value == null) {
37+
value = '';
38+
}
39+
config.value(value.toString());
40+
};
41+
config.show = function () {
42+
if (!viewModel.focused()) {
43+
viewModel.focused(true);
44+
}
45+
return true;
46+
};
47+
$(element).spectrum(config);
48+
} else {
49+
$(element).spectrum({
50+
disabled: true
51+
});
52+
}
3853
},
3954

4055
update: function(element, valueAccessor, allBindings, viewModel) {
4156
var config = valueAccessor();
42-
$(element).spectrum("set", config.value());
57+
if (tinycolor(config.value()).isValid() || config.value() === '') {
58+
$(element).spectrum("set", config.value());
59+
}
4360
}
4461
};
4562

0 commit comments

Comments
 (0)