Giter VIP home page Giter VIP logo

Comments (8)

netdesignr avatar netdesignr commented on July 28, 2024 1

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.

netdesignr avatar netdesignr commented on July 28, 2024 1

Is this library open for contributions? I could submit a more up to date documentation

from remix-forms.

gustavoguichard avatar gustavoguichard commented on July 28, 2024

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.

gustavoguichard avatar gustavoguichard commented on July 28, 2024

I'm glad it worked @netdesignr !
Yeah, it is totally open for contributions... We'd love it!

from remix-forms.

danielweinmann avatar danielweinmann commented on July 28, 2024

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.

netdesignr avatar netdesignr commented on July 28, 2024

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.

danielweinmann avatar danielweinmann commented on July 28, 2024

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.

danielweinmann avatar danielweinmann commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.