Form Elements
The Easy React SDK provides secure form elements for PCI-compliant payment data collection. These elements ensure your application never touches sensitive payment information.
Available Elements
import {
CardElement, // Complete card input
CardNumberElement, // Card number only
CardExpirationDateElement, // Expiration date only
CardVerificationCodeElement, // CVV only
TextElement, // Bank account numbers, routing numbers
} from "@easylabs/react";
CardElement
A complete card input that includes card number, expiration date, and CVV in one field.
Usage
import { CardElement } from "@easylabs/react";
import { useRef } from "react";
function PaymentForm() {
const cardRef = useRef(null);
return (
<form>
<label htmlFor="card">Card Information</label>
<CardElement
ref={cardRef}
id="card"
style={{
base: {
fontSize: "16px",
color: "#424770",
"::placeholder": {
color: "#aab7c4",
},
},
invalid: {
color: "#9e2146",
},
}}
/>
</form>
);
}
Props
ref(required) - React ref to access the elementid- HTML id attributestyle- Custom styling objectdisabled- Disable inputreadOnly- Make input read-only
Separate Card Elements
For more control over layout, use separate elements for each field.
CardNumberElement
import { CardNumberElement } from "@easylabs/react";
import { useRef } from "react";
function PaymentForm() {
const cardNumberRef = useRef(null);
return (
<div>
<label>Card Number</label>
<CardNumberElement ref={cardNumberRef} />
</div>
);
}
CardExpirationDateElement
import { CardExpirationDateElement } from "@easylabs/react";
import { useRef } from "react";
function PaymentForm() {
const expiryRef = useRef(null);
return (
<div>
<label>Expiry Date</label>
<CardExpirationDateElement ref={expiryRef} />
</div>
);
}
CardVerificationCodeElement
import { CardVerificationCodeElement } from "@easylabs/react";
import { useRef } from "react";
function PaymentForm() {
const cvcRef = useRef(null);
return (
<div>
<label>CVC</label>
<CardVerificationCodeElement ref={cvcRef} />
</div>
);
}
Complete Example
import {
CardNumberElement,
CardExpirationDateElement,
CardVerificationCodeElement,
} from "@easylabs/react";
import { useRef } from "react";
function SeparateCardForm() {
const cardNumberRef = useRef(null);
const expiryRef = useRef(null);
const cvcRef = useRef(null);
return (
<form>
<div>
<label>Card Number</label>
<CardNumberElement ref={cardNumberRef} />
</div>
<div style={{ display: "flex", gap: "1rem" }}>
<div style={{ flex: 1 }}>
<label>Expiry</label>
<CardExpirationDateElement ref={expiryRef} />
</div>
<div style={{ flex: 1 }}>
<label>CVC</label>
<CardVerificationCodeElement ref={cvcRef} />
</div>
</div>
</form>
);
}
TextElement
Used for bank account numbers, routing numbers, and other text inputs that need to be tokenized.
Usage
import { TextElement } from "@easylabs/react";
import { useRef } from "react";
function BankAccountForm() {
const routingRef = useRef(null);
const accountRef = useRef(null);
return (
<form>
<div>
<label>Routing Number</label>
<TextElement
ref={routingRef}
placeholder="123456789"
mask={[/\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/]}
/>
</div>
<div>
<label>Account Number</label>
<TextElement ref={accountRef} placeholder="0123456789" />
</div>
</form>
);
}
Props
ref(required) - React ref to access the elementplaceholder- Placeholder textmask- Input mask patterndisabled- Disable inputreadOnly- Make input read-only
Styling Elements
All elements accept a style prop with nested objects for different states:
const elementStyle = {
base: {
fontSize: "16px",
color: "#424770",
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: "antialiased",
"::placeholder": {
color: "#aab7c4",
},
},
invalid: {
color: "#9e2146",
},
complete: {
color: "#28a745",
},
};
<CardElement ref={cardRef} style={elementStyle} />;
Style Properties
base- Default stylesinvalid- Styles when validation failscomplete- Styles when input is complete
Supported CSS properties:
colorfontSizefontFamilyfontSmoothingfontWeightletterSpacingtextDecoration
Using with Checkout
Form elements are used with the checkout method:
import { useEasy, CardElement } from "@easylabs/react";
import { useRef } from "react";
function PaymentForm() {
const { checkout } = useEasy();
const cardRef = useRef(null);
const handleSubmit = async (e) => {
e.preventDefault();
const result = await checkout({
customer_creation: true,
customer_details: {
first_name: "John",
last_name: "Doe",
email: "[email protected]",
},
source: {
type: "PAYMENT_CARD",
cardElement: cardRef, // Pass the ref
name: "Primary Card",
},
line_items: [{ price_id: "price_123", quantity: 1 }],
});
};
return (
<form onSubmit={handleSubmit}>
<CardElement ref={cardRef} />
<button type="submit">Pay</button>
</form>
);
}
Security
PCI Compliance
These secure form elements are PCI-compliant by design. Your application never has access to raw card data, ensuring you don't need to worry about PCI compliance requirements.
- ✅ Card data never touches your servers
- ✅ Data is tokenized before transmission
- ✅ Secure iframes isolate sensitive data
- ✅ Automatic validation and formatting
Best Practices
- Always use refs: Elements must be accessed via React refs
- Style appropriately: Match your application's design
- Provide labels: Ensure accessibility with proper labels
- Handle errors: Show validation errors to users
- Test thoroughly: Use test card numbers in development