-
Notifications
You must be signed in to change notification settings - Fork 448
feat: toolbar dropdown-button contribute #2312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
304897b
feat: toolbar dropdown-button contribute
hacke2 88659f7
refactor: toolbar command
hacke2 15cd69c
chore: sumiCommon -> extHostCommon
hacke2 e81c310
fix: typo
hacke2 dfe0947
typo: kaitianCommon -> extHostCommon
hacke2 7ca6f90
chore: optimize code
hacke2 68d1b56
fix: lint
hacke2 28e3ca8
chore: TOOLBAR_ACTION -> TOOLBAR_ACTION_TYPE
hacke2 a9482bd
chore: use prefix
hacke2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -162,3 +162,5 @@ export const Button = React.memo( | |
| ); | ||
| }, | ||
| ); | ||
|
|
||
| export default Button; | ||
This file contains hidden or 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,102 @@ | ||
| import EllipsisOutlined from '@ant-design/icons/EllipsisOutlined'; | ||
|
hacke2 marked this conversation as resolved.
|
||
| import classNames from 'classnames'; | ||
| import * as React from 'react'; | ||
|
|
||
| import Button from '../button'; | ||
| import type { ButtonSize, ButtonType } from '../button'; | ||
| import type { ButtonHTMLType } from '../button'; | ||
|
|
||
| import type { DropDownProps } from './dropdown'; | ||
| import Dropdown from './dropdown'; | ||
|
|
||
| export interface DropdownButtonProps extends DropDownProps { | ||
| type?: ButtonType; | ||
| size?: ButtonSize; | ||
| htmlType?: ButtonHTMLType; | ||
| danger?: boolean; | ||
| disabled?: boolean; | ||
| loading?: boolean; | ||
| onClick?: React.MouseEventHandler<HTMLButtonElement>; | ||
| icon?: React.ReactNode; | ||
| href?: string; | ||
| children?: React.ReactNode; | ||
| title?: string; | ||
| buttonsRender?: (buttons: React.ReactNode[]) => React.ReactNode[]; | ||
| } | ||
|
|
||
| const DropdownButton: React.FC<DropdownButtonProps> = (props) => { | ||
| const { | ||
| prefixCls: customizePrefixCls, | ||
| type = 'primary', | ||
| size = 'default', | ||
| danger, | ||
| disabled, | ||
| loading, | ||
| onClick, | ||
| htmlType, | ||
| children, | ||
| className, | ||
| overlay, | ||
| trigger, | ||
| align, | ||
| visible, | ||
| onVisibleChange, | ||
| placement, | ||
| getPopupContainer, | ||
| href, | ||
| icon = <EllipsisOutlined />, | ||
| title, | ||
| buttonsRender = (buttons: React.ReactNode[]) => buttons, | ||
| mouseEnterDelay, | ||
| mouseLeaveDelay, | ||
| overlayClassName, | ||
| overlayStyle, | ||
| ...restProps | ||
| } = props; | ||
|
|
||
| const prefixCls = customizePrefixCls || 'kt-dropdown-button'; | ||
| const dropdownProps: DropDownProps = { | ||
| align, | ||
| overlay, | ||
| disabled, | ||
| trigger: disabled ? [] : trigger, | ||
| getPopupContainer, | ||
| mouseEnterDelay, | ||
| mouseLeaveDelay, | ||
| overlayClassName, | ||
| overlayStyle, | ||
| }; | ||
|
|
||
| dropdownProps.placement = props?.placement ?? 'bottomRight'; | ||
|
|
||
| const leftButton = ( | ||
| <Button | ||
| size={size} | ||
| type={type} | ||
| disabled={disabled} | ||
| loading={loading} | ||
| onClick={onClick} | ||
| htmlType={htmlType} | ||
| title={title} | ||
| > | ||
| {children} | ||
| </Button> | ||
| ); | ||
|
|
||
| const rightButton = ( | ||
| <Button size={size} type={type}> | ||
| {icon ?? <EllipsisOutlined />} | ||
| </Button> | ||
| ); | ||
|
|
||
| const [leftButtonToRender, rightButtonToRender] = buttonsRender([leftButton, rightButton]); | ||
|
|
||
| return ( | ||
| <div {...restProps} className={classNames(prefixCls, className)}> | ||
| {leftButtonToRender} | ||
| <Dropdown {...dropdownProps}>{rightButtonToRender}</Dropdown> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DropdownButton; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import Dropdown from './dropdown'; | ||
| import DropdownButton from './dropdown-button'; | ||
| import './style.less'; | ||
|
|
||
| export { DropDownProps } from './dropdown'; | ||
|
|
||
| export { Dropdown }; | ||
| export { Dropdown, DropdownButton }; |
This file contains hidden or 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 hidden or 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
3 changes: 3 additions & 0 deletions
3
packages/core-browser/src/toolbar/components/dropdown-button.module.less
This file contains hidden or 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,3 @@ | ||
| .menu { | ||
| min-width: 100px !important; | ||
| } |
60 changes: 60 additions & 0 deletions
60
packages/core-browser/src/toolbar/components/dropdown-button.tsx
This file contains hidden or 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,60 @@ | ||
| import classnames from 'classnames'; | ||
| import React from 'react'; | ||
|
|
||
| import { DropdownButton, DropDownProps } from '@opensumi/ide-components'; | ||
| import { Menu } from '@opensumi/ide-components/lib/menu'; | ||
| import { Emitter } from '@opensumi/ide-core-common'; | ||
|
|
||
| import { IToolbarActionElementProps, IToolbarActionReactElement, IToolbarActionDropdownButtonProps } from '../types'; | ||
|
|
||
| import style from './dropdown-button.module.less'; | ||
|
|
||
| export function ToolbarActionDropdownButton<T>( | ||
|
hacke2 marked this conversation as resolved.
Outdated
|
||
| props: IToolbarActionDropdownButtonProps<T> & IToolbarActionElementProps, | ||
| ) { | ||
| const selectEmitter = React.useRef(new Emitter<T>()); | ||
| const [firstOption, ...otherOptions] = props.options; | ||
| React.useEffect(() => { | ||
| const _onChangeState = new Emitter<{ from: string; to: string }>(); | ||
| const delegate = { | ||
| onSelect: selectEmitter.current.event, | ||
| }; | ||
| props.delegate && props.delegate(delegate); | ||
| return () => { | ||
| props.delegate && props.delegate(undefined); | ||
| _onChangeState.dispose(); | ||
| }; | ||
| }, []); | ||
|
|
||
| const trigger = React.useMemo(() => props.trigger ?? (['click'] as DropDownProps['trigger']), [props.trigger]); | ||
|
|
||
| const handleClick = React.useCallback((value) => { | ||
| selectEmitter.current.fire(value); | ||
| }, []); | ||
|
|
||
| const menu = React.useMemo(() => ( | ||
| <Menu | ||
| className={classnames('kt-menu', style.menu)} | ||
| selectable={false} | ||
| motion={{ motionLeave: false, motionEnter: false }} | ||
| > | ||
| {otherOptions.map((option) => ( | ||
| <Menu.Item key={option.label} onClick={() => handleClick(option.value)}> | ||
| {option.label} | ||
| </Menu.Item> | ||
| ))} | ||
| </Menu> | ||
| ), []); | ||
|
|
||
| return ( | ||
| <DropdownButton size='small' onClick={() => handleClick(firstOption.value)} overlay={menu} trigger={trigger}> | ||
| {firstOption.label} | ||
| </DropdownButton> | ||
| ); | ||
| } | ||
|
|
||
| export function createToolbarActionDropdownButton<T = string>( | ||
| props: IToolbarActionDropdownButtonProps<T>, | ||
| ): IToolbarActionReactElement { | ||
| return (actionProps) => <ToolbarActionDropdownButton {...props} {...actionProps} />; | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './button'; | ||
| export * from './select'; | ||
| export * from './dropdown-button'; |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.