@usequeek/theme-kit 0.5.1 → 0.5.2

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/README.md CHANGED
@@ -138,6 +138,7 @@ they keep the data already on screen. They return `isLoading`, except
138
138
  | `useHref()` | `hooks/use-href` | Builds a store-relative link |
139
139
  | `useLocales()` | `hooks/use-locales` | The store's languages and the active one |
140
140
  | `useStorefront()` / `useStorefrontLocale()` / `useThemeStrings()` | `provider` | The store, the request locale, the bound `t` |
141
+ | `useProductCount()` | `provider` | `(count) => number \| null`: the product count to print, `null` unless the store turned counts on (`config.display.show_product_counts`, off by default). Print every product count through it and render nothing for `null` |
141
142
 
142
143
  ### Cart pricing
143
144
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The runtime a Queek storefront theme is built on: hooks, stores, page renderer, navigation, shared blocks and locale strings.",
package/provider.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import type { JSX } from 'react';
4
- import { createContext, useContext, useEffect, useMemo, useRef, type ReactNode } from 'react';
4
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, type ReactNode } from 'react';
5
5
  import type { Menu } from './types/menu';
6
6
  import type { ReviewItem } from './types/block';
7
7
  import type { Post } from './types/page';
@@ -227,6 +227,26 @@ export function useIsThemePreview(): boolean {
227
227
  return useStorefront().previewData !== undefined;
228
228
  }
229
229
 
230
+ /**
231
+ * The product count a theme may print, or `null` to print nothing. Counts ("6 products" under a
232
+ * collection title, a number on a category tile, a facet tally) stay hidden unless the store turns
233
+ * them on (`config.display.show_product_counts`, default off). Every theme prints a product count
234
+ * only through this, and renders no element at all for `null`, so no empty span or gap is left.
235
+ *
236
+ * @example
237
+ * const productCount = useProductCount();
238
+ * const shown = productCount(collection.products_count);
239
+ * return shown !== null ? <p>{t('shop.count', { count: shown })}</p> : null;
240
+ */
241
+ export function useProductCount(): (count: number | null | undefined) => number | null {
242
+ const shows = useStorefront().config.display?.show_product_counts === true;
243
+
244
+ return useCallback(
245
+ (count: number | null | undefined): number | null => (shows && typeof count === 'number' && Number.isFinite(count) ? count : null),
246
+ [shows],
247
+ );
248
+ }
249
+
230
250
  /**
231
251
  * Validated request locale for translated reads (`null` = primary).
232
252
  * Browser hooks send `?locale=` when this is set and key their client
package/types/vendor.ts CHANGED
@@ -187,6 +187,14 @@ export interface StorefrontConfig {
187
187
  heading?: string;
188
188
  body?: string;
189
189
  };
190
+ /**
191
+ * Store-wide display choices every theme honours. `show_product_counts` (default false): a theme
192
+ * prints a product count ("6 products") only when the store turns it on; read it through
193
+ * `useProductCount()`, never from here.
194
+ */
195
+ display?: {
196
+ show_product_counts?: boolean;
197
+ };
190
198
  /** Resolved semantic design tokens. Absent for stores that have none. */
191
199
  tokens?: DesignTokens | null;
192
200
  menus?: {