Skip to content

Commit

Permalink
release(toolbar): v0.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Mar 4, 2024
1 parent 3426765 commit 6469a30
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
},
"toolbar": {
"react": true,
"version": "0.5.2",
"version": "0.5.3",
"style": true,
"icon": false,
"test": true,
Expand Down
2 changes: 1 addition & 1 deletion src/toolbar/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "toolbar",
"version": "0.5.2",
"version": "0.5.3",
"description": "Application toolbar",
"luna": {
"react": true
Expand Down
13 changes: 10 additions & 3 deletions src/toolbar/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,23 @@ export const LunaToolbarText: FC<IToolbarTextProps> = (props) => {
}

interface IToolbarButtonProps extends IToolbarItemProps {
content: string | HTMLElement
onClick: () => void
state?: IButtonState
}

export const LunaToolbarButton: FC<IToolbarButtonProps> = (props) => {
const toolbarButton = useRef<ToolbarButton>()
const forceUpdate = useForceUpdate()

useEffect(() => {
if (props.toolbar) {
toolbarButton.current = props.toolbar.appendButton(
props.content,
'',
props.onClick,
props.state
)
forceUpdate()
setDisabled(toolbarButton.current, props.disabled)
}

return () => toolbarButton.current?.detach()
Expand All @@ -111,7 +113,12 @@ export const LunaToolbarButton: FC<IToolbarButtonProps> = (props) => {
}
}, [props.state])

return null
return toolbarButton.current
? createPortal(
<>{props.children}</>,
toolbarButton.current.container.querySelector('button')!
)
: null
}

interface IToolbarSelectProps extends IToolbarItemProps {
Expand Down
5 changes: 3 additions & 2 deletions src/toolbar/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ const def = story(
disabled={true}
/>
<LunaToolbarButton
content="Trigger"
onClick={() => console.log('trigger')}
state="hover"
/>
>
Trigger
</LunaToolbarButton>
<LunaToolbarSpace />
<LunaToolbarHtml>
<span
Expand Down

0 comments on commit 6469a30

Please sign in to comment.