UNPKG

2.84 kBJavaScriptView Raw
1/*
2 * Copyright 2018 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { __assign, __rest } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { CaretDown, DoubleCaretVertical } from "@blueprintjs/icons";
20import { DISABLED, FILL, HTML_SELECT, LARGE, MINIMAL } from "../../common/classes";
21import { DISPLAYNAME_PREFIX } from "../../common/props";
22// this component is simple enough that tests would be purely tautological.
23/* istanbul ignore next */
24/**
25 * HTML select component
26 *
27 * @see https://blueprintjs.com/docs/#core/components/html-select
28 */
29export var HTMLSelect = React.forwardRef(function (props, ref) {
30 var _a;
31 var className = props.className, children = props.children, disabled = props.disabled, fill = props.fill, _b = props.iconName, iconName = _b === void 0 ? "double-caret-vertical" : _b, iconProps = props.iconProps, large = props.large, minimal = props.minimal, _c = props.options, options = _c === void 0 ? [] : _c, value = props.value, htmlProps = __rest(props, ["className", "children", "disabled", "fill", "iconName", "iconProps", "large", "minimal", "options", "value"]);
32 var classes = classNames(HTML_SELECT, (_a = {},
33 _a[DISABLED] = disabled,
34 _a[FILL] = fill,
35 _a[LARGE] = large,
36 _a[MINIMAL] = minimal,
37 _a), className);
38 var iconTitle = "Open dropdown";
39 var rightIcon = iconName === "double-caret-vertical" ? (React.createElement(DoubleCaretVertical, __assign({ title: iconTitle }, iconProps))) : (React.createElement(CaretDown, __assign({ title: iconTitle }, iconProps)));
40 var optionChildren = options.map(function (option) {
41 var optionProps = typeof option === "object" ? option : { value: option };
42 return React.createElement("option", __assign({}, optionProps, { key: optionProps.value, children: optionProps.label || optionProps.value }));
43 });
44 return (React.createElement("div", { className: classes },
45 React.createElement("select", __assign({ disabled: disabled, ref: ref, value: value }, htmlProps, { multiple: false }),
46 optionChildren,
47 children),
48 rightIcon));
49});
50HTMLSelect.displayName = "".concat(DISPLAYNAME_PREFIX, ".HTMLSelect");
51//# sourceMappingURL=htmlSelect.js.map
\No newline at end of file