react-simple-initials 1.0.1 → 1.0.3
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/README.md +59 -32
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +16 -4
- package/.github/workflows/publish.yml +0 -32
- package/src/index.jsx +0 -42
package/README.md
CHANGED
|
@@ -2,63 +2,90 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/react-simple-initials)
|
|
4
4
|
[](https://bundlephobia.com/package/react-simple-initials)
|
|
5
|
+
[](https://github.com/seu-usuario/react-simple-initials/blob/main/LICENSE)
|
|
5
6
|
|
|
6
|
-
Um componente React
|
|
7
|
+
Um componente React funcional, minimalista e ultraleve para gerar avatares baseados nas iniciais do usuário. Ideal para interfaces que necessitam de um fallback visual elegante quando a foto de perfil não está disponível.
|
|
7
8
|
|
|
8
9
|
---
|
|
9
10
|
|
|
10
11
|
## Funcionalidades
|
|
11
12
|
|
|
12
|
-
- **Zero
|
|
13
|
-
- **Cores
|
|
14
|
-
- **
|
|
15
|
-
- **Suporte a TypeScript
|
|
13
|
+
- **Zero Dependencias:** Construido apenas com React e CSS inline, garantindo um bundle size reduzido.
|
|
14
|
+
- **Cores Deterministicas:** O fundo do avatar e gerado algoritmicamente com base no nome fornecido. O mesmo nome sempre resultara na mesma cor.
|
|
15
|
+
- **Escalabilidade:** O tamanho da fonte e do container se ajustam proporcionalmente atraves da prop de tamanho.
|
|
16
|
+
- **Pronto para Producao:** Suporte nativo a TypeScript e compatibilidade com SSR (Next.js, Remix) e ferramentas modernas como Vite.
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Instalacao
|
|
21
|
+
|
|
22
|
+
Instale o pacote utilizando o seu gerenciador de preferencia:
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
```bash
|
|
25
|
+
npm react-simple-initials
|
|
26
|
+
# or
|
|
27
|
+
yarn react-simple-initials
|
|
28
|
+
# or
|
|
29
|
+
pnpm react-simple-initials
|
|
30
|
+
```
|
|
20
31
|
|
|
21
|
-
|
|
32
|
+
---
|
|
22
33
|
|
|
23
34
|
## Como usar
|
|
24
35
|
|
|
25
|
-
|
|
36
|
+
Importe o componente e passe a propriedade obrigatoria nome. O componente cuidara do restante.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import InitialsAvatar from "react-simple-initials";
|
|
40
|
+
|
|
41
|
+
export default function Page() {
|
|
42
|
+
return (
|
|
43
|
+
<div className="flex gap-4 items-centrer">
|
|
26
44
|
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
{/* Exemplo Padrao (40px) */}
|
|
46
|
+
<InitialsAvatar nome="Visitante" />
|
|
29
47
|
|
|
30
|
-
|
|
31
|
-
|
|
48
|
+
{/* Tamanho Customizado */}
|
|
49
|
+
<InitialsAvatar nome="Maria Silva" tamanho={60} />
|
|
32
50
|
|
|
33
|
-
|
|
34
|
-
<InitialsAvatar
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
{/* Customizacao de Estilo */}
|
|
52
|
+
<InitialsAvatar
|
|
53
|
+
nome="Joao"
|
|
54
|
+
tamanho={80}
|
|
55
|
+
corTexto="#FFFFFF"
|
|
56
|
+
fonte="Arial, sans-serif"
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
39
60
|
}
|
|
40
61
|
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
41
66
|
## Propriedades (API)
|
|
42
67
|
|
|
43
|
-
|
|
68
|
+
| Propriedade | Tipo | Padrao | Descricao |
|
|
69
|
+
| :----------- | :----- | :-------- | :-------------------------------------------------------------------------------- |
|
|
70
|
+
| **nome** | string | "?" | O nome do usuario. A primeira letra sera extraida e capitalizada automaticamente. |
|
|
71
|
+
| **tamanho** | number | 40 | O diametro do avatar em pixels. |
|
|
72
|
+
| **fonte** | string | "inherit" | Define a familia da fonte (ex: "Inter, sans-serif"). |
|
|
73
|
+
| **corTexto** | string | "#FFFFFF" | Define a cor da letra central do avatar. |
|
|
44
74
|
|
|
45
|
-
|
|
46
|
-
| :---------- | :----- | :-------- | :------------------------------------------------------------------------------------------------- |
|
|
47
|
-
| nome | string | "?" | O nome do usuário. A primeira letra será extraída e capitalizada automaticamente. |
|
|
48
|
-
| tamanho | number | 40 | O diâmetro do avatar (largura e altura) em pixels. O tamanho da fonte se ajusta proporcionalmente. |
|
|
49
|
-
| fonte | string | "inherit" | A família da fonte. Por padrão, herda a fonte do elemento pai. |
|
|
50
|
-
| corTexto | string | "#FFFFFF" | A cor da letra exibida no centro do avatar. |
|
|
75
|
+
---
|
|
51
76
|
|
|
52
77
|
## Contribuindo
|
|
53
78
|
|
|
54
|
-
|
|
79
|
+
Pull requests sao bem-vindos. Para mudancas maiores, abra uma issue primeiro para discutir o que voce gostaria de mudar.
|
|
55
80
|
|
|
56
81
|
1. Faça um Fork do projeto
|
|
57
|
-
2. Crie sua branch de funcionalidade (git checkout -b feature/
|
|
58
|
-
3.
|
|
59
|
-
4.
|
|
82
|
+
2. Crie sua branch de funcionalidade (git checkout -b feature/NovaFeature)
|
|
83
|
+
3. Commit suas alterações (git commit -m 'feat: Adiciona nova funcionalidade')
|
|
84
|
+
4. Push para a branch (git push origin feature/NovaFeature)
|
|
60
85
|
5. Abra um Pull Request
|
|
61
86
|
|
|
62
|
-
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Licenca
|
|
63
90
|
|
|
64
|
-
Este projeto
|
|
91
|
+
Este projeto esta sob a licenca MIT.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface InitialsAvatarProps {
|
|
4
|
+
nome?: string;
|
|
5
|
+
tamanho?: number;
|
|
6
|
+
fonte?: string;
|
|
7
|
+
corTexto?: string;
|
|
8
|
+
}
|
|
9
|
+
declare function InitialsAvatar({ nome, tamanho, fonte, corTexto, }: InitialsAvatarProps): react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { InitialsAvatar as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface InitialsAvatarProps {
|
|
4
|
+
nome?: string;
|
|
5
|
+
tamanho?: number;
|
|
6
|
+
fonte?: string;
|
|
7
|
+
corTexto?: string;
|
|
8
|
+
}
|
|
9
|
+
declare function InitialsAvatar({ nome, tamanho, fonte, corTexto, }: InitialsAvatarProps): react_jsx_runtime.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { InitialsAvatar as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var h=(n,t)=>{for(var i in t)r(n,i,{get:t[i],enumerable:!0})},u=(n,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of f(t))!g.call(n,e)&&e!==i&&r(n,e,{get:()=>t[e],enumerable:!(o=d(t,e))||o.enumerable});return n};var p=n=>u(r({},"__esModule",{value:!0}),n);var A={};h(A,{default:()=>a});module.exports=p(A);var l=require("react/jsx-runtime"),s=["#EF4444","#F97316","#EAB308","#22C55E","#3B82F6","#A855F7","#EC4899","#64748B"];function a({nome:n="?",tamanho:t=40,fonte:i="inherit",corTexto:o="#FFFFFF"}){let e=n.length,c=s[e%s.length],F=n.trim().charAt(0).toUpperCase();return(0,l.jsx)("div",{style:{width:t,height:t,backgroundColor:c,color:o,fontFamily:i,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",fontSize:t/2.2,fontWeight:"bold",userSelect:"none"},children:F})}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as c}from"react/jsx-runtime";var e=["#EF4444","#F97316","#EAB308","#22C55E","#3B82F6","#A855F7","#EC4899","#64748B"];function l({nome:n="?",tamanho:t=40,fonte:i="inherit",corTexto:o="#FFFFFF"}){let r=n.length,s=e[r%e.length],a=n.trim().charAt(0).toUpperCase();return c("div",{style:{width:t,height:t,backgroundColor:s,color:o,fontFamily:i,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%",fontSize:t/2.2,fontWeight:"bold",userSelect:"none"},children:a})}export{l as default};
|
package/package.json
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-simple-initials",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Um componente React minimalista para avatares com iniciais do nome.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE"
|
|
12
|
+
],
|
|
7
13
|
"scripts": {
|
|
8
|
-
"build": "tsup src/index.
|
|
14
|
+
"build": "tsup src/index.tsx --format cjs,esm --dts --minify",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
9
16
|
},
|
|
10
17
|
"keywords": [
|
|
11
18
|
"react",
|
|
@@ -16,10 +23,15 @@
|
|
|
16
23
|
"author": "WinstonAjr",
|
|
17
24
|
"license": "MIT",
|
|
18
25
|
"peerDependencies": {
|
|
19
|
-
"react": ">=16.8.0"
|
|
26
|
+
"react": ">=16.8.0",
|
|
27
|
+
"react-dom": ">=16.8.0"
|
|
20
28
|
},
|
|
21
29
|
"devDependencies": {
|
|
30
|
+
"@types/react": "^19.0.0",
|
|
31
|
+
"@types/react-dom": "^19.0.0",
|
|
32
|
+
"react": "^19.0.0",
|
|
33
|
+
"react-dom": "^19.0.0",
|
|
22
34
|
"tsup": "^8.5.1",
|
|
23
|
-
"typescript": "^5.
|
|
35
|
+
"typescript": "^5.7.0"
|
|
24
36
|
}
|
|
25
37
|
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
name: Publicar no NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_dispatch:
|
|
5
|
-
|
|
6
|
-
jobs:
|
|
7
|
-
publish:
|
|
8
|
-
runs-on: ubuntu-latest
|
|
9
|
-
permissions:
|
|
10
|
-
contents: read
|
|
11
|
-
id-token: write
|
|
12
|
-
|
|
13
|
-
steps:
|
|
14
|
-
- name: Baixar o código
|
|
15
|
-
uses: actions/checkout@v4
|
|
16
|
-
|
|
17
|
-
- name: Configurar o Node.js
|
|
18
|
-
uses: actions/setup-node@v4
|
|
19
|
-
with:
|
|
20
|
-
node-version: "20"
|
|
21
|
-
registry-url: "https://registry.npmjs.org"
|
|
22
|
-
|
|
23
|
-
- name: Instalar dependências
|
|
24
|
-
run: npm install
|
|
25
|
-
|
|
26
|
-
- name: Construir o projeto
|
|
27
|
-
run: npm run build
|
|
28
|
-
|
|
29
|
-
- name: Publicar no NPM
|
|
30
|
-
run: npm publish --provenance --access public
|
|
31
|
-
env:
|
|
32
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/src/index.jsx
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const FUNDOS = [
|
|
2
|
-
"#EF4444",
|
|
3
|
-
"#F97316",
|
|
4
|
-
"#EAB308",
|
|
5
|
-
"#22C55E",
|
|
6
|
-
"#3B82F6",
|
|
7
|
-
"#A855F7",
|
|
8
|
-
"#EC4899",
|
|
9
|
-
"#64748B",
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
export default function InitialsAvatar({
|
|
13
|
-
nome = "?",
|
|
14
|
-
tamanho = 40,
|
|
15
|
-
fonte = "inherit",
|
|
16
|
-
corTexto = "#FFFFFF",
|
|
17
|
-
}) {
|
|
18
|
-
const tamanhoNome = nome.length;
|
|
19
|
-
const FundoEscolhido = FUNDOS[tamanhoNome % FUNDOS.length];
|
|
20
|
-
const inicial = nome.trim().charAt(0).toUpperCase();
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<div
|
|
24
|
-
style={{
|
|
25
|
-
width: tamanho,
|
|
26
|
-
height: tamanho,
|
|
27
|
-
backgroundColor: FundoEscolhido,
|
|
28
|
-
color: corTexto,
|
|
29
|
-
fontFamily: fonte,
|
|
30
|
-
display: "flex",
|
|
31
|
-
alignItems: "center",
|
|
32
|
-
justifyContent: "center",
|
|
33
|
-
borderRadius: "50%",
|
|
34
|
-
fontSize: tamanho / 2.2,
|
|
35
|
-
fontWeight: "bold",
|
|
36
|
-
userSelect: "none",
|
|
37
|
-
}}
|
|
38
|
-
>
|
|
39
|
-
{inicial}
|
|
40
|
-
</div>
|
|
41
|
-
);
|
|
42
|
-
}
|