Payment Card

The Payment Card input automatically detects and formats credit card types. It shows a small thumbnail icon of the parsed credit card brand to let users know they have entered their card in the correct format. The supported credit card brands are listed here:

The card-validator library is used to determine the card format. It's also re-exported from baseui/payment-card as valid in case you need more metadata about the card.

This component is based on the Input component. All of the props you can pass to Input also work on PaymentCard.

Examples

Basic usage

Default value

If you'd like to add further validations, check out the card-validator package that Base Web uses under the hood too.

AutoFocus

PaymentCard accepts an autoFocus prop. For information on its behaviour, check Input's autoFocus example.

Stateful (uncontrolled) usage

As with many of our components, there is also an uncontrolled version, StatefulPaymentCard, which manages its own state.

API

Payment Card props

NameTypeDefaultDescription
animate
boolean
falseEnable animation for certain parts of input. e.g. shows animated border on hover for ai intent
aria-describedby
string
Sets aria-describedby attribute.
aria-label
string
Sets aria-label attribute.
aria-labelledby
string
Sets aria-labelledby attribute.
autoComplete
string
Determines if browser should provide value suggestions.
autoFocus
string
Takes "start" | "end" | number | boolean values and sets the position of the cursor on mount.
className
string
className to modify style of Input container
clearable
boolean
falseIf true, adds a clear value icon button to the end of the input container.
debounceInterval
number
debouncedOnChange function will be called after onChange stops being called for this duration in milliseconds.
debouncedOnChange
function
Debounced handler of onChange. Specify interval with `debounceInterval` prop.
disabled
boolean
falseRenders component in disabled state.
draggable
boolean
falseSet it to true if the input is rendered in a dnd component. When true, onDragStart's default behaviour will be prevented.
id
string
Id attribute value to be added to the input element and as a label's for attribute value.
inputMode
string
A hint as to the type of data that might be entered by the user while editing the element or its contents.
inputRef
ref
A ref to access an input element.
intent
'default'| 'success'| 'warning'| 'error'| 'ai'
Defines the intent of the Input.
max
string
max value when used as input type=number
maxCharLimit
number
Maximum character needed
min
string
min value when used as input type=number
name
string
Name attribute.
onBlur
function
Called the onBlur event triggers.
onChange
function
Called when input value is changed.
onFocus
function
Called the onFocus event triggers.
onKeyDown
function
Called the onKeyDown event triggers.
onKeyPress
function
Called the onKeyPress event triggers.
onKeyUp
function
Called the onKeyUp event triggers.
overrides
custom
Lets you customize all aspects of the component.
pattern
string
A regex that is used to validate the value of the input on form submission.
placeholder
string
Input's placeholder.
required
boolean
falseRenders component in required state.
size
'xs'| 'sm'| 'md'
Input's size. SPACIOUS | COMFORTABLE -> md, COMPACT -> xxxs, DEFAULT -> md
style
string
className to modify style of Input container
value
string
Input value attribute.
variant
'default'| 'line'
Input's variant - default, line

Payment Card exports

You can import this module like so:

import {PaymentCard} from 'spaceweb/payment-card'

It exports the following components or utility functions:

  • PaymentCard
  • SIZE
  • StatefulContainer
  • StatefulPaymentCard
  • StyledIconWrapper
  • valid