UNPKG

1.64 kBJavaScriptView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3import * as React from 'react';
4import { caretDownEmptyIcon } from '../icon';
5import { classes } from '../utils';
6import { DEFAULT_STYLE_CLASS } from './interface';
7export const HTML_SELECT_CLASS = 'jp-HTMLSelect';
8export class HTMLSelect extends React.Component {
9 render() {
10 const { className, defaultStyle = true, disabled, elementRef, iconProps, icon = caretDownEmptyIcon, options = [], ...htmlProps } = this.props;
11 const cls = classes(HTML_SELECT_CLASS, {
12 [DEFAULT_STYLE_CLASS]: defaultStyle
13 }, className);
14 // If the HTMLSelect is integrated to a toolbar, we avoid propagating the focus
15 // to the element with tabindex=0.
16 const handleFocus = (event) => {
17 event.stopPropagation();
18 };
19 const optionChildren = options.map(option => {
20 const props = typeof option === 'object' ? option : { value: option };
21 return (React.createElement("option", { ...props, key: props.value }, props.label || props.value));
22 });
23 return (React.createElement("div", { className: cls },
24 React.createElement("select", { onFocus: handleFocus, disabled: disabled, ref: elementRef, ...htmlProps, multiple: false },
25 optionChildren,
26 htmlProps.children),
27 React.createElement(icon.react, { tag: 'span',
28 stylesheet: 'select',
29 right: '7px',
30 top: '5px',
31 ...iconProps })));
32 }
33}
34//# sourceMappingURL=htmlselect.js.map
\No newline at end of file