ui.shipaid.com 0.3.47 → 0.3.49
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/README.md +200 -200
- package/dist/nl-CI8lUOMC.js +41 -0
- package/dist/widget.es.js +9 -5
- package/dist/widget.iife.js +46 -43
- package/dist/widget.umd.js +45 -42
- package/dist-types/common/shopify/index.d.ts +6 -6
- package/dist-types/common/shopify/protection.d.ts +7 -7
- package/dist-types/common/shopify/types/ShopifyCart.d.ts +29 -29
- package/dist-types/common/shopify/types/ShopifyProduct.d.ts +7 -7
- package/dist-types/common/types/ShipAid.d.ts +81 -81
- package/dist-types/widget/src/assets/confirmation-styles.d.ts +2 -2
- package/dist-types/widget/src/assets/icons.d.ts +8 -8
- package/dist-types/widget/src/assets/learn-more-styles.d.ts +2 -2
- package/dist-types/widget/src/assets/styles.d.ts +2 -2
- package/dist-types/widget/src/components/confirmation-popup.d.ts +9 -9
- package/dist-types/widget/src/components/learn-more-popup.d.ts +8 -8
- package/dist-types/widget/src/shipaid-widget.d.ts +137 -137
- package/dist-types/widget/src/utils/fetch_interceptor.d.ts +3 -3
- package/dist-types/widget/src/utils/fetch_interceptor.test.d.ts +1 -1
- package/dist-types/widget/types/shipaid.d.ts +10 -10
- package/dist-types/widget/types/shopify.d.ts +29 -29
- package/dist-types/widget/types/widget.d.ts +13 -13
- package/package.json +48 -48
package/README.md
CHANGED
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
# ShipAid Shopify Widget
|
|
2
|
-
|
|
3
|
-
This is the repository for the ShipAid Shopify (and possibly others in future) widget. It uses the [Lit](https://lit.dev/) web components library, so it is recommended to become familiar with it before contributing to this repository.
|
|
4
|
-
|
|
5
|
-
Using Lit provides a framework that allows us to build a reactive UI, using JSX-like syntax - no need to use JQuery etc. And it can easily be installed in a page by using the custom web component name:
|
|
6
|
-
```html
|
|
7
|
-
<shipaid-widget>Fallback Content</shipaid-widget>
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
## Overview
|
|
11
|
-
|
|
12
|
-
This widget provides an interface where a user can choose to add or remove ShipAid protection - this is actually a product in their store that can be added to cart. When the component is loaded, we immediately run a request to fetch the ShipAid protection product details from our API, as well as the customers current cart from the [Shopify AJAX API](https://shopify.dev/api/ajax/reference/cart).
|
|
13
|
-
Once we have this data, we can check whether the customer currently has the ShipAid product in their cart, and show either the add or remove product buttons based on this.
|
|
14
|
-
|
|
15
|
-
We also emit various [custom events](https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events#adding_custom_data_%E2%80%93_customevent) when we add or remove the ShipAid product from the cart, so other developers can listen to these events, and update AJAX carts.
|
|
16
|
-
|
|
17
|
-
### Installation
|
|
18
|
-
|
|
19
|
-
Add the script tag to the theme - if the theme has an ajax cart, you'll likely want to add this to the `theme.liquid` file, otherwise if the store has only a cart page (`/cart`), then you can add it to just that page, to save it being unecessarily loaded when it isn't needed.
|
|
20
|
-
As we don't want to affect a stores speed at all, you should add it to the bottom of the page just before the ending body tag (`</body>`), rather than inside the `<head>` block.
|
|
21
|
-
|
|
22
|
-
```html
|
|
23
|
-
<!-- ShipAid Widget -->
|
|
24
|
-
<script src="https://unpkg.com/ui.shipaid.com/dist/widget.es.js" type="module"></script>
|
|
25
|
-
```
|
|
26
|
-
Then add the widget element where needed:
|
|
27
|
-
|
|
28
|
-
```html
|
|
29
|
-
<shipaid-widget></shipaid-widget>
|
|
30
|
-
|
|
31
|
-
<!-- Disable polling example -->
|
|
32
|
-
<shipaid-widget disablePolling></shipaid-widget>
|
|
33
|
-
|
|
34
|
-
<!-- With customised text -->
|
|
35
|
-
<shipaid-widget>
|
|
36
|
-
<p slot="loading">Loading ShipAid Protection</p>
|
|
37
|
-
</shipaid-widget>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
#### Test Mode
|
|
41
|
-
|
|
42
|
-
Sometimes, a store won't have activated their subscription before you install the widget - in this case, the widget does not display (you will notice a message in the console reflecting this). So to force the widget to show while you are installing and testing it, you can add this query param to the page URL: `shipaid-test`.
|
|
43
|
-
For example: `https://some-store.myshopify.com/cart?shipaid-text`
|
|
44
|
-
|
|
45
|
-
### Slots
|
|
46
|
-
|
|
47
|
-
Slots, with the syntax `slot="<slot name>"`, can be used to customise the widgets content - for example, a merchant may want to add a custom subtitle, which can be done like so:
|
|
48
|
-
```html
|
|
49
|
-
<shipaid-widget>
|
|
50
|
-
<p slot="subtitle">Shipping protection is required to be able to return or refunds items.</p>
|
|
51
|
-
</shipaid-widget>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
The default content will be replaced by any slot content. You can also add inline styles to the slots, if you need to change the font size/weight for example - but color changes should be handled by CSS variables:
|
|
55
|
-
```html
|
|
56
|
-
<span slot="title" style="font-weight: 500;">Package Protection</span>
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
| Name | Description |
|
|
60
|
-
|--------|-------------|
|
|
61
|
-
| `loading` | Replaces the text that is shown whilst the widget is loading - I.e. fetching content from the Shopify or ShipAid API's. |
|
|
62
|
-
| `title` | Replaces the default title. |
|
|
63
|
-
| `subtitle` | Replaces the default subtitle. |
|
|
64
|
-
|
|
65
|
-
### Props
|
|
66
|
-
|
|
67
|
-
This is a list of props that can be used to configure the widget:
|
|
68
|
-
|
|
69
|
-
| Prop | Description | Value/Type |
|
|
70
|
-
|--------|-------------|---------|
|
|
71
|
-
| `disablePolling` | Sets whether the cart should disable polling (enabled by default) - should be disabled if integrating manually with an ajax cart. | `boolean` |
|
|
72
|
-
| `pollingInterval` | If polling is enabled, it sets the interval (in ms) between API updates. | `number` in milliseconds |
|
|
73
|
-
| `disableRefresh ` | Sets whether the store cart should be updated when the protection item is added/removed. Add if you want to initially hide the protection product from the cart, even if it has just been added. | `boolean` |
|
|
74
|
-
| `customerId ` | Passes the information of the customer to the widget. Add if merchant wants to disable auto opt-in for some customers based on the customer tags. | `boolean` |
|
|
75
|
-
| `lang ` | Sets the widget language (see the translations section below). This value can be any supported [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). | `string` defaults to `en` |
|
|
76
|
-
| `refreshCart` | Refresh the page if shipaid product quantity is greater than one to sync product qty at checkout | `boolean` |
|
|
77
|
-
| `persistPopup` | Use local storage to show popup so that popup don't re-render on script refresh | `boolean` |
|
|
78
|
-
|
|
79
|
-
### Events
|
|
80
|
-
|
|
81
|
-
This is a list of the events emitted by the widget. You can listen to these events like so:
|
|
82
|
-
```js
|
|
83
|
-
document.addEventListener('shipaid-protection-status', ({ detail }) => {
|
|
84
|
-
console.log(detail.cart) // ShopifyCart
|
|
85
|
-
})
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
| Event | Description | Payload |
|
|
89
|
-
|-------|-------------|---------|
|
|
90
|
-
| `shipaid-loaded` | Dispatched when the widget has finished fetching data from the API, and has successfully rendered. | Contains the data from the ShipAid API: [`ShipAidStore`](/types/shipaid.ts) |
|
|
91
|
-
| `shipaid-protection-status` | Dispatched when a user either adds or removes the protection product from their cart. | `{ protection: boolean, cart: ShopifyCart, lineItem: ShopifyCartItem }` |
|
|
92
|
-
|
|
93
|
-
### Methods
|
|
94
|
-
|
|
95
|
-
This is a list of public methods available on the widget HTMLElement that can be used to change protection settings. These can be used by querying the element:
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
const shipAidEl = document.querySelector('shipaid-widget')
|
|
99
|
-
if (shipAidEl) await shipAidEl.updateCart()
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
| Method | Description | Payload |
|
|
103
|
-
|--------|-------------|---------|
|
|
104
|
-
| `hasProtection` | Returns a boolean which indicates whether the protection item is currently in the cart. | |
|
|
105
|
-
| `updateCart` | Updates the internal cart, and triggers any protection product updates - use this method with with ajax carts, to update protection state without needing to reload the page. | Optional - the cart object from the ajax API. |
|
|
106
|
-
| `addProtection` | Adds the relevant protection item to cart. | |
|
|
107
|
-
| `removeProtection` | Removes the protection item from the cart. | |
|
|
108
|
-
|
|
109
|
-
### Styles
|
|
110
|
-
|
|
111
|
-
If you need to change any of the widget colors to suit a specific theme, there are various CSS variables you can use to do so. These should be added to the style attribute on the widget element:
|
|
112
|
-
|
|
113
|
-
```html
|
|
114
|
-
<shipaid-widget
|
|
115
|
-
style="
|
|
116
|
-
--shipaid-text: #fff;
|
|
117
|
-
--shipaid-prompt-actions-price-color: #fff;
|
|
118
|
-
"
|
|
119
|
-
>
|
|
120
|
-
</shipaid-widget>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
| Variable | Description | Default |
|
|
124
|
-
|----------|-------------|---------|
|
|
125
|
-
| `--shipaid-text` | Changes the global text color. | `#000000` |
|
|
126
|
-
| `--shipaid-text-muted` | Changes the global muted text color. | `#aaaaaa` |
|
|
127
|
-
| `--shipaid-prompt-margin` | Changes the margins of the main container element. | `2rem 0px 4rem auto` |
|
|
128
|
-
| `--shipaid-prompt-width` | Changes the width of the main container element. | `400px` |
|
|
129
|
-
| `--shipaid-prompt-width-mobile` | Changes the mobile width of the main container element. | `100%` |
|
|
130
|
-
| `--shipaid-prompt-actions-price-color` | Changes the color of the price element. | `var(--shipaid-text-muted)` |
|
|
131
|
-
| `--shipaid-prompt-actions-button-color` | Changes the color of the add/remove button element. | `var(--shipaid-primary)` |
|
|
132
|
-
| `--shipaid-prompt-badge-background-color` | Changes the background color of the learn more button element. | `var(--shipaid-light-grey)` |
|
|
133
|
-
| `--shipaid-prompt-badge-text-color` | Changes the color of the learn more button element. | `var(--shipaid-text)` |
|
|
134
|
-
| `--shipaid-logo-height` | Changes the height of ShipAid logo. | `var(--shipaid-logo-height, 35px)` |
|
|
135
|
-
| `--shipaid-logo-max-height` | Changes the max height of ShipAid logo. | `var(--shipaid-logo-max-height, 35px)` |
|
|
136
|
-
| `--shipaid-logo-width` | Changes the width of ShipAid logo. | `var(--shipaid-logo-width, auto)` |
|
|
137
|
-
| `--shipaid-logo-max-width` | Changes the max width of ShipAid logo. | `var(--shipaid-logo-max-width, 50px)` |
|
|
138
|
-
| `--shipaid-prompt-footer-button-size` | Changes the height of info button in footer. | `var(--shipaid-prompt-footer-button-size, 10px)` |
|
|
139
|
-
| `--shipaid-prompt-badge-border-radius` | Changes border radius of footer | `var(--shipaid-prompt-badge-border-radius, 30px)` |
|
|
140
|
-
| `--shipaid-footer-badge-logo-height` | Changes the height of logo in footer. | `var(--shipaid-footer-badge-logo-height, 9px)` |
|
|
141
|
-
| `--shipaid-prompt-footer-location` | Changes the position of footer badge | `var(--shipaid-prompt-footer-location, flex-start)` |
|
|
142
|
-
| `--shipaid-prompt-product-actions-content` | Changes the spaces between price and add/remove button | `var(--shipaid-prompt-product-actions-content, space-between)` |
|
|
143
|
-
| `--shipaid-prompt-footer-topMargin` | Changes margin between header and badge footer | `var(--shipaid-prompt-footer-topMargin, 0px)` |
|
|
144
|
-
| `-shipaid-prompt-footer-display` | Changes the display option for footer | `var(-shipaid-prompt-footer-display, flex)` |
|
|
145
|
-
|
|
146
|
-
Other variables can be found [here](/widget/src/assets/styles.ts) (`/widget/src/assets/styles.ts`).
|
|
147
|
-
|
|
148
|
-
### Translations
|
|
149
|
-
|
|
150
|
-
This widget also supports multiple languages, using the `lit-translate` plugin. The widget language can be configured using an attribute and would usally be static, but supports reactively swapping the language if a theme needs - i.e. if a user switches the language using a select option in the theme, then the widget language could be updated at the same time by selecting the widget element, and setting the `lang` attribute.
|
|
151
|
-
|
|
152
|
-
To create lang files, you should copy the default `/lang/en.json` file, and rename it to an [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) - for example `cp /src/lang/en.json /src/lang/fs.json`. You can then go through each key, and translate the existing text to the relevant language. This should be all you need to do - the widget automatically (and lazily, to save bundle size) imports the relevant lang file when it is specified. It will also fallback to the default `en.json` lang file if a certain language doesn't exist yet.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
## Contributing
|
|
156
|
-
|
|
157
|
-
### Requirements
|
|
158
|
-
|
|
159
|
-
- Node v16+
|
|
160
|
-
- PNPM
|
|
161
|
-
- Development Shopify store (with the ShipAid app installed)
|
|
162
|
-
- ShipAid API development/staging instance
|
|
163
|
-
|
|
164
|
-
### Development
|
|
165
|
-
|
|
166
|
-
You will need to make sure your development store has the ShipAid app installed, so the store and its protection product is added to the DB. You will also need to ensure the Shopify app you are testing this with has an app proxy added, and pointed towards an API instance.
|
|
167
|
-
|
|
168
|
-
```sh
|
|
169
|
-
pnpm install
|
|
170
|
-
pnpm run develop
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Once the project is running, add the below to your development Shopify store `theme.liquid`:
|
|
174
|
-
|
|
175
|
-
```html
|
|
176
|
-
<!-- Dev -->
|
|
177
|
-
<script src="http://localhost:3000/src/shipaid-widget.ts"type="module" ></script>
|
|
178
|
-
|
|
179
|
-
<!-- Prod -->
|
|
180
|
-
<!-- ShipAid Widget -->
|
|
181
|
-
<script src="https://unpkg.com/ui.shipaid.com/dist/widget.es.js" type="module"></script>
|
|
182
|
-
```
|
|
183
|
-
And add the widget element where needed:
|
|
184
|
-
|
|
185
|
-
```html
|
|
186
|
-
<shipaid-widget>
|
|
187
|
-
<p>Loading ShipAid Protection</p>
|
|
188
|
-
</shipaid-widget>
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Build
|
|
192
|
-
|
|
193
|
-
Once the project has been built, you can publish the project to NPM, and users can add the script to their store using a package CDN (I.e. [Unpkg](https://unpkg.com/)).
|
|
194
|
-
|
|
195
|
-
```sh
|
|
196
|
-
pnpm install
|
|
197
|
-
pnpm run lint
|
|
198
|
-
pnpm run build
|
|
199
|
-
pnpm publish
|
|
200
|
-
```
|
|
1
|
+
# ShipAid Shopify Widget
|
|
2
|
+
|
|
3
|
+
This is the repository for the ShipAid Shopify (and possibly others in future) widget. It uses the [Lit](https://lit.dev/) web components library, so it is recommended to become familiar with it before contributing to this repository.
|
|
4
|
+
|
|
5
|
+
Using Lit provides a framework that allows us to build a reactive UI, using JSX-like syntax - no need to use JQuery etc. And it can easily be installed in a page by using the custom web component name:
|
|
6
|
+
```html
|
|
7
|
+
<shipaid-widget>Fallback Content</shipaid-widget>
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
This widget provides an interface where a user can choose to add or remove ShipAid protection - this is actually a product in their store that can be added to cart. When the component is loaded, we immediately run a request to fetch the ShipAid protection product details from our API, as well as the customers current cart from the [Shopify AJAX API](https://shopify.dev/api/ajax/reference/cart).
|
|
13
|
+
Once we have this data, we can check whether the customer currently has the ShipAid product in their cart, and show either the add or remove product buttons based on this.
|
|
14
|
+
|
|
15
|
+
We also emit various [custom events](https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events#adding_custom_data_%E2%80%93_customevent) when we add or remove the ShipAid product from the cart, so other developers can listen to these events, and update AJAX carts.
|
|
16
|
+
|
|
17
|
+
### Installation
|
|
18
|
+
|
|
19
|
+
Add the script tag to the theme - if the theme has an ajax cart, you'll likely want to add this to the `theme.liquid` file, otherwise if the store has only a cart page (`/cart`), then you can add it to just that page, to save it being unecessarily loaded when it isn't needed.
|
|
20
|
+
As we don't want to affect a stores speed at all, you should add it to the bottom of the page just before the ending body tag (`</body>`), rather than inside the `<head>` block.
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<!-- ShipAid Widget -->
|
|
24
|
+
<script src="https://unpkg.com/ui.shipaid.com/dist/widget.es.js" type="module"></script>
|
|
25
|
+
```
|
|
26
|
+
Then add the widget element where needed:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<shipaid-widget></shipaid-widget>
|
|
30
|
+
|
|
31
|
+
<!-- Disable polling example -->
|
|
32
|
+
<shipaid-widget disablePolling></shipaid-widget>
|
|
33
|
+
|
|
34
|
+
<!-- With customised text -->
|
|
35
|
+
<shipaid-widget>
|
|
36
|
+
<p slot="loading">Loading ShipAid Protection</p>
|
|
37
|
+
</shipaid-widget>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### Test Mode
|
|
41
|
+
|
|
42
|
+
Sometimes, a store won't have activated their subscription before you install the widget - in this case, the widget does not display (you will notice a message in the console reflecting this). So to force the widget to show while you are installing and testing it, you can add this query param to the page URL: `shipaid-test`.
|
|
43
|
+
For example: `https://some-store.myshopify.com/cart?shipaid-text`
|
|
44
|
+
|
|
45
|
+
### Slots
|
|
46
|
+
|
|
47
|
+
Slots, with the syntax `slot="<slot name>"`, can be used to customise the widgets content - for example, a merchant may want to add a custom subtitle, which can be done like so:
|
|
48
|
+
```html
|
|
49
|
+
<shipaid-widget>
|
|
50
|
+
<p slot="subtitle">Shipping protection is required to be able to return or refunds items.</p>
|
|
51
|
+
</shipaid-widget>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The default content will be replaced by any slot content. You can also add inline styles to the slots, if you need to change the font size/weight for example - but color changes should be handled by CSS variables:
|
|
55
|
+
```html
|
|
56
|
+
<span slot="title" style="font-weight: 500;">Package Protection</span>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
| Name | Description |
|
|
60
|
+
|--------|-------------|
|
|
61
|
+
| `loading` | Replaces the text that is shown whilst the widget is loading - I.e. fetching content from the Shopify or ShipAid API's. |
|
|
62
|
+
| `title` | Replaces the default title. |
|
|
63
|
+
| `subtitle` | Replaces the default subtitle. |
|
|
64
|
+
|
|
65
|
+
### Props
|
|
66
|
+
|
|
67
|
+
This is a list of props that can be used to configure the widget:
|
|
68
|
+
|
|
69
|
+
| Prop | Description | Value/Type |
|
|
70
|
+
|--------|-------------|---------|
|
|
71
|
+
| `disablePolling` | Sets whether the cart should disable polling (enabled by default) - should be disabled if integrating manually with an ajax cart. | `boolean` |
|
|
72
|
+
| `pollingInterval` | If polling is enabled, it sets the interval (in ms) between API updates. | `number` in milliseconds |
|
|
73
|
+
| `disableRefresh ` | Sets whether the store cart should be updated when the protection item is added/removed. Add if you want to initially hide the protection product from the cart, even if it has just been added. | `boolean` |
|
|
74
|
+
| `customerId ` | Passes the information of the customer to the widget. Add if merchant wants to disable auto opt-in for some customers based on the customer tags. | `boolean` |
|
|
75
|
+
| `lang ` | Sets the widget language (see the translations section below). This value can be any supported [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). | `string` defaults to `en` |
|
|
76
|
+
| `refreshCart` | Refresh the page if shipaid product quantity is greater than one to sync product qty at checkout | `boolean` |
|
|
77
|
+
| `persistPopup` | Use local storage to show popup so that popup don't re-render on script refresh | `boolean` |
|
|
78
|
+
|
|
79
|
+
### Events
|
|
80
|
+
|
|
81
|
+
This is a list of the events emitted by the widget. You can listen to these events like so:
|
|
82
|
+
```js
|
|
83
|
+
document.addEventListener('shipaid-protection-status', ({ detail }) => {
|
|
84
|
+
console.log(detail.cart) // ShopifyCart
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
| Event | Description | Payload |
|
|
89
|
+
|-------|-------------|---------|
|
|
90
|
+
| `shipaid-loaded` | Dispatched when the widget has finished fetching data from the API, and has successfully rendered. | Contains the data from the ShipAid API: [`ShipAidStore`](/types/shipaid.ts) |
|
|
91
|
+
| `shipaid-protection-status` | Dispatched when a user either adds or removes the protection product from their cart. | `{ protection: boolean, cart: ShopifyCart, lineItem: ShopifyCartItem }` |
|
|
92
|
+
|
|
93
|
+
### Methods
|
|
94
|
+
|
|
95
|
+
This is a list of public methods available on the widget HTMLElement that can be used to change protection settings. These can be used by querying the element:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
const shipAidEl = document.querySelector('shipaid-widget')
|
|
99
|
+
if (shipAidEl) await shipAidEl.updateCart()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
| Method | Description | Payload |
|
|
103
|
+
|--------|-------------|---------|
|
|
104
|
+
| `hasProtection` | Returns a boolean which indicates whether the protection item is currently in the cart. | |
|
|
105
|
+
| `updateCart` | Updates the internal cart, and triggers any protection product updates - use this method with with ajax carts, to update protection state without needing to reload the page. | Optional - the cart object from the ajax API. |
|
|
106
|
+
| `addProtection` | Adds the relevant protection item to cart. | |
|
|
107
|
+
| `removeProtection` | Removes the protection item from the cart. | |
|
|
108
|
+
|
|
109
|
+
### Styles
|
|
110
|
+
|
|
111
|
+
If you need to change any of the widget colors to suit a specific theme, there are various CSS variables you can use to do so. These should be added to the style attribute on the widget element:
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<shipaid-widget
|
|
115
|
+
style="
|
|
116
|
+
--shipaid-text: #fff;
|
|
117
|
+
--shipaid-prompt-actions-price-color: #fff;
|
|
118
|
+
"
|
|
119
|
+
>
|
|
120
|
+
</shipaid-widget>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Variable | Description | Default |
|
|
124
|
+
|----------|-------------|---------|
|
|
125
|
+
| `--shipaid-text` | Changes the global text color. | `#000000` |
|
|
126
|
+
| `--shipaid-text-muted` | Changes the global muted text color. | `#aaaaaa` |
|
|
127
|
+
| `--shipaid-prompt-margin` | Changes the margins of the main container element. | `2rem 0px 4rem auto` |
|
|
128
|
+
| `--shipaid-prompt-width` | Changes the width of the main container element. | `400px` |
|
|
129
|
+
| `--shipaid-prompt-width-mobile` | Changes the mobile width of the main container element. | `100%` |
|
|
130
|
+
| `--shipaid-prompt-actions-price-color` | Changes the color of the price element. | `var(--shipaid-text-muted)` |
|
|
131
|
+
| `--shipaid-prompt-actions-button-color` | Changes the color of the add/remove button element. | `var(--shipaid-primary)` |
|
|
132
|
+
| `--shipaid-prompt-badge-background-color` | Changes the background color of the learn more button element. | `var(--shipaid-light-grey)` |
|
|
133
|
+
| `--shipaid-prompt-badge-text-color` | Changes the color of the learn more button element. | `var(--shipaid-text)` |
|
|
134
|
+
| `--shipaid-logo-height` | Changes the height of ShipAid logo. | `var(--shipaid-logo-height, 35px)` |
|
|
135
|
+
| `--shipaid-logo-max-height` | Changes the max height of ShipAid logo. | `var(--shipaid-logo-max-height, 35px)` |
|
|
136
|
+
| `--shipaid-logo-width` | Changes the width of ShipAid logo. | `var(--shipaid-logo-width, auto)` |
|
|
137
|
+
| `--shipaid-logo-max-width` | Changes the max width of ShipAid logo. | `var(--shipaid-logo-max-width, 50px)` |
|
|
138
|
+
| `--shipaid-prompt-footer-button-size` | Changes the height of info button in footer. | `var(--shipaid-prompt-footer-button-size, 10px)` |
|
|
139
|
+
| `--shipaid-prompt-badge-border-radius` | Changes border radius of footer | `var(--shipaid-prompt-badge-border-radius, 30px)` |
|
|
140
|
+
| `--shipaid-footer-badge-logo-height` | Changes the height of logo in footer. | `var(--shipaid-footer-badge-logo-height, 9px)` |
|
|
141
|
+
| `--shipaid-prompt-footer-location` | Changes the position of footer badge | `var(--shipaid-prompt-footer-location, flex-start)` |
|
|
142
|
+
| `--shipaid-prompt-product-actions-content` | Changes the spaces between price and add/remove button | `var(--shipaid-prompt-product-actions-content, space-between)` |
|
|
143
|
+
| `--shipaid-prompt-footer-topMargin` | Changes margin between header and badge footer | `var(--shipaid-prompt-footer-topMargin, 0px)` |
|
|
144
|
+
| `-shipaid-prompt-footer-display` | Changes the display option for footer | `var(-shipaid-prompt-footer-display, flex)` |
|
|
145
|
+
|
|
146
|
+
Other variables can be found [here](/widget/src/assets/styles.ts) (`/widget/src/assets/styles.ts`).
|
|
147
|
+
|
|
148
|
+
### Translations
|
|
149
|
+
|
|
150
|
+
This widget also supports multiple languages, using the `lit-translate` plugin. The widget language can be configured using an attribute and would usally be static, but supports reactively swapping the language if a theme needs - i.e. if a user switches the language using a select option in the theme, then the widget language could be updated at the same time by selecting the widget element, and setting the `lang` attribute.
|
|
151
|
+
|
|
152
|
+
To create lang files, you should copy the default `/lang/en.json` file, and rename it to an [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) - for example `cp /src/lang/en.json /src/lang/fs.json`. You can then go through each key, and translate the existing text to the relevant language. This should be all you need to do - the widget automatically (and lazily, to save bundle size) imports the relevant lang file when it is specified. It will also fallback to the default `en.json` lang file if a certain language doesn't exist yet.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
## Contributing
|
|
156
|
+
|
|
157
|
+
### Requirements
|
|
158
|
+
|
|
159
|
+
- Node v16+
|
|
160
|
+
- PNPM
|
|
161
|
+
- Development Shopify store (with the ShipAid app installed)
|
|
162
|
+
- ShipAid API development/staging instance
|
|
163
|
+
|
|
164
|
+
### Development
|
|
165
|
+
|
|
166
|
+
You will need to make sure your development store has the ShipAid app installed, so the store and its protection product is added to the DB. You will also need to ensure the Shopify app you are testing this with has an app proxy added, and pointed towards an API instance.
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
pnpm install
|
|
170
|
+
pnpm run develop
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Once the project is running, add the below to your development Shopify store `theme.liquid`:
|
|
174
|
+
|
|
175
|
+
```html
|
|
176
|
+
<!-- Dev -->
|
|
177
|
+
<script src="http://localhost:3000/src/shipaid-widget.ts"type="module" ></script>
|
|
178
|
+
|
|
179
|
+
<!-- Prod -->
|
|
180
|
+
<!-- ShipAid Widget -->
|
|
181
|
+
<script src="https://unpkg.com/ui.shipaid.com/dist/widget.es.js" type="module"></script>
|
|
182
|
+
```
|
|
183
|
+
And add the widget element where needed:
|
|
184
|
+
|
|
185
|
+
```html
|
|
186
|
+
<shipaid-widget>
|
|
187
|
+
<p>Loading ShipAid Protection</p>
|
|
188
|
+
</shipaid-widget>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Build
|
|
192
|
+
|
|
193
|
+
Once the project has been built, you can publish the project to NPM, and users can add the script to their store using a package CDN (I.e. [Unpkg](https://unpkg.com/)).
|
|
194
|
+
|
|
195
|
+
```sh
|
|
196
|
+
pnpm install
|
|
197
|
+
pnpm run lint
|
|
198
|
+
pnpm run build
|
|
199
|
+
pnpm publish
|
|
200
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const loading = "Laad ShipAid Widget...";
|
|
2
|
+
const title = "Bezorggarantie";
|
|
3
|
+
const description = "in geval van verlies, schade of diefstal";
|
|
4
|
+
const footer = {
|
|
5
|
+
button: "Aangedreven door"
|
|
6
|
+
};
|
|
7
|
+
const actions = {
|
|
8
|
+
add: "Toevoegen",
|
|
9
|
+
remove: "Verwijderen",
|
|
10
|
+
loading: "Bezig met laden..."
|
|
11
|
+
};
|
|
12
|
+
const nl = {
|
|
13
|
+
loading,
|
|
14
|
+
title,
|
|
15
|
+
description,
|
|
16
|
+
footer,
|
|
17
|
+
actions,
|
|
18
|
+
"learn-more-popup": {
|
|
19
|
+
close: "Sluiten",
|
|
20
|
+
title: "Bezorggarantie",
|
|
21
|
+
disclaimer: {
|
|
22
|
+
"subtitle-enable": "We stellen je favoriete merken in staat om een bezorggarantie te bieden omdat we weten dat elke bestelling belangrijk is en dingen kunnen gebeuren!",
|
|
23
|
+
"subtitle-monitor": "We monitoren je pakket continu en bieden een handig portaal om de voortgang van je bestelling op elk moment te volgen!",
|
|
24
|
+
"subtitle-notify": "Je wordt gedurende het gehele verzendproces op de hoogte gehouden, zodat je altijd op de hoogte bent van elke stap.",
|
|
25
|
+
"subtitle-resolution": "In geval van problemen tijdens het transport bieden we een snelle en gemakkelijke manier om het probleem direct bij het merk te melden, voor een snelle oplossing.",
|
|
26
|
+
text: "Door deze bezorggarantie aan te schaffen, ga je akkoord met onze Servicevoorwaarden en Privacybeleid. Je bent niet verplicht om deze garantie aan te schaffen. Deze garantie is GEEN verzekering en biedt geen schadevergoeding voor verlies, schade of aansprakelijkheid als gevolg van een onvoorziene of onbekende gebeurtenis, maar biedt via ShipAid een bezorggarantie waarbij, als het product dat je hebt besteld niet in bevredigende staat wordt geleverd, het merk van wie je het product hebt besteld, het product gratis kan vervangen. ShipAid levert geen producten of diensten direct aan consumenten, maar biedt een dienst die merken in staat stelt om productvervanging aan hun klanten te faciliteren. Het kopen van deze garantie betekent niet automatisch dat je wordt vergoed voor product- of verzendkosten, aangezien het oplossingproces en de beslissing voor compensatie strikt wordt bepaald door het merk van wie je koopt. Het merk zal bewijs van schade of niet-geleverde producten vereisen."
|
|
27
|
+
},
|
|
28
|
+
links: {
|
|
29
|
+
terms: "Servicevoorwaarden",
|
|
30
|
+
privacy: "Privacybeleid"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
actions,
|
|
36
|
+
nl as default,
|
|
37
|
+
description,
|
|
38
|
+
footer,
|
|
39
|
+
loading,
|
|
40
|
+
title
|
|
41
|
+
};
|
package/dist/widget.es.js
CHANGED
|
@@ -1596,12 +1596,15 @@ const styles$1 = i$2`
|
|
|
1596
1596
|
|
|
1597
1597
|
@media (max-width: 600px) {
|
|
1598
1598
|
.shipaid-confirmation-popup {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1599
|
+
height: max-content;
|
|
1600
|
+
max-width: 90%;
|
|
1601
|
+
margin: 25% 20px 0 20px;
|
|
1602
|
+
}
|
|
1603
|
+
.popup-actions {
|
|
1604
|
+
flex-direction: column;
|
|
1605
|
+
gap: 10px;
|
|
1604
1606
|
}
|
|
1607
|
+
|
|
1605
1608
|
}
|
|
1606
1609
|
|
|
1607
1610
|
.btn-primary {
|
|
@@ -2021,6 +2024,7 @@ const langFiles = /* @__PURE__ */ Object.assign({
|
|
|
2021
2024
|
"./lang/es.json": () => import("./es-gSoKNDaV.js").then((m2) => m2["default"]),
|
|
2022
2025
|
"./lang/fr.json": () => import("./fr-B4wOlIrE.js").then((m2) => m2["default"]),
|
|
2023
2026
|
"./lang/it.json": () => import("./it-1qLegqAS.js").then((m2) => m2["default"]),
|
|
2027
|
+
"./lang/nl.json": () => import("./nl-CI8lUOMC.js").then((m2) => m2["default"]),
|
|
2024
2028
|
"./lang/pt.json": () => import("./pt-CeUvCcpv.js").then((m2) => m2["default"])
|
|
2025
2029
|
});
|
|
2026
2030
|
registerTranslateConfig({
|