Skip to content

Commit

Permalink
chore: simplify classname structure on formik switch field
Browse files Browse the repository at this point in the history
  • Loading branch information
sjschlapbach committed Jul 17, 2024
1 parent 5af469d commit ad0537f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { Tooltip } from './Tooltip'
import Label from './forms/Label'

export interface SwitchClassName {
override?: string
thumbOverride?: string
root?: string
element?: string
thumb?: string
Expand Down Expand Up @@ -112,7 +110,6 @@ export function Switch({
data-test={data?.test}
checked={checked}
className={twMerge(
className?.override,
'relative rounded-full border-0 bg-uzh-grey-80',
disabled && 'cursor-not-allowed bg-uzh-grey-40',
checked && 'bg-primary-60',
Expand All @@ -127,7 +124,6 @@ export function Switch({
>
<RadixSwitch.Thumb
className={twMerge(
className?.thumbOverride,
'block rounded-full bg-white transition-transform',
typeof checked === 'undefined' &&
transitionSizeUndefined[size || 'md'],
Expand Down
33 changes: 15 additions & 18 deletions src/forms/NewFormikSwitchField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useField } from 'formik'
import React from 'react'
import { twMerge } from 'tailwind-merge'
import Switch, { SwitchClassName } from '../Switch'

export interface NewFormikSwitchFieldProps {
Expand Down Expand Up @@ -53,23 +52,21 @@ export function NewFormikSwitchField({
const [field, meta, helpers] = useField(name)

return (
<div className={twMerge('w-full', className?.root)}>
<Switch
id={id}
required={required}
checked={field.value}
onCheckedChange={(newValue) => helpers.setValue(newValue)}
onBlur={() => helpers.setTouched(true)}
data={data}
disabled={disabled}
label={label}
tooltip={tooltip}
size={size}
error={!!meta.error && meta.touched ? meta.error : error}
hideError={hideError}
className={className}
/>
</div>
<Switch
id={id}
required={required}
checked={field.value}
onCheckedChange={(newValue) => helpers.setValue(newValue)}
onBlur={() => helpers.setTouched(true)}
data={data}
disabled={disabled}
label={label}
tooltip={tooltip}
size={size}
error={!!meta.error && meta.touched ? meta.error : error}
hideError={hideError}
className={className}
/>
)
}

Expand Down

0 comments on commit ad0537f

Please sign in to comment.