Skip to content

Commit

Permalink
chore(forms): refactor Toggle suffix (#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker authored Jun 4, 2024
1 parent 8c3c36f commit 6fba7f9
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions packages/dnb-eufemia/src/extensions/forms/Field/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function Toggle(props: Props) {
disabled,
}

const suffix = help ? (
<HelpButton title={help.title}>{help.content}</HelpButton>
) : undefined

const isOn = value === valueOn
const isOff = value === valueOff

Expand All @@ -103,11 +107,7 @@ function Toggle(props: Props) {
checked={isOn}
disabled={disabled}
status={hasError ? 'error' : undefined}
suffix={
help ? (
<HelpButton title={help.title}>{help.content}</HelpButton>
) : undefined
}
suffix={suffix}
onChange={handleCheckboxChange}
{...htmlAttributes}
/>
Expand All @@ -126,11 +126,7 @@ function Toggle(props: Props) {
checked={isOn}
disabled={disabled}
status={hasError ? 'error' : undefined}
suffix={
help ? (
<HelpButton title={help.title}>{help.content}</HelpButton>
) : undefined
}
suffix={suffix}
value={value ? 'true' : 'false'}
on_change={handleCheckboxChange}
{...htmlAttributes}
Expand All @@ -147,11 +143,7 @@ function Toggle(props: Props) {
onChange: handleToggleChange,
status: hasError ? 'error' : undefined,
disabled,
suffix: help ? (
<HelpButton title={help.title}>
{help.content}
</HelpButton>
) : undefined,
suffix,
}}
>
<ToggleButton
Expand Down Expand Up @@ -182,11 +174,7 @@ function Toggle(props: Props) {
checked={isOn}
disabled={disabled}
status={hasError ? 'error' : undefined}
suffix={
help ? (
<HelpButton title={help.title}>{help.content}</HelpButton>
) : undefined
}
suffix={suffix}
value={value ? 'true' : 'false'}
on_change={handleCheckboxChange}
{...htmlAttributes}
Expand Down

0 comments on commit 6fba7f9

Please sign in to comment.