From 4ab66fdf148171c1daa78d800f085c03fec0f89c Mon Sep 17 00:00:00 2001 From: Ludy Date: Mon, 29 Sep 2025 13:51:42 +0200 Subject: [PATCH] feat(frontend): refactor ToolStep props handling and children usage (#4524) # Description of Changes - Replaced `children` being passed as a prop to `React.createElement` with proper usage as additional arguments (fixes `react/no-children-prop` warning). - Added stricter handling of `isVisible` and `_excludeFromCount` props with improved variable naming (`stepProps`) for clarity. - Refactored JSX structure for collapsed/expanded rendering logic to improve readability. This change was made to clean up prop handling, remove ESLint warnings, and make the component more consistent with React best practices. --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Reece Browne <74901996+reecebrowne@users.noreply.github.com> --- .../src/components/tools/shared/ToolStep.tsx | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/tools/shared/ToolStep.tsx b/frontend/src/components/tools/shared/ToolStep.tsx index 4d9c5a187..b2140eb3f 100644 --- a/frontend/src/components/tools/shared/ToolStep.tsx +++ b/frontend/src/components/tools/shared/ToolStep.tsx @@ -164,13 +164,16 @@ export function createToolSteps() { const isVisible = props.isVisible !== false; const currentStepNumber = isVisible ? stepNumber++ : undefined; - const step = React.createElement(ToolStep, { - ...props, - title, - _stepNumber: currentStepNumber, - children, - key: `step-${title.toLowerCase().replace(/\s+/g, '-')}` - }); + const step = React.createElement( + ToolStep, + { + ...props, + title, + _stepNumber: currentStepNumber, + key: `step-${title.toLowerCase().replace(/\s+/g, '-')}` + }, + children + ); steps.push(step); return step; @@ -186,9 +189,9 @@ export function createToolSteps() { const getVisibleCount = () => { return steps.filter(step => { - const props = step.props as ToolStepProps; - const isVisible = props.isVisible !== false; - const excludeFromCount = props._excludeFromCount === true; + const stepProps = step.props as ToolStepProps; + const isVisible = stepProps.isVisible !== false; + const excludeFromCount = stepProps._excludeFromCount === true; return isVisible && !excludeFromCount; }).length; }; @@ -203,9 +206,9 @@ export function ToolStepProvider({ children, forceStepNumbers }: { children: Rea let count = 0; React.Children.forEach(children, (child) => { if (React.isValidElement(child) && child.type === ToolStep) { - const props = child.props as ToolStepProps; - const isVisible = props.isVisible !== false; - const excludeFromCount = props._excludeFromCount === true; + const stepProps = child.props as ToolStepProps; + const isVisible = stepProps.isVisible !== false; + const excludeFromCount = stepProps._excludeFromCount === true; if (isVisible && !excludeFromCount) count++; } });