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 CHANGED
@@ -2,63 +2,90 @@
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/react-simple-initials.svg)](https://www.npmjs.com/package/react-simple-initials)
4
4
  [![Bundle Size](https://img.shields.io/bundlephobia/minzip/react-simple-initials)](https://bundlephobia.com/package/react-simple-initials)
5
+ [![License](https://img.shields.io/npm/l/react-simple-initials.svg)](https://github.com/seu-usuario/react-simple-initials/blob/main/LICENSE)
5
6
 
6
- Um componente React minimalista, elegante e ultraleve (menos de 5kB) para gerar avatares coloridos baseados nas iniciais do usuário. Perfeito para painéis, listas de contatos e comentários onde o usuário ainda não enviou uma foto de perfil.
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 Dependências:** Sem bibliotecas de imagens pesadas; usa apenas CSS e HTML puro.
13
- - **Cores Determinísticas:** O fundo do avatar é calculado com base no tamanho do nome. O mesmo nome sempre terá a mesma cor.
14
- - **Altamente Customizável:** Adapta-se automaticamente à fonte do seu projeto, ou permite customização total de tamanho e cor.
15
- - **Suporte a TypeScript & SSR:** Funciona perfeitamente com Next.js, Vite, Remix e Create React App.
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
- ## Instalação
18
+ ---
19
+
20
+ ## Instalacao
21
+
22
+ Instale o pacote utilizando o seu gerenciador de preferencia:
18
23
 
19
- Você pode instalar usando o seu gerenciador de pacotes favorito:
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
- npm install react-simple-initials
32
+ ---
22
33
 
23
34
  ## Como usar
24
35
 
25
- A configuração é instantânea. Basta importar o componente e passar o nome desejado:
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
- import React from 'react';
28
- import InitialsAvatar from 'react-simple-initials';
45
+ {/* Exemplo Padrao (40px) */}
46
+ <InitialsAvatar nome="Visitante" />
29
47
 
30
- export default function App() {
31
- return (
48
+ {/* Tamanho Customizado */}
49
+ <InitialsAvatar nome="Maria Silva" tamanho={60} />
32
50
 
33
- <div style={{ display: 'flex', gap: '16px' }}>
34
- <InitialsAvatar nome="Visitante" />
35
- <InitialsAvatar nome="Maria Silva" tamanho={60} />
36
- <InitialsAvatar nome="João" tamanho={80} corTexto="#FFF" fonte="Arial, sans-serif" />
37
- </div>
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
- O componente aceita as seguintes propriedades (props) para você customizar como preferir:
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
- | Propriedade | Tipo | Padrão | Descrição |
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
- Contribuições são super bem-vindas! Se você encontrou um bug ou tem uma ideia para uma nova funcionalidade:
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/MinhaNovaFeature)
58
- 3. Faça o commit das suas alterações (git commit -m 'feat: Adiciona nova paleta de cores')
59
- 4. Faça o push para a branch (git push origin feature/MinhaNovaFeature)
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
- ## Licença
87
+ ---
88
+
89
+ ## Licenca
63
90
 
64
- Este projeto está licenciado sob a Licença MIT.
91
+ Este projeto esta sob a licenca MIT.
@@ -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 };
@@ -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.1",
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.jsx --format cjs,esm"
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.9.3"
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
- }