Content - goobz22/goobs-frontend GitHub Wiki
Content Component
The Content component in goobs-frontend is a flexible and powerful container for rendering various types of content within your application. It serves as a layout component that can incorporate multiple child components and manage their arrangement and styling.
Importing the Component
To use the Content component in your project, import it from the goobs-frontend package:
import { ContentSection } from 'goobs-frontend';
Basic Usage
Here's a basic example of how to use the Content component:
import React from 'react';
import { ContentSection } from 'goobs-frontend';
const ContentExample: React.FC = () => {
const grids = [
{
grid: {
gridconfig: {
gridname: 'exampleGrid',
alignment: 'center',
gridwidth: '100%',
},
},
typography: [
{
text: 'Welcome to our app!',
fontvariant: 'merrih1',
columnconfig: {
row: 1,
column: 1,
alignment: 'center',
},
},
{
text: 'Explore our features below.',
fontvariant: 'merriparagraph',
columnconfig: {
row: 2,
column: 1,
alignment: 'center',
},
},
],
},
];
return <ContentSection grids={grids} />;
};
export default ContentExample;
Props
The ContentSection component accepts the following props:
grids
: Array<ContentSectionProps['grids'][0]> (required) - An array of grid configurations.width
: number (optional) - The width of the content section in pixels.
Each grid in the grids
array can have the following properties:
grid
: objectgridconfig
: gridconfig - Configuration for the grid layout.
confirmationcodeinput
: ExtendedConfirmationCodeInputsProps | ExtendedConfirmationCodeInputsProps[]typography
: TypographyProps | TypographyProps[]radiogroup
: ExtendedRadioGroupProps | ExtendedRadioGroupProps[]link
: LinkProps | LinkProps[]button
: ExtendedButtonProps | ExtendedButtonProps[]image
: ExtendedImageProps | ExtendedImageProps[]pricing
: ExtendedPricingPropsstepper
: ExtendedStepperProps | ExtendedStepperProps[]transferlist
: ExtendedTransferListProps | ExtendedTransferListProps[]card
: ExtendedCardProps | ExtendedCardProps[]codecopy
: ExtendedCodeCopyProps | ExtendedCodeCopyProps[]textfield
: ExtendedTextFieldProps | ExtendedTextFieldProps[]datefield
: ExtendedDateFieldProps | ExtendedDateFieldProps[]dropdown
: ExtendedDropdownProps | ExtendedDropdownProps[]incrementNumberField
: ExtendedIncrementNumberFieldProps | ExtendedIncrementNumberFieldProps[]searchbar
: ExtendedSearchbarProps | ExtendedSearchbarProps[]numberField
: ExtendedNumberFieldProps | ExtendedNumberFieldProps[]passwordField
: ExtendedPasswordFieldProps | ExtendedPasswordFieldProps[]qrcode
: ExtendedQRCodeProps | ExtendedQRCodeProps[]
Features
- Flexible Layout: The Content component uses a grid system to arrange its child components, allowing for complex and responsive layouts.
- Multiple Component Support: It can render various types of components, including typography, form inputs, buttons, images, and more.
- Customizable Styling: Each component within the Content can be styled individually using the respective props and column configurations.
- Responsive Design: The grid system allows for responsive layouts that can adapt to different screen sizes.
Advanced Usage
Multiple Grids
You can create complex layouts by using multiple grids within a single ContentSection:
import React from 'react';
import { ContentSection } from 'goobs-frontend';
const AdvancedContentExample: React.FC = () => {
const grids = [
{
grid: {
gridconfig: {
gridname: 'headerGrid',
alignment: 'center',
gridwidth: '100%',
},
},
typography: [
{
text: 'Welcome to Our App',
fontvariant: 'merrih1',
columnconfig: {
row: 1,
column: 1,
alignment: 'center',
},
},
],
},
{
grid: {
gridconfig: {
gridname: 'contentGrid',
alignment: 'center',
gridwidth: '100%',
},
},
typography: [
{
text: 'Main Content Area',
fontvariant: 'merrih3',
columnconfig: {
row: 1,
column: 1,
alignment: 'left',
},
},
],
button: [
{
text: 'Click Me',
variant: 'contained',
columnconfig: {
row: 2,
column: 1,
alignment: 'left',
},
},
],
},
{
grid: {
gridconfig: {
gridname: 'footerGrid',
alignment: 'center',
gridwidth: '100%',
},
},
typography: [
{
text: '© 2024 Our Company',
fontvariant: 'merriparagraph',
columnconfig: {
row: 1,
column: 1,
alignment: 'center',
},
},
],
},
];
return <ContentSection grids={grids} />;
};
export default AdvancedContentExample;
Mixing Component Types
You can mix different types of components within a single grid:
import React from 'react';
import { ContentSection } from 'goobs-frontend';
const MixedContentExample: React.FC = () => {
const grids = [
{
grid: {
gridconfig: {
gridname: 'mixedGrid',
alignment: 'center',
gridwidth: '100%',
},
},
typography: [
{
text: 'Sign Up Form',
fontvariant: 'merrih2',
columnconfig: {
row: 1,
column: 1,
alignment: 'center',
},
},
],
textfield: [
{
name: 'email',
label: 'Email',
columnconfig: {
row: 2,
column: 1,
alignment: 'center',
},
},
],
passwordField: [
{
label: 'Password',
columnconfig: {
row: 3,
column: 1,
alignment: 'center',
},
},
],
button: [
{
text: 'Submit',
variant: 'contained',
columnconfig: {
row: 4,
column: 1,
alignment: 'center',
},
},
],
},
];
return <ContentSection grids={grids} />;
};
export default MixedContentExample;
Styling
The Content component relies on the styling of its child components. You can customize the appearance of each child component using their respective props and the columnconfig
object. For overall layout adjustments, you can modify the gridconfig
object.
Here's an example of custom styling:
import React from 'react';
import { ContentSection } from 'goobs-frontend';
const StyledContentExample: React.FC = () => {
const grids = [
{
grid: {
gridconfig: {
gridname: 'styledGrid',
alignment: 'center',
gridwidth: '80%',
margintop: 2,
marginbottom: 2,
},
},
typography: [
{
text: 'Styled Content',
fontvariant: 'merrih2',
fontcolor: '#3f51b5',
columnconfig: {
row: 1,
column: 1,
alignment: 'center',
marginbottom: 2,
},
},
],
button: [
{
text: 'Custom Button',
variant: 'contained',
backgroundcolor: '#f50057',
fontcolor: 'white',
width: '200px',
columnconfig: {
row: 2,
column: 1,
alignment: 'center',
},
},
],
},
];
return <ContentSection grids={grids} />;
};
export default StyledContentExample;
Best Practices
-
Organize Content Logically: Group related content within the same grid for better organization and easier management.
-
Use Consistent Styling: Maintain consistent styling across your content sections for a cohesive user experience.
-
Responsive Design: Utilize the column configuration options to create responsive layouts that work well on different screen sizes.
-
Avoid Overcrowding: Don't try to fit too many components into a single grid. If you have a lot of content, consider using multiple grids or implementing pagination.
-
Accessibility: Ensure that your content is accessible by using appropriate ARIA attributes and maintaining a logical tab order.
-
Performance: For large or complex content sections, consider implementing virtualization or lazy loading to improve performance.
Troubleshooting
-
Components Not Rendering: Ensure that you've properly configured the
columnconfig
for each component, including the correctrow
andcolumn
values. -
Styling Issues: Check the
gridconfig
and individual component configurations. Make sure you're using the correct prop names and values for styling. -
Responsive Layout Problems: Review your
columnconfig
settings, especially themobilewidth
,tabletwidth
, andcomputerwidth
properties, to ensure proper responsiveness. -
TypeScript Errors: If you're using TypeScript and encountering type errors, make sure you're importing and using the correct types for each component's props.
Examples
Form Layout
import React from 'react';
import { ContentSection } from 'goobs-frontend';
const FormExample: React.FC = () => {
const grids = [
{
grid: {
gridconfig: {
gridname: 'formGrid',
alignment: 'center',
gridwidth: '400px',
},
},
typography: [
{
text: 'Contact Us',
fontvariant: 'merrih2',
columnconfig: {
row: 1,
column: 1,
alignment: 'center',
marginbottom: 2,
},
},
],
textfield: [
{
name: 'name',
label: 'Full Name',
columnconfig: {
row: 2,
column: 1,
marginbottom: 1,
},
},
{
name: 'email',
label: 'Email Address',
columnconfig: {
row: 3,
column: 1,
marginbottom: 1,
},
},
],
textarea: [
{
name: 'message',
label: 'Message',
columnconfig: {
row: 4,
column: 1,
marginbottom: 2,
},
},
],
button: [
{
text: 'Submit',
variant: 'contained',
columnconfig: {
row: 5,
column: 1,
alignment: 'center',
},
},
],
},
];
return <ContentSection grids={grids} />;
};
export default FormExample;
Dashboard Layout
import React from 'react';
import { ContentSection } from 'goobs-frontend';
const DashboardExample: React.FC = () => {
const grids = [
{
grid: {
gridconfig: {
gridname: 'dashboardHeader',
alignment: 'space-between',
gridwidth: '100%',
},
},
typography: [
{
text: 'Dashboard',
fontvariant: 'merrih1',
columnconfig: {
row: 1,
column: 1,
},
},
],
button: [
{
text: 'Add New',
variant: 'contained',
columnconfig: {
row: 1,
column: 2,
},
},
],
},
{
grid: {
gridconfig: {
gridname: 'dashboardContent',
alignment: 'center',
gridwidth: '100%',
},
},
card: [
{
title: 'Total Users',
body: '1,234',
width: '200px',
columnconfig: {
row: 1,
column: 1,
marginright: 2,
},
},
{
title: 'Revenue',
body: '$45,678',
width: '200px',
columnconfig: {
row: 1,
column: 2,
marginright: 2,
},
},
{
title: 'Active Projects',
body: '56',
width: '200px',
columnconfig: {
row: 1,
column: 3,
},
},
],
},
{
grid: {
gridconfig: {
gridname: 'dashboardChart',
alignment: 'center',
gridwidth: '100%',
margintop: 2,
},
},
chart: [
{
type: 'line',
data: {/* chart data */},
options: {/* chart options */},
columnconfig: {
row: 1,
column: 1,
},
},
],
},
];
return <ContentSection grids={grids} />;
};
export default DashboardExample;
Performance Considerations
When working with large or complex content sections, consider the following performance optimizations:
-
Lazy Loading: For content that's not immediately visible, implement lazy loading to defer the rendering of off-screen components.
-
Virtualization: For long lists or grids, use virtualization techniques to render only the visible items.
-
Memoization: Use React.memo or useMemo for expensive computations or rendering of child components that don't change frequently.
-
Code Splitting: If your content section includes large or rarely used components, consider using dynamic imports to split your code and reduce the initial bundle size.
Accessibility
To ensure your Content component is accessible:
- Use semantic HTML elements within your custom components.
- Provide appropriate ARIA attributes for interactive elements.
- Ensure proper heading hierarchy (
h1
,h2
, etc.) in your typography components. - Maintain a logical tab order for interactive elements.
- Provide sufficient color contrast for text and important UI elements.
Related Components
- Grid: The underlying component used for layout in ContentSection
- Typography: Used for rendering text content
- Button: For interactive elements within the content
- TextField, DateField, etc.: For form inputs in the content
- Card: For displaying grouped content in a visually distinct container
Future Enhancements
Potential future enhancements for the Content component could include:
- Built-in animation support for transitions between different content states
- More advanced responsive behavior, such as reordering of grid items based on screen size
- Integration with a theming system for easier global style management
- Support for nested grids to allow for more complex layouts
- Built-in pagination or infinite scrolling options for handling large amounts of content
- A visual builder or drag-and-drop interface for easier content layout creation
- Performance optimizations for rendering large numbers of components
- Better TypeScript support with stricter typing for component props
- Enhanced accessibility features, such as automatic ARIA attribute management
- Integration with popular animation libraries for smoother transitions between content states
- Support for dynamic content loading based on user interactions or data fetching
- Built-in SEO optimization features for content that needs to be indexed by search engines
- Improved error handling and debugging tools for complex grid configurations
- Support for custom grid systems beyond the default Material-UI grid
- Integration with state management libraries like Redux or MobX for more dynamic content control
These potential enhancements could further improve the flexibility, performance, and ease of use of the Content component in future versions of goobs-frontend.