You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
إنّ مكوّنات React و[مكوّنات الويب](https://developer.mozilla.org/en-US/docs/Web/Web_Components)مبنية لحل مشاكل مختلفة. حيث تُزوِّدنا مكوّنات الويب بتغليف قوي لمكوّنات قابلة لإعادة الاستخدام، بينما تُزوِّدنا مكوّنات React بمكتبة تصريحات تُبقي DOM على تزامن مع بياناتنا. يكون هذا الهدفان متكاملين، وكمُطوّر لك حرية استخدام React في مكوّنات الويب لديك، أو استخدام مكوّنات الويب في React أو كليهما معًا.
9
+
React and [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components)are built to solve different problems. Web Components provide strong encapsulation for reusable components, while React provides a declarative library that keeps the DOM in sync with your data. The two goals are complementary. As a developer, you are free to use React in your Web Components, or to use Web Components in React, or both.
10
10
11
-
معظم من يستخدم React لا يستخدم مكوّنات الويب، ولكن قد ترغب في ذلك خاصة إذا كنت تستخدم مكوّنات لواجهة المستخدم من طرف ثالث والتي تكون مكتوبة باستخدام مكوّنات الويب.
11
+
Most people who use React don't use Web Components, but you may want to, especially if you are using third-party UI components that are written using Web Components.
12
12
13
-
14
-
## استخدام مكوّنات الويب في React {#using-web-components-in-react}
13
+
## Using Web Components in React {#using-web-components-in-react}
>تعرض مكوّنات الويب عادة واجهة برمجة تطبيقات (API) إلزاميّة. على سبيل المثال قد يُعرِّض مكوّن الويب `video`الدالتين `play()` و`pause()`، وللوصول إلى واجهة برمجة التطبيقات الإلزامية لمكوّنات الويب ستحتاج إلى استخدام مرجع للتفاعل مع عقدة DOM مباشرةً. إن كنت تستخدم مكوّنات ويب من طرف ثالث فالحل الأمثل هو كتابة مكوّن React يسلك سلوك غلاف لمكوّنات الويب لديك.
25
+
>Web Components often expose an imperative API. For instance, a `video`Web Component might expose `play()` and`pause()` functions. To access the imperative APIs of a Web Component, you will need to use a ref to interact with the DOM node directly. If you are using third-party Web Components, the best solution is to write a React component that behaves as a wrapper for your Web Component.
27
26
>
28
-
> الأحداث الصادرة من قبل مكوّن الويب قد لا تنتشر بشكل صحيح عبر شجرة تصيير React.
29
-
> ستحتاج إلى إرفاق معالج أحداث يدويًّا للتعامل مع هذه الأحداث ضمن مكوّنات React لديك.
27
+
> Events emitted by a Web Component may not properly propagate through a React render tree.
28
+
> You will need to manually attach event handlers to handle these events within your React components.
30
29
31
-
إحدى الأمور التي من الشائع الخطأ بها هي استخدام مكوّنات الويب للخاصيّة "class" بدلًا من "className":
30
+
One common confusion is that Web Components use "class" instead of "className".
32
31
33
32
```javascript
34
33
functionBrickFlipbox() {
35
34
return (
36
35
<brick-flipbox class="demo">
37
-
<div>الواجهة الأمامية</div>
38
-
<div>الواجهة الخلفية</div>
36
+
<div>front</div>
37
+
<div>back</div>
39
38
</brick-flipbox>
40
39
);
41
40
}
42
41
```
43
42
44
-
## استخدام React في مكوّنات الويب لديك {#using-react-in-your-web-components}
43
+
## Using React in your Web Components {#using-react-in-your-web-components}
45
44
46
45
```javascript
47
46
classXSearchextendsHTMLElement {
@@ -57,7 +56,7 @@ class XSearch extends HTMLElement {
57
56
customElements.define('x-search', XSearch);
58
57
```
59
58
60
-
>ملاحظة:
59
+
>Note:
61
60
>
62
-
>**لن**تعمل هذه الشيفرة إن نقلت الأصناف باستخدام Babel. انظر إلى هذه المشكلة [من هنا](https://github.com/w3c/webcomponents/issues/587).
63
-
>يجب عليك تضمين [custom-elements-es5-adapter](https://github.com/webcomponents/webcomponentsjs#custom-elements-es5-adapterjs)قبل تحميل مكوّنات الويب لإصلاح هذه المشكلة.
61
+
>This code **will not**work if you transform classes with Babel. See [this issue](https://github.com/w3c/webcomponents/issues/587) for the discussion.
62
+
>Include the [custom-elements-es5-adapter](https://github.com/webcomponents/webcomponentsjs#custom-elements-es5-adapterjs)before you load your web components to fix this issue.
0 commit comments