hasting-swatchcart-module 1.0.5 → 1.0.7

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.
Files changed (129) hide show
  1. package/README.md +290 -290
  2. package/dist/assets/index.css +1 -0
  3. package/dist/cdn/lib/components/SwatchesModule.d.ts +11 -0
  4. package/dist/cdn/lib/main.d.ts +4 -0
  5. package/dist/cdn/lib/store/LibraryProvider.d.ts +4 -0
  6. package/dist/cdn/lib/store/rootReducer.d.ts +11 -0
  7. package/dist/cdn/lib/store/store.d.ts +25 -0
  8. package/dist/cdn/lib/store/withStore.d.ts +2 -0
  9. package/dist/cdn/lib/vite-env.d.ts +1 -0
  10. package/dist/cdn/main.css +1 -0
  11. package/dist/cdn/main.js +49110 -0
  12. package/dist/cdn/src/app/App.d.ts +2 -0
  13. package/dist/cdn/src/app/assets/svg/ArrowIconSVG.d.ts +3 -0
  14. package/dist/cdn/src/app/assets/svg/CheckMarkIconSVG.d.ts +3 -0
  15. package/dist/cdn/src/app/assets/svg/ChevronSVGIcon.d.ts +3 -0
  16. package/dist/cdn/src/app/assets/svg/CloseIconSVG.d.ts +3 -0
  17. package/dist/cdn/src/app/assets/svg/DarkWhiteIconSVG.d.ts +1 -0
  18. package/dist/cdn/src/app/assets/svg/MinusIconSVG.d.ts +3 -0
  19. package/dist/cdn/src/app/assets/svg/PlusIconSVG.d.ts +3 -0
  20. package/dist/cdn/src/app/assets/svg/SearchIconSVG.d.ts +3 -0
  21. package/dist/cdn/src/app/assets/svg/TrashIconSVG.d.ts +3 -0
  22. package/dist/cdn/src/app/assets/svg/WhiteWhiteIconSVG.d.ts +1 -0
  23. package/dist/cdn/src/app/main.d.ts +1 -0
  24. package/dist/cdn/src/app/providers/StoreProvider.d.ts +6 -0
  25. package/dist/cdn/src/app/store/rootReducer.d.ts +11 -0
  26. package/dist/cdn/src/app/store/store.d.ts +24 -0
  27. package/dist/cdn/src/features/Cart/lib/CartCervices.d.ts +5 -0
  28. package/dist/cdn/src/features/Cart/model/cartSlice.d.ts +13 -0
  29. package/dist/cdn/src/features/Cart/model/selectors.d.ts +223 -0
  30. package/dist/cdn/src/features/Cart/model/types.d.ts +7 -0
  31. package/dist/cdn/src/features/Cart/ui/CartHeader/CartHeader.d.ts +7 -0
  32. package/dist/cdn/src/features/Cart/ui/CartList/CartList.d.ts +1 -0
  33. package/dist/cdn/src/features/Cart/ui/CartListItem/CartListItem.d.ts +10 -0
  34. package/dist/cdn/src/features/Cart/ui/CartWrapper/CartWrapper.d.ts +9 -0
  35. package/dist/cdn/src/features/Cart/ui/Counter/Counter.d.ts +9 -0
  36. package/dist/cdn/src/features/DataAdapter/lib/DataAdapterServices.d.ts +14 -0
  37. package/dist/cdn/src/features/DataAdapter/utils/types.d.ts +13 -0
  38. package/dist/cdn/src/features/MultiProduct/lib/MultiProductCartServices.d.ts +13 -0
  39. package/dist/cdn/src/features/MultiProduct/model/API/api.d.ts +4 -0
  40. package/dist/cdn/src/features/MultiProduct/model/API/routes.d.ts +4 -0
  41. package/dist/cdn/src/features/MultiProduct/model/multiProductCartSlice.d.ts +9 -0
  42. package/dist/cdn/src/features/MultiProduct/model/selectors.d.ts +35 -0
  43. package/dist/cdn/src/features/MultiProduct/model/types.d.ts +43 -0
  44. package/dist/cdn/src/features/MultiProduct/ui/CartSelectedProductList/CartSelectedProductList.d.ts +1 -0
  45. package/dist/cdn/src/features/MultiProduct/ui/CustomModal/CustomModal.d.ts +8 -0
  46. package/dist/cdn/src/features/MultiProduct/ui/FiltersSelectedProductItem/FiltersSelectedProductItem.d.ts +1 -0
  47. package/dist/cdn/src/features/MultiProduct/ui/MaterialMultiProductList/MaterialMultiProductList.d.ts +7 -0
  48. package/dist/cdn/src/features/MultiProduct/ui/MaterialMultiProductListItem/MaterialMultiProductListItem.d.ts +4 -0
  49. package/dist/cdn/src/features/MultiProduct/ui/MultiProductCartHeader/MultiProductCartHeader.d.ts +5 -0
  50. package/dist/cdn/src/features/MultiProduct/ui/MultiProductItemCart/MultiProductItemCart.d.ts +5 -0
  51. package/dist/cdn/src/features/MultiProduct/ui/MultiProductWrapper/MultiProductWrapper.d.ts +6 -0
  52. package/dist/cdn/src/features/MultiProduct/ui/ProductList/ProductList.d.ts +1 -0
  53. package/dist/cdn/src/features/MultiProduct/ui/ProductListItem/ProductListItem.d.ts +6 -0
  54. package/dist/cdn/src/features/MultiProduct/ui/SelectedProductItem/SelectedProductItem.d.ts +5 -0
  55. package/dist/cdn/src/features/MultiProduct/ui/SwatchContentContainer/SwatchContentContainer.d.ts +1 -0
  56. package/dist/cdn/src/features/MultiProduct/ui/SwatchesMultiProductList/SwatchesMultiProductList.d.ts +7 -0
  57. package/dist/cdn/src/features/MultiProduct/utils/constants.d.ts +8 -0
  58. package/dist/cdn/src/features/MultiProduct/utils/randomList.d.ts +2 -0
  59. package/dist/cdn/src/features/SwatchModule/SwatchModule/ui/SwatchModule.d.ts +2 -0
  60. package/dist/cdn/src/features/swatches/lib/AttributeHelper.d.ts +7 -0
  61. package/dist/cdn/src/features/swatches/lib/SwatchesServices.d.ts +11 -0
  62. package/dist/cdn/src/features/swatches/model/selectors.d.ts +12 -0
  63. package/dist/cdn/src/features/swatches/model/swatchesSlice.d.ts +26 -0
  64. package/dist/cdn/src/features/swatches/model/thunks.d.ts +22 -0
  65. package/dist/cdn/src/features/swatches/model/types.d.ts +142 -0
  66. package/dist/cdn/src/features/swatches/ui/Filters/ColorsFilter.d.ts +1 -0
  67. package/dist/cdn/src/features/swatches/ui/Filters/LooksFilter.d.ts +1 -0
  68. package/dist/cdn/src/features/swatches/ui/Filters/MaterialsFilter.d.ts +1 -0
  69. package/dist/cdn/src/features/swatches/ui/Filters/index.d.ts +5 -0
  70. package/dist/cdn/src/features/swatches/ui/HexGridZoom/HexGridZoom.d.ts +3 -0
  71. package/dist/cdn/src/features/swatches/ui/ImageGridZoom/ImageGridZoom.d.ts +3 -0
  72. package/dist/cdn/src/features/swatches/ui/MaterialListItem/MaterialListItem.d.ts +4 -0
  73. package/dist/cdn/src/features/swatches/ui/MaterialSingleProductList/MaterialSingleProductList.d.ts +7 -0
  74. package/dist/cdn/src/features/swatches/ui/ProductElement/index.d.ts +6 -0
  75. package/dist/cdn/src/features/swatches/ui/SwatchWrapper/SwatchWrapper.d.ts +8 -0
  76. package/dist/cdn/src/features/swatches/ui/Swatches.d.ts +2 -0
  77. package/dist/cdn/src/features/swatches/ui/SwatchesList/SwatchesList.d.ts +7 -0
  78. package/dist/cdn/src/features/swatches/ui/SwatchesListWrapper/SwatchesListWrapper.d.ts +1 -0
  79. package/dist/cdn/src/features/swatches/utils/constants.d.ts +3 -0
  80. package/dist/cdn/src/features/swatches/utils/types.d.ts +22 -0
  81. package/dist/cdn/src/shared/constants/constants.d.ts +1 -0
  82. package/dist/cdn/src/shared/constants/props.d.ts +1058 -0
  83. package/dist/cdn/src/shared/constants/select.d.ts +4 -0
  84. package/dist/cdn/src/shared/constants/selectedMaterials.d.ts +1 -0
  85. package/dist/cdn/src/shared/types/activeTab.d.ts +5 -0
  86. package/dist/cdn/src/shared/types/fetchData.d.ts +41 -0
  87. package/dist/cdn/src/shared/types/svg.d.ts +3 -0
  88. package/dist/cdn/src/shared/ui/CartPrice/CartPrice.d.ts +7 -0
  89. package/dist/cdn/src/shared/ui/Checkbox/Checkbox.d.ts +4 -0
  90. package/dist/cdn/src/shared/ui/CustomButton/CustomButton.d.ts +6 -0
  91. package/dist/cdn/src/shared/ui/CustomSidebar/CustomSidebar.d.ts +8 -0
  92. package/dist/cdn/src/shared/ui/Dialog/Dialog.d.ts +19 -0
  93. package/dist/cdn/src/shared/ui/Hint/Hint.d.ts +12 -0
  94. package/dist/cdn/src/shared/ui/Label/Label.d.ts +7 -0
  95. package/dist/cdn/src/shared/ui/Loader/Loader.d.ts +9 -0
  96. package/dist/cdn/src/shared/ui/Markdown/MDWithAccordion.d.ts +10 -0
  97. package/dist/cdn/src/shared/ui/MaterialItem/MaterialItem.d.ts +8 -0
  98. package/dist/cdn/src/shared/ui/MultiSelect/MultiSelect.d.ts +20 -0
  99. package/dist/cdn/src/shared/ui/PopoverTooltip/InfoIcon.d.ts +1 -0
  100. package/dist/cdn/src/shared/ui/PopoverTooltip/PopoverTooltip.d.ts +11 -0
  101. package/dist/cdn/src/shared/ui/SingleSelect/SingleSelect.d.ts +18 -0
  102. package/dist/cdn/src/shared/ui/Slider/Slider.d.ts +11 -0
  103. package/dist/cdn/src/shared/ui/popover.d.ts +9 -0
  104. package/dist/cdn/src/shared/utils/cn.d.ts +2 -0
  105. package/dist/cdn/src/shared/utils/uniqueList.d.ts +1 -0
  106. package/dist/components/SwatchesModule.d.ts +11 -0
  107. package/dist/main.cjs +408 -0
  108. package/dist/main.cjs.map +1 -0
  109. package/dist/main.d.ts +4 -0
  110. package/dist/main.js +64272 -0
  111. package/dist/main.js.map +1 -0
  112. package/dist/store/LibraryProvider.d.ts +4 -0
  113. package/dist/store/rootReducer.d.ts +11 -0
  114. package/dist/store/store.d.ts +25 -0
  115. package/dist/store/withStore.d.ts +2 -0
  116. package/package.json +101 -101
  117. package/dist/assets/Poppins-Bold-2q5ngAVi.woff2 +0 -0
  118. package/dist/assets/Poppins-Bold-CQjaT_ws.woff +0 -0
  119. package/dist/assets/Poppins-Medium-DJwXWGyq.woff2 +0 -0
  120. package/dist/assets/Poppins-Medium-DOl3WpZ-.woff +0 -0
  121. package/dist/assets/Poppins-Regular-6u--lpAX.woff +0 -0
  122. package/dist/assets/Poppins-Regular-F7nXZSOf.woff2 +0 -0
  123. package/dist/assets/Poppins-SemiBold-CsrPp8BB.woff +0 -0
  124. package/dist/assets/Poppins-SemiBold-N83vw0ch.woff2 +0 -0
  125. package/dist/assets/index-DIjFz2lH.css +0 -1
  126. package/dist/assets/index-DPVw21HN.js +0 -210
  127. package/dist/assets/product_thumb-Bn1S8z9K.png +0 -0
  128. package/dist/index.html +0 -14
  129. /package/dist/{vite.svg → cdn/vite.svg} +0 -0
package/README.md CHANGED
@@ -1,290 +1,290 @@
1
- # hasting-swatchcart-module
2
-
3
- This module was created for implementation into clients applications
4
- There are two ways of using this module: `NPM` or `CDN`
5
-
6
- ## Installation
7
-
8
- ### NPM
9
-
10
- ```bash
11
- npm i hasting-swatchcart-module
12
- ```
13
-
14
- ### NPM usage
15
-
16
- ```js
17
- import { SwatchModule } from 'hasting-swatchcart-module';
18
-
19
- <SwatchModule
20
- isOpen={isOpenModule}
21
- uiDataType={'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT'}
22
- data={data}
23
- onToggleSidebar={handleOpenSidebar}
24
- onSendData={handleSetData}
25
- />;
26
- ```
27
-
28
- ### CDN (no installation required) usage and installation
29
-
30
- ```html
31
- <link
32
- rel="stylesheet"
33
- href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
34
- />
35
- <body>
36
- <div id="root"></div>
37
- <script type="module">
38
- import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
39
-
40
- const rootElement = document.getElementById('root');
41
-
42
- const handleToggleSidebar = () => {
43
- // handleToggleSidebar
44
- };
45
-
46
- const handleSendData = (selectedData) => {
47
- // handleSendData
48
- };
49
-
50
- // UI (attributes from outside) - single product
51
- // mountSwatchModule(rootElement, {
52
- // isOpen: true,
53
- // uiDataType: 'UI',
54
- // data: mockData, // or your data
55
- // onToggleSidebar: handleToggleSidebar,
56
- // onSendData: handleSendData,
57
- // });
58
-
59
- // Fetch product data - single product
60
- mountSwatchModule(rootElement, {
61
- isOpen: true,
62
- uiDataType: 'FETCH_DATA_PRODUCT',
63
- assetId: '67119b1c-36ba-42c1-bcd1-2d21cf44df55',
64
- onToggleSidebar: handleToggleSidebar,
65
- onSendData: handleSendData,
66
- });
67
- </script>
68
- </body>
69
- ```
70
-
71
- ## Props
72
-
73
- ```ts
74
- export interface IAttributeAsset {
75
- assetType: string;
76
- blacklist: unknown[];
77
- defaultValue: { assetId: string; type: string }[];
78
- disabledValues: unknown[];
79
- enabled: boolean;
80
- global: {
81
- defaultValue: { assetId: string; type: string };
82
- id: string;
83
- metadata: unknown[];
84
- name: string;
85
- type: string;
86
- };
87
- hiddenValues: unknown[];
88
- id: string;
89
- label: string;
90
- metadata: {
91
- [key: string]: string;
92
- };
93
- name: string;
94
- type: string;
95
- value: {
96
- assetId: string;
97
- configuration: unknown;
98
- metadata: { [key: string]: string };
99
- name: string;
100
- tags: string[];
101
- type: string;
102
- };
103
- values: IAttributeAssetValues[];
104
- visible: boolean;
105
- }
106
- ```
107
-
108
- | Prop | Type | Required | Description |
109
- | --------------- | -------------------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------- |
110
- | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
111
- | uiDataType | 'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT' or 'FETCH_DATA_PRODUCT' or 'FETCH_DATA_ALL' | Yes | Defines type data mode. Rendered data depends on this parameter |
112
- | data | IAttributeAsset[] | Yes | Array of attributes data. Passed to the module to render swatch cards. |
113
- | onToggleSidebar | void | Yes | This method uses for open/close this module. |
114
- | onSendData | () => selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
115
-
116
- ## Development
117
-
118
- ```bash
119
- git clone https://github.com/Elementals-technical/hasting-swatchcart-module.git
120
- cd hasting-swatchcart-module
121
- npm install
122
- npm run dev
123
- ```
124
-
125
- ### General Information
126
-
127
- This project gives a module which can be implemented in two ways `NPM`, `CDN`.
128
-
129
- **_IMPORTANT_** before pushing code to the git repo, husky runs this scripts for checking `error/warnings`. If your scripts din't finish, check the console for more information
130
-
131
- ```bash
132
- npm run build:all
133
- npx lint-staged
134
- ```
135
-
136
- ### Stack
137
-
138
- - react
139
- - RTK
140
- - css/tailwind
141
- - vite
142
- - husky
143
- - lint
144
- - FSD as architecture base
145
-
146
- ### Testing CDN Usage Locally
147
-
148
- 1. **Build**
149
- If a `dist` folder `doesn't exist`, use this command for making it.
150
-
151
- ```bash
152
- npm run build:all
153
- ```
154
-
155
- If a `dist` folder `exist`, use this command for making it.
156
-
157
- ```bash
158
- npm run build:cdn
159
- ```
160
-
161
- 2. **Test with local files** - Create an HTML file and use local paths:
162
-
163
- ```html
164
- <link rel="stylesheet" href="../dist/cdn/main.css" />
165
- <script type="module">
166
- // Test locally
167
- import { mountSwatchModule } from '../dist/cdn/main.js';
168
-
169
- const rootElement = document.getElementById('root');
170
- const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
171
- const mockData = await fetch(jsonUrl).then((r) => r.json());
172
-
173
- const handleToggleSidebar = () => {
174
- console.log("handleToggleSidebar is working");
175
- }
176
-
177
- const handleSendData = (selectedData) => {
178
- console.log("handleSendData is working", selectedData);
179
- }
180
-
181
- mountSwatchModule(rootElement, {
182
- isOpen: true,
183
- uiDataType: 'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT',
184
- data: mockData,
185
- onToggleSidebar: handleToggleSidebar,
186
- onSendData: handleSendData,
187
- });
188
- </script>
189
- ```
190
-
191
- 3. **Test with CDN** - Use the published CDN version:
192
-
193
- ```html
194
- <!-- Test real CDN -->
195
- <link
196
- rel="stylesheet"
197
- href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
198
- />
199
-
200
- <div id="root"></div>
201
- <script type="module">
202
- // Test real CDN
203
- import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
204
-
205
- // local JSON data
206
- const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
207
- const mockData = await fetch(jsonUrl).then((r) => r.json());
208
-
209
- const rootElement = document.getElementById('root'); <script type="module">
210
- // Test locally
211
- import { mountSwatchModule } from '../dist/cdn/main.js';
212
-
213
- // Test real CDN
214
- // import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
215
-
216
- // local JSON data
217
- const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
218
- const mockData = await fetch(jsonUrl).then((r) => r.json());
219
-
220
- const rootElement = document.getElementById('root');
221
-
222
- const handleToggleSidebar = () => {
223
- console.log('handleToggleSidebar');
224
- };
225
-
226
- const handleSendData = (selectedData) => {
227
- console.log('handleSendData', selectedData);
228
- };
229
-
230
- // UI (attributes from outside) - single product
231
- // mountSwatchModule(rootElement, {
232
- // isOpen: true,
233
- // uiDataType: 'UI',
234
- // data: mockData, // or your data
235
- // onToggleSidebar: handleToggleSidebar,
236
- // onSendData: handleSendData,
237
- // });
238
-
239
- // Fetch product data - single product
240
- mountSwatchModule(rootElement, {
241
- isOpen: true,
242
- uiDataType: 'FETCH_DATA_PRODUCT',
243
- assetId: '67119b1c-36ba-42c1-bcd1-2d21cf44df55',
244
- onToggleSidebar: handleToggleSidebar,
245
- onSendData: handleSendData,
246
- });
247
- </script>
248
- ```
249
-
250
- ### Testing Module Usage Locally
251
-
252
- 1. **Build**
253
-
254
- ```bash
255
- npm run build:lib
256
- ```
257
-
258
- 2. **Run Locally**
259
-
260
- After finishing `build` in the `src/App.ts`, import builded file from the builded folder
261
-
262
- ```js
263
- import { SwatchModule } from '../../dist/main'; // build module
264
- ```
265
-
266
- 3. **Use module**
267
-
268
- ```js
269
- <SwatchModule
270
- isOpen={isOpenModule}
271
- uiDataType={'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT'}
272
- data={data}
273
- onToggleSidebar={handleOpenSidebar}
274
- onSendData={handleSetData}
275
- />
276
- ```
277
-
278
- ## Publishing module
279
-
280
- Before Publishing you need to start
281
-
282
- ```bach
283
- npm run build:all
284
- ```
285
-
286
- Then
287
-
288
- ```bach
289
- npm publish
290
- ```
1
+ # hasting-swatchcart-module
2
+
3
+ This module was created for implementation into clients applications
4
+ There are two ways of using this module: `NPM` or `CDN`
5
+
6
+ ## Installation
7
+
8
+ ### NPM
9
+
10
+ ```bash
11
+ npm i hasting-swatchcart-module
12
+ ```
13
+
14
+ ### NPM usage
15
+
16
+ ```js
17
+ import { SwatchModule } from 'hasting-swatchcart-module';
18
+
19
+ <SwatchModule
20
+ isOpen={isOpenModule}
21
+ uiDataType={'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT'}
22
+ data={data}
23
+ onToggleSidebar={handleOpenSidebar}
24
+ onSendData={handleSetData}
25
+ />;
26
+ ```
27
+
28
+ ### CDN (no installation required) usage and installation
29
+
30
+ ```html
31
+ <link
32
+ rel="stylesheet"
33
+ href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
34
+ />
35
+ <body>
36
+ <div id="root"></div>
37
+ <script type="module">
38
+ import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
39
+
40
+ const rootElement = document.getElementById('root');
41
+
42
+ const handleToggleSidebar = () => {
43
+ // handleToggleSidebar
44
+ };
45
+
46
+ const handleSendData = (selectedData) => {
47
+ // handleSendData
48
+ };
49
+
50
+ // UI (attributes from outside) - single product
51
+ // mountSwatchModule(rootElement, {
52
+ // isOpen: true,
53
+ // uiDataType: 'UI',
54
+ // data: mockData, // or your data
55
+ // onToggleSidebar: handleToggleSidebar,
56
+ // onSendData: handleSendData,
57
+ // });
58
+
59
+ // Fetch product data - single product
60
+ mountSwatchModule(rootElement, {
61
+ isOpen: true,
62
+ uiDataType: 'FETCH_DATA_PRODUCT',
63
+ assetId: '67119b1c-36ba-42c1-bcd1-2d21cf44df55',
64
+ onToggleSidebar: handleToggleSidebar,
65
+ onSendData: handleSendData,
66
+ });
67
+ </script>
68
+ </body>
69
+ ```
70
+
71
+ ## Props
72
+
73
+ ```ts
74
+ export interface IAttributeAsset {
75
+ assetType: string;
76
+ blacklist: unknown[];
77
+ defaultValue: { assetId: string; type: string }[];
78
+ disabledValues: unknown[];
79
+ enabled: boolean;
80
+ global: {
81
+ defaultValue: { assetId: string; type: string };
82
+ id: string;
83
+ metadata: unknown[];
84
+ name: string;
85
+ type: string;
86
+ };
87
+ hiddenValues: unknown[];
88
+ id: string;
89
+ label: string;
90
+ metadata: {
91
+ [key: string]: string;
92
+ };
93
+ name: string;
94
+ type: string;
95
+ value: {
96
+ assetId: string;
97
+ configuration: unknown;
98
+ metadata: { [key: string]: string };
99
+ name: string;
100
+ tags: string[];
101
+ type: string;
102
+ };
103
+ values: IAttributeAssetValues[];
104
+ visible: boolean;
105
+ }
106
+ ```
107
+
108
+ | Prop | Type | Required | Description |
109
+ | --------------- | -------------------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------- |
110
+ | isOpen | boolean | Yes | Controls visibility of the module (module state). true → module is visible. |
111
+ | uiDataType | 'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT' or 'FETCH_DATA_PRODUCT' or 'FETCH_DATA_ALL' | Yes | Defines type data mode. Rendered data depends on this parameter |
112
+ | data | IAttributeAsset[] | Yes | Array of attributes data. Passed to the module to render swatch cards. |
113
+ | onToggleSidebar | void | Yes | This method uses for open/close this module. |
114
+ | onSendData | () => selected materials array from a cart | Yes | Callback that returns selected materials from the cart back to the parent Application. |
115
+
116
+ ## Development
117
+
118
+ ```bash
119
+ git clone https://github.com/Elementals-technical/hasting-swatchcart-module.git
120
+ cd hasting-swatchcart-module
121
+ npm install
122
+ npm run dev
123
+ ```
124
+
125
+ ### General Information
126
+
127
+ This project gives a module which can be implemented in two ways `NPM`, `CDN`.
128
+
129
+ **_IMPORTANT_** before pushing code to the git repo, husky runs this scripts for checking `error/warnings`. If your scripts din't finish, check the console for more information
130
+
131
+ ```bash
132
+ npm run build:all
133
+ npx lint-staged
134
+ ```
135
+
136
+ ### Stack
137
+
138
+ - react
139
+ - RTK
140
+ - css/tailwind
141
+ - vite
142
+ - husky
143
+ - lint
144
+ - FSD as architecture base
145
+
146
+ ### Testing CDN Usage Locally
147
+
148
+ 1. **Build**
149
+ If a `dist` folder `doesn't exist`, use this command for making it.
150
+
151
+ ```bash
152
+ npm run build:all
153
+ ```
154
+
155
+ If a `dist` folder `exist`, use this command for making it.
156
+
157
+ ```bash
158
+ npm run build:cdn
159
+ ```
160
+
161
+ 2. **Test with local files** - Create an HTML file and use local paths:
162
+
163
+ ```html
164
+ <link rel="stylesheet" href="../dist/cdn/main.css" />
165
+ <script type="module">
166
+ // Test locally
167
+ import { mountSwatchModule } from '../dist/cdn/main.js';
168
+
169
+ const rootElement = document.getElementById('root');
170
+ const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
171
+ const mockData = await fetch(jsonUrl).then((r) => r.json());
172
+
173
+ const handleToggleSidebar = () => {
174
+ console.log("handleToggleSidebar is working");
175
+ }
176
+
177
+ const handleSendData = (selectedData) => {
178
+ console.log("handleSendData is working", selectedData);
179
+ }
180
+
181
+ mountSwatchModule(rootElement, {
182
+ isOpen: true,
183
+ uiDataType: 'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT',
184
+ data: mockData,
185
+ onToggleSidebar: handleToggleSidebar,
186
+ onSendData: handleSendData,
187
+ });
188
+ </script>
189
+ ```
190
+
191
+ 3. **Test with CDN** - Use the published CDN version:
192
+
193
+ ```html
194
+ <!-- Test real CDN -->
195
+ <link
196
+ rel="stylesheet"
197
+ href="https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.css"
198
+ />
199
+
200
+ <div id="root"></div>
201
+ <script type="module">
202
+ // Test real CDN
203
+ import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
204
+
205
+ // local JSON data
206
+ const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
207
+ const mockData = await fetch(jsonUrl).then((r) => r.json());
208
+
209
+ const rootElement = document.getElementById('root'); <script type="module">
210
+ // Test locally
211
+ import { mountSwatchModule } from '../dist/cdn/main.js';
212
+
213
+ // Test real CDN
214
+ // import { mountSwatchModule } from 'https://unpkg.com/hasting-swatchcart-module/dist/cdn/main.js';
215
+
216
+ // local JSON data
217
+ const jsonUrl = new URL('./mockAttribute.json', import.meta.url);
218
+ const mockData = await fetch(jsonUrl).then((r) => r.json());
219
+
220
+ const rootElement = document.getElementById('root');
221
+
222
+ const handleToggleSidebar = () => {
223
+ console.log('handleToggleSidebar');
224
+ };
225
+
226
+ const handleSendData = (selectedData) => {
227
+ console.log('handleSendData', selectedData);
228
+ };
229
+
230
+ // UI (attributes from outside) - single product
231
+ // mountSwatchModule(rootElement, {
232
+ // isOpen: true,
233
+ // uiDataType: 'UI',
234
+ // data: mockData, // or your data
235
+ // onToggleSidebar: handleToggleSidebar,
236
+ // onSendData: handleSendData,
237
+ // });
238
+
239
+ // Fetch product data - single product
240
+ mountSwatchModule(rootElement, {
241
+ isOpen: true,
242
+ uiDataType: 'FETCH_DATA_PRODUCT',
243
+ assetId: '67119b1c-36ba-42c1-bcd1-2d21cf44df55',
244
+ onToggleSidebar: handleToggleSidebar,
245
+ onSendData: handleSendData,
246
+ });
247
+ </script>
248
+ ```
249
+
250
+ ### Testing Module Usage Locally
251
+
252
+ 1. **Build**
253
+
254
+ ```bash
255
+ npm run build:lib
256
+ ```
257
+
258
+ 2. **Run Locally**
259
+
260
+ After finishing `build` in the `src/App.ts`, import builded file from the builded folder
261
+
262
+ ```js
263
+ import { SwatchModule } from '../../dist/main'; // build module
264
+ ```
265
+
266
+ 3. **Use module**
267
+
268
+ ```js
269
+ <SwatchModule
270
+ isOpen={isOpenModule}
271
+ uiDataType={'UI' or 'DATA_INPUT' or 'DATA_ALL_PRODUCT'}
272
+ data={data}
273
+ onToggleSidebar={handleOpenSidebar}
274
+ onSendData={handleSetData}
275
+ />
276
+ ```
277
+
278
+ ## Publishing module
279
+
280
+ Before Publishing you need to start
281
+
282
+ ```bach
283
+ npm run build:all
284
+ ```
285
+
286
+ Then
287
+
288
+ ```bach
289
+ npm publish
290
+ ```