1import React from 'react';
2import cn from 'classnames';
3import { useField } from 'react-final-form';
4import Flex from './Flex';
5import { ErrorText } from './Typography';
7export default function Input({
39 } = useField(name, config);
41 disabled = disabled || submitting || submitSucceeded;
43 // choose the base dom component
44 const BaseComponent = type === 'textarea' ? 'textarea' : 'input';
46 // notify parent of enter keypress iff not disabled and passing
47 // TODO: integrate this into react-final-form submission
48 // const onKeyPress = useCallback(
49 // e => !disabled && valid && e.key === 'Enter' && onEnter && onEnter(),
50 // [disabled, valid] // eslint-disable-line react-hooks/exhaustive-deps
53 const showError = !!error;
54 const showSubmitError = !!submitError && !dirtySinceLastSubmit;
55 const indicateError = touched && !active && (showError || showSubmitError);
60 className={cn(className, 'mb1')}
63 pointerEvents: 'none',
64 cursor: 'not-allowed',
69 className={cn('f6 lh-tall', {
76 <Flex.Item as={Flex} row className="rel">
81 // NOTE: 1.15 from input line-height, 24px = 12px * 2 (from p3 styling)
82 style={type === 'textarea' ? { minHeight: 'calc(1.5rem * 3)' } : {}}
84 'b b1 p3 outline-none bs-none',
87 'bg-white': !disabled,
91 gray4: !(active || touched),
92 black: active || touched,
96 'b-black': !valid && active,
97 'b-yellow3': !valid && !active && touched,
98 'b-gray2': !valid && !active && !touched,
104 type={type === 'textarea' ? undefined : type}
113 width: 'calc(1.5em + 24px)',
122 <Flex.Item as={ErrorText} className="mv1">
123 {error || submitError}
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list