UNPKG

1.25 kBTypeScriptView Raw
1/*
2 * Copyright (c) Jupyter Development Team.
3 * Distributed under the terms of the Modified BSD License.
4 */
5
6import React from 'react';
7import { LabIcon } from '../icon';
8import { classes } from '../utils';
9
10/**
11 * InputGroup component properties
12 */
13export interface IInputGroupProps
14 extends React.InputHTMLAttributes<HTMLInputElement> {
15 /**
16 * Pass a ref to the input element
17 */
18 inputRef?: React.RefObject<HTMLInputElement>;
19 /**
20 * Right icon adornment
21 */
22 rightIcon?: string | LabIcon;
23}
24
25/**
26 * InputGroup component
27 *
28 * @param props Component properties
29 * @returns Component
30 */
31export function InputGroup(props: IInputGroupProps): JSX.Element {
32 const { className, inputRef, rightIcon, ...others } = props;
33 return (
34 <div className={classes('jp-InputGroup', className)}>
35 <input ref={inputRef} {...others}></input>
36 {rightIcon && (
37 <span className="jp-InputGroupAction">
38 {typeof rightIcon === 'string' ? (
39 <LabIcon.resolveReact
40 icon={rightIcon}
41 elementPosition="center"
42 tag="span"
43 />
44 ) : (
45 <rightIcon.react elementPosition="center" tag="span" />
46 )}
47 </span>
48 )}
49 </div>
50 );
51}