@patternfly/react-docs 7.6.0-prerelease.7 → 7.6.0-prerelease.8
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/package.json +12 -13
- package/patternfly-docs/generated/components/about-modal/react.js +149 -0
- package/patternfly-docs/generated/components/accordion/react.js +262 -0
- package/patternfly-docs/generated/components/action-list/react.js +144 -0
- package/patternfly-docs/generated/components/alert/react-demos.js +56 -0
- package/patternfly-docs/generated/components/alert/react.js +1433 -0
- package/patternfly-docs/generated/components/avatar/react.js +166 -0
- package/patternfly-docs/generated/components/back-to-top/react-demos.js +60 -0
- package/patternfly-docs/generated/components/back-to-top/react.js +77 -0
- package/patternfly-docs/generated/components/backdrop/react.js +64 -0
- package/patternfly-docs/generated/components/background-image/react.js +62 -0
- package/patternfly-docs/generated/components/badge/react.js +97 -0
- package/patternfly-docs/generated/components/banner/react-demos.js +57 -0
- package/patternfly-docs/generated/components/banner/react.js +148 -0
- package/patternfly-docs/generated/components/brand/react.js +142 -0
- package/patternfly-docs/generated/components/breadcrumb/react.js +206 -0
- package/patternfly-docs/generated/components/button/react-demos.js +57 -0
- package/patternfly-docs/generated/components/button/react.js +826 -0
- package/patternfly-docs/generated/components/card/react-demos.js +201 -0
- package/patternfly-docs/generated/components/card/react.js +1015 -0
- package/patternfly-docs/generated/components/charts/area-chart/-Victory.js +1350 -0
- package/patternfly-docs/generated/components/charts/bar-chart/-Victory.js +1334 -0
- package/patternfly-docs/generated/components/charts/box-plot-chart/-Victory.js +1282 -0
- package/patternfly-docs/generated/components/charts/bullet-chart/-Victory.js +848 -0
- package/patternfly-docs/generated/components/charts/colors-for-charts/-Victory.js +192 -0
- package/patternfly-docs/generated/components/charts/donut-chart/-Victory.js +426 -0
- package/patternfly-docs/generated/components/charts/donut-utilization-chart/-Victory.js +804 -0
- package/patternfly-docs/generated/components/charts/legends/-Victory.js +3230 -0
- package/patternfly-docs/generated/components/charts/line-chart/-Victory.js +1178 -0
- package/patternfly-docs/generated/components/charts/line-chart/ECharts.js +525 -0
- package/patternfly-docs/generated/components/charts/patterns/-Victory.js +3382 -0
- package/patternfly-docs/generated/components/charts/pie-chart/-Victory.js +377 -0
- package/patternfly-docs/generated/components/charts/resize-observer/-Victory.js +2475 -0
- package/patternfly-docs/generated/components/charts/sankey-chart/ECharts.js +538 -0
- package/patternfly-docs/generated/components/charts/scatter-chart/-Victory.js +1551 -0
- package/patternfly-docs/generated/components/charts/skeletons/-Victory.js +4115 -0
- package/patternfly-docs/generated/components/charts/sparkline-chart/-Victory.js +955 -0
- package/patternfly-docs/generated/components/charts/stack-chart/-Victory.js +1173 -0
- package/patternfly-docs/generated/components/charts/threshold-chart/-Victory.js +1166 -0
- package/patternfly-docs/generated/components/charts/tooltips/-Victory.js +413 -0
- package/patternfly-docs/generated/components/chip/react-deprecated.js +323 -0
- package/patternfly-docs/generated/components/clipboard-copy/react.js +373 -0
- package/patternfly-docs/generated/components/code-block/react.js +148 -0
- package/patternfly-docs/generated/components/code-editor/react.js +659 -0
- package/patternfly-docs/generated/components/compass/react-demos.js +147 -0
- package/patternfly-docs/generated/components/compass/react.js +440 -0
- package/patternfly-docs/generated/components/content/react.js +248 -0
- package/patternfly-docs/generated/components/data-list/react-demos.js +90 -0
- package/patternfly-docs/generated/components/data-list/react.js +709 -0
- package/patternfly-docs/generated/components/date-and-time/calendar-month/react.js +283 -0
- package/patternfly-docs/generated/components/date-and-time/date-and-time-picker/react-demos.js +64 -0
- package/patternfly-docs/generated/components/date-and-time/date-picker/react-demos.js +83 -0
- package/patternfly-docs/generated/components/date-and-time/date-picker/react.js +395 -0
- package/patternfly-docs/generated/components/date-and-time/time-picker/react.js +241 -0
- package/patternfly-docs/generated/components/description-list/react-demos.js +58 -0
- package/patternfly-docs/generated/components/description-list/react.js +743 -0
- package/patternfly-docs/generated/components/divider/react.js +126 -0
- package/patternfly-docs/generated/components/drag-and-drop/react-demos.js +351 -0
- package/patternfly-docs/generated/components/drag-and-drop/react-deprecated.js +184 -0
- package/patternfly-docs/generated/components/drag-and-drop/react.js +137 -0
- package/patternfly-docs/generated/components/drawer/react.js +598 -0
- package/patternfly-docs/generated/components/dual-list-selector/react-deprecated.js +772 -0
- package/patternfly-docs/generated/components/dual-list-selector/react.js +594 -0
- package/patternfly-docs/generated/components/empty-state/react.js +199 -0
- package/patternfly-docs/generated/components/expandable-section/react-demos.js +65 -0
- package/patternfly-docs/generated/components/expandable-section/react.js +408 -0
- package/patternfly-docs/generated/components/file-upload/multiple-file-upload/react-demos.js +52 -0
- package/patternfly-docs/generated/components/file-upload/multiple-file-upload/react.js +398 -0
- package/patternfly-docs/generated/components/file-upload/simple-file-upload/react.js +749 -0
- package/patternfly-docs/generated/components/forms/checkbox/react.js +222 -0
- package/patternfly-docs/generated/components/forms/form/react.js +1106 -0
- package/patternfly-docs/generated/components/forms/form-select/react.js +208 -0
- package/patternfly-docs/generated/components/forms/radio/react.js +212 -0
- package/patternfly-docs/generated/components/forms/text-area/react.js +160 -0
- package/patternfly-docs/generated/components/forms/text-input/react.js +216 -0
- package/patternfly-docs/generated/components/helper-text/react-demos.js +180 -0
- package/patternfly-docs/generated/components/helper-text/react.js +164 -0
- package/patternfly-docs/generated/components/hero/react.js +88 -0
- package/patternfly-docs/generated/components/hint/react.js +169 -0
- package/patternfly-docs/generated/components/icon/react.js +215 -0
- package/patternfly-docs/generated/components/input-group/react.js +182 -0
- package/patternfly-docs/generated/components/jump-links/react-demos.js +154 -0
- package/patternfly-docs/generated/components/jump-links/react.js +212 -0
- package/patternfly-docs/generated/components/label/react-demos.js +57 -0
- package/patternfly-docs/generated/components/label/react.js +417 -0
- package/patternfly-docs/generated/components/list/react.js +175 -0
- package/patternfly-docs/generated/components/login-page/react.js +587 -0
- package/patternfly-docs/generated/components/masthead/react-demos.js +79 -0
- package/patternfly-docs/generated/components/masthead/react.js +291 -0
- package/patternfly-docs/generated/components/menus/application-launcher/react-demos.js +769 -0
- package/patternfly-docs/generated/components/menus/context-selector/react-demos.js +665 -0
- package/patternfly-docs/generated/components/menus/custom-menus/react-demos.js +187 -0
- package/patternfly-docs/generated/components/menus/dropdown/react-templates.js +163 -0
- package/patternfly-docs/generated/components/menus/dropdown/react.js +998 -0
- package/patternfly-docs/generated/components/menus/menu/react.js +1540 -0
- package/patternfly-docs/generated/components/menus/menu-toggle/react.js +747 -0
- package/patternfly-docs/generated/components/menus/options-menu/react-demos.js +508 -0
- package/patternfly-docs/generated/components/menus/select/react-templates.js +257 -0
- package/patternfly-docs/generated/components/menus/select/react.js +998 -0
- package/patternfly-docs/generated/components/modal/react-deprecated.js +554 -0
- package/patternfly-docs/generated/components/modal/react.js +597 -0
- package/patternfly-docs/generated/components/navigation/react-demos.js +356 -0
- package/patternfly-docs/generated/components/navigation/react.js +409 -0
- package/patternfly-docs/generated/components/notification-badge/react.js +196 -0
- package/patternfly-docs/generated/components/notification-drawer/react-demos.js +107 -0
- package/patternfly-docs/generated/components/notification-drawer/react.js +394 -0
- package/patternfly-docs/generated/components/number-input/react.js +210 -0
- package/patternfly-docs/generated/components/overflow-menu/react.js +274 -0
- package/patternfly-docs/generated/components/page/react-demos.js +149 -0
- package/patternfly-docs/generated/components/page/react.js +1352 -0
- package/patternfly-docs/generated/components/pagination/react.js +492 -0
- package/patternfly-docs/generated/components/panel/react.js +236 -0
- package/patternfly-docs/generated/components/popover/react.js +390 -0
- package/patternfly-docs/generated/components/progress/react-demos.js +59 -0
- package/patternfly-docs/generated/components/progress/react.js +283 -0
- package/patternfly-docs/generated/components/progress-stepper/react-demos.js +45 -0
- package/patternfly-docs/generated/components/progress-stepper/react.js +219 -0
- package/patternfly-docs/generated/components/search-input/react-demos.js +113 -0
- package/patternfly-docs/generated/components/search-input/react.js +263 -0
- package/patternfly-docs/generated/components/sidebar/react.js +236 -0
- package/patternfly-docs/generated/components/simple-list/react.js +200 -0
- package/patternfly-docs/generated/components/skeleton/react-demos.js +44 -0
- package/patternfly-docs/generated/components/skeleton/react.js +122 -0
- package/patternfly-docs/generated/components/skip-to-content/react.js +73 -0
- package/patternfly-docs/generated/components/slider/react.js +309 -0
- package/patternfly-docs/generated/components/spinner/react.js +111 -0
- package/patternfly-docs/generated/components/switch/react.js +163 -0
- package/patternfly-docs/generated/components/table/react-demos.js +355 -0
- package/patternfly-docs/generated/components/table/react-deprecated.js +1350 -0
- package/patternfly-docs/generated/components/table/react.js +3241 -0
- package/patternfly-docs/generated/components/tabs/react-demos.js +108 -0
- package/patternfly-docs/generated/components/tabs/react.js +1359 -0
- package/patternfly-docs/generated/components/text-input-group/react-demos.js +152 -0
- package/patternfly-docs/generated/components/text-input-group/react.js +278 -0
- package/patternfly-docs/generated/components/tile/react-deprecated.js +242 -0
- package/patternfly-docs/generated/components/timestamp/react.js +283 -0
- package/patternfly-docs/generated/components/title/react.js +94 -0
- package/patternfly-docs/generated/components/toggle-group/react.js +299 -0
- package/patternfly-docs/generated/components/toolbar/react-demos.js +66 -0
- package/patternfly-docs/generated/components/toolbar/react.js +932 -0
- package/patternfly-docs/generated/components/tooltip/react.js +241 -0
- package/patternfly-docs/generated/components/tree-view/react.js +429 -0
- package/patternfly-docs/generated/components/truncate/react.js +211 -0
- package/patternfly-docs/generated/components/wizard/react-demos.js +87 -0
- package/patternfly-docs/generated/components/wizard/react-deprecated.js +788 -0
- package/patternfly-docs/generated/components/wizard/react.js +986 -0
- package/patternfly-docs/generated/developer-guides/open-ui-automation/react.js +285 -0
- package/patternfly-docs/generated/foundations-and-styles/layouts/bullseye/react.js +70 -0
- package/patternfly-docs/generated/foundations-and-styles/layouts/flex/react.js +506 -0
- package/patternfly-docs/generated/foundations-and-styles/layouts/gallery/react.js +94 -0
- package/patternfly-docs/generated/foundations-and-styles/layouts/grid/react.js +272 -0
- package/patternfly-docs/generated/foundations-and-styles/layouts/level/react.js +87 -0
- package/patternfly-docs/generated/foundations-and-styles/layouts/split/react.js +124 -0
- package/patternfly-docs/generated/foundations-and-styles/layouts/stack/react.js +112 -0
- package/patternfly-docs/generated/index.js +1769 -0
- package/patternfly-docs/generated/patterns/card-view/react-demos.js +78 -0
- package/patternfly-docs/generated/patterns/filters/react-demos.js +141 -0
- package/patternfly-docs/generated/patterns/password-generator/react-demos.js +51 -0
- package/patternfly-docs/generated/patterns/password-strength/react-demos.js +61 -0
- package/patternfly-docs/generated/patterns/primary-detail/react-demos.js +124 -0
- package/patternfly-docs/generated/patterns/right-to-left/react-demos.js +81 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AutoLinkHeader, Example, Link as PatternflyThemeLink } from '@patternfly/documentation-framework/components';
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Card,
|
|
7
|
+
CardBody,
|
|
8
|
+
CardFooter,
|
|
9
|
+
DatePicker,
|
|
10
|
+
Form,
|
|
11
|
+
FormGroup,
|
|
12
|
+
Grid,
|
|
13
|
+
GridItem,
|
|
14
|
+
Menu,
|
|
15
|
+
MenuContent,
|
|
16
|
+
MenuItem,
|
|
17
|
+
MenuList,
|
|
18
|
+
MenuToggle,
|
|
19
|
+
Popper,
|
|
20
|
+
SearchInput,
|
|
21
|
+
TextInput
|
|
22
|
+
} from '@patternfly/react-core';
|
|
23
|
+
import { words } from '../../../../../react-core/src/demos/SearchInput/./words.js';
|
|
24
|
+
const pageData = {
|
|
25
|
+
"id": "Search input",
|
|
26
|
+
"section": "components",
|
|
27
|
+
"subsection": "",
|
|
28
|
+
"deprecated": false,
|
|
29
|
+
"template": false,
|
|
30
|
+
"beta": false,
|
|
31
|
+
"demo": false,
|
|
32
|
+
"newImplementationLink": false,
|
|
33
|
+
"source": "react-demos",
|
|
34
|
+
"tabName": null,
|
|
35
|
+
"slug": "/components/search-input/react-demos",
|
|
36
|
+
"sourceLink": "https://github.com/patternfly/patternfly-react/blob/main/packages/react-core/src/demos/SearchInput/SearchInput.md",
|
|
37
|
+
"relPath": "packages/react-core/src/demos/SearchInput/SearchInput.md",
|
|
38
|
+
"examples": [
|
|
39
|
+
"Search with autocomplete",
|
|
40
|
+
"Composable advanced search"
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
pageData.liveContext = {
|
|
44
|
+
useEffect,
|
|
45
|
+
useRef,
|
|
46
|
+
useState,
|
|
47
|
+
Button,
|
|
48
|
+
Card,
|
|
49
|
+
CardBody,
|
|
50
|
+
CardFooter,
|
|
51
|
+
DatePicker,
|
|
52
|
+
Form,
|
|
53
|
+
FormGroup,
|
|
54
|
+
Grid,
|
|
55
|
+
GridItem,
|
|
56
|
+
Menu,
|
|
57
|
+
MenuContent,
|
|
58
|
+
MenuItem,
|
|
59
|
+
MenuList,
|
|
60
|
+
MenuToggle,
|
|
61
|
+
Popper,
|
|
62
|
+
SearchInput,
|
|
63
|
+
TextInput,
|
|
64
|
+
words
|
|
65
|
+
};
|
|
66
|
+
pageData.relativeImports = "import { words } from 'react-core/src/demos/SearchInput/./words.js';"
|
|
67
|
+
pageData.examples = {
|
|
68
|
+
'Search with autocomplete': props =>
|
|
69
|
+
<Example {...pageData} {...props} {...{"code":"import { useEffect, useRef, useState } from 'react';\nimport { Menu, MenuContent, MenuItem, MenuList, Popper, SearchInput } from '@patternfly/react-core';\n\nimport { words } from '../words';\n\nexport const SearchInputAutocomplete: React.FunctionComponent = () => {\n const [value, setValue] = useState('');\n const [hint, setHint] = useState('');\n const [autocompleteOptions, setAutocompleteOptions] = useState([]);\n\n const [isAutocompleteOpen, setIsAutocompleteOpen] = useState(false);\n\n const searchInputRef = useRef(null);\n const autocompleteRef = useRef(null);\n\n const onClear = () => {\n setValue('');\n };\n\n const onChange = (_event, newValue) => {\n if (\n newValue !== '' &&\n searchInputRef &&\n searchInputRef.current &&\n searchInputRef.current.contains(document.activeElement)\n ) {\n setIsAutocompleteOpen(true);\n\n // When the value of the search input changes, build a list of no more than 10 autocomplete options.\n // Options which start with the search input value are listed first, followed by options which contain\n // the search input value.\n let options = words\n .filter((option) => option.startsWith(newValue.toLowerCase()))\n .map((option) => (\n <MenuItem itemId={option} key={option}>\n {option}\n </MenuItem>\n ));\n if (options.length > 10) {\n options = options.slice(0, 10);\n } else {\n options = [\n ...options,\n ...words\n .filter((option) => !option.startsWith(newValue.toLowerCase()) && option.includes(newValue.toLowerCase()))\n .map((option) => (\n <MenuItem itemId={option} key={option}>\n {option}\n </MenuItem>\n ))\n ].slice(0, 10);\n }\n\n // The hint is set whenever there is only one autocomplete option left.\n setHint(options.length === 1 ? options[0].props.itemId : '');\n // The menu is hidden if there are no options\n setIsAutocompleteOpen(options.length > 0);\n setAutocompleteOptions(options);\n } else {\n setIsAutocompleteOpen(false);\n }\n setValue(newValue);\n };\n\n // Whenever an autocomplete option is selected, set the search input value, close the menu, and put the browser\n // focus back on the search input\n const onSelect = (e, itemId) => {\n e.stopPropagation();\n setValue(itemId);\n setIsAutocompleteOpen(false);\n searchInputRef.current.focus();\n };\n\n const handleMenuKeys = (event) => {\n // If there is a hint while the browser focus is on the search input, tab or right arrow will 'accept' the hint value\n // and set it as the search input value\n if (hint && (event.key === 'Tab' || event.key === 'ArrowRight') && searchInputRef.current === event.target) {\n setValue(hint);\n setHint('');\n setIsAutocompleteOpen(false);\n if (event.key === 'ArrowRight') {\n event.preventDefault();\n }\n // if the autocomplete is open and the browser focus is on the search input,\n } else if (isAutocompleteOpen && searchInputRef.current && searchInputRef.current === event.target) {\n // the escape key closes the autocomplete menu and keeps the focus on the search input.\n if (event.key === 'Escape') {\n setIsAutocompleteOpen(false);\n searchInputRef.current.focus();\n // the up and down arrow keys move browser focus into the autocomplete menu\n } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n const firstElement = autocompleteRef.current.querySelector('li > button:not(:disabled)');\n firstElement && firstElement.focus();\n event.preventDefault(); // by default, the up and down arrow keys scroll the window\n // the tab, enter, and space keys will close the menu, and the tab key will move browser\n // focus forward one element (by default)\n } else if (event.key === 'Tab' || event.key === 'Enter' || event.key === ' ') {\n setIsAutocompleteOpen(false);\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n }\n }\n // If the autocomplete is open and the browser focus is in the autocomplete menu\n // hitting tab will close the autocomplete and but browser focus back on the search input.\n } else if (isAutocompleteOpen && autocompleteRef.current.contains(event.target) && event.key === 'Tab') {\n event.preventDefault();\n setIsAutocompleteOpen(false);\n searchInputRef.current.focus();\n }\n };\n\n // The autocomplete menu should close if the user clicks outside the menu.\n const handleClickOutside = (event) => {\n if (\n isAutocompleteOpen &&\n autocompleteRef &&\n autocompleteRef.current &&\n !autocompleteRef.current.contains(event.target)\n ) {\n setIsAutocompleteOpen(false);\n }\n };\n\n useEffect(() => {\n window.addEventListener('keydown', handleMenuKeys);\n window.addEventListener('click', handleClickOutside);\n return () => {\n window.removeEventListener('keydown', handleMenuKeys);\n window.removeEventListener('click', handleClickOutside);\n };\n }, [isAutocompleteOpen, hint, searchInputRef.current]);\n\n const searchInput = (\n <SearchInput\n value={value}\n onChange={onChange}\n onClear={onClear}\n ref={searchInputRef}\n hint={hint}\n id=\"autocomplete-search\"\n aria-label=\"Search with autocomplete\"\n />\n );\n\n const autocomplete = (\n <Menu ref={autocompleteRef} onSelect={onSelect}>\n <MenuContent>\n <MenuList>{autocompleteOptions}</MenuList>\n </MenuContent>\n </Menu>\n );\n\n return (\n <Popper\n trigger={searchInput}\n triggerRef={searchInputRef}\n popper={autocomplete}\n popperRef={autocompleteRef}\n isVisible={isAutocompleteOpen}\n enableFlip={false}\n // append the autocomplete menu to the search input in the DOM for the sake of the keyboard navigation experience\n appendTo={() => document.querySelector('#autocomplete-search')}\n />\n );\n};\n","title":"Search with autocomplete","lang":"ts","className":""}}>
|
|
70
|
+
|
|
71
|
+
<p {...{"className":"pf-v6-c-content--p pf-m-editorial ws-p "}}>
|
|
72
|
+
{`This demo handles building the advanced search form using the composable Menu, and the `}
|
|
73
|
+
|
|
74
|
+
<code {...{"className":"ws-code "}}>
|
|
75
|
+
{`SearchInput`}
|
|
76
|
+
</code>
|
|
77
|
+
{`'s `}
|
|
78
|
+
|
|
79
|
+
<code {...{"className":"ws-code "}}>
|
|
80
|
+
{`hint`}
|
|
81
|
+
</code>
|
|
82
|
+
{` prop.
|
|
83
|
+
It also demonstrates wiring up the appropriate keyboard interactions, focus management, and general event handling.`}
|
|
84
|
+
</p>
|
|
85
|
+
</Example>,
|
|
86
|
+
'Composable advanced search': props =>
|
|
87
|
+
<Example {...pageData} {...props} {...{"code":"import { useEffect, useRef, useState } from 'react';\nimport {\n ActionGroup,\n Button,\n DatePicker,\n Form,\n FormGroup,\n Grid,\n GridItem,\n isValidDate,\n Menu,\n MenuContent,\n MenuItem,\n MenuList,\n MenuToggle,\n Panel,\n PanelMain,\n PanelMainBody,\n Popper,\n SearchInput,\n TextInput,\n yyyyMMddFormat\n} from '@patternfly/react-core';\n\nexport const SearchInputAdvancedComposable: React.FunctionComponent = () => {\n const [value, setValue] = useState('');\n const [hasWords, setHasWords] = useState('');\n const [dateWithin, setDateWithin] = useState('1 day');\n const [date, setDate] = useState();\n\n const [isAdvancedSearchOpen, setIsAdvancedSearchOpen] = useState(false);\n const [isDateWithinOpen, setIsDateWithinOpen] = useState(false);\n\n const isInitialMount = useRef(true);\n const firstAttrRef = useRef(null);\n const searchInputRef = useRef(null);\n const advancedSearchPaneRef = useRef(null);\n const dateWithinToggleRef = useRef(undefined);\n const dateWithinMenuRef = useRef(undefined);\n\n const onClear = () => {\n setValue('');\n setHasWords('');\n setDateWithin('');\n setDate('');\n };\n\n const onChange = (_event, value) => {\n if (value.length <= hasWords.length + 1) {\n setValue(value);\n setHasWords(value);\n } else {\n setValue(hasWords);\n }\n };\n\n // After initial page load, whenever the advanced search menu is opened, the browser focus should be placed on the\n // first advanced search form input. Whenever the advanced search menu is closed, the browser focus should\n // be returned to the search input.\n useEffect(() => {\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else {\n if (isAdvancedSearchOpen && firstAttrRef && firstAttrRef.current) {\n firstAttrRef.current.focus();\n } else if (!isAdvancedSearchOpen && searchInputRef) {\n searchInputRef.current.focus();\n }\n }\n }, [isAdvancedSearchOpen]);\n\n // If a menu is open and has browser focus, then the escape key closes them and puts the browser focus onto their\n // respective toggle. The 'date within' menu also needs to close when the 'tab' key is hit. However, hitting tab while\n // focus is in the advanced search form should move the focus to the next form input, not close the advanced search\n // menu.\n const handleMenuKeys = (event) => {\n if (isDateWithinOpen && dateWithinMenuRef.current && dateWithinMenuRef.current.contains(event.target)) {\n if (event.key === 'Escape' || event.key === 'Tab') {\n setIsDateWithinOpen(!isDateWithinOpen);\n dateWithinToggleRef.current.focus();\n }\n }\n if (isAdvancedSearchOpen && advancedSearchPaneRef.current && advancedSearchPaneRef.current.contains(event.target)) {\n if (\n event.key === 'Escape' ||\n (event.key === 'Tab' &&\n !event.shiftKey &&\n advancedSearchPaneRef.current.querySelector('button[type=reset]') === event.target)\n ) {\n setIsAdvancedSearchOpen(!isAdvancedSearchOpen);\n searchInputRef.current.focus();\n }\n }\n };\n\n // If a menu is open and has browser focus, then clicking outside the menu should close it.\n const handleClickOutside = (event) => {\n if (\n isDateWithinOpen &&\n dateWithinMenuRef &&\n dateWithinMenuRef.current &&\n !dateWithinMenuRef.current.contains(event.target)\n ) {\n setIsDateWithinOpen(false);\n }\n if (\n isAdvancedSearchOpen &&\n advancedSearchPaneRef &&\n advancedSearchPaneRef.current &&\n !advancedSearchPaneRef.current.contains(event.target)\n ) {\n setIsAdvancedSearchOpen(false);\n }\n };\n\n useEffect(() => {\n window.addEventListener('keydown', handleMenuKeys);\n window.addEventListener('click', handleClickOutside);\n return () => {\n window.removeEventListener('keydown', handleMenuKeys);\n window.removeEventListener('click', handleClickOutside);\n };\n }, [dateWithinMenuRef.current, advancedSearchPaneRef.current, isAdvancedSearchOpen, isDateWithinOpen]);\n\n // This demo and its handling of 'date within' and a date picker is modeled after the gmail advanced search form.\n const onSubmit = (event, _value) => {\n event.preventDefault();\n\n if (isValidDate(new Date(date)) && dateWithin) {\n const afterDate = new Date(date);\n const toDate = new Date(date);\n switch (dateWithin) {\n case '1 day':\n afterDate.setDate(afterDate.getDate());\n toDate.setDate(toDate.getDate() + 2);\n break;\n case '3 days':\n afterDate.setDate(afterDate.getDate() - 2);\n toDate.setDate(toDate.getDate() + 4);\n break;\n case '1 week':\n afterDate.setDate(afterDate.getDate() - 6);\n toDate.setDate(toDate.getDate() + 8);\n break;\n case '2 weeks':\n afterDate.setDate(afterDate.getDate() - 13);\n toDate.setDate(toDate.getDate() + 15);\n break;\n case '1 month':\n afterDate.setMonth(afterDate.getMonth() - 1);\n afterDate.setDate(afterDate.getDate() + 1);\n toDate.setMonth(toDate.getMonth() + 1);\n toDate.setDate(toDate.getDate() + 1);\n break;\n case '2 months':\n afterDate.setMonth(afterDate.getMonth() - 2);\n afterDate.setDate(afterDate.getDate() + 1);\n toDate.setMonth(toDate.getMonth() + 2);\n toDate.setDate(toDate.getDate() + 1);\n break;\n case '6 months':\n afterDate.setMonth(afterDate.getMonth() - 6);\n afterDate.setDate(afterDate.getDate() + 1);\n toDate.setMonth(toDate.getMonth() + 6);\n toDate.setDate(toDate.getDate() + 1);\n break;\n case '1 year':\n afterDate.setFullYear(afterDate.getFullYear() - 1);\n afterDate.setDate(afterDate.getDate() + 1);\n toDate.setFullYear(toDate.getFullYear() + 1);\n toDate.setDate(toDate.getDate() + 1);\n break;\n }\n setValue(`${hasWords && hasWords + ' '}after:${yyyyMMddFormat(afterDate)} to:${yyyyMMddFormat(toDate)}`);\n } else {\n setValue(hasWords);\n }\n\n setIsAdvancedSearchOpen(false);\n };\n\n const searchInput = (\n <SearchInput\n value={value}\n onChange={onChange}\n onToggleAdvancedSearch={(e, isOpen) => {\n e.stopPropagation();\n setIsAdvancedSearchOpen(isOpen);\n }}\n isAdvancedSearchOpen={isAdvancedSearchOpen}\n onClear={onClear}\n onSearch={onSubmit}\n ref={searchInputRef}\n id=\"custom-advanced-search\"\n aria-label=\"Composable advanced search\"\n />\n );\n\n // Clicking the 'date within' toggle should open its associated menu and then place the browser\n // focus on the first menu item.\n const toggleDateWithinMenu = (ev) => {\n ev.stopPropagation(); // Stop handleClickOutside from handling\n setTimeout(() => {\n if (dateWithinMenuRef.current) {\n const firstElement = dateWithinMenuRef.current.querySelector('li > button:not(:disabled)');\n firstElement && firstElement.focus();\n }\n }, 0);\n setIsDateWithinOpen(!isDateWithinOpen);\n };\n\n // Selecting a date within option closes the menu, sets the value of date within, and puts browser focus back\n // on the date within toggle.\n const onDateWithinSelect = (e, itemId) => {\n e.stopPropagation();\n setIsDateWithinOpen(false);\n setDateWithin(itemId);\n if (dateWithinToggleRef && dateWithinToggleRef.current) {\n dateWithinToggleRef.current.focus();\n }\n };\n\n const dateWithinOptions = (\n <Menu ref={dateWithinMenuRef} selected={dateWithin} onSelect={onDateWithinSelect}>\n <MenuContent>\n <MenuList>\n <MenuItem itemId=\"1 day\">1 day</MenuItem>\n <MenuItem itemId=\"3 days\">3 days</MenuItem>\n <MenuItem itemId=\"1 week\">1 week</MenuItem>\n <MenuItem itemId=\"2 weeks\">2 weeks</MenuItem>\n <MenuItem itemId=\"1 month\">1 month</MenuItem>\n <MenuItem itemId=\"2 months\">2 months</MenuItem>\n <MenuItem itemId=\"6 months\">6 months</MenuItem>\n <MenuItem itemId=\"1 year\">1 year</MenuItem>\n </MenuList>\n </MenuContent>\n </Menu>\n );\n\n const dateWithinToggle = (\n <MenuToggle\n ref={dateWithinToggleRef}\n onClick={toggleDateWithinMenu}\n isExpanded={isDateWithinOpen}\n style={{ width: '100%' }}\n >\n {dateWithin}\n </MenuToggle>\n );\n\n const advancedForm = (\n <div ref={advancedSearchPaneRef} role=\"dialog\" aria-label=\"Advanced search form\">\n <Panel variant=\"raised\">\n <PanelMain>\n <PanelMainBody>\n <Form>\n <FormGroup label=\"Has the words\" fieldId=\"has-words\" key=\"has-words\">\n <TextInput\n type=\"text\"\n id=\"has-words\"\n value={hasWords}\n onChange={(_event, value) => {\n setHasWords(value);\n setValue(value);\n }}\n ref={firstAttrRef}\n />\n </FormGroup>\n <Grid hasGutter md={6}>\n <GridItem>\n <FormGroup label=\"Date within\" fieldId=\"date-within\" key=\"date-within\">\n <Popper\n trigger={dateWithinToggle}\n triggerRef={dateWithinToggleRef}\n popper={dateWithinOptions}\n popperRef={dateWithinMenuRef}\n isVisible={isDateWithinOpen}\n />\n </FormGroup>\n </GridItem>\n <GridItem>\n <FormGroup label=\"Of date\" fieldId=\"date\" key=\"date\">\n <DatePicker\n id=\"datePicker\"\n style={{ width: '100%' }}\n value={date}\n onChange={(_e, newValue) => setDate(newValue)}\n appendTo={() => document.querySelector('#datePicker')}\n />\n </FormGroup>\n </GridItem>\n </Grid>\n <ActionGroup>\n <Button variant=\"primary\" type=\"submit\" onClick={(e) => onSubmit(null, e)}>\n Submit\n </Button>\n {!!onClear && (\n <Button variant=\"link\" type=\"reset\" onClick={onClear}>\n Reset\n </Button>\n )}\n </ActionGroup>\n </Form>\n </PanelMainBody>\n </PanelMain>\n </Panel>\n </div>\n );\n\n // Popper is just one way to build a relationship between a toggle and a menu.\n return (\n <Popper\n trigger={searchInput}\n triggerRef={searchInputRef}\n popper={advancedForm}\n popperRef={advancedSearchPaneRef}\n isVisible={isAdvancedSearchOpen}\n enableFlip={false}\n appendTo={() => document.querySelector('#custom-advanced-search')}\n />\n );\n};\n","title":"Composable advanced search","lang":"ts","className":""}}>
|
|
88
|
+
|
|
89
|
+
<p {...{"className":"pf-v6-c-content--p pf-m-editorial ws-p "}}>
|
|
90
|
+
{`This demo handles building the advanced search form using the composable Menu, as well as wiring up a
|
|
91
|
+
select using the composable Menu and MenuToggle components. This demo also demonstrates wiring up the appropriate
|
|
92
|
+
keyboard interactions, focus management, and general event handling.`}
|
|
93
|
+
</p>
|
|
94
|
+
|
|
95
|
+
<p {...{"className":"pf-v6-c-content--p pf-m-editorial ws-p "}}>
|
|
96
|
+
{`Note: This demo and its handling of 'date within' and a date picker is modeled after the gmail advanced search form.`}
|
|
97
|
+
</p>
|
|
98
|
+
</Example>
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const Component = () => (
|
|
102
|
+
<React.Fragment>
|
|
103
|
+
<AutoLinkHeader {...{"id":"demos","headingLevel":"h2","className":"ws-title ws-h2"}}>
|
|
104
|
+
{`Demos`}
|
|
105
|
+
</AutoLinkHeader>
|
|
106
|
+
{React.createElement(pageData.examples["Search with autocomplete"])}
|
|
107
|
+
{React.createElement(pageData.examples["Composable advanced search"])}
|
|
108
|
+
</React.Fragment>
|
|
109
|
+
);
|
|
110
|
+
Component.displayName = 'ComponentsSearchInputReactDemosDocs';
|
|
111
|
+
Component.pageData = pageData;
|
|
112
|
+
|
|
113
|
+
export default Component;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AutoLinkHeader, Example, Link as PatternflyThemeLink } from '@patternfly/documentation-framework/components';
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
|
+
import RhUiExternalLinkFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-external-link-fill-icon';
|
|
5
|
+
const pageData = {
|
|
6
|
+
"id": "Search input",
|
|
7
|
+
"section": "components",
|
|
8
|
+
"subsection": "",
|
|
9
|
+
"deprecated": false,
|
|
10
|
+
"template": false,
|
|
11
|
+
"beta": false,
|
|
12
|
+
"demo": false,
|
|
13
|
+
"newImplementationLink": false,
|
|
14
|
+
"source": "react",
|
|
15
|
+
"tabName": null,
|
|
16
|
+
"slug": "/components/search-input/react",
|
|
17
|
+
"sourceLink": "https://github.com/patternfly/patternfly-react/blob/main/packages/react-core/src/components/SearchInput/examples/SearchInput.md",
|
|
18
|
+
"relPath": "packages/react-core/src/components/SearchInput/examples/SearchInput.md",
|
|
19
|
+
"propComponents": [
|
|
20
|
+
{
|
|
21
|
+
"name": "SearchInput",
|
|
22
|
+
"description": "",
|
|
23
|
+
"props": [
|
|
24
|
+
{
|
|
25
|
+
"name": "advancedSearchDelimiter",
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Delimiter in the query string for pairing attributes with search values.\nRequired whenever attributes are passed as props."
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "attributes",
|
|
31
|
+
"type": "string[] | SearchInputSearchAttribute[]",
|
|
32
|
+
"description": "Array of attribute values used for dynamically generated advanced search.",
|
|
33
|
+
"defaultValue": "[]"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "className",
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "Additional classes added to the advanced search menu."
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "formAdditionalItems",
|
|
42
|
+
"type": "React.ReactNode",
|
|
43
|
+
"description": ""
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "getAttrValueMap",
|
|
47
|
+
"type": "() => { [key: string]: string }",
|
|
48
|
+
"description": "Function which builds an attribute-value map by parsing the value in the search input."
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "hasWordsAttrLabel",
|
|
52
|
+
"type": "React.ReactNode",
|
|
53
|
+
"description": "Attribute label for strings unassociated with one of the provided listed attributes.",
|
|
54
|
+
"defaultValue": "'Has words'"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "isSearchMenuOpen",
|
|
58
|
+
"type": "boolean",
|
|
59
|
+
"description": "Flag for toggling the open/close state of the advanced search menu."
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "onChange",
|
|
63
|
+
"type": "(event: React.FormEvent<HTMLInputElement>, value: string) => void",
|
|
64
|
+
"description": "A callback for when the input value changes."
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "onClear",
|
|
68
|
+
"type": "(event: React.SyntheticEvent<HTMLButtonElement>) => void",
|
|
69
|
+
"description": "A callback for when the user clicks the clear button."
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"name": "onSearch",
|
|
73
|
+
"type": "(\n event: React.SyntheticEvent<HTMLButtonElement>,\n value: string,\n attrValueMap: { [key: string]: string }\n) => void",
|
|
74
|
+
"description": "A callback for when the search button is clicked."
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "onToggleAdvancedMenu",
|
|
78
|
+
"type": "(e: React.SyntheticEvent<HTMLButtonElement>) => void",
|
|
79
|
+
"description": "A callback for when the open advanced search button is clicked."
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "parentInputRef",
|
|
83
|
+
"type": "React.RefObject<any>",
|
|
84
|
+
"description": "Ref of the input element within the search input."
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "parentRef",
|
|
88
|
+
"type": "React.RefObject<any>",
|
|
89
|
+
"description": "Ref of the div wrapping the whole search input."
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"name": "resetButtonLabel",
|
|
93
|
+
"type": "string",
|
|
94
|
+
"description": "Label for the button which resets the advanced search form and clears the search input.",
|
|
95
|
+
"defaultValue": "'Reset'"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "submitSearchButtonLabel",
|
|
99
|
+
"type": "string",
|
|
100
|
+
"description": "Label for the button which calls the onSearch event handler.",
|
|
101
|
+
"defaultValue": "'Search'"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"name": "value",
|
|
105
|
+
"type": "string",
|
|
106
|
+
"description": "Value of the search input.",
|
|
107
|
+
"defaultValue": "''"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "SearchInputSearchAttribute",
|
|
113
|
+
"description": "Properties for adding search attributes to an advanced search input. These properties must\nbe passed in as an object within an array to the search input component's attribute property.",
|
|
114
|
+
"props": [
|
|
115
|
+
{
|
|
116
|
+
"name": "attr",
|
|
117
|
+
"type": "string",
|
|
118
|
+
"description": "The search attribute's value to be provided in the search input's query string.\nIt should have no spaces and be unique for every attribute.",
|
|
119
|
+
"required": true
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"name": "display",
|
|
123
|
+
"type": "React.ReactNode",
|
|
124
|
+
"description": "The search attribute's display name. It is used to label the field in the advanced\nsearch menu.",
|
|
125
|
+
"required": true
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "SearchInputExpandable",
|
|
131
|
+
"description": "Properties for creating an expandable search input. These properties should be passed into\nthe search input component's expandableInput property.",
|
|
132
|
+
"props": [
|
|
133
|
+
{
|
|
134
|
+
"name": "hasAnimations",
|
|
135
|
+
"type": "boolean",
|
|
136
|
+
"description": "Flag indicating animations should be enabled when the search input expands and collapses. Note: this will change the component's DOM structure. In a future breaking change release, this will become the default behavior and will no longer be needed."
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"name": "isExpanded",
|
|
140
|
+
"type": "boolean",
|
|
141
|
+
"description": "Flag to indicate if the search input is expanded.",
|
|
142
|
+
"required": true
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"name": "onToggleExpand",
|
|
146
|
+
"type": "(event: React.SyntheticEvent<HTMLButtonElement>, isExpanded: boolean) => void",
|
|
147
|
+
"description": "Callback function to toggle the expandable search input.",
|
|
148
|
+
"required": true
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "toggleAriaLabel",
|
|
152
|
+
"type": "string",
|
|
153
|
+
"description": "An accessible label for the expandable search input toggle.",
|
|
154
|
+
"required": true
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"cssPrefix": [
|
|
160
|
+
"pf-v6-c-search-input"
|
|
161
|
+
],
|
|
162
|
+
"examples": [
|
|
163
|
+
"Basic",
|
|
164
|
+
"Match with result count",
|
|
165
|
+
"Match with navigable options",
|
|
166
|
+
"With submit button",
|
|
167
|
+
"Focus search input using ref",
|
|
168
|
+
"With expandable button",
|
|
169
|
+
"Advanced"
|
|
170
|
+
]
|
|
171
|
+
};
|
|
172
|
+
pageData.liveContext = {
|
|
173
|
+
useRef,
|
|
174
|
+
useState,
|
|
175
|
+
RhUiExternalLinkFillIcon
|
|
176
|
+
};
|
|
177
|
+
pageData.examples = {
|
|
178
|
+
'Basic': props =>
|
|
179
|
+
<Example {...pageData} {...props} {...{"code":"import { useState } from 'react';\nimport { SearchInput } from '@patternfly/react-core';\n\nexport const SearchInputBasic: React.FunctionComponent = () => {\n const [value, setValue] = useState('');\n\n const onChange = (value: string) => {\n setValue(value);\n };\n\n return (\n <SearchInput\n aria-label=\"Search basic example\"\n placeholder=\"Find by name\"\n value={value}\n onChange={(_event, value) => onChange(value)}\n onClear={() => onChange('')}\n />\n );\n};\n","title":"Basic","lang":"ts","className":""}}>
|
|
180
|
+
|
|
181
|
+
</Example>,
|
|
182
|
+
'Match with result count': props =>
|
|
183
|
+
<Example {...pageData} {...props} {...{"code":"import { useState } from 'react';\nimport { SearchInput } from '@patternfly/react-core';\n\nexport const SearchInputWithResultCount: React.FunctionComponent = () => {\n const [value, setValue] = useState('');\n const [resultsCount, setResultsCount] = useState(0);\n\n const onChange = (value: string) => {\n setValue(value);\n setResultsCount(3);\n };\n\n const onClear = () => {\n setValue('');\n setResultsCount(0);\n };\n\n return (\n <SearchInput\n aria-label=\"Match with result count\"\n placeholder=\"Find by name\"\n value={value}\n onChange={(_event, value) => onChange(value)}\n onClear={onClear}\n resultsCount={resultsCount}\n />\n );\n};\n","title":"Match with result count","lang":"ts","className":""}}>
|
|
184
|
+
|
|
185
|
+
</Example>,
|
|
186
|
+
'Match with navigable options': props =>
|
|
187
|
+
<Example {...pageData} {...props} {...{"code":"import { useState } from 'react';\nimport { SearchInput } from '@patternfly/react-core';\n\nexport const SearchInputWithNavigableOptions: React.FunctionComponent = () => {\n const [value, setValue] = useState('');\n const [resultsCount, setResultsCount] = useState(0);\n const [currentResult, setCurrentResult] = useState(1);\n\n const onChange = (value: string) => {\n setValue(value);\n setResultsCount(3);\n };\n\n const onClear = () => {\n setValue('');\n setResultsCount(0);\n setCurrentResult(1);\n };\n\n const onNext = () => {\n const newCurrentResult = currentResult + 1;\n setCurrentResult(newCurrentResult > resultsCount ? resultsCount : newCurrentResult);\n };\n\n const onPrevious = () => {\n const newCurrentResult = currentResult - 1;\n setCurrentResult(newCurrentResult > 0 ? newCurrentResult : 1);\n };\n\n return (\n <SearchInput\n aria-label=\"Search match with navigable options example\"\n placeholder=\"Find by name\"\n value={value}\n onChange={(_event, value) => onChange(value)}\n onClear={onClear}\n isNextNavigationButtonDisabled={currentResult === 3}\n isPreviousNavigationButtonDisabled={currentResult === 1}\n resultsCount={`${currentResult} / ${resultsCount}`}\n onNextClick={onNext}\n onPreviousClick={onPrevious}\n />\n );\n};\n","title":"Match with navigable options","lang":"ts","className":""}}>
|
|
188
|
+
|
|
189
|
+
</Example>,
|
|
190
|
+
'With submit button': props =>
|
|
191
|
+
<Example {...pageData} {...props} {...{"code":"import { useState } from 'react';\nimport { SearchInput } from '@patternfly/react-core';\n\nexport const SearchInputWithSubmitButton: React.FunctionComponent = () => {\n const [value, setValue] = useState('');\n\n return (\n <SearchInput\n aria-label=\"Search with submit button example\"\n placeholder=\"Find by name\"\n value={value}\n onChange={(_event, value) => setValue(value)}\n onSearch={(_event, value) => setValue(value)}\n onClear={() => setValue('')}\n />\n );\n};\n","title":"With submit button","lang":"ts","className":""}}>
|
|
192
|
+
|
|
193
|
+
</Example>,
|
|
194
|
+
'Focus search input using ref': props =>
|
|
195
|
+
<Example {...pageData} {...props} {...{"code":"import { useRef, useState } from 'react';\nimport { SearchInput, Button } from '@patternfly/react-core';\n\nexport const SearchInputFocusSearch: React.FunctionComponent = () => {\n const [value, setValue] = useState('');\n const ref: React.MutableRefObject<HTMLInputElement | null> = useRef(null);\n\n return (\n <>\n <SearchInput\n ref={ref}\n value={value}\n onChange={(_event, value) => setValue(value)}\n onClear={() => setValue('')}\n aria-label=\"Search focus using ref example\"\n />\n <Button onClick={() => ref.current && ref.current.focus()}>Focus on the search input</Button>\n </>\n );\n};\n","title":"Focus search input using ref","lang":"ts","className":""}}>
|
|
196
|
+
|
|
197
|
+
</Example>,
|
|
198
|
+
'With expandable button': props =>
|
|
199
|
+
<Example {...pageData} {...props} {...{"code":"import { useState } from 'react';\nimport { SearchInput } from '@patternfly/react-core';\n\nexport const SearchInputWithExpandable: React.FunctionComponent = () => {\n const [value, setValue] = useState('');\n const [isExpanded, setIsExpanded] = useState(false);\n\n const onChange = (value: string) => {\n setValue(value);\n };\n\n const onToggleExpand = (_event: React.SyntheticEvent<HTMLButtonElement>, isExpanded: boolean) => {\n setIsExpanded(!isExpanded);\n };\n\n return (\n <SearchInput\n aria-label=\"Search with expandable button example\"\n placeholder=\"Find by name\"\n value={value}\n onChange={(_event, value) => onChange(value)}\n onClear={() => onChange('')}\n expandableInput={{\n isExpanded,\n onToggleExpand,\n toggleAriaLabel: 'Expandable search input toggle',\n hasAnimations: true\n }}\n />\n );\n};\n","title":"With expandable button","lang":"ts","className":""}}>
|
|
200
|
+
|
|
201
|
+
<p {...{"className":"pf-v6-c-content--p pf-m-editorial ws-p "}}>
|
|
202
|
+
{`Animations on the expansion and collapse of the search input may be opted into by passing `}
|
|
203
|
+
|
|
204
|
+
<code {...{"className":"ws-code "}}>
|
|
205
|
+
{`hasAnimations`}
|
|
206
|
+
</code>
|
|
207
|
+
{` to the `}
|
|
208
|
+
|
|
209
|
+
<code {...{"className":"ws-code "}}>
|
|
210
|
+
{`expandableInput`}
|
|
211
|
+
</code>
|
|
212
|
+
{` object.`}
|
|
213
|
+
</p>
|
|
214
|
+
</Example>,
|
|
215
|
+
'Advanced': props =>
|
|
216
|
+
<Example {...pageData} {...props} {...{"code":"import { useState } from 'react';\nimport { Button, Checkbox, FormGroup, SearchInput } from '@patternfly/react-core';\nimport RhUiExternalLinkFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-external-link-fill-icon';\n\nexport const SearchInputAdvanced: React.FunctionComponent = () => {\n const [value, setValue] = useState('username:player firstname:john');\n const [useEqualsAsDelimiter, setUseEqualsAsDelimiter] = useState(false);\n const [useCustomFooter, setUseCustomFooter] = useState(false);\n\n const toggleDelimiter = (checked: boolean) => {\n setValue(value.replace(/:|=/g, checked ? '=' : ':'));\n setUseEqualsAsDelimiter(checked);\n };\n\n return (\n <>\n <Checkbox\n label=\"Use equal sign as search attribute delimiter\"\n isChecked={useEqualsAsDelimiter}\n onChange={(_event, checked) => toggleDelimiter(checked)}\n aria-label=\"change delimiter checkbox\"\n id=\"toggle-delimiter\"\n name=\"toggle-delimiter\"\n />\n <Checkbox\n label=\"Add custom footer element after the attributes in the menu\"\n isChecked={useCustomFooter}\n onChange={(_event, checked) => setUseCustomFooter(checked)}\n aria-label=\"change use custom footer checkbox\"\n id=\"toggle-custom-footer\"\n name=\"toggle-custom-footer\"\n />\n <br />\n <SearchInput\n aria-label=\"Advanced search\"\n attributes={[\n { attr: 'username', display: 'Username' },\n { attr: 'firstname', display: 'First name' }\n ]}\n advancedSearchDelimiter={useEqualsAsDelimiter ? '=' : ':'}\n value={value}\n onChange={(_event, value) => setValue(value)}\n onSearch={(_event, value) => setValue(value)}\n onClear={() => setValue('')}\n formAdditionalItems={\n useCustomFooter ? (\n <FormGroup>\n <Button variant=\"link\" isInline icon={<RhUiExternalLinkFillIcon />} iconPosition=\"end\">\n Link\n </Button>\n </FormGroup>\n ) : null\n }\n />\n </>\n );\n};\n","title":"Advanced","lang":"ts","className":""}}>
|
|
217
|
+
|
|
218
|
+
<p {...{"className":"pf-v6-c-content--p pf-m-editorial ws-p "}}>
|
|
219
|
+
{`The search input component can be used to dynamically build a one to one attribute-value advanced search.
|
|
220
|
+
Using the `}
|
|
221
|
+
|
|
222
|
+
<code {...{"className":"ws-code "}}>
|
|
223
|
+
{`attributes`}
|
|
224
|
+
</code>
|
|
225
|
+
{` prop alongside the `}
|
|
226
|
+
|
|
227
|
+
<code {...{"className":"ws-code "}}>
|
|
228
|
+
{`advancedSearchDelimiter`}
|
|
229
|
+
</code>
|
|
230
|
+
{` will expose this functionality, as demonstrated in
|
|
231
|
+
the following example. The search input component can also be used as a composable component and paired with a Popper
|
|
232
|
+
or other elements to build a completely custom advanced search form. This feature is demonstrated
|
|
233
|
+
in the search input's `}
|
|
234
|
+
<a href="/components/search-input/react-demos">{`react demos`}</a>
|
|
235
|
+
{`.`}
|
|
236
|
+
</p>
|
|
237
|
+
|
|
238
|
+
<p {...{"className":"pf-v6-c-content--p pf-m-editorial ws-p "}}>
|
|
239
|
+
{`The values used in the attribute-value form fields may contain spaces. The values containing spaces
|
|
240
|
+
should be wrapped with quotes inside the summary search string in the input field. If the latter is
|
|
241
|
+
autogenerated from the individual fields the quotes will be autoplaced.`}
|
|
242
|
+
</p>
|
|
243
|
+
</Example>
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const Component = () => (
|
|
247
|
+
<React.Fragment>
|
|
248
|
+
<AutoLinkHeader {...{"id":"examples","headingLevel":"h2","className":"ws-title ws-h2"}}>
|
|
249
|
+
{`Examples`}
|
|
250
|
+
</AutoLinkHeader>
|
|
251
|
+
{React.createElement(pageData.examples["Basic"])}
|
|
252
|
+
{React.createElement(pageData.examples["Match with result count"])}
|
|
253
|
+
{React.createElement(pageData.examples["Match with navigable options"])}
|
|
254
|
+
{React.createElement(pageData.examples["With submit button"])}
|
|
255
|
+
{React.createElement(pageData.examples["Focus search input using ref"])}
|
|
256
|
+
{React.createElement(pageData.examples["With expandable button"])}
|
|
257
|
+
{React.createElement(pageData.examples["Advanced"])}
|
|
258
|
+
</React.Fragment>
|
|
259
|
+
);
|
|
260
|
+
Component.displayName = 'ComponentsSearchInputReactDocs';
|
|
261
|
+
Component.pageData = pageData;
|
|
262
|
+
|
|
263
|
+
export default Component;
|