-
Notifications
You must be signed in to change notification settings - Fork 345
feat(drawer): add DrawerPlugin #3381
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 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
115a87c
feat: drawerPlugin
Wesley-0808 a2b46f4
feat: drawerPlugin
Wesley-0808 86db0fe
chore: docs & export
Wesley-0808 17e4bec
feat: drawerPlugin Demos
Wesley-0808 5b6b444
test: update
Wesley-0808 e565ec7
fix: not Set State
Wesley-0808 f0b0df0
Squashed commit of the following:
Wesley-0808 fd5c645
chore: mono
Wesley-0808 677dddc
chore: update test
Wesley-0808 0eb9e9a
Merge branch 'develop' into feat/drawerPlugin
Wesley-0808 aa27208
feat: add drawerPlugin
Wesley-0808 98754b0
feat: add drawerPlugin
Wesley-0808 c2208e8
chore: effect
Wesley-0808 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
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,59 @@ | ||
import React from 'react'; | ||
import { DrawerPlugin, Button, Space } from 'tdesign-react'; | ||
|
||
const buttonStyle = { marginRight: 16 }; | ||
|
||
export default function PluginModalExample() { | ||
const showDrawer = () => { | ||
const myDrawer = DrawerPlugin({ | ||
header: 'Drawer-Plugin', | ||
body: 'Hi, darling! Do you want to be my lover?', | ||
onConfirm: ({ e }) => { | ||
console.log('confirm clicked', e); | ||
myDrawer.hide(); | ||
}, | ||
onClose: ({ e, trigger }) => { | ||
console.log('e: ', e); | ||
console.log('trigger: ', trigger); | ||
myDrawer.hide(); | ||
}, | ||
onCloseBtnClick: ({ e }) => { | ||
console.log('close btn: ', e); | ||
}, | ||
}); | ||
}; | ||
const onDrawerPlugin = () => { | ||
const Drawer = DrawerPlugin({ | ||
header: 'Drawer-Confirm-Plugin', | ||
body: 'I am a drawer!', | ||
confirmBtn: 'hello', | ||
cancelBtn: 'bye', | ||
size: 'large', | ||
className: 't-class-drawer--first', | ||
onConfirm: ({ e }) => { | ||
console.log('confirm button has been clicked!'); | ||
console.log('e: ', e); | ||
Drawer.hide(); | ||
}, | ||
onClose: ({ e, trigger }) => { | ||
console.log('e: ', e); | ||
console.log('trigger: ', trigger); | ||
Drawer.hide(); | ||
}, | ||
}); | ||
}; | ||
return ( | ||
<Space direction="vertical"> | ||
<p>函数调用方式一:DrawerPlugin(options)</p> | ||
<p>函数调用方式二:drawer(options)</p> | ||
<div> | ||
<Button theme="primary" onClick={showDrawer} style={buttonStyle}> | ||
DrawerPlugin | ||
</Button> | ||
<Button theme="primary" onClick={onDrawerPlugin} style={buttonStyle}> | ||
drawer | ||
</Button> | ||
</div> | ||
</Space> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import _Drawer from './Drawer'; | ||
import { DrawerPlugin as _DrawerPlugin } from './plugin'; | ||
|
||
import './style/index.js'; | ||
|
||
export type { DrawerProps } from './Drawer'; | ||
export * from './type'; | ||
|
||
export const Drawer = _Drawer; | ||
|
||
export const drawer = _DrawerPlugin; | ||
uyarn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export const DrawerPlugin = _DrawerPlugin; | ||
|
||
export default Drawer; |
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,55 @@ | ||
import React from 'react'; | ||
import { render } from '../_util/react-render'; | ||
import DrawerComponent, { DrawerProps } from './Drawer'; | ||
|
||
import { getAttach } from '../_util/dom'; | ||
import { DrawerOptions, DrawerMethod, DrawerInstance } from './type'; | ||
Wesley-0808 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import log from '../../common/js/log'; | ||
Wesley-0808 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const createDrawer: DrawerMethod = (props: DrawerOptions): DrawerInstance => { | ||
const drawerRef = React.createRef<DrawerInstance>(); | ||
const options = { ...props }; | ||
Wesley-0808 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 默认先不出现。如有更好的方法,请代替↓ | ||
const { visible = false } = options; | ||
|
||
const fragment = document.createDocumentFragment(); | ||
render(<DrawerComponent {...(options as DrawerProps)} visible={visible} ref={drawerRef} isPlugin />, fragment); | ||
|
||
const container = getAttach(options.attach); | ||
if (container) { | ||
// 抽屉加载出来了再设置出现,才有出现动画。如有更好的方法,请代替↓ | ||
requestAnimationFrame(() => { | ||
drawerRef.current?.show(); | ||
}); | ||
container.appendChild(fragment); | ||
} else { | ||
log.error('Drawer', 'attach is not exist'); | ||
} | ||
|
||
const drawerNode: DrawerInstance = { | ||
show: () => { | ||
requestAnimationFrame(() => { | ||
drawerRef.current?.show(); | ||
}); | ||
}, | ||
hide: () => { | ||
requestAnimationFrame(() => { | ||
drawerRef.current?.destroy(); | ||
}); | ||
}, | ||
update: (updateOptions: DrawerOptions) => { | ||
requestAnimationFrame(() => { | ||
drawerRef.current?.update(updateOptions); | ||
}); | ||
}, | ||
destroy: () => { | ||
requestAnimationFrame(() => { | ||
drawerRef.current?.destroy(); | ||
}); | ||
}, | ||
}; | ||
return drawerNode; | ||
}; | ||
|
||
export const DrawerPlugin = createDrawer; |
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.