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({
40 } = useField(name, config);
42 disabled = disabled || submitting || submitSucceeded;
44 // choose the base dom component
45 const BaseComponent = type === 'textarea' ? 'textarea' : 'input';
47 // notify parent of enter keypress iff not disabled and passing
48 // TODO: integrate this into react-final-form submission
49 // const onKeyPress = useCallback(
50 // e => !disabled && valid && e.key === 'Enter' && onEnter && onEnter(),
51 // [disabled, valid] // eslint-disable-line react-hooks/exhaustive-deps
54 const showError = !!error;
55 const showSubmitError = !!submitError && !dirtySinceLastSubmit;
56 const indicateError = touched && !active && (showError || showSubmitError);
61 className={cn(className, 'mb1')}
64 pointerEvents: 'none',
65 cursor: 'not-allowed',
72 className={cn('f6 lh-tall', {
76 <Flex.Item as="label" justify="center" htmlFor={name}>
79 {labelAccessory && <Flex.Item>{labelAccessory}</Flex.Item>}
81 <Flex.Item as={Flex} row className="rel">
86 // NOTE: 1.15 from input line-height, 24px = 12px * 2 (from p3 styling)
87 style={type === 'textarea' ? { minHeight: 'calc(1.5rem * 3)' } : {}}
89 'b b1 p3 outline-none bs-none r4',
92 'bg-white': !disabled,
96 gray4: !(active || touched),
97 black: active || touched,
101 'b-black': !valid && active,
102 'b-yellow3': !valid && !active && touched,
103 'b-gray2': !valid && !active && !touched,
109 type={type === 'textarea' ? undefined : type}
118 width: 'calc(1.5em + 24px)',
127 <Flex.Item as={ErrorText} className="mv1">
128 {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