Skip to content
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

Convert AddressForm From Angular to React #969

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/common/components/form/textInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { ChangeEvent, FocusEvent, HTMLInputTypeAttribute } from 'react';

interface TextInputProps {
title?: string,
type?: HTMLInputTypeAttribute,
name: string,
required?: boolean,
maxLength?: number,
pattern?: string,
disabled?: boolean,
onChange: (event: ChangeEvent<any>) => void,
onBlur: (event: FocusEvent<any>) => void,
value?: string,
error?: string,
}

const TextInput = ({
title,
type = 'text',
name,
required = false,
maxLength,
pattern,
disabled,
onChange,
onBlur,
value,
error,
}: TextInputProps) => (
<div className={`form-group${required && ' is-required' || ''}${error && ' has-error' || ''}`}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure isn't always in place for text inputs. What's the best way to build a different structure when we need it? (e.g. personalOptionsModal.tpl.html)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could maybe remove this wrapping div from here, and create a wrapper component that will only be used for AddressForm text inputs.

{ title && <label>{title}</label> }
<input
type={type}
className="form-control form-control-subtle"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these overridable? Not all text inputs have form-control-subtle, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I could create an optional prop that overrides the input className value.

name={name}
required={required}
maxLength={maxLength}
pattern={pattern}
disabled={disabled}
onChange={onChange}
onBlur={onBlur}
value={value}
/>
{ error && (
<div role="alert">
<div className="help-block">{error}</div>
</div>
)}
</div>
);

export default TextInput;