@tamagui/avatar 2.7.7 → 3.0.0-beta.1091.1

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.
@@ -5,40 +5,33 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var Avatar_exports = {};
35
28
  __export(Avatar_exports, {
36
- Avatar: () => Avatar,
37
- AvatarFallback: () => AvatarFallback,
38
- AvatarFallbackFrame: () => AvatarFallbackFrame,
39
- AvatarFrame: () => AvatarFrame,
40
- AvatarImage: () => AvatarImage,
41
- createAvatarScope: () => createAvatarScope
29
+ Avatar: () => Avatar,
30
+ AvatarFallback: () => AvatarFallback,
31
+ AvatarFallbackFrame: () => AvatarFallbackFrame,
32
+ AvatarFrame: () => AvatarFrame,
33
+ AvatarImage: () => AvatarImage,
34
+ createAvatarScope: () => createAvatarScope
42
35
  });
43
36
  module.exports = __toCommonJS(Avatar_exports);
44
37
  var import_core = require("@tamagui/core");
@@ -53,108 +46,95 @@ const AVATAR_NAME = "Avatar";
53
46
  const [createAvatarContext, createAvatarScope] = (0, import_create_context.createContextScope)(AVATAR_NAME);
54
47
  const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
55
48
  const IMAGE_NAME = "AvatarImage";
56
- const AvatarImage = React.forwardRef((props, forwardedRef) => {
57
- const {
58
- __scopeAvatar,
59
- src,
60
- source,
61
- onLoadingStatusChange = () => {},
62
- ...imageProps
63
- } = props;
64
- const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
65
- const [status, setStatus] = React.useState("idle");
66
- const resolvedSrc = src || (source && typeof source === "object" && "uri" in source ? source.uri : source);
67
- React.useEffect(() => {
68
- if (!resolvedSrc) {
69
- setStatus("error");
70
- } else {
71
- setStatus("idle");
72
- }
73
- }, [resolvedSrc]);
74
- React.useEffect(() => {
75
- onLoadingStatusChange(status);
76
- context.onImageLoadingStatusChange(status);
77
- }, [status]);
78
- if (!resolvedSrc) {
79
- return null;
80
- }
81
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.YStack, {
82
- fullscreen: true,
83
- zIndex: 1,
84
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_image.Image, {
85
- position: "absolute",
86
- top: 0,
87
- left: 0,
88
- right: 0,
89
- bottom: 0,
90
- objectFit: "cover",
91
- width: "100%",
92
- height: "100%",
93
- ...imageProps,
94
- ref: forwardedRef,
95
- src: resolvedSrc,
96
- onError: () => {
97
- setStatus("error");
98
- },
99
- onLoad: () => {
100
- setStatus("loaded");
101
- }
102
- })
103
- });
49
+ const AvatarImage = (0, import_core.createRefComponent)((props, forwardedRef) => {
50
+ const { __scopeAvatar, src, source, onLoadingStatusChange = () => {}, ...imageProps } = props;
51
+ const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
52
+ const [status, setStatus] = React.useState("idle");
53
+ const resolvedSrc = src || (source && typeof source === "object" && "uri" in source ? source.uri : source);
54
+ React.useEffect(() => {
55
+ if (!resolvedSrc) {
56
+ setStatus("error");
57
+ } else {
58
+ setStatus("idle");
59
+ }
60
+ }, [resolvedSrc]);
61
+ React.useEffect(() => {
62
+ onLoadingStatusChange(status);
63
+ context.onImageLoadingStatusChange(status);
64
+ }, [status]);
65
+ if (!resolvedSrc) {
66
+ return null;
67
+ }
68
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
69
+ position: "absolute",
70
+ inset: 0,
71
+ zIndex: 1,
72
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.Image, {
73
+ position: "absolute",
74
+ top: 0,
75
+ left: 0,
76
+ right: 0,
77
+ bottom: 0,
78
+ objectFit: "cover",
79
+ width: "100%",
80
+ height: "100%",
81
+ ...imageProps,
82
+ ref: forwardedRef,
83
+ src: resolvedSrc,
84
+ onError: () => {
85
+ setStatus("error");
86
+ },
87
+ onLoad: () => {
88
+ setStatus("loaded");
89
+ }
90
+ })
91
+ });
104
92
  });
105
93
  AvatarImage.displayName = IMAGE_NAME;
106
94
  const FALLBACK_NAME = "AvatarFallback";
107
95
  const AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
108
- name: FALLBACK_NAME,
109
- position: "absolute",
110
- fullscreen: true,
111
- zIndex: 0
96
+ displayName: FALLBACK_NAME,
97
+ position: "absolute",
98
+ inset: 0,
99
+ zIndex: 0
112
100
  });
113
- const AvatarFallback = AvatarFallbackFrame.styleable((props, forwardedRef) => {
114
- const {
115
- __scopeAvatar,
116
- delayMs,
117
- ...fallbackProps
118
- } = props;
119
- const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
120
- const [canRender, setCanRender] = React.useState(delayMs === void 0);
121
- React.useEffect(() => {
122
- if (delayMs !== void 0) {
123
- const timerId = setTimeout(() => setCanRender(true), delayMs);
124
- return () => clearTimeout(timerId);
125
- }
126
- }, [delayMs]);
127
- return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
128
- ...fallbackProps,
129
- ref: forwardedRef
130
- }) : null;
101
+ const AvatarFallback = (0, import_core.createStyledHOC)(AvatarFallbackFrame, (props, forwardedRef) => {
102
+ const { __scopeAvatar, delay, ...fallbackProps } = props;
103
+ const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
104
+ const [canRender, setCanRender] = React.useState(delay === void 0);
105
+ React.useEffect(() => {
106
+ if (delay !== void 0) {
107
+ const timerId = setTimeout(() => setCanRender(true), delay);
108
+ return () => clearTimeout(timerId);
109
+ }
110
+ }, [delay]);
111
+ return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
112
+ ...fallbackProps,
113
+ ref: forwardedRef
114
+ }) : null;
131
115
  });
132
116
  AvatarFallback.displayName = FALLBACK_NAME;
133
117
  const AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
134
- name: AVATAR_NAME,
135
- position: "relative",
136
- overflow: "hidden"
118
+ displayName: AVATAR_NAME,
119
+ position: "relative",
120
+ overflow: "hidden"
137
121
  });
138
- const Avatar = (0, import_helpers.withStaticProperties)(React.forwardRef((props, forwardedRef) => {
139
- const {
140
- __scopeAvatar,
141
- size = "$true",
142
- ...avatarProps
143
- } = props;
144
- const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
145
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarProvider, {
146
- size,
147
- scope: __scopeAvatar,
148
- imageLoadingStatus,
149
- onImageLoadingStatusChange: setImageLoadingStatus,
150
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFrame, {
151
- size,
152
- ...avatarProps,
153
- ref: forwardedRef
154
- })
155
- });
122
+ const Avatar = (0, import_helpers.withStaticProperties)((0, import_core.createRefComponent)((props, forwardedRef) => {
123
+ const { __scopeAvatar, size = true, ...avatarProps } = props;
124
+ const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
125
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarProvider, {
126
+ size,
127
+ scope: __scopeAvatar,
128
+ imageLoadingStatus,
129
+ onImageLoadingStatusChange: setImageLoadingStatus,
130
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFrame, {
131
+ size,
132
+ ...avatarProps,
133
+ ref: forwardedRef
134
+ })
135
+ });
156
136
  }), {
157
- Image: AvatarImage,
158
- Fallback: AvatarFallback
137
+ Image: AvatarImage,
138
+ Fallback: AvatarFallback
159
139
  });
160
- Avatar.displayName = AVATAR_NAME;
140
+ Avatar.displayName = AVATAR_NAME;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var Avatar_exports = {};
30
+ __export(Avatar_exports, {
31
+ Avatar: () => Avatar,
32
+ AvatarFallback: () => AvatarFallback,
33
+ AvatarFallbackFrame: () => AvatarFallbackFrame,
34
+ AvatarFrame: () => AvatarFrame,
35
+ AvatarImage: () => AvatarImage,
36
+ createAvatarScope: () => createAvatarScope
37
+ });
38
+ module.exports = __toCommonJS(Avatar_exports);
39
+ var import_jsx_runtime = require("react/jsx-runtime");
40
+ var import_core = require("@tamagui/core");
41
+ var import_create_context = require("@tamagui/create-context");
42
+ var import_helpers = require("@tamagui/helpers");
43
+ var import_image = require("@tamagui/image");
44
+ var import_shapes = require("@tamagui/shapes");
45
+ var import_stacks = require("@tamagui/stacks");
46
+ var React = __toESM(require("react"), 1);
47
+ var AVATAR_NAME = "Avatar";
48
+ var [createAvatarContext, createAvatarScope] = (0, import_create_context.createContextScope)(AVATAR_NAME);
49
+ var [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
50
+ var IMAGE_NAME = "AvatarImage";
51
+ var AvatarImage = (0, import_core.createRefComponent)(function(props, forwardedRef) {
52
+ var { __scopeAvatar, src, source, onLoadingStatusChange = function() {}, ...imageProps } = props;
53
+ var context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
54
+ var [status, setStatus] = React.useState("idle");
55
+ var resolvedSrc = src || (source && typeof source === "object" && "uri" in source ? source.uri : source);
56
+ React.useEffect(function() {
57
+ if (!resolvedSrc) {
58
+ setStatus("error");
59
+ } else {
60
+ setStatus("idle");
61
+ }
62
+ }, [resolvedSrc]);
63
+ React.useEffect(function() {
64
+ onLoadingStatusChange(status);
65
+ context.onImageLoadingStatusChange(status);
66
+ }, [status]);
67
+ if (!resolvedSrc) {
68
+ return null;
69
+ }
70
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
71
+ position: "absolute",
72
+ inset: 0,
73
+ zIndex: 1,
74
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.Image, {
75
+ position: "absolute",
76
+ top: 0,
77
+ left: 0,
78
+ right: 0,
79
+ bottom: 0,
80
+ objectFit: "cover",
81
+ width: "100%",
82
+ height: "100%",
83
+ ...imageProps,
84
+ ref: forwardedRef,
85
+ src: resolvedSrc,
86
+ onError: function() {
87
+ setStatus("error");
88
+ },
89
+ onLoad: function() {
90
+ setStatus("loaded");
91
+ }
92
+ })
93
+ });
94
+ });
95
+ AvatarImage.displayName = IMAGE_NAME;
96
+ var FALLBACK_NAME = "AvatarFallback";
97
+ var AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
98
+ displayName: FALLBACK_NAME,
99
+ position: "absolute",
100
+ inset: 0,
101
+ zIndex: 0
102
+ });
103
+ var AvatarFallback = (0, import_core.createStyledHOC)(AvatarFallbackFrame, function(props, forwardedRef) {
104
+ var { __scopeAvatar, delay, ...fallbackProps } = props;
105
+ var context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
106
+ var [canRender, setCanRender] = React.useState(delay === void 0);
107
+ React.useEffect(function() {
108
+ if (delay !== void 0) {
109
+ var timerId = setTimeout(function() {
110
+ return setCanRender(true);
111
+ }, delay);
112
+ return function() {
113
+ return clearTimeout(timerId);
114
+ };
115
+ }
116
+ }, [delay]);
117
+ return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
118
+ ...fallbackProps,
119
+ ref: forwardedRef
120
+ }) : null;
121
+ });
122
+ AvatarFallback.displayName = FALLBACK_NAME;
123
+ var AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
124
+ displayName: AVATAR_NAME,
125
+ position: "relative",
126
+ overflow: "hidden"
127
+ });
128
+ var Avatar = (0, import_helpers.withStaticProperties)((0, import_core.createRefComponent)(function(props, forwardedRef) {
129
+ var { __scopeAvatar, size = true, ...avatarProps } = props;
130
+ var [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
131
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarProvider, {
132
+ size,
133
+ scope: __scopeAvatar,
134
+ imageLoadingStatus,
135
+ onImageLoadingStatusChange: setImageLoadingStatus,
136
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFrame, {
137
+ size,
138
+ ...avatarProps,
139
+ ref: forwardedRef
140
+ })
141
+ });
142
+ }), {
143
+ Image: AvatarImage,
144
+ Fallback: AvatarFallback
145
+ });
146
+ Avatar.displayName = AVATAR_NAME;