Skip to content

Commit 780f6df

Browse files
authored
feat(TimePickerSelect): class -> functional (#9923)
* feat(TimePickerSelect): class -> functional * feat(TimePickerSelect): removed new icon in favor of the old one * fix(TimePickerSelect): moved ref to select element
1 parent 5757544 commit 780f6df

2 files changed

Lines changed: 101 additions & 1 deletion

File tree

packages/react/src/components/TimePickerSelect/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
export default from './TimePickerSelect';
8+
import * as FeatureFlags from '@carbon/feature-flags';
9+
10+
import { default as TimePickerSelectNext } from './next/TimePickerSelect';
11+
12+
import { default as TimePickerSelectClassic } from './TimePickerSelect';
13+
14+
const TimePickerSelect = FeatureFlags.enabled('enable-v11-release')
15+
? TimePickerSelectNext
16+
: TimePickerSelectClassic;
17+
18+
export default TimePickerSelect;
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)