@availity/mui-button 0.1.3 → 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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.2.0](https://github.com/Availity/element/compare/@availity/mui-button@0.1.3...@availity/mui-button@0.2.0) (2023-06-01)
6
+
7
+
8
+ ### Features
9
+
10
+ * **mui-button:** design specs ([6b67b24](https://github.com/Availity/element/commit/6b67b24cdfef68e14daaeba18a5fd7d90af46a09))
11
+
5
12
  ## [0.1.3](https://github.com/Availity/element/compare/@availity/mui-button@0.1.2...@availity/mui-button@0.1.3) (2023-04-07)
6
13
 
7
14
  ## [0.1.2](https://github.com/Availity/element/compare/@availity/mui-button@0.1.1...@availity/mui-button@0.1.2) (2023-03-23)
package/dist/index.d.ts CHANGED
@@ -1,9 +1,44 @@
1
- import React from 'react';
2
- import { ButtonProps as ButtonProps$1 } from '@mui/material';
1
+ import * as react from 'react';
2
+ import * as _mui_material_OverridableComponent from '@mui/material/OverridableComponent';
3
+ import { ButtonProps as ButtonProps$1, IconButtonProps as IconButtonProps$1 } from '@mui/material';
4
+ import { LoadingButtonProps as LoadingButtonProps$1 } from '@mui/lab/LoadingButton';
3
5
 
4
6
  type ButtonProps = {
7
+ /** The color of the component.
8
+ * @default secondary */
9
+ color?: 'primary' | 'secondary' | 'tertiary' | 'error';
10
+ /** The variant to use.
11
+ * @default contained */
12
+ variant?: 'outlined' | 'contained';
13
+ /** Internal prop used by IconButton for contained variant. */
14
+ iconOnly?: boolean;
15
+ } & Omit<ButtonProps$1, 'color' | 'variant' | 'disableElevation' | 'disableFocusRipple' | 'disableTouchRipple' | 'centerRipple' | 'disableRipple' | 'focusRipple' | 'TouchRippleProps' | 'touchRippleRef'>;
16
+ declare const Button: react.ForwardRefExoticComponent<Pick<ButtonProps, keyof _mui_material_OverridableComponent.CommonProps | "form" | "slot" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "action" | "disabled" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "endIcon" | "fullWidth" | "href" | "size" | "startIcon" | "variant" | "key" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "type" | "value" | "iconOnly"> & react.RefAttributes<HTMLButtonElement>>;
17
+
18
+ type IconButtonProps = {
19
+ /**
20
+ * Text for tooltip and aria-label
21
+ */
22
+ title: string;
23
+ children: React.ReactNode;
24
+ /**
25
+ * Toggles contained Button styling
26
+ */
27
+ filled?: boolean;
28
+ /**
29
+ * The color of the component.
30
+ */
31
+ color?: "primary" | "secondary" | "tertiary" | "error";
32
+ } & Omit<IconButtonProps$1, 'aria-label' | 'color' | 'centerRipple' | 'disableRipple' | 'disableTouchRipple' | 'focusRipple' | 'disableFocusRipple' | 'TouchRippleProps' | 'touchRippleRef'>;
33
+ declare const IconButton: ({ children, title, filled, color, ...rest }: IconButtonProps) => JSX.Element;
34
+
35
+ type LoadingButtonProps = {
5
36
  children: React.ReactNode;
6
- } & ButtonProps$1;
7
- declare const Button: ({ children, ...rest }: ButtonProps) => JSX.Element;
37
+ /**
38
+ * The color of the component.
39
+ */
40
+ color?: 'primary' | 'secondary' | 'error';
41
+ } & Omit<LoadingButtonProps$1, 'color' | 'centerRipple' | 'disableRipple' | 'disableTouchRipple' | 'focusRipple' | 'disableFocusRipple' | 'TouchRippleProps' | 'touchRippleRef' | 'loadingIndicator' | 'loadingPosition'>;
42
+ declare const LoadingButton: react.ForwardRefExoticComponent<Pick<LoadingButtonProps, keyof _mui_material_OverridableComponent.CommonProps | "form" | "slot" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "action" | "disabled" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "disableElevation" | "endIcon" | "fullWidth" | "href" | "size" | "startIcon" | "variant" | "key" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "type" | "value" | "loading"> & react.RefAttributes<HTMLButtonElement>>;
8
43
 
9
- export { Button, ButtonProps };
44
+ export { Button, ButtonProps, IconButton, IconButtonProps, LoadingButton, LoadingButtonProps };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,23 +17,118 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
18
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
25
 
20
26
  // src/index.ts
21
27
  var src_exports = {};
22
28
  __export(src_exports, {
23
- Button: () => Button
29
+ Button: () => Button,
30
+ IconButton: () => IconButton,
31
+ LoadingButton: () => LoadingButton
24
32
  });
25
33
  module.exports = __toCommonJS(src_exports);
26
34
 
27
35
  // src/lib/Button.tsx
36
+ var import_react = require("react");
28
37
  var import_material = require("@mui/material");
29
38
  var import_jsx_runtime = require("react/jsx-runtime");
30
- var Button = ({ children, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Button, {
31
- ...rest,
32
- children
39
+ var tertiaryContainedStyles = {
40
+ bgcolor: "tertiary.main",
41
+ color: "black",
42
+ "&:focus, &:hover": {
43
+ bgcolor: "tertiary.dark"
44
+ },
45
+ "&:active": {
46
+ bgcolor: "tertiary.light"
47
+ }
48
+ };
49
+ var iconOnlyStyles = {
50
+ minWidth: 2,
51
+ px: 1,
52
+ "& .MuiButton-startIcon": {
53
+ m: 0
54
+ },
55
+ "& .MuiButton-endIcon": {
56
+ m: 0
57
+ }
58
+ };
59
+ var Button = (0, import_react.forwardRef)((props, ref) => {
60
+ const { color = "secondary", variant = "contained", iconOnly, sx, ...rest } = props;
61
+ const styles = {
62
+ ...color == "tertiary" && variant == "contained" && tertiaryContainedStyles,
63
+ ...iconOnly && iconOnlyStyles
64
+ };
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Button, {
66
+ color: color == "tertiary" ? "secondary" : color,
67
+ variant,
68
+ sx: { ...styles, ...sx },
69
+ disableRipple: true,
70
+ ...rest,
71
+ ref
72
+ });
73
+ });
74
+
75
+ // src/lib/IconButton.tsx
76
+ var import_material2 = require("@mui/material");
77
+ var import_jsx_runtime = require("react/jsx-runtime");
78
+ var IconButton = ({ children, title, filled, color = "tertiary", ...rest }) => {
79
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material2.Tooltip, {
80
+ title,
81
+ children: filled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
82
+ "aria-label": title,
83
+ color,
84
+ startIcon: children,
85
+ iconOnly: true,
86
+ ...rest,
87
+ children: "\u2060"
88
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material2.IconButton, {
89
+ "aria-label": title,
90
+ disableRipple: true,
91
+ color: color === "tertiary" ? "secondary" : color,
92
+ ...rest,
93
+ children
94
+ })
95
+ });
96
+ };
97
+
98
+ // src/lib/LoadingButton.tsx
99
+ var import_react2 = require("react");
100
+ var import_LoadingButton = __toESM(require("@mui/lab/LoadingButton"));
101
+ var import_CircularProgress = __toESM(require("@mui/material/CircularProgress"));
102
+ var import_jsx_runtime = require("react/jsx-runtime");
103
+ var LoadingIndicator = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CircularProgress.default, {
104
+ color: "inherit",
105
+ size: 16,
106
+ "aria-label": "loading"
107
+ });
108
+ var LoadingButton = (0, import_react2.forwardRef)((props, ref) => {
109
+ const { children, loading, ...rest } = props;
110
+ const loadingPosition = rest.startIcon ? "start" : "end";
111
+ const nonLoadingStyling = rest.startIcon || rest.endIcon || loading ? {} : { padding: "0 .7rem" };
112
+ const endIcon = rest.startIcon ? void 0 : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
113
+ style: loading ? { padding: "0 .7rem" } : {}
114
+ });
115
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_LoadingButton.default, {
116
+ endIcon,
117
+ loadingPosition,
118
+ loading,
119
+ disableRipple: true,
120
+ loadingIndicator: LoadingIndicator,
121
+ ...rest,
122
+ ref,
123
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
124
+ style: nonLoadingStyling,
125
+ children
126
+ })
127
+ });
33
128
  });
34
129
  // Annotate the CommonJS export names for ESM import in node:
35
130
  0 && (module.exports = {
36
- Button
131
+ Button,
132
+ IconButton,
133
+ LoadingButton
37
134
  });
package/dist/index.mjs CHANGED
@@ -1,10 +1,99 @@
1
1
  // src/lib/Button.tsx
2
+ import { forwardRef } from "react";
2
3
  import { Button as MUIButton } from "@mui/material";
3
4
  import { jsx } from "react/jsx-runtime";
4
- var Button = ({ children, ...rest }) => /* @__PURE__ */ jsx(MUIButton, {
5
- ...rest,
6
- children
5
+ var tertiaryContainedStyles = {
6
+ bgcolor: "tertiary.main",
7
+ color: "black",
8
+ "&:focus, &:hover": {
9
+ bgcolor: "tertiary.dark"
10
+ },
11
+ "&:active": {
12
+ bgcolor: "tertiary.light"
13
+ }
14
+ };
15
+ var iconOnlyStyles = {
16
+ minWidth: 2,
17
+ px: 1,
18
+ "& .MuiButton-startIcon": {
19
+ m: 0
20
+ },
21
+ "& .MuiButton-endIcon": {
22
+ m: 0
23
+ }
24
+ };
25
+ var Button = forwardRef((props, ref) => {
26
+ const { color = "secondary", variant = "contained", iconOnly, sx, ...rest } = props;
27
+ const styles = {
28
+ ...color == "tertiary" && variant == "contained" && tertiaryContainedStyles,
29
+ ...iconOnly && iconOnlyStyles
30
+ };
31
+ return /* @__PURE__ */ jsx(MUIButton, {
32
+ color: color == "tertiary" ? "secondary" : color,
33
+ variant,
34
+ sx: { ...styles, ...sx },
35
+ disableRipple: true,
36
+ ...rest,
37
+ ref
38
+ });
39
+ });
40
+
41
+ // src/lib/IconButton.tsx
42
+ import { IconButton as MuiIconButton, Tooltip } from "@mui/material";
43
+ import { jsx as jsx2 } from "react/jsx-runtime";
44
+ var IconButton = ({ children, title, filled, color = "tertiary", ...rest }) => {
45
+ return /* @__PURE__ */ jsx2(Tooltip, {
46
+ title,
47
+ children: filled ? /* @__PURE__ */ jsx2(Button, {
48
+ "aria-label": title,
49
+ color,
50
+ startIcon: children,
51
+ iconOnly: true,
52
+ ...rest,
53
+ children: "\u2060"
54
+ }) : /* @__PURE__ */ jsx2(MuiIconButton, {
55
+ "aria-label": title,
56
+ disableRipple: true,
57
+ color: color === "tertiary" ? "secondary" : color,
58
+ ...rest,
59
+ children
60
+ })
61
+ });
62
+ };
63
+
64
+ // src/lib/LoadingButton.tsx
65
+ import { forwardRef as forwardRef2 } from "react";
66
+ import MUILoadingButton from "@mui/lab/LoadingButton";
67
+ import CircularProgress from "@mui/material/CircularProgress";
68
+ import { jsx as jsx3 } from "react/jsx-runtime";
69
+ var LoadingIndicator = /* @__PURE__ */ jsx3(CircularProgress, {
70
+ color: "inherit",
71
+ size: 16,
72
+ "aria-label": "loading"
73
+ });
74
+ var LoadingButton = forwardRef2((props, ref) => {
75
+ const { children, loading, ...rest } = props;
76
+ const loadingPosition = rest.startIcon ? "start" : "end";
77
+ const nonLoadingStyling = rest.startIcon || rest.endIcon || loading ? {} : { padding: "0 .7rem" };
78
+ const endIcon = rest.startIcon ? void 0 : /* @__PURE__ */ jsx3("span", {
79
+ style: loading ? { padding: "0 .7rem" } : {}
80
+ });
81
+ return /* @__PURE__ */ jsx3(MUILoadingButton, {
82
+ endIcon,
83
+ loadingPosition,
84
+ loading,
85
+ disableRipple: true,
86
+ loadingIndicator: LoadingIndicator,
87
+ ...rest,
88
+ ref,
89
+ children: /* @__PURE__ */ jsx3("span", {
90
+ style: nonLoadingStyling,
91
+ children
92
+ })
93
+ });
7
94
  });
8
95
  export {
9
- Button
96
+ Button,
97
+ IconButton,
98
+ LoadingButton
10
99
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/mui-button",
3
- "version": "0.1.3",
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",
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './lib/Button';
2
+ export * from './lib/IconButton';
3
+ export * from './lib/LoadingButton';
@@ -1,15 +1,67 @@
1
- import React from 'react';
1
+ import { forwardRef } from 'react';
2
2
  import { Button as MUIButton } from '@mui/material';
3
3
  import type { ButtonProps as MUIButtonProps } from '@mui/material';
4
4
 
5
5
  export type ButtonProps = {
6
- children: React.ReactNode;
7
- } & MUIButtonProps;
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
+ >;
8
27
 
9
- export const Button = ({ children, ...rest }: ButtonProps): JSX.Element => (
10
- <MUIButton {...rest}>
11
- {children}
12
- </MUIButton>
13
- );
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
+ };
14
38
 
39
+ const iconOnlyStyles = {
40
+ minWidth: 2,
41
+ px: 1,
42
+ '& .MuiButton-startIcon': {
43
+ m: 0,
44
+ },
45
+ '& .MuiButton-endIcon': {
46
+ m: 0,
47
+ },
48
+ };
15
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
+ };
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
+ }
@@ -1,14 +1,47 @@
1
- import React from 'react';
2
- import MUILoadingButton, { LoadingButtonProps as MuiLoadingButtonProps} from '@mui/lab/LoadingButton';
1
+ import { forwardRef } from 'react';
2
+ import MUILoadingButton, { LoadingButtonProps as MuiLoadingButtonProps } from '@mui/lab/LoadingButton';
3
+ import CircularProgress from '@mui/material/CircularProgress';
3
4
 
4
5
  export type LoadingButtonProps = {
5
6
  children: React.ReactNode;
6
- } & MuiLoadingButtonProps;
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
+ >;
7
24
 
8
- export const LoadingButton = ({ children, ...rest }: LoadingButtonProps): JSX.Element => (
9
- <MUILoadingButton {...rest}>
10
- {children}
11
- </MUILoadingButton>
12
- );
25
+ const LoadingIndicator = <CircularProgress color="inherit" size={16} aria-label="loading" />;
13
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>;
14
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
+ });