@carbon/react
Version:
React components for the Carbon Design System
95 lines (91 loc) • 2.69 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 Search from '../Search/Search.js';
import '../Search/Search.Skeleton.js';
import { usePrefix } from '../../internal/usePrefix.js';
import { FormContext } from '../FluidForm/FormContext.js';
const FluidSearch = /*#__PURE__*/React.forwardRef(function FluidSearch({
className,
...other
}, ref) {
const prefix = usePrefix();
const classNames = cx(`${prefix}--search--fluid`, className);
return /*#__PURE__*/React.createElement(FormContext.Provider, {
value: {
isFluid: true
}
}, /*#__PURE__*/React.createElement(Search, _extends({
ref: ref,
className: classNames
}, other)));
});
FluidSearch.propTypes = {
/**
* Specify an optional value for the `autocomplete` property on the underlying
* `<input>`, defaults to "off"
*/
autoComplete: PropTypes.string,
/**
* Specify an optional className to be applied to the container node
*/
className: PropTypes.string,
/**
* Specify a label to be read by screen readers on the "close" button
*/
closeButtonLabelText: PropTypes.string,
/**
* Optionally provide the default value of the `<input>`
*/
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/**
* Specify whether the `<input>` should be disabled
*/
disabled: PropTypes.bool,
/**
* Specify a custom `id` for the input
*/
id: PropTypes.string,
/**
* Provide the label text for the Search icon
*/
labelText: PropTypes.node.isRequired,
/**
* Optional callback called when the search value changes.
*/
onChange: PropTypes.func,
/**
* Optional callback called when the search value is cleared.
*/
onClear: PropTypes.func,
/**
* Provide a handler that is invoked on the key down event for the input
*/
onKeyDown: PropTypes.func,
/**
* Provide an optional placeholder text for the Search.
* Note: if the label and placeholder differ,
* VoiceOver on Mac will read both
*/
placeholder: PropTypes.string,
/**
* Specify the role for the underlying `<input>`, defaults to `searchbox`
*/
role: PropTypes.string,
/**
* Optional prop to specify the type of the `<input>`
*/
type: PropTypes.string,
/**
* Specify the value of the `<input>`
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
};
export { FluidSearch as default };