-
Notifications
You must be signed in to change notification settings - Fork 2
Tanstack form basics #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
publicJorn
wants to merge
31
commits into
main
Choose a base branch
from
tanstack-form-basics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
5f933e1
feat: localised page title
maanlamp 7cbb2d9
Update index.html
maanlamp bc1f237
fix: Change approach to keep dynamic content on navigation
maanlamp d69f700
fix: use error color for badge
maanlamp 4f6b837
fix: Use idiomatic react
maanlamp 8a39707
fix: Feedback
maanlamp c528222
Update vite.config.ts
maanlamp c8cc8f5
feat: Add canonical URL
maanlamp c5f4309
feat: Reformat title like before
maanlamp 6934d17
Update title.ts
maanlamp eaeff74
added some comments
publicJorn f031c9b
review: rename claude settings file
publicJorn 491afa0
force translatedParams in separate router-i18n connector file
publicJorn ec2eaca
Merge branch 'main' into feature/localised-page-titles
publicJorn ef138b3
create test form page and setup utils to handle backend errors
publicJorn 02b1fb8
Add top-level routing ErrorComponent
publicJorn 9b035f6
add form components and an input connector for tsf
publicJorn 3fd014b
add checkbox component and example
publicJorn 47134a7
add CheckboxGroup
publicJorn ae1e27b
Added some minimal, but useful docs that help adoptation
publicJorn b1523dc
re-implement mutateAndValidate
publicJorn 7e5a96c
update login form
publicJorn 9fb77e5
adjust form component composition according to feedback
publicJorn 7330924
small docs fix
publicJorn d61ed3a
checkbox primitive is now only the control
publicJorn 30106d6
apply agreed upon BE error format
publicJorn d4c4cf2
fix translated url
publicJorn 156db59
Merge branch 'main' into tanstack-form-basics
publicJorn 6f3677e
resolve comments & some style updates
publicJorn e2b0a3b
fix: missed clsx update
publicJorn d46906e
nitpick
publicJorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,3 @@ | ||
| # Documentation | ||
|
|
||
| This folder contains documentation on how to use the IGNE vite-react-template. You can also add project-specific docs. |
This file contains hidden or 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,38 @@ | ||
| # Extending base-ui | ||
|
|
||
| [Base UI](https://base-ui.com) covers a bunch of generic components that we use to build our own on. | ||
|
|
||
| Oftentimes you may want to implement base-ui as-is, but you need a generic way to apply generic styling or functionality to its compound components. | ||
| This doc describes a good way to do that. | ||
|
|
||
| ## Import and re-export | ||
|
|
||
| For example a menu's Trigger should always contain an arrow: | ||
|
|
||
| ```tsx | ||
| import { Menu as BaseMenu } from '@base-ui/react/menu'; | ||
| import ChevronRight from "assets/icons/chevron-right.svg?react"; | ||
|
|
||
| const MenuTrigger = ({children, ...rest}: BaseMenu.Trigger.Props) => | ||
| <BaseMenu.Trigger {...rest}>{children}<ChevronRight /></BaseMenu.Trigger> | ||
|
|
||
| export default { | ||
| ...BaseMenu, | ||
| Trigger: MenuTrigger, | ||
| } | ||
| ``` | ||
|
|
||
| This way you only have to redefine the compound components that you change. | ||
| The suffix format (in this case `Menu`Trigger), prevents issues with reserved component names (eg. Error from Field.Error). | ||
|
|
||
| ## If you add props, always export a type | ||
|
|
||
| ```tsx | ||
| //... | ||
|
|
||
| export type MenuTriggerProps = BaseMenu.Trigger.Props & { icon: "chevron" | "arrow" } | ||
| const MenuTrigger = ({children, icon, ...rest}: MenuTriggerProps) => | ||
| <BaseMenu.Trigger {...rest}>{children}{icon ? <ChevronRight /> : <Arrow />}</BaseMenu.Trigger> | ||
|
|
||
| //... | ||
| ``` |
This file contains hidden or 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,34 @@ | ||
| # Working with forms | ||
|
|
||
| We use [Tanstack Form](https://tanstack.com/form/latest/docs/framework/react/guides/basic-concepts) (TSF). | ||
|
|
||
| In `lib/forms/` you can define reusable form/field components. See the docs on [form composition](https://tanstack.com/form/latest/docs/framework/react/guides/form-composition) for more info. | ||
|
|
||
| Form components are in `components/form/`. Tanstack Form connectors should be prefixed with `tsf-`. | ||
| If you need for example an Input component that is not connected to TSF, create a separate component. Be specific, a search component is `<Search />` etc. | ||
|
|
||
| If you need something VERY specific (used only once), you may not need to make a component at all. Just use BaseUI primitives and reuse the styling classnames. | ||
|
|
||
| ## How to adopt | ||
|
|
||
| ### Error handling | ||
|
|
||
| The first thing to do is to verify the **error object(s)** with Backend. | ||
| Make sure that the validation/error utils can translate the backend errors into something tanstack form understands. | ||
| See TODO's in `lib/forms/validation-helpers` & `lib/api/error-helpers.ts`. | ||
|
|
||
| ### Validation options | ||
|
|
||
| - Use a validation schema (preferably generated from api spec) to do FE validation of the form. Connect to `onDynamic`. | ||
| - If applicable, use the provided util to handle backend validation errors with `onSubmitAsync` & `mutateAndValidate`. | ||
| Note: this is a temp solution. | ||
|
|
||
| ### Submission | ||
|
|
||
| Prefer submitting with Tanstack Query (`useMutation`). An option object should be generated by heyapi. | ||
|
|
||
|
|
||
| See the form-example route to see how it all comes together. | ||
| Note: Normally you would not put everything in the route file, but this is easy to remove when you start a new project. | ||
|
|
||
| 💡 Remove any example files/code you don't need in your project! |
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.