@ornikar/bumper 3.13.0 → 3.14.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 +6 -143
- package/dist/definitions/index.d.ts +2 -0
- package/dist/definitions/index.d.ts.map +1 -1
- package/dist/definitions/system/core/themes/light/light.d.ts.map +1 -1
- package/dist/definitions/system/core/themes/types.d.ts +3 -1
- package/dist/definitions/system/core/themes/types.d.ts.map +1 -1
- package/dist/definitions/system/dataDisplays/Avatar/Avatar.d.ts +52 -0
- package/dist/definitions/system/dataDisplays/Avatar/Avatar.d.ts.map +1 -0
- package/dist/definitions/system/dataDisplays/Avatar/components/AvatarImage.d.ts +5 -0
- package/dist/definitions/system/dataDisplays/Avatar/components/AvatarImage.d.ts.map +1 -0
- package/dist/definitions/system/dataDisplays/Avatar/components/AvatarInitial.d.ts +6 -0
- package/dist/definitions/system/dataDisplays/Avatar/components/AvatarInitial.d.ts.map +1 -0
- package/dist/definitions/system/dataDisplays/Avatar/context.d.ts +3 -0
- package/dist/definitions/system/dataDisplays/Avatar/context.d.ts.map +1 -0
- package/dist/index-metro.es.android.js +141 -9
- package/dist/index-metro.es.android.js.map +1 -1
- package/dist/index-metro.es.ios.js +141 -9
- package/dist/index-metro.es.ios.js.map +1 -1
- package/dist/index-node-22.22.cjs.js +140 -7
- package/dist/index-node-22.22.cjs.js.map +1 -1
- package/dist/index-node-22.22.cjs.web.js +140 -7
- package/dist/index-node-22.22.cjs.web.js.map +1 -1
- package/dist/index-node-22.22.es.mjs +140 -9
- package/dist/index-node-22.22.es.mjs.map +1 -1
- package/dist/index-node-22.22.es.web.mjs +140 -9
- package/dist/index-node-22.22.es.web.mjs.map +1 -1
- package/dist/index.es.js +140 -9
- package/dist/index.es.js.map +1 -1
- package/dist/index.es.web.js +140 -9
- package/dist/index.es.web.js.map +1 -1
- package/dist/storybook-metro.es.android.js +3 -1
- package/dist/storybook-metro.es.android.js.map +1 -1
- package/dist/storybook-metro.es.ios.js +3 -1
- package/dist/storybook-metro.es.ios.js.map +1 -1
- package/dist/storybook-node-22.22.cjs.js +3 -1
- package/dist/storybook-node-22.22.cjs.js.map +1 -1
- package/dist/storybook-node-22.22.cjs.web.js +3 -1
- package/dist/storybook-node-22.22.cjs.web.js.map +1 -1
- package/dist/storybook-node-22.22.es.mjs +3 -1
- package/dist/storybook-node-22.22.es.mjs.map +1 -1
- package/dist/storybook-node-22.22.es.web.mjs +3 -1
- package/dist/storybook-node-22.22.es.web.mjs.map +1 -1
- package/dist/storybook.es.js +3 -1
- package/dist/storybook.es.js.map +1 -1
- package/dist/storybook.es.web.js +3 -1
- package/dist/storybook.es.web.js.map +1 -1
- package/dist/tsbuildinfo +1 -1
- package/docs/migration/Avatar.md +228 -0
- package/package.json +1 -1
- package/src/Bumper.mdx +1 -0
- package/src/index.ts +2 -0
- package/src/system/core/themes/light/__snapshots__/light.stories.tsx.snap +73 -0
- package/src/system/core/themes/light/__snapshots_web__/light.stories.tsx.snap +21 -0
- package/src/system/core/themes/light/light.ts +3 -0
- package/src/system/core/themes/types.ts +5 -1
- package/src/system/dataDisplays/Avatar/Avatar.features.stories.tsx +110 -0
- package/src/system/dataDisplays/Avatar/Avatar.mdx +73 -0
- package/src/system/dataDisplays/Avatar/Avatar.stories.tsx +47 -0
- package/src/system/dataDisplays/Avatar/Avatar.tsx +124 -0
- package/src/system/dataDisplays/Avatar/__snapshots__/Avatar.features.stories.tsx.snap +891 -0
- package/src/system/dataDisplays/Avatar/__snapshots__/Avatar.stories.tsx.snap +50 -0
- package/src/system/dataDisplays/Avatar/__snapshots_web__/Avatar.features.stories.tsx.snap +545 -0
- package/src/system/dataDisplays/Avatar/__snapshots_web__/Avatar.stories.tsx.snap +37 -0
- package/src/system/dataDisplays/Avatar/assets/avatar-placeholder-disabled.webp +0 -0
- package/src/system/dataDisplays/Avatar/assets/avatar-placeholder.webp +0 -0
- package/src/system/dataDisplays/Avatar/components/AvatarImage.tsx +34 -0
- package/src/system/dataDisplays/Avatar/components/AvatarInitial.tsx +30 -0
- package/src/system/dataDisplays/Avatar/context.ts +10 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { styled } from '@tamagui/core';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useProps } from '../../core/hooks/useProps';
|
|
4
|
+
import type { CenterProps } from '../../core/primitives/Center';
|
|
5
|
+
import { Center } from '../../core/primitives/Center';
|
|
6
|
+
import type { TamaguiMediaProps } from '../../types';
|
|
7
|
+
import AvatarPlaceholderDisabledImage from './assets/avatar-placeholder-disabled.webp';
|
|
8
|
+
import AvatarPlaceholderImage from './assets/avatar-placeholder.webp';
|
|
9
|
+
import { AvatarImage } from './components/AvatarImage';
|
|
10
|
+
import { AvatarInitial } from './components/AvatarInitial';
|
|
11
|
+
import { context } from './context';
|
|
12
|
+
|
|
13
|
+
export type AvatarSize = 'small' | 'medium' | 'large' | 'xlarge';
|
|
14
|
+
export type AvatarShape = 'square' | 'circle';
|
|
15
|
+
|
|
16
|
+
export interface InternalAvatarWithoutMediaProps extends Pick<CenterProps, 'testID'> {
|
|
17
|
+
/**
|
|
18
|
+
* Image source if none is given then fallback to the initials
|
|
19
|
+
*/
|
|
20
|
+
src?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The firstname used to produce the initials. If none is given then
|
|
24
|
+
* fallback on the default placeholder image.
|
|
25
|
+
*/
|
|
26
|
+
firstname?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The firstname used to produce the initials
|
|
30
|
+
*/
|
|
31
|
+
lastname?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Is this component in disabled state ?
|
|
35
|
+
*/
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @default large
|
|
40
|
+
*/
|
|
41
|
+
size?: AvatarSize;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* If size is omited, you can use width and height to tweak the avatar
|
|
45
|
+
* size as you wish
|
|
46
|
+
*/
|
|
47
|
+
width?: number;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @see width
|
|
51
|
+
*/
|
|
52
|
+
height?: number;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @default square
|
|
56
|
+
*/
|
|
57
|
+
shape?: AvatarShape;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type AvatarProps = TamaguiMediaProps<InternalAvatarWithoutMediaProps>;
|
|
61
|
+
|
|
62
|
+
export const InternalAvatarFrame = styled(Center, {
|
|
63
|
+
name: 'Avatar',
|
|
64
|
+
context,
|
|
65
|
+
overflow: 'hidden',
|
|
66
|
+
variants: {
|
|
67
|
+
size: {
|
|
68
|
+
small: {
|
|
69
|
+
width: 32,
|
|
70
|
+
height: 32,
|
|
71
|
+
},
|
|
72
|
+
medium: {
|
|
73
|
+
width: 40,
|
|
74
|
+
height: 40,
|
|
75
|
+
},
|
|
76
|
+
large: {
|
|
77
|
+
width: 48,
|
|
78
|
+
height: 48,
|
|
79
|
+
},
|
|
80
|
+
xlarge: {
|
|
81
|
+
width: 64,
|
|
82
|
+
height: 64,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
shape: {
|
|
86
|
+
square: {
|
|
87
|
+
borderRadius: '$radius.m',
|
|
88
|
+
},
|
|
89
|
+
circle: {
|
|
90
|
+
borderRadius: '$radius.circle',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
disabled: {
|
|
94
|
+
true: {
|
|
95
|
+
backgroundColor: '$bg.disabled.hi',
|
|
96
|
+
},
|
|
97
|
+
false: {
|
|
98
|
+
backgroundColor: '$avatar.bg',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
} as const,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const Avatar = InternalAvatarFrame.styleable<AvatarProps, AvatarProps>((props, ref) => {
|
|
105
|
+
const flattenProps = useProps(props);
|
|
106
|
+
|
|
107
|
+
const children = useMemo(() => {
|
|
108
|
+
if (!flattenProps.src && !flattenProps.firstname && !flattenProps.lastname) {
|
|
109
|
+
return <AvatarImage src={flattenProps.disabled ? AvatarPlaceholderDisabledImage : AvatarPlaceholderImage} />;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (flattenProps.src) {
|
|
113
|
+
return <AvatarImage src={flattenProps.src} />;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return <AvatarInitial firstname={flattenProps.firstname ?? ''} lastname={flattenProps.lastname ?? ''} />;
|
|
117
|
+
}, [flattenProps.src, flattenProps.firstname, flattenProps.lastname, flattenProps.disabled]);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<InternalAvatarFrame ref={ref} {...props}>
|
|
121
|
+
{children}
|
|
122
|
+
</InternalAvatarFrame>
|
|
123
|
+
);
|
|
124
|
+
});
|