ui-soxo-bootstrap-core 2.6.59 → 2.6.61

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.
Files changed (422) hide show
  1. package/.babelrc +8 -8
  2. package/.github/workflows/npm-publish.yml +41 -41
  3. package/.husky/pre-commit +11 -11
  4. package/.prettierrc.json +10 -10
  5. package/DEVELOPER_GUIDE.md +294 -294
  6. package/PUBLISHING.md +333 -333
  7. package/babel.config.js +2 -2
  8. package/core/components/component-loader/component-loader.js +125 -125
  9. package/core/components/component-wrapper/component-wrapper.js +121 -121
  10. package/core/components/external-window/DEVELOPER_GUIDE.md +705 -705
  11. package/core/components/external-window/external-window.js +236 -236
  12. package/core/components/external-window/external-window.test.js +80 -80
  13. package/core/components/extra-info/extra-info-details.js +155 -155
  14. package/core/components/extra-info/extra-info-details.scss +26 -26
  15. package/core/components/extra-info/extra-info.js +134 -134
  16. package/core/components/index.js +14 -14
  17. package/core/components/landing-api/landing-api.js +733 -733
  18. package/core/components/landing-api/landing-api.scss +41 -41
  19. package/core/components/license-management/license-alert.js +97 -97
  20. package/core/components/menu-template-api/menu-template-api.js +321 -321
  21. package/core/components/root-application-api/root-application-api.js +174 -174
  22. package/core/index.js +13 -13
  23. package/core/lib/Store.js +375 -375
  24. package/core/lib/components/application-bootstrap/application-bootstrap.js +115 -115
  25. package/core/lib/components/approval-form/approval-form.js +280 -280
  26. package/core/lib/components/approval-form/approval-form.scss +183 -183
  27. package/core/lib/components/approval-list/approval-list.js +143 -143
  28. package/core/lib/components/approval-list/approval-list.scss +2 -2
  29. package/core/lib/components/approval-list/components/request-card/request-card.js +42 -42
  30. package/core/lib/components/approval-list/components/request-card/request-card.scss +30 -30
  31. package/core/lib/components/camera/camera.js +230 -230
  32. package/core/lib/components/camera/camera.scss +86 -86
  33. package/core/lib/components/comment-block/comment-block.js +138 -138
  34. package/core/lib/components/comment-block/comment-block.scss +3 -3
  35. package/core/lib/components/confirm-modal/confirm-modal.js +82 -82
  36. package/core/lib/components/confirm-modal/confirm-modal.scss +2 -2
  37. package/core/lib/components/consent/consent.js +67 -67
  38. package/core/lib/components/consent/pdf-signature.js +299 -299
  39. package/core/lib/components/consent/signature-pad.js +227 -227
  40. package/core/lib/components/consent/signature-pad.scss +23 -23
  41. package/core/lib/components/file-upload/file-upload.js +133 -133
  42. package/core/lib/components/finger-print-reader/finger-print-reader.js +295 -295
  43. package/core/lib/components/finger-print-reader/finger-print-reader.scss +47 -47
  44. package/core/lib/components/finger-print-search/finger-print-search.js +200 -200
  45. package/core/lib/components/finger-print-search/finger-print-search.scss +47 -47
  46. package/core/lib/components/global-header/animations.js +18 -18
  47. package/core/lib/components/global-header/global-header.js +293 -293
  48. package/core/lib/components/global-header/global-header.scss +399 -399
  49. package/core/lib/components/header/generic-header.js +76 -76
  50. package/core/lib/components/header/generic-header.scss +99 -99
  51. package/core/lib/components/image-preview/image-preview.js +33 -33
  52. package/core/lib/components/image-wrapper/image-wrapper.js +108 -108
  53. package/core/lib/components/image-wrapper/image-wrapper.scss +12 -12
  54. package/core/lib/components/index.js +206 -206
  55. package/core/lib/components/landing/landing.js +403 -403
  56. package/core/lib/components/language-switcher/language-switcher.js +49 -49
  57. package/core/lib/components/menu-context/menu-context.js +69 -69
  58. package/core/lib/components/menu-template/menu-template.js +249 -249
  59. package/core/lib/components/menu-template/menu-template.scss +9 -9
  60. package/core/lib/components/modal-search/modal-search.js +153 -153
  61. package/core/lib/components/modal-search/modal-search.scss +78 -78
  62. package/core/lib/components/modal-wrapper/modal-manager.js +15 -15
  63. package/core/lib/components/modal-wrapper/modal-wrapper.js +108 -108
  64. package/core/lib/components/modal-wrapper/modal-wrapper.scss +13 -13
  65. package/core/lib/components/notice-board/notice-board.js +132 -132
  66. package/core/lib/components/notice-board/notice-board.scss +65 -65
  67. package/core/lib/components/page-container/page-container.js +55 -55
  68. package/core/lib/components/page-container/page-container.scss +8 -8
  69. package/core/lib/components/page-header/page-header.js +23 -23
  70. package/core/lib/components/page-header/page-header.scss +17 -17
  71. package/core/lib/components/pdf-viewer/pdf-viewer.js +56 -56
  72. package/core/lib/components/portlet-table/components/table-actions/table-actions.js +58 -58
  73. package/core/lib/components/portlet-table/components/table-actions/table-actions.scss +1 -1
  74. package/core/lib/components/portlet-table/components/table-data/table-data.js +106 -106
  75. package/core/lib/components/portlet-table/portlet-table.js +63 -63
  76. package/core/lib/components/portlet-table/portlet-table.scss +90 -90
  77. package/core/lib/components/progress-bar/progress-bar.js +58 -58
  78. package/core/lib/components/progress-bar/progress-bar.scss +15 -15
  79. package/core/lib/components/request-form/request-form.js +110 -110
  80. package/core/lib/components/root-application/root-application.js +70 -70
  81. package/core/lib/components/rupee/rupee.js +14 -14
  82. package/core/lib/components/script-input/script-input.js +169 -169
  83. package/core/lib/components/script-input/script-input.scss +8 -8
  84. package/core/lib/components/sidemenu/animations.js +51 -51
  85. package/core/lib/components/sidemenu/sidemenu.js +632 -632
  86. package/core/lib/components/sidemenu/sidemenu.scss +314 -314
  87. package/core/lib/components/spotlight-search/spotlight-search.component.js +635 -635
  88. package/core/lib/components/spotlight-search/spotlight-search.component.scss +78 -78
  89. package/core/lib/components/table-wrapper/table-wrapper.js +135 -135
  90. package/core/lib/components/table-wrapper/table-wrapper.scss +72 -72
  91. package/core/lib/components/ui_elements/Loader.js +12 -12
  92. package/core/lib/components/ui_elements/Notify.js +12 -12
  93. package/core/lib/components/ui_elements/PlaceHolder.js +33 -33
  94. package/core/lib/components/web-camera/web-camera.js +161 -161
  95. package/core/lib/components/web-camera/web-camera.scss +28 -28
  96. package/core/lib/core.md +9 -9
  97. package/core/lib/elements/Elements.md +2 -2
  98. package/core/lib/elements/basic/LoggedUserRedirect.js +21 -21
  99. package/core/lib/elements/basic/PrivateRoute.js +16 -16
  100. package/core/lib/elements/basic/button/Button.md +43 -43
  101. package/core/lib/elements/basic/button/button.js +170 -170
  102. package/core/lib/elements/basic/card/Card.md +15 -15
  103. package/core/lib/elements/basic/card/card.js +40 -40
  104. package/core/lib/elements/basic/card/card.scss +13 -13
  105. package/core/lib/elements/basic/checkbox/checkbox.js +23 -23
  106. package/core/lib/elements/basic/col/col.js +15 -15
  107. package/core/lib/elements/basic/copy-to-clipboard/Readme.md +40 -40
  108. package/core/lib/elements/basic/copy-to-clipboard/copy-to-clipboard.js +61 -61
  109. package/core/lib/elements/basic/country-phone-input/Readme.md +98 -98
  110. package/core/lib/elements/basic/country-phone-input/country-phone-input.js +81 -81
  111. package/core/lib/elements/basic/country-phone-input/phone-input.scss +75 -75
  112. package/core/lib/elements/basic/datepicker/datepicker.js +33 -33
  113. package/core/lib/elements/basic/dragabble-wrapper/draggable-wrapper.js +203 -203
  114. package/core/lib/elements/basic/empty/empty.js +14 -14
  115. package/core/lib/elements/basic/fingerprint-protrected/fingerprint-protected.js +118 -118
  116. package/core/lib/elements/basic/fingerprint-protrected/fingerprint-protected.scss +10 -10
  117. package/core/lib/elements/basic/form/form.js +70 -70
  118. package/core/lib/elements/basic/form/form.scss +3 -3
  119. package/core/lib/elements/basic/image/image.js +45 -45
  120. package/core/lib/elements/basic/image/image.scss +17 -17
  121. package/core/lib/elements/basic/image/readme.md +26 -26
  122. package/core/lib/elements/basic/image-viewer/image-viewer.js +108 -108
  123. package/core/lib/elements/basic/image-viewer/image-viewer.scss +7 -7
  124. package/core/lib/elements/basic/input/input.js +81 -81
  125. package/core/lib/elements/basic/input/readme.md +77 -77
  126. package/core/lib/elements/basic/json-input/json-input.js +51 -51
  127. package/core/lib/elements/basic/menu-dashboard/menu-dashboard.js +216 -216
  128. package/core/lib/elements/basic/menu-dashboard/menu-dashboard.scss +28 -28
  129. package/core/lib/elements/basic/menu-tree/menu-tree.js +127 -127
  130. package/core/lib/elements/basic/modal/modal.js +64 -64
  131. package/core/lib/elements/basic/modal/readme.md +62 -62
  132. package/core/lib/elements/basic/popconfirm/popconfirm.js +17 -17
  133. package/core/lib/elements/basic/popover/popover.js +12 -12
  134. package/core/lib/elements/basic/radio/radio.js +18 -18
  135. package/core/lib/elements/basic/rangepicker/rangepicker.js +141 -141
  136. package/core/lib/elements/basic/rangepicker/rangepicker.scss +24 -24
  137. package/core/lib/elements/basic/rangepicker/readme.md +81 -81
  138. package/core/lib/elements/basic/reference-select/readme.md +18 -18
  139. package/core/lib/elements/basic/reference-select/reference-select.js +341 -341
  140. package/core/lib/elements/basic/row/row.js +15 -15
  141. package/core/lib/elements/basic/select/select.js +46 -46
  142. package/core/lib/elements/basic/select-box/readme.md +52 -52
  143. package/core/lib/elements/basic/select-box/select-box.js +63 -63
  144. package/core/lib/elements/basic/skeleton/readme.md +35 -35
  145. package/core/lib/elements/basic/skeleton/skeleton.js +35 -35
  146. package/core/lib/elements/basic/skeleton/skeleton.scss +53 -53
  147. package/core/lib/elements/basic/space/space.js +12 -12
  148. package/core/lib/elements/basic/switch/readme.md +29 -29
  149. package/core/lib/elements/basic/switch/switch.js +67 -67
  150. package/core/lib/elements/basic/tab/tab.js +14 -14
  151. package/core/lib/elements/basic/table/readme.md +8 -8
  152. package/core/lib/elements/basic/table/table.js +95 -95
  153. package/core/lib/elements/basic/tag/tag.js +63 -63
  154. package/core/lib/elements/basic/tag/tag.scss +2 -2
  155. package/core/lib/elements/basic/timeline/timeline.js +13 -13
  156. package/core/lib/elements/basic/title/readme.md +20 -20
  157. package/core/lib/elements/basic/title/title.js +37 -37
  158. package/core/lib/elements/basic/user-search/user-search.js +192 -192
  159. package/core/lib/elements/complex/barcode/barcode.js +27 -27
  160. package/core/lib/elements/complex/bargraph/bar-graph.js +262 -262
  161. package/core/lib/elements/complex/basic-table/basic-table.js +110 -110
  162. package/core/lib/elements/complex/basic-table/basic-table.scss +4 -4
  163. package/core/lib/elements/complex/date-display/date-display.js +37 -37
  164. package/core/lib/elements/complex/error-boundary/error-boundary.js +29 -29
  165. package/core/lib/elements/complex/google-location-input/map-container-library-load.js +92 -92
  166. package/core/lib/elements/complex/google-map/google-map.js +230 -230
  167. package/core/lib/elements/complex/google-map/google-map.scss +13 -13
  168. package/core/lib/elements/complex/line-graph/line-graph.js +108 -108
  169. package/core/lib/elements/complex/location-search-input/location-search-input.js +100 -100
  170. package/core/lib/elements/complex/pie-chart/pie-chart.js +202 -202
  171. package/core/lib/elements/complex/qr-code/qr-code.js +29 -29
  172. package/core/lib/elements/complex/qrscanner/qrscanner.js +57 -57
  173. package/core/lib/elements/complex/search-debounce/search-debounce.js +37 -37
  174. package/core/lib/elements/complex/statistic-card/dashboard-statistic-card.js +75 -75
  175. package/core/lib/elements/complex/statistic-card/statistic-card.js +28 -28
  176. package/core/lib/elements/index.js +226 -226
  177. package/core/lib/hooks/device-detect.js +25 -25
  178. package/core/lib/hooks/index.js +9 -9
  179. package/core/lib/hooks/use-location.js +33 -33
  180. package/core/lib/hooks/use-otp-timer.js +80 -80
  181. package/core/lib/hooks/use-window-size.js +34 -34
  182. package/core/lib/i18n.js +69 -69
  183. package/core/lib/index.js +106 -106
  184. package/core/lib/introduction.md +73 -73
  185. package/core/lib/js-styleguide.md +4112 -4112
  186. package/core/lib/models/actions/actions.js +127 -127
  187. package/core/lib/models/actions/components/action-detail/action-detail.js +190 -190
  188. package/core/lib/models/actions/components/custom-actions/custom-actions.js +185 -185
  189. package/core/lib/models/attachments/attachments.js +231 -231
  190. package/core/lib/models/base-loader.js +99 -99
  191. package/core/lib/models/base.js +716 -716
  192. package/core/lib/models/branches/branches.js +125 -125
  193. package/core/lib/models/checklists/checklists.js +114 -114
  194. package/core/lib/models/columns/columns.js +169 -169
  195. package/core/lib/models/columns/components/columns-add/columns-add.js +171 -171
  196. package/core/lib/models/comments/comments.js +213 -213
  197. package/core/lib/models/departments/departments.js +107 -107
  198. package/core/lib/models/financial-years/financial_years.js +127 -127
  199. package/core/lib/models/forms/components/form-creator/form-creator.js +667 -667
  200. package/core/lib/models/forms/components/form-creator/form-creator.scss +39 -39
  201. package/core/lib/models/forms/components/form-detail/form-detail.js +224 -224
  202. package/core/lib/models/forms/forms.js +121 -121
  203. package/core/lib/models/index.js +203 -203
  204. package/core/lib/models/invoice-numbers/invoice_numbers.js +204 -204
  205. package/core/lib/models/lookup-types/components/lookup-detail/lookup-detail.js +145 -145
  206. package/core/lib/models/lookup-types/lookup-types.js +113 -113
  207. package/core/lib/models/lookup-values/components/lookup-values-add/lookup-values-add.js +126 -126
  208. package/core/lib/models/lookup-values/lookup-values.js +107 -107
  209. package/core/lib/models/menu-roles/menu-roles.js +127 -127
  210. package/core/lib/models/menus/components/menu-add/menu-add.js +228 -228
  211. package/core/lib/models/menus/components/menu-detail/menu-detail.js +170 -170
  212. package/core/lib/models/menus/components/menu-list/menu-list.js +550 -550
  213. package/core/lib/models/menus/components/menu-list/menu-list.scss +5 -5
  214. package/core/lib/models/menus/components/menu-roles-add/menu-roles-add.js +183 -183
  215. package/core/lib/models/menus/menus.js +499 -499
  216. package/core/lib/models/models/components/model-detail/model-detail.js +137 -137
  217. package/core/lib/models/models/components/models.js +128 -128
  218. package/core/lib/models/modules/modules.js +204 -204
  219. package/core/lib/models/outbox/outbox.js +73 -73
  220. package/core/lib/models/pages/pages.js +107 -107
  221. package/core/lib/models/permissions/permissions.js +71 -71
  222. package/core/lib/models/process/components/process-add/process-add.js +181 -181
  223. package/core/lib/models/process/components/process-dashboard/process-dashboard.js +1068 -1068
  224. package/core/lib/models/process/components/process-dashboard/process-dashboard.scss +66 -66
  225. package/core/lib/models/process/components/process-detail/process-detail.js +140 -140
  226. package/core/lib/models/process/components/process-timeline/process-timeline.js +139 -139
  227. package/core/lib/models/process/components/task-detail/task-detail.js +240 -240
  228. package/core/lib/models/process/components/task-detail/task-detail.scss +27 -27
  229. package/core/lib/models/process/components/task-form/task-form.js +528 -528
  230. package/core/lib/models/process/components/task-form/task-form.scss +7 -7
  231. package/core/lib/models/process/components/task-list/task-list.js +221 -221
  232. package/core/lib/models/process/components/task-list/task-list.scss +14 -14
  233. package/core/lib/models/process/components/task-overview/task-overview.js +299 -299
  234. package/core/lib/models/process/components/task-overview-legacy/task-overview-legacy.js +192 -192
  235. package/core/lib/models/process/components/task-routes/task-routes.js +45 -45
  236. package/core/lib/models/process/components/task-status/task-status.js +175 -175
  237. package/core/lib/models/process/components/task-status/task-status.scss +11 -11
  238. package/core/lib/models/process/process.js +780 -780
  239. package/core/lib/models/process-transactions/process-transactions.js +123 -123
  240. package/core/lib/models/roles/roles.js +106 -106
  241. package/core/lib/models/scripts/scripts.js +111 -111
  242. package/core/lib/models/step-transactions/step-transcations.js +147 -147
  243. package/core/lib/models/steps/components/step-add/step-add.js +261 -261
  244. package/core/lib/models/steps/components/step-detail/step-detail.js +157 -157
  245. package/core/lib/models/steps/steps.js +356 -356
  246. package/core/lib/models/user-preferences/user-preferences.js +83 -83
  247. package/core/lib/models/users/components/user-add/user-add.js +226 -226
  248. package/core/lib/models/users/users.js +119 -119
  249. package/core/lib/modules/business/launch-page/launch-page.js +29 -29
  250. package/core/lib/modules/business/launch-page/launch-page.scss +5 -5
  251. package/core/lib/modules/business/slots/slots.js +231 -231
  252. package/core/lib/modules/business/slots/slots.scss +108 -108
  253. package/core/lib/modules/forms/components/field-customizer/field-customizer.js +138 -138
  254. package/core/lib/modules/forms/components/field-selector/field-selector.js +157 -157
  255. package/core/lib/modules/forms/components/field-selector/field-selector.scss +25 -25
  256. package/core/lib/modules/forms/components/form-display/form-display.js +203 -203
  257. package/core/lib/modules/forms/components/form-display/form-display.scss +9 -9
  258. package/core/lib/modules/forms/components/tab-customizer/tab-customizer.js +124 -124
  259. package/core/lib/modules/generic/generic-add/generic-add.js +213 -213
  260. package/core/lib/modules/generic/generic-detail/generic-detail.js +199 -199
  261. package/core/lib/modules/generic/generic-edit/generic-edit.js +120 -120
  262. package/core/lib/modules/generic/generic-list/ExportReactCSV.js +508 -508
  263. package/core/lib/modules/generic/generic-list/fonts/NotoSansBold.js +8 -8
  264. package/core/lib/modules/generic/generic-list/fonts/NotoSansRegular.js +15 -15
  265. package/core/lib/modules/generic/generic-list/generic-list.js +705 -705
  266. package/core/lib/modules/generic/generic-list/generic-list.scss +68 -68
  267. package/core/lib/modules/generic/generic-upload/generic-upload.js +483 -483
  268. package/core/lib/modules/generic/table-settings/table-settings.js +226 -226
  269. package/core/lib/modules/generic/table-settings/table-settings.scss +37 -37
  270. package/core/lib/modules/index.js +52 -52
  271. package/core/lib/modules/modules-routes/module-routes.js +35 -35
  272. package/core/lib/pages/change-password/change-password.js +204 -204
  273. package/core/lib/pages/change-password/change-password.scss +73 -73
  274. package/core/lib/pages/homepage/homepage.js +53 -53
  275. package/core/lib/pages/index.js +19 -19
  276. package/core/lib/pages/login/commnication-mode-selection.js +46 -46
  277. package/core/lib/pages/login/communication-mode-selection.scss +60 -60
  278. package/core/lib/pages/login/login.js +872 -872
  279. package/core/lib/pages/login/login.scss +353 -353
  280. package/core/lib/pages/login/reset-password.js +124 -124
  281. package/core/lib/pages/login/reset-password.scss +31 -31
  282. package/core/lib/pages/manage-users/manage-users.js +429 -429
  283. package/core/lib/pages/manage-users/manage-users.scss +25 -25
  284. package/core/lib/pages/profile/profile.js +247 -247
  285. package/core/lib/pages/profile/profile.scss +107 -107
  286. package/core/lib/pages/profile/theme-config.js +18 -18
  287. package/core/lib/pages/profile/themes-backup.json +310 -310
  288. package/core/lib/pages/profile/themes.json +254 -254
  289. package/core/lib/pages/register/register.js +176 -176
  290. package/core/lib/pages/register/register.scss +128 -128
  291. package/core/lib/react-styleguide.md +756 -756
  292. package/core/lib/utils/api/api.utils.js +207 -207
  293. package/core/lib/utils/api/readme.md +426 -426
  294. package/core/lib/utils/async.js +35 -35
  295. package/core/lib/utils/common/common.utils.js +237 -237
  296. package/core/lib/utils/common/readme.md +30 -30
  297. package/core/lib/utils/date/date.utils.js +295 -295
  298. package/core/lib/utils/date/readme.md +2 -2
  299. package/core/lib/utils/firebase.support.utils.js +98 -98
  300. package/core/lib/utils/firebase.utils.js +808 -808
  301. package/core/lib/utils/font-awesome.utils.js +168 -168
  302. package/core/lib/utils/form/form.utils.js +255 -255
  303. package/core/lib/utils/generic/generic.utils.js +70 -70
  304. package/core/lib/utils/http/auth.helper.js +95 -95
  305. package/core/lib/utils/http/http.utils.js +190 -190
  306. package/core/lib/utils/http/readme.md +14 -14
  307. package/core/lib/utils/index.js +43 -43
  308. package/core/lib/utils/location/location.utils.js +137 -137
  309. package/core/lib/utils/location/readme.md +18 -18
  310. package/core/lib/utils/modal.utils.js +15 -15
  311. package/core/lib/utils/notification.utils.js +34 -34
  312. package/core/lib/utils/pwa/pwa.utils.js +88 -88
  313. package/core/lib/utils/script.utils.js +235 -235
  314. package/core/lib/utils/setting.utils.js +68 -68
  315. package/core/lib/utils/upload.utils.js +29 -29
  316. package/core/models/Preference/Preferences.js +46 -46
  317. package/core/models/base/base.js +403 -403
  318. package/core/models/base-clone-loader.js +107 -107
  319. package/core/models/base-clone.js +187 -187
  320. package/core/models/base-loader.js +97 -97
  321. package/core/models/core-scripts/core-scripts.js +179 -179
  322. package/core/models/dashboard/dashboard.js +201 -201
  323. package/core/models/detail-loader.js +88 -88
  324. package/core/models/doctor/components/doctor-add/doctor-add.js +432 -432
  325. package/core/models/doctor/components/doctor-add/doctor-add.scss +32 -32
  326. package/core/models/groups.js +82 -82
  327. package/core/models/index.js +100 -100
  328. package/core/models/lookup-types/components/lookup-detail/lookup-detail.js +129 -129
  329. package/core/models/lookup-types/lookup-types.js +96 -96
  330. package/core/models/lookup-values/components/lookup-values-modal/lookup-values-modal.js +95 -95
  331. package/core/models/lookup-values/lookup-values.js +92 -92
  332. package/core/models/menu-roles/components/menu-roles-add/menu-roles-add.js +153 -153
  333. package/core/models/menu-roles/menu-roles.js +158 -158
  334. package/core/models/menus/components/menu-add/menu-add.js +315 -315
  335. package/core/models/menus/components/menu-add/menu-add.scss +31 -31
  336. package/core/models/menus/components/menu-detail/menu-detail.js +263 -263
  337. package/core/models/menus/components/menu-list/menu-list.js +392 -392
  338. package/core/models/menus/components/menu-lists/menu-lists.js +647 -647
  339. package/core/models/menus/components/menu-lists/menu-lists.scss +73 -73
  340. package/core/models/menus/menus.js +338 -338
  341. package/core/models/model-columns.js +121 -121
  342. package/core/models/models/components/model-detail/model-add.js +120 -120
  343. package/core/models/models/components/model-detail/model-detail.js +133 -133
  344. package/core/models/models/models.js +154 -154
  345. package/core/models/pages/components/page-add/page-add.js +163 -163
  346. package/core/models/pages/components/page-add/page-add.scss +30 -30
  347. package/core/models/pages/components/page-details/page-details.js +209 -209
  348. package/core/models/pages/components/page-list/page-list.js +248 -248
  349. package/core/models/pages/pages.js +142 -142
  350. package/core/models/pages.js +142 -142
  351. package/core/models/roles/components/role-add/menu-label.js +14 -14
  352. package/core/models/roles/components/role-add/menu-tree.js +127 -127
  353. package/core/models/roles/components/role-add/role-add.js +230 -230
  354. package/core/models/roles/components/role-add/role-add.scss +4 -4
  355. package/core/models/roles/components/role-list/role-list.js +406 -406
  356. package/core/models/roles/roles.js +199 -199
  357. package/core/models/staff/components/staff-add/staff-add.js +455 -455
  358. package/core/models/user-roles/components/user-roles-add/user-roles-add.js +149 -149
  359. package/core/models/user-roles/user-roles.js +113 -113
  360. package/core/models/users/components/assign-role/assign-role.js +428 -428
  361. package/core/models/users/components/assign-role/assign-role.scss +281 -281
  362. package/core/models/users/components/assign-role/avatar-props.js +45 -45
  363. package/core/models/users/components/user-add/user-add.js +847 -847
  364. package/core/models/users/components/user-add/user-edit.js +110 -110
  365. package/core/models/users/components/user-detail/user-detail.js +236 -236
  366. package/core/models/users/components/user-list/user-list.js +397 -397
  367. package/core/models/users/users.js +379 -379
  368. package/core/modules/Informations/change-info/change-info.js +618 -618
  369. package/core/modules/Informations/change-info/change-info.scss +134 -134
  370. package/core/modules/dashboard/components/dashboard-card/animations.js +64 -64
  371. package/core/modules/dashboard/components/dashboard-card/dashboard-card.js +197 -197
  372. package/core/modules/dashboard/components/dashboard-card/menu-dashboard-card.js +430 -430
  373. package/core/modules/dashboard/components/dashboard-card/menu-dashboard-card.scss +59 -59
  374. package/core/modules/dashboard/components/pop-query-dashboard/pop-query-dashboard.js +66 -66
  375. package/core/modules/generic/components/generic-add/generic-add.js +121 -121
  376. package/core/modules/generic/components/generic-add/generic-add.scss +13 -13
  377. package/core/modules/generic/components/generic-add-modal/generic-add-modal.js +125 -125
  378. package/core/modules/generic/components/generic-add-modal/generic-add-modal.scss +13 -13
  379. package/core/modules/generic/components/generic-detail/generic-detail.js +184 -184
  380. package/core/modules/generic/components/generic-detail/generic-detail.scss +25 -25
  381. package/core/modules/generic/components/generic-edit/generic-edit.js +123 -123
  382. package/core/modules/generic/components/generic-list/generic-list.js +335 -335
  383. package/core/modules/generic/components/generic-list/generic-list.scss +35 -35
  384. package/core/modules/index.js +42 -42
  385. package/core/modules/module-routes/module-routes.js +37 -37
  386. package/core/modules/reporting/components/index.js +6 -6
  387. package/core/modules/reporting/components/reporting-dashboard/README.md +316 -316
  388. package/core/modules/reporting/components/reporting-dashboard/adavance-search/advance-search.js +271 -271
  389. package/core/modules/reporting/components/reporting-dashboard/adavance-search/advance-search.scss +76 -76
  390. package/core/modules/reporting/components/reporting-dashboard/display-columns/build-display-columns.js +90 -90
  391. package/core/modules/reporting/components/reporting-dashboard/display-columns/build-display-columns.test.js +74 -74
  392. package/core/modules/reporting/components/reporting-dashboard/display-columns/display-cell-renderer.js +404 -404
  393. package/core/modules/reporting/components/reporting-dashboard/display-columns/display-cell-renderer.test.js +179 -179
  394. package/core/modules/reporting/components/reporting-dashboard/reporting-dashboard.js +652 -652
  395. package/core/modules/reporting/components/reporting-dashboard/reporting-dashboard.scss +215 -215
  396. package/core/modules/reporting/components/reporting-dashboard/reporting-table.js +537 -537
  397. package/core/modules/steps/action-buttons.js +92 -92
  398. package/core/modules/steps/action-buttons.scss +62 -62
  399. package/core/modules/steps/chat-assistant.js +141 -141
  400. package/core/modules/steps/narration.js +192 -192
  401. package/core/modules/steps/openai-realtime.js +275 -275
  402. package/core/modules/steps/progress-storage.js +140 -140
  403. package/core/modules/steps/readme.md +167 -167
  404. package/core/modules/steps/steps.js +1716 -1597
  405. package/core/modules/steps/steps.scss +1068 -1051
  406. package/core/modules/steps/timeline.js +56 -56
  407. package/core/modules/steps/voice-navigation.js +709 -709
  408. package/core/pages/homepage-api/homepage-api.js +106 -106
  409. package/core/pages/homepage-api/homepage-api.scss +233 -233
  410. package/core/pages/homepage-api/menu-dashboard.js +169 -169
  411. package/core/pages/homepage-api/menu-dashboard.scss +11 -11
  412. package/core/translation.json +53 -53
  413. package/core/translations.json +19 -19
  414. package/core/utils/script.utils.js +129 -129
  415. package/core/utils/settings.utils.js +25 -25
  416. package/eslint.config.mjs +79 -79
  417. package/index.js +35 -35
  418. package/jest.config.js +7 -7
  419. package/jest.setup.js +1 -1
  420. package/package.json +125 -125
  421. package/tsconfig.json +26 -26
  422. package/webpack.config.js +173 -173
@@ -1,757 +1,757 @@
1
- ### React/JSX Style Guide
2
-
3
- *A mostly reasonable approach to React and JSX*
4
-
5
- This style guide is mostly based on the standards that are currently prevalent in JavaScript, although some conventions (i.e async/await or static class fields) may still be included or prohibited on a case-by-case basis. Currently, anything prior to stage 3 is not included nor recommended in this guide.
6
-
7
- ## Table of Contents
8
-
9
- 1. [Basic Rules](#basic-rules)
10
- 1. [Class vs `React.createClass` vs stateless](#class-vs-reactcreateclass-vs-stateless)
11
- 1. [Mixins](#mixins)
12
- 1. [Naming](#naming)
13
- 1. [Declaration](#declaration)
14
- 1. [Alignment](#alignment)
15
- 1. [Quotes](#quotes)
16
- 1. [Spacing](#spacing)
17
- 1. [Props](#props)
18
- 1. [Refs](#refs)
19
- 1. [Parentheses](#parentheses)
20
- 1. [Tags](#tags)
21
- 1. [Methods](#methods)
22
- 1. [Ordering](#ordering)
23
- 1. [`isMounted`](#ismounted)
24
-
25
- ## Basic Rules
26
-
27
- - Only include one React component per file.
28
- - However, multiple [Stateless, or Pure, Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) are allowed per file. eslint: [`react/no-multi-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless).
29
- - Always use JSX syntax.
30
- - Do not use `React.createElement` unless you’re initializing the app from a file that is not JSX.
31
- - [`react/forbid-prop-types`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md) will allow `arrays` and `objects` only if it is explicitly noted what `array` and `object` contains, using `arrayOf`, `objectOf`, or `shape`.
32
-
33
- ## Class vs `React.createClass` vs stateless
34
-
35
- - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass`. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md)
36
-
37
- ```jsx static
38
- // bad
39
- const Listing = React.createClass({
40
- // ...
41
- render() {
42
- return <div>{this.state.hello}</div>;
43
- }
44
- });
45
-
46
- // good
47
- class Listing extends React.Component {
48
- // ...
49
- render() {
50
- return <div>{this.state.hello}</div>;
51
- }
52
- }
53
- ```
54
-
55
- And if you don’t have state or refs, prefer normal functions (not arrow functions) over classes:
56
-
57
- ```jsx static
58
- // bad
59
- class Listing extends React.Component {
60
- render() {
61
- return <div>{this.props.hello}</div>;
62
- }
63
- }
64
-
65
- // bad (relying on function name inference is discouraged)
66
- const Listing = ({ hello }) => (
67
- <div>{hello}</div>
68
- );
69
-
70
- // good
71
- function Listing({ hello }) {
72
- return <div>{hello}</div>;
73
- }
74
- ```
75
-
76
- ## Mixins
77
-
78
- - [Do not use mixins](https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html).
79
-
80
- > Why? Mixins introduce implicit dependencies, cause name clashes, and cause snowballing complexity. Most use cases for mixins can be accomplished in better ways via components, higher-order components, or utility modules.
81
-
82
- ## Naming
83
-
84
- - **Extensions**: Use `.jsx` extension for React components. eslint: [`react/jsx-filename-extension`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md)
85
- - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`.
86
- - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md)
87
-
88
- ```jsx static
89
- // bad
90
- import reservationCard from './ReservationCard';
91
-
92
- // good
93
- import ReservationCard from './ReservationCard';
94
-
95
- // bad
96
- const ReservationItem = <ReservationCard />;
97
-
98
- // good
99
- const reservationItem = <ReservationCard />;
100
- ```
101
-
102
- - **Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name:
103
-
104
- ```jsx static
105
- // bad
106
- import Footer from './Footer/Footer';
107
-
108
- // bad
109
- import Footer from './Footer/index';
110
-
111
- // good
112
- import Footer from './Footer';
113
- ```
114
-
115
- - **Higher-order Component Naming**: Use a composite of the higher-order component’s name and the passed-in component’s name as the `displayName` on the generated component. For example, the higher-order component `withFoo()`, when passed a component `Bar` should produce a component with a `displayName` of `withFoo(Bar)`.
116
-
117
- > Why? A component’s `displayName` may be used by developer tools or in error messages, and having a value that clearly expresses this relationship helps people understand what is happening.
118
-
119
- ```jsx static
120
- // bad
121
- export default function withFoo(WrappedComponent) {
122
- return function WithFoo(props) {
123
- return <WrappedComponent {...props} foo />;
124
- }
125
- }
126
-
127
- // good
128
- export default function withFoo(WrappedComponent) {
129
- function WithFoo(props) {
130
- return <WrappedComponent {...props} foo />;
131
- }
132
-
133
- const wrappedComponentName = WrappedComponent.displayName
134
- || WrappedComponent.name
135
- || 'Component';
136
-
137
- WithFoo.displayName = `withFoo(${wrappedComponentName})`;
138
- return WithFoo;
139
- }
140
- ```
141
-
142
- - **Props Naming**: Avoid using DOM component prop names for different purposes.
143
-
144
- > Why? People expect props like `style` and `className` to mean one specific thing. Varying this API for a subset of your app makes the code less readable and less maintainable, and may cause bugs.
145
-
146
- ```jsx static
147
- // bad
148
- <MyComponent style="fancy" />
149
-
150
- // bad
151
- <MyComponent className="fancy" />
152
-
153
- // good
154
- <MyComponent variant="fancy" />
155
- ```
156
-
157
- ## Declaration
158
-
159
- - Do not use `displayName` for naming components. Instead, name the component by reference.
160
-
161
- ```jsx static
162
- // bad
163
- export default React.createClass({
164
- displayName: 'ReservationCard',
165
- // stuff goes here
166
- });
167
-
168
- // good
169
- export default class ReservationCard extends React.Component {
170
- }
171
- ```
172
-
173
- ## Alignment
174
-
175
- - Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) [`react/jsx-closing-tag-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md)
176
-
177
- ```jsx static
178
- // bad
179
- <Foo superLongParam="bar"
180
- anotherSuperLongParam="baz" />
181
-
182
- // good
183
- <Foo
184
- superLongParam="bar"
185
- anotherSuperLongParam="baz"
186
- />
187
-
188
- // if props fit in one line then keep it on the same line
189
- <Foo bar="bar" />
190
-
191
- // children get indented normally
192
- <Foo
193
- superLongParam="bar"
194
- anotherSuperLongParam="baz"
195
- >
196
- <Quux />
197
- </Foo>
198
-
199
- // bad
200
- {showButton &&
201
- <Button />
202
- }
203
-
204
- // bad
205
- {
206
- showButton &&
207
- <Button />
208
- }
209
-
210
- // good
211
- {showButton && (
212
- <Button />
213
- )}
214
-
215
- // good
216
- {showButton && <Button />}
217
-
218
- // good
219
- {someReallyLongConditional
220
- && anotherLongConditional
221
- && (
222
- <Foo
223
- superLongParam="bar"
224
- anotherSuperLongParam="baz"
225
- />
226
- )
227
- }
228
-
229
- // good
230
- {someConditional ? (
231
- <Foo />
232
- ) : (
233
- <Foo
234
- superLongParam="bar"
235
- anotherSuperLongParam="baz"
236
- />
237
- )}
238
- ```
239
-
240
- ## Quotes
241
-
242
- - Always use double quotes (`"`) for JSX attributes, but single quotes (`'`) for all other JS. eslint: [`jsx-quotes`](https://eslint.org/docs/rules/jsx-quotes)
243
-
244
- > Why? Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention.
245
-
246
- ```jsx static
247
- // bad
248
- <Foo bar='bar' />
249
-
250
- // good
251
- <Foo bar="bar" />
252
-
253
- // bad
254
- <Foo style={{ left: "20px" }} />
255
-
256
- // good
257
- <Foo style={{ left: '20px' }} />
258
- ```
259
-
260
- ## Spacing
261
-
262
- - Always include a single space in your self-closing tag. eslint: [`no-multi-spaces`](https://eslint.org/docs/rules/no-multi-spaces), [`react/jsx-tag-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md)
263
-
264
- ```jsx static
265
- // bad
266
- <Foo/>
267
-
268
- // very bad
269
- <Foo />
270
-
271
- // bad
272
- <Foo
273
- />
274
-
275
- // good
276
- <Foo />
277
- ```
278
-
279
- - Do not pad JSX curly braces with spaces. eslint: [`react/jsx-curly-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md)
280
-
281
- ```jsx static
282
- // bad
283
- <Foo bar={ baz } />
284
-
285
- // good
286
- <Foo bar={baz} />
287
- ```
288
-
289
- ## Props
290
-
291
- - Always use camelCase for prop names, or PascalCase if the prop value is a React component.
292
-
293
- ```jsx static
294
- // bad
295
- <Foo
296
- UserName="hello"
297
- phone_number={12345678}
298
- />
299
-
300
- // good
301
- <Foo
302
- userName="hello"
303
- phoneNumber={12345678}
304
- Component={SomeComponent}
305
- />
306
- ```
307
-
308
- - Omit the value of the prop when it is explicitly `true`. eslint: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md)
309
-
310
- ```jsx static
311
- // bad
312
- <Foo
313
- hidden={true}
314
- />
315
-
316
- // good
317
- <Foo
318
- hidden
319
- />
320
-
321
- // good
322
- <Foo hidden />
323
- ```
324
-
325
- - Always include an `alt` prop on `<img>` tags. If the image is presentational, `alt` can be an empty string or the `<img>` must have `role="presentation"`. eslint: [`jsx-a11y/alt-text`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/alt-text.md)
326
-
327
- ```jsx static
328
- // bad
329
- <img src="hello.jpg" />
330
-
331
- // good
332
- <img src="hello.jpg" alt="Me waving hello" />
333
-
334
- // good
335
- <img src="hello.jpg" alt="" />
336
-
337
- // good
338
- <img src="hello.jpg" role="presentation" />
339
- ```
340
-
341
- - Do not use words like "image", "photo", or "picture" in `<img>` `alt` props. eslint: [`jsx-a11y/img-redundant-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md)
342
-
343
- > Why? Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text.
344
-
345
- ```jsx static
346
- // bad
347
- <img src="hello.jpg" alt="Picture of me waving hello" />
348
-
349
- // good
350
- <img src="hello.jpg" alt="Me waving hello" />
351
- ```
352
-
353
- - Use only valid, non-abstract [ARIA roles](https://www.w3.org/TR/wai-aria/#usage_intro). eslint: [`jsx-a11y/aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md)
354
-
355
- ```jsx static
356
- // bad - not an ARIA role
357
- <div role="datepicker" />
358
-
359
- // bad - abstract ARIA role
360
- <div role="range" />
361
-
362
- // good
363
- <div role="button" />
364
- ```
365
-
366
- - Do not use `accessKey` on elements. eslint: [`jsx-a11y/no-access-key`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md)
367
-
368
- > Why? Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility.
369
-
370
- ```jsx static
371
- // bad
372
- <div accessKey="h" />
373
-
374
- // good
375
- <div />
376
- ```
377
-
378
- - Avoid using an array index as `key` prop, prefer a stable ID. eslint: [`react/no-array-index-key`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md)
379
-
380
- > Why? Not using a stable ID [is an anti-pattern](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318) because it can negatively impact performance and cause issues with component state.
381
-
382
- We don’t recommend using indexes for keys if the order of items may change.
383
-
384
- ```jsx static
385
- // bad
386
- {todos.map((todo, index) =>
387
- <Todo
388
- {...todo}
389
- key={index}
390
- />
391
- )}
392
-
393
- // good
394
- {todos.map(todo => (
395
- <Todo
396
- {...todo}
397
- key={todo.id}
398
- />
399
- ))}
400
- ```
401
-
402
- - Always define explicit defaultProps for all non-required props.
403
-
404
- > Why? propTypes are a form of documentation, and providing defaultProps means the reader of your code doesn’t have to assume as much. In addition, it can mean that your code can omit certain type checks.
405
-
406
- ```jsx static
407
- // bad
408
- function SFC({ foo, bar, children }) {
409
- return <div>{foo}{bar}{children}</div>;
410
- }
411
- SFC.propTypes = {
412
- foo: PropTypes.number.isRequired,
413
- bar: PropTypes.string,
414
- children: PropTypes.node,
415
- };
416
-
417
- // good
418
- function SFC({ foo, bar, children }) {
419
- return <div>{foo}{bar}{children}</div>;
420
- }
421
- SFC.propTypes = {
422
- foo: PropTypes.number.isRequired,
423
- bar: PropTypes.string,
424
- children: PropTypes.node,
425
- };
426
- SFC.defaultProps = {
427
- bar: '',
428
- children: null,
429
- };
430
- ```
431
-
432
- - Use spread props sparingly.
433
- > Why? Otherwise you’re more likely to pass unnecessary props down to components. And for React v15.6.1 and older, you could [pass invalid HTML attributes to the DOM](https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html).
434
-
435
- Exceptions:
436
-
437
- - HOCs that proxy down props and hoist propTypes
438
-
439
- ```jsx static
440
- function HOC(WrappedComponent) {
441
- return class Proxy extends React.Component {
442
- Proxy.propTypes = {
443
- text: PropTypes.string,
444
- isLoading: PropTypes.bool
445
- };
446
-
447
- render() {
448
- return <WrappedComponent {...this.props} />
449
- }
450
- }
451
- }
452
- ```
453
-
454
- - Spreading objects with known, explicit props. This can be particularly useful when testing React components with Mocha’s beforeEach construct.
455
-
456
- ```jsx static
457
- export default function Foo {
458
- const props = {
459
- text: '',
460
- isPublished: false
461
- }
462
-
463
- return (<div {...props} />);
464
- }
465
- ```
466
-
467
- Notes for use:
468
- Filter out unnecessary props when possible. Also, use [prop-types-exact](https://www.npmjs.com/package/prop-types-exact) to help prevent bugs.
469
-
470
- ```jsx static
471
- // bad
472
- render() {
473
- const { irrelevantProp, ...relevantProps } = this.props;
474
- return <WrappedComponent {...this.props} />
475
- }
476
-
477
- // good
478
- render() {
479
- const { irrelevantProp, ...relevantProps } = this.props;
480
- return <WrappedComponent {...relevantProps} />
481
- }
482
- ```
483
-
484
- ## Refs
485
-
486
- - Always use ref callbacks. eslint: [`react/no-string-refs`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md)
487
-
488
- ```jsx static
489
- // bad
490
- <Foo
491
- ref="myRef"
492
- />
493
-
494
- // good
495
- <Foo
496
- ref={(ref) => { this.myRef = ref; }}
497
- />
498
- ```
499
-
500
- ## Parentheses
501
-
502
- - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/jsx-wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md)
503
-
504
- ```jsx static
505
- // bad
506
- render() {
507
- return <MyComponent variant="long body" foo="bar">
508
- <MyChild />
509
- </MyComponent>;
510
- }
511
-
512
- // good
513
- render() {
514
- return (
515
- <MyComponent variant="long body" foo="bar">
516
- <MyChild />
517
- </MyComponent>
518
- );
519
- }
520
-
521
- // good, when single line
522
- render() {
523
- const body = <div>hello</div>;
524
- return <MyComponent>{body}</MyComponent>;
525
- }
526
- ```
527
-
528
- ## Tags
529
-
530
- - Always self-close tags that have no children. eslint: [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md)
531
-
532
- ```jsx static
533
- // bad
534
- <Foo variant="stuff"></Foo>
535
-
536
- // good
537
- <Foo variant="stuff" />
538
- ```
539
-
540
- - If your component has multiline properties, close its tag on a new line. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md)
541
-
542
- ```jsx static
543
- // bad
544
- <Foo
545
- bar="bar"
546
- baz="baz" />
547
-
548
- // good
549
- <Foo
550
- bar="bar"
551
- baz="baz"
552
- />
553
- ```
554
-
555
- ## Methods
556
-
557
- - Use arrow functions to close over local variables. It is handy when you need to pass additional data to an event handler. Although, make sure they [do not massively hurt performance](https://www.bignerdranch.com/blog/choosing-the-best-approach-for-react-event-handlers/), in particular when passed to custom components that might be PureComponents, because they will trigger a possibly needless rerender every time.
558
-
559
- ```jsx static
560
- function ItemList(props) {
561
- return (
562
- <ul>
563
- {props.items.map((item, index) => (
564
- <Item
565
- key={item.key}
566
- onClick={(event) => { doSomethingWith(event, item.name, index); }}
567
- />
568
- ))}
569
- </ul>
570
- );
571
- }
572
- ```
573
-
574
- - Bind event handlers for the render method in the constructor. eslint: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md)
575
-
576
- > Why? A bind call in the render path creates a brand new function on every single render. Do not use arrow functions in class fields, because it makes them [challenging to test and debug, and can negatively impact performance](https://medium.com/@charpeni/arrow-functions-in-class-properties-might-not-be-as-great-as-we-think-3b3551c440b1), and because conceptually, class fields are for data, not logic.
577
-
578
- ```jsx static
579
- // bad
580
- class extends React.Component {
581
- onClickDiv() {
582
- // do stuff
583
- }
584
-
585
- render() {
586
- return <div onClick={this.onClickDiv.bind(this)} />;
587
- }
588
- }
589
-
590
- // very bad
591
- class extends React.Component {
592
- onClickDiv = () => {
593
- // do stuff
594
- }
595
-
596
- render() {
597
- return <div onClick={this.onClickDiv} />
598
- }
599
- }
600
-
601
- // good
602
- class extends React.Component {
603
- constructor(props) {
604
- super(props);
605
-
606
- this.onClickDiv = this.onClickDiv.bind(this);
607
- }
608
-
609
- onClickDiv() {
610
- // do stuff
611
- }
612
-
613
- render() {
614
- return <div onClick={this.onClickDiv} />;
615
- }
616
- }
617
- ```
618
-
619
- - Do not use underscore prefix for internal methods of a React component.
620
- > Why? Underscore prefixes are sometimes used as a convention in other languages to denote privacy. But, unlike those languages, there is no native support for privacy in JavaScript, everything is public. Regardless of your intentions, adding underscore prefixes to your properties does not actually make them private, and any property (underscore-prefixed or not) should be treated as being public. See issues [#1024](https://github.com/airbnb/javascript/issues/1024), and [#490](https://github.com/airbnb/javascript/issues/490) for a more in-depth discussion.
621
-
622
- ```jsx static
623
- // bad
624
- React.createClass({
625
- _onClickSubmit() {
626
- // do stuff
627
- },
628
-
629
- // other stuff
630
- });
631
-
632
- // good
633
- class extends React.Component {
634
- onClickSubmit() {
635
- // do stuff
636
- }
637
-
638
- // other stuff
639
- }
640
- ```
641
-
642
- - Be sure to return a value in your `render` methods. eslint: [`react/require-render-return`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md)
643
-
644
- ```jsx static
645
- // bad
646
- render() {
647
- (<div />);
648
- }
649
-
650
- // good
651
- render() {
652
- return (<div />);
653
- }
654
- ```
655
-
656
- ## Ordering
657
-
658
- - Ordering for `class extends React.Component`:
659
-
660
- 1. optional `static` methods
661
- 1. `constructor`
662
- 1. `getChildContext`
663
- 1. `componentWillMount`
664
- 1. `componentDidMount`
665
- 1. `componentWillReceiveProps`
666
- 1. `shouldComponentUpdate`
667
- 1. `componentWillUpdate`
668
- 1. `componentDidUpdate`
669
- 1. `componentWillUnmount`
670
- 1. *event handlers starting with 'handle'* like `handleSubmit()` or `handleChangeDescription()`
671
- 1. *event handlers starting with 'on'* like `onClickSubmit()` or `onChangeDescription()`
672
- 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
673
- 1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
674
- 1. `render`
675
-
676
- - How to define `propTypes`, `defaultProps`, `contextTypes`, etc...
677
-
678
- ```jsx static
679
- import React from 'react';
680
- import PropTypes from 'prop-types';
681
-
682
- const propTypes = {
683
- id: PropTypes.number.isRequired,
684
- url: PropTypes.string.isRequired,
685
- text: PropTypes.string,
686
- };
687
-
688
- const defaultProps = {
689
- text: 'Hello World',
690
- };
691
-
692
- class Link extends React.Component {
693
- static methodsAreOk() {
694
- return true;
695
- }
696
-
697
- render() {
698
- return <a href={this.props.url} data-id={this.props.id}>{this.props.text}</a>;
699
- }
700
- }
701
-
702
- Link.propTypes = propTypes;
703
- Link.defaultProps = defaultProps;
704
-
705
- export default Link;
706
- ```
707
-
708
- - Ordering for `React.createClass`: eslint: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md)
709
-
710
- 1. `displayName`
711
- 1. `propTypes`
712
- 1. `contextTypes`
713
- 1. `childContextTypes`
714
- 1. `mixins`
715
- 1. `statics`
716
- 1. `defaultProps`
717
- 1. `getDefaultProps`
718
- 1. `getInitialState`
719
- 1. `getChildContext`
720
- 1. `componentWillMount`
721
- 1. `componentDidMount`
722
- 1. `componentWillReceiveProps`
723
- 1. `shouldComponentUpdate`
724
- 1. `componentWillUpdate`
725
- 1. `componentDidUpdate`
726
- 1. `componentWillUnmount`
727
- 1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()`
728
- 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
729
- 1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
730
- 1. `render`
731
-
732
- ## `isMounted`
733
-
734
- - Do not use `isMounted`. eslint: [`react/no-is-mounted`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md)
735
-
736
- > Why? [`isMounted` is an anti-pattern][anti-pattern], is not available when using ES6 classes, and is on its way to being officially deprecated.
737
-
738
- [anti-pattern]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html
739
-
740
- <!-- ## Translation
741
-
742
- This JSX/React style guide is also available in other languages:
743
-
744
- - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese (Simplified)**: [jhcccc/javascript](https://github.com/jhcccc/javascript/tree/master/react)
745
- - ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript/tree/master/react)
746
- - ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png) **Español**: [agrcrobles/javascript](https://github.com/agrcrobles/javascript/tree/master/react)
747
- - ![jp](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png) **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide/tree/master/react)
748
- - ![kr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [apple77y/javascript](https://github.com/apple77y/javascript/tree/master/react)
749
- - ![pl](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Poland.png) **Polish**: [pietraszekl/javascript](https://github.com/pietraszekl/javascript/tree/master/react)
750
- - ![Br](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Portuguese**: [ronal2do/javascript](https://github.com/ronal2do/airbnb-react-styleguide)
751
- - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb/tree/master/react)
752
- - ![th](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Thailand.png) **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide/tree/master/react)
753
- - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [alioguzhan/react-style-guide](https://github.com/alioguzhan/react-style-guide)
754
- - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript/tree/master/react)
755
- - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnam**: [uetcodecamp/jsx-style-guide](https://github.com/UETCodeCamp/jsx-style-guide) -->
756
-
1
+ ### React/JSX Style Guide
2
+
3
+ *A mostly reasonable approach to React and JSX*
4
+
5
+ This style guide is mostly based on the standards that are currently prevalent in JavaScript, although some conventions (i.e async/await or static class fields) may still be included or prohibited on a case-by-case basis. Currently, anything prior to stage 3 is not included nor recommended in this guide.
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Basic Rules](#basic-rules)
10
+ 1. [Class vs `React.createClass` vs stateless](#class-vs-reactcreateclass-vs-stateless)
11
+ 1. [Mixins](#mixins)
12
+ 1. [Naming](#naming)
13
+ 1. [Declaration](#declaration)
14
+ 1. [Alignment](#alignment)
15
+ 1. [Quotes](#quotes)
16
+ 1. [Spacing](#spacing)
17
+ 1. [Props](#props)
18
+ 1. [Refs](#refs)
19
+ 1. [Parentheses](#parentheses)
20
+ 1. [Tags](#tags)
21
+ 1. [Methods](#methods)
22
+ 1. [Ordering](#ordering)
23
+ 1. [`isMounted`](#ismounted)
24
+
25
+ ## Basic Rules
26
+
27
+ - Only include one React component per file.
28
+ - However, multiple [Stateless, or Pure, Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) are allowed per file. eslint: [`react/no-multi-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless).
29
+ - Always use JSX syntax.
30
+ - Do not use `React.createElement` unless you’re initializing the app from a file that is not JSX.
31
+ - [`react/forbid-prop-types`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md) will allow `arrays` and `objects` only if it is explicitly noted what `array` and `object` contains, using `arrayOf`, `objectOf`, or `shape`.
32
+
33
+ ## Class vs `React.createClass` vs stateless
34
+
35
+ - If you have internal state and/or refs, prefer `class extends React.Component` over `React.createClass`. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md)
36
+
37
+ ```jsx static
38
+ // bad
39
+ const Listing = React.createClass({
40
+ // ...
41
+ render() {
42
+ return <div>{this.state.hello}</div>;
43
+ }
44
+ });
45
+
46
+ // good
47
+ class Listing extends React.Component {
48
+ // ...
49
+ render() {
50
+ return <div>{this.state.hello}</div>;
51
+ }
52
+ }
53
+ ```
54
+
55
+ And if you don’t have state or refs, prefer normal functions (not arrow functions) over classes:
56
+
57
+ ```jsx static
58
+ // bad
59
+ class Listing extends React.Component {
60
+ render() {
61
+ return <div>{this.props.hello}</div>;
62
+ }
63
+ }
64
+
65
+ // bad (relying on function name inference is discouraged)
66
+ const Listing = ({ hello }) => (
67
+ <div>{hello}</div>
68
+ );
69
+
70
+ // good
71
+ function Listing({ hello }) {
72
+ return <div>{hello}</div>;
73
+ }
74
+ ```
75
+
76
+ ## Mixins
77
+
78
+ - [Do not use mixins](https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html).
79
+
80
+ > Why? Mixins introduce implicit dependencies, cause name clashes, and cause snowballing complexity. Most use cases for mixins can be accomplished in better ways via components, higher-order components, or utility modules.
81
+
82
+ ## Naming
83
+
84
+ - **Extensions**: Use `.jsx` extension for React components. eslint: [`react/jsx-filename-extension`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md)
85
+ - **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`.
86
+ - **Reference Naming**: Use PascalCase for React components and camelCase for their instances. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md)
87
+
88
+ ```jsx static
89
+ // bad
90
+ import reservationCard from './ReservationCard';
91
+
92
+ // good
93
+ import ReservationCard from './ReservationCard';
94
+
95
+ // bad
96
+ const ReservationItem = <ReservationCard />;
97
+
98
+ // good
99
+ const reservationItem = <ReservationCard />;
100
+ ```
101
+
102
+ - **Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name:
103
+
104
+ ```jsx static
105
+ // bad
106
+ import Footer from './Footer/Footer';
107
+
108
+ // bad
109
+ import Footer from './Footer/index';
110
+
111
+ // good
112
+ import Footer from './Footer';
113
+ ```
114
+
115
+ - **Higher-order Component Naming**: Use a composite of the higher-order component’s name and the passed-in component’s name as the `displayName` on the generated component. For example, the higher-order component `withFoo()`, when passed a component `Bar` should produce a component with a `displayName` of `withFoo(Bar)`.
116
+
117
+ > Why? A component’s `displayName` may be used by developer tools or in error messages, and having a value that clearly expresses this relationship helps people understand what is happening.
118
+
119
+ ```jsx static
120
+ // bad
121
+ export default function withFoo(WrappedComponent) {
122
+ return function WithFoo(props) {
123
+ return <WrappedComponent {...props} foo />;
124
+ }
125
+ }
126
+
127
+ // good
128
+ export default function withFoo(WrappedComponent) {
129
+ function WithFoo(props) {
130
+ return <WrappedComponent {...props} foo />;
131
+ }
132
+
133
+ const wrappedComponentName = WrappedComponent.displayName
134
+ || WrappedComponent.name
135
+ || 'Component';
136
+
137
+ WithFoo.displayName = `withFoo(${wrappedComponentName})`;
138
+ return WithFoo;
139
+ }
140
+ ```
141
+
142
+ - **Props Naming**: Avoid using DOM component prop names for different purposes.
143
+
144
+ > Why? People expect props like `style` and `className` to mean one specific thing. Varying this API for a subset of your app makes the code less readable and less maintainable, and may cause bugs.
145
+
146
+ ```jsx static
147
+ // bad
148
+ <MyComponent style="fancy" />
149
+
150
+ // bad
151
+ <MyComponent className="fancy" />
152
+
153
+ // good
154
+ <MyComponent variant="fancy" />
155
+ ```
156
+
157
+ ## Declaration
158
+
159
+ - Do not use `displayName` for naming components. Instead, name the component by reference.
160
+
161
+ ```jsx static
162
+ // bad
163
+ export default React.createClass({
164
+ displayName: 'ReservationCard',
165
+ // stuff goes here
166
+ });
167
+
168
+ // good
169
+ export default class ReservationCard extends React.Component {
170
+ }
171
+ ```
172
+
173
+ ## Alignment
174
+
175
+ - Follow these alignment styles for JSX syntax. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) [`react/jsx-closing-tag-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md)
176
+
177
+ ```jsx static
178
+ // bad
179
+ <Foo superLongParam="bar"
180
+ anotherSuperLongParam="baz" />
181
+
182
+ // good
183
+ <Foo
184
+ superLongParam="bar"
185
+ anotherSuperLongParam="baz"
186
+ />
187
+
188
+ // if props fit in one line then keep it on the same line
189
+ <Foo bar="bar" />
190
+
191
+ // children get indented normally
192
+ <Foo
193
+ superLongParam="bar"
194
+ anotherSuperLongParam="baz"
195
+ >
196
+ <Quux />
197
+ </Foo>
198
+
199
+ // bad
200
+ {showButton &&
201
+ <Button />
202
+ }
203
+
204
+ // bad
205
+ {
206
+ showButton &&
207
+ <Button />
208
+ }
209
+
210
+ // good
211
+ {showButton && (
212
+ <Button />
213
+ )}
214
+
215
+ // good
216
+ {showButton && <Button />}
217
+
218
+ // good
219
+ {someReallyLongConditional
220
+ && anotherLongConditional
221
+ && (
222
+ <Foo
223
+ superLongParam="bar"
224
+ anotherSuperLongParam="baz"
225
+ />
226
+ )
227
+ }
228
+
229
+ // good
230
+ {someConditional ? (
231
+ <Foo />
232
+ ) : (
233
+ <Foo
234
+ superLongParam="bar"
235
+ anotherSuperLongParam="baz"
236
+ />
237
+ )}
238
+ ```
239
+
240
+ ## Quotes
241
+
242
+ - Always use double quotes (`"`) for JSX attributes, but single quotes (`'`) for all other JS. eslint: [`jsx-quotes`](https://eslint.org/docs/rules/jsx-quotes)
243
+
244
+ > Why? Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention.
245
+
246
+ ```jsx static
247
+ // bad
248
+ <Foo bar='bar' />
249
+
250
+ // good
251
+ <Foo bar="bar" />
252
+
253
+ // bad
254
+ <Foo style={{ left: "20px" }} />
255
+
256
+ // good
257
+ <Foo style={{ left: '20px' }} />
258
+ ```
259
+
260
+ ## Spacing
261
+
262
+ - Always include a single space in your self-closing tag. eslint: [`no-multi-spaces`](https://eslint.org/docs/rules/no-multi-spaces), [`react/jsx-tag-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md)
263
+
264
+ ```jsx static
265
+ // bad
266
+ <Foo/>
267
+
268
+ // very bad
269
+ <Foo />
270
+
271
+ // bad
272
+ <Foo
273
+ />
274
+
275
+ // good
276
+ <Foo />
277
+ ```
278
+
279
+ - Do not pad JSX curly braces with spaces. eslint: [`react/jsx-curly-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md)
280
+
281
+ ```jsx static
282
+ // bad
283
+ <Foo bar={ baz } />
284
+
285
+ // good
286
+ <Foo bar={baz} />
287
+ ```
288
+
289
+ ## Props
290
+
291
+ - Always use camelCase for prop names, or PascalCase if the prop value is a React component.
292
+
293
+ ```jsx static
294
+ // bad
295
+ <Foo
296
+ UserName="hello"
297
+ phone_number={12345678}
298
+ />
299
+
300
+ // good
301
+ <Foo
302
+ userName="hello"
303
+ phoneNumber={12345678}
304
+ Component={SomeComponent}
305
+ />
306
+ ```
307
+
308
+ - Omit the value of the prop when it is explicitly `true`. eslint: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md)
309
+
310
+ ```jsx static
311
+ // bad
312
+ <Foo
313
+ hidden={true}
314
+ />
315
+
316
+ // good
317
+ <Foo
318
+ hidden
319
+ />
320
+
321
+ // good
322
+ <Foo hidden />
323
+ ```
324
+
325
+ - Always include an `alt` prop on `<img>` tags. If the image is presentational, `alt` can be an empty string or the `<img>` must have `role="presentation"`. eslint: [`jsx-a11y/alt-text`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/alt-text.md)
326
+
327
+ ```jsx static
328
+ // bad
329
+ <img src="hello.jpg" />
330
+
331
+ // good
332
+ <img src="hello.jpg" alt="Me waving hello" />
333
+
334
+ // good
335
+ <img src="hello.jpg" alt="" />
336
+
337
+ // good
338
+ <img src="hello.jpg" role="presentation" />
339
+ ```
340
+
341
+ - Do not use words like "image", "photo", or "picture" in `<img>` `alt` props. eslint: [`jsx-a11y/img-redundant-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md)
342
+
343
+ > Why? Screenreaders already announce `img` elements as images, so there is no need to include this information in the alt text.
344
+
345
+ ```jsx static
346
+ // bad
347
+ <img src="hello.jpg" alt="Picture of me waving hello" />
348
+
349
+ // good
350
+ <img src="hello.jpg" alt="Me waving hello" />
351
+ ```
352
+
353
+ - Use only valid, non-abstract [ARIA roles](https://www.w3.org/TR/wai-aria/#usage_intro). eslint: [`jsx-a11y/aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md)
354
+
355
+ ```jsx static
356
+ // bad - not an ARIA role
357
+ <div role="datepicker" />
358
+
359
+ // bad - abstract ARIA role
360
+ <div role="range" />
361
+
362
+ // good
363
+ <div role="button" />
364
+ ```
365
+
366
+ - Do not use `accessKey` on elements. eslint: [`jsx-a11y/no-access-key`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md)
367
+
368
+ > Why? Inconsistencies between keyboard shortcuts and keyboard commands used by people using screenreaders and keyboards complicate accessibility.
369
+
370
+ ```jsx static
371
+ // bad
372
+ <div accessKey="h" />
373
+
374
+ // good
375
+ <div />
376
+ ```
377
+
378
+ - Avoid using an array index as `key` prop, prefer a stable ID. eslint: [`react/no-array-index-key`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md)
379
+
380
+ > Why? Not using a stable ID [is an anti-pattern](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318) because it can negatively impact performance and cause issues with component state.
381
+
382
+ We don’t recommend using indexes for keys if the order of items may change.
383
+
384
+ ```jsx static
385
+ // bad
386
+ {todos.map((todo, index) =>
387
+ <Todo
388
+ {...todo}
389
+ key={index}
390
+ />
391
+ )}
392
+
393
+ // good
394
+ {todos.map(todo => (
395
+ <Todo
396
+ {...todo}
397
+ key={todo.id}
398
+ />
399
+ ))}
400
+ ```
401
+
402
+ - Always define explicit defaultProps for all non-required props.
403
+
404
+ > Why? propTypes are a form of documentation, and providing defaultProps means the reader of your code doesn’t have to assume as much. In addition, it can mean that your code can omit certain type checks.
405
+
406
+ ```jsx static
407
+ // bad
408
+ function SFC({ foo, bar, children }) {
409
+ return <div>{foo}{bar}{children}</div>;
410
+ }
411
+ SFC.propTypes = {
412
+ foo: PropTypes.number.isRequired,
413
+ bar: PropTypes.string,
414
+ children: PropTypes.node,
415
+ };
416
+
417
+ // good
418
+ function SFC({ foo, bar, children }) {
419
+ return <div>{foo}{bar}{children}</div>;
420
+ }
421
+ SFC.propTypes = {
422
+ foo: PropTypes.number.isRequired,
423
+ bar: PropTypes.string,
424
+ children: PropTypes.node,
425
+ };
426
+ SFC.defaultProps = {
427
+ bar: '',
428
+ children: null,
429
+ };
430
+ ```
431
+
432
+ - Use spread props sparingly.
433
+ > Why? Otherwise you’re more likely to pass unnecessary props down to components. And for React v15.6.1 and older, you could [pass invalid HTML attributes to the DOM](https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html).
434
+
435
+ Exceptions:
436
+
437
+ - HOCs that proxy down props and hoist propTypes
438
+
439
+ ```jsx static
440
+ function HOC(WrappedComponent) {
441
+ return class Proxy extends React.Component {
442
+ Proxy.propTypes = {
443
+ text: PropTypes.string,
444
+ isLoading: PropTypes.bool
445
+ };
446
+
447
+ render() {
448
+ return <WrappedComponent {...this.props} />
449
+ }
450
+ }
451
+ }
452
+ ```
453
+
454
+ - Spreading objects with known, explicit props. This can be particularly useful when testing React components with Mocha’s beforeEach construct.
455
+
456
+ ```jsx static
457
+ export default function Foo {
458
+ const props = {
459
+ text: '',
460
+ isPublished: false
461
+ }
462
+
463
+ return (<div {...props} />);
464
+ }
465
+ ```
466
+
467
+ Notes for use:
468
+ Filter out unnecessary props when possible. Also, use [prop-types-exact](https://www.npmjs.com/package/prop-types-exact) to help prevent bugs.
469
+
470
+ ```jsx static
471
+ // bad
472
+ render() {
473
+ const { irrelevantProp, ...relevantProps } = this.props;
474
+ return <WrappedComponent {...this.props} />
475
+ }
476
+
477
+ // good
478
+ render() {
479
+ const { irrelevantProp, ...relevantProps } = this.props;
480
+ return <WrappedComponent {...relevantProps} />
481
+ }
482
+ ```
483
+
484
+ ## Refs
485
+
486
+ - Always use ref callbacks. eslint: [`react/no-string-refs`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md)
487
+
488
+ ```jsx static
489
+ // bad
490
+ <Foo
491
+ ref="myRef"
492
+ />
493
+
494
+ // good
495
+ <Foo
496
+ ref={(ref) => { this.myRef = ref; }}
497
+ />
498
+ ```
499
+
500
+ ## Parentheses
501
+
502
+ - Wrap JSX tags in parentheses when they span more than one line. eslint: [`react/jsx-wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md)
503
+
504
+ ```jsx static
505
+ // bad
506
+ render() {
507
+ return <MyComponent variant="long body" foo="bar">
508
+ <MyChild />
509
+ </MyComponent>;
510
+ }
511
+
512
+ // good
513
+ render() {
514
+ return (
515
+ <MyComponent variant="long body" foo="bar">
516
+ <MyChild />
517
+ </MyComponent>
518
+ );
519
+ }
520
+
521
+ // good, when single line
522
+ render() {
523
+ const body = <div>hello</div>;
524
+ return <MyComponent>{body}</MyComponent>;
525
+ }
526
+ ```
527
+
528
+ ## Tags
529
+
530
+ - Always self-close tags that have no children. eslint: [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md)
531
+
532
+ ```jsx static
533
+ // bad
534
+ <Foo variant="stuff"></Foo>
535
+
536
+ // good
537
+ <Foo variant="stuff" />
538
+ ```
539
+
540
+ - If your component has multiline properties, close its tag on a new line. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md)
541
+
542
+ ```jsx static
543
+ // bad
544
+ <Foo
545
+ bar="bar"
546
+ baz="baz" />
547
+
548
+ // good
549
+ <Foo
550
+ bar="bar"
551
+ baz="baz"
552
+ />
553
+ ```
554
+
555
+ ## Methods
556
+
557
+ - Use arrow functions to close over local variables. It is handy when you need to pass additional data to an event handler. Although, make sure they [do not massively hurt performance](https://www.bignerdranch.com/blog/choosing-the-best-approach-for-react-event-handlers/), in particular when passed to custom components that might be PureComponents, because they will trigger a possibly needless rerender every time.
558
+
559
+ ```jsx static
560
+ function ItemList(props) {
561
+ return (
562
+ <ul>
563
+ {props.items.map((item, index) => (
564
+ <Item
565
+ key={item.key}
566
+ onClick={(event) => { doSomethingWith(event, item.name, index); }}
567
+ />
568
+ ))}
569
+ </ul>
570
+ );
571
+ }
572
+ ```
573
+
574
+ - Bind event handlers for the render method in the constructor. eslint: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md)
575
+
576
+ > Why? A bind call in the render path creates a brand new function on every single render. Do not use arrow functions in class fields, because it makes them [challenging to test and debug, and can negatively impact performance](https://medium.com/@charpeni/arrow-functions-in-class-properties-might-not-be-as-great-as-we-think-3b3551c440b1), and because conceptually, class fields are for data, not logic.
577
+
578
+ ```jsx static
579
+ // bad
580
+ class extends React.Component {
581
+ onClickDiv() {
582
+ // do stuff
583
+ }
584
+
585
+ render() {
586
+ return <div onClick={this.onClickDiv.bind(this)} />;
587
+ }
588
+ }
589
+
590
+ // very bad
591
+ class extends React.Component {
592
+ onClickDiv = () => {
593
+ // do stuff
594
+ }
595
+
596
+ render() {
597
+ return <div onClick={this.onClickDiv} />
598
+ }
599
+ }
600
+
601
+ // good
602
+ class extends React.Component {
603
+ constructor(props) {
604
+ super(props);
605
+
606
+ this.onClickDiv = this.onClickDiv.bind(this);
607
+ }
608
+
609
+ onClickDiv() {
610
+ // do stuff
611
+ }
612
+
613
+ render() {
614
+ return <div onClick={this.onClickDiv} />;
615
+ }
616
+ }
617
+ ```
618
+
619
+ - Do not use underscore prefix for internal methods of a React component.
620
+ > Why? Underscore prefixes are sometimes used as a convention in other languages to denote privacy. But, unlike those languages, there is no native support for privacy in JavaScript, everything is public. Regardless of your intentions, adding underscore prefixes to your properties does not actually make them private, and any property (underscore-prefixed or not) should be treated as being public. See issues [#1024](https://github.com/airbnb/javascript/issues/1024), and [#490](https://github.com/airbnb/javascript/issues/490) for a more in-depth discussion.
621
+
622
+ ```jsx static
623
+ // bad
624
+ React.createClass({
625
+ _onClickSubmit() {
626
+ // do stuff
627
+ },
628
+
629
+ // other stuff
630
+ });
631
+
632
+ // good
633
+ class extends React.Component {
634
+ onClickSubmit() {
635
+ // do stuff
636
+ }
637
+
638
+ // other stuff
639
+ }
640
+ ```
641
+
642
+ - Be sure to return a value in your `render` methods. eslint: [`react/require-render-return`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md)
643
+
644
+ ```jsx static
645
+ // bad
646
+ render() {
647
+ (<div />);
648
+ }
649
+
650
+ // good
651
+ render() {
652
+ return (<div />);
653
+ }
654
+ ```
655
+
656
+ ## Ordering
657
+
658
+ - Ordering for `class extends React.Component`:
659
+
660
+ 1. optional `static` methods
661
+ 1. `constructor`
662
+ 1. `getChildContext`
663
+ 1. `componentWillMount`
664
+ 1. `componentDidMount`
665
+ 1. `componentWillReceiveProps`
666
+ 1. `shouldComponentUpdate`
667
+ 1. `componentWillUpdate`
668
+ 1. `componentDidUpdate`
669
+ 1. `componentWillUnmount`
670
+ 1. *event handlers starting with 'handle'* like `handleSubmit()` or `handleChangeDescription()`
671
+ 1. *event handlers starting with 'on'* like `onClickSubmit()` or `onChangeDescription()`
672
+ 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
673
+ 1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
674
+ 1. `render`
675
+
676
+ - How to define `propTypes`, `defaultProps`, `contextTypes`, etc...
677
+
678
+ ```jsx static
679
+ import React from 'react';
680
+ import PropTypes from 'prop-types';
681
+
682
+ const propTypes = {
683
+ id: PropTypes.number.isRequired,
684
+ url: PropTypes.string.isRequired,
685
+ text: PropTypes.string,
686
+ };
687
+
688
+ const defaultProps = {
689
+ text: 'Hello World',
690
+ };
691
+
692
+ class Link extends React.Component {
693
+ static methodsAreOk() {
694
+ return true;
695
+ }
696
+
697
+ render() {
698
+ return <a href={this.props.url} data-id={this.props.id}>{this.props.text}</a>;
699
+ }
700
+ }
701
+
702
+ Link.propTypes = propTypes;
703
+ Link.defaultProps = defaultProps;
704
+
705
+ export default Link;
706
+ ```
707
+
708
+ - Ordering for `React.createClass`: eslint: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md)
709
+
710
+ 1. `displayName`
711
+ 1. `propTypes`
712
+ 1. `contextTypes`
713
+ 1. `childContextTypes`
714
+ 1. `mixins`
715
+ 1. `statics`
716
+ 1. `defaultProps`
717
+ 1. `getDefaultProps`
718
+ 1. `getInitialState`
719
+ 1. `getChildContext`
720
+ 1. `componentWillMount`
721
+ 1. `componentDidMount`
722
+ 1. `componentWillReceiveProps`
723
+ 1. `shouldComponentUpdate`
724
+ 1. `componentWillUpdate`
725
+ 1. `componentDidUpdate`
726
+ 1. `componentWillUnmount`
727
+ 1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()`
728
+ 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
729
+ 1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
730
+ 1. `render`
731
+
732
+ ## `isMounted`
733
+
734
+ - Do not use `isMounted`. eslint: [`react/no-is-mounted`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md)
735
+
736
+ > Why? [`isMounted` is an anti-pattern][anti-pattern], is not available when using ES6 classes, and is on its way to being officially deprecated.
737
+
738
+ [anti-pattern]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html
739
+
740
+ <!-- ## Translation
741
+
742
+ This JSX/React style guide is also available in other languages:
743
+
744
+ - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese (Simplified)**: [jhcccc/javascript](https://github.com/jhcccc/javascript/tree/master/react)
745
+ - ![tw](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png) **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript/tree/master/react)
746
+ - ![es](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png) **Español**: [agrcrobles/javascript](https://github.com/agrcrobles/javascript/tree/master/react)
747
+ - ![jp](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png) **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide/tree/master/react)
748
+ - ![kr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png) **Korean**: [apple77y/javascript](https://github.com/apple77y/javascript/tree/master/react)
749
+ - ![pl](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Poland.png) **Polish**: [pietraszekl/javascript](https://github.com/pietraszekl/javascript/tree/master/react)
750
+ - ![Br](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png) **Portuguese**: [ronal2do/javascript](https://github.com/ronal2do/airbnb-react-styleguide)
751
+ - ![ru](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png) **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb/tree/master/react)
752
+ - ![th](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Thailand.png) **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide/tree/master/react)
753
+ - ![tr](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png) **Turkish**: [alioguzhan/react-style-guide](https://github.com/alioguzhan/react-style-guide)
754
+ - ![ua](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png) **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript/tree/master/react)
755
+ - ![vn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnam**: [uetcodecamp/jsx-style-guide](https://github.com/UETCodeCamp/jsx-style-guide) -->
756
+
757
757
  **[⬆ back to top](#table-of-contents)**