Skip to content

Commit

Permalink
fix(clerk-js): Add clearFeedback to types
Browse files Browse the repository at this point in the history
  • Loading branch information
desiprisg committed Oct 3, 2023
1 parent e904f11 commit 8d9d71a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/clerk-js/src/ui/elements/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type FormControlProps = Omit<PropsOfComponent<typeof Input>, 'label' | 'placehol
feedback: string;
feedbackType: FeedbackType;
setHasPassedComplexity: (b: boolean) => void;
clearFeedback: () => void;
hasPassedComplexity: boolean;
infoText?: string | LocalizationKey;
radioOptions?: {
Expand Down Expand Up @@ -284,6 +285,7 @@ export const FormControl = forwardRef<HTMLInputElement, PropsWithChildren<FormCo
setWarning,
setInfo,
setHasPassedComplexity,
clearFeedback,
radioOptions,
groupPreffix,
groupSuffix,
Expand Down Expand Up @@ -427,6 +429,7 @@ export const FormControl = forwardRef<HTMLInputElement, PropsWithChildren<FormCo
setWarning={setWarning}
setInfo={setInfo}
setHasPassedComplexity={setHasPassedComplexity}
clearFeedback={clearFeedback}
sx={sx}
>
{isCheckbox ? (
Expand Down
26 changes: 23 additions & 3 deletions packages/clerk-js/src/ui/primitives/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,36 @@ import type { FormControlProps } from './hooks';
import { FormControlContextProvider } from './hooks';

export const FormControl = (props: React.PropsWithChildren<FormControlProps>) => {
const { hasError, id, isRequired, setError, setInfo, setSuccess, setWarning, setHasPassedComplexity, ...rest } =
props;
const {
hasError,
id,
isRequired,
setError,
setInfo,
clearFeedback,
setSuccess,
setWarning,
setHasPassedComplexity,
...rest
} = props;
return (
<Flex
direction='col'
{...rest}
css={{ position: 'relative', flex: '1 1 auto' }}
>
<FormControlContextProvider
{...{ hasError, id, isRequired, setError, setInfo, setSuccess, setWarning, setHasPassedComplexity }}
{...{
hasError,
id,
isRequired,
setError,
setInfo,
clearFeedback,
setSuccess,
setWarning,
setHasPassedComplexity,
}}
>
{props.children}
</FormControlContextProvider>
Expand Down
4 changes: 4 additions & 0 deletions packages/clerk-js/src/ui/primitives/hooks/useFormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type FormControlProps = {
setWarning: (warning: string) => void;
setInfo: (info: string) => void;
setHasPassedComplexity: (b: boolean) => void;
clearFeedback: () => void;
};

type FormControlContextValue = Required<FormControlProps> & { errorMessageId: string };
Expand All @@ -34,6 +35,7 @@ export const FormControlContextProvider = (props: React.PropsWithChildren<FormCo
setWarning,
setInfo,
setHasPassedComplexity,
clearFeedback,
} = props;
// TODO: This shouldnt be targettable
const id = `${propsId}-field`;
Expand All @@ -55,6 +57,7 @@ export const FormControlContextProvider = (props: React.PropsWithChildren<FormCo
setWarning,
setInfo,
setHasPassedComplexity,
clearFeedback,
},
}),
[
Expand All @@ -68,6 +71,7 @@ export const FormControlContextProvider = (props: React.PropsWithChildren<FormCo
setInfo,
setWarning,
setHasPassedComplexity,
clearFeedback,
],
);
return <FormControlContext.Provider value={value}>{props.children}</FormControlContext.Provider>;
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/ui/utils/useFormControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type FieldStateProps<Id> = {
setSuccess: (message: string) => void;
setInfo: (info: string) => void;
setHasPassedComplexity: (b: boolean) => void;
clearFeedback: () => void;
hasPassedComplexity: boolean;
} & Omit<Options, 'defaultChecked'>;

Expand Down

0 comments on commit 8d9d71a

Please sign in to comment.