Skip to content

Commit

Permalink
fix(input): render default styles conditionally based on input type
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed Aug 9, 2024
1 parent 23550f5 commit 37d2326
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/components/input/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import styles from "./styles/index.module.scss";
import React, {
type ComponentPropsWithRef,
type HTMLInputTypeAttribute,
useEffect,
useMemo,
} from "react";
import defaultStyles from "./styles/default.module.scss";
import { useFormFieldContext, type FormFieldContextProps } from "@react-ck/form-field";
import classNames from "classnames";

Expand Down Expand Up @@ -33,6 +33,12 @@ export const Input = ({

const computedId = useMemo(() => formFieldContext?.id ?? id, [formFieldContext?.id, id]);

// Determines if input should render the default styles or not
const isDefaultStyle = useMemo(() => {
const specialTypes: HTMLInputTypeAttribute[] = ["checkbox", "radio", "range", "color"];
return !props.type || !specialTypes.includes(props.type);
}, [props.type]);

// Validate usage inside form field
useEffect(() => {
// Is not inside form field, skip
Expand All @@ -48,10 +54,12 @@ export const Input = ({
{...props}
id={computedId}
className={classNames(
styles.root,
formFieldContext === undefined && styles.standalone,
isDefaultStyle && [
defaultStyles.root,
formFieldContext === undefined && defaultStyles.standalone,
defaultStyles[`skin_${computedSkin}`],
],
className,
styles[`skin_${computedSkin}`],
)}
/>
);
Expand Down

0 comments on commit 37d2326

Please sign in to comment.