-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* AsyncSelect (#407) * Draft AsyncSelect * Search icon * controlShouldRenderValue --------- Co-authored-by: stianStensli <stian.hs@hotmail.com> * Bytter til chakra-react-select og legger til dokumentasjon * Rydder opp searchAsync --------- Co-authored-by: stianStensli <stian.hs@hotmail.com>
- Loading branch information
1 parent
707fe38
commit c0c58a7
Showing
10 changed files
with
473 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kvib/react": minor | ||
--- | ||
|
||
Legger til SearchAsync-komponent - dette gjør at det er mulig med en dropdown i et søkefelt. |
39 changes: 39 additions & 0 deletions
39
apps/storybook/stories/components/search/search-async/SearchAsync.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Meta, Canvas, Story, Controls } from "@storybook/blocks"; | ||
import * as SearchAsyncStories from "./SearchAsync.stories"; | ||
|
||
<Meta of={SearchAsyncStories} /> | ||
|
||
# SearchAsync | ||
|
||
SearchAsync er et søkefelt som laster inn søkeresultater fra en liste med objekter. Resultatene blir vist i en dropdown der brukeren kan velge hvilket resultat som skal bli valgt. | ||
|
||
## Ta i bruk | ||
|
||
```jsx | ||
import { SearchAsync } from "@kvib/react"; | ||
``` | ||
|
||
## Props | ||
|
||
<Canvas of={SearchAsyncStories.SearchAsync} /> | ||
<Controls of={SearchAsyncStories.SearchAsync} /> | ||
|
||
## Async søkeresultater | ||
|
||
<Canvas of={SearchAsyncStories.SearchAsyncResults} /> | ||
|
||
## Søkeresultater med delay | ||
|
||
<Canvas of={SearchAsyncStories.SearchAsyncResultsDebounce} /> | ||
|
||
## Standardalternativer | ||
|
||
<Canvas of={SearchAsyncStories.SearchAsyncDropdownIndicator} /> | ||
|
||
## Størrelser | ||
|
||
<Canvas of={SearchAsyncStories.SearchAsyncSizes} /> | ||
|
||
## Varianter | ||
|
||
<Canvas of={SearchAsyncStories.SearchAsyncVariants} /> |
193 changes: 193 additions & 0 deletions
193
apps/storybook/stories/components/search/search-async/SearchAsync.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import { SearchAsync as KvibSearchAsync, Stack as KvibStack, Box, Icon } from "@kvib/react/src"; | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta: Meta<typeof KvibSearchAsync> = { | ||
title: "Komponenter/Search/SearchAsync", | ||
component: KvibSearchAsync, | ||
parameters: { | ||
docs: { | ||
story: { inline: true }, | ||
canvas: { sourceState: "shown" }, | ||
}, | ||
a11y: { | ||
// Label warnings + contrast ratio because of chakra wrapper. | ||
disable: true, | ||
}, | ||
}, | ||
argTypes: { | ||
loadOptions: { | ||
control: "text", | ||
}, | ||
handleFromChange: { | ||
control: "text", | ||
}, | ||
placeholder: { | ||
table: { | ||
type: { summary: "string" }, | ||
}, | ||
control: "text", | ||
}, | ||
autoFocus: { | ||
table: { | ||
type: { summary: "boolean" }, | ||
}, | ||
control: "boolean", | ||
}, | ||
debounceTime: { | ||
table: { | ||
type: { summary: "number" }, | ||
}, | ||
control: "number", | ||
}, | ||
className: { | ||
table: { | ||
type: { summary: "string" }, | ||
}, | ||
control: "text", | ||
}, | ||
isClearable: { | ||
table: { | ||
type: { summary: "boolean" }, | ||
}, | ||
control: "boolean", | ||
}, | ||
dropdownIndicator: { | ||
table: { | ||
type: { summary: "Element" }, | ||
}, | ||
control: "text", | ||
}, | ||
size: { | ||
table: { | ||
type: { summary: "sm | md | lg" }, | ||
defaultValue: { summary: "md" }, | ||
}, | ||
options: ["sm", "md", "lg"], | ||
control: { type: "radio" }, | ||
}, | ||
defaultOptions: { | ||
table: { | ||
type: { summary: "OptionsOrGroups<T, GroupBase<T>>" }, | ||
}, | ||
control: "array", | ||
}, | ||
variant: { | ||
table: { | ||
type: { summary: "outline | filled | flushed | unstyled" }, | ||
defaultValue: { summary: "outline" }, | ||
}, | ||
options: ["outline", "filled", "flushed", "unstyled"], | ||
control: { type: "radio" }, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof KvibSearchAsync>; | ||
|
||
export const SearchAsync: Story = { | ||
args: {}, | ||
render: (args) => ( | ||
<Box h={20}> | ||
<KvibSearchAsync {...args} /> | ||
</Box> | ||
), | ||
}; | ||
|
||
const fruits = [ | ||
{ label: "Eple", value: "eple" }, | ||
{ label: "Banan", value: "banan" }, | ||
{ label: "Kirsebær", value: "kirsebær" }, | ||
{ label: "Pære", value: "pære" }, | ||
{ label: "Svarthyll", value: "svarthyll" }, | ||
]; | ||
|
||
const mockLoadOptions = (inputValue: string, callback: (options: typeof fruits) => void) => { | ||
setTimeout(() => { | ||
const filteredFruits = fruits.filter((fruit) => fruit.label.toLowerCase().includes(inputValue.toLowerCase())); | ||
callback(filteredFruits); | ||
}, 500); | ||
}; | ||
|
||
export const SearchAsyncResults: Story = { | ||
args: { | ||
loadOptions: mockLoadOptions, | ||
handleFromChange: (selectedOption) => { | ||
console.log("Selected Option:", selectedOption); | ||
}, | ||
placeholder: "Søk etter frukt...", | ||
}, | ||
render: (args) => ( | ||
<Box h={40}> | ||
<KvibSearchAsync {...args} /> | ||
</Box> | ||
), | ||
}; | ||
|
||
export const SearchAsyncResultsDebounce: Story = { | ||
args: { | ||
loadOptions: mockLoadOptions, | ||
handleFromChange: (selectedOption) => { | ||
console.log("Selected Option:", selectedOption); | ||
}, | ||
debounceTime: 3000, | ||
placeholder: "Søk etter frukt...", | ||
}, | ||
render: (args) => ( | ||
<Box h={40}> | ||
<KvibSearchAsync {...args} /> | ||
</Box> | ||
), | ||
}; | ||
|
||
export const SearchAsyncDropdownIndicator: Story = { | ||
args: { | ||
loadOptions: mockLoadOptions, | ||
handleFromChange: (selectedOption) => { | ||
console.log("Selected Option:", selectedOption); | ||
}, | ||
dropdownIndicator: <Icon icon="expand_more" weight={400} />, | ||
defaultOptions: fruits, | ||
placeholder: "Søk etter frukt...", | ||
}, | ||
render: (args) => ( | ||
<Box h={60}> | ||
<KvibSearchAsync {...args} /> | ||
</Box> | ||
), | ||
}; | ||
|
||
export const SearchAsyncSizes: Story = { | ||
args: { | ||
loadOptions: mockLoadOptions, | ||
handleFromChange: (selectedOption) => { | ||
console.log("Selected Option:", selectedOption); | ||
}, | ||
placeholder: "Søk etter frukt...", | ||
}, | ||
render: (args) => ( | ||
<KvibStack> | ||
<KvibSearchAsync {...args} size="sm" /> | ||
<KvibSearchAsync {...args} size="md" /> | ||
<KvibSearchAsync {...args} size="lg" /> | ||
</KvibStack> | ||
), | ||
}; | ||
|
||
export const SearchAsyncVariants: Story = { | ||
args: { | ||
loadOptions: mockLoadOptions, | ||
handleFromChange: (selectedOption) => { | ||
console.log("Selected Option:", selectedOption); | ||
}, | ||
placeholder: "Søk etter frukt...", | ||
}, | ||
render: (args) => ( | ||
<KvibStack h={60}> | ||
<KvibSearchAsync {...args} variant="outline" /> | ||
<KvibSearchAsync {...args} variant="filled" /> | ||
<KvibSearchAsync {...args} variant="flushed" /> | ||
<KvibSearchAsync {...args} variant="unstyled" /> | ||
</KvibStack> | ||
), | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.