@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
80 lines (79 loc) • 3.98 kB
JavaScript
;
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SelectValue = void 0;
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _SelectRootContext = require("../root/SelectRootContext");
var _useComponentRenderer = require("../../utils/useComponentRenderer");
var _useForkRef = require("../../utils/useForkRef");
var _mergeReactProps = require("../../utils/mergeReactProps");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
* A text label of the currently selected item.
* Renders a `<span>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
const SelectValue = exports.SelectValue = /*#__PURE__*/React.forwardRef(function SelectValue(props, forwardedRef) {
const {
className,
render,
children,
placeholder,
...otherProps
} = props;
const {
label,
valueRef
} = (0, _SelectRootContext.useSelectRootContext)();
const mergedRef = (0, _useForkRef.useForkRef)(forwardedRef, valueRef);
const state = React.useMemo(() => ({}), []);
const getValueProps = React.useCallback((externalProps = {}) => (0, _mergeReactProps.mergeReactProps)(externalProps, {
children: typeof children === 'function' ? children(label) : label || placeholder
}), [children, label, placeholder]);
const {
renderElement
} = (0, _useComponentRenderer.useComponentRenderer)({
propGetter: getValueProps,
render: render ?? 'span',
className,
state,
ref: mergedRef,
extraProps: otherProps
});
return renderElement();
});
process.env.NODE_ENV !== "production" ? SelectValue.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: _propTypes.default.func,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
/**
* A placeholder value to display when no value is selected.
*
* You can use this prop to pre-render the displayed text
* during SSR in order to avoid the hydration flash.
*/
placeholder: _propTypes.default.string,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func])
} : void 0;