|
| 1 | +import { create, insertMultiple } from '@orama/orama'; |
| 2 | + |
| 3 | +import Search from '#ui/Common/Search'; |
| 4 | +import SearchHit from '#ui/Common/Search/Results/Hit'; |
| 5 | + |
| 6 | +import type { OramaCloud } from '@orama/core'; |
| 7 | +import type { Meta as MetaObj, StoryObj } from '@storybook/react-webpack5'; |
| 8 | + |
| 9 | +type Story = StoryObj<typeof Search>; |
| 10 | +type Meta = MetaObj<typeof Search>; |
| 11 | + |
| 12 | +const searchClient = (() => { |
| 13 | + const db = create({ |
| 14 | + schema: { |
| 15 | + title: 'string', |
| 16 | + description: 'string', |
| 17 | + href: 'string', |
| 18 | + siteSection: 'string', |
| 19 | + pageTitle: 'string', |
| 20 | + pageSectionTitle: 'string', |
| 21 | + pageSectionContent: 'string', |
| 22 | + }, |
| 23 | + }); |
| 24 | + |
| 25 | + void insertMultiple(db, [ |
| 26 | + { |
| 27 | + title: 'Getting Started', |
| 28 | + description: 'Learn how to install Node.js and run your first script.', |
| 29 | + href: '/en/learn/getting-started/introduction-to-nodejs', |
| 30 | + siteSection: 'Learn', |
| 31 | + pageTitle: 'Getting Started', |
| 32 | + pageSectionTitle: 'Introduction to Node.js', |
| 33 | + pageSectionContent: 'A quick overview of Node.js fundamentals.', |
| 34 | + }, |
| 35 | + { |
| 36 | + title: 'Node.js Download', |
| 37 | + description: 'Download binaries for Linux, macOS and Windows.', |
| 38 | + href: '/en/download', |
| 39 | + siteSection: 'Download', |
| 40 | + pageTitle: 'Download', |
| 41 | + pageSectionTitle: 'Choose your platform', |
| 42 | + pageSectionContent: 'Download options for supported platforms.', |
| 43 | + }, |
| 44 | + { |
| 45 | + title: 'About Node.js', |
| 46 | + description: 'History, governance and project overview.', |
| 47 | + href: '/en/about', |
| 48 | + siteSection: 'About', |
| 49 | + pageTitle: 'About', |
| 50 | + pageSectionTitle: 'Project overview', |
| 51 | + pageSectionContent: 'Community-driven runtime for JavaScript.', |
| 52 | + }, |
| 53 | + ]); |
| 54 | + |
| 55 | + return db as unknown as OramaCloud; |
| 56 | +})(); |
| 57 | + |
| 58 | +export const Default: Story = { |
| 59 | + args: { |
| 60 | + client: searchClient, |
| 61 | + placeholder: 'Search the docs...', |
| 62 | + }, |
| 63 | + decorators: [ |
| 64 | + Story => ( |
| 65 | + <div className="mx-auto w-full max-w-[48rem] p-6"> |
| 66 | + <Story /> |
| 67 | + </div> |
| 68 | + ), |
| 69 | + ], |
| 70 | +}; |
| 71 | + |
| 72 | +export const CustomLabels: Story = { |
| 73 | + args: { |
| 74 | + client: searchClient, |
| 75 | + placeholder: 'Search Node.js pages...', |
| 76 | + noResultsTitle: 'Nothing found for', |
| 77 | + closeShortcutLabel: 'close search', |
| 78 | + navigateShortcutLabel: 'move between results', |
| 79 | + selectShortcutLabel: 'open selected page', |
| 80 | + }, |
| 81 | + decorators: Default.decorators, |
| 82 | +}; |
| 83 | + |
| 84 | +export const DescriptionWithCode: Story = { |
| 85 | + render: () => ( |
| 86 | + <div className="mx-auto w-full max-w-[48rem] p-6"> |
| 87 | + <SearchHit |
| 88 | + document={{ |
| 89 | + title: 'Run with watch mode', |
| 90 | + href: '/en/learn/command-line/run-nodejs-scripts-from-the-command-line', |
| 91 | + description: ( |
| 92 | + <> |
| 93 | + Use <code>node --watch app.mjs</code> to restart your app |
| 94 | + automatically on file changes. |
| 95 | + </> |
| 96 | + ), |
| 97 | + }} |
| 98 | + /> |
| 99 | + </div> |
| 100 | + ), |
| 101 | +}; |
| 102 | + |
| 103 | +export default { component: Search } as Meta; |
0 commit comments