From fb860884857da73ee5b5e897745301cdf1d770a2 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Thu, 5 Oct 2023 18:58:30 +0200
Subject: refactor(components): make form components compliant with Eslint
 rules

---
 src/components/molecules/forms/switch/switch.tsx | 55 ++++++++++++++++--------
 1 file changed, 37 insertions(+), 18 deletions(-)

(limited to 'src/components/molecules/forms/switch/switch.tsx')

diff --git a/src/components/molecules/forms/switch/switch.tsx b/src/components/molecules/forms/switch/switch.tsx
index d340a0c..df2ba0c 100644
--- a/src/components/molecules/forms/switch/switch.tsx
+++ b/src/components/molecules/forms/switch/switch.tsx
@@ -1,14 +1,21 @@
-import type { FC, ChangeEventHandler, ReactNode, ReactElement } from 'react';
+import {
+  type FC,
+  type ChangeEventHandler,
+  type ReactNode,
+  type ReactElement,
+  forwardRef,
+  type ForwardRefRenderFunction,
+} from 'react';
 import {
   Fieldset,
   type FieldsetProps,
-  LabelProps,
-  RadioProps,
+  type LabelProps,
+  type RadioProps,
   Label,
   Radio,
 } from '../../../atoms';
+import type { TooltipProps } from '../../tooltip';
 import styles from './switch.module.scss';
-import { TooltipProps } from '../../tooltip';
 
 type SwitchItemProps = Omit<LabelProps, 'children' | 'htmlFor' | 'isRequired'> &
   Pick<RadioProps, 'isDisabled' | 'name'> & {
@@ -94,24 +101,31 @@ export type SwitchProps = Omit<FieldsetProps, 'children'> & {
   value: SwitchOption['value'];
 };
 
-/**
- * Switch component.
- */
-export const Switch: FC<SwitchProps> = ({
-  className = '',
-  isDisabled = false,
-  items,
-  name,
-  onSwitch,
-  tooltip,
-  value,
-  ...props
-}) => {
+const SwitchWithRef: ForwardRefRenderFunction<
+  HTMLFieldSetElement,
+  SwitchProps
+> = (
+  {
+    className = '',
+    isDisabled = false,
+    items,
+    name,
+    onSwitch,
+    tooltip,
+    value,
+    ...props
+  },
+  ref
+) => {
+  const fieldsetClass = `${styles.fieldset} ${className}`;
+
   return (
     <Fieldset
       {...props}
-      className={`${styles.fieldset} ${className}`}
+      className={fieldsetClass}
       isDisabled={isDisabled}
+      ref={ref}
+      // eslint-disable-next-line react/jsx-no-literals -- Role allowed
       role="radiogroup"
     >
       {tooltip}
@@ -130,3 +144,8 @@ export const Switch: FC<SwitchProps> = ({
     </Fieldset>
   );
 };
+
+/**
+ * Switch component.
+ */
+export const Switch = forwardRef(SwitchWithRef);
-- 
cgit v1.2.3

