@availity/mui-avatar 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 +62 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +64 -0
- package/dist/index.mjs +37 -0
- package/introduction.mdx +7 -0
- package/jest.config.js +7 -0
- package/package.json +52 -0
- package/project.json +41 -0
- package/src/index.ts +1 -0
- package/src/lib/Avatar.stories.tsx +41 -0
- package/src/lib/Avatar.test.tsx +17 -0
- package/src/lib/Avatar.tsx +49 -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-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **mui-avatar:** initial commit ([ed356db](https://github.com/Availity/element/commit/ed356dbaeef699b1a8fb201ec3be8c0bc84d62c9))
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @availity/mui-avatar
|
|
2
|
+
|
|
3
|
+
> Availity MUI Avatar component to be used with @availity/element design system.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@availity/mui-avatar)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/mui-avatar)
|
|
7
|
+
[](https://github.com/Availity/element/blob/main/packages/mui-avatar/package.json)
|
|
8
|
+
|
|
9
|
+
- ⚠️ _needs component theme added to @availity/theme_
|
|
10
|
+
- ⚠️ _needs UI Team Verification (must conform to [Availity's Figma Design Standards](https://www.figma.com/file/bf6l79hehcKdRjb5Kzq1De/Element--MUI-%F0%9F%9A%A7?node-id=4662%3A14&t=QMqHeT6daeqXbjBR-1) - private link)_
|
|
11
|
+
|
|
12
|
+
## Documentation
|
|
13
|
+
|
|
14
|
+
This package extends the MUI Avatar component: [MUI Avatar Docs](https://mui.com/components/avatar/)
|
|
15
|
+
|
|
16
|
+
Live demo and documentation in our [Storybook](https://availity.github.io/element/?path=/docs/components-avatar-introduction--docs)
|
|
17
|
+
|
|
18
|
+
Availity standards for design and usage can be found in the [Availity Design Guide](https://zeroheight.com/2e36e50c7)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
### Import Through @availity/element (Recommended)
|
|
23
|
+
|
|
24
|
+
#### NPM
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @availity/element
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### Yarn
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
yarn add @availity/element
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Direct Import
|
|
37
|
+
|
|
38
|
+
#### NPM
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install @availity/mui-avatar
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### Yarn
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
yarn add @availity/mui-avatar
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Usage
|
|
51
|
+
|
|
52
|
+
#### Import through @availity/element
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { Avatar } from '@availity/element';
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### Direct import
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { Avatar } from '@availity/mui-avatar';
|
|
62
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AvatarProps as AvatarProps$1 } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
interface AvatarProps extends Omit<AvatarProps$1, 'variant'> {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
/** The size of the component.
|
|
7
|
+
* @default xl */
|
|
8
|
+
size?: 'xs' | 's' | 'm' | 'l' | 'xl';
|
|
9
|
+
}
|
|
10
|
+
declare const Avatar: ({ children, size, sx, ...rest }: AvatarProps) => JSX.Element;
|
|
11
|
+
|
|
12
|
+
export { Avatar, AvatarProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
Avatar: () => Avatar
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/lib/Avatar.tsx
|
|
28
|
+
var import_material = require("@mui/material");
|
|
29
|
+
var import_design_tokens = require("@availity/design-tokens");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
var sizeStyling = {
|
|
32
|
+
xs: { width: 18, height: 18, fontSize: import_design_tokens.tokens.fontSizesCaption },
|
|
33
|
+
s: { width: 24, height: 24, fontSize: import_design_tokens.tokens.fontSizesCaption },
|
|
34
|
+
m: { width: 40, height: 40, fontSize: import_design_tokens.tokens.fontSizesH5, fontWeight: import_design_tokens.tokens.fontWeightsBold },
|
|
35
|
+
l: { width: 80, height: 80, fontSize: import_design_tokens.tokens.fontSizesH3, fontWeight: import_design_tokens.tokens.fontWeightsBold },
|
|
36
|
+
xl: { width: 140, height: 140, fontSize: import_design_tokens.tokens.fontSizesH1, fontWeight: import_design_tokens.tokens.fontWeightsBold }
|
|
37
|
+
};
|
|
38
|
+
var getInitials = (name, size) => {
|
|
39
|
+
if (name.split(" ").length > 1 && size !== "xs") {
|
|
40
|
+
return `${name.split(" ")[0][0]}${name.split(" ")[1][0]}`;
|
|
41
|
+
}
|
|
42
|
+
return name.charAt(0);
|
|
43
|
+
};
|
|
44
|
+
var formatChildren = (children, size) => {
|
|
45
|
+
if (typeof children === "string") {
|
|
46
|
+
return getInitials(children, size).toUpperCase();
|
|
47
|
+
}
|
|
48
|
+
return children;
|
|
49
|
+
};
|
|
50
|
+
var Avatar = ({ children, size = "xl", sx, ...rest }) => {
|
|
51
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.Avatar, {
|
|
52
|
+
...rest,
|
|
53
|
+
variant: "circular",
|
|
54
|
+
sx: {
|
|
55
|
+
...sx,
|
|
56
|
+
...sizeStyling[size] || sizeStyling.xl
|
|
57
|
+
},
|
|
58
|
+
children: formatChildren(children, size)
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
Avatar
|
|
64
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/lib/Avatar.tsx
|
|
2
|
+
import { Avatar as MuiAvatar } from "@mui/material";
|
|
3
|
+
import { tokens } from "@availity/design-tokens";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
var sizeStyling = {
|
|
6
|
+
xs: { width: 18, height: 18, fontSize: tokens.fontSizesCaption },
|
|
7
|
+
s: { width: 24, height: 24, fontSize: tokens.fontSizesCaption },
|
|
8
|
+
m: { width: 40, height: 40, fontSize: tokens.fontSizesH5, fontWeight: tokens.fontWeightsBold },
|
|
9
|
+
l: { width: 80, height: 80, fontSize: tokens.fontSizesH3, fontWeight: tokens.fontWeightsBold },
|
|
10
|
+
xl: { width: 140, height: 140, fontSize: tokens.fontSizesH1, fontWeight: tokens.fontWeightsBold }
|
|
11
|
+
};
|
|
12
|
+
var getInitials = (name, size) => {
|
|
13
|
+
if (name.split(" ").length > 1 && size !== "xs") {
|
|
14
|
+
return `${name.split(" ")[0][0]}${name.split(" ")[1][0]}`;
|
|
15
|
+
}
|
|
16
|
+
return name.charAt(0);
|
|
17
|
+
};
|
|
18
|
+
var formatChildren = (children, size) => {
|
|
19
|
+
if (typeof children === "string") {
|
|
20
|
+
return getInitials(children, size).toUpperCase();
|
|
21
|
+
}
|
|
22
|
+
return children;
|
|
23
|
+
};
|
|
24
|
+
var Avatar = ({ children, size = "xl", sx, ...rest }) => {
|
|
25
|
+
return /* @__PURE__ */ jsx(MuiAvatar, {
|
|
26
|
+
...rest,
|
|
27
|
+
variant: "circular",
|
|
28
|
+
sx: {
|
|
29
|
+
...sx,
|
|
30
|
+
...sizeStyling[size] || sizeStyling.xl
|
|
31
|
+
},
|
|
32
|
+
children: formatChildren(children, size)
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
Avatar
|
|
37
|
+
};
|
package/introduction.mdx
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/mui-avatar",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Availity MUI Avatar 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-avatar-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/avatar"
|
|
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
|
+
"dependencies": {
|
|
50
|
+
"@availity/design-tokens": "^0.4.6"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mui-avatar",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/avatar/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nrwl/linter:eslint",
|
|
10
|
+
"options": {
|
|
11
|
+
"eslintConfig": ".eslintrc.json",
|
|
12
|
+
"lintFilePatterns": ["packages/avatar/**/*.{js,ts}"],
|
|
13
|
+
"silent": false,
|
|
14
|
+
"fix": false,
|
|
15
|
+
"cache": true,
|
|
16
|
+
"cacheLocation": "./node_modules/.cache/avatar/.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/avatar"],
|
|
27
|
+
"options": {
|
|
28
|
+
"jestConfig": "packages/avatar/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/Avatar';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import { Avatar, AvatarProps } from './Avatar';
|
|
5
|
+
import { HomeIcon } from '@availity/mui-icon';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Avatar> = {
|
|
8
|
+
title: 'Components/Avatar/Avatar',
|
|
9
|
+
component: Avatar,
|
|
10
|
+
argTypes: {
|
|
11
|
+
size: {
|
|
12
|
+
// this guarantees the options display in the correct order
|
|
13
|
+
options: ['xs', 's', 'm', 'l', 'xl'],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
tags: ['autodocs'],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default meta;
|
|
20
|
+
|
|
21
|
+
export const _Avatar: StoryObj<typeof Avatar> = {
|
|
22
|
+
render: (args: AvatarProps) => <Avatar {...args} />,
|
|
23
|
+
args: {
|
|
24
|
+
children: 'John Doe',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const _ImageAvatar: StoryObj<typeof Avatar> = {
|
|
29
|
+
render: (args: AvatarProps) => <Avatar {...args} />,
|
|
30
|
+
args: {
|
|
31
|
+
src: 'https://avatars.githubusercontent.com/u/329985?s=100',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const _IconAvatar: StoryObj<typeof Avatar> = {
|
|
36
|
+
render: (args: AvatarProps) => (
|
|
37
|
+
<Avatar {...args}>
|
|
38
|
+
<HomeIcon />
|
|
39
|
+
</Avatar>
|
|
40
|
+
),
|
|
41
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { Avatar } from './Avatar';
|
|
3
|
+
|
|
4
|
+
describe('Avatar', () => {
|
|
5
|
+
test('should display initials when string passed as child', () => {
|
|
6
|
+
const { getByText } = render(<Avatar>Test Person</Avatar>);
|
|
7
|
+
expect(getByText('TP')).toBeTruthy();
|
|
8
|
+
});
|
|
9
|
+
test('should display first two initials when multi-word child is passed', () => {
|
|
10
|
+
const { getByText } = render(<Avatar>This is a test</Avatar>);
|
|
11
|
+
expect(getByText('TI')).toBeTruthy();
|
|
12
|
+
});
|
|
13
|
+
test('should display first initial when size is small', () => {
|
|
14
|
+
const { getByText } = render(<Avatar size="xs">This is a test</Avatar>);
|
|
15
|
+
expect(getByText('T')).toBeTruthy();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Avatar as MuiAvatar, AvatarProps as MuiAvatarProps } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { tokens } from '@availity/design-tokens';
|
|
4
|
+
|
|
5
|
+
export interface AvatarProps extends Omit<MuiAvatarProps, 'variant'> {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/** The size of the component.
|
|
8
|
+
* @default xl */
|
|
9
|
+
size?: 'xs' | 's' | 'm' | 'l' | 'xl'; // If this changes, you will need to update the story as well. Options are hardcoded to ensure order.
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const sizeStyling = {
|
|
13
|
+
xs: { width: 18, height: 18, fontSize: tokens.fontSizesCaption },
|
|
14
|
+
s: { width: 24, height: 24, fontSize: tokens.fontSizesCaption },
|
|
15
|
+
m: { width: 40, height: 40, fontSize: tokens.fontSizesH5, fontWeight: tokens.fontWeightsBold },
|
|
16
|
+
l: { width: 80, height: 80, fontSize: tokens.fontSizesH3, fontWeight: tokens.fontWeightsBold },
|
|
17
|
+
xl: { width: 140, height: 140, fontSize: tokens.fontSizesH1, fontWeight: tokens.fontWeightsBold },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getInitials = (name: string, size: 'xs' | 's' | 'm' | 'l' | 'xl'): string => {
|
|
21
|
+
if (name.split(' ').length > 1 && size !== 'xs') {
|
|
22
|
+
return `${name.split(' ')[0][0]}${name.split(' ')[1][0]}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return name.charAt(0);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const formatChildren = (children: React.ReactNode, size: 'xs' | 's' | 'm' | 'l' | 'xl'): React.ReactNode => {
|
|
29
|
+
if (typeof children === 'string') {
|
|
30
|
+
return getInitials(children, size).toUpperCase();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return children;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const Avatar = ({ children, size = 'xl', sx, ...rest }: AvatarProps): JSX.Element => {
|
|
37
|
+
return (
|
|
38
|
+
<MuiAvatar
|
|
39
|
+
{...rest}
|
|
40
|
+
variant="circular"
|
|
41
|
+
sx={{
|
|
42
|
+
...sx,
|
|
43
|
+
...(sizeStyling[size] || sizeStyling.xl),
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{formatChildren(children, size)}
|
|
47
|
+
</MuiAvatar>
|
|
48
|
+
);
|
|
49
|
+
};
|
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
|
+
}
|