-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TimePicker): add typescript typings (#13206)
* feat(TimePicker): add TimePicker typescript typings * chore(TimePicker): update copyright banner * docs(all-contributors): add `GalvinGao` to `all-contributors` * fix(TimePicker): fix `js` extension in `-test.js` * feat(TimePicker): use `as any` for Children.map use `as any` instead of type assertion to ensure backward compatibility --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
495cfe3
commit 0ab5fc1
Showing
6 changed files
with
250 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
packages/react/src/components/TimePickerSelect/TimePickerSelect.js
This file was deleted.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
packages/react/src/components/TimePickerSelect/TimePickerSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* 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 { ChevronDown } from '@carbon/icons-react'; | ||
import cx from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import { usePrefix } from '../../internal/usePrefix'; | ||
import { ForwardRefReturn } from '../../types/common'; | ||
|
||
export type TimePickerSelectProps = { | ||
/** | ||
* Provide the contents of your TimePickerSelect | ||
*/ | ||
children?: React.ReactNode; | ||
|
||
/** | ||
* Specify an optional className to be applied to the node containing the label and the select box | ||
*/ | ||
className?: string; | ||
|
||
/** | ||
* Optionally provide the default value of the `<select>` | ||
*/ | ||
defaultValue?: any; | ||
|
||
/** | ||
* Specify whether the control is disabled | ||
*/ | ||
disabled?: boolean; | ||
|
||
/** | ||
* Specify a custom `id` for the `<select>` | ||
*/ | ||
id: string; | ||
} & React.SelectHTMLAttributes<HTMLSelectElement> & | ||
React.InputHTMLAttributes<HTMLSelectElement>; | ||
|
||
type TimePickerSelectComponent = ForwardRefReturn< | ||
HTMLSelectElement, | ||
TimePickerSelectProps | ||
>; | ||
|
||
const TimePickerSelect: TimePickerSelectComponent = React.forwardRef( | ||
function TimePickerSelect( | ||
{ | ||
['aria-label']: ariaLabel = 'open list of options', | ||
children, | ||
id, | ||
disabled = false, | ||
className, | ||
...rest | ||
}, | ||
ref | ||
) { | ||
const prefix = usePrefix(); | ||
|
||
const selectClasses = cx({ | ||
[`${prefix}--select`]: true, | ||
[`${prefix}--time-picker__select`]: true, | ||
...(className && { [className]: true }), | ||
}); | ||
|
||
return ( | ||
<div className={selectClasses}> | ||
<select | ||
aria-label={ariaLabel} | ||
className={`${prefix}--select-input`} | ||
disabled={disabled} | ||
id={id} | ||
ref={ref} | ||
{...rest}> | ||
{children} | ||
</select> | ||
<ChevronDown | ||
className={`${prefix}--select__arrow`} | ||
aria-hidden="true" | ||
/> | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
TimePickerSelect.propTypes = { | ||
/** | ||
* Provide the contents of your TimePickerSelect | ||
*/ | ||
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, | ||
}; | ||
|
||
export default TimePickerSelect; |