@availity/mui-chip 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 +12 -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 +49 -0
- package/project.json +41 -0
- package/src/index.ts +1 -0
- package/src/lib/Chip.stories.tsx +72 -0
- package/src/lib/Chip.test.tsx +17 -0
- package/src/lib/Chip.tsx +16 -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-06-16)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **mui-chip:** initial commit ([7729cfc](https://github.com/Availity/element/commit/7729cfce5f19b0f286c48275d609eadcb9534cdd))
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @availity/mui-chip
|
|
2
|
+
|
|
3
|
+
> Availity MUI Chip component to be used with @availity/element design system.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@availity/mui-chip)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/mui-chip)
|
|
7
|
+
[](https://github.com/Availity/element/blob/main/packages/mui-chip/package.json)
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
This package extends the MUI Chip component: [MUI Chip Docs](https://mui.com/components/chip/)
|
|
12
|
+
|
|
13
|
+
Live demo and documentation in our [Storybook](https://availity.github.io/element/?path=/docs/components-chip-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-chip
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Yarn
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
yarn add @availity/mui-chip
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Usage
|
|
50
|
+
|
|
51
|
+
#### Import through @availity/element
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { Chip } from '@availity/element';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Direct import
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { Chip } from '@availity/mui-chip';
|
|
61
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChipProps as ChipProps$1 } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
type ChipProps = {
|
|
4
|
+
/** The color of the component. Nondefault colors are only to be used with size `small`.
|
|
5
|
+
* @default default */
|
|
6
|
+
color?: 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning';
|
|
7
|
+
/** The size of the component. Size `small` is for statuses and inline counters. */
|
|
8
|
+
size?: 'small' | 'medium';
|
|
9
|
+
} & Omit<ChipProps$1, 'children' | 'color' | 'variant' | 'skipFocusWhenDisabled' | 'disabled' | 'size' | 'icon' | 'clickable'>;
|
|
10
|
+
declare const Chip: ({ color, onDelete, ...rest }: ChipProps) => JSX.Element;
|
|
11
|
+
|
|
12
|
+
export { Chip, ChipProps };
|
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
|
+
Chip: () => Chip
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/lib/Chip.tsx
|
|
28
|
+
var import_material = require("@mui/material");
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
var Chip = ({ color = "default", onDelete, ...rest }) => {
|
|
31
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Chip, {
|
|
32
|
+
color,
|
|
33
|
+
onClick: onDelete,
|
|
34
|
+
onDelete,
|
|
35
|
+
...rest
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
Chip
|
|
41
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/lib/Chip.tsx
|
|
2
|
+
import { Chip as MuiChip } from "@mui/material";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
var Chip = ({ color = "default", onDelete, ...rest }) => {
|
|
5
|
+
return /* @__PURE__ */ jsx(MuiChip, {
|
|
6
|
+
color,
|
|
7
|
+
onClick: onDelete,
|
|
8
|
+
onDelete,
|
|
9
|
+
...rest
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
Chip
|
|
14
|
+
};
|
package/introduction.mdx
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/mui-chip",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Availity MUI Chip 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-chip-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/chip"
|
|
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
|
+
"@mui/material": "^5.11.9",
|
|
37
|
+
"react": "18.2.0",
|
|
38
|
+
"react-dom": "18.2.0",
|
|
39
|
+
"tsup": "^5.12.7",
|
|
40
|
+
"typescript": "^4.6.4"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@mui/material": "^5.11.9",
|
|
44
|
+
"react": ">=16.3.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mui-chip",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/chip/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nrwl/linter:eslint",
|
|
10
|
+
"options": {
|
|
11
|
+
"eslintConfig": ".eslintrc.json",
|
|
12
|
+
"lintFilePatterns": ["packages/chip/**/*.{js,ts}"],
|
|
13
|
+
"silent": false,
|
|
14
|
+
"fix": false,
|
|
15
|
+
"cache": true,
|
|
16
|
+
"cacheLocation": "./node_modules/.cache/chip/.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/chip"],
|
|
27
|
+
"options": {
|
|
28
|
+
"jestConfig": "packages/chip/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
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/Chip';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { Avatar, Collapse } from '@mui/material';
|
|
4
|
+
import { Chip, ChipProps } from './Chip';
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof Chip> = {
|
|
7
|
+
title: 'Components/Chip/Chip',
|
|
8
|
+
component: Chip,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
args: {
|
|
11
|
+
label: 'Chip',
|
|
12
|
+
size: 'medium',
|
|
13
|
+
color: 'default',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default meta;
|
|
18
|
+
|
|
19
|
+
export const _Chip: StoryObj<typeof Chip> = {
|
|
20
|
+
render: (args: ChipProps) => <Chip {...args} />,
|
|
21
|
+
args: {
|
|
22
|
+
label: 'Chip',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const _RemovableChip: StoryObj<typeof Chip> = {
|
|
27
|
+
render: (args: ChipProps) => {
|
|
28
|
+
const [visible, setVisible] = useState(true);
|
|
29
|
+
|
|
30
|
+
const onDelete = () => {
|
|
31
|
+
setVisible(false);
|
|
32
|
+
setTimeout(() => setVisible(true), 1000);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Collapse in={visible}>
|
|
37
|
+
<Chip {...args} onDelete={onDelete} />
|
|
38
|
+
</Collapse>
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const _Avatar: StoryObj<typeof Chip> = {
|
|
44
|
+
render: (args: ChipProps) => <Chip {...args} avatar={<Avatar>A</Avatar>} />,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Status styling is achieved by using size `small` */
|
|
48
|
+
export const _Status: StoryObj<typeof Chip> = {
|
|
49
|
+
render: () => (
|
|
50
|
+
<>
|
|
51
|
+
Item 1 <Chip color="success" label="Approved" size="small" />
|
|
52
|
+
<br />
|
|
53
|
+
Item 2 <Chip color="info" label="Info" size="small" />
|
|
54
|
+
<br />
|
|
55
|
+
Item 3 <Chip color="warning" label="Pending" size="small" />
|
|
56
|
+
<br />
|
|
57
|
+
Item 4 <Chip color="error" label="Declined" size="small" />
|
|
58
|
+
<br />
|
|
59
|
+
Item 5 <Chip color="secondary" label="Neutral" size="small" />
|
|
60
|
+
<br />
|
|
61
|
+
</>
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Inline counter styling is achieved by using size `small`. For counters that affix to the corner of an element see `Badge`. */
|
|
66
|
+
export const _InlineCounter: StoryObj<typeof Chip> = {
|
|
67
|
+
render: () => (
|
|
68
|
+
<div>
|
|
69
|
+
Items <Chip color="error" label="5" size="small" />
|
|
70
|
+
</div>
|
|
71
|
+
),
|
|
72
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { Chip } from './Chip';
|
|
3
|
+
|
|
4
|
+
describe('Chip', () => {
|
|
5
|
+
test('should render successfully', () => {
|
|
6
|
+
const { getByText } = render(<Chip label="Test" />);
|
|
7
|
+
expect(getByText('Test')).toBeTruthy();
|
|
8
|
+
});
|
|
9
|
+
test('should have clickable styling when onDelete passed', () => {
|
|
10
|
+
const onDelete = () => {
|
|
11
|
+
// do nothing
|
|
12
|
+
};
|
|
13
|
+
const { getByRole } = render(<Chip label="Test" onDelete={onDelete} />);
|
|
14
|
+
expect(getByRole('button')).toBeTruthy();
|
|
15
|
+
expect(getByRole('button')).toHaveClass('MuiChip-clickable');
|
|
16
|
+
});
|
|
17
|
+
});
|
package/src/lib/Chip.tsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Chip as MuiChip, ChipProps as MuiChipProps } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
export type ChipProps = {
|
|
4
|
+
/** The color of the component. Nondefault colors are only to be used with size `small`.
|
|
5
|
+
* @default default */
|
|
6
|
+
color?: 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning';
|
|
7
|
+
/** The size of the component. Size `small` is for statuses and inline counters. */
|
|
8
|
+
size?: 'small' | 'medium';
|
|
9
|
+
} & Omit<
|
|
10
|
+
MuiChipProps,
|
|
11
|
+
'children' | 'color' | 'variant' | 'skipFocusWhenDisabled' | 'disabled' | 'size' | 'icon' | 'clickable'
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
export const Chip = ({ color = 'default', onDelete, ...rest }: ChipProps): JSX.Element => {
|
|
15
|
+
return <MuiChip color={color} onClick={onDelete} onDelete={onDelete} {...rest} />;
|
|
16
|
+
};
|
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
|
+
}
|