Skip to content

Commit

Permalink
release(toolbar): v0.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed May 10, 2024
1 parent 2e5b713 commit 4ee1e05
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 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.6",
"version": "0.5.7",
"style": true,
"icon": false,
"test": true,
Expand Down
9 changes: 9 additions & 0 deletions src/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export type IButtonState = '' | 'hover' | 'active'

export class LunaToolbarButton extends LunaToolbarItem {
private $button: $.$
private handler: types.AnyFn
constructor(
toolbar: Toolbar,
content: string | HTMLElement,
Expand All @@ -266,6 +267,7 @@ export class LunaToolbarButton extends LunaToolbarItem {
const $button = this.$container.find('button')
$button.append(content)
$button.on('click', handler)
this.handler = handler
this.$button = $button

this.setState(state)
Expand All @@ -277,6 +279,13 @@ export class LunaToolbarButton extends LunaToolbarItem {
$button.addClass(this.toolbar.c(state))
}
}
setHandler(handler: types.AnyFn) {
const { $button } = this

$button.off('click', this.handler)
$button.on('click', handler)
this.handler = handler
}
}

export class LunaToolbarHtml extends LunaToolbarItem {
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.6",
"version": "0.5.7",
"description": "Application toolbar",
"luna": {
"react": true
Expand Down
6 changes: 6 additions & 0 deletions src/toolbar/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ export const LunaToolbarButton: FC<PropsWithChildren<IToolbarButtonProps>> = (
}
}, [props.state])

useEffect(() => {
if (toolbarButton.current && props.onClick) {
toolbarButton.current.setHandler(props.onClick)
}
}, [props.onClick])

useEffect(
() => setDisabled(toolbarButton.current, props.disabled),
[props.disabled]
Expand Down

0 comments on commit 4ee1e05

Please sign in to comment.