Skip to main content

๐Ÿ“‹ Component Documentation Template

Use this template when documenting React components for the Idling.app project.

๐Ÿ“ Template Instructionsโ€‹

  1. Copy this template to your component documentation location
  2. Replace placeholders with your specific information
  3. Delete this instruction section before publishing
  4. Follow the structure provided below

[ComponentName]

Brief description of the component and its purpose.

๐ŸŽฏ Overviewโ€‹

Purposeโ€‹

Explain what this component does and why it exists.

Key Featuresโ€‹

  • Feature 1: Description of the first key feature
  • Feature 2: Description of the second key feature
  • Feature 3: Description of the third key feature

Component Architectureโ€‹

๐Ÿ“ฆ Installationโ€‹

# If it's a standalone component
npm install @idling/component-name

# Or import from the component library
import { ComponentName } from '@/components/ComponentName';

๐Ÿ”ง Props Interfaceโ€‹

interface ComponentNameProps {
// Required props
id: string;
title: string;

// Optional props
description?: string;
variant?: 'primary' | 'secondary' | 'danger';
size?: 'small' | 'medium' | 'large';
disabled?: boolean;

// Event handlers
onClick?: (event: MouseEvent) => void;
onSubmit?: (data: FormData) => void;

// Children and styling
children?: React.ReactNode;
className?: string;
style?: React.CSSProperties;
}

Props Flow Diagramโ€‹

Prop Descriptionsโ€‹

PropTypeDefaultDescription
idstring-Required. Unique identifier for the component
titlestring-Required. Display title for the component
descriptionstringundefinedOptional description text
variant'primary' | 'secondary' | 'danger''primary'Visual variant of the component
size'small' | 'medium' | 'large''medium'Size variant of the component
disabledbooleanfalseWhether the component is disabled
onClick(event: MouseEvent) => voidundefinedClick event handler
onSubmit(data: FormData) => voidundefinedSubmit event handler
childrenReact.ReactNodeundefinedChild components or content
classNamestringundefinedAdditional CSS classes
styleReact.CSSPropertiesundefinedInline styles

๐Ÿš€ Usage Examplesโ€‹

Basic Usageโ€‹

import { ComponentName } from '@/components/ComponentName';

function MyPage() {
return (
<ComponentName
id="example-component"
title="Example Component"
description="This is an example component"
/>
);
}

With Event Handlersโ€‹

import { ComponentName } from '@/components/ComponentName';

function InteractiveExample() {
const handleClick = (event: MouseEvent) => {
console.log('Component clicked!', event);
};

const handleSubmit = (data: FormData) => {
console.log('Form submitted:', data);
};

return (
<ComponentName
id="interactive-component"
title="Interactive Component"
variant="primary"
size="large"
onClick={handleClick}
onSubmit={handleSubmit}
/>
);
}

With Childrenโ€‹

import { ComponentName } from '@/components/ComponentName';

function WithChildren() {
return (
<ComponentName id="container-component" title="Container Component">
<p>This is child content</p>
<button>Child Button</button>
</ComponentName>
);
}

All Variantsโ€‹

import { ComponentName } from '@/components/ComponentName';

function AllVariants() {
return (
<div>
<ComponentName
id="primary-component"
title="Primary Variant"
variant="primary"
/>

<ComponentName
id="secondary-component"
title="Secondary Variant"
variant="secondary"
/>

<ComponentName
id="danger-component"
title="Danger Variant"
variant="danger"
/>
</div>
);
}

๐ŸŽจ Styling Guidelinesโ€‹

CSS Classesโ€‹

The component uses the following CSS classes:

/* Base component styles */
.component-name {
/* Base styles */
}

/* Variant styles */
.component-name--primary {
/* Primary variant styles */
}

.component-name--secondary {
/* Secondary variant styles */
}

.component-name--danger {
/* Danger variant styles */
}

/* Size styles */
.component-name--small {
/* Small size styles */
}

.component-name--medium {
/* Medium size styles */
}

.component-name--large {
/* Large size styles */
}

/* State styles */
.component-name--disabled {
/* Disabled state styles */
}

Styling Architectureโ€‹

Theme Integrationโ€‹

The component integrates with the application theme system:

/* CSS Custom Properties */
.component-name {
--component-primary-color: var(--theme-primary);
--component-secondary-color: var(--theme-secondary);
--component-border-radius: var(--theme-border-radius);
--component-spacing: var(--theme-spacing-md);
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
.component-name {
--component-background: var(--theme-dark-bg);
--component-text: var(--theme-dark-text);
}
}

๐Ÿงช Testingโ€‹

Unit Testsโ€‹

import { render, screen, fireEvent } from '@testing-library/react';
import { ComponentName } from './ComponentName';

describe('ComponentName', () => {
test('renders with required props', () => {
render(<ComponentName id="test" title="Test Component" />);
expect(screen.getByText('Test Component')).toBeInTheDocument();
});

test('handles click events', () => {
const handleClick = jest.fn();
render(
<ComponentName id="test" title="Test Component" onClick={handleClick} />
);
fireEvent.click(screen.getByText('Test Component'));
expect(handleClick).toHaveBeenCalledTimes(1);
});

test('applies variant classes', () => {
render(<ComponentName id="test" title="Test" variant="danger" />);
expect(screen.getByText('Test')).toHaveClass('component-name--danger');
});
});

Testing Strategyโ€‹

๐Ÿ“š API Referenceโ€‹

Methodsโ€‹

If the component exposes methods via useImperativeHandle:

interface ComponentNameHandle {
focus: () => void;
reset: () => void;
getValue: () => string;
}

const ComponentName = forwardRef<ComponentNameHandle, ComponentNameProps>(
(props, ref) => {
useImperativeHandle(ref, () => ({
focus: () => {
// Focus implementation
},
reset: () => {
// Reset implementation
},
getValue: () => {
// Get value implementation
return '';
}
}));

return <div>{/* Component JSX */}</div>;
}
);

Hooksโ€‹

If the component provides custom hooks:

// Custom hook for component logic
export function useComponentName(options?: ComponentNameOptions) {
const [state, setState] = useState(initialState);

const handleAction = useCallback(() => {
// Hook logic
}, []);

return {
state,
handleAction
};
}

๐Ÿ“‹ Checklistโ€‹

Before marking this component as complete:

  • All required props are documented
  • Usage examples are provided
  • Styling guidelines are complete
  • Unit tests are written
  • Accessibility requirements are met
  • Documentation is reviewed
  • Component is exported from index

๐Ÿ”„ Changelogโ€‹

Version 1.0.0 (Initial Release)โ€‹

  • Initial component implementation
  • Basic props and styling
  • Unit tests and documentation

Component documentation template. Remove this line and update with actual component information.