UNPKG

@commercelayer/react-components

Version:
62 lines (61 loc) 2.13 kB
import type { Address } from "@commercelayer/sdk"; import { type JSX, type ReactNode } from "react"; import type { AddressFieldView } from "../../reducers/AddressReducer"; import type { ChildrenFunction } from "../../typings/index"; interface ChildrenProps extends Omit<Props, "children" | "name"> { address: Address; } type ChildrenProp = ChildrenFunction<ChildrenProps>; type Props = { type?: "field"; label?: never; onClick?: never; children?: ChildrenProp; name: AddressFieldView; className?: string; } | { type?: "edit"; label: string | ReactNode; onClick: (address: Address) => void; children?: ChildrenProp; name?: AddressFieldView; className?: string; } | { type?: "delete"; label: string; onClick: () => void; children?: ChildrenProp; name?: AddressFieldView; className?: string; } | { type?: "edit" | "field" | "delete"; label?: never; onClick?: never; children: ChildrenProp; name?: never; className?: string; }; /** * The AddressField component displays any attribute of the `address` object set in the state of the parent `<Address>` component. * * It accepts a `name` prop to define the attribute to be shown. * It also accepts: * - a `type` props to enable different kind of behaviors like `field` (default), `edit` or `delete`. * - a `label` props to show a custom label if chosen `type` is `edit` or `delete`. * - an `onClick` props to define a custom click behavior. * * <span title="Type `delete`" type="info"> * Only in case `type` is set to `delete` a default `onClick` behavior will be set to manage current address removal. * </span> * * <span title="Requirement" type="warning"> * It must to be used inside the `<Address>` component. * </span> * * <span title="Fields" type="info"> * Check the `addresses` resource from our [Core API documentation](https://docs.commercelayer.io/core/v/api-reference/addresses/object) * for more details about the available attributes to render. * </span> */ export declare function AddressField(props: Props): JSX.Element; export default AddressField;