@carbon/react
Version:
React components for the Carbon Design System
87 lines (83 loc) • 2.35 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.
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import PropTypes from 'prop-types';
import React from 'react';
import cx from 'classnames';
import Select from '../Select/Select.js';
import '../Select/Select.Skeleton.js';
import { usePrefix } from '../../internal/usePrefix.js';
import { FormContext } from '../FluidForm/FormContext.js';
const FluidSelect = /*#__PURE__*/React.forwardRef(function FluidSelect({
className,
children,
...other
}, ref) {
const prefix = usePrefix();
const classNames = cx(`${prefix}--select--fluid`, className);
return /*#__PURE__*/React.createElement(FormContext.Provider, {
value: {
isFluid: true
}
}, /*#__PURE__*/React.createElement(Select, _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
};
export { FluidSelect as default };