@sonic-equipment/ui 202.0.0 → 204.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/address-info-display/address-info-display.js +1 -0
- package/dist/algolia/filter-section.js +1 -0
- package/dist/badges/badge/icon-with-badge/icon-with-badge.js +1 -0
- package/dist/badges/tag/tag.js +1 -0
- package/dist/breadcrumbs/breadcrumb.js +7 -16
- package/dist/breadcrumbs/breadcrumb.module.css.js +1 -1
- package/dist/buttons/add-to-cart-button/add-to-cart-button.d.ts +1 -1
- package/dist/buttons/add-to-cart-button/add-to-cart-button.js +12 -13
- package/dist/cards/data-card/data-card.js +1 -0
- package/dist/cards/orderline-card/orderline-card.js +1 -0
- package/dist/carousel/category-carousel/category-carousel.js +1 -0
- package/dist/carousel/usp-carousel/product-usp-carousel-slide.js +1 -0
- package/dist/carousel/usp-carousel/product-usp-carousel.js +1 -0
- package/dist/cart-totals/cart-totals-summary.js +1 -0
- package/dist/collapsables/accordion/accordion-item.js +6 -5
- package/dist/collapsables/accordion/accordion.js +1 -0
- package/dist/collapsables/accordion/accordion.module.css.js +1 -1
- package/dist/cookies/client-cookie-context.d.ts +3 -0
- package/dist/cookies/client-cookie-context.js +30 -0
- package/dist/cookies/cookie-context.d.ts +2 -0
- package/dist/cookies/cookie-context.js +6 -0
- package/dist/cookies/cookie-provider.d.ts +6 -0
- package/dist/cookies/cookie-provider.js +10 -0
- package/dist/cookies/readonly-cookie-reader.d.ts +2 -0
- package/dist/cookies/readonly-cookie-reader.js +18 -0
- package/dist/cookies/types.d.ts +14 -0
- package/dist/cookies/types.js +7 -0
- package/dist/{shared/hooks → cookies}/use-cookie.d.ts +1 -2
- package/dist/cookies/use-cookie.js +30 -0
- package/dist/country-select/hooks/use-countries.js +2 -1
- package/dist/country-selector/connected-country-selector.js +1 -1
- package/dist/country-selector/use-countries-languages.js +3 -11
- package/dist/display/info-display/info-display.js +1 -0
- package/dist/display/product-sku/product-sku.js +1 -0
- package/dist/exports.d.ts +6 -1
- package/dist/forms/layout/form/form-segment-group.js +1 -0
- package/dist/forms/layout/form/form-segment.js +1 -0
- package/dist/forms/partials/password-validation/password-validation.js +1 -0
- package/dist/global-search/plugins/categories-plugin.js +1 -0
- package/dist/global-search/plugins/popular-categories-plugin.js +1 -0
- package/dist/global-search/plugins/popular-searches-plugin.js +1 -0
- package/dist/global-search/plugins/query-suggestions-plugin.js +1 -0
- package/dist/global-search/plugins/quick-access-plugin.js +1 -0
- package/dist/global-search/plugins/recent-searches-plugin.js +1 -0
- package/dist/global-search/search-highlight/highlight.js +1 -0
- package/dist/global-search/search-result-panel/sections/section-container.js +1 -0
- package/dist/global-search/search-section/search-list.js +1 -0
- package/dist/global-search/search-section/search-section.js +1 -0
- package/dist/header/buttons/account/connected-account-button.js +1 -8
- package/dist/header/drawers/search-drawer.js +1 -0
- package/dist/header/header-layout/header-layout.js +1 -0
- package/dist/icons/glyph/glyphs-arrow-blackcaps-right-icon.js +1 -0
- package/dist/icons/glyph/glyphs-arrow-boldcaps-left-icon.js +1 -0
- package/dist/icons/glyph/glyphs-arrow-boldcaps-right-icon.js +1 -0
- package/dist/icons/glyph/glyphs-arrow-semibold-right-icon.js +1 -0
- package/dist/icons/glyph/glyphs-chevrons-bold-down-icon.js +1 -0
- package/dist/icons/glyph/glyphs-chevrons-bold-up-icon.js +1 -0
- package/dist/icons/glyph/glyphs-chevrons-slim-down-icon.js +1 -0
- package/dist/icons/glyph/glyphs-chevrons-slim-left-icon.js +1 -0
- package/dist/icons/glyph/glyphs-chevrons-slim-right-icon.js +1 -0
- package/dist/icons/solid/solid-attention-icon.js +1 -0
- package/dist/icons/solid/solid-cart-icon.js +1 -0
- package/dist/icons/solid/solid-close-icon.js +1 -0
- package/dist/icons/solid/solid-favorite-icon.js +1 -0
- package/dist/icons/solid/solid-home-icon.js +1 -0
- package/dist/icons/solid/solid-information-icon.js +1 -0
- package/dist/icons/solid/solid-login-icon.js +1 -0
- package/dist/icons/solid/solid-logout-icon.js +1 -0
- package/dist/icons/solid/solid-news-icon.js +1 -0
- package/dist/icons/solid/solid-notice-icon.js +1 -0
- package/dist/icons/solid/solid-okay-icon.js +1 -0
- package/dist/icons/solid/solid-rating-icon.js +1 -0
- package/dist/icons/solid/solid-salecategory-icon.js +1 -0
- package/dist/icons/solid/solid-tag-icon.js +1 -0
- package/dist/icons/stroke/stroke-categories-icon.js +1 -0
- package/dist/icons/stroke/stroke-checkmark-icon.js +1 -0
- package/dist/icons/stroke/stroke-closebox-icon.js +1 -0
- package/dist/icons/stroke/stroke-dehashed-icon.js +1 -0
- package/dist/icons/stroke/stroke-download-icon.js +1 -0
- package/dist/icons/stroke/stroke-event-icon.js +1 -0
- package/dist/icons/stroke/stroke-favorite-icon.js +1 -0
- package/dist/icons/stroke/stroke-filter-icon.js +1 -0
- package/dist/icons/stroke/stroke-hashed-icon.js +1 -0
- package/dist/icons/stroke/stroke-information-icon.js +1 -0
- package/dist/icons/stroke/stroke-minus-icon.js +1 -0
- package/dist/icons/stroke/stroke-plus-icon.js +1 -0
- package/dist/icons/stroke/stroke-recent-icon.js +1 -0
- package/dist/icons/stroke/stroke-search-icon.js +1 -0
- package/dist/icons/stroke/stroke-trash-icon.js +1 -0
- package/dist/index.js +7 -2
- package/dist/intl/use-formatted-date.js +1 -0
- package/dist/layout/center.js +1 -0
- package/dist/lists/download-document-list/download-document-list.js +1 -0
- package/dist/lists/feature-list/feature-list.js +1 -0
- package/dist/lists/icon-list/icon-list.js +1 -0
- package/dist/lists/menu-list/menu-list-header.js +1 -0
- package/dist/lists/menu-list/use-menu-list-item.js +1 -0
- package/dist/lists/menu-list/use-menu-list.js +1 -0
- package/dist/lists/product-overview-grid/product-overview-grid.js +1 -0
- package/dist/loading/blank-page-spacer.js +1 -0
- package/dist/loading/dynamic-loading-overlay.js +1 -0
- package/dist/loading/loading-overlay.js +1 -0
- package/dist/loading/progress-circle.js +1 -0
- package/dist/media/image-grid/images-grid.d.ts +2 -1
- package/dist/media/image-grid/images-grid.js +2 -2
- package/dist/media/image-lightbox/image-lightbox.d.ts +2 -1
- package/dist/media/image-lightbox/image-lightbox.js +2 -2
- package/dist/message/message.js +1 -0
- package/dist/pages/account/components/create-account-form/create-account-form.js +1 -1
- package/dist/pages/account/create-account-page/create-account-page.js +5 -3
- package/dist/pages/account/layouts/sign-in-page-layout/sign-in-page-layout.d.ts +2 -1
- package/dist/pages/account/layouts/sign-in-page-layout/sign-in-page-layout.js +2 -4
- package/dist/pages/account/sign-in-page/sign-in-page.js +2 -2
- package/dist/pages/checkout/cart-page/cart-page.js +1 -1
- package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-content.js +1 -0
- package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-header.js +1 -0
- package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-link.js +1 -0
- package/dist/pages/checkout/layouts/checkout-page-layout/components/checkout-page-section.js +1 -0
- package/dist/pages/checkout/order-confirmation-page/order-confirmation-page-content.js +1 -1
- package/dist/pages/checkout/payment-page/hooks/use-has-returned-from-adyen.js +1 -0
- package/dist/pages/checkout/shipping-page/hooks/use-patch-shipping-details.js +1 -0
- package/dist/pages/components/page-container/page-container.js +1 -0
- package/dist/pages/components/page-meta-data/page-meta-data.js +1 -0
- package/dist/pages/loading-page/loading-page.js +1 -0
- package/dist/pages/my-sonic/actions/change-password/change-password-dialog.js +1 -0
- package/dist/pages/my-sonic/actions/change-password/change-password.js +1 -0
- package/dist/pages/my-sonic/actions/change-password/connected-change-password-dialog.js +1 -0
- package/dist/pages/my-sonic/navigation/my-sonic-desktop-navigation.js +1 -0
- package/dist/pages/my-sonic/navigation/my-sonic-navigation-items.js +1 -0
- package/dist/pages/my-sonic/widgets/connected-bill-to-address-widget.js +2 -1
- package/dist/pages/my-sonic/widgets/connected-ship-to-address-widget.js +2 -1
- package/dist/pages/product/layouts/product-details-page-layout/product-details-page-layout.js +1 -0
- package/dist/pages/product/product-details-page/components/product-details-images/product-detail-images.js +1 -3
- package/dist/pages/product/product-details-page/components/product-details-images/product-detail-images.module.css.js +1 -1
- package/dist/pages/product/product-details-page/product-details.js +5 -1
- package/dist/pages/product/product-listing-page/no-results/no-results.js +3 -1
- package/dist/promos/promo-banner/promo-banner.js +1 -0
- package/dist/shared/api/bff/hooks/use-fetch-announcements.js +1 -0
- package/dist/shared/api/bff/hooks/use-fetch-navigation-links.js +1 -0
- package/dist/shared/api/bff/hooks/use-fetch-product-details-page-data.js +1 -0
- package/dist/shared/api/bff/hooks/use-fetch-product-listing-page-data.js +1 -0
- package/dist/shared/api/bff/hooks/use-fetch-recently-viewed-products.js +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-fetch-session.js +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-invalidate-session.js +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-is-authenticated.js +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-patch-session.js +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-recover-password.js +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-sign-in.js +1 -0
- package/dist/shared/api/storefront/hooks/authentication/use-sign-out.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-add-product-to-current-cart.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-delete-cart-line-by-id.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-delete-current-cart.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-fetch-cart-by-id.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-checkout-atp.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-count.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-lines-with-atp.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-lines.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-product-atp.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-promotions.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart-with-atp.js +7 -4
- package/dist/shared/api/storefront/hooks/cart/use-fetch-current-cart.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-invalidate-current-cart.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart-line-by-id.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-patch-cart.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-place-order.js +1 -0
- package/dist/shared/api/storefront/hooks/cart/use-save-cart-for-later.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-bill-to-address.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-bill-to-addresses.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-current-bill-to-address.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-current-ship-to-address.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-fulfillment-methods-by-customer-id.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-fulfillment-methods-for-current-cart.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-ship-to-address.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-fetch-ship-to-addresses.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-patch-bill-to-address.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-patch-ship-to-address.js +1 -0
- package/dist/shared/api/storefront/hooks/customer/use-post-ship-to-address.js +1 -0
- package/dist/shared/api/storefront/hooks/orders/use-fetch-orders.js +1 -0
- package/dist/shared/api/storefront/hooks/payment/use-create-adyen-session.js +1 -0
- package/dist/shared/api/storefront/hooks/payment/use-fetch-adyen-config.js +1 -0
- package/dist/shared/api/storefront/hooks/payment/use-invalidate-adyen.js +1 -0
- package/dist/shared/api/storefront/hooks/product/use-mark-product-as-viewed.d.ts +5 -3
- package/dist/shared/api/storefront/hooks/product/use-mark-product-as-viewed.js +5 -8
- package/dist/shared/api/storefront/hooks/translation/use-fetch-translations.js +1 -0
- package/dist/shared/api/storefront/hooks/website/use-fetch-countries-languages.js +1 -0
- package/dist/shared/api/storefront/hooks/website/use-fetch-countries-with-languages.js +1 -0
- package/dist/shared/api/storefront/hooks/website/use-fetch-country-models.js +1 -0
- package/dist/shared/api/storefront/hooks/website/use-fetch-settings.js +1 -0
- package/dist/shared/api/storefront/hooks/website/use-update-locale.js +1 -0
- package/dist/shared/api/storefront/hooks/wishlist/use-add-wishlist-item-to-current-wishlist.js +1 -0
- package/dist/shared/api/storefront/hooks/wishlist/use-add-wishlist-item-to-wishlist.js +1 -1
- package/dist/shared/api/storefront/hooks/wishlist/use-create-wishlist.js +1 -0
- package/dist/shared/api/storefront/hooks/wishlist/use-delete-wishlist-item-from-wishlist.js +1 -0
- package/dist/shared/api/storefront/hooks/wishlist/use-fetch-all-wishlists-items.js +1 -1
- package/dist/shared/api/storefront/hooks/wishlist/use-fetch-wishlists.js +1 -0
- package/dist/shared/api/storefront/services/website-service.js +9 -0
- package/dist/shared/feature-flags/use-feature-flags.js +1 -0
- package/dist/shared/hooks/use-debounced-callback.d.ts +5 -1
- package/dist/shared/hooks/use-debounced-callback.js +10 -10
- package/dist/shared/providers/react-query-container.d.ts +8 -3
- package/dist/shared/providers/react-query-container.js +4 -4
- package/dist/shared/routing/route-provider.d.ts +1 -0
- package/dist/shared/routing/types.d.ts +1 -0
- package/dist/shared/routing/use-location.js +2 -2
- package/dist/sidebar/sidebar-provider.js +0 -2
- package/dist/styles.css +31 -1
- package/dist/table/elements/col.js +1 -0
- package/dist/table/elements/use-table-row.js +1 -0
- package/dist/table/elements/use-table.js +1 -0
- package/dist/table/elements/use-td.js +1 -0
- package/dist/table/elements/use-th.js +1 -0
- package/dist/text/highlight-text/highlight-text.js +1 -0
- package/dist/text/truncated/truncated.js +1 -0
- package/package.json +3 -3
- package/dist/shared/hooks/use-cookie.js +0 -34
|
@@ -5,7 +5,7 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
|
|
5
5
|
import { environment } from '../utils/environment.js';
|
|
6
6
|
import { TIME } from '../utils/time.js';
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const globalQueryClient = new QueryClient({
|
|
9
9
|
defaultOptions: {
|
|
10
10
|
queries: {
|
|
11
11
|
/* Set gcTime and staleTime to 0 to disable react query cache */
|
|
@@ -15,8 +15,8 @@ const queryClient = new QueryClient({
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
});
|
|
18
|
-
function ReactQueryContainer({ children, enableDevTools = environment !== 'production', }) {
|
|
19
|
-
return (jsxs(QueryClientProvider, { client: queryClient, children: [enableDevTools && jsx(ReactQueryDevtools, { initialIsOpen: false }), children] }));
|
|
18
|
+
function ReactQueryContainer({ children, enableDevTools = environment !== 'production', queryClient = globalQueryClient, }) {
|
|
19
|
+
return (jsxs(QueryClientProvider, { client: queryClient, children: [enableDevTools && jsx(ReactQueryDevtools, { initialIsOpen: false }), children instanceof Function ? children({ queryClient }) : children] }));
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export { ReactQueryContainer };
|
|
22
|
+
export { ReactQueryContainer, globalQueryClient };
|
|
@@ -3,12 +3,12 @@ import qs from 'query-string';
|
|
|
3
3
|
import { useRouter } from './use-router.js';
|
|
4
4
|
|
|
5
5
|
function useLocation() {
|
|
6
|
-
const { url: { basePathname, pathname, search }, } = useRouter();
|
|
6
|
+
const { url: { basePathname, href, pathname, search }, } = useRouter();
|
|
7
7
|
const query = qs.parse(search || '');
|
|
8
8
|
return {
|
|
9
9
|
basePathname,
|
|
10
10
|
fullPathname: pathname,
|
|
11
|
-
href
|
|
11
|
+
href,
|
|
12
12
|
pathname: pathname.replace(new RegExp(`^${basePathname}`), ''),
|
|
13
13
|
query,
|
|
14
14
|
search,
|
|
@@ -41,8 +41,6 @@ function SidebarProvider({ children }) {
|
|
|
41
41
|
const { close, isDocked, isOpen, transition } = state;
|
|
42
42
|
return (jsxs("div", { className: clsx(styles['sidebar-container'], {
|
|
43
43
|
[styles['transition']]: transition,
|
|
44
|
-
[styles['docked']]: isDocked,
|
|
45
|
-
[styles['open']]: isOpen,
|
|
46
44
|
}), children: [jsx(SidebarDetectBreakpoint, {}), children, jsx(BackgroundOverlay, { isOpen: isDocked && isOpen, onClick: close })] }));
|
|
47
45
|
}
|
|
48
46
|
|
package/dist/styles.css
CHANGED
|
@@ -479,7 +479,7 @@ html {
|
|
|
479
479
|
grid-template-rows: 1fr;
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
-
.accordion-module-9WvAH .accordion-module-lf9d-:has(.accordion-module--Rwpb[disabled]) {
|
|
482
|
+
.accordion-module-9WvAH .accordion-module-lf9d-:has(.accordion-module--Rwpb[disabled]):not(.accordion-module-RnNRT) {
|
|
483
483
|
border-color: var(--color-brand-light-gray);
|
|
484
484
|
}
|
|
485
485
|
|
|
@@ -2218,6 +2218,21 @@ html {
|
|
|
2218
2218
|
content: '/';
|
|
2219
2219
|
margin-inline: 10px;
|
|
2220
2220
|
}
|
|
2221
|
+
.breadcrumb-module-CQGse .breadcrumb-module-hxhDY.breadcrumb-module-ToeDB {
|
|
2222
|
+
display: flex;
|
|
2223
|
+
}
|
|
2224
|
+
.breadcrumb-module-CQGse .breadcrumb-module-hxhDY.breadcrumb-module-np5GK {
|
|
2225
|
+
display: none;
|
|
2226
|
+
}
|
|
2227
|
+
@media (width >= 768px) {
|
|
2228
|
+
.breadcrumb-module-CQGse .breadcrumb-module-hxhDY.breadcrumb-module-ToeDB {
|
|
2229
|
+
display: none;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
.breadcrumb-module-CQGse .breadcrumb-module-hxhDY.breadcrumb-module-np5GK {
|
|
2233
|
+
display: flex;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2221
2236
|
@media (width < 768px) {
|
|
2222
2237
|
.breadcrumb-module-CQGse .breadcrumb-module-hxhDY::after {
|
|
2223
2238
|
display: none;
|
|
@@ -3369,6 +3384,7 @@ html {
|
|
|
3369
3384
|
|
|
3370
3385
|
.product-card-module-pLaiB .product-card-module-XzunM {
|
|
3371
3386
|
z-index: var(--z-top);
|
|
3387
|
+
margin: 0;
|
|
3372
3388
|
grid-area: sku;
|
|
3373
3389
|
justify-self: start;
|
|
3374
3390
|
-webkit-user-select: all;
|
|
@@ -8555,6 +8571,20 @@ button.swiper-pagination-bullet {
|
|
|
8555
8571
|
padding: 64px 48px;
|
|
8556
8572
|
}
|
|
8557
8573
|
|
|
8574
|
+
.product-detail-images-module-cdIHn {
|
|
8575
|
+
display: none;
|
|
8576
|
+
}
|
|
8577
|
+
|
|
8578
|
+
@media (width >= 1024px) {
|
|
8579
|
+
.product-detail-images-module-0udrk {
|
|
8580
|
+
display: none;
|
|
8581
|
+
}
|
|
8582
|
+
|
|
8583
|
+
.product-detail-images-module-cdIHn {
|
|
8584
|
+
display: grid;
|
|
8585
|
+
}
|
|
8586
|
+
}
|
|
8587
|
+
|
|
8558
8588
|
.product-details-panel-module-MXfPm {
|
|
8559
8589
|
display: flex;
|
|
8560
8590
|
flex-direction: column;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonic-equipment/ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "204.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"update-packages": "npx npm-check-updates -u"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"react": "^18",
|
|
50
|
-
"react-dom": "^18"
|
|
49
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
50
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@chromatic-com/storybook": "^3.2.6",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import Cookies from 'js-cookie';
|
|
4
|
-
import { config } from '../../config.js';
|
|
5
|
-
|
|
6
|
-
const defaultCookieOptions = {
|
|
7
|
-
domain: config.COOKIE_DOMAIN,
|
|
8
|
-
expires: 365,
|
|
9
|
-
path: '/',
|
|
10
|
-
sameSite: 'None',
|
|
11
|
-
secure: true,
|
|
12
|
-
};
|
|
13
|
-
function useCookie(name, options = defaultCookieOptions) {
|
|
14
|
-
const cookieValue = Cookies.get()?.[name];
|
|
15
|
-
const [stateValue, setStateValue] = useState(cookieValue);
|
|
16
|
-
if (cookieValue !== stateValue) {
|
|
17
|
-
setStateValue(cookieValue);
|
|
18
|
-
}
|
|
19
|
-
function setValue(valueOrFn) {
|
|
20
|
-
setStateValue(oldValue => {
|
|
21
|
-
const newValue = typeof valueOrFn === 'function' ? valueOrFn(oldValue) : valueOrFn;
|
|
22
|
-
if (newValue) {
|
|
23
|
-
Cookies.set(name, newValue, options);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
Cookies.remove(name);
|
|
27
|
-
}
|
|
28
|
-
return newValue;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return [stateValue, setValue];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { defaultCookieOptions, useCookie };
|