generated from morewings/react-library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
219 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type {MutableRefObject} from 'react'; | ||
import {type FormEvent, useEffect} from 'react'; | ||
|
||
const ChangeEvent = new Event('change', {bubbles: false}); | ||
|
||
export const useRevalidateOnFormChange = ( | ||
inputRef: MutableRefObject<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null>, | ||
validateInput: (event: FormEvent) => unknown, | ||
condition?: boolean | ||
) => { | ||
useEffect(() => { | ||
if (condition) { | ||
const inputElement = inputRef?.current; | ||
const formElement = inputElement?.form; | ||
const revalidateInput = () => { | ||
inputElement && inputElement?.dispatchEvent(ChangeEvent); | ||
inputElement && validateInput(ChangeEvent as unknown as FormEvent); | ||
}; | ||
formElement && formElement.addEventListener('change', revalidateInput); | ||
return () => { | ||
formElement && formElement.removeEventListener('change', revalidateInput); | ||
}; | ||
} | ||
}, [inputRef, condition, validateInput]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
import { Meta, ArgTypes, Story, Canvas, Source, Markdown } from "@storybook/blocks"; | ||
import { Meta, ArgTypes, Story, Canvas, Source, Markdown, Primary } from "@storybook/blocks"; | ||
import * as FormStories from "./Form.stories"; | ||
import { Form } from "./Form"; | ||
|
||
<Meta title="Inputs/Form" component={Form} /> | ||
<Meta title="Inputs/Form" of={FormStories} /> | ||
|
||
# Form | ||
|
||
Form wraps `HTMLFormElement` with some useful features. | ||
|
||
## Icon props | ||
|
||
<ArgTypes of={Form} /> | ||
|
||
## Description | ||
|
||
`Icon` is an icon. | ||
|
||
## Imports | ||
|
||
<Source format={true} code={` | ||
const a = 'b'; | ||
import a from 'b'; | ||
`} /> | ||
<Markdown>{` | ||
\`\`\`ts | ||
import {Form} from 'koval-ui'; | ||
\`\`\` | ||
`}</Markdown> | ||
|
||
## Form props | ||
|
||
<ArgTypes of={Form} /> | ||
|
||
## Demo | ||
|
||
### Basic example | ||
<Canvas of={FormStories.Example} /> | ||
<Primary /> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.