Skip to content

Commit 228172a

Browse files
committed
Added docs to form elements folder
1 parent c8ed5bb commit 228172a

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

frontend/src/components/FormElements/FormElements.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ type InputType = React.DetailedHTMLProps<
3434
HTMLInputElement
3535
>;
3636

37+
/**
38+
* Styled input component
39+
*
40+
* Auto applies type-specific styles (like textInput or emailInput)
41+
*/
3742
export const Input = React.forwardRef<HTMLInputElement, InputType>(
3843
({ type, className, ...props }, ref) => (
3944
<input
@@ -56,6 +61,13 @@ type ButtonProps = {
5661
disabled?: boolean;
5762
};
5863

64+
/**
65+
* Reusable button component with size + style variants
66+
*
67+
* - 'outline' switches between primary and secondary styles
68+
* - 'small' turns on compact sizing
69+
* - click handler is disabled automatically when 'disabled is true
70+
*/
5971
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
6072
(props, ref) => {
6173
const {

frontend/src/components/FormElements/SearchAndFilter.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export default function SearchAndFilter<T extends Record<string, any>>({
2929
const [isFilterOpen, setIsFilterOpen] = useState(false);
3030
const [activeSection, setActiveSection] = useState<string | null>(null);
3131

32+
/**
33+
* Handles changes to the search input.
34+
* Applies search and currently active filters in real time.
35+
*/
36+
3237
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
3338
const newSearchTerm = e.target.value;
3439
setSearchTerm(newSearchTerm);
@@ -75,6 +80,10 @@ export default function SearchAndFilter<T extends Record<string, any>>({
7580
onFilterApply(searchFilteredItems);
7681
};
7782

83+
/**
84+
* Toggles a filter value on or off for a given field.
85+
* Updates pending filters only.
86+
*/
7887
const toggleFilter = (field: string, value: string) => {
7988
setPendingFilters((prevFilters) => {
8089
const updatedFilters = { ...prevFilters };
@@ -94,10 +103,17 @@ export default function SearchAndFilter<T extends Record<string, any>>({
94103
});
95104
};
96105

106+
/**
107+
* Returns the total number of active filter values.
108+
*/
97109
const getActiveFilterCount = () => {
98110
return Object.values(filters).reduce((acc, curr) => acc + curr.length, 0);
99111
};
100112

113+
/**
114+
* Clears all applied and pending filters.
115+
* Keeps the current search term active.
116+
*/
101117
const clearFilters = () => {
102118
setPendingFilters({});
103119
setFilters({});
@@ -115,6 +131,9 @@ export default function SearchAndFilter<T extends Record<string, any>>({
115131
onFilterApply(searchFilteredItems);
116132
};
117133

134+
/**
135+
* Applies pending filters and updates the result set.
136+
*/
118137
const applyFilters = () => {
119138
setFilters(pendingFilters);
120139

@@ -159,6 +178,10 @@ export default function SearchAndFilter<T extends Record<string, any>>({
159178
setIsFilterOpen(false);
160179
};
161180

181+
/**
182+
* Resets search input and all filters.
183+
* Restores the full item list.
184+
*/
162185
const clearAll = () => {
163186
setSearchTerm('');
164187
setFilters({});

0 commit comments

Comments
 (0)