@carbon/react
Version:
React components for the Carbon Design System
133 lines (125 loc) • 5 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var PropTypes = require('prop-types');
var React = require('react');
var cx = require('classnames');
var ComboBox = require('../ComboBox/ComboBox.js');
var usePrefix = require('../../internal/usePrefix.js');
var FormContext = require('../FluidForm/FormContext.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
const FluidComboBox = /*#__PURE__*/React__default["default"].forwardRef(function FluidComboBox({
className,
isCondensed,
...other
}, ref) {
const prefix = usePrefix.usePrefix();
const classNames = cx__default["default"](`${prefix}--list-box__wrapper--fluid`, className, {
[`${prefix}--list-box__wrapper--fluid--condensed`]: isCondensed
});
return /*#__PURE__*/React__default["default"].createElement(FormContext.FormContext.Provider, {
value: {
isFluid: true
}
}, /*#__PURE__*/React__default["default"].createElement(ComboBox["default"], _rollupPluginBabelHelpers["extends"]({
ref: ref,
className: classNames
}, other)));
});
FluidComboBox.propTypes = {
/**
* Specify an optional className to be applied to the outer FluidForm wrapper
*/
className: PropTypes__default["default"].string,
/**
* Specify the direction of the dropdown. Can be either top or bottom.
*/
direction: PropTypes__default["default"].oneOf(['top', 'bottom']),
/**
* Specify whether the `<input>` should be disabled
*/
disabled: PropTypes__default["default"].bool,
/**
* Specify a custom `id` for the `<input>`
*/
id: PropTypes__default["default"].string.isRequired,
/**
* Allow users to pass in an arbitrary item or a string (in case their items are an array of strings)
* from their collection that are pre-selected
*/
initialSelectedItem: PropTypes__default["default"].oneOfType([PropTypes__default["default"].object, PropTypes__default["default"].string, PropTypes__default["default"].number]),
/**
* Specify if the currently selected value is invalid.
*/
invalid: PropTypes__default["default"].bool,
/**
* Provide the text that is displayed when the control is in an invalid state
*/
invalidText: PropTypes__default["default"].node,
/**
* Specify if the `FluidComboBox` should render its menu items in condensed mode
*/
isCondensed: PropTypes__default["default"].bool,
/**
* Function to render items as custom components instead of strings.
* Defaults to null and is overridden by a getter
*/
itemToElement: PropTypes__default["default"].func,
/**
* Helper function passed to downshift that allows the library to render a
* given item to a string label. By default, it extracts the `label` field
* from a given item to serve as the item label in the list.
*/
itemToString: PropTypes__default["default"].func,
/**
* We try to stay as generic as possible here to allow individuals to pass
* in a collection of whatever kind of data structure they prefer
*/
items: PropTypes__default["default"].array.isRequired,
/**
* Generic `label` that will be used as the textual representation of what
* this field is for
*/
label: PropTypes__default["default"].node.isRequired,
/**
* `onChange` is a utility for this controlled component to communicate to a
* consuming component what kind of internal state changes are occurring.
*/
onChange: PropTypes__default["default"].func.isRequired,
/**
* An optional callback to render the currently selected item as a react element instead of only
* as a string.
*/
renderSelectedItem: PropTypes__default["default"].func,
/**
* In the case you want to control the dropdown selection entirely.
*/
selectedItem: PropTypes__default["default"].oneOfType([PropTypes__default["default"].object, PropTypes__default["default"].string, PropTypes__default["default"].number]),
/**
* Provide the title text that will be read by a screen reader when
* visiting this control
*/
titleText: PropTypes__default["default"].node,
/**
* Callback function for translating ListBoxMenuIcon SVG title
*/
translateWithId: PropTypes__default["default"].func,
/**
* Specify whether the control is currently in warning state
*/
warn: PropTypes__default["default"].bool,
/**
* Provide the text that is displayed when the control is in warning state
*/
warnText: PropTypes__default["default"].node
};
exports["default"] = FluidComboBox;