@@ -8,14 +8,18 @@ import {
8
8
isSpace ,
9
9
isEnter ,
10
10
} from "@ui5/webcomponents-base/dist/Keys.js" ;
11
+ import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js" ;
11
12
import ColorPaletteTemplate from "./generated/templates/ColorPaletteTemplate.lit.js" ;
13
+ import ColorPaletteDialogTemplate from "./generated/templates/ColorPaletteDialogTemplate.lit.js" ;
12
14
import ColorPaletteItem from "./ColorPaletteItem.js" ;
13
15
import {
14
16
COLORPALETTE_CONTAINER_LABEL ,
17
+ COLOR_PALETTE_MORE_COLORS_TEXT ,
15
18
} from "./generated/i18n/i18n-defaults.js" ;
16
19
17
20
// Styles
18
21
import ColorPaletteCss from "./generated/themes/ColorPalette.css.js" ;
22
+ import ColorPaletteStaticAreaCss from "./generated/themes/ColorPaletteStaticArea.css.js" ;
19
23
20
24
/**
21
25
* @public
@@ -24,6 +28,17 @@ const metadata = {
24
28
tag : "ui5-color-palette" ,
25
29
managedSlots : true ,
26
30
properties : /** @lends sap.ui.webcomponents.main.ColorPalette.prototype */ {
31
+ /**
32
+ * Defines whether the user can choose a custom color from a color picker
33
+ * <b>Note:</b> In order to use this property you need to import the following module: <code>"@ui5/webcomponents/dist/features/ColorPaletteMoreColors.js"</code>
34
+ * @type {Boolean }
35
+ * @public
36
+ * @since 1.0.0-rc.12
37
+ */
38
+ moreColors : {
39
+ type : Boolean ,
40
+ } ,
41
+
27
42
/**
28
43
*
29
44
* The selected color.
@@ -103,12 +118,22 @@ class ColorPalette extends UI5Element {
103
118
return ColorPaletteCss ;
104
119
}
105
120
121
+ static get staticAreaStyles ( ) {
122
+ return ColorPaletteStaticAreaCss ;
123
+ }
124
+
106
125
static get template ( ) {
107
126
return ColorPaletteTemplate ;
108
127
}
109
128
129
+ static get staticAreaTemplate ( ) {
130
+ return ColorPaletteDialogTemplate ;
131
+ }
132
+
110
133
static get dependencies ( ) {
111
- return [ ColorPaletteItem ] ;
134
+ const moreColorsFeature = getFeature ( "ColorPaletteMoreColors" ) ;
135
+
136
+ return [ ColorPaletteItem ] . concat ( moreColorsFeature ? moreColorsFeature . dependencies : [ ] ) ;
112
137
}
113
138
114
139
static async onDefine ( ) {
@@ -129,13 +154,26 @@ class ColorPalette extends UI5Element {
129
154
this . displayedColors . forEach ( ( item , index ) => {
130
155
item . index = index + 1 ;
131
156
} ) ;
157
+
158
+ if ( this . moreColors ) {
159
+ const moreColorsFeature = getFeature ( "ColorPaletteMoreColors" ) ;
160
+ if ( moreColorsFeature ) {
161
+ this . moreColorsFeature = new moreColorsFeature ( ) ;
162
+ } else {
163
+ throw new Error ( `You have to import "@ui5/webcomponents/dist/features/ColorPaletteMoreColors.js" module to use the more-colors functionality.` ) ;
164
+ }
165
+ }
132
166
}
133
167
134
168
selectColor ( item ) {
135
169
item . focus ( ) ;
136
170
this . _itemNavigation . setCurrentItem ( item ) ;
137
171
138
- this . value = item . value ;
172
+ this . _setColor ( item . value ) ;
173
+ }
174
+
175
+ _setColor ( color ) {
176
+ this . value = color ;
139
177
140
178
this . fireEvent ( "change" , {
141
179
color : this . value ,
@@ -161,13 +199,47 @@ class ColorPalette extends UI5Element {
161
199
}
162
200
}
163
201
202
+ async _chooseCustomColor ( ) {
203
+ const colorPicker = await this . getColorPicker ( ) ;
204
+ this . _setColor ( colorPicker . color ) ;
205
+ this . _closeDialog ( ) ;
206
+ }
207
+
208
+ async _closeDialog ( ) {
209
+ const dialog = await this . _getDialog ( ) ;
210
+ dialog . close ( ) ;
211
+ }
212
+
213
+ async _openMoreColorsDialog ( ) {
214
+ const dialog = await this . _getDialog ( ) ;
215
+ dialog . open ( ) ;
216
+ }
217
+
164
218
get displayedColors ( ) {
165
219
return this . colors . filter ( item => item . value ) . slice ( 0 , 15 ) ;
166
220
}
167
221
168
222
get colorContainerLabel ( ) {
169
223
return this . i18nBundle . getText ( COLORPALETTE_CONTAINER_LABEL ) ;
170
224
}
225
+
226
+ get colorPaleteMoreColorsText ( ) {
227
+ return this . i18nBundle . getText ( COLOR_PALETTE_MORE_COLORS_TEXT ) ;
228
+ }
229
+
230
+ get showMoreColors ( ) {
231
+ return this . moreColors && this . moreColorsFeature ;
232
+ }
233
+
234
+ async _getDialog ( ) {
235
+ const staticAreaItem = await this . getStaticAreaItemDomRef ( ) ;
236
+ return staticAreaItem . querySelector ( "ui5-dialog" ) ;
237
+ }
238
+
239
+ async getColorPicker ( ) {
240
+ const dialog = await this . _getDialog ( ) ;
241
+ return dialog . content [ 0 ] . querySelector ( "ui5-color-picker" ) ;
242
+ }
171
243
}
172
244
173
245
ColorPalette . define ( ) ;
0 commit comments