dev: IconBtn.ref

Massimo Melina committed Aug 6, 2023 at 23:49 UTC 0c4647143eaa8295aa75407f7c241ea839d9d3f4
1 file changed +4 -3
admin/src/misc.ts
+4 -3
@@ -1,6 +1,6 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 -import { createElement as h, FC, Fragment, ReactNode, KeyboardEvent } from 'react'
3 +import { createElement as h, FC, Fragment, ReactNode, KeyboardEvent, forwardRef } from 'react'
4 import {
5 Box,
6 Breakpoint,
@@ -50,13 +50,14 @@ interface IconBtnProps extends Omit<IconButtonProps, 'disabled'|'title'|'onClick
50 onClick: (...args: Parameters<NonNullable<IconButtonProps['onClick']>>) => Promisable<any>
51 }
52
53 -export function IconBtn({ title, icon, onClick, disabled, progress, link, tooltipProps, confirm, ...rest }: IconBtnProps) {
53 +export const IconBtn = forwardRef(({ title, icon, onClick, disabled, progress, link, tooltipProps, confirm, ...rest }: IconBtnProps, ref: any) => {
54 const [loading, setLoading] = useStateMounted(false)
55 if (typeof disabled === 'string')
56 title = disabled
57 if (link)
58 onClick = () => window.open(link)
59 let ret: ReturnType<FC> = h(IconButton, {
60 + ref,
61 disabled: Boolean(loading || progress || disabled),
62 ...rest,
63 async onClick(...args) {
@@ -79,7 +80,7 @@ export function IconBtn({ title, icon, onClick, disabled, progress, link, toolti
80 if (title)
81 ret = h(Tooltip, { title, ...tooltipProps, children: h('span',{},ret) })
82 return ret
82 -}
83 +})
84
85 interface BtnProps extends Omit<LoadingButtonProps,'disabled'|'title'|'onClick'> {
86 icon: SvgIconComponent