@react-md/form
Version:
This package is for creating all the different form input types.
66 lines • 4.89 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef } from "react";
import cn from "classnames";
import { useIcon } from "@react-md/icon";
import { bem } from "@react-md/utils";
import { useFormTheme } from "../FormThemeProvider";
import { FloatingLabel } from "../label/FloatingLabel";
import { TextFieldContainer } from "../text-field/TextFieldContainer";
import { useFieldStates } from "../useFieldStates";
var block = bem("rmd-native-select");
var container = bem("rmd-native-select-container");
/**
* This component is used to render a native `<select>` element with the text
* field theme styles. This component is great to use for native behavior and
* full accessibility.
*/
export var NativeSelect = forwardRef(function NativeSelect(_a, ref) {
var style = _a.style, className = _a.className, labelStyle = _a.labelStyle, labelClassName = _a.labelClassName, selectStyle = _a.selectStyle, selectClassName = _a.selectClassName, propIcon = _a.icon, propTheme = _a.theme, _b = _a.dense, dense = _b === void 0 ? false : _b, _c = _a.inline, inline = _c === void 0 ? false : _c, _d = _a.stretch, stretch = _d === void 0 ? false : _d, _e = _a.error, error = _e === void 0 ? false : _e, _f = _a.disabled, disabled = _f === void 0 ? false : _f, label = _a.label, propOnBlur = _a.onBlur, propOnFocus = _a.onFocus, propOnChange = _a.onChange, containerRef = _a.containerRef, isLeftAddon = _a.isLeftAddon, isRightAddon = _a.isRightAddon, leftChildren = _a.leftChildren, rightChildren = _a.rightChildren, propUnderlineDirection = _a.underlineDirection, children = _a.children, props = __rest(_a, ["style", "className", "labelStyle", "labelClassName", "selectStyle", "selectClassName", "icon", "theme", "dense", "inline", "stretch", "error", "disabled", "label", "onBlur", "onFocus", "onChange", "containerRef", "isLeftAddon", "isRightAddon", "leftChildren", "rightChildren", "underlineDirection", "children"]);
var id = props.id, value = props.value, defaultValue = props.defaultValue, multiple = props.multiple;
var _g = useFormTheme({
theme: propTheme,
underlineDirection: propUnderlineDirection,
}), theme = _g.theme, underlineDirection = _g.underlineDirection;
var underline = theme === "underline" || theme === "filled";
var icon = useIcon("dropdown", propIcon);
var _h = useFieldStates({
onBlur: propOnBlur,
onFocus: propOnFocus,
onChange: propOnChange,
value: value,
defaultValue: defaultValue,
}), valued = _h.valued, focused = _h.focused, onBlur = _h.onBlur, onFocus = _h.onFocus, onChange = _h.onChange;
return (_jsxs(TextFieldContainer, __assign({ style: style, className: cn(container({
multi: multiple,
padded: multiple && label,
}), className), ref: containerRef, theme: theme, error: error, active: focused, label: !!label, dense: dense, inline: inline, stretch: stretch, disabled: disabled, isLeftAddon: isLeftAddon, isRightAddon: isRightAddon, leftChildren: leftChildren, rightChildren: multiple && rightChildren, underlineDirection: underlineDirection }, { children: [_jsx(FloatingLabel, __assign({ style: labelStyle, className: cn(block("label"), labelClassName), htmlFor: id, error: error, active: valued && focused, valued: valued, floating: valued || multiple, dense: dense, disabled: disabled }, { children: label })), _jsx("select", __assign({}, props, { ref: ref, style: selectStyle, className: cn(block({
icon: icon,
multi: multiple,
"label-underline": label && underline,
"placeholder-underline": !label && underline,
floating: label && theme !== "none",
}), selectClassName), disabled: disabled, onFocus: onFocus, onBlur: onBlur, onChange: onChange }, { children: children })), !multiple && icon && _jsx("span", __assign({ className: block("icon") }, { children: icon }))] })));
});
//# sourceMappingURL=NativeSelect.js.map