forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ts): adds types to next/ListBoxTrigger next/ListBoxSelection tsx (c…
…arbon-design-system#17325) * fix(17292): rename .js to .tsx * fix(17292): convert ListBoxTigger and Selection to TS
- Loading branch information
1 parent
2558b38
commit 71c9596
Showing
7 changed files
with
178 additions
and
93 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
70 changes: 0 additions & 70 deletions
70
packages/react/src/components/ListBox/next/ListBoxTrigger.js
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
packages/react/src/components/ListBox/next/ListBoxTrigger.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,90 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2024 | ||
* | ||
* 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 cx from 'classnames'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ChevronDown } from '@carbon/icons-react'; | ||
import { usePrefix } from '../../../internal/usePrefix'; | ||
|
||
export const translationIds = { | ||
'close.menu': 'close.menu', | ||
'open.menu': 'open.menu', | ||
} as const; | ||
|
||
export type TranslationKey = keyof typeof translationIds; | ||
|
||
const defaultTranslations: Record<TranslationKey, string> = { | ||
[translationIds['close.menu']]: 'Close', | ||
[translationIds['open.menu']]: 'Open', | ||
}; | ||
|
||
const defaultTranslateWithId = (id: TranslationKey): string => | ||
defaultTranslations[id]; | ||
|
||
export interface ListBoxTriggerProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
/** | ||
* Specify whether the menu is currently open, which will influence the | ||
* direction of the menu icon | ||
*/ | ||
isOpen: boolean; | ||
/** | ||
* i18n hook used to provide the appropriate description for the given menu | ||
* icon. This function takes in an id defined in `translationIds` and should | ||
* return a string message for that given message id. | ||
*/ | ||
translateWithId?: (id: TranslationKey) => string; | ||
} | ||
|
||
/** | ||
* `ListBoxTrigger` is used to orient the icon up or down depending on the | ||
* state of the menu for a given `ListBox` | ||
*/ | ||
|
||
const ListBoxTrigger = React.forwardRef<HTMLButtonElement, ListBoxTriggerProps>( | ||
function ListBoxTrigger( | ||
{ isOpen, translateWithId: t = defaultTranslateWithId, ...rest }, | ||
ref | ||
) { | ||
const prefix = usePrefix(); | ||
const className = cx({ | ||
[`${prefix}--list-box__menu-icon`]: true, | ||
[`${prefix}--list-box__menu-icon--open`]: isOpen, | ||
}); | ||
const description = isOpen ? t('close.menu') : t('open.menu'); | ||
return ( | ||
<button | ||
{...rest} | ||
aria-label={description} | ||
title={description} | ||
className={className} | ||
type="button" | ||
tabIndex={-1} | ||
ref={ref}> | ||
<ChevronDown /> | ||
</button> | ||
); | ||
} | ||
); | ||
|
||
ListBoxTrigger.propTypes = { | ||
/** | ||
* Specify whether the menu is currently open, which will influence the | ||
* direction of the menu icon | ||
*/ | ||
isOpen: PropTypes.bool.isRequired, | ||
|
||
/** | ||
* i18n hook used to provide the appropriate description for the given menu | ||
* icon. This function takes in an id defined in `translationIds` and should | ||
* return a string message for that given message id. | ||
*/ | ||
translateWithId: PropTypes.func, | ||
}; | ||
|
||
export default ListBoxTrigger; |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2024 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export { | ||
default as ListBoxSelection, | ||
type ListBoxSelectionProps, | ||
} from './ListBoxSelection'; | ||
export { | ||
default as ListBoxTrigger, | ||
type ListBoxTriggerProps, | ||
} from './ListBoxTrigger'; |
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