@cdx-ui/primitives 0.0.1-alpha.17 → 0.0.1-alpha.18
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/lib/commonjs/avatar/context.js +11 -0
- package/lib/commonjs/avatar/context.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarBadge.js +20 -0
- package/lib/commonjs/avatar/createAvatarBadge.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarIcon.js +30 -0
- package/lib/commonjs/avatar/createAvatarIcon.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarImage.js +51 -0
- package/lib/commonjs/avatar/createAvatarImage.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarRoot.js +34 -0
- package/lib/commonjs/avatar/createAvatarRoot.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarText.js +42 -0
- package/lib/commonjs/avatar/createAvatarText.js.map +1 -0
- package/lib/commonjs/avatar/index.js +30 -0
- package/lib/commonjs/avatar/index.js.map +1 -0
- package/lib/commonjs/avatar/types.js +6 -0
- package/lib/commonjs/avatar/types.js.map +1 -0
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/avatar/context.js +5 -0
- package/lib/module/avatar/context.js.map +1 -0
- package/lib/module/avatar/createAvatarBadge.js +15 -0
- package/lib/module/avatar/createAvatarBadge.js.map +1 -0
- package/lib/module/avatar/createAvatarIcon.js +25 -0
- package/lib/module/avatar/createAvatarIcon.js.map +1 -0
- package/lib/module/avatar/createAvatarImage.js +46 -0
- package/lib/module/avatar/createAvatarImage.js.map +1 -0
- package/lib/module/avatar/createAvatarRoot.js +29 -0
- package/lib/module/avatar/createAvatarRoot.js.map +1 -0
- package/lib/module/avatar/createAvatarText.js +37 -0
- package/lib/module/avatar/createAvatarText.js.map +1 -0
- package/lib/module/avatar/index.js +26 -0
- package/lib/module/avatar/index.js.map +1 -0
- package/lib/module/avatar/types.js +4 -0
- package/lib/module/avatar/types.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/avatar/context.d.ts +6 -0
- package/lib/typescript/avatar/context.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarBadge.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarBadge.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarIcon.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarIcon.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarImage.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarImage.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarRoot.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarRoot.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarText.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarText.d.ts.map +1 -0
- package/lib/typescript/avatar/index.d.ts +11 -0
- package/lib/typescript/avatar/index.d.ts.map +1 -0
- package/lib/typescript/avatar/types.d.ts +33 -0
- package/lib/typescript/avatar/types.d.ts.map +1 -0
- package/lib/typescript/checkbox/useCheckboxRoot.d.ts +3 -3
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/avatar/context.tsx +5 -0
- package/src/avatar/createAvatarBadge.tsx +12 -0
- package/src/avatar/createAvatarIcon.tsx +16 -0
- package/src/avatar/createAvatarImage.tsx +40 -0
- package/src/avatar/createAvatarRoot.tsx +23 -0
- package/src/avatar/createAvatarText.tsx +30 -0
- package/src/avatar/index.ts +43 -0
- package/src/avatar/types.ts +77 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useAvatarContext = exports.AvatarProvider = void 0;
|
|
7
|
+
var _utils = require("@cdx-ui/utils");
|
|
8
|
+
const [AvatarProvider, useAvatarContext] = (0, _utils.createContext)('AvatarContext');
|
|
9
|
+
exports.useAvatarContext = useAvatarContext;
|
|
10
|
+
exports.AvatarProvider = AvatarProvider;
|
|
11
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_utils","require","AvatarProvider","useAvatarContext","createContext","exports"],"sourceRoot":"../../../src","sources":["avatar/context.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGO,MAAM,CAACC,cAAc,EAAEC,gBAAgB,CAAC,GAC7C,IAAAC,oBAAa,EAAsB,eAAe,CAAC;AAACC,OAAA,CAAAF,gBAAA,GAAAA,gBAAA;AAAAE,OAAA,CAAAH,cAAA,GAAAA,cAAA","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAvatarBadge = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
const createAvatarBadge = BaseBadge => /*#__PURE__*/(0, _react.forwardRef)(({
|
|
10
|
+
children,
|
|
11
|
+
...props
|
|
12
|
+
}, ref) => {
|
|
13
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(BaseBadge, {
|
|
14
|
+
ref: ref,
|
|
15
|
+
...props,
|
|
16
|
+
children: children
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
exports.createAvatarBadge = createAvatarBadge;
|
|
20
|
+
//# sourceMappingURL=createAvatarBadge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_jsxRuntime","createAvatarBadge","BaseBadge","forwardRef","children","props","ref","jsx","exports"],"sourceRoot":"../../../src","sources":["avatar/createAvatarBadge.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAAmC,IAAAC,WAAA,GAAAD,OAAA;AAG5B,MAAME,iBAAiB,GAAQC,SAAiC,iBACrE,IAAAC,iBAAU,EAA6B,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EACtE,oBACE,IAAAN,WAAA,CAAAO,GAAA,EAACL,SAAS;IAACI,GAAG,EAAEA,GAAI;IAAA,GAAMD,KAAK;IAAAD,QAAA,EAC5BA;EAAQ,CACA,CAAC;AAEhB,CAAC,CAAC;AAACI,OAAA,CAAAP,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAvatarIcon = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _context = require("./context");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
const createAvatarIcon = BaseIcon => /*#__PURE__*/(0, _react.forwardRef)(({
|
|
11
|
+
children,
|
|
12
|
+
style,
|
|
13
|
+
...props
|
|
14
|
+
}, ref) => {
|
|
15
|
+
const {
|
|
16
|
+
imageLoaded,
|
|
17
|
+
imageError
|
|
18
|
+
} = (0, _context.useAvatarContext)();
|
|
19
|
+
const visible = !imageLoaded || imageError;
|
|
20
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(BaseIcon, {
|
|
21
|
+
ref: ref,
|
|
22
|
+
style: [style, !visible && {
|
|
23
|
+
opacity: 0
|
|
24
|
+
}],
|
|
25
|
+
...props,
|
|
26
|
+
children: children
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
exports.createAvatarIcon = createAvatarIcon;
|
|
30
|
+
//# sourceMappingURL=createAvatarIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_context","_jsxRuntime","createAvatarIcon","BaseIcon","forwardRef","children","style","props","ref","imageLoaded","imageError","useAvatarContext","visible","jsx","opacity","exports"],"sourceRoot":"../../../src","sources":["avatar/createAvatarIcon.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAA6C,IAAAE,WAAA,GAAAF,OAAA;AAGtC,MAAMG,gBAAgB,GAAQC,QAAgC,iBACnE,IAAAC,iBAAU,EAA4B,CAAC;EAAEC,QAAQ;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EAC5E,MAAM;IAAEC,WAAW;IAAEC;EAAW,CAAC,GAAG,IAAAC,yBAAgB,EAAC,CAAC;EACtD,MAAMC,OAAO,GAAG,CAACH,WAAW,IAAIC,UAAU;EAE1C,oBACE,IAAAT,WAAA,CAAAY,GAAA,EAACV,QAAQ;IAACK,GAAG,EAAEA,GAAI;IAACF,KAAK,EAAE,CAACA,KAAK,EAAE,CAACM,OAAO,IAAI;MAAEE,OAAO,EAAE;IAAE,CAAC,CAAE;IAAA,GAAMP,KAAK;IAAAF,QAAA,EACvEA;EAAQ,CACD,CAAC;AAEf,CAAC,CAAC;AAACU,OAAA,CAAAb,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAvatarImage = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _context = require("./context");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
const createAvatarImage = BaseImage => /*#__PURE__*/(0, _react.forwardRef)(({
|
|
11
|
+
src,
|
|
12
|
+
source,
|
|
13
|
+
onLoad,
|
|
14
|
+
onError,
|
|
15
|
+
...props
|
|
16
|
+
}, ref) => {
|
|
17
|
+
const {
|
|
18
|
+
imageError,
|
|
19
|
+
setImageLoaded,
|
|
20
|
+
setImageError
|
|
21
|
+
} = (0, _context.useAvatarContext)();
|
|
22
|
+
const resolvedSource = (0, _react.useMemo)(() => src ? {
|
|
23
|
+
uri: src
|
|
24
|
+
} : source, [src, source]);
|
|
25
|
+
(0, _react.useEffect)(() => {
|
|
26
|
+
if (!resolvedSource) {
|
|
27
|
+
setImageError(true);
|
|
28
|
+
} else {
|
|
29
|
+
setImageError(false);
|
|
30
|
+
setImageLoaded(false);
|
|
31
|
+
}
|
|
32
|
+
}, [resolvedSource, setImageError, setImageLoaded]);
|
|
33
|
+
if (!resolvedSource || imageError) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(BaseImage, {
|
|
37
|
+
ref: ref,
|
|
38
|
+
source: resolvedSource,
|
|
39
|
+
onLoad: e => {
|
|
40
|
+
setImageLoaded(true);
|
|
41
|
+
onLoad?.(e);
|
|
42
|
+
},
|
|
43
|
+
onError: e => {
|
|
44
|
+
setImageError(true);
|
|
45
|
+
onError?.(e);
|
|
46
|
+
},
|
|
47
|
+
...props
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
exports.createAvatarImage = createAvatarImage;
|
|
51
|
+
//# sourceMappingURL=createAvatarImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_context","_jsxRuntime","createAvatarImage","BaseImage","forwardRef","src","source","onLoad","onError","props","ref","imageError","setImageLoaded","setImageError","useAvatarContext","resolvedSource","useMemo","uri","useEffect","jsx","e","exports"],"sourceRoot":"../../../src","sources":["avatar/createAvatarImage.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAA6C,IAAAE,WAAA,GAAAF,OAAA;AAGtC,MAAMG,iBAAiB,GAAQC,SAAiC,iBACrE,IAAAC,iBAAU,EAA6B,CAAC;EAAEC,GAAG;EAAEC,MAAM;EAAEC,MAAM;EAAEC,OAAO;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EAC1F,MAAM;IAAEC,UAAU;IAAEC,cAAc;IAAEC;EAAc,CAAC,GAAG,IAAAC,yBAAgB,EAAC,CAAC;EAExE,MAAMC,cAAc,GAAG,IAAAC,cAAO,EAAC,MAAOX,GAAG,GAAG;IAAEY,GAAG,EAAEZ;EAAI,CAAC,GAAGC,MAAO,EAAE,CAACD,GAAG,EAAEC,MAAM,CAAC,CAAC;EAElF,IAAAY,gBAAS,EAAC,MAAM;IACd,IAAI,CAACH,cAAc,EAAE;MACnBF,aAAa,CAAC,IAAI,CAAC;IACrB,CAAC,MAAM;MACLA,aAAa,CAAC,KAAK,CAAC;MACpBD,cAAc,CAAC,KAAK,CAAC;IACvB;EACF,CAAC,EAAE,CAACG,cAAc,EAAEF,aAAa,EAAED,cAAc,CAAC,CAAC;EAEnD,IAAI,CAACG,cAAc,IAAIJ,UAAU,EAAE;IACjC,OAAO,IAAI;EACb;EAEA,oBACE,IAAAV,WAAA,CAAAkB,GAAA,EAAChB,SAAS;IACRO,GAAG,EAAEA,GAAI;IACTJ,MAAM,EAAES,cAAe;IACvBR,MAAM,EAAGa,CAAU,IAAK;MACtBR,cAAc,CAAC,IAAI,CAAC;MACnBL,MAAM,GAA4Ba,CAAC,CAAC;IACvC,CAAE;IACFZ,OAAO,EAAGY,CAAU,IAAK;MACvBP,aAAa,CAAC,IAAI,CAAC;MAClBL,OAAO,GAA4BY,CAAC,CAAC;IACxC,CAAE;IAAA,GACGX;EAAK,CACX,CAAC;AAEN,CAAC,CAAC;AAACY,OAAA,CAAAnB,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAvatarRoot = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _context = require("./context");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
const createAvatarRoot = BaseAvatar => /*#__PURE__*/(0, _react.forwardRef)(({
|
|
11
|
+
children,
|
|
12
|
+
...props
|
|
13
|
+
}, ref) => {
|
|
14
|
+
const [imageLoaded, setImageLoaded] = (0, _react.useState)(false);
|
|
15
|
+
const [imageError, setImageError] = (0, _react.useState)(false);
|
|
16
|
+
const contextValue = (0, _react.useMemo)(() => ({
|
|
17
|
+
imageLoaded,
|
|
18
|
+
imageError,
|
|
19
|
+
setImageLoaded,
|
|
20
|
+
setImageError
|
|
21
|
+
}), [imageLoaded, imageError]);
|
|
22
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.AvatarProvider, {
|
|
23
|
+
value: contextValue,
|
|
24
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(BaseAvatar, {
|
|
25
|
+
ref: ref,
|
|
26
|
+
role: "img",
|
|
27
|
+
accessibilityRole: "image",
|
|
28
|
+
...props,
|
|
29
|
+
children: children
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
exports.createAvatarRoot = createAvatarRoot;
|
|
34
|
+
//# sourceMappingURL=createAvatarRoot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_context","_jsxRuntime","createAvatarRoot","BaseAvatar","forwardRef","children","props","ref","imageLoaded","setImageLoaded","useState","imageError","setImageError","contextValue","useMemo","jsx","AvatarProvider","value","role","accessibilityRole","exports"],"sourceRoot":"../../../src","sources":["avatar/createAvatarRoot.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAA2C,IAAAE,WAAA,GAAAF,OAAA;AAGpC,MAAMG,gBAAgB,GAAQC,UAAkC,iBACrE,IAAAC,iBAAU,EAAwB,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EACjE,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAG,IAAAC,eAAQ,EAAC,KAAK,CAAC;EACrD,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAF,eAAQ,EAAC,KAAK,CAAC;EAEnD,MAAMG,YAAY,GAAG,IAAAC,cAAO,EAC1B,OAAO;IAAEN,WAAW;IAAEG,UAAU;IAAEF,cAAc;IAAEG;EAAc,CAAC,CAAC,EAClE,CAACJ,WAAW,EAAEG,UAAU,CAC1B,CAAC;EAED,oBACE,IAAAV,WAAA,CAAAc,GAAA,EAACf,QAAA,CAAAgB,cAAc;IAACC,KAAK,EAAEJ,YAAa;IAAAR,QAAA,eAClC,IAAAJ,WAAA,CAAAc,GAAA,EAACZ,UAAU;MAACI,GAAG,EAAEA,GAAI;MAACW,IAAI,EAAC,KAAK;MAACC,iBAAiB,EAAC,OAAO;MAAA,GAAMb,KAAK;MAAAD,QAAA,EAClEA;IAAQ,CACC;EAAC,CACC,CAAC;AAErB,CAAC,CAAC;AAACe,OAAA,CAAAlB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAvatarText = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _context = require("./context");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
function getInitials(name) {
|
|
11
|
+
const words = name.trim().split(/\s+/);
|
|
12
|
+
let result = '';
|
|
13
|
+
for (const word of words) {
|
|
14
|
+
if (word.length > 0) {
|
|
15
|
+
result += word.charAt(0);
|
|
16
|
+
}
|
|
17
|
+
if (result.length >= 2) break;
|
|
18
|
+
}
|
|
19
|
+
return result.toUpperCase();
|
|
20
|
+
}
|
|
21
|
+
const createAvatarText = BaseText => /*#__PURE__*/(0, _react.forwardRef)(({
|
|
22
|
+
children,
|
|
23
|
+
style,
|
|
24
|
+
...props
|
|
25
|
+
}, ref) => {
|
|
26
|
+
const {
|
|
27
|
+
imageLoaded,
|
|
28
|
+
imageError
|
|
29
|
+
} = (0, _context.useAvatarContext)();
|
|
30
|
+
const visible = !imageLoaded || imageError;
|
|
31
|
+
const text = typeof children === 'string' ? getInitials(children) : children;
|
|
32
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(BaseText, {
|
|
33
|
+
ref: ref,
|
|
34
|
+
style: [style, !visible && {
|
|
35
|
+
opacity: 0
|
|
36
|
+
}],
|
|
37
|
+
...props,
|
|
38
|
+
children: text
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
exports.createAvatarText = createAvatarText;
|
|
42
|
+
//# sourceMappingURL=createAvatarText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_context","_jsxRuntime","getInitials","name","words","trim","split","result","word","length","charAt","toUpperCase","createAvatarText","BaseText","forwardRef","children","style","props","ref","imageLoaded","imageError","useAvatarContext","visible","text","jsx","opacity","exports"],"sourceRoot":"../../../src","sources":["avatar/createAvatarText.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAA6C,IAAAE,WAAA,GAAAF,OAAA;AAG7C,SAASG,WAAWA,CAACC,IAAY,EAAU;EACzC,MAAMC,KAAK,GAAGD,IAAI,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,KAAK,CAAC;EACtC,IAAIC,MAAM,GAAG,EAAE;EACf,KAAK,MAAMC,IAAI,IAAIJ,KAAK,EAAE;IACxB,IAAII,IAAI,CAACC,MAAM,GAAG,CAAC,EAAE;MACnBF,MAAM,IAAIC,IAAI,CAACE,MAAM,CAAC,CAAC,CAAC;IAC1B;IACA,IAAIH,MAAM,CAACE,MAAM,IAAI,CAAC,EAAE;EAC1B;EACA,OAAOF,MAAM,CAACI,WAAW,CAAC,CAAC;AAC7B;AAEO,MAAMC,gBAAgB,GAAQC,QAAgC,iBACnE,IAAAC,iBAAU,EAA4B,CAAC;EAAEC,QAAQ;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EAC5E,MAAM;IAAEC,WAAW;IAAEC;EAAW,CAAC,GAAG,IAAAC,yBAAgB,EAAC,CAAC;EACtD,MAAMC,OAAO,GAAG,CAACH,WAAW,IAAIC,UAAU;EAE1C,MAAMG,IAAI,GAAG,OAAOR,QAAQ,KAAK,QAAQ,GAAGb,WAAW,CAACa,QAAQ,CAAC,GAAGA,QAAQ;EAE5E,oBACE,IAAAd,WAAA,CAAAuB,GAAA,EAACX,QAAQ;IAACK,GAAG,EAAEA,GAAI;IAACF,KAAK,EAAE,CAACA,KAAK,EAAE,CAACM,OAAO,IAAI;MAAEG,OAAO,EAAE;IAAE,CAAC,CAAE;IAAA,GAAMR,KAAK;IAAAF,QAAA,EACvEQ;EAAI,CACG,CAAC;AAEf,CAAC,CAAC;AAACG,OAAA,CAAAd,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAvatar = createAvatar;
|
|
7
|
+
var _createAvatarBadge = require("./createAvatarBadge");
|
|
8
|
+
var _createAvatarIcon = require("./createAvatarIcon");
|
|
9
|
+
var _createAvatarText = require("./createAvatarText");
|
|
10
|
+
var _createAvatarImage = require("./createAvatarImage");
|
|
11
|
+
var _createAvatarRoot = require("./createAvatarRoot");
|
|
12
|
+
function createAvatar(BaseComponents) {
|
|
13
|
+
const Avatar = (0, _createAvatarRoot.createAvatarRoot)(BaseComponents.Root);
|
|
14
|
+
const AvatarImage = (0, _createAvatarImage.createAvatarImage)(BaseComponents.Image);
|
|
15
|
+
const Text = (0, _createAvatarText.createAvatarText)(BaseComponents.Text);
|
|
16
|
+
const AvatarIcon = (0, _createAvatarIcon.createAvatarIcon)(BaseComponents.Icon);
|
|
17
|
+
const Badge = (0, _createAvatarBadge.createAvatarBadge)(BaseComponents.Badge);
|
|
18
|
+
Avatar.displayName = 'AvatarPrimitive';
|
|
19
|
+
AvatarImage.displayName = 'AvatarPrimitive.Image';
|
|
20
|
+
Text.displayName = 'AvatarPrimitive.Text';
|
|
21
|
+
AvatarIcon.displayName = 'AvatarPrimitive.Icon';
|
|
22
|
+
Badge.displayName = 'AvatarPrimitive.Badge';
|
|
23
|
+
return Object.assign(Avatar, {
|
|
24
|
+
Image: AvatarImage,
|
|
25
|
+
Text,
|
|
26
|
+
Icon: AvatarIcon,
|
|
27
|
+
Badge
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_createAvatarBadge","require","_createAvatarIcon","_createAvatarText","_createAvatarImage","_createAvatarRoot","createAvatar","BaseComponents","Avatar","createAvatarRoot","Root","AvatarImage","createAvatarImage","Image","Text","createAvatarText","AvatarIcon","createAvatarIcon","Icon","Badge","createAvatarBadge","displayName","Object","assign"],"sourceRoot":"../../../src","sources":["avatar/index.ts"],"mappings":";;;;;;AACA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAYO,SAASK,YAAYA,CAAiCC,cAM5D,EAAE;EACD,MAAMC,MAAM,GAAG,IAAAC,kCAAgB,EAACF,cAAc,CAACG,IAAI,CAAC;EACpD,MAAMC,WAAW,GAAG,IAAAC,oCAAiB,EAACL,cAAc,CAACM,KAAK,CAAC;EAC3D,MAAMC,IAAI,GAAG,IAAAC,kCAAgB,EAACR,cAAc,CAACO,IAAI,CAAC;EAClD,MAAME,UAAU,GAAG,IAAAC,kCAAgB,EAACV,cAAc,CAACW,IAAI,CAAC;EACxD,MAAMC,KAAK,GAAG,IAAAC,oCAAiB,EAACb,cAAc,CAACY,KAAK,CAAC;EAErDX,MAAM,CAACa,WAAW,GAAG,iBAAiB;EACtCV,WAAW,CAACU,WAAW,GAAG,uBAAuB;EACjDP,IAAI,CAACO,WAAW,GAAG,sBAAsB;EACzCL,UAAU,CAACK,WAAW,GAAG,sBAAsB;EAC/CF,KAAK,CAACE,WAAW,GAAG,uBAAuB;EAE3C,OAAOC,MAAM,CAACC,MAAM,CAACf,MAAM,EAAE;IAC3BK,KAAK,EAAEF,WAAW;IAClBG,IAAI;IACJI,IAAI,EAAEF,UAAU;IAChBG;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["avatar/types.ts"],"mappings":"","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -12,6 +12,18 @@ Object.defineProperty(exports, "OverlayInsetsProvider", {
|
|
|
12
12
|
return _overlay.OverlayInsetsProvider;
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
+
var _avatar = require("./avatar");
|
|
16
|
+
Object.keys(_avatar).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _avatar[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _avatar[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
15
27
|
var _button = require("./button");
|
|
16
28
|
Object.keys(_button).forEach(function (key) {
|
|
17
29
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_avatar","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_button","_checkbox","_input","_link","_overlay","_select","_switch"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","AvatarProvider","useAvatarContext"],"sourceRoot":"../../../src","sources":["avatar/context.tsx"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,eAAe;AAG7C,OAAO,MAAM,CAACC,cAAc,EAAEC,gBAAgB,CAAC,GAC7CF,aAAa,CAAsB,eAAe,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
export const createAvatarBadge = BaseBadge => /*#__PURE__*/forwardRef(({
|
|
6
|
+
children,
|
|
7
|
+
...props
|
|
8
|
+
}, ref) => {
|
|
9
|
+
return /*#__PURE__*/_jsx(BaseBadge, {
|
|
10
|
+
ref: ref,
|
|
11
|
+
...props,
|
|
12
|
+
children: children
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=createAvatarBadge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["forwardRef","jsx","_jsx","createAvatarBadge","BaseBadge","children","props","ref"],"sourceRoot":"../../../src","sources":["avatar/createAvatarBadge.tsx"],"mappings":";;AACA,SAASA,UAAU,QAAQ,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGnC,OAAO,MAAMC,iBAAiB,GAAQC,SAAiC,iBACrEJ,UAAU,CAA6B,CAAC;EAAEK,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EACtE,oBACEL,IAAA,CAACE,SAAS;IAACG,GAAG,EAAEA,GAAI;IAAA,GAAMD,KAAK;IAAAD,QAAA,EAC5BA;EAAQ,CACA,CAAC;AAEhB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { useAvatarContext } from './context';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export const createAvatarIcon = BaseIcon => /*#__PURE__*/forwardRef(({
|
|
7
|
+
children,
|
|
8
|
+
style,
|
|
9
|
+
...props
|
|
10
|
+
}, ref) => {
|
|
11
|
+
const {
|
|
12
|
+
imageLoaded,
|
|
13
|
+
imageError
|
|
14
|
+
} = useAvatarContext();
|
|
15
|
+
const visible = !imageLoaded || imageError;
|
|
16
|
+
return /*#__PURE__*/_jsx(BaseIcon, {
|
|
17
|
+
ref: ref,
|
|
18
|
+
style: [style, !visible && {
|
|
19
|
+
opacity: 0
|
|
20
|
+
}],
|
|
21
|
+
...props,
|
|
22
|
+
children: children
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=createAvatarIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["forwardRef","useAvatarContext","jsx","_jsx","createAvatarIcon","BaseIcon","children","style","props","ref","imageLoaded","imageError","visible","opacity"],"sourceRoot":"../../../src","sources":["avatar/createAvatarIcon.tsx"],"mappings":";;AACA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,gBAAgB,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAG7C,OAAO,MAAMC,gBAAgB,GAAQC,QAAgC,iBACnEL,UAAU,CAA4B,CAAC;EAAEM,QAAQ;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EAC5E,MAAM;IAAEC,WAAW;IAAEC;EAAW,CAAC,GAAGV,gBAAgB,CAAC,CAAC;EACtD,MAAMW,OAAO,GAAG,CAACF,WAAW,IAAIC,UAAU;EAE1C,oBACER,IAAA,CAACE,QAAQ;IAACI,GAAG,EAAEA,GAAI;IAACF,KAAK,EAAE,CAACA,KAAK,EAAE,CAACK,OAAO,IAAI;MAAEC,OAAO,EAAE;IAAE,CAAC,CAAE;IAAA,GAAML,KAAK;IAAAF,QAAA,EACvEA;EAAQ,CACD,CAAC;AAEf,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useEffect, useMemo } from 'react';
|
|
4
|
+
import { useAvatarContext } from './context';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export const createAvatarImage = BaseImage => /*#__PURE__*/forwardRef(({
|
|
7
|
+
src,
|
|
8
|
+
source,
|
|
9
|
+
onLoad,
|
|
10
|
+
onError,
|
|
11
|
+
...props
|
|
12
|
+
}, ref) => {
|
|
13
|
+
const {
|
|
14
|
+
imageError,
|
|
15
|
+
setImageLoaded,
|
|
16
|
+
setImageError
|
|
17
|
+
} = useAvatarContext();
|
|
18
|
+
const resolvedSource = useMemo(() => src ? {
|
|
19
|
+
uri: src
|
|
20
|
+
} : source, [src, source]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!resolvedSource) {
|
|
23
|
+
setImageError(true);
|
|
24
|
+
} else {
|
|
25
|
+
setImageError(false);
|
|
26
|
+
setImageLoaded(false);
|
|
27
|
+
}
|
|
28
|
+
}, [resolvedSource, setImageError, setImageLoaded]);
|
|
29
|
+
if (!resolvedSource || imageError) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return /*#__PURE__*/_jsx(BaseImage, {
|
|
33
|
+
ref: ref,
|
|
34
|
+
source: resolvedSource,
|
|
35
|
+
onLoad: e => {
|
|
36
|
+
setImageLoaded(true);
|
|
37
|
+
onLoad?.(e);
|
|
38
|
+
},
|
|
39
|
+
onError: e => {
|
|
40
|
+
setImageError(true);
|
|
41
|
+
onError?.(e);
|
|
42
|
+
},
|
|
43
|
+
...props
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=createAvatarImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["forwardRef","useEffect","useMemo","useAvatarContext","jsx","_jsx","createAvatarImage","BaseImage","src","source","onLoad","onError","props","ref","imageError","setImageLoaded","setImageError","resolvedSource","uri","e"],"sourceRoot":"../../../src","sources":["avatar/createAvatarImage.tsx"],"mappings":";;AACA,SAASA,UAAU,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AACtD,SAASC,gBAAgB,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAG7C,OAAO,MAAMC,iBAAiB,GAAQC,SAAiC,iBACrEP,UAAU,CAA6B,CAAC;EAAEQ,GAAG;EAAEC,MAAM;EAAEC,MAAM;EAAEC,OAAO;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EAC1F,MAAM;IAAEC,UAAU;IAAEC,cAAc;IAAEC;EAAc,CAAC,GAAGb,gBAAgB,CAAC,CAAC;EAExE,MAAMc,cAAc,GAAGf,OAAO,CAAC,MAAOM,GAAG,GAAG;IAAEU,GAAG,EAAEV;EAAI,CAAC,GAAGC,MAAO,EAAE,CAACD,GAAG,EAAEC,MAAM,CAAC,CAAC;EAElFR,SAAS,CAAC,MAAM;IACd,IAAI,CAACgB,cAAc,EAAE;MACnBD,aAAa,CAAC,IAAI,CAAC;IACrB,CAAC,MAAM;MACLA,aAAa,CAAC,KAAK,CAAC;MACpBD,cAAc,CAAC,KAAK,CAAC;IACvB;EACF,CAAC,EAAE,CAACE,cAAc,EAAED,aAAa,EAAED,cAAc,CAAC,CAAC;EAEnD,IAAI,CAACE,cAAc,IAAIH,UAAU,EAAE;IACjC,OAAO,IAAI;EACb;EAEA,oBACET,IAAA,CAACE,SAAS;IACRM,GAAG,EAAEA,GAAI;IACTJ,MAAM,EAAEQ,cAAe;IACvBP,MAAM,EAAGS,CAAU,IAAK;MACtBJ,cAAc,CAAC,IAAI,CAAC;MACnBL,MAAM,GAA4BS,CAAC,CAAC;IACvC,CAAE;IACFR,OAAO,EAAGQ,CAAU,IAAK;MACvBH,aAAa,CAAC,IAAI,CAAC;MAClBL,OAAO,GAA4BQ,CAAC,CAAC;IACxC,CAAE;IAAA,GACGP;EAAK,CACX,CAAC;AAEN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useMemo, useState } from 'react';
|
|
4
|
+
import { AvatarProvider } from './context';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export const createAvatarRoot = BaseAvatar => /*#__PURE__*/forwardRef(({
|
|
7
|
+
children,
|
|
8
|
+
...props
|
|
9
|
+
}, ref) => {
|
|
10
|
+
const [imageLoaded, setImageLoaded] = useState(false);
|
|
11
|
+
const [imageError, setImageError] = useState(false);
|
|
12
|
+
const contextValue = useMemo(() => ({
|
|
13
|
+
imageLoaded,
|
|
14
|
+
imageError,
|
|
15
|
+
setImageLoaded,
|
|
16
|
+
setImageError
|
|
17
|
+
}), [imageLoaded, imageError]);
|
|
18
|
+
return /*#__PURE__*/_jsx(AvatarProvider, {
|
|
19
|
+
value: contextValue,
|
|
20
|
+
children: /*#__PURE__*/_jsx(BaseAvatar, {
|
|
21
|
+
ref: ref,
|
|
22
|
+
role: "img",
|
|
23
|
+
accessibilityRole: "image",
|
|
24
|
+
...props,
|
|
25
|
+
children: children
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=createAvatarRoot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["forwardRef","useMemo","useState","AvatarProvider","jsx","_jsx","createAvatarRoot","BaseAvatar","children","props","ref","imageLoaded","setImageLoaded","imageError","setImageError","contextValue","value","role","accessibilityRole"],"sourceRoot":"../../../src","sources":["avatar/createAvatarRoot.tsx"],"mappings":";;AACA,SAASA,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACrD,SAASC,cAAc,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAG3C,OAAO,MAAMC,gBAAgB,GAAQC,UAAkC,iBACrEP,UAAU,CAAwB,CAAC;EAAEQ,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EACjE,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGV,QAAQ,CAAC,KAAK,CAAC;EACrD,MAAM,CAACW,UAAU,EAAEC,aAAa,CAAC,GAAGZ,QAAQ,CAAC,KAAK,CAAC;EAEnD,MAAMa,YAAY,GAAGd,OAAO,CAC1B,OAAO;IAAEU,WAAW;IAAEE,UAAU;IAAED,cAAc;IAAEE;EAAc,CAAC,CAAC,EAClE,CAACH,WAAW,EAAEE,UAAU,CAC1B,CAAC;EAED,oBACER,IAAA,CAACF,cAAc;IAACa,KAAK,EAAED,YAAa;IAAAP,QAAA,eAClCH,IAAA,CAACE,UAAU;MAACG,GAAG,EAAEA,GAAI;MAACO,IAAI,EAAC,KAAK;MAACC,iBAAiB,EAAC,OAAO;MAAA,GAAMT,KAAK;MAAAD,QAAA,EAClEA;IAAQ,CACC;EAAC,CACC,CAAC;AAErB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { useAvatarContext } from './context';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
function getInitials(name) {
|
|
7
|
+
const words = name.trim().split(/\s+/);
|
|
8
|
+
let result = '';
|
|
9
|
+
for (const word of words) {
|
|
10
|
+
if (word.length > 0) {
|
|
11
|
+
result += word.charAt(0);
|
|
12
|
+
}
|
|
13
|
+
if (result.length >= 2) break;
|
|
14
|
+
}
|
|
15
|
+
return result.toUpperCase();
|
|
16
|
+
}
|
|
17
|
+
export const createAvatarText = BaseText => /*#__PURE__*/forwardRef(({
|
|
18
|
+
children,
|
|
19
|
+
style,
|
|
20
|
+
...props
|
|
21
|
+
}, ref) => {
|
|
22
|
+
const {
|
|
23
|
+
imageLoaded,
|
|
24
|
+
imageError
|
|
25
|
+
} = useAvatarContext();
|
|
26
|
+
const visible = !imageLoaded || imageError;
|
|
27
|
+
const text = typeof children === 'string' ? getInitials(children) : children;
|
|
28
|
+
return /*#__PURE__*/_jsx(BaseText, {
|
|
29
|
+
ref: ref,
|
|
30
|
+
style: [style, !visible && {
|
|
31
|
+
opacity: 0
|
|
32
|
+
}],
|
|
33
|
+
...props,
|
|
34
|
+
children: text
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=createAvatarText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["forwardRef","useAvatarContext","jsx","_jsx","getInitials","name","words","trim","split","result","word","length","charAt","toUpperCase","createAvatarText","BaseText","children","style","props","ref","imageLoaded","imageError","visible","text","opacity"],"sourceRoot":"../../../src","sources":["avatar/createAvatarText.tsx"],"mappings":";;AACA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,gBAAgB,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAG7C,SAASC,WAAWA,CAACC,IAAY,EAAU;EACzC,MAAMC,KAAK,GAAGD,IAAI,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,KAAK,CAAC;EACtC,IAAIC,MAAM,GAAG,EAAE;EACf,KAAK,MAAMC,IAAI,IAAIJ,KAAK,EAAE;IACxB,IAAII,IAAI,CAACC,MAAM,GAAG,CAAC,EAAE;MACnBF,MAAM,IAAIC,IAAI,CAACE,MAAM,CAAC,CAAC,CAAC;IAC1B;IACA,IAAIH,MAAM,CAACE,MAAM,IAAI,CAAC,EAAE;EAC1B;EACA,OAAOF,MAAM,CAACI,WAAW,CAAC,CAAC;AAC7B;AAEA,OAAO,MAAMC,gBAAgB,GAAQC,QAAgC,iBACnEf,UAAU,CAA4B,CAAC;EAAEgB,QAAQ;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EAC5E,MAAM;IAAEC,WAAW;IAAEC;EAAW,CAAC,GAAGpB,gBAAgB,CAAC,CAAC;EACtD,MAAMqB,OAAO,GAAG,CAACF,WAAW,IAAIC,UAAU;EAE1C,MAAME,IAAI,GAAG,OAAOP,QAAQ,KAAK,QAAQ,GAAGZ,WAAW,CAACY,QAAQ,CAAC,GAAGA,QAAQ;EAE5E,oBACEb,IAAA,CAACY,QAAQ;IAACI,GAAG,EAAEA,GAAI;IAACF,KAAK,EAAE,CAACA,KAAK,EAAE,CAACK,OAAO,IAAI;MAAEE,OAAO,EAAE;IAAE,CAAC,CAAE;IAAA,GAAMN,KAAK;IAAAF,QAAA,EACvEO;EAAI,CACG,CAAC;AAEf,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createAvatarBadge } from './createAvatarBadge';
|
|
4
|
+
import { createAvatarIcon } from './createAvatarIcon';
|
|
5
|
+
import { createAvatarText } from './createAvatarText';
|
|
6
|
+
import { createAvatarImage } from './createAvatarImage';
|
|
7
|
+
import { createAvatarRoot } from './createAvatarRoot';
|
|
8
|
+
export function createAvatar(BaseComponents) {
|
|
9
|
+
const Avatar = createAvatarRoot(BaseComponents.Root);
|
|
10
|
+
const AvatarImage = createAvatarImage(BaseComponents.Image);
|
|
11
|
+
const Text = createAvatarText(BaseComponents.Text);
|
|
12
|
+
const AvatarIcon = createAvatarIcon(BaseComponents.Icon);
|
|
13
|
+
const Badge = createAvatarBadge(BaseComponents.Badge);
|
|
14
|
+
Avatar.displayName = 'AvatarPrimitive';
|
|
15
|
+
AvatarImage.displayName = 'AvatarPrimitive.Image';
|
|
16
|
+
Text.displayName = 'AvatarPrimitive.Text';
|
|
17
|
+
AvatarIcon.displayName = 'AvatarPrimitive.Icon';
|
|
18
|
+
Badge.displayName = 'AvatarPrimitive.Badge';
|
|
19
|
+
return Object.assign(Avatar, {
|
|
20
|
+
Image: AvatarImage,
|
|
21
|
+
Text,
|
|
22
|
+
Icon: AvatarIcon,
|
|
23
|
+
Badge
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAvatarBadge","createAvatarIcon","createAvatarText","createAvatarImage","createAvatarRoot","createAvatar","BaseComponents","Avatar","Root","AvatarImage","Image","Text","AvatarIcon","Icon","Badge","displayName","Object","assign"],"sourceRoot":"../../../src","sources":["avatar/index.ts"],"mappings":";;AACA,SAASA,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,gBAAgB,QAAQ,oBAAoB;AAYrD,OAAO,SAASC,YAAYA,CAAiCC,cAM5D,EAAE;EACD,MAAMC,MAAM,GAAGH,gBAAgB,CAACE,cAAc,CAACE,IAAI,CAAC;EACpD,MAAMC,WAAW,GAAGN,iBAAiB,CAACG,cAAc,CAACI,KAAK,CAAC;EAC3D,MAAMC,IAAI,GAAGT,gBAAgB,CAACI,cAAc,CAACK,IAAI,CAAC;EAClD,MAAMC,UAAU,GAAGX,gBAAgB,CAACK,cAAc,CAACO,IAAI,CAAC;EACxD,MAAMC,KAAK,GAAGd,iBAAiB,CAACM,cAAc,CAACQ,KAAK,CAAC;EAErDP,MAAM,CAACQ,WAAW,GAAG,iBAAiB;EACtCN,WAAW,CAACM,WAAW,GAAG,uBAAuB;EACjDJ,IAAI,CAACI,WAAW,GAAG,sBAAsB;EACzCH,UAAU,CAACG,WAAW,GAAG,sBAAsB;EAC/CD,KAAK,CAACC,WAAW,GAAG,uBAAuB;EAE3C,OAAOC,MAAM,CAACC,MAAM,CAACV,MAAM,EAAE;IAC3BG,KAAK,EAAED,WAAW;IAClBE,IAAI;IACJE,IAAI,EAAED,UAAU;IAChBE;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["avatar/types.ts"],"mappings":"","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["OverlayInsetsProvider"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,UAAU;AACxB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,SAA0BA,qBAAqB,QAAQ,WAAW;AAClE,cAAc,UAAU;AACxB,cAAc,UAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["OverlayInsetsProvider"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ;AACtB,SAA0BA,qBAAqB,QAAQ,WAAW;AAClE,cAAc,UAAU;AACxB,cAAc,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IAvatarContextValue } from './types';
|
|
2
|
+
export declare const AvatarProvider: import("react").FunctionComponent<{
|
|
3
|
+
children: import("react").ReactNode;
|
|
4
|
+
value: IAvatarContextValue;
|
|
5
|
+
}>, useAvatarContext: () => IAvatarContextValue;
|
|
6
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/avatar/context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,eAAO,MAAO,cAAc;;;IAAE,gBAAgB,2BACO,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IAvatarBadgeProps } from './types';
|
|
3
|
+
export declare const createAvatarBadge: <T>(BaseBadge: React.ComponentType<T>) => React.ForwardRefExoticComponent<IAvatarBadgeProps & React.RefAttributes<unknown>>;
|
|
4
|
+
//# sourceMappingURL=createAvatarBadge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAvatarBadge.d.ts","sourceRoot":"","sources":["../../../src/avatar/createAvatarBadge.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAG,WAAW,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,sFAOnE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IAvatarIconProps } from './types';
|
|
3
|
+
export declare const createAvatarIcon: <T>(BaseIcon: React.ComponentType<T>) => React.ForwardRefExoticComponent<IAvatarIconProps & React.RefAttributes<unknown>>;
|
|
4
|
+
//# sourceMappingURL=createAvatarIcon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAvatarIcon.d.ts","sourceRoot":"","sources":["../../../src/avatar/createAvatarIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAG,UAAU,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,qFAUjE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IAvatarImageProps } from './types';
|
|
3
|
+
export declare const createAvatarImage: <T>(BaseImage: React.ComponentType<T>) => React.ForwardRefExoticComponent<IAvatarImageProps & React.RefAttributes<unknown>>;
|
|
4
|
+
//# sourceMappingURL=createAvatarImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAvatarImage.d.ts","sourceRoot":"","sources":["../../../src/avatar/createAvatarImage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAG,WAAW,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,sFAkCnE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IAvatarProps } from './types';
|
|
3
|
+
export declare const createAvatarRoot: <T>(BaseAvatar: React.ComponentType<T>) => React.ForwardRefExoticComponent<IAvatarProps & React.RefAttributes<unknown>>;
|
|
4
|
+
//# sourceMappingURL=createAvatarRoot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAvatarRoot.d.ts","sourceRoot":"","sources":["../../../src/avatar/createAvatarRoot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAG,YAAY,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,iFAiBnE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IAvatarTextProps } from './types';
|
|
3
|
+
export declare const createAvatarText: <T>(BaseText: React.ComponentType<T>) => React.ForwardRefExoticComponent<IAvatarTextProps & React.RefAttributes<unknown>>;
|
|
4
|
+
//# sourceMappingURL=createAvatarText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAvatarText.d.ts","sourceRoot":"","sources":["../../../src/avatar/createAvatarText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAchD,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAG,UAAU,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,qFAYjE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IAvatarComponentType } from './types';
|
|
3
|
+
export type { IAvatarBadgeProps, IAvatarComponentType, IAvatarIconProps, IAvatarTextProps, IAvatarImageProps, IAvatarProps, } from './types';
|
|
4
|
+
export declare function createAvatar<Root, Image, Text, Icon, Badge>(BaseComponents: {
|
|
5
|
+
Root: React.ComponentType<Root>;
|
|
6
|
+
Image: React.ComponentType<Image>;
|
|
7
|
+
Text: React.ComponentType<Text>;
|
|
8
|
+
Icon: React.ComponentType<Icon>;
|
|
9
|
+
Badge: React.ComponentType<Badge>;
|
|
10
|
+
}): IAvatarComponentType<Root, Image, Text, Icon, Badge>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/avatar/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,wBAAgB,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE;IAC3E,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;CACnC,GAkBkB,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CACtE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ImageProps, TextProps, ViewProps } from 'react-native';
|
|
2
|
+
export interface IAvatarProps extends ViewProps {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export interface IAvatarImageProps extends Omit<ImageProps, 'source'> {
|
|
6
|
+
/** Image source — URI string or RN ImageSourcePropType */
|
|
7
|
+
src?: string;
|
|
8
|
+
source?: ImageProps['source'];
|
|
9
|
+
alt?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IAvatarTextProps extends TextProps {
|
|
12
|
+
/** Full name — initials will be derived automatically */
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export interface IAvatarIconProps extends ViewProps {
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export interface IAvatarBadgeProps extends ViewProps {
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export interface IAvatarContextValue {
|
|
22
|
+
imageLoaded: boolean;
|
|
23
|
+
imageError: boolean;
|
|
24
|
+
setImageLoaded: (loaded: boolean) => void;
|
|
25
|
+
setImageError: (error: boolean) => void;
|
|
26
|
+
}
|
|
27
|
+
export type IAvatarComponentType<Root, Image, Text, Icon, Badge> = React.ForwardRefExoticComponent<React.RefAttributes<Root> & React.PropsWithoutRef<Root> & IAvatarProps> & {
|
|
28
|
+
Image: React.ForwardRefExoticComponent<React.RefAttributes<Image> & React.PropsWithoutRef<Image> & IAvatarImageProps>;
|
|
29
|
+
Text: React.ForwardRefExoticComponent<React.RefAttributes<Text> & React.PropsWithoutRef<Text> & IAvatarTextProps>;
|
|
30
|
+
Icon: React.ForwardRefExoticComponent<React.RefAttributes<Icon> & React.PropsWithoutRef<Icon> & IAvatarIconProps>;
|
|
31
|
+
Badge: React.ForwardRefExoticComponent<React.RefAttributes<Badge> & React.PropsWithoutRef<Badge> & IAvatarBadgeProps>;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/avatar/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMrE,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAMD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;IACnE,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAMD,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD,yDAAyD;IACzD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAMD,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAMD,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAMD,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1C,aAAa,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACzC;AAMD,MAAM,MAAM,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,IAAI,KAAK,CAAC,yBAAyB,CAChG,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,YAAY,CACvE,GAAG;IACF,KAAK,EAAE,KAAK,CAAC,yBAAyB,CACpC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAC9E,CAAC;IACF,IAAI,EAAE,KAAK,CAAC,yBAAyB,CACnC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAC3E,CAAC;IACF,IAAI,EAAE,KAAK,CAAC,yBAAyB,CACnC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAC3E,CAAC;IACF,KAAK,EAAE,KAAK,CAAC,yBAAyB,CACpC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAC9E,CAAC;CACH,CAAC"}
|
|
@@ -73,12 +73,12 @@ export declare function useCheckboxRoot(props: ICheckboxProps, ref?: React.Ref<u
|
|
|
73
73
|
accessibilityLargeContentTitle?: string | undefined;
|
|
74
74
|
accessibilityRespondsToUserInteraction?: boolean | undefined;
|
|
75
75
|
id?: string | undefined;
|
|
76
|
-
needsOffscreenAlphaCompositing?: boolean | undefined | undefined;
|
|
77
76
|
onLayout?: ((event: import("react-native").LayoutChangeEvent) => void) | undefined | undefined;
|
|
78
|
-
pointerEvents?: "box-none" | "none" | "box-only" | "auto" | undefined | undefined;
|
|
79
|
-
removeClippedSubviews?: boolean | undefined | undefined;
|
|
80
77
|
testID?: string | undefined | undefined;
|
|
81
78
|
nativeID?: string | undefined | undefined;
|
|
79
|
+
needsOffscreenAlphaCompositing?: boolean | undefined | undefined;
|
|
80
|
+
pointerEvents?: "box-none" | "none" | "box-only" | "auto" | undefined | undefined;
|
|
81
|
+
removeClippedSubviews?: boolean | undefined | undefined;
|
|
82
82
|
collapsable?: boolean | undefined | undefined;
|
|
83
83
|
collapsableChildren?: boolean | undefined | undefined;
|
|
84
84
|
renderToHardwareTextureAndroid?: boolean | undefined | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,KAAK,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACnE,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,KAAK,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACnE,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdx-ui/primitives",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.18",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"module": "lib/module/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@react-native-aria/interactions": "^0.2.16",
|
|
53
53
|
"@react-stately/checkbox": "3.7.4",
|
|
54
54
|
"@react-stately/toggle": "3.9.4",
|
|
55
|
-
"@cdx-ui/utils": "0.0.1-alpha.
|
|
55
|
+
"@cdx-ui/utils": "0.0.1-alpha.18"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/react": "*",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import type { IAvatarBadgeProps } from './types';
|
|
4
|
+
|
|
5
|
+
export const createAvatarBadge = <T,>(BaseBadge: React.ComponentType<T>) =>
|
|
6
|
+
forwardRef<unknown, IAvatarBadgeProps>(({ children, ...props }, ref) => {
|
|
7
|
+
return (
|
|
8
|
+
<BaseBadge ref={ref} {...(props as T)}>
|
|
9
|
+
{children}
|
|
10
|
+
</BaseBadge>
|
|
11
|
+
);
|
|
12
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { useAvatarContext } from './context';
|
|
4
|
+
import type { IAvatarIconProps } from './types';
|
|
5
|
+
|
|
6
|
+
export const createAvatarIcon = <T,>(BaseIcon: React.ComponentType<T>) =>
|
|
7
|
+
forwardRef<unknown, IAvatarIconProps>(({ children, style, ...props }, ref) => {
|
|
8
|
+
const { imageLoaded, imageError } = useAvatarContext();
|
|
9
|
+
const visible = !imageLoaded || imageError;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<BaseIcon ref={ref} style={[style, !visible && { opacity: 0 }]} {...(props as T)}>
|
|
13
|
+
{children}
|
|
14
|
+
</BaseIcon>
|
|
15
|
+
);
|
|
16
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef, useEffect, useMemo } from 'react';
|
|
3
|
+
import { useAvatarContext } from './context';
|
|
4
|
+
import type { IAvatarImageProps } from './types';
|
|
5
|
+
|
|
6
|
+
export const createAvatarImage = <T,>(BaseImage: React.ComponentType<T>) =>
|
|
7
|
+
forwardRef<unknown, IAvatarImageProps>(({ src, source, onLoad, onError, ...props }, ref) => {
|
|
8
|
+
const { imageError, setImageLoaded, setImageError } = useAvatarContext();
|
|
9
|
+
|
|
10
|
+
const resolvedSource = useMemo(() => (src ? { uri: src } : source), [src, source]);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!resolvedSource) {
|
|
14
|
+
setImageError(true);
|
|
15
|
+
} else {
|
|
16
|
+
setImageError(false);
|
|
17
|
+
setImageLoaded(false);
|
|
18
|
+
}
|
|
19
|
+
}, [resolvedSource, setImageError, setImageLoaded]);
|
|
20
|
+
|
|
21
|
+
if (!resolvedSource || imageError) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<BaseImage
|
|
27
|
+
ref={ref}
|
|
28
|
+
source={resolvedSource}
|
|
29
|
+
onLoad={(e: unknown) => {
|
|
30
|
+
setImageLoaded(true);
|
|
31
|
+
(onLoad as (e: unknown) => void)?.(e);
|
|
32
|
+
}}
|
|
33
|
+
onError={(e: unknown) => {
|
|
34
|
+
setImageError(true);
|
|
35
|
+
(onError as (e: unknown) => void)?.(e);
|
|
36
|
+
}}
|
|
37
|
+
{...(props as T)}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef, useMemo, useState } from 'react';
|
|
3
|
+
import { AvatarProvider } from './context';
|
|
4
|
+
import type { IAvatarProps } from './types';
|
|
5
|
+
|
|
6
|
+
export const createAvatarRoot = <T,>(BaseAvatar: React.ComponentType<T>) =>
|
|
7
|
+
forwardRef<unknown, IAvatarProps>(({ children, ...props }, ref) => {
|
|
8
|
+
const [imageLoaded, setImageLoaded] = useState(false);
|
|
9
|
+
const [imageError, setImageError] = useState(false);
|
|
10
|
+
|
|
11
|
+
const contextValue = useMemo(
|
|
12
|
+
() => ({ imageLoaded, imageError, setImageLoaded, setImageError }),
|
|
13
|
+
[imageLoaded, imageError],
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<AvatarProvider value={contextValue}>
|
|
18
|
+
<BaseAvatar ref={ref} role="img" accessibilityRole="image" {...(props as T)}>
|
|
19
|
+
{children}
|
|
20
|
+
</BaseAvatar>
|
|
21
|
+
</AvatarProvider>
|
|
22
|
+
);
|
|
23
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { useAvatarContext } from './context';
|
|
4
|
+
import type { IAvatarTextProps } from './types';
|
|
5
|
+
|
|
6
|
+
function getInitials(name: string): string {
|
|
7
|
+
const words = name.trim().split(/\s+/);
|
|
8
|
+
let result = '';
|
|
9
|
+
for (const word of words) {
|
|
10
|
+
if (word.length > 0) {
|
|
11
|
+
result += word.charAt(0);
|
|
12
|
+
}
|
|
13
|
+
if (result.length >= 2) break;
|
|
14
|
+
}
|
|
15
|
+
return result.toUpperCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const createAvatarText = <T,>(BaseText: React.ComponentType<T>) =>
|
|
19
|
+
forwardRef<unknown, IAvatarTextProps>(({ children, style, ...props }, ref) => {
|
|
20
|
+
const { imageLoaded, imageError } = useAvatarContext();
|
|
21
|
+
const visible = !imageLoaded || imageError;
|
|
22
|
+
|
|
23
|
+
const text = typeof children === 'string' ? getInitials(children) : children;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<BaseText ref={ref} style={[style, !visible && { opacity: 0 }]} {...(props as T)}>
|
|
27
|
+
{text}
|
|
28
|
+
</BaseText>
|
|
29
|
+
);
|
|
30
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { createAvatarBadge } from './createAvatarBadge';
|
|
3
|
+
import { createAvatarIcon } from './createAvatarIcon';
|
|
4
|
+
import { createAvatarText } from './createAvatarText';
|
|
5
|
+
import { createAvatarImage } from './createAvatarImage';
|
|
6
|
+
import { createAvatarRoot } from './createAvatarRoot';
|
|
7
|
+
import type { IAvatarComponentType } from './types';
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
IAvatarBadgeProps,
|
|
11
|
+
IAvatarComponentType,
|
|
12
|
+
IAvatarIconProps,
|
|
13
|
+
IAvatarTextProps,
|
|
14
|
+
IAvatarImageProps,
|
|
15
|
+
IAvatarProps,
|
|
16
|
+
} from './types';
|
|
17
|
+
|
|
18
|
+
export function createAvatar<Root, Image, Text, Icon, Badge>(BaseComponents: {
|
|
19
|
+
Root: React.ComponentType<Root>;
|
|
20
|
+
Image: React.ComponentType<Image>;
|
|
21
|
+
Text: React.ComponentType<Text>;
|
|
22
|
+
Icon: React.ComponentType<Icon>;
|
|
23
|
+
Badge: React.ComponentType<Badge>;
|
|
24
|
+
}) {
|
|
25
|
+
const Avatar = createAvatarRoot(BaseComponents.Root);
|
|
26
|
+
const AvatarImage = createAvatarImage(BaseComponents.Image);
|
|
27
|
+
const Text = createAvatarText(BaseComponents.Text);
|
|
28
|
+
const AvatarIcon = createAvatarIcon(BaseComponents.Icon);
|
|
29
|
+
const Badge = createAvatarBadge(BaseComponents.Badge);
|
|
30
|
+
|
|
31
|
+
Avatar.displayName = 'AvatarPrimitive';
|
|
32
|
+
AvatarImage.displayName = 'AvatarPrimitive.Image';
|
|
33
|
+
Text.displayName = 'AvatarPrimitive.Text';
|
|
34
|
+
AvatarIcon.displayName = 'AvatarPrimitive.Icon';
|
|
35
|
+
Badge.displayName = 'AvatarPrimitive.Badge';
|
|
36
|
+
|
|
37
|
+
return Object.assign(Avatar, {
|
|
38
|
+
Image: AvatarImage,
|
|
39
|
+
Text,
|
|
40
|
+
Icon: AvatarIcon,
|
|
41
|
+
Badge,
|
|
42
|
+
}) as unknown as IAvatarComponentType<Root, Image, Text, Icon, Badge>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ImageProps, TextProps, ViewProps } from 'react-native';
|
|
2
|
+
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// AVATAR ROOT
|
|
5
|
+
// =============================================================================
|
|
6
|
+
|
|
7
|
+
export interface IAvatarProps extends ViewProps {
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// AVATAR IMAGE
|
|
13
|
+
// =============================================================================
|
|
14
|
+
|
|
15
|
+
export interface IAvatarImageProps extends Omit<ImageProps, 'source'> {
|
|
16
|
+
/** Image source — URI string or RN ImageSourcePropType */
|
|
17
|
+
src?: string;
|
|
18
|
+
source?: ImageProps['source'];
|
|
19
|
+
alt?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// AVATAR FALLBACK TEXT
|
|
24
|
+
// =============================================================================
|
|
25
|
+
|
|
26
|
+
export interface IAvatarTextProps extends TextProps {
|
|
27
|
+
/** Full name — initials will be derived automatically */
|
|
28
|
+
children?: React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// =============================================================================
|
|
32
|
+
// AVATAR ICON (fallback icon — hidden when image loads)
|
|
33
|
+
// =============================================================================
|
|
34
|
+
|
|
35
|
+
export interface IAvatarIconProps extends ViewProps {
|
|
36
|
+
children?: React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// =============================================================================
|
|
40
|
+
// AVATAR BADGE
|
|
41
|
+
// =============================================================================
|
|
42
|
+
|
|
43
|
+
export interface IAvatarBadgeProps extends ViewProps {
|
|
44
|
+
children?: React.ReactNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// =============================================================================
|
|
48
|
+
// CONTEXT
|
|
49
|
+
// =============================================================================
|
|
50
|
+
|
|
51
|
+
export interface IAvatarContextValue {
|
|
52
|
+
imageLoaded: boolean;
|
|
53
|
+
imageError: boolean;
|
|
54
|
+
setImageLoaded: (loaded: boolean) => void;
|
|
55
|
+
setImageError: (error: boolean) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// =============================================================================
|
|
59
|
+
// COMPOUND COMPONENT TYPE
|
|
60
|
+
// =============================================================================
|
|
61
|
+
|
|
62
|
+
export type IAvatarComponentType<Root, Image, Text, Icon, Badge> = React.ForwardRefExoticComponent<
|
|
63
|
+
React.RefAttributes<Root> & React.PropsWithoutRef<Root> & IAvatarProps
|
|
64
|
+
> & {
|
|
65
|
+
Image: React.ForwardRefExoticComponent<
|
|
66
|
+
React.RefAttributes<Image> & React.PropsWithoutRef<Image> & IAvatarImageProps
|
|
67
|
+
>;
|
|
68
|
+
Text: React.ForwardRefExoticComponent<
|
|
69
|
+
React.RefAttributes<Text> & React.PropsWithoutRef<Text> & IAvatarTextProps
|
|
70
|
+
>;
|
|
71
|
+
Icon: React.ForwardRefExoticComponent<
|
|
72
|
+
React.RefAttributes<Icon> & React.PropsWithoutRef<Icon> & IAvatarIconProps
|
|
73
|
+
>;
|
|
74
|
+
Badge: React.ForwardRefExoticComponent<
|
|
75
|
+
React.RefAttributes<Badge> & React.PropsWithoutRef<Badge> & IAvatarBadgeProps
|
|
76
|
+
>;
|
|
77
|
+
};
|
package/src/index.ts
CHANGED