1import React, { useCallback } from 'react';
2import cn from 'classnames';
4import Flex from './Flex';
5import { ErrorText } from './Typography';
7export default React.memo(function Input({
41 // NB(shrugs): we disable exhaustive deps because we don't want the callbacks
42 // (whose identity might change between renders) to trigger a re-notify of
43 // state that we already know
44 // this also happens to prevent render loops when rendering a map of inputs
46 // notify parent of enter keypress iff not disabled and passing
47 const onKeyPress = useCallback(
48 e => !disabled && pass && e.key === 'Enter' && onEnter && onEnter(),
49 [disabled, pass] // eslint-disable-line react-hooks/exhaustive-deps
54 className={cn(className, 'mb1')}
58 pointerEvents: 'none',
59 cursor: 'not-allowed',
64 className={cn('f6 lh-tall', {
71 <Flex.Item as={Flex} className="rel" row>
73 as={type === 'textarea' ? 'textarea' : 'input'}
74 type={type === 'textarea' ? undefined : type}
76 // NOTE: 24px = 12px * 2 (from p3 styling)
77 style={type === 'textarea' ? { minHeight: 'calc(1rem + 24px)' } : {}}
79 'b b1 p3 outline-none',
82 'bg-white': !disabled,
86 gray4: !focused && !touched,
87 black: focused || touched,
90 'b-green3': visiblyPassed,
91 'b-black': focused && !visiblyPassed,
92 'b-yellow3': !focused && hintError,
93 'b-gray2': !focused && !hintError && !visiblyPassed,
95 // TODO: inputClassName ?
99 onKeyPress={onKeyPress}
118 <Flex.Item as={ErrorText} className="mv1">
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