Skip to content

Commit d4545b9

Browse files
committed
Translate createPortal.md to pt-br
1 parent 7148d38 commit d4545b9

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

src/content/reference/react-dom/createPortal.md

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ title: createPortal
44

55
<Intro>
66

7-
`createPortal` lets you render some children into a different part of the DOM.
8-
7+
`createPortal` permite que você renderize alguns filhos em uma parte diferente do DOM.
98

109
```js
1110
<div>
@@ -20,75 +19,75 @@ title: createPortal
2019
2120
---
2221
23-
## Reference {/*reference*/}
22+
## Referência {/*reference*/}
2423
2524
### `createPortal(children, domNode, key?)` {/*createportal*/}
2625
27-
To create a portal, call `createPortal`, passing some JSX, and the DOM node where it should be rendered:
26+
Para criar um portal, chame `createPortal`, passando algum JSX e o nó DOM onde ele deve ser renderizado:
2827
2928
```js
3029
import { createPortal } from 'react-dom';
3130

3231
// ...
3332

3433
<div>
35-
<p>This child is placed in the parent div.</p>
34+
<p>Este filho é colocado na div pai.</p>
3635
{createPortal(
37-
<p>This child is placed in the document body.</p>,
36+
<p>Este filho é colocado no corpo do documento.</p>,
3837
document.body
3938
)}
4039
</div>
4140
```
4241
43-
[See more examples below.](#usage)
42+
[Veja mais exemplos abaixo.](#usage)
4443
45-
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events bubble up from children to parents according to the React tree.
44+
Um portal apenas altera a colocação física do nó DOM. De todas as outras maneiras, o JSX que você renderiza em um portal atua como um nó filho do componente React que o renderiza. Por exemplo, o filho pode acessar o contexto fornecido pela árvore pai, e os eventos se propagam de filhos para pais de acordo com a árvore React.
4645
47-
#### Parameters {/*parameters*/}
46+
#### Parâmetros {/*parameters*/}
4847
49-
* `children`: Anything that can be rendered with React, such as a piece of JSX (e.g. `<div />` or `<SomeComponent />`), a [Fragment](/reference/react/Fragment) (`<>...</>`), a string or a number, or an array of these.
48+
* `children`: Qualquer coisa que pode ser renderizada com o React, como um pedaço de JSX (por exemplo, `<div />` ou `<SomeComponent />`), um [Fragmento](/reference/react/Fragment) (`<>...</>`), uma string ou um número, ou um array desses.
5049
51-
* `domNode`: Some DOM node, such as those returned by `document.getElementById()`. The node must already exist. Passing a different DOM node during an update will cause the portal content to be recreated.
50+
* `domNode`: Algum nó DOM, como aqueles retornados por `document.getElementById()`. O nó deve já existir. Passar um nó DOM diferente durante uma atualização fará com que o conteúdo do portal seja recriado.
5251
53-
* **optional** `key`: A unique string or number to be used as the portal's [key.](/learn/rendering-lists/#keeping-list-items-in-order-with-key)
52+
* **opcional** `key`: Uma string ou número único a ser usado como a [chave](/learn/rendering-lists/#keeping-list-items-in-order-with-key) do portal.
5453
55-
#### Returns {/*returns*/}
54+
#### Retornos {/*returns*/}
5655
57-
`createPortal` returns a React node that can be included into JSX or returned from a React component. If React encounters it in the render output, it will place the provided `children` inside the provided `domNode`.
56+
`createPortal` retorna um nó React que pode ser incluído no JSX ou retornado de um componente React. Se o React encontrá-lo na saída do render, colocará os `children` fornecidos dentro do `domNode` fornecido.
5857
59-
#### Caveats {/*caveats*/}
58+
#### Ressalvas {/*caveats*/}
6059
61-
* Events from portals propagate according to the React tree rather than the DOM tree. For example, if you click inside a portal, and the portal is wrapped in `<div onClick>`, that `onClick` handler will fire. If this causes issues, either stop the event propagation from inside the portal, or move the portal itself up in the React tree.
60+
* Eventos de portais se propagam de acordo com a árvore React e não com a árvore DOM. Por exemplo, se você clicar dentro de um portal, e o portal estiver envolvido em `<div onClick>`, o manipulador `onClick` será disparado. Se isso causar problemas, pare a propagação do evento de dentro do portal, ou mova o portal para cima na árvore React.
6261
6362
---
6463
65-
## Usage {/*usage*/}
64+
## Uso {/*usage*/}
6665
67-
### Rendering to a different part of the DOM {/*rendering-to-a-different-part-of-the-dom*/}
66+
### Renderizando em uma parte diferente do DOM {/*rendering-to-a-different-part-of-the-dom*/}
6867
69-
*Portals* let your components render some of their children into a different place in the DOM. This lets a part of your component "escape" from whatever containers it may be in. For example, a component can display a modal dialog or a tooltip that appears above and outside of the rest of the page.
68+
*Portais* permitem que seus componentes renderizem alguns de seus filhos em um lugar diferente no DOM. Isso permite que uma parte do seu componente "escape" de quaisquer contêineres em que possa estar. Por exemplo, um componente pode exibir um diálogo modal ou um tooltip que aparece acima e fora do resto da página.
7069
71-
To create a portal, render the result of `createPortal` with <CodeStep step={1}>some JSX</CodeStep> and the <CodeStep step={2}>DOM node where it should go</CodeStep>:
70+
Para criar um portal, renderize o resultado de `createPortal` com <CodeStep step={1}>algum JSX</CodeStep> e o <CodeStep step={2}>DOM onde ele deve ir</CodeStep>:
7271
73-
```js [[1, 8, "<p>This child is placed in the document body.</p>"], [2, 9, "document.body"]]
72+
```js [[1, 8, "<p>Este filho é colocado no corpo do documento.</p>"], [2, 9, "document.body"]]
7473
import { createPortal } from 'react-dom';
7574

7675
function MyComponent() {
7776
return (
7877
<div style={{ border: '2px solid black' }}>
79-
<p>This child is placed in the parent div.</p>
78+
<p>Este filho é colocado na div pai.</p>
8079
{createPortal(
81-
<p>This child is placed in the document body.</p>,
80+
<p>Este filho é colocado no corpo do documento.</p>,
8281
document.body
8382
)}
8483
</div>
8584
);
8685
}
8786
```
8887
89-
React will put the DOM nodes for <CodeStep step={1}>the JSX you passed</CodeStep> inside of the <CodeStep step={2}>DOM node you provided</CodeStep>.
88+
O React colocará os nós DOM do <CodeStep step={1}>JSX que você passou</CodeStep> dentro do <CodeStep step={2}>DOM que você forneceu</CodeStep>.
9089
91-
Without a portal, the second `<p>` would be placed inside the parent `<div>`, but the portal "teleported" it into the [`document.body`:](https://developer.mozilla.org/en-US/docs/Web/API/Document/body)
90+
Sem um portal, o segundo `<p>` seria colocado dentro da `<div>` pai, mas o portal "teletransportou" ele para o [`document.body`:](https://developer.mozilla.org/en-US/docs/Web/API/Document/body)
9291
9392
<Sandpack>
9493
@@ -98,9 +97,9 @@ import { createPortal } from 'react-dom';
9897
export default function MyComponent() {
9998
return (
10099
<div style={{ border: '2px solid black' }}>
101-
<p>This child is placed in the parent div.</p>
100+
<p>Este filho é colocado na div pai.</p>
102101
{createPortal(
103-
<p>This child is placed in the document body.</p>,
102+
<p>Este filho é colocado no corpo do documento.</p>,
104103
document.body
105104
)}
106105
</div>
@@ -110,30 +109,30 @@ export default function MyComponent() {
110109
111110
</Sandpack>
112111
113-
Notice how the second paragraph visually appears outside the parent `<div>` with the border. If you inspect the DOM structure with developer tools, you'll see that the second `<p>` got placed directly into the `<body>`:
112+
Note como o segundo parágrafo aparece visualmente fora da `<div>` pai com a borda. Se você inspecionar a estrutura do DOM com ferramentas de desenvolvedor, verá que o segundo `<p>` foi colocado diretamente no `<body>`:
114113
115114
```html {4-6,9}
116115
<body>
117116
<div id="root">
118117
...
119118
<div style="border: 2px solid black">
120-
<p>This child is placed inside the parent div.</p>
119+
<p>Este filho é colocado dentro da div pai.</p>
121120
</div>
122121
...
123122
</div>
124-
<p>This child is placed in the document body.</p>
123+
<p>Este filho é colocado no corpo do documento.</p>
125124
</body>
126125
```
127126
128-
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events still bubble up from children to parents according to the React tree.
127+
Um portal apenas altera a colocação física do nó DOM. De todas as outras maneiras, o JSX que você renderiza em um portal atua como um nó filho do componente React que o renderiza. Por exemplo, o filho pode acessar o contexto fornecido pela árvore pai, e os eventos ainda se propagam de filhos para pais de acordo com a árvore React.
129128
130129
---
131130
132-
### Rendering a modal dialog with a portal {/*rendering-a-modal-dialog-with-a-portal*/}
131+
### Renderizando um diálogo modal com um portal {/*rendering-a-modal-dialog-with-a-portal*/}
133132
134-
You can use a portal to create a modal dialog that floats above the rest of the page, even if the component that summons the dialog is inside a container with `overflow: hidden` or other styles that interfere with the dialog.
133+
Você pode usar um portal para criar um diálogo modal que flutua acima do resto da página, mesmo que o componente que invoca o diálogo esteja dentro de um contêiner com `overflow: hidden` ou outros estilos que interferem com o diálogo.
135134
136-
In this example, the two containers have styles that disrupt the modal dialog, but the one rendered into a portal is unaffected because, in the DOM, the modal is not contained within the parent JSX elements.
135+
Neste exemplo, os dois contêineres têm estilos que interrompem o diálogo modal, mas o que é renderizado em um portal não é afetado porque, no DOM, o modal não está contido dentro dos elementos JSX pai.
137136
138137
<Sandpack>
139138
@@ -164,7 +163,7 @@ export default function NoPortalExample() {
164163
return (
165164
<>
166165
<button onClick={() => setShowModal(true)}>
167-
Show modal without a portal
166+
Mostrar modal sem um portal
168167
</button>
169168
{showModal && (
170169
<ModalContent onClose={() => setShowModal(false)} />
@@ -184,7 +183,7 @@ export default function PortalExample() {
184183
return (
185184
<>
186185
<button onClick={() => setShowModal(true)}>
187-
Show modal using a portal
186+
Mostrar modal usando um portal
188187
</button>
189188
{showModal && createPortal(
190189
<ModalContent onClose={() => setShowModal(false)} />,
@@ -199,8 +198,8 @@ export default function PortalExample() {
199198
export default function ModalContent({ onClose }) {
200199
return (
201200
<div className="modal">
202-
<div>I'm a modal dialog</div>
203-
<button onClick={onClose}>Close</button>
201+
<div>Eu sou um diálogo modal</div>
202+
<button onClick={onClose}>Fechar</button>
204203
</div>
205204
);
206205
}
@@ -226,7 +225,7 @@ export default function ModalContent({ onClose }) {
226225
background-color: white;
227226
border: 2px solid rgb(240, 240, 240);
228227
border-radius: 12px;
229-
position: absolute;
228+
position: absolute;
230229
width: 250px;
231230
top: 70px;
232231
left: calc(50% - 125px);
@@ -238,29 +237,29 @@ export default function ModalContent({ onClose }) {
238237
239238
<Pitfall>
240239
241-
It's important to make sure that your app is accessible when using portals. For instance, you may need to manage keyboard focus so that the user can move the focus in and out of the portal in a natural way.
240+
É importante garantir que seu aplicativo seja acessível ao usar portais. Por exemplo, você pode precisar gerenciar o foco do teclado para que o usuário possa mover o foco dentro e fora do portal de uma maneira natural.
242241
243-
Follow the [WAI-ARIA Modal Authoring Practices](https://www.w3.org/WAI/ARIA/apg/#dialog_modal) when creating modals. If you use a community package, ensure that it is accessible and follows these guidelines.
242+
Siga as [Práticas de Autoria de Modal WAI-ARIA](https://www.w3.org/WAI/ARIA/apg/#dialog_modal) ao criar modais. Se você usar um pacote da comunidade, garanta que ele seja acessível e siga essas diretrizes.
244243
245244
</Pitfall>
246245
247246
---
248247
249-
### Rendering React components into non-React server markup {/*rendering-react-components-into-non-react-server-markup*/}
248+
### Renderizando componentes React em marcação de servidor não-React {/*rendering-react-components-into-non-react-server-markup*/}
250249
251-
Portals can be useful if your React root is only part of a static or server-rendered page that isn't built with React. For example, if your page is built with a server framework like Rails, you can create areas of interactivity within static areas such as sidebars. Compared with having [multiple separate React roots,](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) portals let you treat the app as a single React tree with shared state even though its parts render to different parts of the DOM.
250+
Os portais podem ser úteis se sua raiz React for apenas parte de uma página estática ou renderizada no servidor que não é construída com o React. Por exemplo, se sua página for construída com um framework de servidor como Rails, você pode criar áreas de interatividade dentro de áreas estáticas, como barras laterais. Comparado a ter [várias raízes React separadas](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react), os portais permitem que você trate o aplicativo como uma única árvore React com estado compartilhado, mesmo que suas partes sejam renderizadas em diferentes partes do DOM.
252251
253252
<Sandpack>
254253
255254
```html index.html
256255
<!DOCTYPE html>
257256
<html>
258-
<head><title>My app</title></head>
257+
<head><title>Meu app</title></head>
259258
<body>
260-
<h1>Welcome to my hybrid app</h1>
259+
<h1>Bem-vindo ao meu aplicativo híbrido</h1>
261260
<div class="parent">
262261
<div class="sidebar">
263-
This is server non-React markup
262+
Esta é uma marcação de servidor não-React
264263
<div id="sidebar-content"></div>
265264
</div>
266265
<div id="root"></div>
@@ -301,11 +300,11 @@ export default function App() {
301300
}
302301

303302
function MainContent() {
304-
return <p>This part is rendered by React</p>;
303+
return <p>Esta parte é renderizada pelo React</p>;
305304
}
306305

307306
function SidebarContent() {
308-
return <p>This part is also rendered by React!</p>;
307+
return <p>Esta parte também é renderizada pelo React!</p>;
309308
}
310309
```
311310
@@ -342,15 +341,15 @@ p {
342341
343342
---
344343
345-
### Rendering React components into non-React DOM nodes {/*rendering-react-components-into-non-react-dom-nodes*/}
344+
### Renderizando componentes React em nós DOM não-React {/*rendering-react-components-into-non-react-dom-nodes*/}
346345
347-
You can also use a portal to manage the content of a DOM node that's managed outside of React. For example, suppose you're integrating with a non-React map widget and you want to render React content inside a popup. To do this, declare a `popupContainer` state variable to store the DOM node you're going to render into:
346+
Você também pode usar um portal para gerenciar o conteúdo de um nó DOM que é gerenciado fora do React. Por exemplo, suponha que você esteja integrando com um widget de mapa não-React e deseja renderizar conteúdo React dentro de um popup. Para fazer isso, declare uma variável de estado `popupContainer` para armazenar o nó DOM no qual você vai renderizar:
348347
349348
```js
350349
const [popupContainer, setPopupContainer] = useState(null);
351350
```
352351
353-
When you create the third-party widget, store the DOM node returned by the widget so you can render into it:
352+
Quando você criar o widget de terceiros, armazene o nó DOM retornado pelo widget para que você possa renderizar nele:
354353
355354
```js {5-6}
356355
useEffect(() => {
@@ -363,20 +362,20 @@ useEffect(() => {
363362
}, []);
364363
```
365364
366-
This lets you use `createPortal` to render React content into `popupContainer` once it becomes available:
365+
Isso permite que você use `createPortal` para renderizar conteúdo React dentro de `popupContainer` uma vez que ele se torne disponível:
367366
368367
```js {3-6}
369368
return (
370369
<div style={{ width: 250, height: 250 }} ref={containerRef}>
371370
{popupContainer !== null && createPortal(
372-
<p>Hello from React!</p>,
371+
<p>Olá do React!</p>,
373372
popupContainer
374373
)}
375374
</div>
376375
);
377376
```
378377
379-
Here is a complete example you can play with:
378+
Aqui está um exemplo completo que você pode experimentar:
380379
381380
<Sandpack>
382381
@@ -420,7 +419,7 @@ export default function Map() {
420419
return (
421420
<div style={{ width: 250, height: 250 }} ref={containerRef}>
422421
{popupContainer !== null && createPortal(
423-
<p>Hello from React!</p>,
422+
<p>Olá do React!</p>,
424423
popupContainer
425424
)}
426425
</div>
@@ -456,4 +455,4 @@ export function addPopupToMapWidget(map) {
456455
button { margin: 5px; }
457456
```
458457
459-
</Sandpack>
458+
</Sandpack>

0 commit comments

Comments
 (0)