@carbon/react
Version:
React components for the Carbon Design System
35 lines (32 loc) • 755 B
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.
*/
const invalidProps = invalidId => ({
'data-invalid': true,
'aria-invalid': true,
'aria-describedby': invalidId
});
const warnProps = warnId => ({
'aria-describedby': warnId
});
const helperProps = helperId => ({
'aria-describedby': helperId
});
const getTextInputProps = ({
sharedTextInputProps,
invalid,
invalidId,
warn,
warnId,
hasHelper,
helperId
}) => ({
...sharedTextInputProps,
...(invalid ? invalidProps(invalidId) : {}),
...(warn ? warnProps(warnId) : {}),
...(hasHelper ? helperProps(helperId) : {})
});
export { getTextInputProps };