@availity/mui-checkbox 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 +10 -0
- package/README.md +61 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +41 -0
- package/dist/index.mjs +14 -0
- package/introduction.mdx +7 -0
- package/jest.config.js +7 -0
- package/package.json +51 -0
- package/project.json +42 -0
- package/src/index.ts +1 -0
- package/src/lib/Checkbox.stories.tsx +136 -0
- package/src/lib/Checkbox.test.tsx +9 -0
- package/src/lib/Checkbox.tsx +11 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
## 0.1.0 (2023-10-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **mui-checkbox:** init ([c7200a8](https://github.com/Availity/element/commit/c7200a84175174f43d502b47881dd7e57e02aa0e))
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @availity/mui-checkbox
|
|
2
|
+
|
|
3
|
+
> Availity MUI Checkbox component to be used with @availity/element design system.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@availity/mui-checkbox)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/mui-checkbox)
|
|
7
|
+
[](https://github.com/Availity/element/blob/main/packages/mui-checkbox/package.json)
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
This package extends the MUI Checkbox component: [MUI Checkbox Docs](https://mui.com/components/checkbox/)
|
|
12
|
+
|
|
13
|
+
Live demo and documentation in our [Storybook](https://availity.github.io/element/?path=/docs/components-checkbox-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-checkbox
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Yarn
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
yarn add @availity/mui-checkbox
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Usage
|
|
50
|
+
|
|
51
|
+
#### Import through @availity/element
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { Checkbox } from '@availity/element';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Direct import
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { Checkbox } from '@availity/mui-checkbox';
|
|
61
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { CheckboxProps as CheckboxProps$1 } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
interface CheckboxProps extends Omit<CheckboxProps$1, 'size'> {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
color?: 'primary' | 'error';
|
|
7
|
+
}
|
|
8
|
+
declare const Checkbox: react.ForwardRefExoticComponent<Pick<CheckboxProps, "classes" | "checkedIcon" | "color" | "icon" | "className" | "style" | "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" | "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" | "centerRipple" | "disabled" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "sx" | "TouchRippleProps" | "touchRippleRef" | "key" | "autoFocus" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "checked" | "disableFocusRipple" | "edge" | "inputProps" | "inputRef" | "readOnly" | "required" | "indeterminate" | "indeterminateIcon"> & react.RefAttributes<HTMLButtonElement>>;
|
|
9
|
+
|
|
10
|
+
export { Checkbox, CheckboxProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Checkbox: () => Checkbox
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/lib/Checkbox.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_material = require("@mui/material");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
var Checkbox = (0, import_react.forwardRef)((props, ref) => {
|
|
32
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Checkbox, {
|
|
33
|
+
...props,
|
|
34
|
+
ref,
|
|
35
|
+
size: "medium"
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
Checkbox
|
|
41
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/lib/Checkbox.tsx
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { Checkbox as MuiCheckbox } from "@mui/material";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
var Checkbox = forwardRef((props, ref) => {
|
|
6
|
+
return /* @__PURE__ */ jsx(MuiCheckbox, {
|
|
7
|
+
...props,
|
|
8
|
+
ref,
|
|
9
|
+
size: "medium"
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
export {
|
|
13
|
+
Checkbox
|
|
14
|
+
};
|
package/introduction.mdx
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/mui-checkbox",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Availity MUI Checkbox 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-checkbox-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/checkbox"
|
|
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
|
+
"devDependencies": {
|
|
36
|
+
"@availity/mui-form-utils": "^0.4.0",
|
|
37
|
+
"@availity/mui-icon": "^0.6.0",
|
|
38
|
+
"@mui/material": "^5.11.9",
|
|
39
|
+
"react": "18.2.0",
|
|
40
|
+
"react-dom": "18.2.0",
|
|
41
|
+
"tsup": "^5.12.7",
|
|
42
|
+
"typescript": "^4.6.4"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@mui/material": "^5.11.9",
|
|
46
|
+
"react": ">=16.3.0"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mui-checkbox",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/checkbox/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nrwl/linter:eslint",
|
|
10
|
+
"options": {
|
|
11
|
+
"eslintConfig": ".eslintrc.json",
|
|
12
|
+
"lintFilePatterns": ["packages/checkbox/**/*.{js,ts}"],
|
|
13
|
+
"silent": false,
|
|
14
|
+
"fix": false,
|
|
15
|
+
"cache": true,
|
|
16
|
+
"cacheLocation": "./node_modules/.cache/checkbox/.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/checkbox"],
|
|
27
|
+
"options": {
|
|
28
|
+
"jestConfig": "packages/checkbox/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/Checkbox';
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
5
|
+
import { FormControlLabel } from '@availity/mui-form-utils';
|
|
6
|
+
import { Box, FormGroup } from '@mui/material';
|
|
7
|
+
import { HeartEmptyIcon, HeartIcon } from '@availity/mui-icon';
|
|
8
|
+
import { Checkbox, CheckboxProps } from './Checkbox';
|
|
9
|
+
|
|
10
|
+
const meta: Meta<typeof Checkbox> = {
|
|
11
|
+
title: 'Components/Checkbox/Checkbox',
|
|
12
|
+
component: Checkbox,
|
|
13
|
+
tags: ['autodocs'],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default meta;
|
|
17
|
+
|
|
18
|
+
export const _Checkbox: StoryObj<typeof Checkbox> = {
|
|
19
|
+
render: (args: CheckboxProps) => (
|
|
20
|
+
<>
|
|
21
|
+
<Checkbox {...args} defaultChecked />
|
|
22
|
+
<Checkbox {...args} />
|
|
23
|
+
<Checkbox {...args} disabled />
|
|
24
|
+
<Checkbox {...args} disabled checked />
|
|
25
|
+
</>
|
|
26
|
+
),
|
|
27
|
+
args: {
|
|
28
|
+
color: 'primary',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const _CustomCheckbox: StoryObj<typeof Checkbox> = {
|
|
33
|
+
render: (args: CheckboxProps) => (
|
|
34
|
+
<>
|
|
35
|
+
<Checkbox {...args} defaultChecked />
|
|
36
|
+
<Checkbox {...args} />
|
|
37
|
+
<Checkbox {...args} disabled />
|
|
38
|
+
<Checkbox {...args} disabled checked />
|
|
39
|
+
</>
|
|
40
|
+
),
|
|
41
|
+
args: {
|
|
42
|
+
color: 'error',
|
|
43
|
+
icon: <HeartEmptyIcon />,
|
|
44
|
+
checkedIcon: <HeartIcon />,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const _LabeledCheckbox: StoryObj<typeof Checkbox> = {
|
|
49
|
+
render: (args: CheckboxProps) => (
|
|
50
|
+
<>
|
|
51
|
+
<FormControlLabel control={<Checkbox {...args} defaultChecked />} label="Label" />
|
|
52
|
+
<FormControlLabel required control={<Checkbox {...args} />} label="Required" />
|
|
53
|
+
<FormControlLabel disabled control={<Checkbox {...args} />} label="Disabled" />
|
|
54
|
+
</>
|
|
55
|
+
),
|
|
56
|
+
args: {
|
|
57
|
+
children: 'This text is a child of Checkbox',
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const _ControlledCheckbox: StoryObj<typeof Checkbox> = {
|
|
62
|
+
render: (args: CheckboxProps) => {
|
|
63
|
+
const [checked, setChecked] = useState(false);
|
|
64
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => setChecked(event.target.checked);
|
|
65
|
+
return <Checkbox {...args} checked={checked} onChange={handleChange} inputProps={{ 'aria-label': 'controlled' }} />;
|
|
66
|
+
},
|
|
67
|
+
args: {
|
|
68
|
+
children: 'This text is a child of Checkbox',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
export const _IndeterminateCheckbox: StoryObj<typeof Checkbox> = {
|
|
72
|
+
render: (args: CheckboxProps) => {
|
|
73
|
+
const [checked, setChecked] = useState([true, false]);
|
|
74
|
+
|
|
75
|
+
const handleChange1 = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
76
|
+
setChecked([event.target.checked, event.target.checked]);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const handleChange2 = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
80
|
+
setChecked([event.target.checked, checked[1]]);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const handleChange3 = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
84
|
+
setChecked([checked[0], event.target.checked]);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const children = (
|
|
88
|
+
<Box sx={{ display: 'flex', flexDirection: 'column', ml: 3 }}>
|
|
89
|
+
<FormControlLabel label="Child 1" control={<Checkbox checked={checked[0]} onChange={handleChange2} />} />
|
|
90
|
+
<FormControlLabel label="Child 2" control={<Checkbox checked={checked[1]} onChange={handleChange3} />} />
|
|
91
|
+
</Box>
|
|
92
|
+
);
|
|
93
|
+
return (
|
|
94
|
+
<div>
|
|
95
|
+
<FormControlLabel
|
|
96
|
+
label="Parent"
|
|
97
|
+
control={
|
|
98
|
+
<Checkbox
|
|
99
|
+
{...args}
|
|
100
|
+
checked={checked[0] && checked[1]}
|
|
101
|
+
indeterminate={checked[0] !== checked[1]}
|
|
102
|
+
onChange={handleChange1}
|
|
103
|
+
/>
|
|
104
|
+
}
|
|
105
|
+
/>
|
|
106
|
+
{children}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
},
|
|
110
|
+
args: {},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const _FormGroupCheckbox: StoryObj<typeof Checkbox> = {
|
|
114
|
+
render: (args: CheckboxProps) => (
|
|
115
|
+
<FormGroup>
|
|
116
|
+
<FormControlLabel control={<Checkbox {...args} defaultChecked />} label="Label" />
|
|
117
|
+
<FormControlLabel required control={<Checkbox {...args} />} label="Required" />
|
|
118
|
+
<FormControlLabel disabled control={<Checkbox {...args} />} label="Disabled" />
|
|
119
|
+
</FormGroup>
|
|
120
|
+
),
|
|
121
|
+
args: {
|
|
122
|
+
color: 'primary',
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
export const _FormGroupHorizontalCheckbox: StoryObj<typeof Checkbox> = {
|
|
126
|
+
render: (args: CheckboxProps) => (
|
|
127
|
+
<FormGroup row>
|
|
128
|
+
<FormControlLabel control={<Checkbox {...args} defaultChecked />} label="Label" />
|
|
129
|
+
<FormControlLabel required control={<Checkbox {...args} />} label="Required" />
|
|
130
|
+
<FormControlLabel disabled control={<Checkbox {...args} />} label="Disabled" />
|
|
131
|
+
</FormGroup>
|
|
132
|
+
),
|
|
133
|
+
args: {
|
|
134
|
+
color: 'primary',
|
|
135
|
+
},
|
|
136
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { Checkbox } from './Checkbox';
|
|
3
|
+
|
|
4
|
+
describe('Checkbox', () => {
|
|
5
|
+
test('should render successfully', () => {
|
|
6
|
+
const { getByRole } = render(<Checkbox />);
|
|
7
|
+
expect(getByRole('checkbox')).toBeTruthy();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { Checkbox as MuiCheckbox, CheckboxProps as MuiCheckboxProps } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
export interface CheckboxProps extends Omit<MuiCheckboxProps, 'size'> {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
color?: 'primary' | 'error';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const Checkbox = forwardRef<HTMLButtonElement, CheckboxProps>((props, ref) => {
|
|
10
|
+
return <MuiCheckbox {...props} ref={ref} size="medium" />;
|
|
11
|
+
});
|
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
|
+
}
|