@carbon/react
Version:
React components for the Carbon Design System
92 lines (86 loc) • 2.58 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 Select = require('../Select/Select.js');
require('../Select/Select.Skeleton.js');
var usePrefix = require('../../internal/usePrefix.js');
var FormContext = require('../FluidForm/FormContext.js');
// eslint-disable-next-line react/display-name -- https://github.com/carbon-design-system/carbon/issues/20452
const FluidSelect = /*#__PURE__*/React.forwardRef(({
className,
children,
...other
}, ref) => {
const prefix = usePrefix.usePrefix();
const classNames = cx(`${prefix}--select--fluid`, className);
return /*#__PURE__*/React.createElement(FormContext.FormContext.Provider, {
value: {
isFluid: true
}
}, /*#__PURE__*/React.createElement(Select.default, _rollupPluginBabelHelpers.extends({
ref: ref,
className: classNames
}, other), children));
});
FluidSelect.propTypes = {
/**
* Provide the contents of your Select
*/
children: PropTypes.node,
/**
* Specify an optional className to be applied to the node containing the label and the select box
*/
className: PropTypes.string,
/**
* Optionally provide the default value of the `<select>`
*/
defaultValue: PropTypes.any,
/**
* Specify whether the control is disabled
*/
disabled: PropTypes.bool,
/**
* Specify a custom `id` for the `<select>`
*/
id: PropTypes.string.isRequired,
/**
* Specify if the currently value is invalid.
*/
invalid: PropTypes.bool,
/**
* Message which is displayed if the value is invalid.
*/
invalidText: PropTypes.node,
/**
* Provide label text to be read by screen readers when interacting with the
* control
*/
labelText: PropTypes.node,
/**
* Provide an optional `onChange` hook that is called each time the value of
* the underlying `<input>` changes
*/
onChange: PropTypes.func,
/**
* Specify whether the control is currently in warning state
*/
warn: PropTypes.bool,
/**
* Provide the text that is displayed when the control is in warning state
*/
warnText: PropTypes.node,
/**
* Whether or not the component is readonly
*/
readOnly: PropTypes.bool
};
exports.default = FluidSelect;