From 79925bc0e46d6cfdd1f1fc4c27fe36df246b12e6 Mon Sep 17 00:00:00 2001 From: "drosca@totalsoft.ro" Date: Tue, 3 Dec 2024 10:15:34 +0200 Subject: [PATCH] added mix value story --- .../Autocomplete/Autocomplete.stories.tsx | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/src/stories/inputs/Autocomplete/Autocomplete.stories.tsx b/src/stories/inputs/Autocomplete/Autocomplete.stories.tsx index fb94c7c..379dda2 100644 --- a/src/stories/inputs/Autocomplete/Autocomplete.stories.tsx +++ b/src/stories/inputs/Autocomplete/Autocomplete.stories.tsx @@ -3,7 +3,7 @@ import React from 'react' import type { Meta, StoryObj } from '@storybook/react' -import { Autocomplete as AutocompleteComponent } from 'components' +import { Autocomplete as AutocompleteComponent, Typography } from 'components' import { CreatablePreview } from './CreatablePreview' import { DefaultPreview } from './DefaultPreview' import { OptionTypesPreview } from './OptionTypesPreview' @@ -12,6 +12,9 @@ import { customOptions, loadFilteredOptionsPaginated, loadOptions, options } fro import { RequiredPreview } from './RequiredPreview' import { CustomOptionPreview } from './CustomOptionPreview' import { GroupedPreview } from './GroupedPreview' +import { Stack } from '@mui/material' +import { all, has } from 'ramda' +import FormattedJson from './components/FormattedJson' const meta: Meta = { title: 'Components/Inputs/Autocomplete', @@ -410,11 +413,55 @@ export const GroupedPreview = (props: any) => { } }, args: { - label: 'Grouped Options', - onChange: null, - onClose: null, - onInputChange: null, - onOpen: null + label: 'Grouped Options' }, render: args => } + +/** + * You can give your autocomplete both the option or just it's `valueKey` in the `value` prop. + * This will render the option from the `options` array when found, otherwise it will render the value as it is. + * When you have multiple selection enabled, the `value` array can be a mix between. + */ +export const MixedValue: Story = { + parameters: { + docs: { + source: { + code: ` + + + `, + format: true + } + } + }, + args: { + options + }, + render: args => { + const options: readonly any[] = args.options + const value = options[0].id + const values = [options[0].id, options[1]] + return ( + + + + {`value={${value}}`} + + + + {`value={${JSON.stringify(values)}}`} + + + ) + } +}