ui.shipaid.com 0.2.7 → 0.2.10

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 CHANGED
@@ -1,80 +1,90 @@
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
- ### Events
18
-
19
- This is a list of the events emitted by the widget:
20
-
21
- | Event | Description | Payload |
22
- |-------|-------------|---------|
23
- | `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) |
24
- | `shipaid-protection-status` | Dispatched when a user either adds or removes the protection product from their cart. | `{ protection: boolean, cart: ShopifyCart, lineItem: ShopifyCartItem }` |
25
-
26
- ### Methods
27
-
28
- This is a list of public methods that can be used to change protection settings:
29
-
30
- | Method | Description | Payload |
31
- |--------|-------------|---------|
32
- | `hasProtection` | Returns a boolean which indicates whether the protection item is currently in the cart. | |
33
- | `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. |
34
- | `addProtection` | Adds the relevant protection item to cart. | |
35
- | `removeProtection` | Removes the protection item from the cart. | |
36
-
37
- ## Contributing
38
-
39
- ### Requirements
40
-
41
- - Node v16+
42
- - PNPM
43
- - Development Shopify store (with the ShipAid app installed)
44
- - ShipAid API development/staging instance
45
-
46
- ### Development
47
-
48
- 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.
49
-
50
- ```sh
51
- pnpm install
52
- pnpm run develop
53
- ```
54
-
55
- Once the project is running, add the below to your development Shopify store `theme.liquid`:
56
-
57
- ```html
58
- <!-- Dev -->
59
- <script src="http://localhost:3000/src/shipaid-widget.ts"type="module" ></script>
60
- <!-- Prod -->
61
- <script src="https://unpkg.com/ui.shipaid.com?module" type="module"></script>
62
- ```
63
- And add the widget element in your cart (likely `/sections/main-cart-items.liquid`):
64
-
65
- ```html
66
- <shipaid-widget>
67
- <p>Loading ShipAid Protection</p>
68
- </shipaid-widget>
69
- ```
70
-
71
- ### Build
72
-
73
- 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/)).
74
-
75
- ```sh
76
- pnpm install
77
- pnpm run lint
78
- pnpm run build
79
- pnpm publish
80
- ```
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
+ ### Events
18
+
19
+ This is a list of the events emitted by the widget:
20
+
21
+ | Event | Description | Payload |
22
+ |-------|-------------|---------|
23
+ | `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) |
24
+ | `shipaid-protection-status` | Dispatched when a user either adds or removes the protection product from their cart. | `{ protection: boolean, cart: ShopifyCart, lineItem: ShopifyCartItem }` |
25
+
26
+ ### Methods
27
+
28
+ This is a list of public methods that can be used to change protection settings:
29
+
30
+ | Method | Description | Payload |
31
+ |--------|-------------|---------|
32
+ | `hasProtection` | Returns a boolean which indicates whether the protection item is currently in the cart. | |
33
+ | `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. |
34
+ | `addProtection` | Adds the relevant protection item to cart. | |
35
+ | `removeProtection` | Removes the protection item from the cart. | |
36
+
37
+ ### Props
38
+
39
+ This is a list of props that can be used to configure the widget:
40
+
41
+ | Prop | Description | Value/Type |
42
+ |--------|-------------|---------|
43
+ | `disablePolling` | Sets whether the cart should disable polling (enabled by default) - should be disabled if integrating manually with an ajax cart. | `boolean` |
44
+ | `pollingInterval` | If polling is enabled, it sets the interval (in ms) between API updates. | `number` in milliseconds |
45
+ | `disableRefresh ` | Sets whether the store cart should be updated when the protection item is added/removed. Set to `true` if you want to initially hide the protection product from the cart, even if it has just been added. | `boolean` |
46
+
47
+ ## Contributing
48
+
49
+ ### Requirements
50
+
51
+ - Node v16+
52
+ - PNPM
53
+ - Development Shopify store (with the ShipAid app installed)
54
+ - ShipAid API development/staging instance
55
+
56
+ ### Development
57
+
58
+ 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.
59
+
60
+ ```sh
61
+ pnpm install
62
+ pnpm run develop
63
+ ```
64
+
65
+ Once the project is running, add the below to your development Shopify store `theme.liquid`:
66
+
67
+ ```html
68
+ <!-- Dev -->
69
+ <script src="http://localhost:3000/src/shipaid-widget.ts"type="module" ></script>
70
+ <!-- Prod -->
71
+ <script src="https://unpkg.com/ui.shipaid.com/dist/widget.es.js" type="module"></script>
72
+ ```
73
+ And add the widget element in your cart (likely `/sections/main-cart-items.liquid`):
74
+
75
+ ```html
76
+ <shipaid-widget>
77
+ <p>Loading ShipAid Protection</p>
78
+ </shipaid-widget>
79
+ ```
80
+
81
+ ### Build
82
+
83
+ 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/)).
84
+
85
+ ```sh
86
+ pnpm install
87
+ pnpm run lint
88
+ pnpm run build
89
+ pnpm publish
90
+ ```