diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 8ff71575..76b495e7 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -1,6 +1,6 @@ # Component Index -> 154 components exported from carbon-components-svelte@0.23.2. +> 155 components exported from carbon-components-svelte@0.23.2. ## Components @@ -57,6 +57,7 @@ - [`HeaderPanelDivider`](#headerpaneldivider) - [`HeaderPanelLink`](#headerpanellink) - [`HeaderPanelLinks`](#headerpanellinks) +- [`HeaderSearch`](#headersearch) - [`HeaderUtilities`](#headerutilities) - [`Icon`](#icon) - [`IconSkeleton`](#iconskeleton) @@ -1609,6 +1610,48 @@ None. None. +## `HeaderSearch` + +### Types + +```ts +export interface HeaderSearchResult { + href: string; + text: string; + description?: string; +} +``` + +### Props + +| Prop name | Kind | Reactive | Type | Default value | Description | +| :------------------ | :--------------- | :------- | :---------------------------------------- | ------------------ | -------------------------------------------------- | +| selectedResultIndex | let | Yes | number | 0 | Specify the selected result index | +| ref | let | Yes | null | HTMLInputElement | null | Obtain a reference to the input HTML element | +| active | let | Yes | boolean | false | Set to `true` to activate and focus the search bar | +| value | let | Yes | string | "" | Specify the search input value | +| results | let | No | HeaderSearchResult[] | [] | Render a list of search results | + +### Slots + +| Slot name | Default | Props | Fallback | +| :-------- | :------ | :---------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ | +| -- | Yes | { result: HeaderSearchResult; index: number } | {result.text}
{#if result.description}<span>– {result.description}</span>{/if}
| + +### Events + +| Event name | Type | Detail | +| :--------- | :--------- | :---------------------------------------------------------------------------------------------- | +| active | dispatched | any | +| inactive | dispatched | any | +| clear | dispatched | any | +| select | dispatched | { value: string; selectedResultIndex: number; selectedResult: HeaderSearchResult } | +| change | forwarded | -- | +| input | forwarded | -- | +| focus | forwarded | -- | +| blur | forwarded | -- | +| keydown | forwarded | -- | + ## `HeaderUtilities` ### Props diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index 7a1cdbea..4411396f 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -1,5 +1,5 @@ { - "total": 154, + "total": 155, "components": [ { "moduleName": "SkeletonText", @@ -10258,6 +10258,93 @@ "typedefs": [], "rest_props": { "type": "Element", "name": "button" } }, + { + "moduleName": "HeaderSearch", + "filePath": "/src/UIShell/HeaderSearch.svelte", + "props": [ + { + "name": "value", + "kind": "let", + "description": "Specify the search input value", + "type": "string", + "value": "\"\"", + "isFunction": false, + "constant": false, + "reactive": true + }, + { + "name": "active", + "kind": "let", + "description": "Set to `true` to activate and focus the search bar", + "type": "boolean", + "value": "false", + "isFunction": false, + "constant": false, + "reactive": true + }, + { + "name": "ref", + "kind": "let", + "description": "Obtain a reference to the input HTML element", + "type": "null | HTMLInputElement", + "value": "null", + "isFunction": false, + "constant": false, + "reactive": true + }, + { + "name": "results", + "kind": "let", + "description": "Render a list of search results", + "type": "HeaderSearchResult[]", + "value": "[]", + "isFunction": false, + "constant": false, + "reactive": false + }, + { + "name": "selectedResultIndex", + "kind": "let", + "description": "Specify the selected result index", + "type": "number", + "value": "0", + "isFunction": false, + "constant": false, + "reactive": true + } + ], + "slots": [ + { + "name": "__default__", + "default": true, + "fallback": "{result.text}\n {#if result.description}– {result.description}{/if}", + "slot_props": "{ result: HeaderSearchResult; index: number }" + } + ], + "events": [ + { "type": "dispatched", "name": "active", "detail": "any" }, + { "type": "dispatched", "name": "inactive", "detail": "any" }, + { "type": "dispatched", "name": "clear", "detail": "any" }, + { + "type": "dispatched", + "name": "select", + "detail": "{ value: string; selectedResultIndex: number; selectedResult: HeaderSearchResult }" + }, + { "type": "forwarded", "name": "change", "element": "input" }, + { "type": "forwarded", "name": "input", "element": "input" }, + { "type": "forwarded", "name": "focus", "element": "input" }, + { "type": "forwarded", "name": "blur", "element": "input" }, + { "type": "forwarded", "name": "keydown", "element": "input" } + ], + "typedefs": [ + { + "type": "{ href: string; text: string; description?: string; }", + "name": "HeaderSearchResult", + "ts": "interface HeaderSearchResult { href: string; text: string; description?: string; }" + } + ], + "rest_props": { "type": "Element", "name": "input" } + }, { "moduleName": "UnorderedList", "filePath": "/src/UnorderedList/UnorderedList.svelte", diff --git a/docs/src/pages/components/UIShell.svx b/docs/src/pages/components/UIShell.svx index 46eea0ee..33a18b98 100644 --- a/docs/src/pages/components/UIShell.svx +++ b/docs/src/pages/components/UIShell.svx @@ -4,7 +4,7 @@ components: ["Header", "HeaderAction", "HeaderActionLink", -"HeaderActionSearch", +"HeaderSearch", "HeaderNav", "HeaderNavItem", "HeaderNavMenu", @@ -34,6 +34,10 @@ components: ["Header", +### Header with global search + + + ### Header with utilities diff --git a/docs/src/pages/framed/UIShell/HeaderSearch.svelte b/docs/src/pages/framed/UIShell/HeaderSearch.svelte new file mode 100644 index 00000000..d5d30ebd --- /dev/null +++ b/docs/src/pages/framed/UIShell/HeaderSearch.svelte @@ -0,0 +1,130 @@ + + +
+
+ +
+ + + +
+ + + + + +

HeaderSearch

+ +

Reactive values

+

active: {active}

+

value: {value}

+

selectedResultIndex: {selectedResultIndex}

+

Events

+

+ Click the button and search for something. Dispatched events are + logged below: +

+
+ {#each events as { type, ...rest }} +
+
on:{type}
+ {#if Object.keys(rest).length > 0} +
{JSON.stringify(rest, null, 2)}
+ {/if} +
+ {/each} +
+
+
+
+
diff --git a/docs/src/pages/framed/UIShell/HeaderUtilities.svelte b/docs/src/pages/framed/UIShell/HeaderUtilities.svelte index 74e90182..a0fb3300 100644 --- a/docs/src/pages/framed/UIShell/HeaderUtilities.svelte +++ b/docs/src/pages/framed/UIShell/HeaderUtilities.svelte @@ -3,7 +3,6 @@ Header, HeaderUtilities, HeaderAction, - HeaderActionSearch, HeaderGlobalAction, HeaderPanelLinks, HeaderPanelDivider, @@ -30,7 +29,6 @@ - diff --git a/src/UIShell/GlobalHeader/HeaderActionSearch.svelte b/src/UIShell/GlobalHeader/HeaderActionSearch.svelte index 21b5f8b9..8ed2a15c 100644 --- a/src/UIShell/GlobalHeader/HeaderActionSearch.svelte +++ b/src/UIShell/GlobalHeader/HeaderActionSearch.svelte @@ -1,4 +1,10 @@ + + + + + +
+ +
+ + + +
+ + {#if active && results.length > 0} + + {/if} +
diff --git a/src/UIShell/index.js b/src/UIShell/index.js index c4f78b8e..aba209bd 100644 --- a/src/UIShell/index.js +++ b/src/UIShell/index.js @@ -17,3 +17,4 @@ export { default as SideNavMenuItem } from "./SideNav/SideNavMenuItem.svelte"; export { default as Content } from "./Content.svelte"; export { default as SkipToContent } from "./SkipToContent.svelte"; export { default as HeaderGlobalAction } from "./HeaderGlobalAction.svelte"; +export { default as HeaderSearch } from "./HeaderSearch.svelte"; diff --git a/src/index.js b/src/index.js index 7610fa9c..522bc154 100644 --- a/src/index.js +++ b/src/index.js @@ -134,5 +134,6 @@ export { Content, SkipToContent, HeaderGlobalAction, + HeaderSearch, } from "./UIShell"; export { UnorderedList } from "./UnorderedList"; diff --git a/tests/HeaderSearch.svelte b/tests/HeaderSearch.svelte new file mode 100644 index 00000000..58e4048a --- /dev/null +++ b/tests/HeaderSearch.svelte @@ -0,0 +1,117 @@ + + +
+
+ +
+ + +
{result.text}{index}
+
+ + + Switcher subject 1 + Switcher item 1 + Switcher subject 2 + Switcher item 1 + Switcher item 2 + Switcher item 3 + Switcher item 4 + Switcher item 5 + + +
+
+ + + + + + + + + + + + + + + + + + +

Welcome

+
+
+
+
diff --git a/types/UIShell/HeaderSearch.d.ts b/types/UIShell/HeaderSearch.d.ts new file mode 100644 index 00000000..a961d6d2 --- /dev/null +++ b/types/UIShell/HeaderSearch.d.ts @@ -0,0 +1,60 @@ +/// + +export interface HeaderSearchResult { + href: string; + text: string; + description?: string; +} + +export interface HeaderSearchProps extends svelte.JSX.HTMLAttributes { + /** + * Specify the search input value + * @default "" + */ + value?: string; + + /** + * Set to `true` to activate and focus the search bar + * @default false + */ + active?: boolean; + + /** + * Obtain a reference to the input HTML element + * @default null + */ + ref?: null | HTMLInputElement; + + /** + * Render a list of search results + * @default [] + */ + results?: HeaderSearchResult[]; + + /** + * Specify the selected result index + * @default 0 + */ + selectedResultIndex?: number; +} + +export default class HeaderSearch { + $$prop_def: HeaderSearchProps; + $$slot_def: { + default: { result: HeaderSearchResult; index: number }; + }; + + $on(eventname: "active", cb: (event: CustomEvent) => void): () => void; + $on(eventname: "inactive", cb: (event: CustomEvent) => void): () => void; + $on(eventname: "clear", cb: (event: CustomEvent) => void): () => void; + $on( + eventname: "select", + cb: (event: CustomEvent<{ value: string; selectedResultIndex: number; selectedResult: HeaderSearchResult }>) => void + ): () => void; + $on(eventname: "change", cb: (event: WindowEventMap["change"]) => void): () => void; + $on(eventname: "input", cb: (event: WindowEventMap["input"]) => void): () => void; + $on(eventname: "focus", cb: (event: WindowEventMap["focus"]) => void): () => void; + $on(eventname: "blur", cb: (event: WindowEventMap["blur"]) => void): () => void; + $on(eventname: "keydown", cb: (event: WindowEventMap["keydown"]) => void): () => void; + $on(eventname: string, cb: (event: Event) => void): () => void; +} diff --git a/types/index.d.ts b/types/index.d.ts index 3ce43582..c1862c40 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -151,4 +151,5 @@ export { default as SideNavMenuItem } from "./UIShell/SideNav/SideNavMenuItem"; export { default as Content } from "./UIShell/Content"; export { default as SkipToContent } from "./UIShell/SkipToContent"; export { default as HeaderGlobalAction } from "./UIShell/HeaderGlobalAction"; +export { default as HeaderSearch } from "./UIShell/HeaderSearch"; export { default as UnorderedList } from "./UnorderedList/UnorderedList";