-
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.
Merge branch 'main' into 17106-region
- Loading branch information
Showing
45 changed files
with
375 additions
and
223 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
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+333 KB
.yarn/cache/@typescript-eslint-scope-manager-npm-8.3.0-3c8dd1afa1-ce56dbd826.zip
Binary file not shown.
Binary file added
BIN
+33.7 KB
.yarn/cache/@typescript-eslint-types-npm-8.3.0-11406c6bf2-0265f6b699.zip
Binary file not shown.
Binary file added
BIN
+184 KB
.yarn/cache/@typescript-eslint-typescript-estree-npm-8.3.0-c590ea2cb7-61243c9251.zip
Binary file not shown.
Binary file added
BIN
+115 KB
.yarn/cache/@typescript-eslint-utils-npm-8.3.0-76b00c816e-9d3494c15f.zip
Binary file not shown.
Binary file added
BIN
+9.84 KB
.yarn/cache/@typescript-eslint-visitor-keys-npm-8.3.0-324a7124f6-4ee45dd258.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-51.7 KB
.yarn/cache/@webassemblyjs-ast-npm-1.12.1-3ff9ea1c0e-a775b05594.zip
Binary file not shown.
Binary file added
BIN
+3.18 KB
.yarn/cache/@webassemblyjs-helper-buffer-npm-1.11.6-69996544b0-b14d0573bf.zip
Binary file not shown.
Binary file removed
BIN
-6.19 KB
.yarn/cache/@webassemblyjs-helper-buffer-npm-1.12.1-d025434a45-1d8705daa4.zip
Binary file not shown.
Binary file added
BIN
+5.07 KB
.yarn/cache/@webassemblyjs-helper-wasm-section-npm-1.11.6-344f8ff2af-38a615ab3d.zip
Binary file not shown.
Binary file removed
BIN
-9.37 KB
.yarn/cache/@webassemblyjs-helper-wasm-section-npm-1.12.1-cd0e2f1eab-e91e6b2811.zip
Binary file not shown.
Binary file added
BIN
+6.9 KB
.yarn/cache/@webassemblyjs-wasm-edit-npm-1.11.6-8d2703f828-c168bfc6d0.zip
Binary file not shown.
Binary file removed
BIN
-12.5 KB
.yarn/cache/@webassemblyjs-wasm-edit-npm-1.12.1-727bec592a-5678ae02db.zip
Binary file not shown.
Binary file added
BIN
+5.37 KB
.yarn/cache/@webassemblyjs-wasm-gen-npm-1.11.6-0ca036cab0-f91903506c.zip
Binary file not shown.
Binary file removed
BIN
-9.5 KB
.yarn/cache/@webassemblyjs-wasm-gen-npm-1.12.1-bbe22ad265-ec45bd50e8.zip
Binary file not shown.
Binary file added
BIN
+3.46 KB
.yarn/cache/@webassemblyjs-wasm-opt-npm-1.11.6-8be3443975-e0cfeea381.zip
Binary file not shown.
Binary file removed
BIN
-6.76 KB
.yarn/cache/@webassemblyjs-wasm-opt-npm-1.12.1-450c932de6-21f25ae109.zip
Binary file not shown.
Binary file added
BIN
+14.4 KB
.yarn/cache/@webassemblyjs-wasm-parser-npm-1.11.6-88e2433c21-6995e0b7b8.zip
Binary file not shown.
Binary file removed
BIN
-27.3 KB
.yarn/cache/@webassemblyjs-wasm-parser-npm-1.12.1-54a7a19806-f7311685b7.zip
Binary file not shown.
Binary file added
BIN
+5.04 KB
.yarn/cache/@webassemblyjs-wast-printer-npm-1.11.6-3191861e3f-fd45fd0d69.zip
Binary file not shown.
Binary file removed
BIN
-9.59 KB
.yarn/cache/@webassemblyjs-wast-printer-npm-1.12.1-e75655c7ff-1a6a4b6bc4.zip
Binary file not shown.
Binary file added
BIN
+8.87 KB
.yarn/cache/acorn-import-assertions-npm-1.9.0-22f56507c7-af8dd58f6b.zip
Binary file not shown.
Binary file removed
BIN
-10.6 KB
.yarn/cache/acorn-import-attributes-npm-1.9.5-d1e666eb35-8bfbfbb6e2.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+12.4 KB
...-keys-npm-3.4.1-a5d0a58208-92641e7ccd.zip → ...-keys-npm-3.4.3-a356ac7e46-3f357c554a.zip
Binary file not shown.
Binary file removed
BIN
-22.4 KB
.yarn/cache/terser-webpack-plugin-npm-5.3.10-3bde1920fb-fb1c2436ae.zip
Binary file not shown.
Binary file added
BIN
+22.4 KB
.yarn/cache/terser-webpack-plugin-npm-5.3.9-7ba1eb45f4-339737a407.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 was deleted.
Oops, something went wrong.
157 changes: 157 additions & 0 deletions
157
packages/react/src/components/ChatButton/ChatButton.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,157 @@ | ||
/** | ||
* Copyright IBM Corp. 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 React, { type ComponentType, type FunctionComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
import Button from '../Button'; | ||
import { usePrefix } from '../../internal/usePrefix'; | ||
|
||
export type ChatButtonKind = | ||
| 'primary' | ||
| 'secondary' | ||
| 'danger' | ||
| 'ghost' | ||
| 'tertiary'; | ||
export type ChatButtonSize = 'sm' | 'md' | 'lg'; | ||
|
||
export interface ChatButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
/** | ||
* Provide the contents of your Select | ||
*/ | ||
children?: React.ReactNode; | ||
/** | ||
* Specify an optional className to be applied to the node containing the label and the select box | ||
*/ | ||
className?: string; | ||
/** | ||
* Specify whether the `ChatButton` should be disabled | ||
*/ | ||
disabled?: boolean; | ||
/** | ||
* Specify whether the `ChatButton` should be rendered as a quick action button | ||
*/ | ||
isQuickAction?: boolean; | ||
/** | ||
* Specify whether the quick action `ChatButton` should be rendered as selected. This disables the input | ||
*/ | ||
isSelected?: boolean; | ||
/** | ||
* Specify the kind of `ChatButton` you want to create | ||
*/ | ||
kind?: ChatButtonKind; | ||
/** | ||
* Optional prop to specify an icon to be rendered. | ||
* Can be a React component class | ||
*/ | ||
renderIcon?: ComponentType | FunctionComponent; | ||
/** | ||
* Specify the size of the `ChatButton`, from the following list of sizes: | ||
*/ | ||
size?: ChatButtonSize; | ||
} | ||
|
||
const ChatButton = React.forwardRef<HTMLButtonElement, ChatButtonProps>( | ||
function ChatButton( | ||
{ | ||
className, | ||
children, | ||
disabled, | ||
isQuickAction, | ||
isSelected, | ||
kind, | ||
renderIcon, | ||
size, | ||
...other | ||
}: ChatButtonProps, | ||
ref | ||
) { | ||
const prefix = usePrefix(); | ||
const classNames = classnames(className, { | ||
[`${prefix}--chat-btn`]: true, | ||
[`${prefix}--chat-btn--with-icon`]: renderIcon, | ||
[`${prefix}--chat-btn--quick-action`]: isQuickAction, | ||
[`${prefix}--chat-btn--quick-action--selected`]: isSelected, | ||
}); | ||
|
||
const allowedSizes: ChatButtonSize[] = ['sm', 'md', 'lg']; | ||
|
||
if (isQuickAction) { | ||
kind = 'ghost'; | ||
size = 'sm'; | ||
} else { | ||
// Do not allow size larger than `lg` | ||
size = allowedSizes.includes(size as ChatButtonSize) ? size : 'lg'; | ||
} | ||
|
||
return ( | ||
<Button | ||
disabled={disabled} | ||
className={classNames} | ||
kind={kind} | ||
ref={ref} | ||
size={size as ChatButtonSize} | ||
renderIcon={renderIcon} | ||
{...other}> | ||
{children} | ||
</Button> | ||
); | ||
} | ||
); | ||
|
||
ChatButton.propTypes = { | ||
/** | ||
* Provide the contents of your Select | ||
*/ | ||
children: PropTypes.node, | ||
|
||
/** | ||
* Specify an optional className to be applied to the node containing the label and the select box | ||
*/ | ||
className: PropTypes.string, | ||
|
||
/** | ||
* Specify whether the `ChatButton` should be disabled | ||
*/ | ||
disabled: PropTypes.bool, | ||
|
||
/** | ||
* Specify whether the `ChatButton` should be rendered as a quick action button | ||
*/ | ||
isQuickAction: PropTypes.bool, | ||
|
||
/** | ||
* Specify whether the quick action `ChatButton` should be rendered as selected. This disables the input | ||
*/ | ||
isSelected: PropTypes.bool, | ||
|
||
/** | ||
* Specify the kind of `ChatButton` you want to create | ||
*/ | ||
kind: PropTypes.oneOf([ | ||
'primary', | ||
'secondary', | ||
'danger', | ||
'ghost', | ||
'tertiary', | ||
]), | ||
|
||
/** | ||
* Optional prop to specify an icon to be rendered. | ||
* Can be a React component class | ||
*/ | ||
// @ts-expect-error: PropTypes are not expressive enough to cover this case | ||
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), | ||
|
||
/** | ||
* Specify the size of the `ChatButton`, from the following list of sizes: | ||
*/ | ||
size: PropTypes.oneOf(['sm', 'md', 'lg']), | ||
}; | ||
|
||
export default ChatButton; |
Oops, something went wrong.