import { storiesOf } from "@storybook/react"; import React from "react"; import Form from "@saleor/components/Form"; import { countries } from "@saleor/fixtures"; import CardDecorator from "@saleor/storybook/CardDecorator"; import Decorator from "@saleor/storybook/Decorator"; import { ChoiceProvider } from "@saleor/storybook/mock"; import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler"; import SingleAutocompleteSelectField, { SingleAutocompleteSelectFieldProps } from "./SingleAutocompleteSelectField"; import SingleAutocompleteSelectFieldContent, { SingleAutocompleteSelectFieldContentProps } from "./SingleAutocompleteSelectFieldContent"; const suggestions = countries.map(c => ({ label: c.name, value: c.code })); const props: SingleAutocompleteSelectFieldProps = { choices: undefined, displayValue: undefined, label: "Country", loading: false, name: "country", onChange: () => undefined, placeholder: "Select country", value: suggestions[0].value }; const Story: React.FC> = ({ allowCustomValues, emptyOption, enableLoadMore }) => { const [displayValue, setDisplayValue] = React.useState(suggestions[0].label); return (
{({ change, data }) => ( {({ choices, fetchChoices, onFetchMore, hasMore, loading }) => { const handleSelect = createSingleAutocompleteSelectHandler( change, setDisplayValue, choices ); return ( ); }} )}
); }; const contentProps: SingleAutocompleteSelectFieldContentProps = { choices: suggestions.slice(0, 10), displayCustomValue: false, emptyOption: false, getItemProps: () => undefined, hasMore: false, highlightedIndex: 0, inputValue: suggestions[0].label, isCustomValueSelected: false, loading: false, onFetchMore: () => undefined, selectedItem: suggestions[0].value }; storiesOf("Generics / Select with autocomplete", module) .addDecorator(CardDecorator) .addDecorator(Decorator) .add("default", () => ( )) .add("can load more", () => ( )) .add("no data", () => ( )) .add("interactive", () => ) .add("interactive with custom option", () => ( )) .add("interactive with empty option", () => ) .add("interactive with load more", () => );