@ordergroove/offers 2.28.9 → 2.28.11-alpha-PR-703-17.87

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.
package/examples/index.js CHANGED
@@ -63,162 +63,158 @@ const textCopy = {
63
63
  defaultFrequencyCopy: '(Recommended)'
64
64
  };
65
65
 
66
- const exampleTemplates = [
67
- [
68
- 'Offers example',
69
- {
70
- name: 'empty',
71
- selector: 'og-offer:not([location])',
72
- id: '1'
73
- },
74
- {
75
- name: 'built-in',
76
- selector: 'og-offer[location="initial"]',
77
- id: '2',
78
- config: {
79
- settings: {
80
- ...settings,
81
- offerType: 'radio'
82
- },
83
- textCopy: { ...textCopy }
84
- }
85
- },
86
- {
87
- name: 'checkbox',
88
- selector: 'og-offer[location="initial-checkbox"]',
89
- id: '3',
90
- config: {
91
- settings: {
92
- ...settings,
93
- offerType: 'toggle'
94
- },
95
- textCopy: {
96
- ...textCopy
97
- }
98
- }
99
- },
100
- {
101
- name: 'select',
102
- selector: 'og-offer[location="initial-select"]',
103
- id: '4',
104
- config: {
105
- settings: {
106
- ...settings,
107
- offerType: 'select'
108
- },
109
- textCopy: { ...textCopy }
110
- }
111
- },
112
- {
113
- name: 'cart',
114
- selector: 'og-offer[location="cart"]',
115
- id: '5',
116
- defaultPreviewMode: 'subscribed',
117
- config: {
118
- settings: {
119
- ...settings,
120
- offerType: 'cart'
121
- },
122
- textCopy: { ...textCopy }
66
+ const offersExamples = [
67
+ {
68
+ name: 'empty',
69
+ selector: 'og-offer:not([location])'
70
+ },
71
+ {
72
+ name: 'built-in',
73
+ selector: 'og-offer[location="initial"]',
74
+ config: {
75
+ settings: {
76
+ ...settings,
77
+ offerType: 'radio'
78
+ },
79
+ textCopy: { ...textCopy }
80
+ }
81
+ },
82
+ {
83
+ name: 'checkbox',
84
+ selector: 'og-offer[location="initial-checkbox"]',
85
+ config: {
86
+ settings: {
87
+ ...settings,
88
+ offerType: 'toggle'
89
+ },
90
+ textCopy: {
91
+ ...textCopy
123
92
  }
124
- },
125
- {
126
- name: 'side-by-side',
127
- selector: 'og-offer[location="side-by-side"]',
128
- id: '6',
129
- config: {
130
- settings: {
131
- ...settings,
132
- offerType: 'side-by-side'
133
- },
134
- textCopy: { ...textCopy },
135
- styles: {
136
- primaryColor: 'navy',
137
- defaultColor: 'pink'
138
- }
93
+ }
94
+ },
95
+ {
96
+ name: 'select',
97
+ selector: 'og-offer[location="initial-select"]',
98
+ config: {
99
+ settings: {
100
+ ...settings,
101
+ offerType: 'select'
102
+ },
103
+ textCopy: { ...textCopy }
104
+ }
105
+ },
106
+ {
107
+ name: 'cart',
108
+ selector: 'og-offer[location="cart"]',
109
+ defaultPreviewMode: 'subscribed',
110
+ config: {
111
+ settings: {
112
+ ...settings,
113
+ offerType: 'cart'
114
+ },
115
+ textCopy: { ...textCopy }
116
+ }
117
+ },
118
+ {
119
+ name: 'side-by-side',
120
+ selector: 'og-offer[location="side-by-side"]',
121
+ config: {
122
+ settings: {
123
+ ...settings,
124
+ offerType: 'side-by-side'
125
+ },
126
+ textCopy: { ...textCopy },
127
+ styles: {
128
+ primaryColor: 'navy',
129
+ defaultColor: 'pink'
139
130
  }
140
- },
141
- {
142
- name: 'read-only',
143
- selector: 'og-offer[location="read-only"]',
144
- id: '7',
145
- defaultPreviewMode: 'subscribed',
146
- config: {
147
- settings: {
148
- ...settings,
149
- offerType: 'read-only'
150
- },
151
- textCopy: { ...textCopy },
152
- styles: {
153
- primaryColor: 'navy',
154
- defaultColor: 'pink'
155
- }
131
+ }
132
+ },
133
+ {
134
+ name: 'read-only',
135
+ selector: 'og-offer[location="read-only"]',
136
+ defaultPreviewMode: 'subscribed',
137
+ config: {
138
+ settings: {
139
+ ...settings,
140
+ offerType: 'read-only'
141
+ },
142
+ textCopy: { ...textCopy },
143
+ styles: {
144
+ primaryColor: 'navy',
145
+ defaultColor: 'pink'
156
146
  }
157
- },
158
- {
159
- name: 'buttons',
160
- selector: 'og-offer[location="buttons"]',
161
- id: '8',
162
- config: {
163
- settings: {
164
- ...settings,
165
- offerType: 'buttons'
166
- },
167
- textCopy: { ...textCopy },
168
- styles: {
169
- primaryColor: 'navy',
170
- defaultColor: 'pink'
171
- }
147
+ }
148
+ },
149
+ {
150
+ name: 'buttons',
151
+ selector: 'og-offer[location="buttons"]',
152
+ config: {
153
+ settings: {
154
+ ...settings,
155
+ offerType: 'buttons'
156
+ },
157
+ textCopy: { ...textCopy },
158
+ styles: {
159
+ primaryColor: 'navy',
160
+ defaultColor: 'pink'
172
161
  }
173
- },
174
-
175
- {
176
- name: 'first-test',
177
- selector: 'og-offer[location="first-test"]',
178
- id: '9',
179
- config: {
180
- settings: {
181
- ...settings,
182
- offerType: 'toggle'
183
- },
184
- textCopy: {
185
- ...textCopy,
186
- offerOptOutLabel: '1st offerOptOutLabel'
187
- }
162
+ }
163
+ },
164
+ {
165
+ name: 'Prepaid',
166
+ selector: 'og-offer[location="initial"]',
167
+ config: {
168
+ settings: {
169
+ ...settings,
170
+ offerType: 'prepaid-enabled-radio'
171
+ },
172
+ textCopy: { ...textCopy }
173
+ }
174
+ },
175
+ {
176
+ name: 'first-test',
177
+ selector: 'og-offer[location="first-test"]',
178
+ config: {
179
+ settings: {
180
+ ...settings,
181
+ offerType: 'toggle'
182
+ },
183
+ textCopy: {
184
+ ...textCopy,
185
+ offerOptOutLabel: '1st offerOptOutLabel'
188
186
  }
189
- },
190
- {
191
- name: 'second-test no tooltip',
192
- selector: 'og-offer[location="second-test"]',
193
- id: '10',
194
- config: {
195
- settings: {
196
- ...settings,
197
- offerType: 'radio'
198
- },
199
- textCopy: {
200
- ...textCopy,
201
- showTooltip: false,
202
- offerOptOutLabel: '2st offerOptOutLabel'
203
- }
187
+ }
188
+ },
189
+ {
190
+ name: 'second-test no tooltip',
191
+ selector: 'og-offer[location="second-test"]',
192
+ config: {
193
+ settings: {
194
+ ...settings,
195
+ offerType: 'radio'
196
+ },
197
+ textCopy: {
198
+ ...textCopy,
199
+ showTooltip: false,
200
+ offerOptOutLabel: '2st offerOptOutLabel'
204
201
  }
205
- },
206
- {
207
- name: 'Select mode',
208
- selector: 'og-offer[location="select1"]',
209
- id: '11',
210
- markup: `
202
+ }
203
+ },
204
+ {
205
+ name: 'Select mode',
206
+ selector: 'og-offer[location="select1"]',
207
+ markup: `
211
208
  <og-optin-select>
212
209
  <option value="optedOut">Buy one time</option>
213
210
  <option value="2w" selected>2 weeks (recomended)</option>
214
211
  <option value="1m">1 month </option>
215
212
  </og-optin-select>`
216
- },
217
- {
218
- name: 'Custom markup',
219
- selector: 'og-offer[location="custom1"]',
220
- id: '12',
221
- markup: `
213
+ },
214
+ {
215
+ name: 'Custom markup',
216
+ selector: 'og-offer[location="custom1"]',
217
+ markup: `
222
218
  <og-when test="regularEligible">
223
219
  <p>
224
220
  <og-optout-button>Buy one time</og-optout-button>
@@ -266,13 +262,12 @@ Add item to order on
266
262
  <span slot="cancel">cancel</span>
267
263
  </og-upsell-modal>
268
264
  </og-when>`
269
- },
270
- {
271
- name: 'Upsell modal - radio',
272
- defaultPreviewMode: 'upsell',
273
- selector: 'og-offer[location="upsell-radio"]',
274
- id: '13',
275
- markup: `
265
+ },
266
+ {
267
+ name: 'Upsell modal - radio',
268
+ defaultPreviewMode: 'upsell',
269
+ selector: 'og-offer[location="upsell-radio"]',
270
+ markup: `
276
271
  <og-when test="upsellEligible">
277
272
  <og-upsell-button target="#upsell-radio">
278
273
  <a href="#">Add item to next order via radio</a>
@@ -291,13 +286,12 @@ Add item to order on
291
286
  </p>
292
287
  </og-upsell-modal>
293
288
  </og-when>`
294
- },
295
- {
296
- name: 'Upsell modal - select',
297
- defaultPreviewMode: 'upsell',
298
- selector: 'og-offer[location="upsell-select"]',
299
- id: '14',
300
- markup: `
289
+ },
290
+ {
291
+ name: 'Upsell modal - select',
292
+ defaultPreviewMode: 'upsell',
293
+ selector: 'og-offer[location="upsell-select"]',
294
+ markup: `
301
295
  <og-when test="upsellEligible">
302
296
  <og-upsell-button target="#upsell-select">
303
297
  <a href="#">Add item to next order via select</a>
@@ -306,13 +300,12 @@ Add item to order on
306
300
  <og-optin-select></og-optin-select>
307
301
  </og-upsell-modal>
308
302
  </og-when>`
309
- },
310
- {
311
- name: 'Upsell modal - toggle',
312
- defaultPreviewMode: 'upsell',
313
- selector: 'og-offer[location="upsell-toggle"]',
314
- id: '15',
315
- markup: `
303
+ },
304
+ {
305
+ name: 'Upsell modal - toggle',
306
+ defaultPreviewMode: 'upsell',
307
+ selector: 'og-offer[location="upsell-toggle"]',
308
+ markup: `
316
309
  <og-when test="upsellEligible">
317
310
  <og-upsell-button target="#upsell-toggle">
318
311
  <a href="#">Add item to next order via toggle</a>
@@ -325,13 +318,12 @@ Add item to order on
325
318
  <span slot="cancel">Nope</span>
326
319
  </og-upsell-modal>
327
320
  </og-when>
328
- `
329
- },
330
- {
331
- name: 'Product-specific default frequencies',
332
- selector: 'og-offer[location="psdf"]',
333
- id: '16',
334
- markup: `
321
+ `
322
+ },
323
+ {
324
+ name: 'Product-specific default frequencies',
325
+ selector: 'og-offer[location="psdf"]',
326
+ markup: `
335
327
  <og-when test="regularEligible">
336
328
  <og-select-frequency default-text=" Most common!">
337
329
  <option value="1w">1 week</option>
@@ -339,56 +331,60 @@ Add item to order on
339
331
  <option value="3w">3 weeks</option>
340
332
  </og-select-frequency>
341
333
  </og-when>
342
- `
343
- }
344
- ],
345
- [
346
- 'Individual components',
347
- {
348
- name: 'og-optin-button',
349
- selector: 'og-offer[location=og-optin-button]',
350
- id: '17',
351
- markup: `
334
+ `
335
+ }
336
+ ];
337
+
338
+ const componentExamples = [
339
+ {
340
+ name: 'og-optin-button',
341
+ selector: 'og-offer[location=og-optin-button]',
342
+ markup: `
352
343
  <og-optin-button>
353
344
  I want to subscribe to this product
354
345
  </og-optin-button>
355
- `
356
- },
357
- {
358
- name: 'Frequency Status',
359
- selector: 'og-offer[location="frequency"]',
360
- id: '18',
361
- markup: `
346
+ `
347
+ },
348
+ {
349
+ name: 'Frequency Status',
350
+ selector: 'og-offer[location="frequency"]',
351
+ markup: `
362
352
  <og-frequency-status>
363
353
  <span slot="not-subscribed">you are not subscribed </span>
364
354
  </og-frequency-status>`
365
- },
366
- {
367
- name: 'Tooltip',
368
- selector: 'og-offer[location="tooltip-placement"]',
369
- id: '19',
370
- markup: [
371
- ['top-left', 'top', 'top-right'],
372
- ['left', '', 'right'],
373
- ['bottom-left', 'bottom', 'bottom-right']
374
- ]
375
- .map(options =>
376
- options
377
- .map(
378
- it =>
379
- `<span class="tooltip-example">${
380
- it
381
- ? `<og-tooltip placement="${it}" style="width:100%">
382
- <div slot="trigger">${it}</div>
383
- <div slot="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
384
- </og-tooltip>`
385
- : ' &nbsp; '
386
- }</span>`
387
- )
388
- .join('\n')
389
- )
390
- .join('<br>\n')
391
- }
355
+ },
356
+ {
357
+ name: 'Tooltip',
358
+ selector: 'og-offer[location="tooltip-placement"]',
359
+ markup: [
360
+ ['top-left', 'top', 'top-right'],
361
+ ['left', '', 'right'],
362
+ ['bottom-left', 'bottom', 'bottom-right']
363
+ ]
364
+ .map(options =>
365
+ options
366
+ .map(
367
+ it =>
368
+ `<span class="tooltip-example">${
369
+ it
370
+ ? `<og-tooltip placement="${it}" style="width:100%">
371
+ <div slot="trigger">${it}</div>
372
+ <div slot="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
373
+ </og-tooltip>`
374
+ : ' &nbsp; '
375
+ }</span>`
376
+ )
377
+ .join('\n')
378
+ )
379
+ .join('<br>\n')
380
+ }
381
+ ];
382
+
383
+ const exampleTemplates = [
384
+ ['Offers example', ...offersExamples.map((x, idx) => ({ ...x, id: idx.toString() }))],
385
+ [
386
+ 'Individual components',
387
+ ...componentExamples.map((x, idx) => ({ ...x, id: (idx + offersExamples.length).toString() }))
392
388
  ]
393
389
  ];
394
390
  function updateTemplate(target) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordergroove/offers",
3
- "version": "2.28.9",
3
+ "version": "2.28.11-alpha-PR-703-17.87+e0434fb5",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -47,5 +47,5 @@
47
47
  "devDependencies": {
48
48
  "@ordergroove/offers-templates": "^0.4.20"
49
49
  },
50
- "gitHead": "e6ea1ceb9b29e0b63acba4380870c222997baf2b"
50
+ "gitHead": "e0434fb512e57c225bc1a957163e8a57bbda1418"
51
51
  }
@@ -51,11 +51,11 @@ export class Modal extends LitElement {
51
51
  }
52
52
 
53
53
  .og-modal__container {
54
- background-color: #fff;
55
- padding: 30px;
54
+ background-color: var(--og-modal-background-color, #fff);
55
+ padding: var(--og-modal-padding, 30px);
56
56
  max-width: 500px;
57
57
  max-height: 100vh;
58
- border-radius: 4px;
58
+ border-radius: var(--og-modal-border-radius, 4px);
59
59
  box-sizing: border-box;
60
60
  }
61
61
 
@@ -0,0 +1,100 @@
1
+ import { LitElement, html, css } from 'lit-element';
2
+ import { connect } from '../core/connect';
3
+ import { makeProductPrepaidShipmentsSelector } from '../core/selectors';
4
+ import { productChangePrepaidShipments } from '../core/actions';
5
+ import { withProduct } from '../core/resolveProperties';
6
+
7
+ export class PrepaidToggle extends withProduct(LitElement) {
8
+ constructor() {
9
+ super();
10
+ this._selectedOption = null;
11
+ }
12
+
13
+ static get properties() {
14
+ return {
15
+ shipments: { type: Number }
16
+ };
17
+ }
18
+
19
+ // copied from SelectFrequency
20
+ static get styles() {
21
+ return css`
22
+ og-select {
23
+ display: inline-block;
24
+ cursor: pointer;
25
+ background-color: #fff;
26
+ border: var(--og-select-border, 1px solid #aaa);
27
+ border-width: var(--og-select-border-width, 1px);
28
+ box-shadow: 0 1px 0 1px rgba(0, 0, 0, 0.04);
29
+ z-index: 1;
30
+ }
31
+
32
+ input {
33
+ width: 1.2em;
34
+ height: 1.2em;
35
+ accent-color: black;
36
+ border-radius: 4px;
37
+ }
38
+ `;
39
+ }
40
+
41
+ get childOptions() {
42
+ const options = Array.from(this.querySelectorAll('option'));
43
+ return options.map(option => ({
44
+ value: +option.value,
45
+ text: option.text || `${option.value} shipments`
46
+ }));
47
+ }
48
+
49
+ get checked() {
50
+ return this.shipments > 1;
51
+ }
52
+
53
+ handleChange(e) {
54
+ if (e.target.checked) {
55
+ const selectedShipments = this._selectedOption || +this.querySelector('option').value;
56
+ this.productChangePrepaidShipments(this.product, selectedShipments, this.offer);
57
+ } else {
58
+ this.productChangePrepaidShipments(this.product, null, this.offer);
59
+ }
60
+ }
61
+
62
+ handleSelect({ target: { value } }) {
63
+ const valueAsNumber = +value;
64
+ // keep track of selected option so that checking the checkbox opts them into the currently selected value in the dropdown
65
+ // this only happens if they opt-out then opt back in.
66
+ this._selectedOption = valueAsNumber;
67
+ this.productChangePrepaidShipments(this.product, valueAsNumber, this.offer);
68
+ }
69
+
70
+ render() {
71
+ return html`
72
+ <div>
73
+ <input id="cbx" type="checkbox" .checked=${this.checked} @change=${this.handleChange} />
74
+ <label for="cbx">
75
+ <slot name="label">Prepay for</slot>
76
+ ${this.childOptions.length > 1
77
+ ? html`
78
+ <og-select
79
+ .options=${this.childOptions}
80
+ .selected=${this._selectedOption || this.shipments}
81
+ .onChange="${e => this.handleSelect(e)}"
82
+ ></og-select>
83
+ `
84
+ : html`
85
+ <span>${this.childOptions[0].text}</span>
86
+ `}
87
+ <slot name="append"></slot>
88
+ </label>
89
+ </div>
90
+ `;
91
+ }
92
+ }
93
+
94
+ const mapStateToProps = (state, ownProps) => ({
95
+ shipments: makeProductPrepaidShipmentsSelector(ownProps.product)(state)
96
+ });
97
+
98
+ const ConnectedPrepaidToggle = connect(mapStateToProps, { productChangePrepaidShipments })(PrepaidToggle);
99
+
100
+ export { ConnectedPrepaidToggle };
@@ -70,7 +70,7 @@ export class Select extends LitElement {
70
70
  <select @change="${handleOnChange}">
71
71
  ${this.options.map(
72
72
  option => html`
73
- <option value="${option.value}" ?selected=${option.value === this.selected}>${option.text}</option>
73
+ <option value="${option.value}" .selected=${option.value === this.selected}>${option.text}</option>
74
74
  `
75
75
  )}
76
76
  </select>