@availity/mui-textfield 0.1.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 +20 -0
- package/README.md +61 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +94 -0
- package/dist/index.mjs +61 -0
- package/introduction.mdx +7 -0
- package/jest.config.js +7 -0
- package/package.json +53 -0
- package/project.json +42 -0
- package/src/index.ts +1 -0
- package/src/lib/TextField.stories.tsx +45 -0
- package/src/lib/TextField.test.tsx +9 -0
- package/src/lib/TextField.tsx +60 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
## 0.1.0 (2023-09-25)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **mui-form-utils:** move Input to form-utils pkg ([991596c](https://github.com/Availity/element/commit/991596c5256360979c58e4e7c36313a7f1f4ce09))
|
|
11
|
+
* **mui-textfield:** add textfield component ([edf7e72](https://github.com/Availity/element/commit/edf7e728e9e8a79ee78219e41fc5659d175d70e5))
|
|
12
|
+
* **mui-textfield:** add textfield component ([fec1a7f](https://github.com/Availity/element/commit/fec1a7fedda2420577e29b6c0e264d244a91a00e))
|
|
13
|
+
* **mui-textfield:** update styles ([69f8291](https://github.com/Availity/element/commit/69f82910269a6fdcd2b5de852b3c8a777c09b24d))
|
|
14
|
+
* **mui-textfield:** use mui-form-utils ([9623a25](https://github.com/Availity/element/commit/9623a25fc8b6cfafa8c53e383450f501f3068af8))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **mui-textfield:** fix test ([81d11c4](https://github.com/Availity/element/commit/81d11c47900aaccd7bf2d27a2c6ec51544083325))
|
|
20
|
+
* **mui-textfield:** remove unneeded aria-labelledby ([2c20c98](https://github.com/Availity/element/commit/2c20c98eee1f163525b0198cf4b9f5188342c09a))
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @availity/mui-textfield
|
|
2
|
+
|
|
3
|
+
> Availity MUI Textfield component to be used with @availity/element design system.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@availity/mui-textfield)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/mui-textfield)
|
|
7
|
+
[](https://github.com/Availity/element/blob/main/packages/mui-textfield/package.json)
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
This package extends the MUI Textfield component: [MUI Textfield Docs](https://mui.com/components/textfield/)
|
|
12
|
+
|
|
13
|
+
Live demo and documentation in our [Storybook](https://availity.github.io/element/?path=/docs/components-textfield-introduction--docs)
|
|
14
|
+
|
|
15
|
+
Availity standards for design and usage can be found in the [Availity Design Guide](https://zeroheight.com/2e36e50c7)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Import Through @availity/element (Recommended)
|
|
20
|
+
|
|
21
|
+
#### NPM
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @availity/element
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Yarn
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add @availity/element
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Direct Import
|
|
34
|
+
|
|
35
|
+
#### NPM
|
|
36
|
+
|
|
37
|
+
_This package has a few peer dependencies. Add `@mui/material` & `@emotion/react` to your project if not already installed._
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @availity/mui-textfield
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Yarn
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
yarn add @availity/mui-textfield
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Usage
|
|
50
|
+
|
|
51
|
+
#### Import through @availity/element
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { Textfield } from '@availity/element';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Direct import
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { Textfield } from '@availity/mui-textfield';
|
|
61
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { InputProps } from '@availity/mui-form-utils';
|
|
3
|
+
|
|
4
|
+
type TextFieldProps = {
|
|
5
|
+
helperText?: string;
|
|
6
|
+
} & Omit<InputProps, 'aria-describedby' | 'classes' | 'disableInjectingGlobalStyles' | 'color' | 'multiline' | 'notched' | 'fullWidth' | 'inputProps'>;
|
|
7
|
+
declare const TextField: react.ForwardRefExoticComponent<Pick<TextFieldProps, "className" | "style" | "label" | "slot" | "title" | "id" | "lang" | "name" | "type" | "role" | "tabIndex" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "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" | "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" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "nonce" | "placeholder" | "spellCheck" | "translate" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "autoFocus" | "disabled" | "value" | "autoComplete" | "readOnly" | "required" | "size" | "rows" | "error" | "margin" | "inputRef" | "endAdornment" | "renderSuffix" | "maxRows" | "minRows" | "startAdornment" | "helperText"> & react.RefAttributes<unknown>>;
|
|
8
|
+
|
|
9
|
+
export { TextField, TextFieldProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var src_exports = {};
|
|
28
|
+
__export(src_exports, {
|
|
29
|
+
TextField: () => TextField
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
|
|
33
|
+
// src/lib/TextField.tsx
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var import_FormControl = __toESM(require("@mui/material/FormControl"));
|
|
36
|
+
var import_InputAdornment = __toESM(require("@mui/material/InputAdornment"));
|
|
37
|
+
var import_FormHelperText = __toESM(require("@mui/material/FormHelperText"));
|
|
38
|
+
var import_mui_form_utils = require("@availity/mui-form-utils");
|
|
39
|
+
var import_mui_icon = require("@availity/mui-icon");
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
var smallStyles = { sx: { padding: "8px 8px" } };
|
|
42
|
+
var mediumStyles = { sx: { padding: "16px 8px" } };
|
|
43
|
+
var iconStyles = { marginRight: "4px", paddingTop: "4px" };
|
|
44
|
+
var TextField = (0, import_react.forwardRef)(
|
|
45
|
+
({ error, helperText, id, label, startAdornment, endAdornment, required, size, ...rest }, ref) => {
|
|
46
|
+
const labelId = `${id}-label`;
|
|
47
|
+
const helperId = `${id}-helper-text`;
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_FormControl.default, {
|
|
49
|
+
size: "small",
|
|
50
|
+
children: [
|
|
51
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_form_utils.FormLabel, {
|
|
52
|
+
id: labelId,
|
|
53
|
+
htmlFor: id,
|
|
54
|
+
required,
|
|
55
|
+
error: !!error,
|
|
56
|
+
disabled: rest.disabled,
|
|
57
|
+
children: label
|
|
58
|
+
}),
|
|
59
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_form_utils.Input, {
|
|
60
|
+
inputRef: ref,
|
|
61
|
+
id,
|
|
62
|
+
"aria-describedby": helperId,
|
|
63
|
+
error: !!error,
|
|
64
|
+
inputProps: size === "medium" ? mediumStyles : smallStyles,
|
|
65
|
+
startAdornment: startAdornment ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_InputAdornment.default, {
|
|
66
|
+
position: "start",
|
|
67
|
+
children: startAdornment
|
|
68
|
+
}) : void 0,
|
|
69
|
+
endAdornment: endAdornment ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_InputAdornment.default, {
|
|
70
|
+
position: "end",
|
|
71
|
+
children: endAdornment
|
|
72
|
+
}) : void 0,
|
|
73
|
+
size,
|
|
74
|
+
...rest
|
|
75
|
+
}),
|
|
76
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_FormHelperText.default, {
|
|
77
|
+
id: helperId,
|
|
78
|
+
error,
|
|
79
|
+
children: [
|
|
80
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_icon.WarningTriangleIcon, {
|
|
81
|
+
sx: iconStyles
|
|
82
|
+
}),
|
|
83
|
+
helperText
|
|
84
|
+
]
|
|
85
|
+
})
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
TextField.displayName = "TextField";
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
TextField
|
|
94
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/lib/TextField.tsx
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import FormControl from "@mui/material/FormControl";
|
|
4
|
+
import InputAdornment from "@mui/material/InputAdornment";
|
|
5
|
+
import FormHelperText from "@mui/material/FormHelperText";
|
|
6
|
+
import { FormLabel, Input } from "@availity/mui-form-utils";
|
|
7
|
+
import { WarningTriangleIcon } from "@availity/mui-icon";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
var smallStyles = { sx: { padding: "8px 8px" } };
|
|
10
|
+
var mediumStyles = { sx: { padding: "16px 8px" } };
|
|
11
|
+
var iconStyles = { marginRight: "4px", paddingTop: "4px" };
|
|
12
|
+
var TextField = forwardRef(
|
|
13
|
+
({ error, helperText, id, label, startAdornment, endAdornment, required, size, ...rest }, ref) => {
|
|
14
|
+
const labelId = `${id}-label`;
|
|
15
|
+
const helperId = `${id}-helper-text`;
|
|
16
|
+
return /* @__PURE__ */ jsxs(FormControl, {
|
|
17
|
+
size: "small",
|
|
18
|
+
children: [
|
|
19
|
+
label && /* @__PURE__ */ jsx(FormLabel, {
|
|
20
|
+
id: labelId,
|
|
21
|
+
htmlFor: id,
|
|
22
|
+
required,
|
|
23
|
+
error: !!error,
|
|
24
|
+
disabled: rest.disabled,
|
|
25
|
+
children: label
|
|
26
|
+
}),
|
|
27
|
+
/* @__PURE__ */ jsx(Input, {
|
|
28
|
+
inputRef: ref,
|
|
29
|
+
id,
|
|
30
|
+
"aria-describedby": helperId,
|
|
31
|
+
error: !!error,
|
|
32
|
+
inputProps: size === "medium" ? mediumStyles : smallStyles,
|
|
33
|
+
startAdornment: startAdornment ? /* @__PURE__ */ jsx(InputAdornment, {
|
|
34
|
+
position: "start",
|
|
35
|
+
children: startAdornment
|
|
36
|
+
}) : void 0,
|
|
37
|
+
endAdornment: endAdornment ? /* @__PURE__ */ jsx(InputAdornment, {
|
|
38
|
+
position: "end",
|
|
39
|
+
children: endAdornment
|
|
40
|
+
}) : void 0,
|
|
41
|
+
size,
|
|
42
|
+
...rest
|
|
43
|
+
}),
|
|
44
|
+
/* @__PURE__ */ jsxs(FormHelperText, {
|
|
45
|
+
id: helperId,
|
|
46
|
+
error,
|
|
47
|
+
children: [
|
|
48
|
+
error && /* @__PURE__ */ jsx(WarningTriangleIcon, {
|
|
49
|
+
sx: iconStyles
|
|
50
|
+
}),
|
|
51
|
+
helperText
|
|
52
|
+
]
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
TextField.displayName = "TextField";
|
|
59
|
+
export {
|
|
60
|
+
TextField
|
|
61
|
+
};
|
package/introduction.mdx
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/mui-textfield",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Availity MUI Textfield Component - part of the @availity/element design system",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"typescript",
|
|
8
|
+
"availity",
|
|
9
|
+
"mui"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://availity.github.io/element/?path=/docs/components-textfield-introduction--docs",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Availity/element/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/Availity/element.git",
|
|
18
|
+
"directory": "packages/textfield"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Availity Developers <AVOSS@availity.com>",
|
|
22
|
+
"browser": "./dist/index.js",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
28
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
29
|
+
"clean": "rm -rf dist",
|
|
30
|
+
"clean:nm": "rm -rf node_modules",
|
|
31
|
+
"bundlesize": "bundlesize",
|
|
32
|
+
"publish": "yarn npm publish --tolerate-republish --access public",
|
|
33
|
+
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@availity/mui-form-utils": "0.3.0",
|
|
37
|
+
"@availity/mui-icon": "0.5.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@mui/material": "^5.11.9",
|
|
41
|
+
"react": "18.2.0",
|
|
42
|
+
"react-dom": "18.2.0",
|
|
43
|
+
"tsup": "^5.12.7",
|
|
44
|
+
"typescript": "^4.6.4"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@mui/material": "^5.11.9",
|
|
48
|
+
"react": ">=16.3.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mui-textfield",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/textfield/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nrwl/linter:eslint",
|
|
10
|
+
"options": {
|
|
11
|
+
"eslintConfig": ".eslintrc.json",
|
|
12
|
+
"lintFilePatterns": ["packages/textfield/**/*.{js,ts}"],
|
|
13
|
+
"silent": false,
|
|
14
|
+
"fix": false,
|
|
15
|
+
"cache": true,
|
|
16
|
+
"cacheLocation": "./node_modules/.cache/textfield/.eslintcache",
|
|
17
|
+
"maxWarnings": -1,
|
|
18
|
+
"quiet": false,
|
|
19
|
+
"noEslintrc": false,
|
|
20
|
+
"hasTypeAwareRules": true,
|
|
21
|
+
"cacheStrategy": "metadata"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"test": {
|
|
25
|
+
"executor": "@nrwl/jest:jest",
|
|
26
|
+
"outputs": ["coverage/textfield"],
|
|
27
|
+
"options": {
|
|
28
|
+
"jestConfig": "packages/textfield/jest.config.js",
|
|
29
|
+
"passWithNoTests": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"version": {
|
|
33
|
+
"executor": "@jscutlery/semver:version",
|
|
34
|
+
"options": {
|
|
35
|
+
"preset": "conventional",
|
|
36
|
+
"commitMessageFormat": "chore(${projectName}): release version ${version} [skip ci]",
|
|
37
|
+
"tagPrefix": "@availity/${projectName}@"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"trackDeps": true
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/TextField';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import { EyeIcon, EyeSlashIcon } from '@availity/mui-icon';
|
|
5
|
+
import { IconButton } from '@availity/mui-button';
|
|
6
|
+
|
|
7
|
+
import { TextField, TextFieldProps } from './TextField';
|
|
8
|
+
|
|
9
|
+
const meta: Meta<typeof TextField> = {
|
|
10
|
+
title: 'Components/TextField/TextField',
|
|
11
|
+
component: TextField,
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default meta;
|
|
16
|
+
|
|
17
|
+
export const _TextField: StoryObj<typeof TextField> = {
|
|
18
|
+
render: (args: TextFieldProps) => <TextField {...args} />,
|
|
19
|
+
args: {
|
|
20
|
+
label: 'Field Label',
|
|
21
|
+
id: 'test',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const _PasswordField: StoryObj<typeof TextField> = {
|
|
26
|
+
render: (args: TextFieldProps) => {
|
|
27
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<TextField
|
|
31
|
+
{...args}
|
|
32
|
+
type={showPassword ? 'text' : 'password'}
|
|
33
|
+
id="password"
|
|
34
|
+
endAdornment={
|
|
35
|
+
<IconButton title="password visibility toggle" onClick={() => setShowPassword((prev) => !prev)}>
|
|
36
|
+
{showPassword ? <EyeIcon /> : <EyeSlashIcon />}
|
|
37
|
+
</IconButton>
|
|
38
|
+
}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
args: {
|
|
43
|
+
label: 'Password',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { TextField } from './TextField';
|
|
3
|
+
|
|
4
|
+
describe('TextField', () => {
|
|
5
|
+
test('should render successfully', () => {
|
|
6
|
+
const { getByText } = render(<TextField label="Test" />);
|
|
7
|
+
expect(getByText('Test')).toBeTruthy();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import FormControl from '@mui/material/FormControl';
|
|
3
|
+
import InputAdornment from '@mui/material/InputAdornment';
|
|
4
|
+
import FormHelperText from '@mui/material/FormHelperText';
|
|
5
|
+
import { FormLabel, Input, InputProps } from '@availity/mui-form-utils';
|
|
6
|
+
import { WarningTriangleIcon } from '@availity/mui-icon';
|
|
7
|
+
|
|
8
|
+
export type TextFieldProps = {
|
|
9
|
+
helperText?: string;
|
|
10
|
+
} & Omit<
|
|
11
|
+
InputProps,
|
|
12
|
+
| 'aria-describedby'
|
|
13
|
+
| 'classes'
|
|
14
|
+
| 'disableInjectingGlobalStyles'
|
|
15
|
+
| 'color'
|
|
16
|
+
| 'multiline'
|
|
17
|
+
| 'notched'
|
|
18
|
+
| 'fullWidth'
|
|
19
|
+
| 'inputProps'
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
const smallStyles = { sx: { padding: '8px 8px' } };
|
|
23
|
+
const mediumStyles = { sx: { padding: '16px 8px' } };
|
|
24
|
+
const iconStyles = { marginRight: '4px', paddingTop: '4px' };
|
|
25
|
+
|
|
26
|
+
export const TextField = forwardRef(
|
|
27
|
+
({ error, helperText, id, label, startAdornment, endAdornment, required, size, ...rest }: TextFieldProps, ref) => {
|
|
28
|
+
const labelId = `${id}-label`;
|
|
29
|
+
const helperId = `${id}-helper-text`;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<FormControl size="small">
|
|
33
|
+
{label && (
|
|
34
|
+
<FormLabel id={labelId} htmlFor={id} required={required} error={!!error} disabled={rest.disabled}>
|
|
35
|
+
{label}
|
|
36
|
+
</FormLabel>
|
|
37
|
+
)}
|
|
38
|
+
<Input
|
|
39
|
+
inputRef={ref}
|
|
40
|
+
id={id}
|
|
41
|
+
aria-describedby={helperId}
|
|
42
|
+
error={!!error}
|
|
43
|
+
inputProps={size === 'medium' ? mediumStyles : smallStyles}
|
|
44
|
+
startAdornment={
|
|
45
|
+
startAdornment ? <InputAdornment position="start">{startAdornment}</InputAdornment> : undefined
|
|
46
|
+
}
|
|
47
|
+
endAdornment={endAdornment ? <InputAdornment position="end">{endAdornment}</InputAdornment> : undefined}
|
|
48
|
+
size={size}
|
|
49
|
+
{...rest}
|
|
50
|
+
/>
|
|
51
|
+
<FormHelperText id={helperId} error={error}>
|
|
52
|
+
{error && <WarningTriangleIcon sx={iconStyles} />}
|
|
53
|
+
{helperText}
|
|
54
|
+
</FormHelperText>
|
|
55
|
+
</FormControl>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
TextField.displayName = 'TextField';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node", "@testing-library/jest-dom"],
|
|
7
|
+
"allowJs": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["**/*.test.js", "**/*.test.ts", "**/*.test.tsx", "**/*.d.ts"]
|
|
10
|
+
}
|