@faststore/core 22.42.6

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 (475) hide show
  1. package/.babelrc +4 -0
  2. package/.editorconfig +13 -0
  3. package/.eslintignore +8 -0
  4. package/.eslintrc +21 -0
  5. package/.github/CODEOWNERS +2 -0
  6. package/.github/workflows/release.yml +40 -0
  7. package/.husky/pre-commit +4 -0
  8. package/.prettierignore +8 -0
  9. package/.prettierrc +1 -0
  10. package/.release-it.json +31 -0
  11. package/.storybook/components/BestPractices.tsx +18 -0
  12. package/.storybook/components/BestPracticesRule.tsx +43 -0
  13. package/.storybook/components/Callout.tsx +12 -0
  14. package/.storybook/components/SectionItem.tsx +44 -0
  15. package/.storybook/components/SectionList.tsx +27 -0
  16. package/.storybook/components/TokenDivider.tsx +12 -0
  17. package/.storybook/components/TokenRow.tsx +32 -0
  18. package/.storybook/components/TokenTable.tsx +33 -0
  19. package/.storybook/components/index.ts +8 -0
  20. package/.storybook/main.js +59 -0
  21. package/.storybook/manager-head.html +9 -0
  22. package/.storybook/manager.js +6 -0
  23. package/.storybook/mocks/cart-sidebar.js +40 -0
  24. package/.storybook/mocks/filter-slider.js +59 -0
  25. package/.storybook/mocks/index.ts +5 -0
  26. package/.storybook/mocks/product.ts +67 -0
  27. package/.storybook/mocks/productGridItems.ts +334 -0
  28. package/.storybook/mocks/searchHistory.ts +8 -0
  29. package/.storybook/mocks/searchTerms.ts +5 -0
  30. package/.storybook/preview-head.html +1 -0
  31. package/.storybook/preview.js +89 -0
  32. package/.storybook/storybook.css +550 -0
  33. package/.storybook/theme.js +21 -0
  34. package/.stylelintignore +1 -0
  35. package/.vscode/settings.json +7 -0
  36. package/@generated/graphql/index.ts +1133 -0
  37. package/@generated/graphql/persisted.json +12 -0
  38. package/CHANGELOG.md +730 -0
  39. package/LICENSE +21 -0
  40. package/README.md +437 -0
  41. package/bun.lockb +0 -0
  42. package/cms/content-types.json +52 -0
  43. package/cms/sections.json +350 -0
  44. package/cms/translation-keys.json +1 -0
  45. package/cms-webhook-urls.json +5 -0
  46. package/codegen.yml +22 -0
  47. package/cypress/fixtures/example.json +5 -0
  48. package/cypress/global.js +15 -0
  49. package/cypress/integration/a11y.test.js +45 -0
  50. package/cypress/integration/analytics.test.js +381 -0
  51. package/cypress/integration/cart.test.js +100 -0
  52. package/cypress/integration/performance.test.js +65 -0
  53. package/cypress/integration/plp.test.js +224 -0
  54. package/cypress/integration/search.test.js +38 -0
  55. package/cypress/integration/seo.test.js +318 -0
  56. package/cypress/plugins/index.js +41 -0
  57. package/cypress/support/commands.js +70 -0
  58. package/cypress/support/index.js +3 -0
  59. package/cypress.json +9 -0
  60. package/lighthouserc.js +22 -0
  61. package/next-env.d.ts +5 -0
  62. package/next.config.js +35 -0
  63. package/package.json +114 -0
  64. package/postcss.config.js +5 -0
  65. package/public/brandless-negative.png +0 -0
  66. package/public/brandless-neutral.png +0 -0
  67. package/public/brandless-positive.png +0 -0
  68. package/public/brandless-storybook.png +0 -0
  69. package/public/favicon.ico +0 -0
  70. package/public/icons.svg +58 -0
  71. package/public/logo.svg +42 -0
  72. package/public/mockServiceWorker.js +367 -0
  73. package/public/robots.txt +5 -0
  74. package/pull_request_template.md +37 -0
  75. package/renovate.json +5 -0
  76. package/src/Layout.tsx +51 -0
  77. package/src/components/ThirdPartyScripts/GoogleTagManager.tsx +61 -0
  78. package/src/components/ThirdPartyScripts/ThirdPartyScripts.tsx +37 -0
  79. package/src/components/ThirdPartyScripts/index.ts +1 -0
  80. package/src/components/ThirdPartyScripts/vtex.tsx +23 -0
  81. package/src/components/cart/CartItem/CartItem.stories.mdx +134 -0
  82. package/src/components/cart/CartItem/CartItem.tsx +158 -0
  83. package/src/components/cart/CartItem/cart-item.module.scss +68 -0
  84. package/src/components/cart/CartItem/index.ts +1 -0
  85. package/src/components/cart/CartSidebar/CartSidebar.stories.mdx +119 -0
  86. package/src/components/cart/CartSidebar/CartSidebar.tsx +140 -0
  87. package/src/components/cart/CartSidebar/cart-sidebar.module.scss +69 -0
  88. package/src/components/cart/CartSidebar/index.ts +1 -0
  89. package/src/components/cart/CartToggle/CartToggle.tsx +20 -0
  90. package/src/components/cart/CartToggle/index.ts +1 -0
  91. package/src/components/cart/EmptyCart/EmptyCart.tsx +26 -0
  92. package/src/components/cart/EmptyCart/index.ts +1 -0
  93. package/src/components/cart/OrderSummary/OrderSummary.tsx +39 -0
  94. package/src/components/cart/OrderSummary/index.ts +1 -0
  95. package/src/components/cart/OrderSummary/order-summary.module.scss +22 -0
  96. package/src/components/cms/RenderPageSections.tsx +52 -0
  97. package/src/components/cms/SectionBoundary.tsx +34 -0
  98. package/src/components/common/Alert/Alert.tsx +53 -0
  99. package/src/components/common/Alert/index.ts +1 -0
  100. package/src/components/common/Footer/Footer.stories.mdx +158 -0
  101. package/src/components/common/Footer/Footer.tsx +160 -0
  102. package/src/components/common/Footer/FooterLinks.tsx +155 -0
  103. package/src/components/common/Footer/footer.module.scss +246 -0
  104. package/src/components/common/Footer/index.ts +2 -0
  105. package/src/components/common/Navbar/NavLinks.stories.mdx +122 -0
  106. package/src/components/common/Navbar/NavLinks.tsx +58 -0
  107. package/src/components/common/Navbar/Navbar.stories.mdx +179 -0
  108. package/src/components/common/Navbar/Navbar.tsx +97 -0
  109. package/src/components/common/Navbar/NavbarSlider.stories.mdx +108 -0
  110. package/src/components/common/Navbar/NavbarSlider.tsx +62 -0
  111. package/src/components/common/Navbar/index.ts +3 -0
  112. package/src/components/common/Navbar/navbar-slider.module.scss +60 -0
  113. package/src/components/common/Navbar/navbar.module.scss +204 -0
  114. package/src/components/common/Navbar/navlinks.module.scss +96 -0
  115. package/src/components/common/Toast/Toast.tsx +40 -0
  116. package/src/components/common/Toast/index.ts +1 -0
  117. package/src/components/product/OutOfStock/OutOfStock.stories.mdx +127 -0
  118. package/src/components/product/OutOfStock/OutOfStock.tsx +134 -0
  119. package/src/components/product/OutOfStock/index.ts +2 -0
  120. package/src/components/product/OutOfStock/out-of-stock.module.scss +55 -0
  121. package/src/components/product/ProductCard/ProductCard.stories.mdx +412 -0
  122. package/src/components/product/ProductCard/ProductCard.tsx +170 -0
  123. package/src/components/product/ProductCard/index.ts +2 -0
  124. package/src/components/product/ProductCard/product-card.module.scss +254 -0
  125. package/src/components/product/ProductGrid/ProductGrid.stories.mdx +97 -0
  126. package/src/components/product/ProductGrid/ProductGrid.tsx +37 -0
  127. package/src/components/product/ProductGrid/index.ts +1 -0
  128. package/src/components/product/ProductGrid/product-grid.module.scss +39 -0
  129. package/src/components/regionalization/Regionalization.stories.mdx +182 -0
  130. package/src/components/regionalization/RegionalizationBar/RegionalizationBar.stories.mdx +116 -0
  131. package/src/components/regionalization/RegionalizationBar/RegionalizationBar.tsx +40 -0
  132. package/src/components/regionalization/RegionalizationBar/index.ts +1 -0
  133. package/src/components/regionalization/RegionalizationBar/regionalization-bar.module.scss +56 -0
  134. package/src/components/regionalization/RegionalizationButton/RegionalizationButton.tsx +24 -0
  135. package/src/components/regionalization/RegionalizationButton/index.ts +1 -0
  136. package/src/components/regionalization/RegionalizationInput/RegionalizationInput.tsx +61 -0
  137. package/src/components/regionalization/RegionalizationInput/index.ts +1 -0
  138. package/src/components/regionalization/RegionalizationModal/RegionalizationModal.stories.mdx +161 -0
  139. package/src/components/regionalization/RegionalizationModal/RegionalizationModal.tsx +13 -0
  140. package/src/components/regionalization/RegionalizationModal/RegionalizationModalContent.tsx +48 -0
  141. package/src/components/regionalization/RegionalizationModal/index.ts +2 -0
  142. package/src/components/regionalization/RegionalizationModal/regionalization-modal-content.module.scss +79 -0
  143. package/src/components/search/Filter/Facets.stories.mdx +284 -0
  144. package/src/components/search/Filter/Facets.tsx +136 -0
  145. package/src/components/search/Filter/Filter.stories.mdx +209 -0
  146. package/src/components/search/Filter/Filter.tsx +91 -0
  147. package/src/components/search/Filter/FilterSlider.stories.mdx +226 -0
  148. package/src/components/search/Filter/FilterSlider.tsx +109 -0
  149. package/src/components/search/Filter/facets.module.scss +117 -0
  150. package/src/components/search/Filter/filter-slider.module.scss +63 -0
  151. package/src/components/search/Filter/index.ts +2 -0
  152. package/src/components/search/Filter/useFilter.ts +131 -0
  153. package/src/components/search/Search.stories.mdx +169 -0
  154. package/src/components/search/SearchDropdown/SearchDropdown.stories.mdx +62 -0
  155. package/src/components/search/SearchDropdown/SearchDropdown.tsx +44 -0
  156. package/src/components/search/SearchDropdown/index.ts +2 -0
  157. package/src/components/search/SearchHistory/SearchHistory.stories.mdx +59 -0
  158. package/src/components/search/SearchHistory/SearchHistory.tsx +51 -0
  159. package/src/components/search/SearchHistory/index.ts +1 -0
  160. package/src/components/search/SearchInput/SearchInput.stories.mdx +205 -0
  161. package/src/components/search/SearchInput/SearchInput.tsx +128 -0
  162. package/src/components/search/SearchInput/index.ts +2 -0
  163. package/src/components/search/SearchInput/search-input.module.scss +153 -0
  164. package/src/components/search/SearchProductCard/SearchProductCard.stories.mdx +96 -0
  165. package/src/components/search/SearchProductCard/SearchProductCard.tsx +103 -0
  166. package/src/components/search/SearchProductCard/index.ts +1 -0
  167. package/src/components/search/SearchProductCard/search-product-card.module.scss +54 -0
  168. package/src/components/search/SearchSharedTokenTable.mdx +98 -0
  169. package/src/components/search/SearchSuggestions/SearchSuggestions.stories.mdx +58 -0
  170. package/src/components/search/SearchSuggestions/SearchSuggestions.tsx +136 -0
  171. package/src/components/search/SearchSuggestions/index.ts +2 -0
  172. package/src/components/search/SearchTop/SearchTop.stories.mdx +58 -0
  173. package/src/components/search/SearchTop/SearchTop.tsx +78 -0
  174. package/src/components/search/SearchTop/index.ts +2 -0
  175. package/src/components/search/Sort/Sort.tsx +42 -0
  176. package/src/components/search/Sort/index.ts +1 -0
  177. package/src/components/search/search.module.scss +101 -0
  178. package/src/components/search/searchMock.ts +48 -0
  179. package/src/components/sections/BannerNewsletter/BannerNewsletter.tsx +28 -0
  180. package/src/components/sections/BannerNewsletter/banner-newsletter.module.scss +23 -0
  181. package/src/components/sections/BannerText/BannerText.stories.mdx +270 -0
  182. package/src/components/sections/BannerText/BannerText.tsx +87 -0
  183. package/src/components/sections/BannerText/banner-text.module.scss +127 -0
  184. package/src/components/sections/BannerText/index.ts +2 -0
  185. package/src/components/sections/Breadcrumb/Breadcrumb.tsx +24 -0
  186. package/src/components/sections/Breadcrumb/index.ts +1 -0
  187. package/src/components/sections/Hero/Hero.stories.mdx +277 -0
  188. package/src/components/sections/Hero/Hero.tsx +109 -0
  189. package/src/components/sections/Hero/hero.module.scss +180 -0
  190. package/src/components/sections/Hero/index.ts +2 -0
  191. package/src/components/sections/Incentives/Incentives.stories.mdx +159 -0
  192. package/src/components/sections/Incentives/Incentives.tsx +69 -0
  193. package/src/components/sections/Incentives/IncentivesFooter.tsx +8 -0
  194. package/src/components/sections/Incentives/IncentivesHeader.tsx +23 -0
  195. package/src/components/sections/Incentives/incentives.module.scss +122 -0
  196. package/src/components/sections/Incentives/incentivesMock.ts +55 -0
  197. package/src/components/sections/Incentives/index.ts +2 -0
  198. package/src/components/sections/Newsletter/Newsletter.stories.mdx +139 -0
  199. package/src/components/sections/Newsletter/Newsletter.tsx +151 -0
  200. package/src/components/sections/Newsletter/index.ts +2 -0
  201. package/src/components/sections/Newsletter/newsletter.module.scss +135 -0
  202. package/src/components/sections/ProducDetailsContent/ProductDetailsContent.stories.mdx +66 -0
  203. package/src/components/sections/ProducDetailsContent/ProductDetailsContent.tsx +278 -0
  204. package/src/components/sections/ProducDetailsContent/index.ts +1 -0
  205. package/src/components/sections/ProducDetailsContent/product-details-content.module.scss +50 -0
  206. package/src/components/sections/ProductDetails/ProductDetails.tsx +316 -0
  207. package/src/components/sections/ProductDetails/index.ts +1 -0
  208. package/src/components/sections/ProductDetails/product-details.module.scss +194 -0
  209. package/src/components/sections/ProductGallery/EmptyGallery.tsx +38 -0
  210. package/src/components/sections/ProductGallery/ProductGallery.tsx +186 -0
  211. package/src/components/sections/ProductGallery/ProductGalleryPage.tsx +70 -0
  212. package/src/components/sections/ProductGallery/index.ts +1 -0
  213. package/src/components/sections/ProductGallery/product-gallery.module.scss +184 -0
  214. package/src/components/sections/ProductGallery/useDelayedFacets.ts +18 -0
  215. package/src/components/sections/ProductGallery/useDelayedPagination.ts +16 -0
  216. package/src/components/sections/ProductGallery/useGalleryQuery.ts +58 -0
  217. package/src/components/sections/ProductGallery/usePageProducts.ts +48 -0
  218. package/src/components/sections/ProductShelf/ProductShelf.tsx +68 -0
  219. package/src/components/sections/ProductShelf/index.ts +1 -0
  220. package/src/components/sections/ProductShelf/product-shelf.module.scss +41 -0
  221. package/src/components/sections/ProductTiles/ProductTiles.tsx +83 -0
  222. package/src/components/sections/ProductTiles/index.ts +1 -0
  223. package/src/components/sections/ScrollToTopButton/ScrollToTopButton.tsx +45 -0
  224. package/src/components/sections/ScrollToTopButton/index.ts +1 -0
  225. package/src/components/sections/ScrollToTopButton/scroll-to-top-button.module.scss +12 -0
  226. package/src/components/sections/Section/Section.tsx +15 -0
  227. package/src/components/sections/Section/index.ts +1 -0
  228. package/src/components/sections/Section/section.scss +16 -0
  229. package/src/components/skeletons/FilterSkeleton/FilterSkeleton.stories.mdx +97 -0
  230. package/src/components/skeletons/FilterSkeleton/FilterSkeleton.tsx +34 -0
  231. package/src/components/skeletons/FilterSkeleton/filter-skeleton.module.scss +51 -0
  232. package/src/components/skeletons/FilterSkeleton/index.ts +1 -0
  233. package/src/components/skeletons/ProductCardSkeleton/ProductCardSkeleton.stories.mdx +176 -0
  234. package/src/components/skeletons/ProductCardSkeleton/ProductCardSkeleton.tsx +52 -0
  235. package/src/components/skeletons/ProductCardSkeleton/index.ts +1 -0
  236. package/src/components/skeletons/ProductCardSkeleton/product-card-skeleton.module.scss +97 -0
  237. package/src/components/skeletons/ProductGridSkeleton/ProductGridSkeleton.tsx +29 -0
  238. package/src/components/skeletons/ProductGridSkeleton/index.ts +1 -0
  239. package/src/components/skeletons/ProductShelfSkeleton/ProductShelfSkeleton.tsx +32 -0
  240. package/src/components/skeletons/ProductShelfSkeleton/index.ts +1 -0
  241. package/src/components/skeletons/ProductTilesSkeleton/ProductTileSkeleton/ProductTileSkeleton.tsx +57 -0
  242. package/src/components/skeletons/ProductTilesSkeleton/ProductTileSkeleton/index.ts +1 -0
  243. package/src/components/skeletons/ProductTilesSkeleton/ProductTileSkeleton/product-tile-skeleton.module.scss +218 -0
  244. package/src/components/skeletons/ProductTilesSkeleton/ProductTilesSkeleton.tsx +33 -0
  245. package/src/components/skeletons/ProductTilesSkeleton/index.ts +2 -0
  246. package/src/components/skeletons/Shimmer/Shimmer.tsx +11 -0
  247. package/src/components/skeletons/Shimmer/index.ts +1 -0
  248. package/src/components/skeletons/Shimmer/shimmer.module.scss +43 -0
  249. package/src/components/skeletons/Skeleton/Skeleton.tsx +49 -0
  250. package/src/components/skeletons/Skeleton/index.ts +1 -0
  251. package/src/components/skeletons/Skeleton/skeleton.module.scss +77 -0
  252. package/src/components/skeletons/Skeletons.stories.mdx +178 -0
  253. package/src/components/ui/Accordion/Accordion.stories.mdx +219 -0
  254. package/src/components/ui/Accordion/Accordion.tsx +39 -0
  255. package/src/components/ui/Accordion/AccordionItem.stories.mdx +116 -0
  256. package/src/components/ui/Accordion/AccordionItem.tsx +82 -0
  257. package/src/components/ui/Accordion/accordion.module.scss +65 -0
  258. package/src/components/ui/Accordion/index.ts +2 -0
  259. package/src/components/ui/Alert/Alert.stories.mdx +164 -0
  260. package/src/components/ui/Alert/Alert.tsx +78 -0
  261. package/src/components/ui/Alert/alert.module.scss +93 -0
  262. package/src/components/ui/Alert/index.ts +1 -0
  263. package/src/components/ui/Badge/Badge.stories.mdx +465 -0
  264. package/src/components/ui/Badge/Badge.tsx +76 -0
  265. package/src/components/ui/Badge/DiscountBadge.stories.mdx +191 -0
  266. package/src/components/ui/Badge/DiscountBadge.tsx +57 -0
  267. package/src/components/ui/Badge/badge.module.scss +252 -0
  268. package/src/components/ui/Badge/index.ts +4 -0
  269. package/src/components/ui/Breadcrumb/Breadcrumb.stories.mdx +197 -0
  270. package/src/components/ui/Breadcrumb/Breadcrumb.tsx +122 -0
  271. package/src/components/ui/Breadcrumb/breadcrumb.module.scss +144 -0
  272. package/src/components/ui/Breadcrumb/index.ts +2 -0
  273. package/src/components/ui/Button/Button.stories.mdx +685 -0
  274. package/src/components/ui/Button/Button.tsx +85 -0
  275. package/src/components/ui/Button/ButtonBuy/ButtonBuy.tsx +24 -0
  276. package/src/components/ui/Button/ButtonBuy/index.ts +1 -0
  277. package/src/components/ui/Button/ButtonLink/ButtonLink.tsx +49 -0
  278. package/src/components/ui/Button/ButtonLink/ButtonSignIn/ButtonSignIn.tsx +22 -0
  279. package/src/components/ui/Button/ButtonLink/ButtonSignIn/ButtonSignInFallback/ButtonSignInFallback.tsx +18 -0
  280. package/src/components/ui/Button/ButtonLink/ButtonSignIn/ButtonSignInFallback/index.ts +1 -0
  281. package/src/components/ui/Button/ButtonLink/ButtonSignIn/index.ts +1 -0
  282. package/src/components/ui/Button/ButtonLink/index.ts +1 -0
  283. package/src/components/ui/Button/button.module.scss +392 -0
  284. package/src/components/ui/Button/index.ts +6 -0
  285. package/src/components/ui/Checkbox/Checkbox.stories.mdx +268 -0
  286. package/src/components/ui/Checkbox/Checkbox.tsx +20 -0
  287. package/src/components/ui/Checkbox/checkbox.module.scss +157 -0
  288. package/src/components/ui/Checkbox/index.ts +2 -0
  289. package/src/components/ui/Dropdown/Dropdown.stories.mdx +232 -0
  290. package/src/components/ui/Dropdown/Dropdown.tsx +12 -0
  291. package/src/components/ui/Dropdown/DropdownButton.tsx +20 -0
  292. package/src/components/ui/Dropdown/DropdownItem.stories.mdx +139 -0
  293. package/src/components/ui/Dropdown/DropdownItem.tsx +26 -0
  294. package/src/components/ui/Dropdown/DropdownMenu.stories.mdx +115 -0
  295. package/src/components/ui/Dropdown/DropdownMenu.tsx +34 -0
  296. package/src/components/ui/Dropdown/dropdown.module.scss +101 -0
  297. package/src/components/ui/Dropdown/index.ts +4 -0
  298. package/src/components/ui/EmptyState/EmptyState.stories.mdx +146 -0
  299. package/src/components/ui/EmptyState/EmptyState.tsx +26 -0
  300. package/src/components/ui/EmptyState/empty-state.module.scss +63 -0
  301. package/src/components/ui/EmptyState/index.ts +1 -0
  302. package/src/components/ui/Gift/Gift.stories.mdx +99 -0
  303. package/src/components/ui/Gift/Gift.tsx +76 -0
  304. package/src/components/ui/Gift/gift.module.scss +94 -0
  305. package/src/components/ui/Gift/index.ts +2 -0
  306. package/src/components/ui/Icon/Icon.tsx +35 -0
  307. package/src/components/ui/Icon/index.ts +1 -0
  308. package/src/components/ui/Image/Image.tsx +59 -0
  309. package/src/components/ui/Image/index.ts +1 -0
  310. package/src/components/ui/Image/thumborUrlBuilder.ts +101 -0
  311. package/src/components/ui/Image/useImage.ts +46 -0
  312. package/src/components/ui/ImageGallery/ImageGallery.stories.mdx +173 -0
  313. package/src/components/ui/ImageGallery/ImageGallery.tsx +51 -0
  314. package/src/components/ui/ImageGallery/ImageGallerySelector.tsx +116 -0
  315. package/src/components/ui/ImageGallery/ImageZoom.tsx +12 -0
  316. package/src/components/ui/ImageGallery/image-gallery-selector.module.scss +131 -0
  317. package/src/components/ui/ImageGallery/image-gallery.module.scss +56 -0
  318. package/src/components/ui/ImageGallery/index.ts +4 -0
  319. package/src/components/ui/InputText/InputText.stories.mdx +311 -0
  320. package/src/components/ui/InputText/InputText.tsx +128 -0
  321. package/src/components/ui/InputText/index.ts +2 -0
  322. package/src/components/ui/InputText/input-text.module.scss +168 -0
  323. package/src/components/ui/Link/Link.stories.mdx +272 -0
  324. package/src/components/ui/Link/Link.tsx +68 -0
  325. package/src/components/ui/Link/index.ts +2 -0
  326. package/src/components/ui/Link/link.module.scss +98 -0
  327. package/src/components/ui/Logo/Logo.tsx +14 -0
  328. package/src/components/ui/Logo/index.ts +1 -0
  329. package/src/components/ui/Logo/logo.module.scss +12 -0
  330. package/src/components/ui/Modal/Modal.stories.mdx +142 -0
  331. package/src/components/ui/Modal/Modal.tsx +43 -0
  332. package/src/components/ui/Modal/index.ts +1 -0
  333. package/src/components/ui/Modal/modal.module.scss +46 -0
  334. package/src/components/ui/Price/Price.stories.mdx +194 -0
  335. package/src/components/ui/Price/Price.tsx +32 -0
  336. package/src/components/ui/Price/index.ts +1 -0
  337. package/src/components/ui/Price/price.module.scss +27 -0
  338. package/src/components/ui/PriceRange/PriceRange.stories.mdx +192 -0
  339. package/src/components/ui/PriceRange/PriceRange.tsx +138 -0
  340. package/src/components/ui/PriceRange/index.ts +1 -0
  341. package/src/components/ui/PriceRange/price-range.module.scss +176 -0
  342. package/src/components/ui/ProductTitle/ProductTitle.stories.mdx +107 -0
  343. package/src/components/ui/ProductTitle/ProductTitle.tsx +11 -0
  344. package/src/components/ui/ProductTitle/index.ts +1 -0
  345. package/src/components/ui/ProductTitle/product-title.module.scss +48 -0
  346. package/src/components/ui/QuantitySelector/QuantitySelector.stories.mdx +246 -0
  347. package/src/components/ui/QuantitySelector/QuantitySelector.tsx +103 -0
  348. package/src/components/ui/QuantitySelector/index.ts +1 -0
  349. package/src/components/ui/QuantitySelector/quantity-selector.module.scss +160 -0
  350. package/src/components/ui/Radio/Radio.stories.mdx +237 -0
  351. package/src/components/ui/Radio/Radio.tsx +36 -0
  352. package/src/components/ui/Radio/index.ts +2 -0
  353. package/src/components/ui/Radio/radio.module.scss +122 -0
  354. package/src/components/ui/SROnly/SROnly.tsx +20 -0
  355. package/src/components/ui/SROnly/index.ts +1 -0
  356. package/src/components/ui/SROnly/sr-only.module.scss +15 -0
  357. package/src/components/ui/Select/Select.stories.mdx +168 -0
  358. package/src/components/ui/Select/Select.tsx +70 -0
  359. package/src/components/ui/Select/index.ts +2 -0
  360. package/src/components/ui/Select/select.module.scss +85 -0
  361. package/src/components/ui/ShippingSimulation/ShippingSimulation.stories.mdx +140 -0
  362. package/src/components/ui/ShippingSimulation/ShippingSimulation.tsx +109 -0
  363. package/src/components/ui/ShippingSimulation/index.ts +1 -0
  364. package/src/components/ui/ShippingSimulation/shipping-simulation.module.scss +96 -0
  365. package/src/components/ui/ShippingSimulation/useShippingSimulation.ts +225 -0
  366. package/src/components/ui/SkuSelector/Selectors.stories.mdx +82 -0
  367. package/src/components/ui/SkuSelector/Selectors.tsx +87 -0
  368. package/src/components/ui/SkuSelector/SkuSelector.stories.mdx +345 -0
  369. package/src/components/ui/SkuSelector/SkuSelector.tsx +46 -0
  370. package/src/components/ui/SkuSelector/index.ts +3 -0
  371. package/src/components/ui/SkuSelector/sku-selector.module.scss +172 -0
  372. package/src/components/ui/SkuSelector/skuVariants.ts +59 -0
  373. package/src/components/ui/SlideOver/SlideOver.stories.mdx +285 -0
  374. package/src/components/ui/SlideOver/SlideOver.tsx +58 -0
  375. package/src/components/ui/SlideOver/index.ts +1 -0
  376. package/src/components/ui/SlideOver/overlay.scss +14 -0
  377. package/src/components/ui/SlideOver/slide-over.module.scss +63 -0
  378. package/src/components/ui/Tiles/Tiles.stories.mdx +153 -0
  379. package/src/components/ui/Tiles/Tiles.tsx +14 -0
  380. package/src/components/ui/Tiles/index.ts +5 -0
  381. package/src/components/ui/Tiles/tiles.module.scss +60 -0
  382. package/src/components/ui/Toast/Toast.stories.mdx +158 -0
  383. package/src/components/ui/Toast/Toast.tsx +56 -0
  384. package/src/components/ui/Toast/index.ts +1 -0
  385. package/src/components/ui/Toast/toast.module.scss +112 -0
  386. package/src/components/ui/Toggle/Toggle.stories.mdx +604 -0
  387. package/src/components/ui/Toggle/Toggle.tsx +75 -0
  388. package/src/components/ui/Toggle/index.ts +2 -0
  389. package/src/components/ui/Toggle/toggle.module.scss +200 -0
  390. package/src/constants.ts +2 -0
  391. package/src/fonts/WebFonts.tsx +15 -0
  392. package/src/images/icon.png +0 -0
  393. package/src/pages/404.tsx +27 -0
  394. package/src/pages/500.tsx +31 -0
  395. package/src/pages/[...slug].tsx +186 -0
  396. package/src/pages/[slug]/p.tsx +209 -0
  397. package/src/pages/_app.tsx +38 -0
  398. package/src/pages/_document.tsx +22 -0
  399. package/src/pages/account.tsx +20 -0
  400. package/src/pages/api/graphql.ts +72 -0
  401. package/src/pages/api/preview.ts +61 -0
  402. package/src/pages/checkout.tsx +20 -0
  403. package/src/pages/index.tsx +72 -0
  404. package/src/pages/login.tsx +20 -0
  405. package/src/pages/s.tsx +83 -0
  406. package/src/sdk/analytics/hooks/useViewItemListEvent.ts +51 -0
  407. package/src/sdk/analytics/index.tsx +30 -0
  408. package/src/sdk/analytics/platform/vtex/index.ts +11 -0
  409. package/src/sdk/analytics/platform/vtex/search.ts +102 -0
  410. package/src/sdk/analytics/types.ts +22 -0
  411. package/src/sdk/cart/index.ts +187 -0
  412. package/src/sdk/cart/useBuyButton.ts +62 -0
  413. package/src/sdk/cart/useCartToggleButton.ts +23 -0
  414. package/src/sdk/cart/useCheckoutButton.ts +22 -0
  415. package/src/sdk/cart/useRemoveButton.ts +56 -0
  416. package/src/sdk/error/ErrorBoundary/ErrorBoundary.tsx +67 -0
  417. package/src/sdk/error/ErrorBoundary/index.ts +1 -0
  418. package/src/sdk/graphql/prefetchQuery.ts +20 -0
  419. package/src/sdk/graphql/request.ts +25 -0
  420. package/src/sdk/graphql/useLazyQuery.ts +29 -0
  421. package/src/sdk/graphql/useQuery.ts +40 -0
  422. package/src/sdk/newsletter/useNewsletter.ts +31 -0
  423. package/src/sdk/product/useDiscountPercent.ts +10 -0
  424. package/src/sdk/product/useFormattedPrice.ts +27 -0
  425. package/src/sdk/product/useProduct.ts +46 -0
  426. package/src/sdk/product/useProductLink.ts +69 -0
  427. package/src/sdk/product/useProductsQuery.ts +107 -0
  428. package/src/sdk/search/Sentinel.tsx +78 -0
  429. package/src/sdk/search/state.ts +11 -0
  430. package/src/sdk/search/useSearchHistory.ts +40 -0
  431. package/src/sdk/search/useSearchInput.tsx +43 -0
  432. package/src/sdk/search/useSuggestions.ts +49 -0
  433. package/src/sdk/search/useTopSearch.ts +49 -0
  434. package/src/sdk/session/index.ts +71 -0
  435. package/src/sdk/tests/mark.tsx +10 -0
  436. package/src/sdk/ui/Provider.tsx +151 -0
  437. package/src/sdk/ui/useFadeEffect.ts +21 -0
  438. package/src/sdk/ui/useOnClickOutside.ts +39 -0
  439. package/src/sdk/ui/useScrollDirection.ts +31 -0
  440. package/src/sdk/useStore.ts +24 -0
  441. package/src/server/cms.ts +66 -0
  442. package/src/server/index.ts +105 -0
  443. package/src/stories/brandless.stories.mdx +85 -0
  444. package/src/stories/changelog-template.stories.mdx +10 -0
  445. package/src/stories/colors.stories.mdx +306 -0
  446. package/src/stories/customizing.stories.mdx +113 -0
  447. package/src/stories/getting-started.stories.mdx +65 -0
  448. package/src/stories/grid-layout.stories.mdx +53 -0
  449. package/src/stories/icons.stories.mdx +237 -0
  450. package/src/stories/interactive-controls.stories.mdx +50 -0
  451. package/src/stories/midnight.stories.mdx +56 -0
  452. package/src/stories/refinements.stories.mdx +96 -0
  453. package/src/stories/soft-blue.stories.mdx +56 -0
  454. package/src/stories/spacing.stories.mdx +38 -0
  455. package/src/stories/typography.stories.mdx +224 -0
  456. package/src/styles/global/components.scss +5 -0
  457. package/src/styles/global/layout.scss +80 -0
  458. package/src/styles/global/resets.scss +48 -0
  459. package/src/styles/global/storybook-components.scss +5 -0
  460. package/src/styles/global/tokens.scss +276 -0
  461. package/src/styles/global/typography.scss +66 -0
  462. package/src/styles/global/utilities.scss +69 -0
  463. package/src/styles/scaffold.scss +7 -0
  464. package/src/styles/themes/custom-theme.scss +36 -0
  465. package/src/styles/themes/midnight.scss +123 -0
  466. package/src/styles/themes/soft-blue.scss +79 -0
  467. package/src/styles/vendors/include-media.scss +4 -0
  468. package/src/styles/vendors/include-media_overwrite.scss +9 -0
  469. package/src/styles/vendors/modern-normalize.css +270 -0
  470. package/src/typings/global.d.ts +6 -0
  471. package/src/typings/module.css.d.ts +7 -0
  472. package/store.config.js +69 -0
  473. package/stylelint.config.js +82 -0
  474. package/tsconfig.json +25 -0
  475. package/vtex.env +14 -0
@@ -0,0 +1,187 @@
1
+ import { gql } from '@faststore/graphql-utils'
2
+ import { createCartStore } from '@faststore/sdk'
3
+ import { useMemo } from 'react'
4
+ import type { Cart as SDKCart, CartItem as SDKCartItem } from '@faststore/sdk'
5
+
6
+ import type {
7
+ CartItemFragment,
8
+ CartMessageFragment,
9
+ IStoreOffer,
10
+ ValidateCartMutationMutation,
11
+ ValidateCartMutationMutationVariables,
12
+ } from '@generated/graphql'
13
+
14
+ import { request } from '../graphql/request'
15
+ import { sessionStore } from '../session'
16
+ import { createValidationStore, useStore } from '../useStore'
17
+
18
+ export interface CartItem extends SDKCartItem, CartItemFragment {}
19
+
20
+ export interface Cart extends SDKCart<CartItem> {
21
+ messages?: CartMessageFragment[]
22
+ }
23
+
24
+ export const ValidateCartMutation = gql`
25
+ mutation ValidateCartMutation($cart: IStoreCart!, $session: IStoreSession!) {
26
+ validateCart(cart: $cart, session: $session) {
27
+ order {
28
+ orderNumber
29
+ acceptedOffer {
30
+ ...CartItem
31
+ }
32
+ }
33
+ messages {
34
+ ...CartMessage
35
+ }
36
+ }
37
+ }
38
+
39
+ fragment CartMessage on StoreCartMessage {
40
+ text
41
+ status
42
+ }
43
+
44
+ fragment CartItem on StoreOffer {
45
+ seller {
46
+ identifier
47
+ }
48
+ quantity
49
+ price
50
+ listPrice
51
+ itemOffered {
52
+ ...CartProductItem
53
+ }
54
+ }
55
+
56
+ fragment CartProductItem on StoreProduct {
57
+ sku
58
+ name
59
+ image {
60
+ url
61
+ alternateName
62
+ }
63
+ brand {
64
+ name
65
+ }
66
+ isVariantOf {
67
+ productGroupID
68
+ name
69
+ }
70
+ gtin
71
+ additionalProperty {
72
+ propertyID
73
+ name
74
+ value
75
+ valueReference
76
+ }
77
+ }
78
+ `
79
+
80
+ const isGift = (item: CartItem) => item.price === 0
81
+
82
+ const getItemId = (item: Pick<CartItem, 'itemOffered' | 'seller' | 'price'>) =>
83
+ [
84
+ item.itemOffered.sku,
85
+ item.seller.identifier,
86
+ item.itemOffered.additionalProperty
87
+ ?.map(({ propertyID }) => propertyID)
88
+ .join('-'),
89
+ ]
90
+ .filter(Boolean)
91
+ .join('::')
92
+
93
+ const validateCart = async (cart: Cart): Promise<Cart | null> => {
94
+ const { validateCart: validated = null } = await request<
95
+ ValidateCartMutationMutation,
96
+ ValidateCartMutationMutationVariables
97
+ >(ValidateCartMutation, {
98
+ session: sessionStore.read(),
99
+ cart: {
100
+ order: {
101
+ orderNumber: cart.id,
102
+ acceptedOffer: cart.items.map(
103
+ ({
104
+ price,
105
+ listPrice,
106
+ seller,
107
+ quantity,
108
+ itemOffered,
109
+ }): IStoreOffer => ({
110
+ price,
111
+ listPrice,
112
+ seller,
113
+ quantity,
114
+ itemOffered: {
115
+ sku: itemOffered.sku,
116
+ image: itemOffered.image,
117
+ name: itemOffered.name,
118
+ additionalProperty: itemOffered.additionalProperty,
119
+ },
120
+ })
121
+ ),
122
+ },
123
+ },
124
+ })
125
+
126
+ return (
127
+ validated && {
128
+ id: validated.order.orderNumber,
129
+ items: validated.order.acceptedOffer.map((item) => ({
130
+ ...item,
131
+ id: getItemId(item),
132
+ })),
133
+ messages: validated.messages,
134
+ }
135
+ )
136
+ }
137
+
138
+ const [validationStore, onValidate] = createValidationStore(validateCart)
139
+ const defaultCartStore = createCartStore<Cart>(
140
+ {
141
+ id: '',
142
+ items: [],
143
+ messages: [],
144
+ },
145
+ onValidate
146
+ )
147
+
148
+ export const cartStore = {
149
+ ...defaultCartStore,
150
+ addItem: (item: Omit<CartItem, 'id'>) => {
151
+ const cartItem = {
152
+ ...item,
153
+ id: getItemId(item),
154
+ }
155
+
156
+ defaultCartStore.addItem(cartItem)
157
+ },
158
+ }
159
+
160
+ export const useCart = () => {
161
+ const cart = useStore(cartStore)
162
+ const isValidating = useStore(validationStore)
163
+
164
+ return useMemo(
165
+ () => ({
166
+ ...cart,
167
+ isValidating,
168
+ messages: cart.messages,
169
+ gifts: cart.items.filter((item) => isGift(item)),
170
+ items: cart.items.filter((item) => !isGift(item)),
171
+ totalUniqueItems: cart.items.length,
172
+ totalItems: cart.items.reduce(
173
+ (acc, curr) => acc + (isGift(curr) ? 0 : curr.quantity),
174
+ 0
175
+ ),
176
+ total: cart.items.reduce(
177
+ (acc, curr) => acc + curr.price * curr.quantity,
178
+ 0
179
+ ),
180
+ subTotal: cart.items.reduce(
181
+ (acc, curr) => acc + curr.listPrice * curr.quantity,
182
+ 0
183
+ ),
184
+ }),
185
+ [cart, isValidating]
186
+ )
187
+ }
@@ -0,0 +1,62 @@
1
+ import { sendAnalyticsEvent } from '@faststore/sdk'
2
+ import { useCallback } from 'react'
3
+ import type { CurrencyCode, AddToCartEvent } from '@faststore/sdk'
4
+
5
+ import type { AnalyticsItem } from 'src/sdk/analytics/types'
6
+ import type { CartItem } from 'src/sdk/cart'
7
+
8
+ import { useSession } from '../session'
9
+ import { useUI } from '../ui/Provider'
10
+ import { cartStore } from './index'
11
+
12
+ export const useBuyButton = (item: CartItem | null) => {
13
+ const { openCart } = useUI()
14
+ const {
15
+ currency: { code },
16
+ } = useSession()
17
+
18
+ const onClick = useCallback(
19
+ (e: React.MouseEvent<HTMLButtonElement>) => {
20
+ e.preventDefault()
21
+
22
+ if (!item) {
23
+ return
24
+ }
25
+
26
+ sendAnalyticsEvent<AddToCartEvent<AnalyticsItem>>({
27
+ name: 'add_to_cart',
28
+ params: {
29
+ currency: code as CurrencyCode,
30
+ // TODO: In the future, we can explore more robust ways of
31
+ // calculating the value (gift items, discounts, etc.).
32
+ value: item.price * item.quantity,
33
+ items: [
34
+ {
35
+ item_id: item.itemOffered.isVariantOf.productGroupID,
36
+ item_name: item.itemOffered.isVariantOf.name,
37
+ item_brand: item.itemOffered.brand.name,
38
+ item_variant: item.itemOffered.sku,
39
+ quantity: item.quantity,
40
+ price: item.price,
41
+ discount: item.listPrice - item.price,
42
+ currency: code as CurrencyCode,
43
+ item_variant_name: item.itemOffered.name,
44
+ product_reference_id: item.itemOffered.gtin,
45
+ },
46
+ ],
47
+ },
48
+ })
49
+
50
+ cartStore.addItem(item)
51
+ openCart()
52
+ },
53
+ [code, item, openCart]
54
+ )
55
+
56
+ return {
57
+ onClick,
58
+ 'data-testid': 'buy-button',
59
+ 'data-sku': item?.itemOffered.sku,
60
+ 'data-seller': item?.seller.identifier,
61
+ }
62
+ }
@@ -0,0 +1,23 @@
1
+ import { useCallback } from 'react'
2
+
3
+ import { useUI } from '../ui/Provider'
4
+ import { useCart } from './index'
5
+
6
+ export const useCartToggleButton = () => {
7
+ const { totalItems } = useCart()
8
+ const { cart: displayCart, openCart, closeCart } = useUI()
9
+
10
+ const onClick = useCallback(() => {
11
+ if (displayCart) {
12
+ closeCart()
13
+ } else {
14
+ openCart()
15
+ }
16
+ }, [closeCart, displayCart, openCart])
17
+
18
+ return {
19
+ onClick,
20
+ 'data-testid': 'cart-toggle',
21
+ 'data-items': totalItems,
22
+ }
23
+ }
@@ -0,0 +1,22 @@
1
+ import { useCart } from './index'
2
+ import * as storeConfig from '../../../store.config'
3
+
4
+ const { checkoutUrl } = storeConfig
5
+
6
+ export const useCheckoutButton = () => {
7
+ const { isValidating, id } = useCart()
8
+
9
+ const onClick = (e: React.MouseEvent<HTMLButtonElement>) => {
10
+ e.preventDefault()
11
+
12
+ if (!isValidating && id) {
13
+ window.location.href = `${checkoutUrl}?orderFormId=${id}`
14
+ }
15
+ }
16
+
17
+ return {
18
+ onClick,
19
+ disabled: isValidating,
20
+ 'data-testid': 'checkout-button',
21
+ }
22
+ }
@@ -0,0 +1,56 @@
1
+ import { sendAnalyticsEvent } from '@faststore/sdk'
2
+ import { useCallback } from 'react'
3
+ import type { CurrencyCode, RemoveFromCartEvent } from '@faststore/sdk'
4
+
5
+ import type { AnalyticsItem } from 'src/sdk/analytics/types'
6
+
7
+ import { useSession } from '../session'
8
+ import { cartStore } from './index'
9
+ import type { CartItem } from '.'
10
+
11
+ export const useRemoveButton = (item: CartItem | null) => {
12
+ const {
13
+ currency: { code },
14
+ } = useSession()
15
+
16
+ const onClick = useCallback(
17
+ (e: React.MouseEvent<HTMLButtonElement>) => {
18
+ e.preventDefault()
19
+
20
+ if (!item) {
21
+ return
22
+ }
23
+
24
+ sendAnalyticsEvent<RemoveFromCartEvent<AnalyticsItem>>({
25
+ name: 'remove_from_cart',
26
+ params: {
27
+ currency: code as CurrencyCode,
28
+ value: item.price * item.quantity, // TODO: In the future, we can explore more robust ways of calculating the value (gift items, discounts, etc.).
29
+ items: [
30
+ {
31
+ item_id: item.itemOffered.isVariantOf.productGroupID,
32
+ item_name: item.itemOffered.isVariantOf.name,
33
+ item_brand: item.itemOffered.brand.name,
34
+ item_variant: item.itemOffered.sku,
35
+ quantity: item.quantity,
36
+ price: item.price,
37
+ discount: item.listPrice - item.price,
38
+ currency: code as CurrencyCode,
39
+ item_variant_name: item.itemOffered.name,
40
+ product_reference_id: item.itemOffered.gtin,
41
+ },
42
+ ],
43
+ },
44
+ })
45
+
46
+ cartStore.removeItem(item.id)
47
+ },
48
+ [code, item]
49
+ )
50
+
51
+ return {
52
+ onClick,
53
+ 'data-testid': 'remove-from-cart-button',
54
+ 'data-sku': item?.itemOffered.sku,
55
+ }
56
+ }
@@ -0,0 +1,67 @@
1
+ import { Component } from 'react'
2
+ import type { ErrorInfo, ReactNode } from 'react'
3
+
4
+ const getReloads = () =>
5
+ Number(window.sessionStorage.getItem('store:reloads') ?? '0')
6
+
7
+ const setReloads = (reloads: number) =>
8
+ window.sessionStorage.setItem('store:reloads', `${reloads}`)
9
+
10
+ const canRecover = () => getReloads() < 2
11
+
12
+ const isFrameworkLevelError = (error: Error) => error?.name === 'ChunkLoadError'
13
+
14
+ if (typeof window !== 'undefined') {
15
+ window.setInterval(() => setReloads(0), 30e3)
16
+ }
17
+
18
+ class ErrorBoundary extends Component<{ children: ReactNode }> {
19
+ public state = { hasError: false, error: null }
20
+
21
+ public static getDerivedStateFromError(error: Error) {
22
+ return {
23
+ hasError: true,
24
+ error,
25
+ }
26
+ }
27
+
28
+ // We can't accurately type the error here, since it could vary depending on
29
+ // what caused it. This is not standardized.
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ public componentDidCatch(error: any, errorInfo: ErrorInfo) {
32
+ console.error(`React Error: ${error.message} ${errorInfo.componentStack}`)
33
+
34
+ const errorId = 'unknown'
35
+
36
+ // prevent infinite loop
37
+ if (
38
+ window.location.pathname.startsWith('/404') ||
39
+ window.location.pathname.startsWith('/500')
40
+ ) {
41
+ return
42
+ }
43
+
44
+ const from = encodeURIComponent(window.location.pathname)
45
+
46
+ const is404 = error?.extensions?.exception?.status === 404
47
+
48
+ if (isFrameworkLevelError(error) && canRecover()) {
49
+ setReloads(getReloads() + 1)
50
+ window.location.reload()
51
+ } else if (is404) {
52
+ window.location.href = `/404?from=${from}`
53
+ } else {
54
+ window.location.href = `/500?from=${from}&errorId=${errorId}`
55
+ }
56
+ }
57
+
58
+ public render() {
59
+ if (this.state.hasError && process.env.NODE_ENV === 'production') {
60
+ return null
61
+ }
62
+
63
+ return this.props.children
64
+ }
65
+ }
66
+
67
+ export default ErrorBoundary
@@ -0,0 +1 @@
1
+ export { default } from './ErrorBoundary'
@@ -0,0 +1,20 @@
1
+ import { mutate } from 'swr'
2
+ import type { Cache } from 'swr'
3
+
4
+ import { request } from './request'
5
+ import { getKey } from './useQuery'
6
+ import type { RequestOptions } from './request'
7
+
8
+ export const prefetchQuery = <Data, Variables = Record<string, unknown>>(
9
+ operationName: string,
10
+ variables: Variables,
11
+ { cache, ...options }: Partial<RequestOptions> & { cache: Cache }
12
+ ) => {
13
+ const key = getKey(operationName, variables)
14
+
15
+ if (cache.get(key)) {
16
+ return
17
+ }
18
+
19
+ mutate(key, request<Data, Variables>(operationName, variables, options))
20
+ }
@@ -0,0 +1,25 @@
1
+ import { request as baseRequest } from '@faststore/graphql-utils'
2
+ import type { RequestOptions as GraphQLRequestOptions } from '@faststore/graphql-utils'
3
+
4
+ export type RequestOptions = Omit<
5
+ GraphQLRequestOptions,
6
+ 'operationName' | 'variables'
7
+ >
8
+
9
+ export const request = async <Query = unknown, Variables = unknown>(
10
+ operationName: string,
11
+ variables: Variables,
12
+ options?: RequestOptions
13
+ ) => {
14
+ const { data, errors } = await baseRequest<Variables, Query>('/api/graphql', {
15
+ ...options,
16
+ variables,
17
+ operationName,
18
+ })
19
+
20
+ if (errors?.length) {
21
+ throw errors[0]
22
+ }
23
+
24
+ return data
25
+ }
@@ -0,0 +1,29 @@
1
+ import useSWR from 'swr'
2
+
3
+ import { request } from './request'
4
+ import { DEFAULT_OPTIONS, getKey } from './useQuery'
5
+ import type { QueryOptions } from './useQuery'
6
+
7
+ export const useLazyQuery = <Data, Variables = Record<string, unknown>>(
8
+ operationName: string,
9
+ variables: Variables,
10
+ options?: QueryOptions
11
+ ) => {
12
+ const response = useSWR<Data | null>(
13
+ getKey(operationName, variables),
14
+ () => null,
15
+ DEFAULT_OPTIONS
16
+ )
17
+
18
+ const execute = async (queryVariables: Variables) => {
19
+ const data = await request<Data, Variables>(
20
+ operationName,
21
+ queryVariables,
22
+ options
23
+ )
24
+
25
+ response.mutate(data, false)
26
+ }
27
+
28
+ return [execute, response] as [typeof execute, typeof response]
29
+ }
@@ -0,0 +1,40 @@
1
+ import useSWR from 'swr'
2
+ import type { SWRConfiguration } from 'swr'
3
+
4
+ import { request } from './request'
5
+ import type { RequestOptions } from './request'
6
+
7
+ export type QueryOptions = SWRConfiguration & RequestOptions
8
+
9
+ export const getKey = <Variables>(
10
+ operationName: string,
11
+ variables: Variables
12
+ ) => `${operationName}::${JSON.stringify(variables)}`
13
+
14
+ export const DEFAULT_OPTIONS = {
15
+ errorRetryCount: 3,
16
+ refreshWhenHidden: false,
17
+ refreshWhenOffline: false,
18
+ revalidateOnFocus: false,
19
+ revalidateOnReconnect: false,
20
+ shouldRetryOnError: true,
21
+ }
22
+
23
+ export const useQuery = <Data, Variables = Record<string, unknown>>(
24
+ operationName: string,
25
+ variables: Variables,
26
+ options?: QueryOptions
27
+ ) =>
28
+ useSWR<Data>(getKey(operationName, variables), {
29
+ fetcher: () => {
30
+ return new Promise((resolve) => {
31
+ setTimeout(async () => {
32
+ resolve(
33
+ await request<Data, Variables>(operationName, variables, options)
34
+ )
35
+ })
36
+ })
37
+ },
38
+ ...DEFAULT_OPTIONS,
39
+ ...options,
40
+ })
@@ -0,0 +1,31 @@
1
+ import { gql } from '@faststore/graphql-utils'
2
+
3
+ import type {
4
+ SubscribeToNewsletterMutation as Mutation,
5
+ SubscribeToNewsletterMutationVariables as Variables,
6
+ } from '../../../@generated/graphql/index'
7
+ import { useLazyQuery } from '../graphql/useLazyQuery'
8
+
9
+ export const mutation = gql`
10
+ mutation SubscribeToNewsletter($data: IPersonNewsletter!) {
11
+ subscribeToNewsletter(data: $data) {
12
+ id
13
+ }
14
+ }
15
+ `
16
+
17
+ export const useNewsletter = () => {
18
+ const [subscribeUser, { data, error, isValidating: loading }] = useLazyQuery<
19
+ Mutation,
20
+ Variables
21
+ >(mutation, {
22
+ data: { name: '', email: '' },
23
+ })
24
+
25
+ return {
26
+ subscribeUser,
27
+ data,
28
+ error,
29
+ loading,
30
+ }
31
+ }
@@ -0,0 +1,10 @@
1
+ import { useMemo } from 'react'
2
+
3
+ export const useDiscountPercent = (listPrice: number, spotPrice: number) => {
4
+ return useMemo(() => {
5
+ const diff = listPrice - spotPrice
6
+ const discount = (diff * 100) / listPrice
7
+
8
+ return Math.round(discount)
9
+ }, [spotPrice, listPrice])
10
+ }
@@ -0,0 +1,27 @@
1
+ import { useCallback, useMemo } from 'react'
2
+
3
+ import { useSession } from '../session'
4
+
5
+ interface PriceFormatterOptions {
6
+ decimals?: boolean
7
+ }
8
+
9
+ export const usePriceFormatter = ({ decimals }: PriceFormatterOptions = {}) => {
10
+ const { currency, locale } = useSession()
11
+
12
+ return useCallback(
13
+ (price: number) =>
14
+ Intl.NumberFormat(locale, {
15
+ style: 'currency',
16
+ currency: currency.code,
17
+ minimumFractionDigits: decimals ? 2 : 0,
18
+ }).format(price),
19
+ [currency.code, locale, decimals]
20
+ )
21
+ }
22
+
23
+ export const useFormattedPrice = (price: number) => {
24
+ const formatter = usePriceFormatter()
25
+
26
+ return useMemo(() => formatter(price), [formatter, price])
27
+ }
@@ -0,0 +1,46 @@
1
+ import { gql } from '@faststore/graphql-utils'
2
+ import { useMemo } from 'react'
3
+
4
+ import type {
5
+ BrowserProductQueryQuery,
6
+ BrowserProductQueryQueryVariables,
7
+ } from '@generated/graphql'
8
+
9
+ import { useQuery } from '../graphql/useQuery'
10
+ import { useSession } from '../session'
11
+
12
+ const query = gql`
13
+ query BrowserProductQuery($locator: [IStoreSelectedFacet!]!) {
14
+ product(locator: $locator) {
15
+ ...ProductDetailsFragment_product
16
+ }
17
+ }
18
+ `
19
+
20
+ export const useProduct = <T extends BrowserProductQueryQuery>(
21
+ productID: string,
22
+ fallbackData?: T
23
+ ) => {
24
+ const { channel, locale } = useSession()
25
+ const variables = useMemo(() => {
26
+ if (!channel) {
27
+ throw new Error(`useProduct: 'channel' from session is an empty string.`)
28
+ }
29
+
30
+ return {
31
+ locator: [
32
+ { key: 'id', value: productID },
33
+ { key: 'channel', value: channel },
34
+ { key: 'locale', value: locale },
35
+ ],
36
+ }
37
+ }, [channel, locale, productID])
38
+
39
+ return useQuery<
40
+ BrowserProductQueryQuery & T,
41
+ BrowserProductQueryQueryVariables
42
+ >(query, variables, {
43
+ fallbackData,
44
+ revalidateOnMount: true,
45
+ })
46
+ }