@gem-sdk/components 2.0.0-dev.400 → 2.0.0-dev.402

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.
@@ -1,13 +1,19 @@
1
1
  'use client';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { createStyle, createClass } from '@gem-sdk/system';
4
- import { composeContainerStyles, composeFormDropdownStyles } from './common/composeStyles.js';
3
+ import { createStyle, createClass, If } from '@gem-sdk/system';
4
+ import { composeContainerStyles, composeFormDropdownStyles, getStyleOption } from './common/composeStyles.js';
5
5
  import { composeContainerClasses, composeFormDropdownClasses } from './common/composeClasses.js';
6
+ import { useGetColorContent } from './hooks/index.js';
6
7
 
7
- const FormDropdown = ({ builderProps, builderAttrs, setting, advanced, children })=>{
8
+ const FormDropdown = ({ builderProps, builderAttrs, setting, advanced, children, styles })=>{
8
9
  const { name, childItem, required } = setting ?? {};
10
+ const { handleOnChange, getTextColor } = useGetColorContent(setting);
9
11
  const composedContainerStyles = createStyle(composeContainerStyles(advanced, setting));
10
- const composedFormDropdownStyles = createStyle(composeFormDropdownStyles(advanced, setting));
12
+ const composedFormDropdownStyles = createStyle({
13
+ ...composeFormDropdownStyles(advanced, setting, styles),
14
+ ...getTextColor
15
+ });
16
+ const composedOptionStyles = createStyle(getStyleOption(setting));
11
17
  const composedContainerClasses = createClass(composeContainerClasses(advanced, builderProps));
12
18
  const composedFormDropdownClasses = createClass(composeFormDropdownClasses(setting));
13
19
  return /*#__PURE__*/ jsxs("div", {
@@ -16,15 +22,29 @@ const FormDropdown = ({ builderProps, builderAttrs, setting, advanced, children
16
22
  className: composedContainerClasses,
17
23
  style: composedContainerStyles,
18
24
  children: [
19
- /*#__PURE__*/ jsx("select", {
25
+ /*#__PURE__*/ jsxs("select", {
20
26
  className: composedFormDropdownClasses,
21
27
  style: composedFormDropdownStyles,
22
28
  required: required,
23
29
  name: name,
24
- children: childItem?.map((item, index)=>/*#__PURE__*/ jsx("option", {
25
- value: item,
26
- children: item
27
- }, index))
30
+ onChange: handleOnChange,
31
+ children: [
32
+ If(!Number(setting?.defaultOption), /*#__PURE__*/ jsx("option", {
33
+ className: "gp-hidden",
34
+ value: "",
35
+ disabled: true,
36
+ selected: true,
37
+ children: setting?.placeholder
38
+ })),
39
+ childItem?.map((item, index)=>/*#__PURE__*/ jsx("option", {
40
+ value: item,
41
+ style: composedOptionStyles,
42
+ ...!!Number(setting?.defaultOption) && {
43
+ selected: item === childItem[Number(setting?.defaultOption) - 1]
44
+ },
45
+ children: item
46
+ }, index))
47
+ ]
28
48
  }),
29
49
  children
30
50
  ]
@@ -1,10 +1,10 @@
1
1
  import { template, RenderIf, isLocalEnv, baseAssetURL } from '@gem-sdk/core';
2
2
  import { getDynamicSourceLocales, getSettingPreloadData } from '../../../helpers.js';
3
3
  import { createStyle, createClass, If } from '@gem-sdk/system';
4
- import { composeContainerStyles, composeFormDropdownStyles } from './common/composeStyles.js';
4
+ import { composeContainerStyles, composeFormDropdownStyles, getAppendTypoStyleFirstTime, getStyleOption } from './common/composeStyles.js';
5
5
  import { composeContainerClasses, composeFormDropdownClasses } from './common/composeClasses.js';
6
6
 
7
- const FormDropdown = ({ builderProps, setting, advanced, pageContext })=>{
7
+ const FormDropdown = ({ builderProps, setting, advanced, pageContext, styles })=>{
8
8
  const { name, childItem, required, translate } = setting ?? {};
9
9
  const childItemVal = childItem?.map((item, index)=>getDynamicSourceLocales({
10
10
  val: item,
@@ -14,7 +14,11 @@ const FormDropdown = ({ builderProps, setting, advanced, pageContext })=>{
14
14
  translate
15
15
  }));
16
16
  const composedContainerStyles = createStyle(composeContainerStyles(advanced, setting));
17
- const composedFormDropdownStyles = createStyle(composeFormDropdownStyles(advanced, setting));
17
+ const composedFormDropdownStyles = createStyle({
18
+ ...composeFormDropdownStyles(advanced, setting, styles),
19
+ ...getAppendTypoStyleFirstTime(setting)
20
+ });
21
+ const composedOptionStyles = createStyle(getStyleOption(setting));
18
22
  const composedContainerClasses = createClass(composeContainerClasses(advanced, builderProps));
19
23
  const composedFormDropdownClasses = createClass(composeFormDropdownClasses(setting));
20
24
  return template`
@@ -29,10 +33,16 @@ const FormDropdown = ({ builderProps, setting, advanced, pageContext })=>{
29
33
  style="${composedFormDropdownStyles}"
30
34
  ${If(required, 'required')}
31
35
  name="${name}"
36
+ gp-data='${JSON.stringify(setting).replaceAll("'", ''')}'
32
37
  >
38
+ ${If(!Number(setting?.defaultOption), `<option class="gp-hidden" value="" disabled selected>
39
+ ${setting?.placeholder}
40
+ </option>`)}
33
41
  ${childItemVal?.map((item)=>template /* liquid */ `
34
42
  <option
35
43
  value="${item}"
44
+ style="${composedOptionStyles}"
45
+ ${If(!!Number(setting?.defaultOption), `selected: ${item === childItemVal[Number(setting?.defaultOption) - 1]}`)}
36
46
  >
37
47
  ${item}
38
48
  </option>`).join('')}
@@ -14,7 +14,7 @@ const composeFormDropdownClasses = (setting)=>{
14
14
  return composeClasses({
15
15
  [appendTypoClass]: !!appendTypoClass,
16
16
  [`${genSizeClass(setting?.size?.type)}`]: !!setting?.size?.type,
17
- 'gp-form-item !gp-outline-none !gp-h-auto focus:!gp-shadow-none hover:!gp-shadow-none': true
17
+ 'gp-form-item !gp-outline-none focus:!gp-shadow-none hover:!gp-shadow-none': true
18
18
  });
19
19
  };
20
20
 
@@ -1,5 +1,5 @@
1
1
  import { filterTruthy } from '../../../helpers/common.js';
2
- import { composeAdvanceStyle, makeStyleResponsive, composeTypographyStyle, makeWidth, composeSize } from '@gem-sdk/core';
2
+ import { composeAdvanceStyle, makeStyleResponsive, makeGlobalSize, composeSize, getStyleBackgroundByDevice, getStyleShadow, getSingleColorVariable, getCustomRadius, composeTypographyStyle } from '@gem-sdk/core';
3
3
 
4
4
  const composeStyles = (styles)=>filterTruthy(styles);
5
5
  const composeContainerStyles = (advanced, setting)=>{
@@ -23,28 +23,86 @@ const composeContainerStyles = (advanced, setting)=>{
23
23
  ...makeStyleResponsive('ta', setting?.align)
24
24
  });
25
25
  };
26
- const composeFormDropdownStyles = (advanced, setting)=>{
27
- const { size } = setting ?? {};
26
+ const composeFormDropdownStyles = (advanced, setting, styles)=>{
28
27
  const { border, rounded, hasBoxShadow, boxShadow } = advanced ?? {};
29
- const { typography, width } = setting ?? {};
30
- const appendTypoStyle = composeTypographyStyle(setting?.typo, typography);
28
+ const { background, size } = setting ?? {};
29
+ const { globalSize, borderActive, boxShadowActive, roundedActive, backgroundColorV2Active } = styles ?? {};
31
30
  const inputStyle = composeAdvanceStyle({
32
31
  border,
33
32
  rounded,
34
33
  hasBoxShadow,
35
34
  boxShadow
36
35
  });
37
- const inputWidth = makeStyleResponsive('w', makeWidth(width));
36
+ const composeGlobalSize = makeGlobalSize(globalSize);
38
37
  return composeStyles({
39
- ...inputWidth,
38
+ ...composeGlobalSize?.width?.['--w'] ? composeGlobalSize.width : {
39
+ '--w': '100%'
40
+ },
41
+ ...composeGlobalSize?.height?.['--h'] ? composeGlobalSize.height : {
42
+ '--h': 'auto'
43
+ },
44
+ ...composeGlobalSize.padding,
40
45
  ...inputStyle,
41
46
  ...!size?.type ? composeSize(size?.custom) : {},
42
- ...appendTypoStyle,
43
47
  appearance: 'none',
44
- 'background-image': 'url(https://cdn.shopify.com/s/files/1/1827/4239/t/1/assets/ico-select.svg?v=155563818344741998551488860031)',
48
+ ...getStyleBackgroundByDevice(background),
49
+ ...generateStylesTarget({
50
+ state: 'focus',
51
+ borderStyle: borderActive?.active,
52
+ background: backgroundColorV2Active?.active,
53
+ radius: roundedActive?.active
54
+ }),
55
+ ...getStyleShadow({
56
+ value: boxShadowActive?.active,
57
+ state: 'focus',
58
+ styleAppliedFor: 'box-shadow',
59
+ isEnableShadow: true
60
+ }),
61
+ '--bgi': getBgImageUrl(background?.desktop?.color),
45
62
  'background-repeat': 'no-repeat',
46
- 'background-position': 'right 10px center'
63
+ 'background-position': 'right 10px center, 0 0',
64
+ '--focus-bgi': getBgImageUrl(backgroundColorV2Active?.active)
65
+ });
66
+ };
67
+ const getBgImageUrl = (color)=>{
68
+ const iconDropDown = 'url(https://cdn.shopify.com/s/files/1/1827/4239/t/1/assets/ico-select.svg?v=155563818344741998551488860031)';
69
+ return `${iconDropDown} ${color?.includes('linear-gradient') ? ',' + color : ''}`;
70
+ };
71
+ const generateStylesTarget = ({ state, borderStyle, background, radius })=>{
72
+ const { border, width, color } = borderStyle ?? {};
73
+ const getState = {
74
+ hover: 'hvr',
75
+ focus: 'focus'
76
+ };
77
+ const currentState = getState[state];
78
+ return {
79
+ ...width && {
80
+ [`--${currentState}-bw`]: `${width}`
81
+ },
82
+ ...border && {
83
+ [`--${currentState}-b`]: `${border} ${getSingleColorVariable(color)}`
84
+ },
85
+ ...background && {
86
+ [`--${currentState}-bgc`]: `${getSingleColorVariable(background)}`
87
+ },
88
+ ...getCustomRadius(state, radius)
89
+ };
90
+ };
91
+ const getAppendTypoStyleFirstTime = (setting)=>{
92
+ const appendTypoStyle = composeTypographyStyle(setting?.typo, setting?.typography);
93
+ return composeStyles({
94
+ ...appendTypoStyle,
95
+ ...!Number(setting?.defaultOption) && {
96
+ '--c': setting?.placeholderColor
97
+ }
98
+ });
99
+ };
100
+ const getStyleOption = (setting)=>{
101
+ const { typography, typo } = setting ?? {};
102
+ const appendTypoStyle = composeTypographyStyle(typo, typography);
103
+ return composeStyles({
104
+ ...appendTypoStyle
47
105
  });
48
106
  };
49
107
 
50
- export { composeContainerStyles, composeFormDropdownStyles };
108
+ export { composeContainerStyles, composeFormDropdownStyles, generateStylesTarget, getAppendTypoStyleFirstTime, getStyleOption };
@@ -0,0 +1,24 @@
1
+ import { useState } from 'react';
2
+ import { composeTypographyStyle } from '@gem-sdk/core';
3
+
4
+ const useGetColorContent = (setting)=>{
5
+ const [showPlaceholder, setShowPlaceholder] = useState(true);
6
+ const { typography, placeholderColor } = setting ?? {};
7
+ const appendTypoStyle = composeTypographyStyle(setting?.typo, typography);
8
+ const handleOnChange = ()=>{
9
+ if (showPlaceholder) {
10
+ setShowPlaceholder(false);
11
+ }
12
+ };
13
+ return {
14
+ handleOnChange,
15
+ getTextColor: {
16
+ ...appendTypoStyle,
17
+ ...showPlaceholder && {
18
+ '--c': placeholderColor
19
+ }
20
+ }
21
+ };
22
+ };
23
+
24
+ export { useGetColorContent };
@@ -2,6 +2,24 @@ const FormDropdownSettings = [
2
2
  {
3
3
  id: 'setting',
4
4
  controls: [
5
+ {
6
+ id: 'placeholder',
7
+ type: 'input',
8
+ label: 'Placeholder',
9
+ default: 'Choose your option'
10
+ },
11
+ {
12
+ id: 'placeholderColor',
13
+ type: 'color-picker-v2',
14
+ label: 'Color',
15
+ default: '#A3A3A3'
16
+ },
17
+ {
18
+ id: 'defaultOption',
19
+ type: 'input',
20
+ label: 'Default option',
21
+ default: '1'
22
+ },
5
23
  {
6
24
  id: 'name',
7
25
  type: 'input',
@@ -16,8 +34,7 @@ const FormDropdownSettings = [
16
34
  'Option 1',
17
35
  'Option 2',
18
36
  'Option 3'
19
- ],
20
- expandItem: true
37
+ ]
21
38
  },
22
39
  {
23
40
  id: 'translate',
@@ -28,7 +45,7 @@ const FormDropdownSettings = [
28
45
  id: 'required',
29
46
  type: 'toggle',
30
47
  label: 'Placeholder',
31
- default: true
48
+ default: false
32
49
  },
33
50
  {
34
51
  id: 'typo',
@@ -77,22 +94,6 @@ const FormDropdownSettings = [
77
94
  }
78
95
  }
79
96
  },
80
- {
81
- id: 'width',
82
- type: 'input:unit',
83
- label: 'Width',
84
- min: 0,
85
- units: [
86
- 'px',
87
- '%'
88
- ],
89
- hide: true,
90
- devices: {
91
- desktop: {
92
- default: '358px'
93
- }
94
- }
95
- },
96
97
  {
97
98
  id: 'align',
98
99
  label: 'Alignment',
@@ -130,23 +131,12 @@ const FormDropdownSettings = [
130
131
  id: 'background',
131
132
  type: 'background-media',
132
133
  ignoreReRender: true,
134
+ hideImage: true,
133
135
  devices: {
134
136
  desktop: {
135
137
  default: {
136
138
  type: 'color',
137
- color: 'transparent',
138
- image: {
139
- src: '',
140
- width: 0,
141
- height: 0
142
- },
143
- size: 'cover',
144
- position: {
145
- x: 50,
146
- y: 50
147
- },
148
- repeat: 'no-repeat',
149
- attachment: 'scroll'
139
+ color: 'transparent'
150
140
  }
151
141
  }
152
142
  },
@@ -154,20 +144,7 @@ const FormDropdownSettings = [
154
144
  desktop: {
155
145
  default: {
156
146
  type: 'color',
157
- color: '#DDDDDD',
158
- image: {
159
- src: 'https://ucarecdn.com/5e27d43d-eb1e-4e71-b7e1-4158f3071bb6/-/format/auto/',
160
- width: 1200,
161
- height: 480
162
- },
163
- size: 'cover',
164
- position: {
165
- x: 50,
166
- y: 50
167
- },
168
- repeat: 'no-repeat',
169
- attachment: 'scroll',
170
- preload: false
147
+ color: '#DDDDDD'
171
148
  }
172
149
  }
173
150
  }
@@ -183,14 +160,14 @@ const FormDropdownSettings = [
183
160
  devices: {
184
161
  desktop: {
185
162
  default: {
186
- width: 'Auto',
163
+ width: '100%',
187
164
  height: 'Auto',
188
165
  padding: {
189
166
  type: 'medium',
190
167
  top: '12px',
191
168
  bottom: '12px',
192
- left: '24px',
193
- right: '24px'
169
+ left: '12px',
170
+ right: '12px'
194
171
  }
195
172
  }
196
173
  }
@@ -272,6 +249,52 @@ const FormDropdownSettings = [
272
249
  }
273
250
  }
274
251
  }
252
+ },
253
+ {
254
+ id: 'backgroundColorV2Active',
255
+ type: 'color-picker-v2',
256
+ enableGradient: true
257
+ },
258
+ {
259
+ id: 'borderActive',
260
+ type: 'border',
261
+ emptyOnClear: true,
262
+ state: {
263
+ active: true
264
+ }
265
+ },
266
+ {
267
+ id: 'roundedActive',
268
+ type: 'radius-preset',
269
+ default: {
270
+ active: {
271
+ radiusType: 'small'
272
+ }
273
+ },
274
+ state: {
275
+ active: true
276
+ }
277
+ },
278
+ {
279
+ id: 'boxShadowActive',
280
+ type: 'shadow-v2',
281
+ label: 'Button Shadow',
282
+ hideOnState: {
283
+ active: true
284
+ },
285
+ default: {
286
+ active: {
287
+ type: 'shadow-1',
288
+ distance: '4px',
289
+ blur: '12px',
290
+ spread: '0px',
291
+ color: 'rgba(0, 0, 0, 0.20)',
292
+ angle: 90
293
+ }
294
+ },
295
+ state: {
296
+ active: true
297
+ }
275
298
  }
276
299
  ]
277
300
  }
@@ -4,6 +4,33 @@ const SettingUIV2 = [
4
4
  en: 'Item management'
5
5
  },
6
6
  controls: [
7
+ {
8
+ type: 'combo',
9
+ label: {
10
+ en: 'Placeholder'
11
+ },
12
+ iconName: 'polaris-text-block',
13
+ getValueFromSettingID: 'placeholder',
14
+ isHideClear: true,
15
+ controls: [
16
+ {
17
+ label: {
18
+ en: 'Content'
19
+ },
20
+ setting: {
21
+ id: 'placeholder'
22
+ }
23
+ },
24
+ {
25
+ setting: {
26
+ id: 'placeholderColor'
27
+ },
28
+ label: {
29
+ en: 'Color'
30
+ }
31
+ }
32
+ ]
33
+ },
7
34
  {
8
35
  label: {
9
36
  en: 'Options'
@@ -11,6 +38,14 @@ const SettingUIV2 = [
11
38
  setting: {
12
39
  id: 'childItem'
13
40
  }
41
+ },
42
+ {
43
+ label: {
44
+ en: 'Default option'
45
+ },
46
+ setting: {
47
+ id: 'defaultOption'
48
+ }
14
49
  }
15
50
  ]
16
51
  },
@@ -97,7 +132,7 @@ const SettingUIV2 = [
97
132
  ],
98
133
  hideUnit: false,
99
134
  linkWithSetting: {
100
- name: 'globalSizeBtn',
135
+ name: 'globalSize',
101
136
  field: 'height'
102
137
  },
103
138
  displayOptions: [
@@ -168,48 +203,114 @@ const SettingUIV2 = [
168
203
  label: {
169
204
  en: 'Border'
170
205
  },
171
- controlConfig: {
206
+ setting: {
172
207
  id: 'border',
173
- type: 'border-v2',
174
- linkWithSetting: {
175
- name: 'wrapperBorder'
176
- },
177
- compoDefaultValue: {
178
- desktop: {
179
- default: {
180
- normal: {
181
- border: 'solid',
182
- color: '#121212',
183
- width: '1px',
184
- borderWidth: '1px'
185
- }
208
+ state: 'normal'
209
+ }
210
+ },
211
+ {
212
+ label: {
213
+ en: 'Corner'
214
+ },
215
+ setting: {
216
+ id: 'rounded',
217
+ state: 'normal'
218
+ }
219
+ },
220
+ {
221
+ label: {
222
+ en: 'Shadow'
223
+ },
224
+ setting: {
225
+ id: 'boxShadow',
226
+ state: 'normal'
227
+ },
228
+ options: {
229
+ updateFields: [
230
+ {
231
+ field: 'enable',
232
+ settingId: 'hasBoxShadow',
233
+ state: 'normal'
234
+ }
235
+ ]
236
+ },
237
+ controlChangeTrigger: {
238
+ settings: [
239
+ {
240
+ condition: `boxShadow.normal.enable === true`,
241
+ source: [
242
+ 'boxShadow',
243
+ 'hasBoxShadow'
244
+ ],
245
+ action: {
246
+ controlId: 'hasBoxShadow',
247
+ groupType: 'advanced',
248
+ controlType: 'advanced',
249
+ state: 'normal',
250
+ newValue: true
251
+ }
252
+ },
253
+ {
254
+ condition: `boxShadow.normal.enable === false`,
255
+ source: [
256
+ 'boxShadow',
257
+ 'hasBoxShadow'
258
+ ],
259
+ action: {
260
+ controlId: 'hasBoxShadow',
261
+ groupType: 'advanced',
262
+ controlType: 'advanced',
263
+ state: 'normal',
264
+ newValue: false
186
265
  }
187
266
  }
267
+ ],
268
+ options: {
269
+ noRecordHistory: true
188
270
  }
189
271
  }
272
+ }
273
+ ]
274
+ },
275
+ {
276
+ label: {
277
+ en: 'Active state'
278
+ },
279
+ controls: [
280
+ {
281
+ label: {
282
+ en: 'Background'
283
+ },
284
+ setting: {
285
+ id: 'backgroundColorV2Active',
286
+ state: 'active'
287
+ }
288
+ },
289
+ {
290
+ label: {
291
+ en: 'Border'
292
+ },
293
+ setting: {
294
+ id: 'borderActive',
295
+ state: 'active'
296
+ }
190
297
  },
191
298
  {
192
299
  label: {
193
300
  en: 'Corner'
194
301
  },
195
- controlConfig: {
196
- id: 'corner',
197
- type: 'corner-v2',
198
- linkWithSetting: {
199
- name: 'borderRadius'
200
- }
302
+ setting: {
303
+ id: 'roundedActive',
304
+ state: 'active'
201
305
  }
202
306
  },
203
307
  {
204
308
  label: {
205
309
  en: 'Shadow'
206
310
  },
207
- controlConfig: {
208
- id: 'shadow',
209
- type: 'shadow-v2',
210
- linkWithSetting: {
211
- name: 'shadow'
212
- }
311
+ setting: {
312
+ id: 'boxShadowActive',
313
+ state: 'active'
213
314
  }
214
315
  }
215
316
  ]
@@ -233,6 +334,9 @@ const SettingUIV2 = [
233
334
  },
234
335
  setting: {
235
336
  id: 'name'
337
+ },
338
+ help: {
339
+ content: 'Identify the information submitted via this element.'
236
340
  }
237
341
  }
238
342
  ]
@@ -243,7 +347,7 @@ const SettingUIV2 = [
243
347
  label: {
244
348
  en: 'Align'
245
349
  },
246
- conditionEnable: '!(parseInt(width) >= 100 && width?.includes("%"))',
350
+ conditionEnable: '!(parseInt(globalSize.width) >= 100 && globalSize.width?.includes("%"))',
247
351
  setting: {
248
352
  id: 'align'
249
353
  },