import * as React from "react"; import { StoryFn, Meta } from "@storybook/react"; import { action } from "@storybook/addon-actions"; import { FieldList, FieldListColumn, FieldListColumnSeparator, FieldListAddButton } from ".."; import { TextInput } from "../../textInput"; import FieldListStoryHelper from "./helpers/FieldListStoryHelper"; import { MonospaceText } from "../../styleUtils/typography"; const mockItems = [ { name: "Brian Vaughn", role: "Software Engineer", city: "San Jose", id: 0 }, { name: "Jon Doe", role: "Product engineer", city: "Mountain View", id: 1 }, { name: "Jane Doe", role: "UX Designer", city: "San Francisco", id: 2 } ]; const testFieldUpdateHandler = (rowIndex, pathToValue) => () => action( `update row ${rowIndex} with the property that has the key ${pathToValue}` ); export default { title: "Forms/Form structure/FieldList", component: FieldList, subcomponents: { FieldListColumn, FieldListColumnSeparator, FieldListAddButton } } as Meta; const Template: StoryFn = args => ( {({ onRemoveItem, onAddItem, onFieldUpdate, items }) => ( <> onAddItem({ name: "", role: "", city: "", id: Math.random() }) } pathToUniqueKey="id" {...args} > {({ defaultProps, onChange, value }) => ( )} {({ defaultProps, onChange, value }) => ( )} {({ defaultProps, onChange, value }) => ( )} Add Field
FieldList data:
{JSON.stringify(items, null, 2)}
)}
); export const EditableFieldsControlledInputs = { render: Template }; export const DefaultUncontrolledInputs = { render: args => { return ( {({ defaultProps, onChange, value }) => ( )} {({ defaultProps, onChange, value }) => ( )} {({ defaultProps, onChange, value }) => ( )} ); } }; export const VariedColumnWidths = { render: args => ( {({ defaultProps, onChange, value }) => ( )} {({ defaultProps, onChange, value }) => ( )} {({ defaultProps, onChange, value }) => ( )} ) }; export const DisabledRows = { render: args => ( {({ disabled, defaultProps, onChange, value }) => ( )} {({ disabled, defaultProps, onChange, value }) => ( )} {({ disabled, defaultProps, onChange, value }) => ( )} ) }; export const WAddButton = () => ( {({ defaultProps, onChange, value }) => ( )} {({ defaultProps, onChange, value }) => ( )} {({ defaultProps, onChange, value }) => ( )} Add a row ); export const WithColumnSeparators = { render: args => ( {({ defaultProps, onChange, value }) => ( )} : {({ defaultProps, onChange, value }) => ( )} 👉 {({ defaultProps, onChange, value }) => ( )} ) };