@grazziotin/react-components-next 1.0.0 → 2.0.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/README.md +184 -105
- package/dist/accessibility/index.d.mts +136 -0
- package/dist/accessibility/index.d.ts +136 -0
- package/dist/accessibility/index.js +138 -0
- package/dist/accessibility/index.js.map +1 -0
- package/dist/accessibility/index.mjs +127 -0
- package/dist/accessibility/index.mjs.map +1 -0
- package/dist/chunk-BWW3F4R4.mjs +118 -0
- package/dist/chunk-BWW3F4R4.mjs.map +1 -0
- package/dist/functions/index.d.mts +36 -1
- package/dist/functions/index.d.ts +36 -1
- package/dist/functions/index.js +36 -0
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/index.mjs +1 -1
- package/dist/index.css +1 -1
- package/dist/ui/index.d.mts +301 -6
- package/dist/ui/index.d.ts +301 -6
- package/dist/ui/index.js +852 -2
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/index.mjs +873 -2
- package/dist/ui/index.mjs.map +1 -1
- package/package.json +9 -11
- package/dist/chunk-CNXFSE26.mjs +0 -120
- package/dist/chunk-CNXFSE26.mjs.map +0 -1
- package/dist/chunk-NHHZBMJL.mjs +0 -64
- package/dist/chunk-NHHZBMJL.mjs.map +0 -1
- package/dist/index.d.mts +0 -5
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -217
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -29
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,132 +1,205 @@
|
|
|
1
|
-
# React Components Library
|
|
1
|
+
# Grazziotin React Components Library
|
|
2
2
|
|
|
3
|
-
Biblioteca de componentes React reutilizáveis, construída com TypeScript
|
|
3
|
+
Biblioteca de componentes React reutilizáveis para o projeto Grazziotin, construída com TypeScript, Tailwind CSS, Material UI e Mantine.
|
|
4
4
|
|
|
5
5
|
## Instalação
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install react-components-next
|
|
8
|
+
npm install @grazziotin/react-components-next
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### Requisitos
|
|
12
|
+
|
|
13
|
+
- React `>= 18`
|
|
14
|
+
- Tailwind CSS v4 configurado no projeto consumidor
|
|
15
|
+
- `ThemeProvider` do MUI e `MantineProvider` do Mantine envolvendo a aplicação
|
|
16
|
+
|
|
17
|
+
### Configuração no projeto consumidor
|
|
18
|
+
|
|
19
|
+
Importe os estilos da biblioteca e configure as variáveis CSS do tema:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import "@grazziotin/react-components-next/styles";
|
|
23
|
+
|
|
24
|
+
import { CssBaseline, ThemeProvider, createTheme } from "@mui/material";
|
|
25
|
+
import { MantineProvider } from "@mantine/core";
|
|
26
|
+
import "@mantine/core/styles.css";
|
|
27
|
+
|
|
28
|
+
const theme = createTheme({
|
|
29
|
+
typography: { fontFamily: "var(--font-family, inherit)" },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export function AppProviders({ children }: { children: React.ReactNode }) {
|
|
33
|
+
return (
|
|
34
|
+
<ThemeProvider theme={theme}>
|
|
35
|
+
<CssBaseline />
|
|
36
|
+
<MantineProvider>{children}</MantineProvider>
|
|
37
|
+
</ThemeProvider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```css
|
|
43
|
+
:root {
|
|
44
|
+
--primary-color: #00b2a6;
|
|
45
|
+
--font-family: "Poppins", sans-serif;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> **Atenção:** vários componentes usam classes do Tailwind CSS e dependem do MUI/Mantine. Certifique-se de que o Tailwind esteja configurado e os providers estejam na raiz da aplicação.
|
|
12
50
|
|
|
13
51
|
## Componentes disponíveis
|
|
14
52
|
|
|
15
|
-
| Componente
|
|
16
|
-
|
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
20
|
-
| `
|
|
21
|
-
|
|
53
|
+
| Componente | Descrição |
|
|
54
|
+
| ------------ | --------------------------------------------------------------- |
|
|
55
|
+
| `Card` | Container com cabeçalho colorido, título, ícone e tooltip |
|
|
56
|
+
| `Dialog` | Modal baseado no MUI com título, conteúdo e ações opcionais |
|
|
57
|
+
| `DataTable` | Tabela de dados com MUI DataGrid, filtros e textos em português |
|
|
58
|
+
| `Tab`/`Tabs` | Abas estilizadas com indicador e tipografia customizáveis |
|
|
59
|
+
|
|
60
|
+
## Funções utilitárias
|
|
61
|
+
|
|
62
|
+
| Função | Descrição |
|
|
63
|
+
| --------------- | ------------------------------------------------ |
|
|
64
|
+
| `cn` | Mescla classes CSS com `clsx` e `tailwind-merge` |
|
|
65
|
+
| `nvl` | Retorna valor padrão quando `null`/`undefined` |
|
|
66
|
+
| `formatCpfCnpj` | Formata CPF ou CNPJ |
|
|
67
|
+
| `formatPhoneBr` | Formata telefone brasileiro |
|
|
22
68
|
|
|
23
69
|
## Uso
|
|
24
70
|
|
|
25
71
|
```tsx
|
|
26
72
|
import {
|
|
27
|
-
Button,
|
|
28
73
|
Card,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} from "react-components-next";
|
|
74
|
+
Dialog,
|
|
75
|
+
DataTable,
|
|
76
|
+
Tab,
|
|
77
|
+
Tabs,
|
|
78
|
+
cn,
|
|
79
|
+
formatCpfCnpj,
|
|
80
|
+
} from "@grazziotin/react-components-next";
|
|
81
|
+
import type { GridColDef } from "@mui/x-data-grid";
|
|
82
|
+
|
|
83
|
+
const colunas: GridColDef[] = [
|
|
84
|
+
{ field: "id", headerName: "ID", width: 80 },
|
|
85
|
+
{ field: "nome", headerName: "Nome", flex: 1 },
|
|
86
|
+
{ field: "documento", headerName: "CPF/CNPJ", width: 180 },
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const linhas = [
|
|
90
|
+
{ id: 1, nome: "Ana Silva", documento: formatCpfCnpj("12345678901") },
|
|
91
|
+
];
|
|
36
92
|
|
|
37
93
|
export function Example() {
|
|
38
94
|
return (
|
|
39
|
-
<Card>
|
|
40
|
-
<
|
|
41
|
-
<CardTitle>Perfil</CardTitle>
|
|
42
|
-
</CardHeader>
|
|
43
|
-
<CardContent>
|
|
44
|
-
<div className="flex items-center gap-3">
|
|
45
|
-
<Avatar fallback="João Silva" size="md" />
|
|
46
|
-
<div>
|
|
47
|
-
<p>João Silva</p>
|
|
48
|
-
<Badge variant="success" dot>
|
|
49
|
-
Online
|
|
50
|
-
</Badge>
|
|
51
|
-
</div>
|
|
52
|
-
</div>
|
|
53
|
-
<Input label="E-mail" type="email" placeholder="joao@exemplo.com" />
|
|
54
|
-
<Button variant="primary" fullWidth>
|
|
55
|
-
Salvar
|
|
56
|
-
</Button>
|
|
57
|
-
</CardContent>
|
|
95
|
+
<Card title="Colaboradores" toolTip className={cn("max-w-3xl")}>
|
|
96
|
+
<DataTable rows={linhas} columns={colunas} pageSizeOptions={[10, 20]} />
|
|
58
97
|
</Card>
|
|
59
98
|
);
|
|
60
99
|
}
|
|
61
100
|
```
|
|
62
101
|
|
|
102
|
+
## Entry points
|
|
103
|
+
|
|
104
|
+
A biblioteca expõe múltiplos pontos de entrada:
|
|
105
|
+
|
|
106
|
+
| Import | Conteúdo |
|
|
107
|
+
| --------------------------------------------- | ---------------------------------------- |
|
|
108
|
+
| `@grazziotin/react-components-next` | Componentes e funções (export principal) |
|
|
109
|
+
| `@grazziotin/react-components-next/ui` | Apenas componentes de UI |
|
|
110
|
+
| `@grazziotin/react-components-next/functions` | Apenas funções utilitárias |
|
|
111
|
+
| `@grazziotin/react-components-next/styles` | CSS compilado da biblioteca |
|
|
112
|
+
|
|
63
113
|
## Componentes
|
|
64
114
|
|
|
65
|
-
###
|
|
115
|
+
### Card
|
|
66
116
|
|
|
67
117
|
```tsx
|
|
68
|
-
<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
118
|
+
<Card
|
|
119
|
+
title="Título do card"
|
|
120
|
+
toolTip={false}
|
|
121
|
+
width="100%"
|
|
122
|
+
height="auto"
|
|
123
|
+
titleColor="var(--primary-color)"
|
|
124
|
+
borderRadius="10px"
|
|
125
|
+
borderTitle="10px 10px 0 0"
|
|
126
|
+
icon={<Icon />}
|
|
127
|
+
onClick={() => {}}
|
|
128
|
+
className="text-sm"
|
|
75
129
|
>
|
|
76
|
-
|
|
77
|
-
</
|
|
130
|
+
Conteúdo do card
|
|
131
|
+
</Card>
|
|
78
132
|
```
|
|
79
133
|
|
|
80
|
-
###
|
|
134
|
+
### Dialog
|
|
81
135
|
|
|
82
136
|
```tsx
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
137
|
+
<Dialog
|
|
138
|
+
open={open}
|
|
139
|
+
title="Confirmar exclusão"
|
|
140
|
+
onClose={() => setOpen(false)}
|
|
141
|
+
maxWidth="sm"
|
|
142
|
+
blurBackdrop={false}
|
|
143
|
+
actions={<button onClick={() => setOpen(false)}>OK</button>}
|
|
144
|
+
>
|
|
145
|
+
Deseja realmente excluir este item?
|
|
146
|
+
</Dialog>
|
|
93
147
|
```
|
|
94
148
|
|
|
95
|
-
###
|
|
149
|
+
### DataTable
|
|
150
|
+
|
|
151
|
+
Wrapper sobre o MUI `DataGrid` com estilização, textos em português e operador de filtro "entre" automático para colunas `string` e `number`. Aceita todas as props do `DataGrid`.
|
|
96
152
|
|
|
97
153
|
```tsx
|
|
98
|
-
<
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
<CardFooter>
|
|
105
|
-
<Button>Ação</Button>
|
|
106
|
-
</CardFooter>
|
|
107
|
-
</Card>
|
|
154
|
+
<DataTable
|
|
155
|
+
rows={dados}
|
|
156
|
+
columns={colunas}
|
|
157
|
+
loading={carregando}
|
|
158
|
+
pageSizeOptions={[10, 20, 50]}
|
|
159
|
+
/>
|
|
108
160
|
```
|
|
109
161
|
|
|
110
|
-
###
|
|
162
|
+
### Tab / Tabs
|
|
111
163
|
|
|
112
164
|
```tsx
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
165
|
+
const [value, setValue] = useState(0);
|
|
166
|
+
|
|
167
|
+
<Tabs
|
|
168
|
+
value={value}
|
|
169
|
+
onChange={(_, newValue) => setValue(newValue)}
|
|
170
|
+
color="var(--primary-color)"
|
|
116
171
|
>
|
|
117
|
-
|
|
118
|
-
|
|
172
|
+
<Tab label="Geral" />
|
|
173
|
+
<Tab label="Detalhes" />
|
|
174
|
+
</Tabs>;
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Funções
|
|
178
|
+
|
|
179
|
+
### cn
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
cn("px-4 py-2", condicao && "bg-teal-500", "px-6");
|
|
119
183
|
```
|
|
120
184
|
|
|
121
|
-
###
|
|
185
|
+
### nvl
|
|
122
186
|
|
|
123
187
|
```tsx
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
188
|
+
nvl(valor, "padrão"); // retorna "padrão" se valor for null/undefined
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### formatCpfCnpj
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
formatCpfCnpj("12345678901"); // "123.456.789-01"
|
|
195
|
+
formatCpfCnpj("12345678000199"); // "12.345.678/0001-99"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### formatPhoneBr
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
formatPhoneBr("11987654321"); // "(11) 98765-4321"
|
|
202
|
+
formatPhoneBr("1133334444"); // "(11) 3333-4444"
|
|
130
203
|
```
|
|
131
204
|
|
|
132
205
|
## Desenvolvimento
|
|
@@ -135,17 +208,20 @@ export function Example() {
|
|
|
135
208
|
# Instalar dependências
|
|
136
209
|
npm install
|
|
137
210
|
|
|
138
|
-
#
|
|
139
|
-
npm run
|
|
211
|
+
# Storybook (visualização e documentação dos componentes)
|
|
212
|
+
npm run storybook
|
|
213
|
+
|
|
214
|
+
# Build estático do Storybook
|
|
215
|
+
npm run build-storybook
|
|
140
216
|
|
|
141
217
|
# Build da biblioteca para npm
|
|
142
218
|
npm run build:lib
|
|
143
219
|
|
|
144
|
-
# Build completo (biblioteca + Next.js)
|
|
145
|
-
npm run build:all
|
|
146
|
-
|
|
147
220
|
# Verificar tipos TypeScript
|
|
148
221
|
npm run type-check
|
|
222
|
+
|
|
223
|
+
# Lint
|
|
224
|
+
npm run lint
|
|
149
225
|
```
|
|
150
226
|
|
|
151
227
|
## Publicar no npm
|
|
@@ -162,24 +238,27 @@ npm publish
|
|
|
162
238
|
|
|
163
239
|
```
|
|
164
240
|
src/
|
|
165
|
-
├── app/
|
|
166
|
-
│ ├──
|
|
167
|
-
│
|
|
168
|
-
│
|
|
169
|
-
|
|
170
|
-
│
|
|
171
|
-
│ ├── badge/
|
|
172
|
-
│ └── avatar/
|
|
173
|
-
├── components/ # Biblioteca de componentes (publicada no npm)
|
|
174
|
-
│ ├── index.ts # Entrypoint principal
|
|
241
|
+
├── app/ # Next.js App Router (página inicial mínima)
|
|
242
|
+
│ ├── globals.css # Variáveis CSS e tema
|
|
243
|
+
│ ├── layout.tsx # Providers MUI + Mantine
|
|
244
|
+
│ └── page.tsx
|
|
245
|
+
├── components/
|
|
246
|
+
│ ├── index.ts
|
|
175
247
|
│ └── ui/
|
|
176
|
-
│ ├──
|
|
177
|
-
│ ├──
|
|
178
|
-
│ ├──
|
|
179
|
-
│
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
248
|
+
│ ├── card/
|
|
249
|
+
│ ├── dialog/
|
|
250
|
+
│ ├── data-table/
|
|
251
|
+
│ └── tab/
|
|
252
|
+
├── core/ # Utilitários internos
|
|
253
|
+
├── functions/
|
|
254
|
+
│ ├── cn/
|
|
255
|
+
│ ├── nvl/
|
|
256
|
+
│ ├── format-cpf-cnpj/
|
|
257
|
+
│ └── format-phone-br/
|
|
258
|
+
├── providers/
|
|
259
|
+
├── styles/
|
|
260
|
+
│ └── index.css # Entrada do Tailwind para o build CSS
|
|
261
|
+
└── index.ts # Entrypoint principal da biblioteca
|
|
183
262
|
```
|
|
184
263
|
|
|
185
264
|
## Licença
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import react__default from 'react';
|
|
2
|
+
|
|
3
|
+
type SayFeedbackType = "info" | "success" | "warning" | "error" | "default";
|
|
4
|
+
interface SayNotifyOptions {
|
|
5
|
+
type?: SayFeedbackType;
|
|
6
|
+
autoClose?: number;
|
|
7
|
+
}
|
|
8
|
+
interface SayCallOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Tipo de feedback. desativa notificação.
|
|
11
|
+
* Padrão: (via do hook).
|
|
12
|
+
*/
|
|
13
|
+
type?: SayFeedbackType | false;
|
|
14
|
+
/**
|
|
15
|
+
* Exibe notificação via .
|
|
16
|
+
* Padrão: .
|
|
17
|
+
*/
|
|
18
|
+
notify?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Dispara vibração conforme .
|
|
21
|
+
* Padrão: .
|
|
22
|
+
*/
|
|
23
|
+
vibrate?: boolean;
|
|
24
|
+
/** Duração da notificação em ms (repasse para ). */
|
|
25
|
+
autoClose?: number;
|
|
26
|
+
}
|
|
27
|
+
interface UseSayOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Callback de notificação visual (ex.: toast).
|
|
30
|
+
* Omitir para não exibir notificação.
|
|
31
|
+
*/
|
|
32
|
+
onNotify?: (text: string, options: SayNotifyOptions) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Tipo padrão da notificação.
|
|
35
|
+
* Padrão: .
|
|
36
|
+
*/
|
|
37
|
+
defaultNotifyType?: SayFeedbackType;
|
|
38
|
+
/**
|
|
39
|
+
* Auto-close padrão da notificação em ms.
|
|
40
|
+
* Padrão: .
|
|
41
|
+
*/
|
|
42
|
+
defaultNotifyAutoClose?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Duração padrão da vibração em ms.
|
|
45
|
+
* Padrão: .
|
|
46
|
+
*/
|
|
47
|
+
vibrateDuration?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Define se deve vibrar para o informado.
|
|
50
|
+
* Padrão: ( quando é omitido ou ).
|
|
51
|
+
*/
|
|
52
|
+
shouldVibrate?: (type?: SayFeedbackType | false) => boolean;
|
|
53
|
+
}
|
|
54
|
+
interface UseSayReturn {
|
|
55
|
+
say: (text: string, options?: SayCallOptions) => void;
|
|
56
|
+
isSpeaking: boolean;
|
|
57
|
+
textSpeaking: string;
|
|
58
|
+
setIsSpeaking: React.Dispatch<React.SetStateAction<boolean>>;
|
|
59
|
+
}
|
|
60
|
+
interface SayProps {
|
|
61
|
+
isSpeaking: boolean;
|
|
62
|
+
text: string;
|
|
63
|
+
setIsSpeaking: React.Dispatch<React.SetStateAction<boolean>>;
|
|
64
|
+
/**
|
|
65
|
+
* Nome da voz do .
|
|
66
|
+
* Padrão: .
|
|
67
|
+
*/
|
|
68
|
+
voice?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Velocidade da fala.
|
|
71
|
+
* Padrão: .
|
|
72
|
+
*/
|
|
73
|
+
rate?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Tom da voz.
|
|
76
|
+
* Padrão: .
|
|
77
|
+
*/
|
|
78
|
+
pitch?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Volume da fala.
|
|
81
|
+
* Padrão: .
|
|
82
|
+
*/
|
|
83
|
+
volume?: number;
|
|
84
|
+
onEnd?: () => void;
|
|
85
|
+
onStart?: () => void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Hook para disparar fala, notificação e vibração de forma configurável.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* const { say, isSpeaking, textSpeaking, setIsSpeaking } = useSay({
|
|
94
|
+
* onNotify: (text, { type }) => toast(text, { type }),
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* <Say
|
|
98
|
+
* isSpeaking={isSpeaking}
|
|
99
|
+
* text={textSpeaking}
|
|
100
|
+
* setIsSpeaking={setIsSpeaking}
|
|
101
|
+
* />
|
|
102
|
+
*
|
|
103
|
+
* <button type="button" onClick={() => say("Operação concluída")}>
|
|
104
|
+
* Falar
|
|
105
|
+
* </button>
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function useSay({ onNotify, defaultNotifyType, vibrateDuration, defaultNotifyAutoClose, shouldVibrate, }?: UseSayOptions): UseSayReturn;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Sintetiza texto em fala via Web Speech API (`react-say`).
|
|
112
|
+
* Use com {@link useSay} para controlar `isSpeaking`, `text` e `setIsSpeaking`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```tsx
|
|
116
|
+
* const { say, isSpeaking, textSpeaking, setIsSpeaking } = useSay({
|
|
117
|
+
* onNotify: (text, { type }) => toast(text, { type }),
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* return (
|
|
121
|
+
* <>
|
|
122
|
+
* <Say
|
|
123
|
+
* isSpeaking={isSpeaking}
|
|
124
|
+
* text={textSpeaking}
|
|
125
|
+
* setIsSpeaking={setIsSpeaking}
|
|
126
|
+
* voice="Google português do Brasil"
|
|
127
|
+
* rate={1.4}
|
|
128
|
+
* />
|
|
129
|
+
* <button type="button" onClick={() => say("Pronto")}>Falar</button>
|
|
130
|
+
* </>
|
|
131
|
+
* );
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
declare function Say({ text, onEnd, onStart, isSpeaking, setIsSpeaking, rate, voice, pitch, volume, }: Readonly<SayProps>): react__default.ReactElement | null;
|
|
135
|
+
|
|
136
|
+
export { Say, type SayCallOptions, type SayFeedbackType, type SayNotifyOptions, type SayProps, type UseSayOptions, type UseSayReturn, useSay };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import react__default from 'react';
|
|
2
|
+
|
|
3
|
+
type SayFeedbackType = "info" | "success" | "warning" | "error" | "default";
|
|
4
|
+
interface SayNotifyOptions {
|
|
5
|
+
type?: SayFeedbackType;
|
|
6
|
+
autoClose?: number;
|
|
7
|
+
}
|
|
8
|
+
interface SayCallOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Tipo de feedback. desativa notificação.
|
|
11
|
+
* Padrão: (via do hook).
|
|
12
|
+
*/
|
|
13
|
+
type?: SayFeedbackType | false;
|
|
14
|
+
/**
|
|
15
|
+
* Exibe notificação via .
|
|
16
|
+
* Padrão: .
|
|
17
|
+
*/
|
|
18
|
+
notify?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Dispara vibração conforme .
|
|
21
|
+
* Padrão: .
|
|
22
|
+
*/
|
|
23
|
+
vibrate?: boolean;
|
|
24
|
+
/** Duração da notificação em ms (repasse para ). */
|
|
25
|
+
autoClose?: number;
|
|
26
|
+
}
|
|
27
|
+
interface UseSayOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Callback de notificação visual (ex.: toast).
|
|
30
|
+
* Omitir para não exibir notificação.
|
|
31
|
+
*/
|
|
32
|
+
onNotify?: (text: string, options: SayNotifyOptions) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Tipo padrão da notificação.
|
|
35
|
+
* Padrão: .
|
|
36
|
+
*/
|
|
37
|
+
defaultNotifyType?: SayFeedbackType;
|
|
38
|
+
/**
|
|
39
|
+
* Auto-close padrão da notificação em ms.
|
|
40
|
+
* Padrão: .
|
|
41
|
+
*/
|
|
42
|
+
defaultNotifyAutoClose?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Duração padrão da vibração em ms.
|
|
45
|
+
* Padrão: .
|
|
46
|
+
*/
|
|
47
|
+
vibrateDuration?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Define se deve vibrar para o informado.
|
|
50
|
+
* Padrão: ( quando é omitido ou ).
|
|
51
|
+
*/
|
|
52
|
+
shouldVibrate?: (type?: SayFeedbackType | false) => boolean;
|
|
53
|
+
}
|
|
54
|
+
interface UseSayReturn {
|
|
55
|
+
say: (text: string, options?: SayCallOptions) => void;
|
|
56
|
+
isSpeaking: boolean;
|
|
57
|
+
textSpeaking: string;
|
|
58
|
+
setIsSpeaking: React.Dispatch<React.SetStateAction<boolean>>;
|
|
59
|
+
}
|
|
60
|
+
interface SayProps {
|
|
61
|
+
isSpeaking: boolean;
|
|
62
|
+
text: string;
|
|
63
|
+
setIsSpeaking: React.Dispatch<React.SetStateAction<boolean>>;
|
|
64
|
+
/**
|
|
65
|
+
* Nome da voz do .
|
|
66
|
+
* Padrão: .
|
|
67
|
+
*/
|
|
68
|
+
voice?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Velocidade da fala.
|
|
71
|
+
* Padrão: .
|
|
72
|
+
*/
|
|
73
|
+
rate?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Tom da voz.
|
|
76
|
+
* Padrão: .
|
|
77
|
+
*/
|
|
78
|
+
pitch?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Volume da fala.
|
|
81
|
+
* Padrão: .
|
|
82
|
+
*/
|
|
83
|
+
volume?: number;
|
|
84
|
+
onEnd?: () => void;
|
|
85
|
+
onStart?: () => void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Hook para disparar fala, notificação e vibração de forma configurável.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* const { say, isSpeaking, textSpeaking, setIsSpeaking } = useSay({
|
|
94
|
+
* onNotify: (text, { type }) => toast(text, { type }),
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* <Say
|
|
98
|
+
* isSpeaking={isSpeaking}
|
|
99
|
+
* text={textSpeaking}
|
|
100
|
+
* setIsSpeaking={setIsSpeaking}
|
|
101
|
+
* />
|
|
102
|
+
*
|
|
103
|
+
* <button type="button" onClick={() => say("Operação concluída")}>
|
|
104
|
+
* Falar
|
|
105
|
+
* </button>
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function useSay({ onNotify, defaultNotifyType, vibrateDuration, defaultNotifyAutoClose, shouldVibrate, }?: UseSayOptions): UseSayReturn;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Sintetiza texto em fala via Web Speech API (`react-say`).
|
|
112
|
+
* Use com {@link useSay} para controlar `isSpeaking`, `text` e `setIsSpeaking`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```tsx
|
|
116
|
+
* const { say, isSpeaking, textSpeaking, setIsSpeaking } = useSay({
|
|
117
|
+
* onNotify: (text, { type }) => toast(text, { type }),
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* return (
|
|
121
|
+
* <>
|
|
122
|
+
* <Say
|
|
123
|
+
* isSpeaking={isSpeaking}
|
|
124
|
+
* text={textSpeaking}
|
|
125
|
+
* setIsSpeaking={setIsSpeaking}
|
|
126
|
+
* voice="Google português do Brasil"
|
|
127
|
+
* rate={1.4}
|
|
128
|
+
* />
|
|
129
|
+
* <button type="button" onClick={() => say("Pronto")}>Falar</button>
|
|
130
|
+
* </>
|
|
131
|
+
* );
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
declare function Say({ text, onEnd, onStart, isSpeaking, setIsSpeaking, rate, voice, pitch, volume, }: Readonly<SayProps>): react__default.ReactElement | null;
|
|
135
|
+
|
|
136
|
+
export { Say, type SayCallOptions, type SayFeedbackType, type SayNotifyOptions, type SayProps, type UseSayOptions, type UseSayReturn, useSay };
|