@redneckz/wildless-cms-uni-blocks 0.6.41 → 0.6.42

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 (233) hide show
  1. package/bundle/blocks.schema.json +1 -1
  2. package/bundle/bundle.umd.js +130 -32
  3. package/bundle/bundle.umd.min.js +1 -1
  4. package/bundle/components/CarouselRecommendationCard/CarouselRecommendationCard.d.ts +5 -0
  5. package/bundle/components/CarouselRecommendationCard/CarouselRecommendationCardContent.d.ts +44 -0
  6. package/bundle/components/Header/HeaderSecondaryMenu.d.ts +2 -0
  7. package/bundle/hooks/useCachedAsyncData.d.ts +2 -0
  8. package/bundle/hooks/useLocation.d.ts +6 -0
  9. package/bundle/hooks/useRegions.d.ts +6 -0
  10. package/bundle/services/sitemap/SitemapProps.d.ts +8 -0
  11. package/bundle/ui-kit/Location/Location.d.ts +19 -0
  12. package/bundle/ui-kit/Location/SearchBar.d.ts +6 -0
  13. package/bundle/utils/groupBy.d.ts +1 -0
  14. package/dist/components/Blocks.js +4 -2
  15. package/dist/components/Blocks.js.map +1 -1
  16. package/dist/components/CarouselRecommendationCard/CarouselRecommendationCard.d.ts +5 -0
  17. package/dist/components/CarouselRecommendationCard/CarouselRecommendationCard.js +22 -0
  18. package/dist/components/CarouselRecommendationCard/CarouselRecommendationCard.js.map +1 -0
  19. package/dist/components/CarouselRecommendationCard/CarouselRecommendationCardContent.d.ts +44 -0
  20. package/dist/components/CarouselRecommendationCard/CarouselRecommendationCardContent.js +2 -0
  21. package/dist/components/CarouselRecommendationCard/CarouselRecommendationCardContent.js.map +1 -0
  22. package/dist/components/Header/Header.js +2 -2
  23. package/dist/components/Header/Header.js.map +1 -1
  24. package/dist/components/Header/HeaderBurger.js +4 -3
  25. package/dist/components/Header/HeaderBurger.js.map +1 -1
  26. package/dist/components/Header/HeaderSecondaryMenu.d.ts +2 -0
  27. package/dist/components/Header/HeaderSecondaryMenu.js +13 -4
  28. package/dist/components/Header/HeaderSecondaryMenu.js.map +1 -1
  29. package/dist/components/Recommendation/RecommendationCard.js +1 -1
  30. package/dist/components/Recommendation/RecommendationCard.js.map +1 -1
  31. package/dist/hooks/useCachedAsyncData.d.ts +2 -0
  32. package/dist/hooks/useCachedAsyncData.js +25 -0
  33. package/dist/hooks/useCachedAsyncData.js.map +1 -0
  34. package/dist/hooks/useLocation.d.ts +6 -0
  35. package/dist/hooks/useLocation.js +26 -0
  36. package/dist/hooks/useLocation.js.map +1 -0
  37. package/dist/hooks/useRegions.d.ts +6 -0
  38. package/dist/hooks/useRegions.js +11 -0
  39. package/dist/hooks/useRegions.js.map +1 -0
  40. package/dist/services/sitemap/SitemapProps.d.ts +8 -0
  41. package/dist/ui-kit/Location/Location.d.ts +19 -0
  42. package/dist/ui-kit/Location/Location.js +44 -0
  43. package/dist/ui-kit/Location/Location.js.map +1 -0
  44. package/dist/ui-kit/Location/SearchBar.d.ts +6 -0
  45. package/dist/ui-kit/Location/SearchBar.js +9 -0
  46. package/dist/ui-kit/Location/SearchBar.js.map +1 -0
  47. package/dist/ui-kit/SwipeListControl/SwipeListContainer.js +8 -4
  48. package/dist/ui-kit/SwipeListControl/SwipeListContainer.js.map +1 -1
  49. package/dist/utils/groupBy.d.ts +1 -0
  50. package/dist/utils/groupBy.js +13 -0
  51. package/dist/utils/groupBy.js.map +1 -0
  52. package/lib/common.css +1 -1
  53. package/lib/components/Blocks.js +4 -2
  54. package/lib/components/Blocks.js.map +1 -1
  55. package/lib/components/Carousel/Carousel.fixture.d.ts +1 -0
  56. package/lib/components/CarouselRecommendationCard/CarouselRecommendationCard.d.ts +5 -0
  57. package/lib/components/CarouselRecommendationCard/CarouselRecommendationCard.fixture.d.ts +9 -0
  58. package/lib/components/CarouselRecommendationCard/CarouselRecommendationCard.js +20 -0
  59. package/lib/components/CarouselRecommendationCard/CarouselRecommendationCard.js.map +1 -0
  60. package/lib/components/CarouselRecommendationCard/CarouselRecommendationCardContent.d.ts +44 -0
  61. package/lib/components/CarouselRecommendationCard/CarouselRecommendationCardContent.js +2 -0
  62. package/lib/components/CarouselRecommendationCard/CarouselRecommendationCardContent.js.map +1 -0
  63. package/lib/components/Header/Header.js +2 -2
  64. package/lib/components/Header/Header.js.map +1 -1
  65. package/lib/components/Header/HeaderBurger.js +4 -3
  66. package/lib/components/Header/HeaderBurger.js.map +1 -1
  67. package/lib/components/Header/HeaderSecondaryMenu.d.ts +2 -0
  68. package/lib/components/Header/HeaderSecondaryMenu.js +13 -4
  69. package/lib/components/Header/HeaderSecondaryMenu.js.map +1 -1
  70. package/lib/components/Recommendation/Recommendation.fixture.d.ts +1 -1
  71. package/lib/components/Recommendation/RecommendationCard.js +1 -1
  72. package/lib/components/Recommendation/RecommendationCard.js.map +1 -1
  73. package/lib/hooks/useCachedAsyncData.d.ts +2 -0
  74. package/lib/hooks/useCachedAsyncData.js +22 -0
  75. package/lib/hooks/useCachedAsyncData.js.map +1 -0
  76. package/lib/hooks/useLocation.d.ts +6 -0
  77. package/lib/hooks/useLocation.js +23 -0
  78. package/lib/hooks/useLocation.js.map +1 -0
  79. package/lib/hooks/useRegions.d.ts +6 -0
  80. package/lib/hooks/useRegions.js +8 -0
  81. package/lib/hooks/useRegions.js.map +1 -0
  82. package/lib/services/sitemap/SitemapProps.d.ts +8 -0
  83. package/lib/ui-kit/Location/Location.d.ts +19 -0
  84. package/lib/ui-kit/Location/Location.fixture.d.ts +6 -0
  85. package/lib/ui-kit/Location/Location.js +42 -0
  86. package/lib/ui-kit/Location/Location.js.map +1 -0
  87. package/lib/ui-kit/Location/SearchBar.d.ts +6 -0
  88. package/lib/ui-kit/Location/SearchBar.js +7 -0
  89. package/lib/ui-kit/Location/SearchBar.js.map +1 -0
  90. package/lib/ui-kit/SwipeListControl/SwipeListContainer.js +8 -4
  91. package/lib/ui-kit/SwipeListControl/SwipeListContainer.js.map +1 -1
  92. package/lib/utils/groupBy.d.ts +1 -0
  93. package/lib/utils/groupBy.js +10 -0
  94. package/lib/utils/groupBy.js.map +1 -0
  95. package/mobile/bundle/bundle.umd.js +48 -20
  96. package/mobile/bundle/bundle.umd.min.js +1 -1
  97. package/mobile/bundle/components/CarouselRecommendationCard/CarouselRecommendationCard.d.ts +5 -0
  98. package/mobile/bundle/components/CarouselRecommendationCard/CarouselRecommendationCardContent.d.ts +44 -0
  99. package/mobile/bundle/components/Header/HeaderSecondaryMenu.d.ts +2 -0
  100. package/mobile/bundle/hooks/useCachedAsyncData.d.ts +2 -0
  101. package/mobile/bundle/hooks/useLocation.d.ts +6 -0
  102. package/mobile/bundle/hooks/useRegions.d.ts +6 -0
  103. package/mobile/bundle/services/sitemap/SitemapProps.d.ts +8 -0
  104. package/mobile/bundle/ui-kit/Location/Location.d.ts +19 -0
  105. package/mobile/bundle/ui-kit/Location/SearchBar.d.ts +6 -0
  106. package/mobile/bundle/utils/groupBy.d.ts +1 -0
  107. package/mobile/dist/components/CarouselRecommendationCard/CarouselRecommendationCard.d.ts +5 -0
  108. package/mobile/dist/components/CarouselRecommendationCard/CarouselRecommendationCard.js +22 -0
  109. package/mobile/dist/components/CarouselRecommendationCard/CarouselRecommendationCard.js.map +1 -0
  110. package/mobile/dist/components/CarouselRecommendationCard/CarouselRecommendationCardContent.d.ts +44 -0
  111. package/mobile/dist/components/CarouselRecommendationCard/CarouselRecommendationCardContent.js +2 -0
  112. package/mobile/dist/components/CarouselRecommendationCard/CarouselRecommendationCardContent.js.map +1 -0
  113. package/mobile/dist/components/Header/HeaderBurger.js +4 -3
  114. package/mobile/dist/components/Header/HeaderBurger.js.map +1 -1
  115. package/mobile/dist/components/Header/HeaderSecondaryMenu.d.ts +2 -0
  116. package/mobile/dist/components/Header/HeaderSecondaryMenu.js +13 -4
  117. package/mobile/dist/components/Header/HeaderSecondaryMenu.js.map +1 -1
  118. package/mobile/dist/components/Recommendation/RecommendationCard.js +1 -1
  119. package/mobile/dist/components/Recommendation/RecommendationCard.js.map +1 -1
  120. package/mobile/dist/hooks/useCachedAsyncData.d.ts +2 -0
  121. package/mobile/dist/hooks/useCachedAsyncData.js +25 -0
  122. package/mobile/dist/hooks/useCachedAsyncData.js.map +1 -0
  123. package/mobile/dist/hooks/useLocation.d.ts +6 -0
  124. package/mobile/dist/hooks/useLocation.js +26 -0
  125. package/mobile/dist/hooks/useLocation.js.map +1 -0
  126. package/mobile/dist/hooks/useRegions.d.ts +6 -0
  127. package/mobile/dist/hooks/useRegions.js +11 -0
  128. package/mobile/dist/hooks/useRegions.js.map +1 -0
  129. package/mobile/dist/services/sitemap/SitemapProps.d.ts +8 -0
  130. package/mobile/dist/ui-kit/Location/Location.d.ts +19 -0
  131. package/mobile/dist/ui-kit/Location/Location.js +44 -0
  132. package/mobile/dist/ui-kit/Location/Location.js.map +1 -0
  133. package/mobile/dist/ui-kit/Location/SearchBar.d.ts +6 -0
  134. package/mobile/dist/ui-kit/Location/SearchBar.js +9 -0
  135. package/mobile/dist/ui-kit/Location/SearchBar.js.map +1 -0
  136. package/mobile/dist/ui-kit/SwipeListControl/SwipeListContainer.js +8 -4
  137. package/mobile/dist/ui-kit/SwipeListControl/SwipeListContainer.js.map +1 -1
  138. package/mobile/dist/utils/groupBy.d.ts +1 -0
  139. package/mobile/dist/utils/groupBy.js +13 -0
  140. package/mobile/dist/utils/groupBy.js.map +1 -0
  141. package/mobile/lib/components/CarouselRecommendationCard/CarouselRecommendationCard.d.ts +5 -0
  142. package/mobile/lib/components/CarouselRecommendationCard/CarouselRecommendationCard.js +20 -0
  143. package/mobile/lib/components/CarouselRecommendationCard/CarouselRecommendationCard.js.map +1 -0
  144. package/mobile/lib/components/CarouselRecommendationCard/CarouselRecommendationCardContent.d.ts +44 -0
  145. package/mobile/lib/components/CarouselRecommendationCard/CarouselRecommendationCardContent.js +2 -0
  146. package/mobile/lib/components/CarouselRecommendationCard/CarouselRecommendationCardContent.js.map +1 -0
  147. package/mobile/lib/components/Header/HeaderBurger.js +4 -3
  148. package/mobile/lib/components/Header/HeaderBurger.js.map +1 -1
  149. package/mobile/lib/components/Header/HeaderSecondaryMenu.d.ts +2 -0
  150. package/mobile/lib/components/Header/HeaderSecondaryMenu.js +13 -4
  151. package/mobile/lib/components/Header/HeaderSecondaryMenu.js.map +1 -1
  152. package/mobile/lib/components/Recommendation/RecommendationCard.js +1 -1
  153. package/mobile/lib/components/Recommendation/RecommendationCard.js.map +1 -1
  154. package/mobile/lib/hooks/useCachedAsyncData.d.ts +2 -0
  155. package/mobile/lib/hooks/useCachedAsyncData.js +22 -0
  156. package/mobile/lib/hooks/useCachedAsyncData.js.map +1 -0
  157. package/mobile/lib/hooks/useLocation.d.ts +6 -0
  158. package/mobile/lib/hooks/useLocation.js +23 -0
  159. package/mobile/lib/hooks/useLocation.js.map +1 -0
  160. package/mobile/lib/hooks/useRegions.d.ts +6 -0
  161. package/mobile/lib/hooks/useRegions.js +8 -0
  162. package/mobile/lib/hooks/useRegions.js.map +1 -0
  163. package/mobile/lib/services/sitemap/SitemapProps.d.ts +8 -0
  164. package/mobile/lib/ui-kit/Location/Location.d.ts +19 -0
  165. package/mobile/lib/ui-kit/Location/Location.js +42 -0
  166. package/mobile/lib/ui-kit/Location/Location.js.map +1 -0
  167. package/mobile/lib/ui-kit/Location/SearchBar.d.ts +6 -0
  168. package/mobile/lib/ui-kit/Location/SearchBar.js +7 -0
  169. package/mobile/lib/ui-kit/Location/SearchBar.js.map +1 -0
  170. package/mobile/lib/ui-kit/SwipeListControl/SwipeListContainer.js +8 -4
  171. package/mobile/lib/ui-kit/SwipeListControl/SwipeListContainer.js.map +1 -1
  172. package/mobile/lib/utils/groupBy.d.ts +1 -0
  173. package/mobile/lib/utils/groupBy.js +10 -0
  174. package/mobile/lib/utils/groupBy.js.map +1 -0
  175. package/mobile/src/components/CarouselRecommendationCard/CarouselRecommendationCard.example.json +19 -0
  176. package/mobile/src/components/CarouselRecommendationCard/CarouselRecommendationCard.tsx +62 -0
  177. package/mobile/src/components/CarouselRecommendationCard/CarouselRecommendationCard.ui.json +9 -0
  178. package/mobile/src/components/CarouselRecommendationCard/CarouselRecommendationCardContent.ts +45 -0
  179. package/mobile/src/components/Header/HeaderBurger.tsx +5 -7
  180. package/mobile/src/components/Header/HeaderSecondaryMenu.tsx +32 -5
  181. package/mobile/src/components/MiniGallery/MiniGallery.ui.json +1 -1
  182. package/mobile/src/components/Recommendation/Recommendation.example.json +6 -5
  183. package/mobile/src/components/Recommendation/Recommendation.ui.json +8 -0
  184. package/mobile/src/components/Recommendation/RecommendationCard.tsx +1 -1
  185. package/mobile/src/hooks/useCachedAsyncData.ts +37 -0
  186. package/mobile/src/hooks/useLocation.ts +48 -0
  187. package/mobile/src/hooks/useRegions.ts +16 -0
  188. package/mobile/src/services/sitemap/SitemapProps.ts +9 -0
  189. package/mobile/src/ui-kit/Location/Location.tsx +168 -0
  190. package/mobile/src/ui-kit/Location/SearchBar.tsx +30 -0
  191. package/mobile/src/ui-kit/SwipeListControl/SwipeListContainer.tsx +8 -4
  192. package/mobile/src/utils/groupBy.ts +10 -0
  193. package/package.json +2 -2
  194. package/src/components/Blocks.ts +4 -2
  195. package/src/components/Carousel/Carousel.fixture.tsx +22 -4
  196. package/src/components/CarouselRecommendationCard/CarouselRecommendationCard.example.json +19 -0
  197. package/src/components/CarouselRecommendationCard/CarouselRecommendationCard.fixture.tsx +47 -0
  198. package/src/components/CarouselRecommendationCard/CarouselRecommendationCard.tsx +62 -0
  199. package/src/components/CarouselRecommendationCard/CarouselRecommendationCard.ui.json +9 -0
  200. package/src/components/CarouselRecommendationCard/CarouselRecommendationCardContent.ts +45 -0
  201. package/src/components/Header/Header.tsx +6 -4
  202. package/src/components/Header/HeaderBurger.tsx +5 -7
  203. package/src/components/Header/HeaderSecondaryMenu.tsx +32 -5
  204. package/src/components/MiniGallery/MiniGallery.ui.json +1 -1
  205. package/src/components/Recommendation/Recommendation.example.json +6 -5
  206. package/src/components/Recommendation/Recommendation.fixture.tsx +11 -10
  207. package/src/components/Recommendation/Recommendation.ui.json +8 -0
  208. package/src/components/Recommendation/RecommendationCard.tsx +1 -1
  209. package/src/hooks/useCachedAsyncData.ts +37 -0
  210. package/src/hooks/useLocation.ts +48 -0
  211. package/src/hooks/useRegions.ts +16 -0
  212. package/src/services/sitemap/SitemapProps.ts +9 -0
  213. package/src/ui-kit/Location/Location.fixture.tsx +81 -0
  214. package/src/ui-kit/Location/Location.tsx +168 -0
  215. package/src/ui-kit/Location/SearchBar.tsx +30 -0
  216. package/src/ui-kit/SwipeListControl/SwipeListContainer.tsx +8 -4
  217. package/src/utils/groupBy.ts +10 -0
  218. package/bundle/hooks/useGeolocation.d.ts +0 -1
  219. package/dist/hooks/useGeolocation.d.ts +0 -1
  220. package/dist/hooks/useGeolocation.js +0 -21
  221. package/dist/hooks/useGeolocation.js.map +0 -1
  222. package/lib/hooks/useGeolocation.d.ts +0 -1
  223. package/lib/hooks/useGeolocation.js +0 -18
  224. package/lib/hooks/useGeolocation.js.map +0 -1
  225. package/mobile/bundle/hooks/useGeolocation.d.ts +0 -1
  226. package/mobile/dist/hooks/useGeolocation.d.ts +0 -1
  227. package/mobile/dist/hooks/useGeolocation.js +0 -21
  228. package/mobile/dist/hooks/useGeolocation.js.map +0 -1
  229. package/mobile/lib/hooks/useGeolocation.d.ts +0 -1
  230. package/mobile/lib/hooks/useGeolocation.js +0 -18
  231. package/mobile/lib/hooks/useGeolocation.js.map +0 -1
  232. package/mobile/src/hooks/useGeolocation.ts +0 -22
  233. package/src/hooks/useGeolocation.ts +0 -22
@@ -0,0 +1,23 @@
1
+ import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
2
+ import { fetchJSONUnsafe } from '../utils/fetchJSON.js';
3
+ import { useCachedAsyncData } from './useCachedAsyncData.js';
4
+ const REGION_URL = '/api/v1/region';
5
+ const localStorageLocation = globalThis?.localStorage.getItem('location');
6
+ const currentLocation = localStorageLocation
7
+ ? JSON.parse(localStorageLocation)
8
+ : null;
9
+ export function useLocation(defaultLocation) {
10
+ const [location, setLocation] = useState(currentLocation?.region ?? { name: defaultLocation });
11
+ const { data } = useCachedAsyncData(REGION_URL, fetchJSONUnsafe);
12
+ useEffect(() => {
13
+ setLocation(currentLocation?.region && currentLocation?.manual
14
+ ? currentLocation.region
15
+ : data || { name: defaultLocation });
16
+ }, [data]);
17
+ const onChangeLocation = useCallback((region) => {
18
+ globalThis?.localStorage.setItem('location', JSON.stringify({ manual: true, region }));
19
+ setLocation(region);
20
+ }, [setLocation]);
21
+ return [location, onChangeLocation];
22
+ }
23
+ //# sourceMappingURL=useLocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocation.js","sourceRoot":"","sources":["../../src/hooks/useLocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAapC,MAAM,oBAAoB,GAAG,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC1E,MAAM,eAAe,GAA+B,oBAAoB;IACtE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAClC,CAAC,CAAC,IAAI,CAAC;AAET,MAAM,UAAU,WAAW,CACzB,eAAuB;IAEvB,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CACtC,eAAe,EAAE,MAAM,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,CACrD,CAAC;IACF,MAAM,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAAa,UAAU,EAAE,eAAe,CAAC,CAAC;IAE7E,SAAS,CAAC,GAAG,EAAE;QACb,WAAW,CACT,eAAe,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM;YAChD,CAAC,CAAC,eAAe,CAAC,MAAM;YACxB,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,CACtC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,MAAM,gBAAgB,GAAG,WAAW,CAClC,CAAC,MAAkB,EAAE,EAAE;QACrB,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QACvF,WAAW,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC,EACD,CAAC,WAAW,CAAC,CACd,CAAC;IAEF,OAAO,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface Region {
2
+ id?: number;
3
+ code?: string;
4
+ name?: string;
5
+ }
6
+ export declare function useRegions(): Region[];
@@ -0,0 +1,8 @@
1
+ import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
2
+ import { fetchJSONUnsafe } from '../utils/fetchJSON.js';
3
+ const REGIONS_URL = '/api/v1/regions';
4
+ export function useRegions() {
5
+ const { data } = useAsyncData(REGIONS_URL, fetchJSONUnsafe);
6
+ return data || [];
7
+ }
8
+ //# sourceMappingURL=useRegions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRegions.js","sourceRoot":"","sources":["../../src/hooks/useRegions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAQtC,MAAM,UAAU,UAAU;IACxB,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,CAAW,WAAW,EAAE,eAAe,CAAC,CAAC;IAEtE,OAAO,IAAI,IAAI,EAAE,CAAC;AACpB,CAAC"}
@@ -17,10 +17,18 @@ export interface DispositionItem extends LinkProps {
17
17
  /** @hidden */
18
18
  icon?: Picture;
19
19
  }
20
+ /**
21
+ * @title Представительства за рубежом
22
+ * @required ["text", "href"]
23
+ */
24
+ export interface ForeignOffice extends LinkProps {
25
+ icon?: Picture;
26
+ }
20
27
  export interface SitemapDataProps {
21
28
  topItems?: TopMenuItem[];
22
29
  dispositions?: DispositionItem[];
23
30
  logo?: LogoType;
31
+ foreignOffices?: ForeignOffice[];
24
32
  defaultLocation?: string;
25
33
  officesLink?: string;
26
34
  }
@@ -0,0 +1,19 @@
1
+ import type { Region } from '../../hooks/useRegions';
2
+ import type { UniBlockProps } from '../../model/JSXBlock';
3
+ import type { ForeignOffice } from '../../services/sitemap/SitemapProps';
4
+ interface RegionLinkProps {
5
+ onChangeLocation?: (region: Region) => void;
6
+ }
7
+ interface CloseButtonProps {
8
+ close?: () => void;
9
+ }
10
+ interface CurrentLocationProps {
11
+ currentLocation?: Region;
12
+ }
13
+ interface ForeignOfficeProps {
14
+ foreignOffices?: ForeignOffice[];
15
+ }
16
+ export declare type LocationProps = ForeignOfficeProps & CloseButtonProps & RegionLinkProps & CurrentLocationProps & UniBlockProps;
17
+ export declare const Location: import("@redneckz/uni-jsx").UNIComponent<LocationProps, any, any>;
18
+ declare const ForeignOffice: import("@redneckz/uni-jsx").UNIComponent<ForeignOffice, any, any>;
19
+ export {};
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@redneckz/uni-jsx/jsx-runtime";
2
+ import { JSX } from '@redneckz/uni-jsx';
3
+ import { useCallback } from '@redneckz/uni-jsx/lib/hooks';
4
+ import { useLink } from '../../hooks/useLink.js';
5
+ import { useRegions } from '../../hooks/useRegions.js';
6
+ import { useSearch } from '../../hooks/useSearch.js';
7
+ import { Text } from '../../ui-kit/Text/Text.js';
8
+ import { groupBy } from '../../utils/groupBy.js';
9
+ import { Img } from '../Img/Img.js';
10
+ import { SearchBar } from './SearchBar.js';
11
+ const SEARCH_TERM_MIN_LENGTH = 3;
12
+ export const Location = JSX(({ currentLocation, onChangeLocation, close, foreignOffices }) => {
13
+ const { term, setTerm } = useSearch();
14
+ const handleSearch = useCallback((_) => setTerm(_), []);
15
+ const regions = cleanUpRegions(useRegions()).sort((a, b) => a.name.localeCompare(b.name));
16
+ const regionsGroupByLetter = groupBy(regions, regionFirstLetter);
17
+ return (_jsxs("div", { className: "absolute h-full w-full inset-0 bg-white text-l-light z-50", children: [_jsx(CloseButton, { close: close }), _jsxs("div", { className: "container py-12", children: [_jsx(CurrentLocation, { currentLocation: currentLocation }), _jsx(SearchBar, { onSearch: handleSearch, searchTerm: term, className: "mb-7" }), term && term.length >= SEARCH_TERM_MIN_LENGTH ? (_jsx("div", { children: regions
18
+ .filter((region) => region.name?.startsWith(term))
19
+ .map(renderRegion({ onChangeLocation, close })) })) : (_jsx("div", { className: "columns-5", children: Array.from(regionsGroupByLetter.entries()).map(renderRegionGroup({ onChangeLocation, close })) })), _jsx(ForeignOffices, { foreignOffices: foreignOffices })] })] }));
20
+ });
21
+ const regionFirstLetter = (region) => region.name?.charAt(0) || '';
22
+ const cleanUpRegions = (regions) => regions.map((region) => ({
23
+ ...region,
24
+ name: region.name?.replace(/республика|область|край'/gi, '').trim() || '',
25
+ }));
26
+ const CurrentLocation = JSX(({ currentLocation }) => currentLocation ? (_jsxs("div", { className: "mb-4", children: [_jsx(Text, { size: "text-l", font: "font-light", children: "\u0421\u0435\u0439\u0447\u0430\u0441 \u0432\u044B\u0431\u0440\u0430\u043D:\u00A0" }), _jsx("button", { className: "cursor-pointer", onClick: close, children: _jsx(Text, { color: "text-green", children: currentLocation.name }) })] })) : null);
27
+ const CloseButton = JSX(({ close }) => (_jsx("button", { className: "visible peer-placeholder-shown:invisible absolute top-6 right-6 w-6 h-6 p-1 bg-transparent cursor-pointer border-none", onClick: (e) => {
28
+ e.preventDefault();
29
+ close && close();
30
+ }, children: _jsx(Img, { image: "CloseIcon", width: "24", height: "24" }) })));
31
+ const renderRegionGroup = ({ onChangeLocation, close }) => ([letter, regions]) => (_jsxs("div", { className: "break-inside-avoid mb-7 w-[224px]", children: [_jsx("div", { className: "mb-2.5", children: _jsx(Text, { size: "text-h6", children: letter }) }), regions.map(renderRegion({ onChangeLocation, close }))] }, letter));
32
+ const renderRegion = ({ onChangeLocation, close }) => (region) => (_jsx("div", { className: "mb-1", children: _jsx("button", { className: "cursor-pointer hover:text-primary-hover", onClick: () => {
33
+ onChangeLocation && onChangeLocation(region);
34
+ close && close();
35
+ }, children: region.name }) }, region.id));
36
+ const ForeignOffices = JSX(({ foreignOffices }) => foreignOffices?.length ? (_jsxs("div", { className: "border-t border-main-divider mt-7 pt-7", children: [_jsx("div", { className: "mb-4", children: _jsx(Text, { size: "text-m-light", color: "text-secondary-text", children: "\u041F\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u0435\u043B\u044C\u0441\u0442\u0432\u0430 \u0437\u0430 \u0440\u0443\u0431\u0435\u0436\u043E\u043C:" }) }), _jsx("div", { className: "flex gap-10", children: foreignOffices.map((office, i) => (_jsx(ForeignOffice, { ...office }, String(i)))) })] })) : null);
37
+ const ForeignOffice = JSX(({ icon, ...rest }) => {
38
+ const link = useLink();
39
+ const { text, target, href, onClick } = link(rest);
40
+ return (_jsxs("div", { className: "flex gap-x-3", children: [_jsx(Img, { image: icon }), _jsx("a", { className: "hover:text-primary-hover", href: href, target: target, onClick: onClick, children: text })] }));
41
+ });
42
+ //# sourceMappingURL=Location.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Location.js","sourceRoot":"","sources":["../../../src/ui-kit/Location/Location.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,C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AAC,wCAAwC,aACrD,cAAK,SAAS,EAAC,MAAM,YACnB,KAAC,IAAI,IAAC,IAAI,EAAC,cAAc,EAAC,KAAK,EAAC,qBAAqB,gLAE9C,GACH,EACN,cAAK,SAAS,EAAC,aAAa,YACzB,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAS,EAAE,EAAE,CAAC,CACzC,KAAC,aAAa,OAAqB,MAAM,IAArB,MAAM,CAAC,CAAC,CAAC,CAAgB,CAC9C,CAAC,GACE,IACF,CACP,CAAC,CAAC,CAAC,IAAI,CACT,CAAC;AAEF,MAAM,aAAa,GAAG,GAAG,CAAgB,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE;IAC7D,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAEnD,OAAO,CACL,eAAK,SAAS,EAAC,cAAc,aAC3B,KAAC,GAAG,IAAC,KAAK,EAAE,IAAI,GAAI,EACpB,YAAG,SAAS,EAAC,0BAA0B,EAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,YACjF,IAAI,GACH,IACA,CACP,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface SearchBarInnerProps {
2
+ className?: string;
3
+ searchTerm?: string;
4
+ onSearch: (_: string) => void;
5
+ }
6
+ export declare const SearchBar: import("@redneckz/uni-jsx").UNIComponent<SearchBarInnerProps, any, any>;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@redneckz/uni-jsx/jsx-runtime";
2
+ import { JSX } from '@redneckz/uni-jsx';
3
+ export const SearchBar = JSX(({ className, searchTerm, onSearch }) => {
4
+ return (_jsxs("form", { className: `font-sans relative ${className}`, children: [_jsx("div", { className: "absolute rounded h-full flex items-center justify-center pl-4 max-w-[170px] gap-3.5 pointer-events-none", children: searchTerm ? null : (_jsx("label", { htmlFor: "search-bar-input", className: `text-secondary-text `, children: "\u041F\u043E\u0438\u0441\u043A \u043F\u043E \u0444\u0438\u043B\u0438\u0430\u043B\u0430\u043C" })) }), _jsx("input", { id: "search-bar-input", className: `h-12 pl-4 w-full peer text-l text-black border border-solid rounded-md box-border
5
+ outline-none border-main-stroke hover:border-primary-hover active:border-primary-text focus:border-primary-text`, value: searchTerm, onChange: (e) => onSearch(e.target.value), type: "text", name: "location-search-bar-input" })] }));
6
+ });
7
+ //# sourceMappingURL=SearchBar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchBar.js","sourceRoot":"","sources":["../../../src/ui-kit/Location/SearchBar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAQxC,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAsB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IACxF,OAAO,CACL,gBAAM,SAAS,EAAE,sBAAsB,SAAS,EAAE,aAChD,cAAK,SAAS,EAAC,yGAAyG,YACrH,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACnB,gBAAO,OAAO,EAAC,kBAAkB,EAAC,SAAS,EAAE,sBAAsB,6GAE3D,CACT,GACG,EACN,gBACE,EAAE,EAAC,kBAAkB,EACrB,SAAS,EAAE;8HAC2G,EACtH,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAe,CAAC,EACnD,IAAI,EAAC,MAAM,EACX,IAAI,EAAC,2BAA2B,GAChC,IACG,CACR,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -4,7 +4,7 @@ import { useCallback, useRef } from '@redneckz/uni-jsx/lib/hooks';
4
4
  import { mapChildren } from '../../utils/mapChildren.js';
5
5
  import { SwipeListItem } from './SwipeListItem.js';
6
6
  const childStyleMap = ['min-w-[100%]', 'min-w-[50%]', 'min-w-[33.33%]', 'min-w-[25%]'];
7
- export const SwipeListContainer = JSX(({ className = '', containerRef, activeIndex, visibleItemCount, gap = 0, padding = 0, snapAlign = 'snap-center', children, onVisibleItemsChange, onVisibleIndicesChange, }) => {
7
+ export const SwipeListContainer = JSX(({ className = '', containerRef, activeIndex, visibleItemCount = 0, gap = 0, padding = 0, snapAlign = 'snap-center', children, onVisibleItemsChange, onVisibleIndicesChange, }) => {
8
8
  const observerOptions = {
9
9
  sensitivity: 1,
10
10
  rootRef: containerRef,
@@ -17,14 +17,18 @@ export const SwipeListContainer = JSX(({ className = '', containerRef, activeInd
17
17
  onVisibleItemsChange && onVisibleItemsChange(itemsVisibilityList);
18
18
  onVisibleIndicesChange && onVisibleIndicesChange(getVisibleIndices(itemsVisibilityList));
19
19
  }, [onVisibleItemsChange, onVisibleIndicesChange]);
20
- return (_jsx("div", { className: `box-border overflow-auto flex horizontal-list no-scrollbar ${className}`, style: { ...getContainerStyle(padding), gap: `${gap}px` }, role: "list", ref: containerRef, children: mapChildren((child, idx) => (_jsx(SwipeListItem, { className: `${snapAlign} ${visibleItemCount ? childStyleMap[visibleItemCount - 1] : ''}`, style: getContainerStyle(padding / 4), activeIndex: activeIndex, idx: idx, observerOptions: observerOptions, onIntersection: handleIntersection, children: child }, String(idx))))(children) }));
20
+ const additionPadding = visibleItemCount > 0 ? gap * Number(visibleItemCount) - 1 : 0;
21
+ return (_jsx("div", { className: `box-border overflow-auto flex horizontal-list no-scrollbar ${className}`, style: {
22
+ ...getContainerStyle(padding, additionPadding),
23
+ gap: `${gap}px`,
24
+ }, role: "list", ref: containerRef, children: mapChildren((child, idx) => (_jsx(SwipeListItem, { className: `${snapAlign} ${visibleItemCount ? childStyleMap[visibleItemCount - 1] : ''}`, style: getContainerStyle(padding / 4), activeIndex: activeIndex, idx: idx, observerOptions: observerOptions, onIntersection: handleIntersection, children: child }, String(idx))))(children) }));
21
25
  });
22
26
  // Styles used to compensate outer container padding to get rid of clipping effect
23
- const getContainerStyle = (padding) => ({
27
+ const getContainerStyle = (padding, additionalPadding = 0) => ({
24
28
  marginLeft: `${-padding}px`,
25
29
  marginRight: `${-padding}px`,
26
30
  paddingLeft: `${padding}px`,
27
- paddingRight: `${padding}px`,
31
+ paddingRight: `${padding + additionalPadding}px`,
28
32
  });
29
33
  const getVisibleIndices = (itemsVisibilityList) => itemsVisibilityList
30
34
  .map((_, i) => [_, i])
@@ -1 +1 @@
1
- {"version":3,"file":"SwipeListContainer.js","sourceRoot":"","sources":["../../../src/ui-kit/SwipeListControl/SwipeListContainer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAmBhD,MAAM,aAAa,GAAG,CAAC,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAC;AAEvF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CACnC,CAAC,EACC,SAAS,GAAG,EAAE,EACd,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,GAAG,GAAG,CAAC,EACP,OAAO,GAAG,CAAC,EACX,SAAS,GAAG,aAAa,EACzB,QAAQ,EACR,oBAAoB,EACpB,sBAAsB,GACvB,EAAE,EAAE;IACH,MAAM,eAAe,GAAgC;QACnD,WAAW,EAAE,CAAC;QACd,OAAO,EAAE,YAAY;KACtB,CAAC;IAEF,MAAM,sBAAsB,GAAG,MAAM,CAAsB,EAAE,CAAC,CAAC;IAC/D,MAAM,kBAAkB,GAAG,WAAW,CACpC,CAAC,GAAW,EAAE,KAAgC,EAAE,EA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AAK,IAVD,MAAM,CAAC,GAAG,CAAC,CAWF,CACjB,CAAC,CAAC,QAAQ,CAAC,GACR,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,kFAAkF;AAClF,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,iBAAiB,GAAG,CAAC,EAA0B,EAAE,CAAC,CAAC;IAC7F,UAAU,EAAE,GAAG,CAAC,OAAO,IAAI;IAC3B,WAAW,EAAE,GAAG,CAAC,OAAO,IAAI;IAC5B,WAAW,EAAE,GAAG,OAAO,IAAI;IAC3B,YAAY,EAAE,GAAG,OAAO,GAAG,iBAAiB,IAAI;CACjD,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,CAAC,mBAAwC,EAAE,EAAE,CACrE,mBAAmB;KAChB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAmD,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACtE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,iBAAiB,IAAI,GAAG,CAAC;KAChD,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const groupBy: <K, V>(list: V[], keyGetter: (input: V) => K) => Map<K, V[]>;
@@ -0,0 +1,10 @@
1
+ export const groupBy = (list, keyGetter) => {
2
+ const map = new Map();
3
+ list.forEach((item) => {
4
+ const key = keyGetter(item);
5
+ const collection = map.get(key);
6
+ map.set(key, [...(collection || []), item]);
7
+ });
8
+ return map;
9
+ };
10
+ //# sourceMappingURL=groupBy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groupBy.js","sourceRoot":"","sources":["../../src/utils/groupBy.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CAAO,IAAc,EAAE,SAA0B,EAAoB,EAAE;IAC5F,MAAM,GAAG,GAAG,IAAI,GAAG,EAAe,CAAC;IACnC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACpB,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAC5B,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ {
2
+ "content": {
3
+ "image": {
4
+ "format": "webp",
5
+ "size": {
6
+ "width": 180,
7
+ "height": 180
8
+ }
9
+ },
10
+ "title": "Заголовок 1",
11
+ "description": "Описание 1",
12
+ "socialMedia": [
13
+ { "href": "https://t.me" },
14
+ { "href": "https://vk.com" },
15
+ { "href": "https://ok.ru" }
16
+ ],
17
+ "version": "primary"
18
+ }
19
+ }
@@ -0,0 +1,62 @@
1
+ import { BaseTile } from '../BaseTile/BaseTile';
2
+ import { BlockWrapper } from '../../ui-kit/BlockWrapper';
3
+ import { BorderVersionStyleMap } from '../../model/BorderVersion';
4
+ import { Heading } from '../../ui-kit/Heading/Heading';
5
+ import { Img } from '../../ui-kit/Img/Img';
6
+ import { JSX } from '@redneckz/uni-jsx';
7
+ import { List } from '../../ui-kit/List/List';
8
+ import { renderButton } from '../../ui-kit/Button/ButtonSection';
9
+ import { SocialMedia } from '../Footer/SocialMedia';
10
+ import { VersionStyleMap } from '../../model/BlockVersion';
11
+ import type { CarouselRecommendationCardContent } from './CarouselRecommendationCardContent';
12
+ import type { UniBlockProps } from '../../model/JSXBlock';
13
+
14
+ export interface RecommendationCardProps extends CarouselRecommendationCardContent, UniBlockProps {}
15
+
16
+ export const CarouselRecommendationCard = JSX<RecommendationCardProps>(
17
+ ({
18
+ button,
19
+ className = '',
20
+ description,
21
+ image,
22
+ items = [],
23
+ socialMedia = [],
24
+ title,
25
+ version = 'primary',
26
+ ...rest
27
+ }) => {
28
+ const tileTitle = title ? (
29
+ <Heading headingType="h5" as="h3" className="mb-3.5 z-10" title={title} />
30
+ ) : null;
31
+ const tileImage = image?.src ? (
32
+ <Img className="absolute bottom-0 right-0 m-0" image={image} />
33
+ ) : null;
34
+
35
+ return (
36
+ <BlockWrapper
37
+ className={`relative text-left border border-solid box-border p-7 min-w-[524px]
38
+ ${BorderVersionStyleMap[version]}
39
+ ${VersionStyleMap[version]}
40
+ ${className}`}
41
+ {...rest}
42
+ >
43
+ <BaseTile className="flex justify-between" title={tileTitle} image={tileImage}>
44
+ <div className="h-full flex flex-col justify-between">
45
+ {description ? <span className="mb-2">{description}</span> : null}
46
+ {items.length ? (
47
+ <List
48
+ className="text-xl-light flex flex-col flex-1 gap-2 max-w-[236px]"
49
+ items={items}
50
+ version={version}
51
+ />
52
+ ) : null}
53
+ {socialMedia.length ? (
54
+ <SocialMedia className="pt-10 pb-0" media={socialMedia} version={version} />
55
+ ) : null}
56
+ {button?.text ? <div className="pt-2 mt-16">{renderButton({ button })}</div> : null}
57
+ </div>
58
+ </BaseTile>
59
+ </BlockWrapper>
60
+ );
61
+ },
62
+ );
@@ -0,0 +1,9 @@
1
+ {
2
+ "content": {
3
+ "items": {
4
+ "image": {
5
+ "ui:field": "picture"
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,45 @@
1
+ import type { BlockVersion } from '../../model/BlockVersion';
2
+ import type { HeadlineCommonProps } from '../../model/HeadlineType';
3
+ import type { LinkCommonProps } from '../../model/LinkProps';
4
+ import type { Picture } from '../../model/Picture';
5
+ import type { ButtonProps } from '../../ui-kit/Button/ButtonProps';
6
+ import type { ListContent } from '../../ui-kit/List/ListContent';
7
+
8
+ /**
9
+ * @title Карточка рекомендаций
10
+ */
11
+ export interface CarouselRecommendationCardContent extends HeadlineCommonProps, ListContent {
12
+ /**
13
+ * @title Соц сети
14
+ * @minItems 3
15
+ * @default [
16
+ * { "href": "https://t.me" },
17
+ * { "href": "https://vk.com" },
18
+ * { "href": "https://ok.ru" },
19
+ * ]
20
+ */
21
+ socialMedia?: LinkCommonProps[];
22
+ /**
23
+ * @default {
24
+ * "format": "webp",
25
+ * "size": {
26
+ * "width": 290
27
+ * },
28
+ * "sources": [{
29
+ * "media": 1279,
30
+ * "width": 174,
31
+ * "format": "webp",
32
+ * "alignment": "southeast"
33
+ * }]
34
+ * }
35
+ */
36
+ image?: Picture;
37
+ /**
38
+ * @default {
39
+ * "text": "",
40
+ * "version": "secondary"
41
+ * }
42
+ */
43
+ button?: ButtonProps;
44
+ version?: BlockVersion;
45
+ }
@@ -1,8 +1,9 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useGeolocation } from '../../hooks/useGeolocation';
2
+ import { useLocation } from '../../hooks/useLocation';
3
3
  import type { VNode } from '../../model/VNode';
4
4
  import { Img } from '../../ui-kit/Img/Img';
5
5
  import { SearchBar } from '../../ui-kit/SearchBar/SearchBar';
6
+ import { Text } from '../../ui-kit/Text/Text';
6
7
  import type { DispositionItem } from './HeaderContent';
7
8
 
8
9
  export interface HeaderBurgerProps {
@@ -14,7 +15,7 @@ export interface HeaderBurgerProps {
14
15
 
15
16
  export const HeaderBurger = JSX<HeaderBurgerProps>(
16
17
  ({ burgerSubMenu, onClick, defaultLocation = '', children }) => {
17
- const [city, getCity] = useGeolocation(defaultLocation);
18
+ const [location] = useLocation(defaultLocation);
18
19
 
19
20
  return (
20
21
  <div className="absolute top-0 left-0 w-full h-full bg-white p-4 box-border z-20">
@@ -24,10 +25,7 @@ export const HeaderBurger = JSX<HeaderBurgerProps>(
24
25
  >
25
26
  <Img image="CloseIcon" width="24" height="24" asSVG />
26
27
  </button>
27
- <button
28
- onClick={getCity}
29
- className="flex items-center text-s text-secondary-text p-0 mb-4 bg-transparent cursor-pointer"
30
- >
28
+ <button className="flex items-center text-s p-0 mb-4 bg-transparent cursor-pointer">
31
29
  <Img
32
30
  image="GeolocationIcon"
33
31
  width="20"
@@ -35,7 +33,7 @@ export const HeaderBurger = JSX<HeaderBurgerProps>(
35
33
  className="text-primary-main box-border mr-2"
36
34
  asSVG
37
35
  />
38
- {city}
36
+ <Text color="text-secondary-text">{location.name}</Text>
39
37
  </button>
40
38
  {children}
41
39
  <div className="mb-7">{burgerSubMenu?.map(renderBurgerSubMenuItem)}</div>
@@ -1,8 +1,11 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useGeolocation } from '../../hooks/useGeolocation';
2
+ import { useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { useLocation } from '../../hooks/useLocation';
3
4
  import type { BgColorVersion } from '../../model/BgColorVersion';
4
5
  import type { IconVersion } from '../../model/IconVersion';
6
+ import type { ForeignOffice } from '../../services/sitemap/SitemapProps';
5
7
  import { Img } from '../../ui-kit/Img/Img';
8
+ import { Location } from '../../ui-kit/Location/Location';
6
9
  import { TopItem } from '../../ui-kit/TopItem/TopItem';
7
10
  import { HeaderSecondaryMenuButton } from './HeaderSecondaryMenuButton';
8
11
 
@@ -10,6 +13,7 @@ interface HeaderSecondaryMenuContent {
10
13
  defaultLocation?: string;
11
14
  officesLink?: string;
12
15
  bgColor?: BgColorVersion;
16
+ foreignOffices?: ForeignOffice[];
13
17
  }
14
18
 
15
19
  export interface HeaderSecondaryMenuProps extends HeaderSecondaryMenuContent {
@@ -30,8 +34,23 @@ const LINKS_ICON_VERSION_MAP: Record<BgColorVersion, IconVersion> = {
30
34
  };
31
35
 
32
36
  export const HeaderSecondaryMenu = JSX<HeaderSecondaryMenuProps>(
33
- ({ className, officesLink, defaultLocation = 'Москва', bgColor = 'bg-white' }) => {
34
- const [city, getCity] = useGeolocation(defaultLocation);
37
+ ({
38
+ className,
39
+ officesLink,
40
+ defaultLocation = 'Москва',
41
+ foreignOffices,
42
+ bgColor = 'bg-white',
43
+ }) => {
44
+ const [isShowLocationModal, setShowLocationModal] = useState<boolean>(false);
45
+
46
+ const [location, onChangeLocation] = useLocation(defaultLocation);
47
+
48
+ const showLocationModal = () => {
49
+ setShowLocationModal(true);
50
+ };
51
+ const hideLocationModal = () => {
52
+ setShowLocationModal(false);
53
+ };
35
54
 
36
55
  return (
37
56
  <div className={`flex items-center ${className || ''}`}>
@@ -39,9 +58,9 @@ export const HeaderSecondaryMenu = JSX<HeaderSecondaryMenuProps>(
39
58
  className="mr-5"
40
59
  flat={true}
41
60
  href="#"
42
- text={city}
61
+ text={location.name}
43
62
  ariaLabel="Местоположение"
44
- onClick={getCity}
63
+ onClick={showLocationModal}
45
64
  bgColor={bgColor}
46
65
  />
47
66
  {officesLink ? (
@@ -76,6 +95,14 @@ export const HeaderSecondaryMenu = JSX<HeaderSecondaryMenuProps>(
76
95
  asSVG
77
96
  />
78
97
  </HeaderSecondaryMenuButton>
98
+ {isShowLocationModal ? (
99
+ <Location
100
+ currentLocation={location}
101
+ foreignOffices={foreignOffices}
102
+ onChangeLocation={onChangeLocation}
103
+ close={hideLocationModal}
104
+ />
105
+ ) : null}
79
106
  </div>
80
107
  );
81
108
  },
@@ -8,7 +8,7 @@
8
8
  "button": {
9
9
  "icon": {
10
10
  "ui:field": "icon"
11
- },
11
+ },
12
12
  "iconRight": {
13
13
  "ui:field": "icon"
14
14
  }
@@ -28,11 +28,12 @@
28
28
  },
29
29
  "title": "Заголовок 2",
30
30
  "description": "Описание 2",
31
- "socialMedia": [
32
- { "href": "https://t.me" },
33
- { "href": "https://vk.com" },
34
- { "href": "https://ok.ru" }
35
- ]
31
+ "button": {
32
+ "href": "",
33
+ "text": "Подробнее",
34
+ "target": "_self",
35
+ "version": "primary"
36
+ }
36
37
  },
37
38
  {
38
39
  "image": {
@@ -4,6 +4,14 @@
4
4
  "items": {
5
5
  "image": {
6
6
  "ui:field": "picture"
7
+ },
8
+ "button": {
9
+ "icon": {
10
+ "ui:field": "icon"
11
+ },
12
+ "iconRight": {
13
+ "ui:field": "icon"
14
+ }
7
15
  }
8
16
  }
9
17
  }
@@ -41,7 +41,7 @@ export const RecommendationCard = JSX<RecommendationCardProps>(
41
41
  <SocialMedia className="pt-10 pb-0" media={socialMedia} version={version} />
42
42
  ) : null}
43
43
  {button?.text ? (
44
- <div className="pt-2">{renderButton({ button, buttonClassName: 'mt-16' })}</div>
44
+ <div className="pt-2">{renderButton({ button, buttonClassName: 'mt-16 px-5' })}</div>
45
45
  ) : null}
46
46
  </div>
47
47
  </BaseTile>
@@ -0,0 +1,37 @@
1
+ import { useCallback } from '@redneckz/uni-jsx/lib/hooks';
2
+ import type { AsyncDataResponse, Fetcher } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
3
+ import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
4
+
5
+ const STORAGE_DEFAULT_TTL = 86400000; // 24 * 60 * 60 * 1000
6
+
7
+ export function useCachedAsyncData<Data = any>(
8
+ key: string,
9
+ fetcher: Fetcher<Data, string>,
10
+ storage: any = globalThis?.localStorage,
11
+ ): AsyncDataResponse<Data> {
12
+ const cachedFetcher: typeof fetcher = useCallback(
13
+ async (...args) => {
14
+ const storageKey = `async:${key}`;
15
+ const storageData: string = storage.getItem(storageKey);
16
+
17
+ const cachedData = getParsedData(storageData);
18
+ if (cachedData) {
19
+ return cachedData;
20
+ }
21
+
22
+ const data = await fetcher(...args);
23
+ storage.setItem(storageKey, JSON.stringify({ data, timestamp: Date.now() }));
24
+
25
+ return data;
26
+ },
27
+ [key, fetcher],
28
+ );
29
+
30
+ return useAsyncData(key, cachedFetcher);
31
+ }
32
+
33
+ function getParsedData(storageData: string) {
34
+ const { data = null, timestamp = null } = storageData ? JSON.parse(storageData) : {};
35
+
36
+ return data && Date.now() - timestamp < STORAGE_DEFAULT_TTL ? data : undefined;
37
+ }
@@ -0,0 +1,48 @@
1
+ import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
2
+ import { fetchJSONUnsafe } from '../utils/fetchJSON';
3
+ import { useCachedAsyncData } from './useCachedAsyncData';
4
+
5
+ const REGION_URL = '/api/v1/region';
6
+
7
+ export interface RegionData {
8
+ id?: number;
9
+ code?: string;
10
+ name?: string;
11
+ }
12
+
13
+ interface LocationStorageData {
14
+ manual?: boolean;
15
+ region: RegionData;
16
+ }
17
+
18
+ const localStorageLocation = globalThis?.localStorage.getItem('location');
19
+ const currentLocation: LocationStorageData | null = localStorageLocation
20
+ ? JSON.parse(localStorageLocation)
21
+ : null;
22
+
23
+ export function useLocation(
24
+ defaultLocation: string,
25
+ ): [RegionData, (newLocation: RegionData) => void] {
26
+ const [location, setLocation] = useState<RegionData>(
27
+ currentLocation?.region ?? { name: defaultLocation },
28
+ );
29
+ const { data } = useCachedAsyncData<RegionData>(REGION_URL, fetchJSONUnsafe);
30
+
31
+ useEffect(() => {
32
+ setLocation(
33
+ currentLocation?.region && currentLocation?.manual
34
+ ? currentLocation.region
35
+ : data || { name: defaultLocation },
36
+ );
37
+ }, [data]);
38
+
39
+ const onChangeLocation = useCallback(
40
+ (region: RegionData) => {
41
+ globalThis?.localStorage.setItem('location', JSON.stringify({ manual: true, region }));
42
+ setLocation(region);
43
+ },
44
+ [setLocation],
45
+ );
46
+
47
+ return [location, onChangeLocation];
48
+ }