Comments (8)
Hi @gustavoguichard, this is exactly what I was looking for! I tried everything but did think it takes a function with the props :)
from remix-forms.
Is this library open for contributions? I could submit a more up to date documentation
from remix-forms.
Hey @netdesignr , we use Tailwind and love it too. The docs are indeed lacking a little bit on that section, so I'll leave an example here of a form I customized for a particular project, I hope it helps:
import * as React from 'react'
import type { FormProps } from 'remix-forms'
import { Form } from 'remix-forms'
import type { SomeZodObject } from 'zod'
import Button from '~/components/button'
import { cx } from '~/framework/common'
function RemixForm<Schema extends SomeZodObject>(props: FormProps<Schema>) {
return (
<Form<Schema>
fieldComponent={(props) => (
<div
{...props}
className={cx(
'flex flex-col text-left focus-within:text-blush',
props.className,
)}
/>
)}
labelComponent={(props) => (
<label
{...props}
className={cx('mb-1 px-3 text-sm text-current', props.className)}
/>
)}
inputComponent={React.forwardRef<
HTMLInputElement,
JSX.IntrinsicElements['input']
>(({ type = 'text', ...props }, ref) => (
<input
ref={ref}
type={type}
{...props}
className={cx(
'rounded border-gray-light px-3 py-4 transition-all focus:border-blush focus:ring-blush',
props.className,
)}
/>
))}
multilineComponent={React.forwardRef<
HTMLTextAreaElement,
JSX.IntrinsicElements['textarea']
>((props, ref) => (
<textarea
ref={ref}
{...props}
className={cx(
'rounded border-gray-light px-3 py-4 transition-all focus:border-blush focus:ring-blush',
props.className,
)}
/>
))}
selectComponent={React.forwardRef<
HTMLSelectElement,
JSX.IntrinsicElements['select']
>((props, ref) => (
<select
ref={ref}
{...props}
className={cx(
'rounded border-gray-light px-3 py-4 transition-all focus:border-blush focus:ring-blush',
props.className,
)}
/>
))}
buttonComponent={(props) => (
<Button
variant="primary"
size="lg"
contained
type="submit"
{...props}
/>
)}
fieldErrorsComponent={(props) => (
<small
{...props}
className={cx('mt-1 px-3 text-salmon', props.className)}
/>
)}
globalErrorsComponent={(props) => (
<small
{...props}
className={cx('mt-1 px-3 text-salmon', props.className)}
/>
)}
errorComponent={(props) => (
<span
{...props}
className={cx('text-xs font-semibold text-current', props.className)}
/>
)}
renderField={({ Field, ...props }) => {
const { label, required, errors } = props
return (
<Field {...props}>
{({ Label, SmartInput, Errors }) => (
<>
<Label className={cx(errors && '!text-salmon')}>
{label}
{required && ' *'}
</Label>
<SmartInput
className={cx(errors && '!border-salmon !text-salmon')}
/>
<Errors />
</>
)}
</Field>
)
}}
{...props}
/>
)
}
export default RemixForm
from remix-forms.
I'm glad it worked @netdesignr !
Yeah, it is totally open for contributions... We'd love it!
from remix-forms.
Hey, @netdesignr! Thank you for creating this issue and for offering to contribute with documentation! We appreciate it a lot
I just added an example to our Get Started page. Do you think this example would have helped you learn the API?
from remix-forms.
Hi @danielweinmann, I think that should have just helped me. I was looking around for some source where you've used it but didn't realise it was hidden inside the remix-forms-site
repo. Having said that, it would have been better if at least one example existed directly on Get started
page so you won't necessarily have to go away from the docs.
from remix-forms.
Awesome! That's great feedback :D
I'm going to leave this issue open until we have a better solution. Feel free to send a PR to remix-forms-site
if you have an idea about how to make this clearer. Thank you!
from remix-forms.
Closing this because people seem to be learning how to create their components with the current solution. We'll open a new one when the time comes to make it better.
from remix-forms.
Related Issues (20)
- Reset field value when other field value has changed HOT 2
- Access session cookie in mutation HOT 4
- Suport Remix's `v2_normalizeFormMethod` HOT 4
- put, patch, delete methods don't work HOT 1
- Better type inference for formAction result HOT 2
- Typings for the underlying Fields, Errors etc HOT 3
- Add `replace` prop to `Form` HOT 1
- Add a way to avoid magically passing props to inputs HOT 3
- How to disable inputs during the form submission? HOT 1
- Bug: TS types for `props.name` is wrong HOT 3
- Bug: Wrong accessibility tags applied to wrapping components when using `renderField` HOT 4
- How to handle custom Combobox input? HOT 4
- Element Types JSX.IntrinsicElements vs React.[Element]HTMLAttributes* HOT 1
- Global error duplicate with multiple forms HOT 2
- Form re-renders more than it should
- field param of useFieldArray not being updated in real-time and out of date when passed to modal HOT 3
- pendingButtonLabel should default to the value of buttonLabel HOT 1
- 1.6.3: Uncaught (in promise) Error: Cannot submit element that is not <form>, <button>, or <input type="submit|image"> HOT 1
- Attach errors to Fields that are dynamically generated? HOT 2
- Inconsistent display of selected option in select control HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remix-forms.