@stackshift-ui/avatar 6.0.2 → 6.0.4-beta.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/dist/avatar.js +1 -1
- package/dist/avatar.mjs +1 -1
- package/dist/chunk-ZPYNVPAC.mjs +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +8 -7
- package/src/avatar.test.tsx +24 -0
- package/src/avatar.tsx +77 -0
- package/src/index.ts +4 -0
- package/dist/chunk-ZGTLWTPQ.mjs +0 -1
package/dist/avatar.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var A=Object.create;var l=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var P=(e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:!0})},c=(e,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of M(t))!I.call(e,r)&&r!==a&&l(e,r,{get:()=>t[r],enumerable:!(s=L(t,r))||s.enumerable});return e};var E=(e,t,a)=>(a=e!=null?A(T(e)):{},c(t||!e||!e.__esModule?l(a,"default",{value:e,enumerable:!0}):a,e)),F=e=>c(l({},"__esModule",{value:!0}),e);var H={};P(H,{Avatar:()=>y});module.exports=F(H);var d=require("@stackshift-ui/flex"),f=require("@stackshift-ui/image"),m=require("@stackshift-ui/system"),g=E(require("classnames")),u=require("react"),o=require("react/jsx-runtime"),i="Avatar",y=({src:e,alt:t="image",size:a="sm",text:s,children:r,className:h,as:b,...N})=>{var p;let{[i]:v=m.DefaultComponent}=(0,m.useStackShiftUIComponents)(),[x,C]=(0,u.useState)(!1),n=typeof a=="number"?`${a}px`:`${{sm:40,md:80,lg:120,xl:160}[a]}px`,S=s?(p=s==null?void 0:s.split(" "))==null?void 0:p.reduce((z,w)=>z+w[0],""):"AB";return(0,o.jsxs)(v,{as:b,className:(0,g.default)("relative flex rounded-full aspect-square overflow-hidden border-2 border-solid border-primary",h),style:{maxWidth:n},...N,"data-testid":i,children:[(!x||!e)&&(0,o.jsx)(d.Flex,{align:"center",justify:"center",className:"w-full h-full bg-primary",children:(0,o.jsx)("p",{style:{fontSize:`calc(${n}/2)`},className:"text-white",children:S})}),e&&(0,o.jsx)(f.Image,{className:"object-cover object-center w-[100%] h-[100%]",src:e,alt:t,width:100,height:100,onLoad:()=>C(!0)})]})};y.displayName=i;0&&(module.exports={Avatar});
|
package/dist/avatar.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-ZPYNVPAC.mjs";export{a as Avatar};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Flex as h}from"@stackshift-ui/flex";import{Image as b}from"@stackshift-ui/image";import{DefaultComponent as N,useStackShiftUIComponents as v}from"@stackshift-ui/system";import x from"classnames";import{useState as C}from"react";import{jsx as s,jsxs as z}from"react/jsx-runtime";var r="Avatar",S=({src:t,alt:m="image",size:a="sm",text:e,children:w,className:i,as:n,...p})=>{var l;let{[r]:c=N}=v(),[d,f]=C(!1),o=typeof a=="number"?`${a}px`:`${{sm:40,md:80,lg:120,xl:160}[a]}px`,g=e?(l=e==null?void 0:e.split(" "))==null?void 0:l.reduce((u,y)=>u+y[0],""):"AB";return z(c,{as:n,className:x("relative flex rounded-full aspect-square overflow-hidden border-2 border-solid border-primary",i),style:{maxWidth:o},...p,"data-testid":r,children:[(!d||!t)&&s(h,{align:"center",justify:"center",className:"w-full h-full bg-primary",children:s("p",{style:{fontSize:`calc(${o}/2)`},className:"text-white",children:g})}),t&&s(b,{className:"object-cover object-center w-[100%] h-[100%]",src:t,alt:m,width:100,height:100,onLoad:()=>f(!0)})]})};S.displayName=r;export{S as a};
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var A=Object.create;var l=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var P=(e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:!0})},c=(e,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of M(t))!I.call(e,r)&&r!==a&&l(e,r,{get:()=>t[r],enumerable:!(s=L(t,r))||s.enumerable});return e};var E=(e,t,a)=>(a=e!=null?A(T(e)):{},c(t||!e||!e.__esModule?l(a,"default",{value:e,enumerable:!0}):a,e)),F=e=>c(l({},"__esModule",{value:!0}),e);var H={};P(H,{Avatar:()=>y});module.exports=F(H);var d=require("@stackshift-ui/flex"),f=require("@stackshift-ui/image"),m=require("@stackshift-ui/system"),u=E(require("classnames")),g=require("react"),o=require("react/jsx-runtime"),i="Avatar",y=({src:e,alt:t="image",size:a="sm",text:s,children:r,className:h,as:b,...N})=>{var p;let{[i]:v=m.DefaultComponent}=(0,m.useStackShiftUIComponents)(),[x,C]=(0,g.useState)(!1),n=typeof a=="number"?`${a}px`:`${{sm:40,md:80,lg:120,xl:160}[a]}px`,S=s?(p=s==null?void 0:s.split(" "))==null?void 0:p.reduce((z,w)=>z+w[0],""):"AB";return(0,o.jsxs)(v,{as:b,className:(0,u.default)("relative flex rounded-full aspect-square overflow-hidden border-2 border-solid border-primary",h),style:{maxWidth:n},...N,"data-testid":i,children:[(!x||!e)&&(0,o.jsx)(d.Flex,{align:"center",justify:"center",className:"w-full h-full bg-primary",children:(0,o.jsx)("p",{style:{fontSize:`calc(${n}/2)`},className:"text-white",children:S})}),e&&(0,o.jsx)(f.Image,{className:"object-cover object-center w-[100%] h-[100%]",src:e,alt:t,width:100,height:100,onLoad:()=>C(!0)})]})};y.displayName=i;0&&(module.exports={Avatar});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";import{a as e}from"./chunk-
|
|
2
|
+
"use strict";import{a as e}from"./chunk-ZPYNVPAC.mjs";export{e as Avatar};
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/avatar",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.4-beta.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
|
-
"dist/**"
|
|
11
|
+
"dist/**",
|
|
12
|
+
"src"
|
|
12
13
|
],
|
|
13
14
|
"author": "WebriQ <info@webriq.com>",
|
|
14
15
|
"devDependencies": {
|
|
@@ -28,15 +29,15 @@
|
|
|
28
29
|
"typescript": "^5.6.2",
|
|
29
30
|
"vite-tsconfig-paths": "^5.0.1",
|
|
30
31
|
"vitest": "^2.1.1",
|
|
31
|
-
"@stackshift-ui/
|
|
32
|
-
"@stackshift-ui/
|
|
32
|
+
"@stackshift-ui/typescript-config": "6.0.2",
|
|
33
|
+
"@stackshift-ui/eslint-config": "6.0.2"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"classnames": "^2.5.1",
|
|
36
|
-
"@stackshift-ui/flex": "6.0.2",
|
|
37
|
-
"@stackshift-ui/image": "6.0.2",
|
|
38
37
|
"@stackshift-ui/scripts": "6.0.2",
|
|
39
|
-
"@stackshift-ui/system": "6.0.
|
|
38
|
+
"@stackshift-ui/system": "6.0.3",
|
|
39
|
+
"@stackshift-ui/flex": "6.0.3",
|
|
40
|
+
"@stackshift-ui/image": "6.0.3"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"@types/react": "16.8 - 19",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, test } from "vitest";
|
|
3
|
+
import { Avatar } from "./avatar";
|
|
4
|
+
|
|
5
|
+
describe.concurrent("avatar", () => {
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
test("Common: Avatar - test if renders without errors", ({ expect }) => {
|
|
9
|
+
const clx = "avatar-class";
|
|
10
|
+
|
|
11
|
+
render(
|
|
12
|
+
<Avatar
|
|
13
|
+
className={clx}
|
|
14
|
+
src="https://via.placeholder.com/150"
|
|
15
|
+
alt="Sample Avatar"
|
|
16
|
+
text="StackShift"
|
|
17
|
+
/>,
|
|
18
|
+
);
|
|
19
|
+
const elements = screen.getAllByTestId("div");
|
|
20
|
+
elements.forEach(element => {
|
|
21
|
+
expect(element.classList).toBeDefined();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
package/src/avatar.tsx
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Flex } from "@stackshift-ui/flex";
|
|
2
|
+
import { Image } from "@stackshift-ui/image";
|
|
3
|
+
import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
4
|
+
import cn from "classnames";
|
|
5
|
+
import type { ElementType, HTMLProps, ReactNode } from "react";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
|
|
8
|
+
type ImageSize = "sm" | "md" | "lg" | "xl";
|
|
9
|
+
|
|
10
|
+
export interface AvatarProps extends Omit<HTMLProps<HTMLElement>, "as" | "size"> {
|
|
11
|
+
src: string;
|
|
12
|
+
alt: string;
|
|
13
|
+
size?: ImageSize | number;
|
|
14
|
+
text?: string;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
as?: ElementType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const displayName = "Avatar";
|
|
21
|
+
|
|
22
|
+
export const Avatar: React.FC<AvatarProps> = ({
|
|
23
|
+
src,
|
|
24
|
+
alt = "image",
|
|
25
|
+
size = "sm",
|
|
26
|
+
text,
|
|
27
|
+
children,
|
|
28
|
+
className,
|
|
29
|
+
as,
|
|
30
|
+
...props
|
|
31
|
+
}) => {
|
|
32
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
33
|
+
|
|
34
|
+
const [loaded, setLoaded] = useState(false);
|
|
35
|
+
const sizeMap = {
|
|
36
|
+
sm: 40,
|
|
37
|
+
md: 80,
|
|
38
|
+
lg: 120,
|
|
39
|
+
xl: 160,
|
|
40
|
+
};
|
|
41
|
+
const avatarSize = typeof size === "number" ? `${size}px` : `${sizeMap[size]}px`;
|
|
42
|
+
const initials = text ? text?.split(" ")?.reduce((acc, curr) => acc + curr[0], "") : "AB";
|
|
43
|
+
const baseClass = `relative flex rounded-full aspect-square overflow-hidden border-2 border-solid border-primary`;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Component
|
|
47
|
+
as={as}
|
|
48
|
+
className={cn(baseClass, className)}
|
|
49
|
+
style={{ maxWidth: avatarSize }}
|
|
50
|
+
{...props}
|
|
51
|
+
data-testid={displayName}>
|
|
52
|
+
{(!loaded || !src) && (
|
|
53
|
+
<Flex align="center" justify="center" className="w-full h-full bg-primary">
|
|
54
|
+
<p
|
|
55
|
+
style={{
|
|
56
|
+
fontSize: `calc(${avatarSize}/2)`,
|
|
57
|
+
}}
|
|
58
|
+
className="text-white">
|
|
59
|
+
{initials}
|
|
60
|
+
</p>
|
|
61
|
+
</Flex>
|
|
62
|
+
)}
|
|
63
|
+
{src && (
|
|
64
|
+
<Image
|
|
65
|
+
className="object-cover object-center w-[100%] h-[100%]"
|
|
66
|
+
src={src}
|
|
67
|
+
alt={alt}
|
|
68
|
+
width={100}
|
|
69
|
+
height={100}
|
|
70
|
+
onLoad={() => setLoaded(true)}
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
</Component>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
Avatar.displayName = displayName;
|
package/src/index.ts
ADDED
package/dist/chunk-ZGTLWTPQ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Flex as p}from"@stackshift-ui/flex";import{Image as d}from"@stackshift-ui/image";import{DefaultComponent as N,useStackShiftUIComponents as v}from"@stackshift-ui/system";import w from"classnames";import{useState as x}from"react";import{jsx as t,jsxs as z}from"react/jsx-runtime";var s="Avatar",S=({src:e,alt:l="image",size:o="sm",text:a,children:C,className:f,as:u,...g})=>{var c;let{[s]:h=N}=v(),[n,i]=x(!1),r=typeof o=="number"?`${o}px`:`${{sm:40,md:80,lg:120,xl:160}[o]}px`,m=a?(c=a==null?void 0:a.split(" "))==null?void 0:c.reduce((y,b)=>y+b[0],""):"AB";return z(h,{as:u,className:w("relative flex rounded-full aspect-square overflow-hidden border-2 border-solid border-primary-foreground",f),style:{maxWidth:r},...g,"data-testid":s,children:[(!n||!e)&&t(p,{align:"center",justify:"center",className:"w-full h-full bg-primary-foreground",children:t("p",{style:{fontSize:`calc(${r}/2)`},className:"text-white",children:m})}),e&&t(d,{className:"object-cover object-center w-[100%] h-[100%]",src:e,alt:l,width:100,height:100,onLoad:()=>i(!0)}),(!n||!e)&&t(p,{align:"center",justify:"center",className:"w-full h-full bg-primary-foreground",children:t("p",{style:{fontSize:`calc(${r}/2)`},className:"text-white",children:m})}),e&&t(d,{className:"object-cover object-center w-[100%] h-[100%]",src:e,alt:l,width:100,height:100,onLoad:()=>i(!0)})]})};S.displayName=s;export{S as a};
|