FAQ Block
The FAQ Component is a fully customizable and accessible FAQ accordion built with React and TypeScript. It provides a complete frequently asked questions interface with modern design patterns, expandable/collapsible sections, and flexible customization options.
π Installationβ
npm install @nodeblocks/frontend-faq-block
π Usageβ
import {FAQ} from '@nodeblocks/frontend-faq-block';
- Basic Usage
- Advanced Usage
function BasicFAQ() { const faqItems = [ { question: "What is this service?", answer: "This is a comprehensive platform designed to help you manage your business operations efficiently." }, { question: "How do I get started?", answer: "Simply sign up for an account, complete your profile, and you can start using all the features immediately." }, { question: "Is there a free trial?", answer: "Yes, we offer a 14-day free trial with full access to all features. No credit card required." }, { question: "How can I contact support?", answer: "You can reach our support team through email, live chat, or by calling our support hotline during business hours." } ]; return ( <FAQ faqTitle="Frequently Asked Questions" subtitle="Find answers to the most common questions about our service" items={faqItems}> <FAQ.Title /> <FAQ.ItemList /> </FAQ> ); }
function AdvancedFAQ() { const faqItems = [ { question: "What makes our platform unique?", answer: "Our platform combines AI-powered analytics with intuitive design to deliver unparalleled business insights and automation capabilities." }, { question: "Do you offer enterprise solutions?", answer: "Yes, we provide customized enterprise solutions with dedicated support, advanced security features, and scalable infrastructure." }, { question: "How secure is your platform?", answer: "We implement bank-level encryption, multi-factor authentication, and comply with industry standards including SOC 2 Type II and GDPR." }, { question: "What integrations are available?", answer: "We integrate with 200+ popular business tools including Slack, Salesforce, HubSpot, Google Workspace, and Microsoft 365." } ]; return ( <FAQ faqTitle="Enterprise Solutions" subtitle="Comprehensive answers for business decision makers" items={faqItems} className="custom-faq" style={{ backgroundColor: '#f8f9fa', border: '1px solid #e9ecef', borderRadius: '12px', padding: '32px', maxWidth: '800px', margin: '0 auto' }}> {({ defaultBlocks, defaultBlockOrder }) => ({ blocks: { ...defaultBlocks, // π― Custom title with enhanced styling title: { ...defaultBlocks.title, props: { ...defaultBlocks.title.props, className: 'custom-title', style: { background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', color: 'white', padding: '24px', borderRadius: '8px', marginBottom: '32px', boxShadow: '0 4px 12px rgba(0,0,0,0.15)', }, }, }, // π Custom stats section stats: ( <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))', gap: '16px', marginBottom: '32px', padding: '20px', backgroundColor: '#e3f2fd', borderRadius: '8px', border: '1px solid #bbdefb', }}> <div style={{ textAlign: 'center' }}> <div style={{ fontSize: '24px', fontWeight: 'bold', color: '#1976d2' }}>99.9%</div> <div style={{ fontSize: '14px', color: '#666' }}>Uptime</div> </div> <div style={{ textAlign: 'center' }}> <div style={{ fontSize: '24px', fontWeight: 'bold', color: '#1976d2' }}>24/7</div> <div style={{ fontSize: '14px', color: '#666' }}>Support</div> </div> <div style={{ textAlign: 'center' }}> <div style={{ fontSize: '24px', fontWeight: 'bold', color: '#1976d2' }}>200+</div> <div style={{ fontSize: '14px', color: '#666' }}>Integrations</div> </div> </div> ), // π¬ Custom FAQ item list with enhanced styling itemList: { ...defaultBlocks.itemList, props: { ...defaultBlocks.itemList.props, className: 'custom-item-list', style: { backgroundColor: 'white', borderRadius: '8px', padding: '16px', boxShadow: '0 2px 8px rgba(0,0,0,0.1)', }, }, }, // π Custom help section helpSection: ( <div style={{ marginTop: '32px', padding: '24px', backgroundColor: '#fff3e0', borderRadius: '8px', border: '1px solid #ffcc02', textAlign: 'center', }}> <h3 style={{ margin: '0 0 16px 0', color: '#f57c00', fontSize: '20px', fontWeight: 'bold' }}> π€ Need More Help? </h3> <p style={{ margin: '0 0 20px 0', color: '#666', lineHeight: '1.6' }}> Our expert team is ready to help you get the most out of our platform. </p> <div style={{ display: 'flex', justifyContent: 'center', gap: '16px' }}> <button style={{ padding: '12px 24px', backgroundColor: '#2196f3', color: 'white', border: 'none', borderRadius: '6px', cursor: 'pointer', fontWeight: 'bold', }}> π Schedule Demo </button> <button style={{ padding: '12px 24px', backgroundColor: '#4caf50', color: 'white', border: 'none', borderRadius: '6px', cursor: 'pointer', fontWeight: 'bold', }}> π¬ Live Chat </button> </div> </div> ), }, blockOrder: ['title', 'stats', 'itemList', 'helpSection'], })} </FAQ> ); }
π§ Props Referenceβ
Main Component Propsβ
Prop | Type | Default | Description |
---|---|---|---|
faqTitle | ReactNode | Required | The main title displayed at the top of the FAQ section |
subtitle | ReactNode | Required | The subtitle or description displayed below the main title |
items | Array<{question: string, answer: string}> | Required | Array of FAQ items, each containing a question and answer |
className | string | undefined | Additional CSS class name for styling the FAQ container |
children | BlocksOverride | undefined | Custom block components to override default rendering |
Note: The main component inherits all HTML div
element props.
Sub-Componentsβ
The FAQ component provides several sub-components. All sub-components receive their default values from the main component's context and can override these values through props.
FAQ.Titleβ
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | Context faqTitle | Content to display as the main title (overrides context faqTitle) |
subtitle | string | Context subtitle | Subtitle text to display (overrides context subtitle) |
Note: This component inherits all HTML div
element props.
FAQ.Itemβ
Prop | Type | Default | Description |
---|---|---|---|
question | string | Required | The question text to display in the accordion header |
answer | string | Required | The answer text to display when the accordion is expanded |
index | number | Required | The index of this item in the FAQ list |
isActive | boolean | Required | Whether this accordion item is currently expanded |
onToggle | (index: number) => void | Required | Callback function to toggle the accordion state |
Note: This component inherits all HTML div
element props.
FAQ.ItemListβ
Prop | Type | Default | Description |
---|---|---|---|
subtitle | string | Context subtitle | Subtitle text to display (overrides context subtitle) |
Note: This component inherits all HTML div
element props. Renders a list of FAQ.Item
components.
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {FAQ} from '@nodeblocks/frontend-faq-block';
import {ComponentProps, ReactNode} from 'react';
// Individual FAQ item interface
interface FAQItem {
question: string;
answer: string;
}
// Main component interface
interface FAQProps extends Omit<ComponentProps<'div'>, 'children'> {
faqTitle: ReactNode;
subtitle: ReactNode;
items: FAQItem[];
className?: string;
}
// Example usage with custom data
const faqData: FAQItem[] = [
{
question: 'What payment methods do you accept?',
answer: 'We accept all major credit cards, PayPal, and bank transfers.',
},
{
question: 'How do I cancel my subscription?',
answer: 'You can cancel your subscription anytime from your account settings.',
},
];
// Advanced example with custom styling
function CustomFAQ() {
return (
<FAQ
faqTitle="Customer Support"
subtitle="Get quick answers to common questions"
items={faqData}
className="my-custom-faq">
<FAQ.Title className="custom-title" subtitle="We're here to help you succeed">
πββοΈ Frequently Asked Questions
</FAQ.Title>
<FAQ.ItemList className="custom-item-list" />
</FAQ>
);
}
Built with β€οΈ using React, TypeScript, and modern web standards.