1import React, { useCallback, useEffect } from 'react';
2import cn from 'classnames';
4import Flex from './Flex';
5import { ErrorText } from './Typography';
7export default 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
52 // notify parent of value only when passing
54 pass && onValue && onValue(data);
55 }, [pass, data]); // eslint-disable-line react-hooks/exhaustive-deps
57 // notify parent of pass
59 onPass && onPass(pass);
60 }, [pass]); // eslint-disable-line react-hooks/exhaustive-deps
62 // notify parent of error whenever error changes
64 onError && onError(error);
65 }, [error]); // eslint-disable-line react-hooks/exhaustive-deps
67 // notify parent of focus
69 onFocus && onFocus(focused);
70 }, [focused]); // eslint-disable-line react-hooks/exhaustive-deps
74 className={cn(className, 'mb1')}
78 pointerEvents: 'none',
79 cursor: 'not-allowed',
82 <Flex.Item as="label" className="f6 lh-tall" htmlFor={name}>
85 <Flex.Item as={Flex} className="rel" row>
90 'b b1 p3 outline-none',
93 'bg-white': !disabled,
101 'b-green3': visiblyPassed,
102 'b-black': focused && !visiblyPassed,
103 'b-yellow3': !focused && error,
104 'b-gray3': !focused && !error && !visiblyPassed,
106 // TODO: inputClassName ?
110 onKeyPress={onKeyPress}
129 <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