|
| 1 | +/** |
| 2 | + * Copyright IBM Corp. 2016, 2018 |
| 3 | + * |
| 4 | + * This source code is licensed under the Apache-2.0 license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import PropTypes from 'prop-types'; |
| 9 | +import React from 'react'; |
| 10 | +import cx from 'classnames'; |
| 11 | +import { ChevronDown16 } from '@carbon/icons-react'; |
| 12 | + |
| 13 | +import { usePrefix } from '../../../internal/usePrefix'; |
| 14 | +import deprecate from '../../../prop-types/deprecate'; |
| 15 | + |
| 16 | +const TimePickerSelect = React.forwardRef(function TimePickerSelect( |
| 17 | + { |
| 18 | + ['aria-label']: ariaLabel = 'open list of options', |
| 19 | + children, |
| 20 | + id, |
| 21 | + disabled = false, |
| 22 | + className, |
| 23 | + ...rest |
| 24 | + }, |
| 25 | + ref |
| 26 | +) { |
| 27 | + const prefix = usePrefix(); |
| 28 | + |
| 29 | + const selectClasses = cx({ |
| 30 | + [`${prefix}--select`]: true, |
| 31 | + [`${prefix}--time-picker__select`]: true, |
| 32 | + [className]: className, |
| 33 | + }); |
| 34 | + |
| 35 | + return ( |
| 36 | + <div className={selectClasses}> |
| 37 | + <select |
| 38 | + aria-label={ariaLabel} |
| 39 | + className={`${prefix}--select-input`} |
| 40 | + disabled={disabled} |
| 41 | + id={id} |
| 42 | + ref={ref} |
| 43 | + {...rest}> |
| 44 | + {children} |
| 45 | + </select> |
| 46 | + <ChevronDown16 |
| 47 | + className={`${prefix}--select__arrow`} |
| 48 | + aria-hidden="true" |
| 49 | + /> |
| 50 | + </div> |
| 51 | + ); |
| 52 | +}); |
| 53 | + |
| 54 | +TimePickerSelect.propTypes = { |
| 55 | + /** |
| 56 | + * Provide the contents of your TimePickerSelect |
| 57 | + */ |
| 58 | + children: PropTypes.node, |
| 59 | + |
| 60 | + /** |
| 61 | + * Specify an optional className to be applied to the node containing the label and the select box |
| 62 | + */ |
| 63 | + className: PropTypes.string, |
| 64 | + |
| 65 | + /** |
| 66 | + * Optionally provide the default value of the `<select>` |
| 67 | + */ |
| 68 | + defaultValue: PropTypes.any, |
| 69 | + |
| 70 | + /** |
| 71 | + * Specify whether the control is disabled |
| 72 | + */ |
| 73 | + disabled: PropTypes.bool, |
| 74 | + |
| 75 | + /** |
| 76 | + * Provide a description for the twistie icon that can be read by screen readers |
| 77 | + */ |
| 78 | + iconDescription: deprecate( |
| 79 | + PropTypes.string, |
| 80 | + 'The `iconDescription` prop for `TimePickerSelect` is no longer needed and has ' + |
| 81 | + 'been deprecated. It will be moved in the next major release. Use "aria-label" instead' |
| 82 | + ), |
| 83 | + |
| 84 | + /** |
| 85 | + * Specify a custom `id` for the `<select>` |
| 86 | + */ |
| 87 | + id: PropTypes.string.isRequired, |
| 88 | +}; |
| 89 | + |
| 90 | +export default TimePickerSelect; |
0 commit comments