@availity/mui-button 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/index.d.ts +40 -6
- package/dist/index.js +85 -1278
- package/dist/index.mjs +85 -1300
- package/package.json +4 -1
- package/src/index.ts +2 -0
- package/src/lib/Button.tsx +59 -15
- package/src/lib/IconButton.tsx +35 -0
- package/src/lib/LoadingButton.tsx +47 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/mui-button",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Availity MUI Button Component - part of the @availity/element design system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
"publish": "yarn npm publish --tolerate-republish --access public",
|
|
34
34
|
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
35
35
|
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@mui/lab": "^5.0.0-alpha.121"
|
|
38
|
+
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"@mui/material": "^5.11.9",
|
|
38
41
|
"react": "18.2.0",
|
package/src/index.ts
CHANGED
package/src/lib/Button.tsx
CHANGED
|
@@ -1,23 +1,67 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
2
|
import { Button as MUIButton } from '@mui/material';
|
|
3
|
-
import {LoadingButton as MUILoadingButton} from '@mui/lab'
|
|
4
3
|
import type { ButtonProps as MUIButtonProps } from '@mui/material';
|
|
5
|
-
// import Icon from '@availity/mui-icon';
|
|
6
4
|
|
|
7
5
|
export type ButtonProps = {
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/** The color of the component.
|
|
7
|
+
* @default secondary */
|
|
8
|
+
color?: 'primary' | 'secondary' | 'tertiary' | 'error';
|
|
9
|
+
/** The variant to use.
|
|
10
|
+
* @default contained */
|
|
11
|
+
variant?: 'outlined' | 'contained';
|
|
12
|
+
/** Internal prop used by IconButton for contained variant. */
|
|
13
|
+
iconOnly?: boolean;
|
|
14
|
+
} & Omit<
|
|
15
|
+
MUIButtonProps,
|
|
16
|
+
| 'color'
|
|
17
|
+
| 'variant'
|
|
18
|
+
| 'disableElevation'
|
|
19
|
+
| 'disableFocusRipple'
|
|
20
|
+
| 'disableTouchRipple'
|
|
21
|
+
| 'centerRipple'
|
|
22
|
+
| 'disableRipple'
|
|
23
|
+
| 'focusRipple'
|
|
24
|
+
| 'TouchRippleProps'
|
|
25
|
+
| 'touchRippleRef'
|
|
26
|
+
>;
|
|
10
27
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
const tertiaryContainedStyles = {
|
|
29
|
+
bgcolor: 'tertiary.main',
|
|
30
|
+
color: 'black',
|
|
31
|
+
'&:focus, &:hover': {
|
|
32
|
+
bgcolor: 'tertiary.dark',
|
|
33
|
+
},
|
|
34
|
+
'&:active': {
|
|
35
|
+
bgcolor: 'tertiary.light',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
16
38
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
const iconOnlyStyles = {
|
|
40
|
+
minWidth: 2,
|
|
41
|
+
px: 1,
|
|
42
|
+
'& .MuiButton-startIcon': {
|
|
43
|
+
m: 0,
|
|
44
|
+
},
|
|
45
|
+
'& .MuiButton-endIcon': {
|
|
46
|
+
m: 0,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
22
49
|
|
|
50
|
+
export const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
|
|
51
|
+
const { color = 'secondary', variant = 'contained', iconOnly, sx, ...rest } = props;
|
|
52
|
+
const styles = {
|
|
53
|
+
...(color == 'tertiary' && variant == 'contained' && tertiaryContainedStyles),
|
|
54
|
+
...(iconOnly && iconOnlyStyles),
|
|
55
|
+
};
|
|
23
56
|
|
|
57
|
+
return (
|
|
58
|
+
<MUIButton
|
|
59
|
+
color={color == 'tertiary' ? 'secondary' : color}
|
|
60
|
+
variant={variant}
|
|
61
|
+
sx={{ ...styles, ...sx }}
|
|
62
|
+
disableRipple
|
|
63
|
+
{...rest}
|
|
64
|
+
ref={ref}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IconButton as MuiIconButton, Tooltip } from '@mui/material';
|
|
2
|
+
import type { IconButtonProps as MUIIconButtonProps } from '@mui/material';
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
|
|
5
|
+
export type IconButtonProps = {
|
|
6
|
+
/**
|
|
7
|
+
* Text for tooltip and aria-label
|
|
8
|
+
*/
|
|
9
|
+
title: string;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* Toggles contained Button styling
|
|
13
|
+
*/
|
|
14
|
+
filled?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The color of the component.
|
|
17
|
+
*/
|
|
18
|
+
color?: "primary" | "secondary" | "tertiary" | "error";
|
|
19
|
+
} & Omit<MUIIconButtonProps, 'aria-label' | 'color' | 'centerRipple' | 'disableRipple' | 'disableTouchRipple' | 'focusRipple' | 'disableFocusRipple' | 'TouchRippleProps' | 'touchRippleRef'>;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export const IconButton = ({ children, title, filled, color = 'tertiary', ...rest }: IconButtonProps): JSX.Element => {
|
|
24
|
+
return (
|
|
25
|
+
<Tooltip title={title}>
|
|
26
|
+
{ filled ?
|
|
27
|
+
<Button aria-label={title} color={color} startIcon={children} iconOnly {...rest}>{'\u2060'}</Button>
|
|
28
|
+
:
|
|
29
|
+
<MuiIconButton aria-label={title} disableRipple color={color === 'tertiary' ? 'secondary' : color} {...rest}>
|
|
30
|
+
{children}
|
|
31
|
+
</MuiIconButton>
|
|
32
|
+
}
|
|
33
|
+
</Tooltip>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import MUILoadingButton, { LoadingButtonProps as MuiLoadingButtonProps } from '@mui/lab/LoadingButton';
|
|
3
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
|
4
|
+
|
|
5
|
+
export type LoadingButtonProps = {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* The color of the component.
|
|
9
|
+
*/
|
|
10
|
+
color?: 'primary' | 'secondary' | 'error';
|
|
11
|
+
} & Omit<
|
|
12
|
+
MuiLoadingButtonProps,
|
|
13
|
+
| 'color'
|
|
14
|
+
| 'centerRipple'
|
|
15
|
+
| 'disableRipple'
|
|
16
|
+
| 'disableTouchRipple'
|
|
17
|
+
| 'focusRipple'
|
|
18
|
+
| 'disableFocusRipple'
|
|
19
|
+
| 'TouchRippleProps'
|
|
20
|
+
| 'touchRippleRef'
|
|
21
|
+
| 'loadingIndicator'
|
|
22
|
+
| 'loadingPosition'
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
const LoadingIndicator = <CircularProgress color="inherit" size={16} aria-label="loading" />;
|
|
26
|
+
|
|
27
|
+
export const LoadingButton = forwardRef<HTMLButtonElement, LoadingButtonProps>((props, ref) => {
|
|
28
|
+
const { children, loading, ...rest } = props;
|
|
29
|
+
//changing default loading button behavior to add end loading icon instead of replacing contents completely with icon
|
|
30
|
+
const loadingPosition = rest.startIcon ? 'start' : 'end';
|
|
31
|
+
const nonLoadingStyling = rest.startIcon || rest.endIcon || loading ? {} : { padding: '0 .7rem' };
|
|
32
|
+
const endIcon = rest.startIcon ? undefined : <span style={loading ? { padding: '0 .7rem' } : {}}></span>;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<MUILoadingButton
|
|
36
|
+
endIcon={endIcon}
|
|
37
|
+
loadingPosition={loadingPosition}
|
|
38
|
+
loading={loading}
|
|
39
|
+
disableRipple
|
|
40
|
+
loadingIndicator={LoadingIndicator}
|
|
41
|
+
{...rest}
|
|
42
|
+
ref={ref}
|
|
43
|
+
>
|
|
44
|
+
<span style={nonLoadingStyling}>{children}</span>
|
|
45
|
+
</MUILoadingButton>
|
|
46
|
+
);
|
|
47
|
+
});
|