Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
DRY and RequiredErrorMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
pelusanchez committed Dec 26, 2023
1 parent 447e82f commit bec2abd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/widgets/RequiredErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import { Error } from './Widget'

export const RequiredErrorMessage = () => {
return (
<Error data-error='required'>At least one selection must be made</Error>
)
}
6 changes: 3 additions & 3 deletions src/widgets/StringChoiceWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import {
ReservedSpace,
WidgetActionsWrapper,
WidgetHeader,
WidgetTitle,
Error
WidgetTitle
} from './Widget'

import { isDisabled, useBypassRequired } from '../utils'
import { RequiredErrorMessage } from './RequiredErrorMessage'

export interface StringChoiceWidgetDetails {
columns: number
Expand Down Expand Up @@ -175,7 +175,7 @@ const StringChoiceWidget = ({
</WidgetHeader>
<ReservedSpace data-stylizable='widget string-choice reserved-error-space'>
{!bypassed && required && !selection?.length ? (
<Error>At least one selection must be made</Error>
<RequiredErrorMessage />
) : null}
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/StringListArrayWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
WidgetActionsWrapper,
WidgetHeader,
WidgetTitle,
Error,
ReservedSpace
} from './Widget'

Expand All @@ -34,6 +33,7 @@ import {
useBypassRequired,
useWidgetSelection
} from '../utils'
import { RequiredErrorMessage } from './RequiredErrorMessage'

declare global {
interface Set<T> {
Expand Down Expand Up @@ -431,7 +431,7 @@ const StringListArrayWidget = ({
</WidgetHeader>
<ReservedSpace data-stylizable='widget string-listarray reserved-error-space'>
{!bypassed && required && !selection[name]?.length ? (
<Error>At least one selection must be made</Error>
<RequiredErrorMessage />
) : null}
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/StringListWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
WidgetActionsWrapper,
WidgetHeader,
WidgetTitle,
Error,
ReservedSpace
} from './Widget'

Expand All @@ -30,6 +29,7 @@ import {
useBypassRequired,
useWidgetSelection
} from '../utils'
import { RequiredErrorMessage } from './RequiredErrorMessage'

declare global {
interface Set<T> {
Expand Down Expand Up @@ -189,7 +189,7 @@ const StringListWidget = ({
</WidgetHeader>
<ReservedSpace>
{!bypassed && required && !selection[name]?.length ? (
<Error>At least one selection must be made</Error>
<RequiredErrorMessage />
) : null}
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
Expand Down

0 comments on commit bec2abd

Please sign in to comment.