Example Code Snippets
Here's an example of TypeScript and Tailwind CSS code for a couple of components commonly used in the fintech platform builder:
Transaction History List Component
import React from 'react';
interface Transaction {
id: string;
description: string;
amount: number;
date: string;
}
interface TransactionHistoryProps {
transactions: Transaction[];
}
const TransactionHistory: React.FC<TransactionHistoryProps> = ({ transactions }) => {
return (
<div className="bg-white shadow-md rounded-lg p-4">
<h2 className="text-lg font-semibold mb-4">Transaction History</h2>
<ul>
{transactions.map((transaction) => (
<li key={transaction.id} className="flex justify-between mb-2">
<div>
<p className="text-gray-800">{transaction.description}</p>
<p className="text-gray-500 text-sm">{transaction.date}</p>
</div>
<p className={transaction.amount >= 0 ? 'text-green-600' : 'text-red-600'}>
{transaction.amount >= 0 ? '+' : '-'}
${Math.abs(transaction.amount)}
</p>
</li>
))}
</ul>
</div>
);
};
export default TransactionHistory;
Balance Summary Card Component
import React from 'react';
interface BalanceSummaryProps {
balance: number;
}
const BalanceSummary: React.FC<BalanceSummaryProps> = ({ balance }) => {
return (
<div className="bg-white shadow-md rounded-lg p-4">
<h2 className="text-lg font-semibold mb-4">Balance Summary</h2>
<p className="text-3xl font-semibold text-gray-800">${balance}</p>
<p className="text-gray-500 text-sm">Available Balance</p>
</div>
);
};
export default BalanceSummary;
In the above code examples, TypeScript is used to define the types of the props passed to the components (TransactionHistoryProps
and BalanceSummaryProps
). The components are built using functional components with the help of the React.FC
type. Tailwind CSS classes are applied to the HTML elements using the className
attribute.
To use these components in your fintech platform builder, you can import and render them where appropriate, passing the necessary props:
import React from 'react';
import TransactionHistory from './TransactionHistory';
import BalanceSummary from './BalanceSummary';
const MyFintechPage: React.FC = () => {
const transactions = [
{ id: '1', description: 'Purchase', amount: -25, date: '2023-05-01' },
{ id: '2', description: 'Deposit', amount: 100, date: '2023-04-30' },
{ id: '3', description: 'Withdrawal', amount: -50, date: '2023-04-29' },
];
const balance = 125;
return (
<div>
<TransactionHistory transactions={transactions} />
<BalanceSummary balance={balance} />
</div>
);
};
export default MyFintechPage;
Please note that these code examples demonstrate the structure and usage of the components with TypeScript and Tailwind CSS, but the implementation may vary depending on the specific requirements and design of your fintech platform builder.
Certainly! Here are a few more code snippets for common components in a fintech platform builder:
Payment Form Component
import React, { useState } from 'react';
interface PaymentFormProps {
onSubmit: (amount: number, recipient: string) => void;
}
const PaymentForm: React.FC<PaymentFormProps> = ({ onSubmit }) => {
const [amount, setAmount] = useState(0);
const [recipient, setRecipient] = useState('');
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
onSubmit(amount, recipient);
setAmount(0);
setRecipient('');
};
return (
<form onSubmit={handleSubmit} className="bg-white shadow-md rounded-lg p-4">
<h2 className="text-lg font-semibold mb-4">Payment Form</h2>
<div className="mb-4">
<label htmlFor="amount" className="block text-gray-700 font-semibold mb-1">
Amount
</label>
<input
type="number"
id="amount"
value={amount}
onChange={(e) => setAmount(Number(e.target.value))}
className="border-gray-300 rounded-lg p-2 focus:outline-none focus:ring-2 focus:ring-blue-500 w-full"
/>
</div>
<div className="mb-4">
<label htmlFor="recipient" className="block text-gray-700 font-semibold mb-1">
Recipient
</label>
<input
type="text"
id="recipient"
value={recipient}
onChange={(e) => setRecipient(e.target.value)}
className="border-gray-300 rounded-lg p-2 focus:outline-none focus:ring-2 focus:ring-blue-500 w-full"
/>
</div>
<button type="submit" className="bg-blue-500 text-white rounded-lg px-4 py-2">
Submit Payment
</button>
</form>
);
};
export default PaymentForm;
User Profile Component
import React from 'react';
interface UserProfile {
name: string;
email: string;
phone: string;
avatar: string;
}
interface UserProfileProps {
user: UserProfile;
}
const UserProfile: React.FC<UserProfileProps> = ({ user }) => {
return (
<div className="bg-white shadow-md rounded-lg p-4">
<h2 className="text-lg font-semibold mb-4">User Profile</h2>
<div className="flex items-center mb-4">
<img src={user.avatar} alt="User Avatar" className="w-12 h-12 rounded-full mr-2" />
<div>
<p className="text-gray-800 font-semibold">{user.name}</p>
<p className="text-gray-500 text-sm">{user.email}</p>
</div>
</div>
<p className="text-gray-800">Phone: {user.phone}</p>
</div>
);
};
export default UserProfile;
These code snippets demonstrate a payment form component and a user profile component. The payment form allows users to enter an amount and recipient for making payments, while the user profile component displays basic user information including name, email, phone, and avatar.
Remember to adapt and customize these code snippets according to your specific requirements and design guidelines for the fintech platform builder.
Last updated
Was this helpful?