feat(controllers): ✨ add new input and button components
* Introduced ButtonCtrl, IconButtonCtrl, NativeSelectCtrl, PasswordInputCtrl, SwitchCtrl, TextAreaCtrl, TextInputCtrl * Updated FormerControllers.types.ts to include SpecialIDProps * Enhanced lib.ts to export new components
This commit is contained in:
36
src/FormerControllers/Buttons/IconButtonCtrl.tsx
Normal file
36
src/FormerControllers/Buttons/IconButtonCtrl.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { ActionIcon, type ActionIconProps, Tooltip, VisuallyHidden } from '@mantine/core';
|
||||
import { useState } from 'react';
|
||||
|
||||
import type { SpecialIDProps } from '../FormerControllers.types';
|
||||
|
||||
const IconButtonCtrl = (
|
||||
props: {
|
||||
onClick?: (e?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<void>;
|
||||
} & Omit<ActionIconProps, 'onClick'> &
|
||||
SpecialIDProps
|
||||
) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
return (
|
||||
<Tooltip label={props.tooltip ?? ''} withArrow>
|
||||
<ActionIcon
|
||||
loaderProps={{
|
||||
type: 'bars',
|
||||
}}
|
||||
{...props}
|
||||
loading={loading || props.loading}
|
||||
onClick={(e) => {
|
||||
if (props.onClick) {
|
||||
setLoading(true);
|
||||
props.onClick(e).finally(() => setLoading(false));
|
||||
}
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
<VisuallyHidden>Action Button: {props.tooltip ?? props.sid ?? ''}</VisuallyHidden>
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
export { IconButtonCtrl };
|
||||
export default IconButtonCtrl;
|
||||
Reference in New Issue
Block a user