Skip to content
Snippets Groups Projects
Commit 8ae30ce0 authored by Tore.Brede's avatar Tore.Brede
Browse files

Removing unused form component

parent e53b82e7
No related branches found
No related tags found
1 merge request!167Removing unused form component
Pipeline #100832 passed
import styled from '@emotion/styled/macro'
const StyledValidationError = styled.span`
color: "red"
`
export default StyledValidationError
\ No newline at end of file
import React from 'react'
import { UseFormReturn } from 'react-hook-form'
import { isValidFnr } from 'utils'
interface FnrProps extends Partial<Pick<UseFormReturn, 'register'>> {
name: string
errors?: any
}
function Fnr(props: FnrProps) {
const { register, name, errors } = props
if (register === undefined) {
return <></>
}
return (
<>
<input
type="text"
placeholder={name}
// eslint-disable-next-line react/jsx-props-no-spreading
{...register(name, {
required: 'Fnr is required',
validate: isValidFnr,
})}
id="fnr"
/>
{errors.fnr && errors.fnr.message}
{errors.fnr && errors.fnr.type === 'validate' && 'Invalid fnr'}
</>
)
}
Fnr.defaultProps = {
errors: {},
}
export default Fnr
import React from 'react'
import { useForm } from 'react-hook-form'
interface FormProps {
children: any
onSubmit: any
}
export default function Form(props: FormProps) {
const { children, onSubmit } = props
const methods = useForm()
const {
handleSubmit,
formState: { errors },
} = methods
return (
<form onSubmit={handleSubmit(onSubmit)}>
{React.Children.map(children, (child) =>
child.props.name
? React.createElement(child.type, {
// eslint-disable-next-line react/jsx-props-no-spreading
...{
// eslint-disable-next-line react/jsx-props-no-spreading
...child.props,
control: methods.control,
register: methods.register,
errors,
key: child.props.name,
},
})
: child
)}
</form>
)
}
import Form from './form'
import Input from './input'
import Select from './select'
import Fnr from './fnr'
export { Fnr, Form, Input, Select }
import React from 'react'
import styled from '@emotion/styled/macro'
import { UseFormReturn } from 'react-hook-form'
interface InputProps
extends Partial<React.InputHTMLAttributes<HTMLInputElement>>,
Partial<UseFormReturn> {
name: string
errors?: any
type?: 'text' | 'email' | 'number'
}
export const StyledInput = styled.input`
width: 50%;
border: 1px solid;
border-width: 0.013rem;
border-radius: 0.3rem;
border-color: #ccc;
box-shadow: inset 0 0 0 0.013rem #4d4d4d;
padding: 0.625rem;
`
export const StyledLabel = styled.label`
display: block;
font-size: 1rem;
padding: 0.3rem 0 0.3rem 0;
`
function Input(props: InputProps) {
// eslint-disable-next-line react/jsx-props-no-spreading
const { register, name, errors, type, ...rest } = props
if (register === undefined) {
return <></>
}
// eslint-disable-next-line react/jsx-props-no-spreading
return <StyledInput {...register(name)} {...rest} />
}
Input.defaultProps = {
type: 'text',
errors: {},
}
export default Input
import React from 'react'
import { UseFormReturn } from 'react-hook-form'
interface SelectProps extends Partial<Pick<UseFormReturn, 'register'>> {
options: Array<string>
name: string
type?: 'text' | 'email' | 'number'
}
function Select(props: SelectProps) {
const { register, options, name, ...rest } = props
if (register === undefined) {
return <></>
}
return (
// eslint-disable-next-line react/jsx-props-no-spreading
<select {...register(name)} {...rest}>
{options.map((value) => (
<option key={value} value={value}>
{value}
</option>
))}
</select>
)
}
Select.defaultProps = {
type: 'text',
}
export default Select
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment