Skip to content

Commit 30e120f

Browse files
committed
refactor: improve syntax
1 parent 7a5d082 commit 30e120f

File tree

2 files changed

+45
-49
lines changed

2 files changed

+45
-49
lines changed

packages/coreui-react/src/components/form/CFormCheck.tsx

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,21 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
107107
}
108108
}, [indeterminate])
109109

110-
const formControl = () => {
111-
return (
112-
<input
113-
type={type}
114-
className={classNames(button ? 'btn-check' : 'form-check-input', {
115-
'is-invalid': invalid,
116-
'is-valid': valid,
117-
'me-2': hitArea,
118-
})}
119-
id={id}
120-
{...rest}
121-
ref={forkedRef}
122-
/>
123-
)
124-
}
110+
const FormControl = () => (
111+
<input
112+
type={type}
113+
className={classNames(button ? 'btn-check' : 'form-check-input', {
114+
'is-invalid': invalid,
115+
'is-valid': valid,
116+
'me-2': hitArea,
117+
})}
118+
id={id}
119+
{...rest}
120+
ref={forkedRef}
121+
/>
122+
)
125123

126-
const formValidation = () => (
124+
const FormValidation = () => (
127125
<CFormControlValidation
128126
describedby={rest['aria-describedby']}
129127
feedback={feedback}
@@ -136,42 +134,40 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
136134
/>
137135
)
138136

139-
const formLabel = () => {
140-
return (
141-
<CFormLabel
142-
customClassName={classNames(
143-
button
144-
? classNames(
145-
'btn',
146-
button.variant ? `btn-${button.variant}-${button.color}` : `btn-${button.color}`,
147-
{
148-
[`btn-${button.size}`]: button.size,
149-
},
150-
`${button.shape}`,
151-
)
152-
: 'form-check-label',
153-
)}
154-
{...(id && { htmlFor: id })}
155-
>
156-
{label}
157-
</CFormLabel>
158-
)
159-
}
137+
const FormLabel = () => (
138+
<CFormLabel
139+
customClassName={classNames(
140+
button
141+
? classNames(
142+
'btn',
143+
button.variant ? `btn-${button.variant}-${button.color}` : `btn-${button.color}`,
144+
{
145+
[`btn-${button.size}`]: button.size,
146+
},
147+
`${button.shape}`,
148+
)
149+
: 'form-check-label',
150+
)}
151+
{...(id && { htmlFor: id })}
152+
>
153+
{label}
154+
</CFormLabel>
155+
)
160156

161157
return button ? (
162158
<>
163-
{formControl()}
164-
{label && formLabel()}
165-
{formValidation()}
159+
<FormControl />
160+
{label && <FormLabel />}
161+
<FormValidation />
166162
</>
167163
) : label ? (
168164
hitArea ? (
169165
<>
170166
<CFormLabel customClassName={className} {...(id && { htmlFor: id })}>
171-
{formControl()}
167+
<FormControl />
172168
{label}
173169
</CFormLabel>
174-
{formValidation()}
170+
<FormValidation />
175171
</>
176172
) : (
177173
<div
@@ -185,13 +181,13 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
185181
className,
186182
)}
187183
>
188-
{formControl()}
189-
{formLabel()}
190-
{formValidation()}
184+
<FormControl />
185+
<FormLabel />
186+
<FormValidation />
191187
</div>
192188
)
193189
) : (
194-
formControl()
190+
<FormControl />
195191
)
196192
},
197193
)

packages/coreui-react/src/components/form/CFormControlWrapper.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
5656
tooltipFeedback,
5757
valid,
5858
}) => {
59-
const formControlValidation = () => (
59+
const FormControlValidation = () => (
6060
<CFormControlValidation
6161
describedby={describedby}
6262
feedback={feedback}
@@ -73,14 +73,14 @@ export const CFormControlWrapper: FC<CFormControlWrapperProps> = ({
7373
{children}
7474
<CFormLabel htmlFor={id}>{label || floatingLabel}</CFormLabel>
7575
{text && <CFormText id={describedby}>{text}</CFormText>}
76-
{formControlValidation()}
76+
<FormControlValidation />
7777
</CFormFloating>
7878
) : (
7979
<>
8080
{label && <CFormLabel htmlFor={id}>{label}</CFormLabel>}
8181
{children}
8282
{text && <CFormText id={describedby}>{text}</CFormText>}
83-
{formControlValidation()}
83+
<FormControlValidation />
8484
</>
8585
)
8686
}

0 commit comments

Comments
 (0)