@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.
Files changed (149) hide show
  1. package/cjs/dist/astro/actions/custom-checkout.d.ts +1 -1
  2. package/cjs/dist/astro/actions/custom-checkout.js +2 -2
  3. package/cjs/dist/astro/actions/index.d.ts +1 -1
  4. package/cjs/dist/astro/actions/index.js +1 -1
  5. package/cjs/dist/enums/index.d.ts +2 -2
  6. package/cjs/dist/enums/index.js +2 -2
  7. package/cjs/dist/react/Category.d.ts +168 -67
  8. package/cjs/dist/react/Category.js +166 -50
  9. package/cjs/dist/react/CategoryList.d.ts +56 -138
  10. package/cjs/dist/react/CategoryList.js +44 -129
  11. package/cjs/dist/react/Choice.d.ts +193 -0
  12. package/cjs/dist/react/Choice.js +259 -0
  13. package/cjs/dist/react/Option.d.ts +224 -0
  14. package/cjs/dist/react/Option.js +388 -0
  15. package/cjs/dist/react/Product.d.ts +339 -96
  16. package/cjs/dist/react/Product.js +507 -94
  17. package/cjs/dist/react/{BuyNow.js → core/BuyNow.js} +2 -2
  18. package/cjs/dist/react/core/Category.d.ts +98 -0
  19. package/cjs/dist/react/core/Category.js +81 -0
  20. package/cjs/dist/react/core/CategoryList.d.ts +185 -0
  21. package/cjs/dist/react/core/CategoryList.js +174 -0
  22. package/{dist/react → cjs/dist/react/core}/PayNow.js +2 -2
  23. package/cjs/dist/react/core/Product.d.ts +148 -0
  24. package/cjs/dist/react/core/Product.js +126 -0
  25. package/cjs/dist/react/{ProductList.d.ts → core/ProductList.d.ts} +3 -3
  26. package/cjs/dist/react/{ProductList.js → core/ProductList.js} +10 -10
  27. package/{dist/react → cjs/dist/react/core}/ProductListFilters.d.ts +3 -3
  28. package/{dist/react → cjs/dist/react/core}/ProductListFilters.js +7 -7
  29. package/cjs/dist/react/{ProductListPagination.js → core/ProductListPagination.js} +8 -8
  30. package/{dist/react → cjs/dist/react/core}/ProductListSort.d.ts +1 -1
  31. package/cjs/dist/react/{ProductListSort.js → core/ProductListSort.js} +3 -3
  32. package/{dist/react → cjs/dist/react/core}/ProductModifiers.d.ts +1 -1
  33. package/{dist/react → cjs/dist/react/core}/ProductModifiers.js +13 -13
  34. package/{dist/react → cjs/dist/react/core}/ProductVariantSelector.d.ts +2 -2
  35. package/{dist/react → cjs/dist/react/core}/ProductVariantSelector.js +7 -10
  36. package/{dist/react → cjs/dist/react/core}/SelectedVariant.d.ts +2 -2
  37. package/{dist/react → cjs/dist/react/core}/SelectedVariant.js +43 -15
  38. package/cjs/dist/react/index.d.ts +15 -10
  39. package/cjs/dist/react/index.js +15 -10
  40. package/cjs/dist/react/types.d.ts +8 -0
  41. package/cjs/dist/react/types.js +9 -0
  42. package/cjs/dist/server-actions/custom-checkout-action.js +14 -10
  43. package/cjs/dist/server-actions/index.d.ts +1 -1
  44. package/cjs/dist/server-actions/index.js +1 -1
  45. package/cjs/dist/services/buy-now-service.d.ts +1 -1
  46. package/cjs/dist/services/buy-now-service.js +6 -6
  47. package/cjs/dist/services/categories-list-service.d.ts +4 -4
  48. package/cjs/dist/services/categories-list-service.js +10 -10
  49. package/cjs/dist/services/category-service.d.ts +18 -22
  50. package/cjs/dist/services/category-service.js +12 -10
  51. package/cjs/dist/services/index.d.ts +7 -7
  52. package/cjs/dist/services/index.js +7 -7
  53. package/cjs/dist/services/pay-now-service.d.ts +1 -1
  54. package/cjs/dist/services/pay-now-service.js +4 -4
  55. package/cjs/dist/services/product-modifiers-service.d.ts +3 -3
  56. package/cjs/dist/services/product-modifiers-service.js +7 -7
  57. package/cjs/dist/services/product-service.d.ts +4 -4
  58. package/cjs/dist/services/product-service.js +18 -18
  59. package/cjs/dist/services/products-list-search-service.d.ts +5 -5
  60. package/cjs/dist/services/products-list-search-service.js +117 -117
  61. package/cjs/dist/services/products-list-service.d.ts +4 -4
  62. package/cjs/dist/services/products-list-service.js +12 -12
  63. package/cjs/dist/services/selected-variant-service.d.ts +6 -2
  64. package/cjs/dist/services/selected-variant-service.js +92 -87
  65. package/cjs/dist/utils/index.d.ts +1 -0
  66. package/cjs/dist/utils/index.js +5 -4
  67. package/cjs/dist/utils/renderAsChild.d.ts +96 -0
  68. package/cjs/dist/utils/renderAsChild.js +66 -0
  69. package/cjs/dist/utils/renderChildren.d.ts +41 -0
  70. package/cjs/dist/utils/renderChildren.js +44 -0
  71. package/cjs/dist/utils/url-params.js +3 -3
  72. package/dist/astro/actions/custom-checkout.d.ts +1 -1
  73. package/dist/astro/actions/custom-checkout.js +2 -2
  74. package/dist/astro/actions/index.d.ts +1 -1
  75. package/dist/astro/actions/index.js +1 -1
  76. package/dist/enums/index.d.ts +2 -2
  77. package/dist/enums/index.js +2 -2
  78. package/dist/react/Category.d.ts +168 -67
  79. package/dist/react/Category.js +166 -50
  80. package/dist/react/CategoryList.d.ts +56 -138
  81. package/dist/react/CategoryList.js +44 -129
  82. package/dist/react/Choice.d.ts +193 -0
  83. package/dist/react/Choice.js +259 -0
  84. package/dist/react/Option.d.ts +224 -0
  85. package/dist/react/Option.js +388 -0
  86. package/dist/react/Product.d.ts +339 -96
  87. package/dist/react/Product.js +507 -94
  88. package/dist/react/{BuyNow.js → core/BuyNow.js} +2 -2
  89. package/dist/react/core/Category.d.ts +98 -0
  90. package/dist/react/core/Category.js +81 -0
  91. package/dist/react/core/CategoryList.d.ts +185 -0
  92. package/dist/react/core/CategoryList.js +174 -0
  93. package/{cjs/dist/react → dist/react/core}/PayNow.js +2 -2
  94. package/dist/react/core/Product.d.ts +148 -0
  95. package/dist/react/core/Product.js +126 -0
  96. package/dist/react/{ProductList.d.ts → core/ProductList.d.ts} +3 -3
  97. package/dist/react/{ProductList.js → core/ProductList.js} +10 -10
  98. package/{cjs/dist/react → dist/react/core}/ProductListFilters.d.ts +3 -3
  99. package/{cjs/dist/react → dist/react/core}/ProductListFilters.js +7 -7
  100. package/dist/react/{ProductListPagination.js → core/ProductListPagination.js} +8 -8
  101. package/{cjs/dist/react → dist/react/core}/ProductListSort.d.ts +1 -1
  102. package/dist/react/{ProductListSort.js → core/ProductListSort.js} +3 -3
  103. package/{cjs/dist/react → dist/react/core}/ProductModifiers.d.ts +1 -1
  104. package/{cjs/dist/react → dist/react/core}/ProductModifiers.js +13 -13
  105. package/{cjs/dist/react → dist/react/core}/ProductVariantSelector.d.ts +2 -2
  106. package/{cjs/dist/react → dist/react/core}/ProductVariantSelector.js +7 -10
  107. package/{cjs/dist/react → dist/react/core}/SelectedVariant.d.ts +2 -2
  108. package/{cjs/dist/react → dist/react/core}/SelectedVariant.js +43 -15
  109. package/dist/react/index.d.ts +15 -10
  110. package/dist/react/index.js +15 -10
  111. package/dist/react/types.d.ts +8 -0
  112. package/dist/react/types.js +9 -0
  113. package/dist/server-actions/custom-checkout-action.js +14 -10
  114. package/dist/server-actions/index.d.ts +1 -1
  115. package/dist/server-actions/index.js +1 -1
  116. package/dist/services/buy-now-service.d.ts +1 -1
  117. package/dist/services/buy-now-service.js +6 -6
  118. package/dist/services/categories-list-service.d.ts +4 -4
  119. package/dist/services/categories-list-service.js +10 -10
  120. package/dist/services/category-service.d.ts +18 -22
  121. package/dist/services/category-service.js +12 -10
  122. package/dist/services/index.d.ts +7 -7
  123. package/dist/services/index.js +7 -7
  124. package/dist/services/pay-now-service.d.ts +1 -1
  125. package/dist/services/pay-now-service.js +4 -4
  126. package/dist/services/product-modifiers-service.d.ts +3 -3
  127. package/dist/services/product-modifiers-service.js +7 -7
  128. package/dist/services/product-service.d.ts +4 -4
  129. package/dist/services/product-service.js +18 -18
  130. package/dist/services/products-list-search-service.d.ts +5 -5
  131. package/dist/services/products-list-search-service.js +117 -117
  132. package/dist/services/products-list-service.d.ts +4 -4
  133. package/dist/services/products-list-service.js +12 -12
  134. package/dist/services/selected-variant-service.d.ts +6 -2
  135. package/dist/services/selected-variant-service.js +92 -87
  136. package/dist/utils/index.d.ts +1 -0
  137. package/dist/utils/index.js +5 -4
  138. package/dist/utils/renderAsChild.d.ts +96 -0
  139. package/dist/utils/renderAsChild.js +66 -0
  140. package/dist/utils/renderChildren.d.ts +41 -0
  141. package/dist/utils/renderChildren.js +44 -0
  142. package/dist/utils/url-params.js +3 -3
  143. package/package.json +7 -3
  144. /package/cjs/dist/react/{BuyNow.d.ts → core/BuyNow.d.ts} +0 -0
  145. /package/cjs/dist/react/{PayNow.d.ts → core/PayNow.d.ts} +0 -0
  146. /package/cjs/dist/react/{ProductListPagination.d.ts → core/ProductListPagination.d.ts} +0 -0
  147. /package/dist/react/{BuyNow.d.ts → core/BuyNow.d.ts} +0 -0
  148. /package/dist/react/{PayNow.d.ts → core/PayNow.d.ts} +0 -0
  149. /package/dist/react/{ProductListPagination.d.ts → core/ProductListPagination.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { type CustomLineItemCheckoutOptions } from "../../server-actions/index.js";
1
+ import { type CustomLineItemCheckoutOptions } from '../../server-actions/index.js';
2
2
  /**
3
3
  * Creates an Astro action factory for custom checkout functionality with line items.
4
4
  *
@@ -1,7 +1,7 @@
1
1
  /// <reference types="astro/env" />
2
2
  // @ts-ignore
3
- import { defineAction } from "astro:actions";
4
- import { getCustomLineItemCheckoutURLFactory, } from "../../server-actions/index.js";
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 "./custom-checkout.js";
1
+ export * from './custom-checkout.js';
@@ -1 +1 @@
1
- export * from "./custom-checkout.js";
1
+ export * from './custom-checkout.js';
@@ -1,2 +1,2 @@
1
- export * from "./sort-enums.js";
2
- export * from "./social-platform-enums.js";
1
+ export * from './sort-enums.js';
2
+ export * from './social-platform-enums.js';
@@ -1,2 +1,2 @@
1
- export * from "./sort-enums.js";
2
- export * from "./social-platform-enums.js";
1
+ export * from './sort-enums.js';
2
+ export * from './social-platform-enums.js';
@@ -1,98 +1,199 @@
1
- import { type CategoryServiceConfig } from "../services/category-service.js";
2
- export interface RootProps {
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
- * Root component that provides the Category service context to its children.
8
- * This component sets up the necessary services for managing category state.
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/components';
85
+ * import { Category } from '@wix/headless-stores/react';
15
86
  *
16
- * function CategoryPage() {
17
- * return (
18
- * <Category.Root categoryServiceConfig={{ category: myCategory }}>
19
- * <Category.Name>
20
- * {({ name }) => <h1>{name}</h1>}
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: RootProps): React.ReactNode;
94
+ export declare function Root(props: CategoryRootProps): React.ReactNode;
31
95
  /**
32
- * Props for Name headless component
33
- */
34
- export interface NameProps {
35
- /** Content to display (can be a render function receiving name data or ReactNode) */
36
- children: ((props: NameRenderProps) => React.ReactNode) | React.ReactNode;
37
- }
38
- /**
39
- * Render props for Name component
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 interface NameRenderProps {
42
- /** Category name */
43
- name: string;
44
- }
124
+ export declare const Trigger: React.ForwardRefExoticComponent<CategoryTriggerProps & React.RefAttributes<HTMLButtonElement>>;
45
125
  /**
46
- * Headless component for category name display
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
- * import { Category } from '@wix/stores/components';
132
+ * // Default usage
133
+ * <Category.Label className="text-lg font-medium text-content-primary" />
52
134
  *
53
- * function CategoryHeader() {
54
- * return (
55
- * <Category.Name>
56
- * {({ name }) => (
57
- * <h1 className="category-title">{name}</h1>
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
- * </Category.Name>
60
- * );
61
- * }
145
+ * </span>
146
+ * ))}
147
+ * </Category.Label>
62
148
  * ```
63
149
  */
64
- export declare function Name(props: NameProps): import("react").ReactNode;
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
- * Render props for Slug component
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 interface SlugRenderProps {
76
- /** Category slug */
77
- slug: string;
78
- }
176
+ export declare const ID: React.ForwardRefExoticComponent<CategoryIDProps & React.RefAttributes<HTMLElement>>;
79
177
  /**
80
- * Headless component for category slug display
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
- * import { Category } from '@wix/stores/components';
86
- *
87
- * function CategoryInfo() {
88
- * return (
89
- * <Category.Slug>
90
- * {({ slug }) => (
91
- * <p className="category-slug">Category slug: {slug}</p>
92
- * )}
93
- * </Category.Slug>
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 function Slug(props: SlugProps): import("react").ReactNode;
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 { createServicesMap } from "@wix/services-manager";
3
- import { useService, WixServices } from "@wix/services-manager-react";
4
- import { CategoryService, CategoryServiceDefinition, } from "../services/category-service.js";
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 component that provides the Category service context to its children.
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/components';
25
+ * import { Category } from '@wix/headless-stores/react';
14
26
  *
15
- * function CategoryPage() {
16
- * return (
17
- * <Category.Root categoryServiceConfig={{ category: myCategory }}>
18
- * <Category.Name>
19
- * {({ name }) => <h1>{name}</h1>}
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
- return (_jsx(WixServices, { servicesMap: createServicesMap().addService(CategoryServiceDefinition, CategoryService, props.categoryServiceConfig), children: props.children }));
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
- * Headless component for category name display
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
- * import { Category } from '@wix/stores/components';
52
+ * // Default usage
53
+ * <Category.Trigger className="px-4 py-2 rounded border hover:bg-surface-hover" />
39
54
  *
40
- * function CategoryHeader() {
41
- * return (
42
- * <Category.Name>
43
- * {({ name }) => (
44
- * <h1 className="category-title">{name}</h1>
45
- * )}
46
- * </Category.Name>
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 function Name(props) {
74
+ export const Trigger = React.forwardRef((props, ref) => {
75
+ const { asChild, children, onSelect, className } = props;
52
76
  const categoryService = useService(CategoryServiceDefinition);
53
- return typeof props.children === "function"
54
- ? props.children({ name: categoryService.category.get().name })
55
- : props.children;
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
- * Headless component for category slug display
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
- * import { Category } from '@wix/stores/components';
100
+ * // Default usage
101
+ * <Category.Label className="text-lg font-medium text-content-primary" />
64
102
  *
65
- * function CategoryInfo() {
66
- * return (
67
- * <Category.Slug>
68
- * {({ slug }) => (
69
- * <p className="category-slug">Category slug: {slug}</p>
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
- * </Category.Slug>
72
- * );
73
- * }
113
+ * </span>
114
+ * ))}
115
+ * </Category.Label>
74
116
  * ```
75
117
  */
76
- export function Slug(props) {
118
+ export const Label = React.forwardRef((props, ref) => {
119
+ const { asChild, children, className } = props;
77
120
  const categoryService = useService(CategoryServiceDefinition);
78
- return typeof props.children === "function"
79
- ? props.children({ slug: categoryService.category.get().slug })
80
- : props.children;
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
+ });