@wix/headless-stores 0.0.51 → 0.0.53
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/cjs/dist/astro/actions/custom-checkout.d.ts +1 -1
- package/cjs/dist/astro/actions/custom-checkout.js +2 -2
- package/cjs/dist/astro/actions/index.d.ts +1 -1
- package/cjs/dist/astro/actions/index.js +1 -1
- package/cjs/dist/enums/index.d.ts +2 -2
- package/cjs/dist/enums/index.js +2 -2
- package/cjs/dist/react/Category.d.ts +168 -67
- package/cjs/dist/react/Category.js +166 -50
- package/cjs/dist/react/CategoryList.d.ts +56 -138
- package/cjs/dist/react/CategoryList.js +44 -129
- package/cjs/dist/react/Choice.d.ts +193 -0
- package/cjs/dist/react/Choice.js +259 -0
- package/cjs/dist/react/Option.d.ts +224 -0
- package/cjs/dist/react/Option.js +388 -0
- package/cjs/dist/react/Product.d.ts +339 -96
- package/cjs/dist/react/Product.js +507 -94
- package/cjs/dist/react/{BuyNow.js → core/BuyNow.js} +2 -2
- package/cjs/dist/react/core/Category.d.ts +98 -0
- package/cjs/dist/react/core/Category.js +81 -0
- package/cjs/dist/react/core/CategoryList.d.ts +185 -0
- package/cjs/dist/react/core/CategoryList.js +174 -0
- package/{dist/react → cjs/dist/react/core}/PayNow.js +2 -2
- package/cjs/dist/react/core/Product.d.ts +148 -0
- package/cjs/dist/react/core/Product.js +126 -0
- package/cjs/dist/react/{ProductList.d.ts → core/ProductList.d.ts} +3 -3
- package/cjs/dist/react/{ProductList.js → core/ProductList.js} +10 -10
- package/{dist/react → cjs/dist/react/core}/ProductListFilters.d.ts +3 -3
- package/{dist/react → cjs/dist/react/core}/ProductListFilters.js +7 -7
- package/cjs/dist/react/{ProductListPagination.js → core/ProductListPagination.js} +8 -8
- package/{dist/react → cjs/dist/react/core}/ProductListSort.d.ts +1 -1
- package/cjs/dist/react/{ProductListSort.js → core/ProductListSort.js} +3 -3
- package/{dist/react → cjs/dist/react/core}/ProductModifiers.d.ts +1 -1
- package/{dist/react → cjs/dist/react/core}/ProductModifiers.js +13 -13
- package/{dist/react → cjs/dist/react/core}/ProductVariantSelector.d.ts +2 -2
- package/{dist/react → cjs/dist/react/core}/ProductVariantSelector.js +7 -10
- package/{dist/react → cjs/dist/react/core}/SelectedVariant.d.ts +2 -2
- package/{dist/react → cjs/dist/react/core}/SelectedVariant.js +43 -15
- package/cjs/dist/react/index.d.ts +15 -10
- package/cjs/dist/react/index.js +15 -10
- package/cjs/dist/react/types.d.ts +8 -0
- package/cjs/dist/react/types.js +9 -0
- package/cjs/dist/server-actions/custom-checkout-action.js +14 -10
- package/cjs/dist/server-actions/index.d.ts +1 -1
- package/cjs/dist/server-actions/index.js +1 -1
- package/cjs/dist/services/buy-now-service.d.ts +1 -1
- package/cjs/dist/services/buy-now-service.js +6 -6
- package/cjs/dist/services/categories-list-service.d.ts +4 -4
- package/cjs/dist/services/categories-list-service.js +10 -10
- package/cjs/dist/services/category-service.d.ts +18 -22
- package/cjs/dist/services/category-service.js +12 -10
- package/cjs/dist/services/index.d.ts +7 -7
- package/cjs/dist/services/index.js +7 -7
- package/cjs/dist/services/pay-now-service.d.ts +1 -1
- package/cjs/dist/services/pay-now-service.js +4 -4
- package/cjs/dist/services/product-modifiers-service.d.ts +3 -3
- package/cjs/dist/services/product-modifiers-service.js +7 -7
- package/cjs/dist/services/product-service.d.ts +4 -4
- package/cjs/dist/services/product-service.js +18 -18
- package/cjs/dist/services/products-list-search-service.d.ts +5 -5
- package/cjs/dist/services/products-list-search-service.js +117 -117
- package/cjs/dist/services/products-list-service.d.ts +4 -4
- package/cjs/dist/services/products-list-service.js +12 -12
- package/cjs/dist/services/selected-variant-service.d.ts +6 -2
- package/cjs/dist/services/selected-variant-service.js +92 -87
- package/cjs/dist/utils/index.d.ts +1 -0
- package/cjs/dist/utils/index.js +5 -4
- package/cjs/dist/utils/renderAsChild.d.ts +96 -0
- package/cjs/dist/utils/renderAsChild.js +66 -0
- package/cjs/dist/utils/renderChildren.d.ts +41 -0
- package/cjs/dist/utils/renderChildren.js +44 -0
- package/cjs/dist/utils/url-params.js +3 -3
- package/dist/astro/actions/custom-checkout.d.ts +1 -1
- package/dist/astro/actions/custom-checkout.js +2 -2
- package/dist/astro/actions/index.d.ts +1 -1
- package/dist/astro/actions/index.js +1 -1
- package/dist/enums/index.d.ts +2 -2
- package/dist/enums/index.js +2 -2
- package/dist/react/Category.d.ts +168 -67
- package/dist/react/Category.js +166 -50
- package/dist/react/CategoryList.d.ts +56 -138
- package/dist/react/CategoryList.js +44 -129
- package/dist/react/Choice.d.ts +193 -0
- package/dist/react/Choice.js +259 -0
- package/dist/react/Option.d.ts +224 -0
- package/dist/react/Option.js +388 -0
- package/dist/react/Product.d.ts +339 -96
- package/dist/react/Product.js +507 -94
- package/dist/react/{BuyNow.js → core/BuyNow.js} +2 -2
- package/dist/react/core/Category.d.ts +98 -0
- package/dist/react/core/Category.js +81 -0
- package/dist/react/core/CategoryList.d.ts +185 -0
- package/dist/react/core/CategoryList.js +174 -0
- package/{cjs/dist/react → dist/react/core}/PayNow.js +2 -2
- package/dist/react/core/Product.d.ts +148 -0
- package/dist/react/core/Product.js +126 -0
- package/dist/react/{ProductList.d.ts → core/ProductList.d.ts} +3 -3
- package/dist/react/{ProductList.js → core/ProductList.js} +10 -10
- package/{cjs/dist/react → dist/react/core}/ProductListFilters.d.ts +3 -3
- package/{cjs/dist/react → dist/react/core}/ProductListFilters.js +7 -7
- package/dist/react/{ProductListPagination.js → core/ProductListPagination.js} +8 -8
- package/{cjs/dist/react → dist/react/core}/ProductListSort.d.ts +1 -1
- package/dist/react/{ProductListSort.js → core/ProductListSort.js} +3 -3
- package/{cjs/dist/react → dist/react/core}/ProductModifiers.d.ts +1 -1
- package/{cjs/dist/react → dist/react/core}/ProductModifiers.js +13 -13
- package/{cjs/dist/react → dist/react/core}/ProductVariantSelector.d.ts +2 -2
- package/{cjs/dist/react → dist/react/core}/ProductVariantSelector.js +7 -10
- package/{cjs/dist/react → dist/react/core}/SelectedVariant.d.ts +2 -2
- package/{cjs/dist/react → dist/react/core}/SelectedVariant.js +43 -15
- package/dist/react/index.d.ts +15 -10
- package/dist/react/index.js +15 -10
- package/dist/react/types.d.ts +8 -0
- package/dist/react/types.js +9 -0
- package/dist/server-actions/custom-checkout-action.js +14 -10
- package/dist/server-actions/index.d.ts +1 -1
- package/dist/server-actions/index.js +1 -1
- package/dist/services/buy-now-service.d.ts +1 -1
- package/dist/services/buy-now-service.js +6 -6
- package/dist/services/categories-list-service.d.ts +4 -4
- package/dist/services/categories-list-service.js +10 -10
- package/dist/services/category-service.d.ts +18 -22
- package/dist/services/category-service.js +12 -10
- package/dist/services/index.d.ts +7 -7
- package/dist/services/index.js +7 -7
- package/dist/services/pay-now-service.d.ts +1 -1
- package/dist/services/pay-now-service.js +4 -4
- package/dist/services/product-modifiers-service.d.ts +3 -3
- package/dist/services/product-modifiers-service.js +7 -7
- package/dist/services/product-service.d.ts +4 -4
- package/dist/services/product-service.js +18 -18
- package/dist/services/products-list-search-service.d.ts +5 -5
- package/dist/services/products-list-search-service.js +117 -117
- package/dist/services/products-list-service.d.ts +4 -4
- package/dist/services/products-list-service.js +12 -12
- package/dist/services/selected-variant-service.d.ts +6 -2
- package/dist/services/selected-variant-service.js +92 -87
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +5 -4
- package/dist/utils/renderAsChild.d.ts +96 -0
- package/dist/utils/renderAsChild.js +66 -0
- package/dist/utils/renderChildren.d.ts +41 -0
- package/dist/utils/renderChildren.js +44 -0
- package/dist/utils/url-params.js +3 -3
- package/package.json +7 -3
- /package/cjs/dist/react/{BuyNow.d.ts → core/BuyNow.d.ts} +0 -0
- /package/cjs/dist/react/{PayNow.d.ts → core/PayNow.d.ts} +0 -0
- /package/cjs/dist/react/{ProductListPagination.d.ts → core/ProductListPagination.d.ts} +0 -0
- /package/dist/react/{BuyNow.d.ts → core/BuyNow.d.ts} +0 -0
- /package/dist/react/{PayNow.d.ts → core/PayNow.d.ts} +0 -0
- /package/dist/react/{ProductListPagination.d.ts → core/ProductListPagination.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="astro/env" />
|
|
2
2
|
// @ts-ignore
|
|
3
|
-
import { defineAction } from
|
|
4
|
-
import { getCustomLineItemCheckoutURLFactory, } from
|
|
3
|
+
import { defineAction } from 'astro:actions';
|
|
4
|
+
import { getCustomLineItemCheckoutURLFactory, } from '../../server-actions/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* Creates an Astro action factory for custom checkout functionality with line items.
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './custom-checkout.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './custom-checkout.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './sort-enums.js';
|
|
2
|
+
export * from './social-platform-enums.js';
|
package/cjs/dist/enums/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './sort-enums.js';
|
|
2
|
+
export * from './social-platform-enums.js';
|
|
@@ -1,98 +1,199 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Category } from '../services/category-service.js';
|
|
3
|
+
import { type CategoryServiceConfig } from '../services/category-service.js';
|
|
4
|
+
/**
|
|
5
|
+
* Props for Category.Root component
|
|
6
|
+
*/
|
|
7
|
+
export interface CategoryRootProps {
|
|
8
|
+
/** Category object to initialize the service with */
|
|
9
|
+
category?: Category;
|
|
10
|
+
/** Configuration for the category service */
|
|
11
|
+
categoryServiceConfig?: CategoryServiceConfig;
|
|
12
|
+
/** Whether the category is currently selected */
|
|
13
|
+
isSelected?: boolean;
|
|
14
|
+
/** Child components */
|
|
3
15
|
children: React.ReactNode;
|
|
4
|
-
categoryServiceConfig: CategoryServiceConfig;
|
|
5
16
|
}
|
|
6
17
|
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
18
|
+
* Props for Category.Trigger component
|
|
19
|
+
*/
|
|
20
|
+
export interface CategoryTriggerProps {
|
|
21
|
+
/** Whether to render as a child component */
|
|
22
|
+
asChild?: boolean;
|
|
23
|
+
/** Custom render function when using asChild */
|
|
24
|
+
children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLButtonElement, {
|
|
25
|
+
category: Category;
|
|
26
|
+
isSelected: boolean;
|
|
27
|
+
onSelect: () => void;
|
|
28
|
+
}>;
|
|
29
|
+
/** Callback when category is selected */
|
|
30
|
+
onSelect?: (category: Category) => void;
|
|
31
|
+
/** CSS classes to apply to the default element */
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Props for Category.Label component
|
|
36
|
+
*/
|
|
37
|
+
export interface CategoryLabelProps {
|
|
38
|
+
/** Whether to render as a child component */
|
|
39
|
+
asChild?: boolean;
|
|
40
|
+
/** Custom render function when using asChild */
|
|
41
|
+
children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLElement, {
|
|
42
|
+
name: string;
|
|
43
|
+
category: Category;
|
|
44
|
+
}>;
|
|
45
|
+
/** CSS classes to apply to the default element */
|
|
46
|
+
className?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Props for Category.ID component
|
|
50
|
+
*/
|
|
51
|
+
export interface CategoryIDProps {
|
|
52
|
+
/** Whether to render as a child component */
|
|
53
|
+
asChild?: boolean;
|
|
54
|
+
/** Custom render function when using asChild */
|
|
55
|
+
children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLElement, {
|
|
56
|
+
id: string;
|
|
57
|
+
category: Category;
|
|
58
|
+
}>;
|
|
59
|
+
/** CSS classes to apply to the default element */
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Props for Category.Raw component
|
|
64
|
+
*/
|
|
65
|
+
export interface CategoryRawProps {
|
|
66
|
+
/** Whether to render as a child component */
|
|
67
|
+
asChild?: boolean;
|
|
68
|
+
/** Custom render function when using asChild */
|
|
69
|
+
children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLElement, {
|
|
70
|
+
category: Category;
|
|
71
|
+
isSelected: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
/** CSS classes to apply to the default element */
|
|
74
|
+
className?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Root container for a single category item.
|
|
78
|
+
* This component sets up the necessary services for managing category state
|
|
79
|
+
* and provides category context to child components.
|
|
9
80
|
*
|
|
10
81
|
* @order 1
|
|
11
82
|
* @component
|
|
12
83
|
* @example
|
|
13
84
|
* ```tsx
|
|
14
|
-
* import { Category } from '@wix/stores/
|
|
85
|
+
* import { Category } from '@wix/headless-stores/react';
|
|
15
86
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* </Category.Name>
|
|
22
|
-
* <Category.Slug>
|
|
23
|
-
* {({ slug }) => <p>Slug: {slug}</p>}
|
|
24
|
-
* </Category.Slug>
|
|
25
|
-
* </Category.Root>
|
|
26
|
-
* );
|
|
27
|
-
* }
|
|
87
|
+
* <Category.Root categoryServiceConfig={{ category }}>
|
|
88
|
+
* <Category.Trigger />
|
|
89
|
+
* <Category.Label />
|
|
90
|
+
* <Category.ID />
|
|
91
|
+
* </Category.Root>
|
|
28
92
|
* ```
|
|
29
93
|
*/
|
|
30
|
-
export declare function Root(props:
|
|
94
|
+
export declare function Root(props: CategoryRootProps): React.ReactNode;
|
|
31
95
|
/**
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
96
|
+
* Interactive element for selecting or triggering category actions.
|
|
97
|
+
* Provides category data and selection state to custom render functions.
|
|
98
|
+
*
|
|
99
|
+
* @component
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* // Default usage
|
|
103
|
+
* <Category.Trigger className="px-4 py-2 rounded border hover:bg-surface-hover" />
|
|
104
|
+
*
|
|
105
|
+
* // Custom rendering with forwardRef
|
|
106
|
+
* <Category.Trigger asChild>
|
|
107
|
+
* {React.forwardRef(({category, isSelected, onSelect, ...props}, ref) => (
|
|
108
|
+
* <button
|
|
109
|
+
* ref={ref}
|
|
110
|
+
* {...props}
|
|
111
|
+
* onClick={onSelect}
|
|
112
|
+
* className={`px-4 py-2 rounded transition-colors ${
|
|
113
|
+
* isSelected
|
|
114
|
+
* ? 'bg-brand-primary text-white'
|
|
115
|
+
* : 'border border-surface-subtle hover:bg-surface-hover'
|
|
116
|
+
* }`}
|
|
117
|
+
* >
|
|
118
|
+
* {category.name}
|
|
119
|
+
* </button>
|
|
120
|
+
* ))}
|
|
121
|
+
* </Category.Trigger>
|
|
122
|
+
* ```
|
|
40
123
|
*/
|
|
41
|
-
export
|
|
42
|
-
/** Category name */
|
|
43
|
-
name: string;
|
|
44
|
-
}
|
|
124
|
+
export declare const Trigger: React.ForwardRefExoticComponent<CategoryTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
45
125
|
/**
|
|
46
|
-
*
|
|
126
|
+
* Displays the category name or label.
|
|
127
|
+
* Provides category name and full category data to custom render functions.
|
|
47
128
|
*
|
|
48
129
|
* @component
|
|
49
130
|
* @example
|
|
50
131
|
* ```tsx
|
|
51
|
-
*
|
|
132
|
+
* // Default usage
|
|
133
|
+
* <Category.Label className="text-lg font-medium text-content-primary" />
|
|
52
134
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
135
|
+
* // Custom rendering with forwardRef
|
|
136
|
+
* <Category.Label asChild>
|
|
137
|
+
* {React.forwardRef(({name, category, ...props}, ref) => (
|
|
138
|
+
* <span ref={ref} {...props} className="text-lg font-medium text-content-primary">
|
|
139
|
+
* {name}
|
|
140
|
+
* {category.numberOfProducts > 0 && (
|
|
141
|
+
* <span className="text-sm text-content-muted ml-2">
|
|
142
|
+
* ({category.numberOfProducts})
|
|
143
|
+
* </span>
|
|
58
144
|
* )}
|
|
59
|
-
* </
|
|
60
|
-
* )
|
|
61
|
-
*
|
|
145
|
+
* </span>
|
|
146
|
+
* ))}
|
|
147
|
+
* </Category.Label>
|
|
62
148
|
* ```
|
|
63
149
|
*/
|
|
64
|
-
export declare
|
|
65
|
-
/**
|
|
66
|
-
* Props for Slug headless component
|
|
67
|
-
*/
|
|
68
|
-
export interface SlugProps {
|
|
69
|
-
/** Content to display (can be a render function receiving slug data or ReactNode) */
|
|
70
|
-
children: ((props: SlugRenderProps) => React.ReactNode) | React.ReactNode;
|
|
71
|
-
}
|
|
150
|
+
export declare const Label: React.ForwardRefExoticComponent<CategoryLabelProps & React.RefAttributes<HTMLElement>>;
|
|
72
151
|
/**
|
|
73
|
-
*
|
|
152
|
+
* Provides access to the category ID for advanced use cases.
|
|
153
|
+
* Typically used for tracking, analytics, or hidden form fields.
|
|
154
|
+
*
|
|
155
|
+
* @component
|
|
156
|
+
* @example
|
|
157
|
+
* ```tsx
|
|
158
|
+
* // Default usage (hidden by default)
|
|
159
|
+
* <Category.ID className="hidden" />
|
|
160
|
+
*
|
|
161
|
+
* // Custom rendering with forwardRef
|
|
162
|
+
* <Category.ID asChild>
|
|
163
|
+
* {React.forwardRef(({id, category, ...props}, ref) => (
|
|
164
|
+
* <span
|
|
165
|
+
* ref={ref}
|
|
166
|
+
* {...props}
|
|
167
|
+
* data-category-id={id}
|
|
168
|
+
* className="sr-only"
|
|
169
|
+
* >
|
|
170
|
+
* Category ID: {id}
|
|
171
|
+
* </span>
|
|
172
|
+
* ))}
|
|
173
|
+
* </Category.ID>
|
|
174
|
+
* ```
|
|
74
175
|
*/
|
|
75
|
-
export
|
|
76
|
-
/** Category slug */
|
|
77
|
-
slug: string;
|
|
78
|
-
}
|
|
176
|
+
export declare const ID: React.ForwardRefExoticComponent<CategoryIDProps & React.RefAttributes<HTMLElement>>;
|
|
79
177
|
/**
|
|
80
|
-
*
|
|
178
|
+
* Provides access to the full category data for advanced use cases.
|
|
179
|
+
* Useful for custom implementations that need access to all category properties.
|
|
81
180
|
*
|
|
82
181
|
* @component
|
|
83
182
|
* @example
|
|
84
183
|
* ```tsx
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* {
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
184
|
+
* // Custom rendering with forwardRef
|
|
185
|
+
* <Category.Raw asChild>
|
|
186
|
+
* {React.forwardRef(({category, ...props}, ref) => (
|
|
187
|
+
* <div
|
|
188
|
+
* ref={ref}
|
|
189
|
+
* {...props}
|
|
190
|
+
* data-category-id={category._id}
|
|
191
|
+
* className="category-raw-data"
|
|
192
|
+
* >
|
|
193
|
+
* <pre>{JSON.stringify(category, null, 2)}</pre>
|
|
194
|
+
* </div>
|
|
195
|
+
* ))}
|
|
196
|
+
* </Category.Raw>
|
|
96
197
|
* ```
|
|
97
198
|
*/
|
|
98
|
-
export declare
|
|
199
|
+
export declare const Raw: React.ForwardRefExoticComponent<CategoryRawProps & React.RefAttributes<HTMLElement>>;
|
|
@@ -1,81 +1,197 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
4
|
+
import * as CoreCategory from './core/Category.js';
|
|
5
|
+
import { CategoryServiceDefinition, } from '../services/category-service.js';
|
|
6
|
+
import { useService } from '@wix/services-manager-react';
|
|
7
|
+
import { renderChildren } from '../utils/renderChildren.js';
|
|
8
|
+
var TestIds;
|
|
9
|
+
(function (TestIds) {
|
|
10
|
+
TestIds["categoryItem"] = "category-item";
|
|
11
|
+
TestIds["categoryTrigger"] = "category-trigger";
|
|
12
|
+
TestIds["categoryLabel"] = "category-label";
|
|
13
|
+
TestIds["categoryId"] = "category-id";
|
|
14
|
+
TestIds["categoryRaw"] = "category-raw";
|
|
15
|
+
})(TestIds || (TestIds = {}));
|
|
5
16
|
/**
|
|
6
|
-
* Root
|
|
7
|
-
* This component sets up the necessary services for managing category state
|
|
17
|
+
* Root container for a single category item.
|
|
18
|
+
* This component sets up the necessary services for managing category state
|
|
19
|
+
* and provides category context to child components.
|
|
8
20
|
*
|
|
9
21
|
* @order 1
|
|
10
22
|
* @component
|
|
11
23
|
* @example
|
|
12
24
|
* ```tsx
|
|
13
|
-
* import { Category } from '@wix/stores/
|
|
25
|
+
* import { Category } from '@wix/headless-stores/react';
|
|
14
26
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* </Category.Name>
|
|
21
|
-
* <Category.Slug>
|
|
22
|
-
* {({ slug }) => <p>Slug: {slug}</p>}
|
|
23
|
-
* </Category.Slug>
|
|
24
|
-
* </Category.Root>
|
|
25
|
-
* );
|
|
26
|
-
* }
|
|
27
|
+
* <Category.Root categoryServiceConfig={{ category }}>
|
|
28
|
+
* <Category.Trigger />
|
|
29
|
+
* <Category.Label />
|
|
30
|
+
* <Category.ID />
|
|
31
|
+
* </Category.Root>
|
|
27
32
|
* ```
|
|
28
33
|
*/
|
|
29
34
|
export function Root(props) {
|
|
30
|
-
|
|
35
|
+
const { category, categoryServiceConfig, isSelected, children } = props;
|
|
36
|
+
if (!category && !categoryServiceConfig) {
|
|
37
|
+
throw new Error('Category.Root: category or categoryServiceConfig is required');
|
|
38
|
+
}
|
|
39
|
+
const serviceConfig = categoryServiceConfig || {
|
|
40
|
+
category: category,
|
|
41
|
+
isSelected,
|
|
42
|
+
};
|
|
43
|
+
return (_jsx(CoreCategory.Root, { categoryServiceConfig: serviceConfig, children: children }));
|
|
31
44
|
}
|
|
32
45
|
/**
|
|
33
|
-
*
|
|
46
|
+
* Interactive element for selecting or triggering category actions.
|
|
47
|
+
* Provides category data and selection state to custom render functions.
|
|
34
48
|
*
|
|
35
49
|
* @component
|
|
36
50
|
* @example
|
|
37
51
|
* ```tsx
|
|
38
|
-
*
|
|
52
|
+
* // Default usage
|
|
53
|
+
* <Category.Trigger className="px-4 py-2 rounded border hover:bg-surface-hover" />
|
|
39
54
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
55
|
+
* // Custom rendering with forwardRef
|
|
56
|
+
* <Category.Trigger asChild>
|
|
57
|
+
* {React.forwardRef(({category, isSelected, onSelect, ...props}, ref) => (
|
|
58
|
+
* <button
|
|
59
|
+
* ref={ref}
|
|
60
|
+
* {...props}
|
|
61
|
+
* onClick={onSelect}
|
|
62
|
+
* className={`px-4 py-2 rounded transition-colors ${
|
|
63
|
+
* isSelected
|
|
64
|
+
* ? 'bg-brand-primary text-white'
|
|
65
|
+
* : 'border border-surface-subtle hover:bg-surface-hover'
|
|
66
|
+
* }`}
|
|
67
|
+
* >
|
|
68
|
+
* {category.name}
|
|
69
|
+
* </button>
|
|
70
|
+
* ))}
|
|
71
|
+
* </Category.Trigger>
|
|
49
72
|
* ```
|
|
50
73
|
*/
|
|
51
|
-
export
|
|
74
|
+
export const Trigger = React.forwardRef((props, ref) => {
|
|
75
|
+
const { asChild, children, onSelect, className } = props;
|
|
52
76
|
const categoryService = useService(CategoryServiceDefinition);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
77
|
+
const category = categoryService.category.get();
|
|
78
|
+
const isSelected = categoryService.isSelected.get();
|
|
79
|
+
const handleSelect = () => {
|
|
80
|
+
if (onSelect) {
|
|
81
|
+
onSelect(category);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const Comp = asChild && children ? Slot : 'button';
|
|
85
|
+
return (_jsx(Comp, { ref: ref, className: className, onClick: handleSelect, "data-testid": TestIds.categoryTrigger, "data-selected": isSelected ? 'true' : 'false', children: asChild && children
|
|
86
|
+
? renderChildren({
|
|
87
|
+
children,
|
|
88
|
+
props: { category, isSelected, onSelect: handleSelect },
|
|
89
|
+
ref,
|
|
90
|
+
})
|
|
91
|
+
: category.name }));
|
|
92
|
+
});
|
|
57
93
|
/**
|
|
58
|
-
*
|
|
94
|
+
* Displays the category name or label.
|
|
95
|
+
* Provides category name and full category data to custom render functions.
|
|
59
96
|
*
|
|
60
97
|
* @component
|
|
61
98
|
* @example
|
|
62
99
|
* ```tsx
|
|
63
|
-
*
|
|
100
|
+
* // Default usage
|
|
101
|
+
* <Category.Label className="text-lg font-medium text-content-primary" />
|
|
64
102
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
103
|
+
* // Custom rendering with forwardRef
|
|
104
|
+
* <Category.Label asChild>
|
|
105
|
+
* {React.forwardRef(({name, category, ...props}, ref) => (
|
|
106
|
+
* <span ref={ref} {...props} className="text-lg font-medium text-content-primary">
|
|
107
|
+
* {name}
|
|
108
|
+
* {category.numberOfProducts > 0 && (
|
|
109
|
+
* <span className="text-sm text-content-muted ml-2">
|
|
110
|
+
* ({category.numberOfProducts})
|
|
111
|
+
* </span>
|
|
70
112
|
* )}
|
|
71
|
-
* </
|
|
72
|
-
* )
|
|
73
|
-
*
|
|
113
|
+
* </span>
|
|
114
|
+
* ))}
|
|
115
|
+
* </Category.Label>
|
|
74
116
|
* ```
|
|
75
117
|
*/
|
|
76
|
-
export
|
|
118
|
+
export const Label = React.forwardRef((props, ref) => {
|
|
119
|
+
const { asChild, children, className } = props;
|
|
77
120
|
const categoryService = useService(CategoryServiceDefinition);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
121
|
+
const category = categoryService.category.get();
|
|
122
|
+
const isSelected = categoryService.isSelected.get();
|
|
123
|
+
return (_jsx(CoreCategory.Name, { children: ({ name }) => {
|
|
124
|
+
const Comp = asChild && children ? Slot : 'span';
|
|
125
|
+
return (_jsx(Comp, { ref: ref, className: className, "data-testid": TestIds.categoryLabel, "data-selected": isSelected ? 'true' : 'false', children: asChild && children
|
|
126
|
+
? renderChildren({ children, props: { name, category }, ref })
|
|
127
|
+
: name }));
|
|
128
|
+
} }));
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* Provides access to the category ID for advanced use cases.
|
|
132
|
+
* Typically used for tracking, analytics, or hidden form fields.
|
|
133
|
+
*
|
|
134
|
+
* @component
|
|
135
|
+
* @example
|
|
136
|
+
* ```tsx
|
|
137
|
+
* // Default usage (hidden by default)
|
|
138
|
+
* <Category.ID className="hidden" />
|
|
139
|
+
*
|
|
140
|
+
* // Custom rendering with forwardRef
|
|
141
|
+
* <Category.ID asChild>
|
|
142
|
+
* {React.forwardRef(({id, category, ...props}, ref) => (
|
|
143
|
+
* <span
|
|
144
|
+
* ref={ref}
|
|
145
|
+
* {...props}
|
|
146
|
+
* data-category-id={id}
|
|
147
|
+
* className="sr-only"
|
|
148
|
+
* >
|
|
149
|
+
* Category ID: {id}
|
|
150
|
+
* </span>
|
|
151
|
+
* ))}
|
|
152
|
+
* </Category.ID>
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export const ID = React.forwardRef((props, ref) => {
|
|
156
|
+
const { asChild, children, className } = props;
|
|
157
|
+
const categoryService = useService(CategoryServiceDefinition);
|
|
158
|
+
const category = categoryService.category.get();
|
|
159
|
+
const isSelected = categoryService.isSelected.get();
|
|
160
|
+
const id = category._id || '';
|
|
161
|
+
const Comp = asChild && children ? Slot : 'span';
|
|
162
|
+
return (_jsx(Comp, { ref: ref, className: className || 'sr-only', "data-testid": TestIds.categoryId, "data-selected": isSelected ? 'true' : 'false', children: asChild && children
|
|
163
|
+
? renderChildren({ children, props: { id, category }, ref })
|
|
164
|
+
: id }));
|
|
165
|
+
});
|
|
166
|
+
/**
|
|
167
|
+
* Provides access to the full category data for advanced use cases.
|
|
168
|
+
* Useful for custom implementations that need access to all category properties.
|
|
169
|
+
*
|
|
170
|
+
* @component
|
|
171
|
+
* @example
|
|
172
|
+
* ```tsx
|
|
173
|
+
* // Custom rendering with forwardRef
|
|
174
|
+
* <Category.Raw asChild>
|
|
175
|
+
* {React.forwardRef(({category, ...props}, ref) => (
|
|
176
|
+
* <div
|
|
177
|
+
* ref={ref}
|
|
178
|
+
* {...props}
|
|
179
|
+
* data-category-id={category._id}
|
|
180
|
+
* className="category-raw-data"
|
|
181
|
+
* >
|
|
182
|
+
* <pre>{JSON.stringify(category, null, 2)}</pre>
|
|
183
|
+
* </div>
|
|
184
|
+
* ))}
|
|
185
|
+
* </Category.Raw>
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export const Raw = React.forwardRef((props, ref) => {
|
|
189
|
+
const { asChild, children, className } = props;
|
|
190
|
+
const categoryService = useService(CategoryServiceDefinition);
|
|
191
|
+
const category = categoryService.category.get();
|
|
192
|
+
const isSelected = categoryService.isSelected.get();
|
|
193
|
+
const Comp = asChild && children ? Slot : 'span';
|
|
194
|
+
return (_jsx(Comp, { ref: ref, className: className || 'sr-only', "data-testid": TestIds.categoryRaw, "data-selected": isSelected ? 'true' : 'false', children: asChild && children
|
|
195
|
+
? renderChildren({ children, props: { category, isSelected }, ref })
|
|
196
|
+
: JSON.stringify(category) }));
|
|
197
|
+
});
|