Grapes homepage1.57.0
  • Guide
  • Tokens
  • Components
    Grapes on GithubGrapes on Figma
    Interaction
    • Button
    • IconButton
    • FloatingActionBar
    • Link
    Icons
    • Icon
    • HighlightIcon
    Form
    • AmountInput
    • Autocomplete
    • AutocompleteMultiple
    • AutocompletePlace
    • CheckboxBox
    • CheckboxField
    • DatePicker
    • FormField
    • Input
    • OptionGroup
    • PasswordInput
    • PhoneInput
    • RadioBox
    • RadioField
    • RadioGroup
    • Select
    • SwitchField
    • TextArea
    • TextInput
    • Upload
    • UploadButton
    Feedback
    • Badge
    • Banner
    • Callout
    • EmptyState
    • Modal
    • ModalSlideshow
    • DeprecatedModalSlideshow
    • PageModal
    • Skeleton
    • Tag
    • Toast
    • Tooltip
    Data display
    • Accordion
    • Avatar
    • Box
    • Calendar
    • CalendarRange
    • CollapsibleList
    • FileCard
    • InfoTip
    • ListBox
    • ListView
    • Panel
    • SidePanel
    • DeprecatedPreview
    • Table
    • Timeline
    • useDateFormatter
    Navigation
    • DropdownItem
    • DropdownMenu
    • Navigation
    • NavigationItem
    • Popover
    • Tabs

    AmountInput

    The AmountInput is a number input designed to handle currency amounts.

    View source code
    • Usage
    • Props

    Basic Usage

    €
    const Demo = () => {
      const [selectedValue, setSelectedValue] = useState<number | null>(null);
    
      return (
        <AmountInput
          currency={{ key: "EUR", label: "€ - Euro" }}
          value={selectedValue}
          onChange={(_, newValue) => {
            setSelectedValue(newValue);
          }}
        />
      );
    };
    

    Variant

    Use the inputVariant prop to control the visual style of the Autocomplete. The Autocomplete comes with two visual styles: default (default) and magicGradient.

    €
    <AmountInput variant="magicGradient" {...otherProps} />
    

    Multiple currencies

    The AmountInput supports multiple currencies using currencies prop. onSelectCurrency also needs to be provided to catch the event when the user updates the currency. If both are provided, a dropdown will be displayed with the predefined currencies.

    <AmountInput
      currencies={currencies}
      onSelectCurrency={(selectedCurrency) => {
        setCurrency(selectedCurrency);
      }}
      currency={currentCurrency}
      {...otherProps}
    />
    

    Allow negative value

    By default, the AmountInput doesn't allow negative values. Use hasNegativeValueAllowed to allow negative values.

    €
    <AmountInput hasNegativeValueAllowed {...otherProps} />
    

    Customize input

    Use the leftAddon prop to add a ReactNode on the left side of the input.

    <AmountInput
      leftAddon={
        <div className="ml-8 mt-4">
          <Icon name="robot" />
        </div>
      }
      {...otherProps}
    />
    
      €