Settings Block
The Settings Component is a fully customizable and accessible settings interface built with React and TypeScript. It provides a complete settings menu with modern design patterns, flexible customization options, and a clean hierarchical structure for organizing settings items.
π Installationβ
npm install @nodeblocks/frontend-settings-block
π Usageβ
import {Settings} from '@nodeblocks/frontend-settings-block';
- Basic Usage
- Advanced Usage
function BasicSettings() { const settingsItems = [ { icon: 'person' as const, title: 'Profile Settings', onClick: () => console.log('Profile clicked'), }, { icon: 'lock' as const, title: 'Security', onClick: () => console.log('Security clicked'), }, { icon: 'notifications' as const, title: 'Notifications', onClick: () => console.log('Notifications clicked'), }, ]; return ( <Settings settingsTitle="Account Settings" items={settingsItems}> <Settings.Title>My Settings</Settings.Title> <Settings.SettingsRows /> </Settings> ); }
function AdvancedSettings() { const settingsItems = [ { icon: 'person' as const, title: 'Profile Settings', onClick: () => console.log('Profile clicked'), }, { icon: 'lock' as const, title: 'Security', onClick: () => console.log('Security clicked'), }, { icon: 'notifications' as const, title: 'Notifications', onClick: () => console.log('Notifications clicked'), }, ]; return ( <Settings settingsTitle="Account Settings" items={settingsItems}> {({ defaultBlocks, defaultBlockOrder }) => ({ blocks: { ...defaultBlocks, // π Custom Title with props override title: { ...defaultBlocks.title, props: { ...defaultBlocks.title.props, className: "custom-settings-title", style: { background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent', fontSize: '2rem', fontWeight: 'bold', textAlign: 'center', marginBottom: '30px', padding: '20px' }, children: "βοΈ Advanced Settings Dashboard" }, }, // ποΈ Rich Settings Rows with full component override settingsRows: ( <div style={{ display: 'grid', gap: '20px', maxWidth: '600px', margin: '0 auto' }}> {/* Account Section */} <div style={{ backgroundColor: '#f8f9fa', borderRadius: '16px', padding: '20px', border: '1px solid #e9ecef' }}> <h3 style={{ color: '#495057', fontSize: '1.1rem', fontWeight: '600', marginBottom: '15px', display: 'flex', alignItems: 'center', gap: '8px' }}> π€ Account Management </h3> <div style={{ display: 'grid', gap: '12px' }}> {[ { icon: 'π', title: 'Edit Profile', description: 'Update your information', color: '#007bff' }, { icon: 'π', title: 'Change Password', description: 'Secure your account', color: '#28a745' }, { icon: 'π±', title: 'Two-Factor Auth', description: 'Additional security', color: '#17a2b8' } ].map((item, index) => ( <button key={index} style={{ backgroundColor: 'white', border: `2px solid ${item.color}20`, borderRadius: '12px', padding: '16px', display: 'flex', alignItems: 'center', gap: '15px', cursor: 'pointer', transition: 'all 0.3s ease', textAlign: 'left' }} onMouseEnter={(e) => { e.currentTarget.style.backgroundColor = item.color; e.currentTarget.style.borderColor = item.color; e.currentTarget.style.color = 'white'; e.currentTarget.style.transform = 'translateX(10px)'; }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = 'white'; e.currentTarget.style.borderColor = `${item.color}20`; e.currentTarget.style.color = 'black'; e.currentTarget.style.transform = 'translateX(0)'; }} > <div style={{ fontSize: '1.5rem' }}>{item.icon}</div> <div style={{ flex: 1 }}> <div style={{ fontWeight: '600', marginBottom: '4px' }}>{item.title}</div> <div style={{ fontSize: '0.85rem', opacity: 0.8 }}>{item.description}</div> </div> <div style={{ fontSize: '1.2rem', opacity: 0.6 }}>β</div> </button> ))} </div> </div> {/* Preferences Section */} <div style={{ backgroundColor: '#fff3cd', borderRadius: '16px', padding: '20px', border: '1px solid #ffeaa7' }}> <h3 style={{ color: '#856404', fontSize: '1.1rem', fontWeight: '600', marginBottom: '15px', display: 'flex', alignItems: 'center', gap: '8px' }}> π¨ Preferences </h3> <div style={{ display: 'grid', gap: '12px' }}> {[ { icon: 'π', title: 'Notifications', description: 'Manage alert preferences', color: '#ffc107' }, { icon: 'π', title: 'Dark Mode', description: 'Toggle theme settings', color: '#6c757d' }, { icon: 'π', title: 'Language', description: 'Select your language', color: '#fd7e14' } ].map((item, index) => ( <button key={index} style={{ backgroundColor: 'white', border: `2px solid ${item.color}20`, borderRadius: '12px', padding: '16px', display: 'flex', alignItems: 'center', gap: '15px', cursor: 'pointer', transition: 'all 0.3s ease', textAlign: 'left' }} onMouseEnter={(e) => { e.currentTarget.style.backgroundColor = item.color; e.currentTarget.style.borderColor = item.color; e.currentTarget.style.color = 'white'; e.currentTarget.style.transform = 'scale(1.02)'; }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = 'white'; e.currentTarget.style.borderColor = `${item.color}20`; e.currentTarget.style.color = 'black'; e.currentTarget.style.transform = 'scale(1)'; }} > <div style={{ fontSize: '1.5rem' }}>{item.icon}</div> <div style={{ flex: 1 }}> <div style={{ fontWeight: '600', marginBottom: '4px' }}>{item.title}</div> <div style={{ fontSize: '0.85rem', opacity: 0.8 }}>{item.description}</div> </div> <div style={{ fontSize: '1.2rem', opacity: 0.6 }}>βοΈ</div> </button> ))} </div> </div> {/* Quick Actions */} <div style={{ backgroundColor: '#d1ecf1', borderRadius: '16px', padding: '20px', border: '1px solid #bee5eb' }}> <h3 style={{ color: '#0c5460', fontSize: '1.1rem', fontWeight: '600', marginBottom: '15px', display: 'flex', alignItems: 'center', gap: '8px' }}> β‘ Quick Actions </h3> <div style={{ display: 'flex', gap: '12px', flexWrap: 'wrap' }}> {[ { icon: 'π', title: 'Analytics', color: '#17a2b8' }, { icon: 'π', title: 'Export Data', color: '#6c757d' }, { icon: 'ποΈ', title: 'Delete Account', color: '#dc3545' } ].map((item, index) => ( <button key={index} style={{ backgroundColor: 'white', border: `2px solid ${item.color}`, borderRadius: '25px', padding: '12px 20px', display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer', transition: 'all 0.3s ease', fontSize: '0.9rem', fontWeight: '500' }} onMouseEnter={(e) => { e.currentTarget.style.backgroundColor = item.color; e.currentTarget.style.color = 'white'; e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = `0 4px 15px ${item.color}40`; }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = 'white'; e.currentTarget.style.color = 'black'; e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = 'none'; }} > <span style={{ fontSize: '1.1rem' }}>{item.icon}</span> {item.title} </button> ))} </div> </div> </div> ), }, blockOrder: defaultBlockOrder, })} </Settings> ); }
π§ Props Referenceβ
Main Component Propsβ
Prop | Type | Default | Description |
---|---|---|---|
settingsTitle | string | Required | Title for the settings section used in context and default title rendering |
items | SettingsItem[] | Required | Array of settings items to be displayed |
className | string | undefined | Additional CSS class name for styling the settings container |
children | BlocksOverride | undefined | Custom block components to override default rendering |
Note: This component inherits all props from the HTML div
element.
Sub-Componentsβ
The Settings 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.
Settings.Titleβ
Prop | Type | Default | Description |
---|---|---|---|
children | ReactNode | settingsTitle from context | Title content - falls back to settingsTitle if not provided |
className | string | undefined | Additional CSS class name for styling the title |
Note: This component inherits all standard HTML h4
element props.
Settings.SettingsRowβ
Prop | Type | Default | Description |
---|---|---|---|
icon | IconType | Required | Icon to display on the left side of the settings row |
onClick | () => void | Required | Function to handle row click interactions |
children | ReactNode | undefined | Content to display as the settings row text |
Note: This component inherits all standard HTML div
element props.
Settings.SettingsRowsβ
Prop | Type | Default | Description |
---|---|---|---|
items | SettingsItem[] | Items from context | Array of settings items to render - falls back to context items if not provided |
children | ReactNode | Auto-generated rows | Custom content to override default settings rows rendering |
className | string | undefined | Additional CSS class name for styling the rows container |
Note: This component inherits all standard HTML div
element props.
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {Settings} from '@nodeblocks/frontend-settings-block';
// Settings item structure
interface SettingsItem {
icon: ComponentProps<typeof Settings.SettingsRow>['icon'];
title: string;
onClick: () => void;
}
// Custom settings with additional functionality
interface CustomSettingsProps {
settingsTitle: string;
items: SettingsItem[];
onSettingClick?: (item: SettingsItem) => void;
}
const MySettingsPanel = () => {
const handleProfileSettings = () => {
console.log('Opening profile settings');
// Navigate to profile settings
};
const handleSecuritySettings = () => {
console.log('Opening security settings');
// Navigate to security settings
};
const settingsItems: SettingsItem[] = [
{
icon: 'person',
title: 'Profile Information',
onClick: handleProfileSettings
},
{
icon: 'lock',
title: 'Privacy & Security',
onClick: handleSecuritySettings
},
{
icon: 'notifications',
title: 'Notification Preferences',
onClick: () => console.log('Notifications')
}
];
return (
<Settings
settingsTitle="Account Settings"
items={settingsItems}
className="custom-settings-container">
<Settings.Title className="custom-title">
Manage Your Account
</Settings.Title>
<Settings.SettingsRows className="custom-rows" />
</Settings>
);
};
// Custom settings rows with individual control
const CustomSettingsExample = () => {
return (
<Settings
settingsTitle="Advanced Settings"
items={[]}>
<Settings.Title>Custom Settings</Settings.Title>
<div className="custom-settings-section">
<Settings.SettingsRow
icon="person"
onClick={() => console.log('Custom profile action')}>
Profile Management
</Settings.SettingsRow>
<Settings.SettingsRow
icon="notifications"
onClick={() => console.log('Custom preferences action')}>
Application Preferences
</Settings.SettingsRow>
</div>
</Settings>
);
};
Built with β€οΈ using React, TypeScript, and modern web standards.