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. Built on top of MUI components for consistent styling.
π Installationβ
npm install @nodeblocks/frontend-faq-block@0.2.0
π Usageβ
import {FAQ} from '@nodeblocks/frontend-faq-block';
- Basic Usage
- Advanced Usage
function SimpleFAQ() { 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" sx={{ backgroundColor: '#f8f9fa', border: '1px solid #e9ecef', borderRadius: '12px', padding: '32px', maxWidth: '800px', margin: '0 auto', }} > {({defaultBlocks}) => ({ blocks: { ...defaultBlocks, 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> ), 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 |
sx | SxProps<Theme> | { px: 2, py: 5 } | MUI system props for custom styling |
children | BlocksOverride | undefined | Custom block components to override default rendering |
Note: This component inherits all MUI Stack component props. Default spacing={5}.
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β
Renders the FAQ title section using MUI Stack and Typography components.
| Prop | Type | Default | Description |
|---|---|---|---|
faqTitle | ReactNode | Context value | Title content (overrides context) |
subtitle | ReactNode | Context value | Subtitle content (overrides context) |
children | ReactNode | Context faqTitle | Custom content - overrides faqTitle |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | { textAlign: 'center' } | MUI system props for custom styling |
Note: This component inherits all MUI Stack component props. The title is rendered with Typography variant="h6" and color="primary.main". The subtitle is rendered with Typography variant="h4". Internal spacing between title and subtitle is hardcoded to 1.
FAQ.Itemβ
Renders an individual FAQ accordion item using MUI Accordion.
| 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 |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | undefined | MUI system props for custom styling |
Note: This component inherits all MUI Accordion component props (except onToggle). The question displays with a "Q." prefix in primary.main color.
FAQ.ItemListβ
Renders the list of FAQ items with dividers using MUI Stack.
| Prop | Type | Default | Description |
|---|---|---|---|
items | Array<{question: string, answer: string}> | Context value | FAQ items array (overrides context) |
activeIndex | number | null | Context value | Currently active/expanded item index (overrides context) |
toggleAccordion | (index: number) => void | Context value | Toggle callback (overrides context) |
className | string | undefined | Additional CSS class name for styling |
sx | SxProps<Theme> | undefined | MUI system props for custom styling |
Note: This component inherits all MUI Stack component props. Renders a Divider before and after the item list.
π¨ Configuration examplesβ
Custom Title Stylingβ
<FAQ.Title
sx={{
textAlign: 'left',
backgroundColor: 'primary.light',
p: 3,
borderRadius: 2
}}>
Custom FAQ Title
</FAQ.Title>
Custom Item List Stylingβ
<FAQ.ItemList
sx={{
backgroundColor: 'background.paper',
borderRadius: 2,
boxShadow: 1,
p: 2
}}
/>
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {FAQ} from '@nodeblocks/frontend-faq-block';
import {StackProps, AccordionProps} from '@mui/material';
import {ReactNode} from 'react';
// Individual FAQ item interface
interface FAQItem {
question: string;
answer: string;
}
// Main component props extend MUI StackProps
interface FAQProps extends Omit<StackProps, 'children'> {
faqTitle: ReactNode;
subtitle: ReactNode;
items: FAQItem[];
children?: BlocksOverride;
}
// Example with MUI styling
function CustomStyledFAQ() {
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.',
},
];
return (
<FAQ
faqTitle="Customer Support"
subtitle="Get quick answers to common questions"
items={faqData}
className="my-custom-faq"
spacing={4}
sx={{maxWidth: 800, mx: 'auto'}}
>
<FAQ.Title sx={{textAlign: 'left'}}>πββοΈ Frequently Asked Questions</FAQ.Title>
<FAQ.ItemList sx={{mt: 2}} />
</FAQ>
);
}
π Notesβ
- The component uses MUI's
Stackfor layout with defaultspacing={5} - Default padding is
px: 2(horizontal) andpy: 5(vertical) - FAQ items use MUI
AccordionwithExpandMoreicon - The title section displays the main title with
variant="h6"inprimary.maincolor - The subtitle displays with
variant="h4" - Questions are prefixed with "Q." in
primary.maincolor with bold styling Dividercomponents are rendered before and after the FAQ item list- Only one accordion item can be expanded at a time (controlled by
activeIndexstate) - All sub-components support the
sxprop for MUI system styling - Block override pattern allows inserting custom blocks between default blocks
Built with β€οΈ using React, TypeScript, and MUI.