import React from 'react'; import { AsChildChildren } from '@wix/headless-utils/react'; /** * Choice data interface. */ export interface Choice { /** Hex color code for color choices. For example, "#FF0000". */ colorCode?: string; /** Unique identifier for the choice. */ choiceId?: string | null; /** Media linked to this choice.*/ linkedMedia?: any[]; /** The type of choice: `color`, `text`, or `free-text`. */ type?: 'color' | 'text' | 'free-text'; /** Key identifier for the choice. */ key?: string; /** Display name for the choice. */ name?: string | null; /** Additional price for this choice as a formatted string, for example "$5.00". */ addedPrice?: string | null; /** Minimum character count for free-text choices. */ minCharCount?: number; /** Maximum character count for free-text choices. */ maxCharCount?: number; } /** * Context value interface for individual choice data and behavior. */ export interface ChoiceContextValue { /** The choice data object. */ choice: Choice; /** Whether this choice should render as text. */ shouldRenderAsText: boolean; /** Whether this choice should render as color swatch. */ shouldRenderAsColor: boolean; /** Whether this choice should render as free text input. */ shouldRenderAsFreeText: boolean; /** Display value for the choice. */ value: string; /** Whether this choice is currently selected. */ isSelected: boolean; /** Whether this choice is visible based on current selections. */ isVisible: boolean; /** Whether this choice is in stock. */ isInStock: boolean; /** Whether this choice is available for pre-order. */ isPreOrderEnabled: boolean; /** Function to select this choice. */ select: () => void; /** Callback for free text value changes. */ onValueChange?: (value: string) => void; } export declare const ChoiceContext: React.Context; /** * Hook to access the choice context provided by `Option.ChoiceRepeater`. * * Use this hook when you need access to choice data that isn't exposed through * the `asChild` pattern on `Choice.Text`, `Choice.Color`, or `Choice.FreeText`. * * The following properties are only available through `useChoiceContext()` hook, not exposed in `asChild` render props: * - `choice` (`Choice`): The full choice data object with: * - `addedPrice` (`string | null`): Additional price for this choice as a formatted string, for example "$5.00". * - `colorCode` (`string | undefined`): Hex color code for color choices. For example, "#FF0000". * - `linkedMedia` (`any[] | undefined`): Media items linked to this choice. * - `minCharCount` (`number | undefined`): Minimum character count for free-text choices. * - `maxCharCount` (`number | undefined`): Maximum character count for free-text choices. * - `isSelected` (`boolean`): Whether this choice is currently selected. * - `isVisible` (`boolean`): Whether this choice is visible based on current selections. * - `isInStock` (`boolean`): Whether this choice is in stock. * - `isPreOrderEnabled` (`boolean`): Whether this choice is available for pre-order. * - `shouldRenderAsText` (`boolean`): Whether this choice should render as text. * - `shouldRenderAsColor` (`boolean`): Whether this choice should render as color swatch. * - `shouldRenderAsFreeText` (`boolean`): Whether this choice should render as free text input. * - `select` (`() => void`): Function to select this choice. * - `onValueChange` (`((value: string) => void) | undefined`): Callback for free text value changes. * * @returns {ChoiceContextValue} The current choice context value. * @throws {Error} If used outside of an `Option.ChoiceRepeater` component. * * @example Custom choice rendering * ```tsx * // import { Option, Choice } from '@wix/stores/components'; * // * // Call from a component rendered within Option.ChoiceRepeater * * // Custom component using the hook for advanced rendering * function ChoiceWithPrice() { * const { value, isSelected, isInStock, choice, select } = Choice.useChoiceContext(); * * return ( * * ); * } * * // Usage within the parent component * * * * ``` */ export declare function useChoiceContext(): ChoiceContextValue; /** * Props for the `Choice.Root` component. */ export interface RootProps { /** * Child components to render within the choice context. * * Use `Choice.Text`, `Choice.Color`, or `Choice.FreeText` to display * the choice based on its type. */ children?: React.ReactNode; } /** * Root component that consumes ChoiceContext provided by Option.ChoiceRepeater. * * Use `Option.ChoiceRepeater` alone when rendering Choice sub-components like `Choice.Text`, `Choice.Color`, etc. * Use `Choice.Root` directly when you need to render a custom choice component that accesses the choice context via `useChoiceContext()`. * * ### Component hierarchy * * ```tsx * * * * * * ``` * * ### Custom choice rendering * * Use `Choice.useChoiceContext()` to access data not exposed via `asChild`. * See `useChoiceContext` for more information. * * @component * @example Basic usage with Option.ChoiceRepeater (Choice.Root not needed) * ```tsx * // import { Option, Choice } from '@wix/stores/components'; * // * // Option.ChoiceRepeater automatically provides Choice.Root * * // Default styling * * * * * ``` * * @example Custom choice rendering with `useChoiceContext()` * ```tsx * // import { Option, Choice } from '@wix/stores/components'; * // * // Must be used within Option.ChoiceRepeater * * // Custom component using the hook for advanced rendering * function ChoiceWithPrice() { * const { value, isSelected, isInStock, choice, select } = Choice.useChoiceContext(); * * return ( * * ); * } * * // Usage within the parent component * * * * ``` */ export declare const Root: React.ForwardRefExoticComponent>; /** * Props for the `Choice.Text` component. */ export interface TextProps { /** * When `true`, replaces the default ` * ))} * * * // asChild with render object - Syntax demonstration for accessing render props * * {{ * render: ({ id, value, ...props }, ref) => ( * * ) * }} * * ``` */ export declare const Text: React.ForwardRefExoticComponent>; /** * Props for the `Choice.Color` component. */ export interface ColorProps { /** * When `true`, replaces the default `