Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x | /* eslint-disable react/prop-types */ import _ from 'lodash'; import React, { createElement } from 'react'; import PropTypes from 'prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { StandardProps, getFirst, Overwrite } from '../../util/component-types'; import { buildModernHybridComponent } from '../../util/state-management'; import TextField, { ITextFieldProps } from '../TextField/TextField'; import SearchIcon from '../Icon/SearchIcon/SearchIcon'; import reducers from './SearchField.reducers'; import { ITextFieldState } from '../TextField/TextField'; const cx = lucidClassNames.bind('&-SearchField'); const { bool, func, node, number, oneOfType, string } = PropTypes; interface ISearchFieldIcon extends StandardProps {} const SearchFieldIcon = (_props: ISearchFieldIcon): null => null; SearchFieldIcon.peek = { description: `Icon this is displayed on the right side of the SearchField. Any of the lucid \`*Icon\` components should work.`, }; SearchFieldIcon.displayName = 'SearchField.Icon'; SearchFieldIcon.propName = 'Icon'; interface ISearchFieldTextField extends ITextFieldProps {} const SearchFieldTextField = (_props: ISearchFieldTextField): null => null; SearchFieldTextField.peek = { description: `Icon this is displayed on the right side of the SearchField. Any of the lucid \`*Icon\` components should work.`, }; SearchFieldTextField.displayName = 'SearchField.TextField'; SearchFieldTextField.propName = 'TextField'; export interface ISearchFieldState extends ITextFieldState {} export interface ISearchFieldProps extends StandardProps { /** Fires an event every time the user types text into the TextField. */ onChange?: ( value: string, { event, props }: { event: React.FormEvent; props: ITextFieldProps } ) => void; /** Fires an event, debounced by \`debounceLevel\`, when the user types text into the TextField. */ onChangeDebounced?: ( value: string, { event, props }: { event: React.FormEvent; props: ITextFieldProps } ) => void; /** Number of milliseconds to debounce the \`onChangeDebounced\` callback. Only useful if you provide an \`onChangeDebounced\` handler. */ debounceLevel?: number; /** Fires an event when the user hits "enter" from the SearchField. */ onSubmit?: ( value: string, { event, props }: { event: React.FormEvent; props: ITextFieldProps } ) => void; /** Set the value of the input. */ value?: string | number; /** Controls the highlighting of the search icon. Should be passed \`true\` when the search text is valid, e.g. contains enough characters to perform a search. */ isValid?: boolean; /** Disables the SearchField by greying it out. */ isDisabled?: boolean; /**n placeholder value */ placeholder?: string; } /** TODO: Remove the nonPassThroughs when the component is converted to a functional component */ const nonPassThroughs = [ 'onChange', 'onChangeDebounced', 'debounceLevel', 'onSubmit', 'value', 'isValid', 'isDisabled', 'placeholder', 'className', 'Icon', 'TextField', 'initialState', 'callbackId', ]; type ISearchFieldPropsWithPassThroughs = Overwrite< React.DetailedHTMLProps< React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement >, ISearchFieldProps >; class SearchField extends React.Component< ISearchFieldPropsWithPassThroughs, ISearchFieldState > { static displayName = 'SearchField'; static TextField = SearchFieldTextField; static Icon = SearchFieldIcon; static peek = { description: `A wrapper around \`TextField\` that styles it for a search use-case. The icon and TextField are customizable through child components.`, categories: ['controls', 'text'], madeFrom: ['TextField', 'SearchIcon'], }; static reducers = reducers; static propTypes = { /** Fires an event every time the user types text into the TextField. Signature: \`(value, { event, props }) => {}\` */ onChange: func, /** Fires an event, debounced by \`debounceLevel\`, when the user types text into the TextField. Signature: \`(value, { event, props }) => {}\` */ onChangeDebounced: func, /** Number of milliseconds to debounce the \`onChangeDebounced\` callback. Only useful if you provide an \`onChangeDebounced\` handler. */ debounceLevel: number, /** Fires an event when the user hits "enter" from the SearchField. Signature: \`(value, { event, props }) => {}\` */ onSubmit: func, /** Set the value of the input. */ value: oneOfType([number, string]), /** Controls the highlighting of the search icon. Should be passed \`true\` when the search text is valid, e.g. contains enough characters to perform a search. */ isValid: bool, /** Disables the SearchField by greying it out. */ isDisabled: bool, /** placeholder value */ placeholder: string, /** Appended to the component-specific class names set on the root element. */ className: string, Icon: node /** Icon this is displayed on the right side of the SearchField. Any of the lucid \`*Icon\` components should work. */, /** The TextField that Searchfield is composed of. */ TextField: node, }; static defaultProps = { isDisabled: false, onChange: _.noop, onChangeDebounced: _.noop, debounceLevel: 500, onSubmit: _.noop, value: '', }; private textFieldElement = React.createRef<TextField>(); focus = (options?: FocusOptions): void => { this.textFieldElement.current && this.textFieldElement.current.focus(options); }; render(): React.ReactNode { const { props, props: { className, isDisabled, isValid, onChange, onChangeDebounced, debounceLevel, onSubmit, placeholder, value, autoComplete, ...passThroughs }, } = this; const { Icon } = SearchField; const textFieldProps = _.get( getFirst(props, SearchField.TextField), 'props' ) || { isDisabled, onChange, onChangeDebounced, debounceLevel, onSubmit, placeholder, isMultiLine: false, value, autoComplete, }; const textFieldElement = ( <TextField ref={this.textFieldElement} {...textFieldProps} /> ); const isIconActive = _.isUndefined(isValid) ? !_.isEmpty(_.get(textFieldElement, 'props.value')) : isValid; const defaultIcon = ( <SearchIcon size={12} className={cx('&-Icon', { '&-Icon-active': isIconActive })} /> ); const iconElement = getFirst(props, Icon); const iconChildren = _.get(iconElement, 'props.children'); const icon = iconChildren ? createElement(iconChildren.type, { ...iconChildren.props, className: cx( '&-Icon', { '&-Icon-active': isIconActive }, iconChildren.props.className ), }) : defaultIcon; return ( <div {..._.omit(passThroughs, nonPassThroughs)} className={cx('&', className)} > {textFieldElement} <div className={cx('&-Icon-container', { '&-Icon-is-disabled': isDisabled, })} > {icon} </div> </div> ); } } export default buildModernHybridComponent< ISearchFieldPropsWithPassThroughs, ISearchFieldState, typeof SearchField >(SearchField, { reducers }); export { SearchField as SearchFieldDumb }; |