An open source design system that's fully customizable and agent ready
TypeScript
docs(usePowerSearchConfig): add hook docs and a filtered directory table example block (#10660)
Utkarsh patwad84658f7d6ad
diff --git a/.changeset/hook-doc-use-power-search-config.md b/.changeset/hook-doc-use-power-search-config.mdnew file mode 100644index 0000000000..25e7e7366a--- /dev/null+++ b/.changeset/hook-doc-use-power-search-config.md@@ -0,0 +1,8 @@+---+'@astryxdesign/core': patch+'@astryxdesign/cli': patch+---++[docs] Add usePowerSearchConfig hook docs and a filtered directory table example block++@utkarshpatwa393-sysdiff --git a/apps/sandbox/scripts/next-export-routes.json b/apps/sandbox/scripts/next-export-routes.jsonindex d89a915d33..29c19116db 100644--- a/apps/sandbox/scripts/next-export-routes.json+++ b/apps/sandbox/scripts/next-export-routes.json@@ -826,6 +826,7 @@"/templates/useOutlineFromMarkdownHookUsage/","/templates/useOverflowHookUsage/","/templates/useOverlayHookUsage/",+ "/templates/usePowerSearchConfigHookUsage/","/templates/usePressFeedbackHookUsage/","/templates/useScrollLockHookUsage/","/templates/useScrollOverflowHookUsage/",diff --git a/internal/shadcn-registry/routes.lock.json b/internal/shadcn-registry/routes.lock.jsonindex fe8df1773c..bb8b0ad950 100644--- a/internal/shadcn-registry/routes.lock.json+++ b/internal/shadcn-registry/routes.lock.json@@ -3891,6 +3891,11 @@"path": "examples/use-popover/quick-actions","aliases": []},+ {+ "name": "example-use-power-search-config-filtered-directory-table",+ "path": "examples/use-power-search-config/filtered-directory-table",+ "aliases": []+ },{"name": "example-use-press-feedback-pressable-card","path": "examples/use-press-feedback/pressable-card",@@ -4276,6 +4281,11 @@"path": "hooks/use-popover","aliases": []},+ {+ "name": "hook-use-power-search-config",+ "path": "hooks/use-power-search-config",+ "aliases": []+ },{"name": "hook-use-press-feedback","path": "hooks/use-press-feedback",diff --git a/packages/cli/api/component/__fixtures__/resolutions/modules.txt b/packages/cli/api/component/__fixtures__/resolutions/modules.txtindex ac56858871..fb06600b5a 100644--- a/packages/cli/api/component/__fixtures__/resolutions/modules.txt+++ b/packages/cli/api/component/__fixtures__/resolutions/modules.txt@@ -282,7 +282,7 @@ useOverlay useOverlay Overlay/useOverlay.doc.mjs Overlay/useOverlay.tsxuseOwnScrollGesture useOwnScrollGesture DateInput/DateInput.doc.mjs DateInput/useOwnScrollGesture.tsusePager usePager hooks/useAnimatedLayout.doc.mjs hooks/usePager.tsusePointerDragScroll usePointerDragScroll DateInput/DateInput.doc.mjs DateInput/usePointerDragScroll.ts-usePowerSearchConfig usePowerSearchConfig PowerSearch/PowerSearch.doc.mjs PowerSearch/usePowerSearchConfig.ts+usePowerSearchConfig usePowerSearchConfig PowerSearch/usePowerSearchConfig.doc.mjs PowerSearch/usePowerSearchConfig.tsusePowerSearchSource usePowerSearchSource PowerSearch/PowerSearch.doc.mjs PowerSearch/usePowerSearchSource.tsuseRenamedProp useRenamedProp hooks/useAnimatedLayout.doc.mjs hooks/useRenamedProp.tsuseResolvedRequired useResolvedRequired hooks/useAnimatedLayout.doc.mjs hooks/useResolvedRequired.tsdiff --git a/packages/cli/api/template/use-power-search-config-hook-usage.test.tsx b/packages/cli/api/template/use-power-search-config-hook-usage.test.tsxnew file mode 100644index 0000000000..ba9d6f45d2--- /dev/null+++ b/packages/cli/api/template/use-power-search-config-hook-usage.test.tsx@@ -0,0 +1,81 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @vitest-environment jsdom++/**+ * The usePowerSearchConfig example demonstrates PowerSearch paired with Table+ * to search and filter people directory rows.+ */++import {act} from 'react';+import {createRoot, type Root} from 'react-dom/client';+import {afterEach, beforeEach, describe, expect, it} from 'vitest';+import UsePowerSearchConfigHookUsage from '../../assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage';++(globalThis as {IS_REACT_ACT_ENVIRONMENT?: boolean}).IS_REACT_ACT_ENVIRONMENT =+ true;++let root: Root | null = null;+let container: HTMLElement;++function rowNames(): string[] {+ return Array.from(container.querySelectorAll('tbody tr')).map(+ row => row.querySelector('td')?.textContent?.trim() ?? '',+ );+}++beforeEach(() => {+ container = document.createElement('div');+ document.body.appendChild(container);+ act(() => {+ root = createRoot(container);+ root.render(<UsePowerSearchConfigHookUsage />);+ });+});++afterEach(() => {+ act(() => root?.unmount());+ root = null;+ container.remove();+});++describe('usePowerSearchConfig example', () => {+ it('renders all directory people rows initially', () => {+ expect(rowNames()).toEqual([+ 'Alice Chen',+ 'Bob Dylan',+ 'Charlie Kim',+ 'Dana Scully',+ 'Evan Wright',+ ]);+ });++ it('renders PowerSearch input with placeholder', () => {+ const input = container.querySelector('input');+ expect(input).not.toBeNull();+ expect(input?.placeholder).toBe(+ 'Filter directory by name, status, start date...',+ );+ });++ it('formats start date in UTC so midnight timestamps do not shift in western timezones', () => {+ act(() => root?.unmount());+ const originalTZ = process.env.TZ;+ process.env.TZ = 'America/Los_Angeles';+ try {+ act(() => {+ root = createRoot(container);+ root.render(<UsePowerSearchConfigHookUsage />);+ });+ const evanRow = Array.from(container.querySelectorAll('tbody tr')).find(+ row => row.textContent?.includes('Evan Wright'),+ );+ expect(evanRow?.textContent).toContain('Jan 1, 2024');+ } finally {+ if (originalTZ === undefined) {+ delete process.env.TZ;+ } else {+ process.env.TZ = originalTZ;+ }+ }+ });+});diff --git a/packages/cli/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjs b/packages/cli/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjsnew file mode 100644index 0000000000..d44e455ef1--- /dev/null+++ b/packages/cli/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjs@@ -0,0 +1,14 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */+export const doc = {+ type: 'block',+ exampleFor: 'usePowerSearchConfig',+ name: 'usePowerSearchConfig — Filtered Directory Table',+ displayName: 'usePowerSearchConfig — Filtered Directory Table',+ description:+ 'A people directory with a PowerSearch bar over a Table: typed field definitions feed usePowerSearchConfig, returning the search config and an applyFilters helper that updates Table rows.',+ isReady: true,+ aspectRatio: 4 / 3,+ componentsUsed: ['PowerSearch', 'Table', 'Layout'],+};diff --git a/packages/cli/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsx b/packages/cli/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsxnew file mode 100644index 0000000000..5ebb27eb52--- /dev/null+++ b/packages/cli/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsx@@ -0,0 +1,83 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++'use client';++import {useState} from 'react';+import {VStack} from '@astryxdesign/core/Layout';+import {+ PowerSearch,+ usePowerSearchConfig,+} from '@astryxdesign/core/PowerSearch';+import type {PowerSearchFilter} from '@astryxdesign/core/PowerSearch';+import {Table} from '@astryxdesign/core/Table';+import type {TableColumn} from '@astryxdesign/core/Table';++const statusValues = [+ {value: 'active', label: 'Active'},+ {value: 'on-leave', label: 'On Leave'},+ {value: 'contractor', label: 'Contractor'},+];++const fieldDefs = [+ {key: 'name', type: 'string', label: 'Name'},+ {key: 'status', type: 'enum', label: 'Status', enumValues: statusValues},+ {key: 'startDate', type: 'date', label: 'Start date'},+] as const;++interface Person extends Record<string, unknown> {+ id: string;+ name: string;+ status: string;+ startDate: number;+}++const people: Person[] = [+ {id: '1', name: 'Alice Chen', status: 'active', startDate: 1672531200},+ {id: '2', name: 'Bob Dylan', status: 'on-leave', startDate: 1680307200},+ {id: '3', name: 'Charlie Kim', status: 'active', startDate: 1688169600},+ {id: '4', name: 'Dana Scully', status: 'contractor', startDate: 1696118400},+ {id: '5', name: 'Evan Wright', status: 'active', startDate: 1704067200},+];++const columns: TableColumn<Person>[] = [+ {key: 'name', header: 'Name'},+ {+ key: 'status',+ header: 'Status',+ renderCell: (person: Person) =>+ statusValues.find(s => s.value === person.status)?.label ?? person.status,+ },+ {+ key: 'startDate',+ header: 'Start Date',+ renderCell: (person: Person) =>+ new Date(person.startDate * 1000).toLocaleDateString('en-US', {+ timeZone: 'UTC',+ year: 'numeric',+ month: 'short',+ day: 'numeric',+ }),+ },+];++export default function UsePowerSearchConfigHookUsage() {+ const [filters, setFilters] = useState<PowerSearchFilter[]>([]);+ const {config, applyFilters} = usePowerSearchConfig(+ fieldDefs,+ 'PeopleDirectory',+ );+ const filteredPeople = applyFilters(filters, people);++ return (+ <VStack gap={4}>+ <PowerSearch+ config={config}+ filters={filters}+ onChange={newFilters => setFilters([...newFilters])}+ placeholder="Filter directory by name, status, start date..."+ resultCount={filteredPeople.length}+ />+ <Table data={filteredPeople} columns={columns} idKey="id" hasHover />+ </VStack>+ );+}diff --git a/packages/cli/test/__golden__/no-icon-set/search-search.json b/packages/cli/test/__golden__/no-icon-set/search-search.jsonindex f5663523c8..c17fdabd31 100644--- a/packages/cli/test/__golden__/no-icon-set/search-search.json+++ b/packages/cli/test/__golden__/no-icon-set/search-search.json@@ -3,7 +3,7 @@"type": "search","data": {"query": "search",- "matchCount": 115,+ "matchCount": 117,"results": [{"domain": "doc",@@ -73,6 +73,17 @@"command": "astryx component TextInput","mentions": []},+ {+ "domain": "hook",+ "name": "usePowerSearchConfig",+ "package": "@astryxdesign/core",+ "score": "<text>",+ "reason": "<text>",+ "description": "<text>",+ "import": "@astryxdesign/core/PowerSearch",+ "command": "astryx hook usePowerSearchConfig",+ "mentions": []+ },{"domain": "hook","name": "useTypeahead",@@ -179,6 +190,18 @@"command": "astryx template TableInlineFilterTable --type block","mentions": []},+ {+ "domain": "template",+ "name": "usePowerSearchConfigHookUsage",+ "package": "@astryxdesign/core",+ "score": "<text>",+ "reason": "<text>",+ "description": "<text>",+ "displayName": "<text>",+ "kind": "block",+ "command": "astryx template usePowerSearchConfigHookUsage --type block",+ "mentions": []+ },{"domain": "doc","name": "authoring/building-blocks/templates/document-the-template/template-doc-overview",@@ -218,31 +241,6 @@"command": "astryx docs cli/api/enums/response-types","parent": "astryx docs cli/api/enums","mentions": []- },- {- "domain": "doc",- "name": "cli/api/functions/discover",- "package": "@astryxdesign/cli",- "score": "<text>",- "reason": "<text>",- "description": "<text>",- "title": "<text>",- "command": "astryx docs cli/api/functions/discover",- "parent": "astryx docs cli/api/functions",- "mentions": []- },- {- "domain": "doc",- "name": "global/problems",- "package": "@astryxdesign/cli",- "score": "<text>",- "reason": "<text>",- "description": "<text>",- "section": "<text>",- "title": "<text>",- "command": "astryx docs global/problems core-offline",- "parent": "astryx docs global/problems --index",- "mentions": []}]},diff --git a/packages/cli/test/__golden__/no-icon-set/search-search.txt b/packages/cli/test/__golden__/no-icon-set/search-search.txtindex bde7338d7d..3cd613b96f 100644--- a/packages/cli/test/__golden__/no-icon-set/search-search.txt+++ b/packages/cli/test/__golden__/no-icon-set/search-search.txt@@ -1,4 +1,4 @@-Results for "search" (20 of 115)+Results for "search" (20 of 117)name: cli/api/functions/searchdomain: docpackage: @astryxdesign/cli@@ -29,6 +29,11 @@ domain: componentpackage: @astryxdesign/coreimport: @astryxdesign/core/TextInputcommand: pnpm exec astryx component TextInput+name: usePowerSearchConfig+domain: hook+package: @astryxdesign/core+import: @astryxdesign/core/PowerSearch+command: pnpm exec astryx hook usePowerSearchConfigname: useTypeaheaddomain: hookpackage: @astryxdesign/core@@ -67,6 +72,10 @@ name: TableInlineFilterTabledomain: templatepackage: @astryxdesign/corecommand: pnpm exec astryx template TableInlineFilterTable --type block+name: usePowerSearchConfigHookUsage+domain: template+package: @astryxdesign/core+command: pnpm exec astryx template usePowerSearchConfigHookUsage --type blockname: authoring/building-blocks/templates/document-the-template/template-doc-overviewsection: document-the-shared-fieldsdomain: doc@@ -83,15 +92,4 @@ name: cli/api/enums/response-typesdomain: docpackage: @astryxdesign/clicommand: pnpm exec astryx docs cli/api/enums/response-types-parent: pnpm exec astryx docs cli/api/enums-name: cli/api/functions/discover-domain: doc-package: @astryxdesign/cli-command: pnpm exec astryx docs cli/api/functions/discover-parent: pnpm exec astryx docs cli/api/functions-name: global/problems-section: core-offline-domain: doc-package: @astryxdesign/cli-command: pnpm exec astryx docs global/problems core-offline-parent: pnpm exec astryx docs global/problems --index\ No newline at end of file+parent: pnpm exec astryx docs cli/api/enums\ No newline at end of filediff --git a/packages/core/src/PowerSearch/usePowerSearchConfig.doc.mjs b/packages/core/src/PowerSearch/usePowerSearchConfig.doc.mjsnew file mode 100644index 0000000000..4a5e4ca9dc--- /dev/null+++ b/packages/core/src/PowerSearch/usePowerSearchConfig.doc.mjs@@ -0,0 +1,106 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/** @type {import('@astryxdesign/cli/authoring').HookDoc} */+export const docs = {+ name: 'usePowerSearchConfig',+ displayName: 'usePowerSearchConfig',+ group: 'PowerSearch',+ keywords: [+ 'powersearch',+ 'search',+ 'filter',+ 'filters',+ 'query builder',+ 'table filter',+ 'usePowerSearchConfig',+ 'createPowerSearchConfig',+ ],+ params: [+ {+ name: 'definitions',+ type: 'ReadonlyArray<FieldDefinition>',+ description:+ 'Typed field definitions (key, type, label, enumValues) used to build PowerSearch fields and operators.',+ required: true,+ },+ {+ name: 'configName',+ type: 'string',+ description:+ 'Optional name for the PowerSearchConfig object (defaults to "PowerSearchConfig").',+ required: false,+ },+ ],+ returns: [+ {+ name: 'config',+ type: 'PowerSearchConfig',+ description:+ 'Memoized PowerSearch configuration object with fields and type-appropriate operators.',+ },+ {+ name: 'applyFilters',+ type: '<T extends InferData<D>>(filters: ReadonlyArray<PowerSearchFilter>, data: ReadonlyArray<T>) => T[]',+ description:+ 'Client-side filtering helper that filters a dataset using the active PowerSearch filter rules.',+ },+ ],+ usage: {+ description:+ 'Memoizes a PowerSearch configuration built from typed field definitions and returns it along with an applyFilters function for client-side filtering. Automatically maps field types (string, number, boolean, date, enum, etc.) to their canonical operators and provides an efficient predicate evaluator to filter datasets.',+ bestPractices: [+ {+ guidance: true,+ description:+ 'Declare field definitions as const outside the component or memoize them so usePowerSearchConfig only recalculates when needed.',+ },+ {+ guidance: true,+ description:+ 'Pass the returned config to PowerSearch and use applyFilters to compute the filtered data rows for a Table or List.',+ },+ {+ guidance: false,+ description:+ 'Recreate field definitions inline on every render without as const or memoization.',+ },+ ],+ },+ relatedComponents: ['PowerSearch', 'Table'],+ relatedHooks: ['useTableFilterState', 'useTableFiltering'],+ importPath: '@astryxdesign/core/PowerSearch',+ category: 'utilities',+};++/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */+export const docsDense = {+ description:+ 'Memoizes PowerSearch config from typed field definitions + returns applyFilters for client filtering. Automatically maps types (string, number, date, enum) to canonical operators.',+ paramDescriptions: {+ definitions: 'Typed field definitions (key, type, label, enumValues).',+ configName: 'Optional config name (defaults to "PowerSearchConfig").',+ },+ returnDescriptions: {+ config: 'Memoized PowerSearchConfig for PowerSearch.',+ applyFilters: 'Filters dataset against active PowerSearch filters.',+ },+ usage: {+ description:+ 'Builds memoized PowerSearch config and client filtering function from field definitions.',+ bestPractices: [+ {+ guidance: true,+ description: 'Declare definitions with as const outside component.',+ },+ {+ guidance: true,+ description:+ 'Pass config to PowerSearch and use applyFilters for Table/List data.',+ },+ {+ guidance: false,+ description: 'Recreate field definitions inline on every render.',+ },+ ],+ },+};