@addev-be/ui 0.8.13 → 0.9.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/package.json +2 -1
- package/src/components/ui/Avatar/index.tsx +54 -0
- package/src/components/ui/Avatar/styles.ts +61 -0
- package/src/components/ui/index.ts +1 -0
- package/src/providers/ThemeProvider/defaultTheme.ts +1 -0
- package/src/providers/ThemeProvider/types.ts +2 -0
- package/tsconfig.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@addev-be/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"watch": "tsc -b --watch",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@uidotdev/usehooks": "^2.4.1",
|
|
51
51
|
"fp-ts": "^2.16.9",
|
|
52
|
+
"hash.js": "^1.1.7",
|
|
52
53
|
"io-ts": "^2.2.21",
|
|
53
54
|
"lodash": "^4.17.21",
|
|
54
55
|
"moment": "^2.30.1",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as styles from './styles';
|
|
2
|
+
|
|
3
|
+
import { FC, PropsWithChildren, useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
import { ThemeColorWithIntensity } from '../../../providers';
|
|
6
|
+
import { sha256 } from 'hash.js';
|
|
7
|
+
|
|
8
|
+
type AvatarProps = PropsWithChildren<
|
|
9
|
+
{
|
|
10
|
+
className?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
color?: ThemeColorWithIntensity;
|
|
13
|
+
} & styles.AvatarContainerProps
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
const getInitials = (name: string) => {
|
|
17
|
+
const matches = name.matchAll(/(?:^|\s+)([A-Z0-9])/g);
|
|
18
|
+
return Array.from(matches)
|
|
19
|
+
.slice(0, 2)
|
|
20
|
+
.map((m) => m[1])
|
|
21
|
+
.join('');
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const Avatar: FC<AvatarProps> = ({
|
|
25
|
+
children,
|
|
26
|
+
className,
|
|
27
|
+
color,
|
|
28
|
+
name,
|
|
29
|
+
size = 'md',
|
|
30
|
+
}) => {
|
|
31
|
+
const initials = useMemo(() => getInitials(name || ''), [name]);
|
|
32
|
+
const backgroundColor = useMemo(() => {
|
|
33
|
+
if (color) return `var(--color-${color})`;
|
|
34
|
+
const h =
|
|
35
|
+
parseInt(
|
|
36
|
+
sha256()
|
|
37
|
+
.update(name || '')
|
|
38
|
+
.digest('hex')
|
|
39
|
+
.substring(0, 4),
|
|
40
|
+
16
|
|
41
|
+
) % 360;
|
|
42
|
+
return `hsl(${h}, 50%, 50%)`;
|
|
43
|
+
}, [color, name]);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<styles.AvatarContainer
|
|
47
|
+
size={size}
|
|
48
|
+
className={className}
|
|
49
|
+
style={{ backgroundColor }}
|
|
50
|
+
>
|
|
51
|
+
{initials || children}
|
|
52
|
+
</styles.AvatarContainer>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export type AvatarContainerProps = {
|
|
4
|
+
size: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const stylesMap: Record<
|
|
8
|
+
AvatarContainerProps['size'],
|
|
9
|
+
ReturnType<typeof css>
|
|
10
|
+
> = {
|
|
11
|
+
xs: css`
|
|
12
|
+
width: var(--size-6);
|
|
13
|
+
height: var(--size-6);
|
|
14
|
+
min-width: var(--size-6);
|
|
15
|
+
min-height: var(--size-6);
|
|
16
|
+
font-size: var(--text-xs);
|
|
17
|
+
line-height: var(--text-xs);
|
|
18
|
+
`,
|
|
19
|
+
sm: css`
|
|
20
|
+
width: var(--size-8);
|
|
21
|
+
height: var(--size-8);
|
|
22
|
+
min-width: var(--size-8);
|
|
23
|
+
min-height: var(--size-8);
|
|
24
|
+
font-size: var(--text-sm);
|
|
25
|
+
line-height: var(--text-sm);
|
|
26
|
+
`,
|
|
27
|
+
md: css`
|
|
28
|
+
width: var(--size-10);
|
|
29
|
+
height: var(--size-10);
|
|
30
|
+
min-width: var(--size-10);
|
|
31
|
+
min-height: var(--size-10);
|
|
32
|
+
font-size: var(--text-md);
|
|
33
|
+
line-height: var(--text-md);
|
|
34
|
+
`,
|
|
35
|
+
lg: css`
|
|
36
|
+
width: var(--size-12);
|
|
37
|
+
height: var(--size-12);
|
|
38
|
+
min-width: var(--size-12);
|
|
39
|
+
min-height: var(--size-12);
|
|
40
|
+
font-size: var(--text-lg);
|
|
41
|
+
line-height: var(--text-lg);
|
|
42
|
+
`,
|
|
43
|
+
xl: css`
|
|
44
|
+
width: var(--size-14);
|
|
45
|
+
height: var(--size-14);
|
|
46
|
+
min-width: var(--size-14);
|
|
47
|
+
min-height: var(--size-14);
|
|
48
|
+
font-size: var(--text-2xl);
|
|
49
|
+
line-height: var(--text-2xl);
|
|
50
|
+
`,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const AvatarContainer = styled.div<AvatarContainerProps>`
|
|
54
|
+
display: inline-flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
border-radius: var(--rounded-full);
|
|
58
|
+
user-select: none;
|
|
59
|
+
|
|
60
|
+
${({ size }) => stylesMap[size]}
|
|
61
|
+
`;
|
|
@@ -48,6 +48,7 @@ export type ThemePredefinedColor =
|
|
|
48
48
|
| 'info';
|
|
49
49
|
export type ThemeColor = ThemeRawColor | ThemePredefinedColor;
|
|
50
50
|
export type ThemeColorReference = ThemeColor | ThemeColorDefinition;
|
|
51
|
+
export type ThemeColorWithIntensity = `${ThemeColor}-${ThemeColorIntensity}`;
|
|
51
52
|
|
|
52
53
|
export type ThemeTextSize =
|
|
53
54
|
| 'xs'
|
|
@@ -75,6 +76,7 @@ export type ThemeSpace =
|
|
|
75
76
|
| '8'
|
|
76
77
|
| '10'
|
|
77
78
|
| '12'
|
|
79
|
+
| '14'
|
|
78
80
|
| '16'
|
|
79
81
|
| '20'
|
|
80
82
|
| '24'
|
package/tsconfig.json
CHANGED