@nectary/components 2.9.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (447) hide show
  1. package/accordion/index.d.ts +11 -0
  2. package/accordion/index.js +86 -0
  3. package/accordion/types.d.ts +21 -0
  4. package/accordion/types.js +1 -0
  5. package/accordion-item/index.d.ts +14 -0
  6. package/accordion-item/index.js +95 -0
  7. package/accordion-item/types.d.ts +36 -0
  8. package/accordion-item/types.js +1 -0
  9. package/accordion-item/utils.d.ts +2 -0
  10. package/accordion-item/utils.js +1 -0
  11. package/action-menu/index.d.ts +11 -0
  12. package/action-menu/index.js +195 -0
  13. package/action-menu/types.d.ts +13 -0
  14. package/action-menu/types.js +1 -0
  15. package/action-menu-option/index.d.ts +12 -0
  16. package/action-menu-option/index.js +82 -0
  17. package/action-menu-option/types.d.ts +23 -0
  18. package/action-menu-option/types.js +1 -0
  19. package/action-menu-option/utils.d.ts +2 -0
  20. package/action-menu-option/utils.js +3 -0
  21. package/alert/index.d.ts +14 -0
  22. package/alert/index.js +48 -0
  23. package/alert/types.d.ts +18 -0
  24. package/alert/types.js +1 -0
  25. package/alert/utils.d.ts +2 -0
  26. package/alert/utils.js +1 -0
  27. package/avatar/index.d.ts +11 -0
  28. package/avatar/index.js +94 -0
  29. package/avatar/types.d.ts +37 -0
  30. package/avatar/types.js +1 -0
  31. package/avatar/utils.d.ts +4 -0
  32. package/avatar/utils.js +7 -0
  33. package/badge/index.d.ts +11 -0
  34. package/badge/index.js +114 -0
  35. package/badge/types.d.ts +34 -0
  36. package/badge/types.js +1 -0
  37. package/badge/utils.d.ts +2 -0
  38. package/badge/utils.js +1 -0
  39. package/button/index.d.ts +11 -0
  40. package/button/index.js +182 -0
  41. package/button/types.d.ts +53 -0
  42. package/button/types.js +1 -0
  43. package/button/utils.d.ts +2 -0
  44. package/button/utils.js +1 -0
  45. package/card/index.d.ts +13 -0
  46. package/card/index.js +133 -0
  47. package/card/types.d.ts +28 -0
  48. package/card/types.js +1 -0
  49. package/card-container/index.d.ts +11 -0
  50. package/card-container/index.js +11 -0
  51. package/card-container/types.d.ts +3 -0
  52. package/card-container/types.js +1 -0
  53. package/chat/index.d.ts +11 -0
  54. package/chat/index.js +11 -0
  55. package/chat/types.d.ts +3 -0
  56. package/chat/types.js +1 -0
  57. package/chat-block/index.d.ts +11 -0
  58. package/chat-block/index.js +86 -0
  59. package/chat-block/types.d.ts +30 -0
  60. package/chat-block/types.js +1 -0
  61. package/chat-bubble/index.d.ts +11 -0
  62. package/chat-bubble/index.js +41 -0
  63. package/chat-bubble/types.d.ts +20 -0
  64. package/chat-bubble/types.js +1 -0
  65. package/chat-bubble/utils.d.ts +3 -0
  66. package/chat-bubble/utils.js +2 -0
  67. package/checkbox/index.d.ts +11 -0
  68. package/checkbox/index.js +126 -0
  69. package/checkbox/types.d.ts +49 -0
  70. package/checkbox/types.js +1 -0
  71. package/chip/index.d.ts +13 -0
  72. package/chip/index.js +144 -0
  73. package/chip/types.d.ts +37 -0
  74. package/chip/types.js +1 -0
  75. package/chip/utils.d.ts +2 -0
  76. package/chip/utils.js +6 -0
  77. package/code-tag/index.d.ts +11 -0
  78. package/code-tag/index.js +31 -0
  79. package/code-tag/types.d.ts +11 -0
  80. package/code-tag/types.js +1 -0
  81. package/color-menu/index.d.ts +11 -0
  82. package/color-menu/index.js +308 -0
  83. package/color-menu/types.d.ts +32 -0
  84. package/color-menu/types.js +1 -0
  85. package/color-menu/utils.d.ts +1 -0
  86. package/color-menu/utils.js +11 -0
  87. package/color-menu-option/index.d.ts +13 -0
  88. package/color-menu-option/index.js +48 -0
  89. package/color-menu-option/types.d.ts +11 -0
  90. package/color-menu-option/types.js +1 -0
  91. package/color-menu-option/utils.d.ts +1 -0
  92. package/color-menu-option/utils.js +11 -0
  93. package/color-swatch/index.d.ts +12 -0
  94. package/color-swatch/index.js +54 -0
  95. package/color-swatch/types.d.ts +11 -0
  96. package/color-swatch/types.js +1 -0
  97. package/color-swatch/utils.d.ts +2 -0
  98. package/color-swatch/utils.js +6 -0
  99. package/date-picker/index.d.ts +14 -0
  100. package/date-picker/index.js +381 -0
  101. package/date-picker/types.d.ts +70 -0
  102. package/date-picker/types.js +1 -0
  103. package/date-picker/utils.d.ts +28 -0
  104. package/date-picker/utils.js +142 -0
  105. package/dialog/index.d.ts +15 -0
  106. package/dialog/index.js +144 -0
  107. package/dialog/types.d.ts +28 -0
  108. package/dialog/types.js +1 -0
  109. package/dialog/utils.d.ts +2 -0
  110. package/dialog/utils.js +18 -0
  111. package/emoji/index.d.ts +11 -0
  112. package/emoji/index.js +46 -0
  113. package/emoji/types.d.ts +11 -0
  114. package/emoji/types.js +1 -0
  115. package/emoji/utils.d.ts +3 -0
  116. package/emoji/utils.js +47 -0
  117. package/emoji-picker/index.d.ts +22 -0
  118. package/emoji-picker/index.js +308 -0
  119. package/emoji-picker/types.d.ts +26 -0
  120. package/emoji-picker/types.js +1 -0
  121. package/field/index.d.ts +11 -0
  122. package/field/index.js +120 -0
  123. package/field/types.d.ts +35 -0
  124. package/field/types.js +1 -0
  125. package/file-drop/index.d.ts +13 -0
  126. package/file-drop/index.js +205 -0
  127. package/file-drop/types.d.ts +50 -0
  128. package/file-drop/types.js +1 -0
  129. package/file-drop/utils.d.ts +2 -0
  130. package/file-drop/utils.js +31 -0
  131. package/file-picker/index.d.ts +11 -0
  132. package/file-picker/index.js +103 -0
  133. package/file-picker/types.d.ts +32 -0
  134. package/file-picker/types.js +1 -0
  135. package/file-picker/utils.d.ts +1 -0
  136. package/file-picker/utils.js +8 -0
  137. package/file-status/index.d.ts +14 -0
  138. package/file-status/index.js +61 -0
  139. package/file-status/types.d.ts +18 -0
  140. package/file-status/types.js +1 -0
  141. package/file-status/utils.d.ts +2 -0
  142. package/file-status/utils.js +1 -0
  143. package/flag/index.d.ts +11 -0
  144. package/flag/index.js +46 -0
  145. package/flag/types.d.ts +11 -0
  146. package/flag/types.js +1 -0
  147. package/flag/utils.d.ts +1 -0
  148. package/flag/utils.js +17 -0
  149. package/grid/index.d.ts +11 -0
  150. package/grid/index.js +11 -0
  151. package/grid/types.d.ts +3 -0
  152. package/grid/types.js +1 -0
  153. package/grid-item/index.d.ts +11 -0
  154. package/grid-item/index.js +35 -0
  155. package/grid-item/types.d.ts +17 -0
  156. package/grid-item/types.js +1 -0
  157. package/help-tooltip/index.d.ts +13 -0
  158. package/help-tooltip/index.js +74 -0
  159. package/help-tooltip/types.d.ts +3 -0
  160. package/help-tooltip/types.js +1 -0
  161. package/horizontal-stepper/index.d.ts +11 -0
  162. package/horizontal-stepper/index.js +61 -0
  163. package/horizontal-stepper/types.d.ts +13 -0
  164. package/horizontal-stepper/types.js +1 -0
  165. package/horizontal-stepper-item/index.d.ts +14 -0
  166. package/horizontal-stepper-item/index.js +61 -0
  167. package/horizontal-stepper-item/types.d.ts +24 -0
  168. package/horizontal-stepper-item/types.js +1 -0
  169. package/horizontal-stepper-item/utils.d.ts +2 -0
  170. package/horizontal-stepper-item/utils.js +1 -0
  171. package/icon/index.d.ts +11 -0
  172. package/icon/index.js +32 -0
  173. package/icon/types.d.ts +11 -0
  174. package/icon/types.js +1 -0
  175. package/icon-button/index.d.ts +12 -0
  176. package/icon-button/index.js +175 -0
  177. package/icon-button/types.d.ts +44 -0
  178. package/icon-button/types.js +1 -0
  179. package/icon-button/utils.d.ts +2 -0
  180. package/icon-button/utils.js +1 -0
  181. package/inline-alert/index.d.ts +15 -0
  182. package/inline-alert/index.js +83 -0
  183. package/inline-alert/types.d.ts +15 -0
  184. package/inline-alert/types.js +1 -0
  185. package/inline-alert/utils.d.ts +2 -0
  186. package/inline-alert/utils.js +1 -0
  187. package/input/index.d.ts +11 -0
  188. package/input/index.js +642 -0
  189. package/input/types.d.ts +86 -0
  190. package/input/types.js +1 -0
  191. package/input/utils.d.ts +26 -0
  192. package/input/utils.js +302 -0
  193. package/link/index.d.ts +12 -0
  194. package/link/index.js +150 -0
  195. package/link/types.d.ts +59 -0
  196. package/link/types.js +1 -0
  197. package/list/index.d.ts +11 -0
  198. package/list/index.js +14 -0
  199. package/list/types.d.ts +3 -0
  200. package/list/types.js +1 -0
  201. package/list-item/index.d.ts +11 -0
  202. package/list-item/index.js +14 -0
  203. package/list-item/types.d.ts +3 -0
  204. package/list-item/types.js +1 -0
  205. package/package.json +1 -1
  206. package/pagination/index.d.ts +12 -0
  207. package/pagination/index.js +147 -0
  208. package/pagination/types.d.ts +16 -0
  209. package/pagination/types.js +1 -0
  210. package/pop/index.d.ts +11 -0
  211. package/pop/index.js +425 -0
  212. package/pop/types.d.ts +35 -0
  213. package/pop/types.js +1 -0
  214. package/pop/utils.d.ts +4 -0
  215. package/pop/utils.js +16 -0
  216. package/popover/index.d.ts +12 -0
  217. package/popover/index.js +146 -0
  218. package/popover/types.d.ts +38 -0
  219. package/popover/types.js +1 -0
  220. package/popover/utils.d.ts +4 -0
  221. package/popover/utils.js +10 -0
  222. package/progress/index.d.ts +12 -0
  223. package/progress/index.js +58 -0
  224. package/progress/types.d.ts +12 -0
  225. package/progress/types.js +1 -0
  226. package/progress-stepper/index.d.ts +11 -0
  227. package/progress-stepper/index.js +206 -0
  228. package/progress-stepper/types.d.ts +22 -0
  229. package/progress-stepper/types.js +1 -0
  230. package/progress-stepper-item/index.d.ts +12 -0
  231. package/progress-stepper-item/index.js +82 -0
  232. package/progress-stepper-item/types.d.ts +23 -0
  233. package/progress-stepper-item/types.js +1 -0
  234. package/progress-stepper-item/utils.d.ts +11 -0
  235. package/progress-stepper-item/utils.js +13 -0
  236. package/radio/index.d.ts +11 -0
  237. package/radio/index.js +154 -0
  238. package/radio/types.d.ts +14 -0
  239. package/radio/types.js +1 -0
  240. package/radio-option/index.d.ts +11 -0
  241. package/radio-option/index.js +79 -0
  242. package/radio-option/types.d.ts +18 -0
  243. package/radio-option/types.js +1 -0
  244. package/rich-text/index.d.ts +14 -0
  245. package/rich-text/index.js +75 -0
  246. package/rich-text/types.d.ts +12 -0
  247. package/rich-text/types.js +1 -0
  248. package/rich-text/utils.d.ts +7 -0
  249. package/rich-text/utils.js +107 -0
  250. package/rich-textarea/index.d.ts +11 -0
  251. package/rich-textarea/index.js +464 -0
  252. package/rich-textarea/types.d.ts +48 -0
  253. package/rich-textarea/types.js +1 -0
  254. package/rich-textarea/utils.d.ts +39 -0
  255. package/rich-textarea/utils.js +1730 -0
  256. package/segment/index.d.ts +12 -0
  257. package/segment/index.js +109 -0
  258. package/segment/types.d.ts +16 -0
  259. package/segment/types.js +1 -0
  260. package/segment/utils.d.ts +3 -0
  261. package/segment/utils.js +16 -0
  262. package/segment-collapse/index.d.ts +13 -0
  263. package/segment-collapse/index.js +60 -0
  264. package/segment-collapse/types.d.ts +11 -0
  265. package/segment-collapse/types.js +1 -0
  266. package/segmented-control/index.d.ts +11 -0
  267. package/segmented-control/index.js +85 -0
  268. package/segmented-control/types.d.ts +11 -0
  269. package/segmented-control/types.js +1 -0
  270. package/segmented-control-option/index.d.ts +11 -0
  271. package/segmented-control-option/index.js +95 -0
  272. package/segmented-control-option/types.d.ts +19 -0
  273. package/segmented-control-option/types.js +1 -0
  274. package/segmented-icon-control/index.d.ts +11 -0
  275. package/segmented-icon-control/index.js +101 -0
  276. package/segmented-icon-control/types.d.ts +14 -0
  277. package/segmented-icon-control/types.js +1 -0
  278. package/segmented-icon-control-option/index.d.ts +11 -0
  279. package/segmented-icon-control-option/index.js +82 -0
  280. package/segmented-icon-control-option/types.d.ts +16 -0
  281. package/segmented-icon-control-option/types.js +1 -0
  282. package/select-button/index.d.ts +13 -0
  283. package/select-button/index.js +202 -0
  284. package/select-button/types.d.ts +50 -0
  285. package/select-button/types.js +1 -0
  286. package/select-menu/index.d.ts +15 -0
  287. package/select-menu/index.js +339 -0
  288. package/select-menu/types.d.ts +41 -0
  289. package/select-menu/types.js +1 -0
  290. package/select-menu-option/index.d.ts +28 -0
  291. package/select-menu-option/index.js +65 -0
  292. package/select-menu-option/types.d.ts +26 -0
  293. package/select-menu-option/types.js +1 -0
  294. package/skeleton/index.d.ts +11 -0
  295. package/skeleton/index.js +108 -0
  296. package/skeleton/types.d.ts +9 -0
  297. package/skeleton/types.js +1 -0
  298. package/skeleton-item/index.d.ts +11 -0
  299. package/skeleton-item/index.js +11 -0
  300. package/skeleton-item/types.d.ts +13 -0
  301. package/skeleton-item/types.js +1 -0
  302. package/spinner/index.d.ts +11 -0
  303. package/spinner/index.js +58 -0
  304. package/spinner/types.d.ts +12 -0
  305. package/spinner/types.js +1 -0
  306. package/standalone.d.ts +85 -0
  307. package/standalone.js +87 -0
  308. package/stop-events/index.d.ts +1 -0
  309. package/stop-events/index.js +27 -0
  310. package/table/index.d.ts +11 -0
  311. package/table/index.js +14 -0
  312. package/table/types.d.ts +3 -0
  313. package/table/types.js +1 -0
  314. package/table-body/index.d.ts +11 -0
  315. package/table-body/index.js +14 -0
  316. package/table-body/types.d.ts +3 -0
  317. package/table-body/types.js +1 -0
  318. package/table-cell/index.d.ts +11 -0
  319. package/table-cell/index.js +21 -0
  320. package/table-cell/types.d.ts +9 -0
  321. package/table-cell/types.js +1 -0
  322. package/table-cell/utils.d.ts +2 -0
  323. package/table-cell/utils.js +1 -0
  324. package/table-head/index.d.ts +11 -0
  325. package/table-head/index.js +14 -0
  326. package/table-head/types.d.ts +3 -0
  327. package/table-head/types.js +1 -0
  328. package/table-head-cell/index.d.ts +12 -0
  329. package/table-head-cell/index.js +57 -0
  330. package/table-head-cell/types.d.ts +15 -0
  331. package/table-head-cell/types.js +1 -0
  332. package/table-row/index.d.ts +11 -0
  333. package/table-row/index.js +42 -0
  334. package/table-row/types.d.ts +11 -0
  335. package/table-row/types.js +1 -0
  336. package/tabs/index.d.ts +11 -0
  337. package/tabs/index.js +80 -0
  338. package/tabs/types.d.ts +18 -0
  339. package/tabs/types.js +1 -0
  340. package/tabs-icon-option/index.d.ts +11 -0
  341. package/tabs-icon-option/index.js +79 -0
  342. package/tabs-icon-option/types.d.ts +19 -0
  343. package/tabs-icon-option/types.js +1 -0
  344. package/tabs-option/index.d.ts +12 -0
  345. package/tabs-option/index.js +86 -0
  346. package/tabs-option/types.d.ts +25 -0
  347. package/tabs-option/types.js +1 -0
  348. package/tag/index.d.ts +12 -0
  349. package/tag/index.js +84 -0
  350. package/tag/types.d.ts +23 -0
  351. package/tag/types.js +1 -0
  352. package/tag/utils.d.ts +2 -0
  353. package/tag/utils.js +6 -0
  354. package/text/index.d.ts +11 -0
  355. package/text/index.js +64 -0
  356. package/text/types.d.ts +30 -0
  357. package/text/types.js +1 -0
  358. package/text/utils.d.ts +2 -0
  359. package/text/utils.js +1 -0
  360. package/textarea/index.d.ts +11 -0
  361. package/textarea/index.js +322 -0
  362. package/textarea/types.d.ts +60 -0
  363. package/textarea/types.js +1 -0
  364. package/tile-control/index.d.ts +11 -0
  365. package/tile-control/index.js +110 -0
  366. package/tile-control/types.d.ts +37 -0
  367. package/tile-control/types.js +1 -0
  368. package/tile-control-option/index.d.ts +11 -0
  369. package/tile-control-option/index.js +98 -0
  370. package/tile-control-option/types.d.ts +37 -0
  371. package/tile-control-option/types.js +1 -0
  372. package/time-picker/index.d.ts +15 -0
  373. package/time-picker/index.js +337 -0
  374. package/time-picker/types.d.ts +34 -0
  375. package/time-picker/types.js +1 -0
  376. package/time-picker/utils.d.ts +11 -0
  377. package/time-picker/utils.js +75 -0
  378. package/title/index.d.ts +11 -0
  379. package/title/index.js +60 -0
  380. package/title/types.d.ts +31 -0
  381. package/title/types.js +1 -0
  382. package/title/utils.d.ts +3 -0
  383. package/title/utils.js +17 -0
  384. package/toast/index.d.ts +13 -0
  385. package/toast/index.js +86 -0
  386. package/toast/types.d.ts +28 -0
  387. package/toast/types.js +1 -0
  388. package/toast/utils.d.ts +2 -0
  389. package/toast/utils.js +1 -0
  390. package/toast-manager/index.d.ts +13 -0
  391. package/toast-manager/index.js +170 -0
  392. package/toast-manager/types.d.ts +13 -0
  393. package/toast-manager/types.js +1 -0
  394. package/toast-manager/utils.d.ts +2 -0
  395. package/toast-manager/utils.js +1 -0
  396. package/toggle/index.d.ts +11 -0
  397. package/toggle/index.js +141 -0
  398. package/toggle/types.d.ts +23 -0
  399. package/toggle/types.js +1 -0
  400. package/tooltip/index.d.ts +13 -0
  401. package/tooltip/index.js +275 -0
  402. package/tooltip/tooltip-state.d.ts +19 -0
  403. package/tooltip/tooltip-state.js +126 -0
  404. package/tooltip/types.d.ts +42 -0
  405. package/tooltip/types.js +1 -0
  406. package/tooltip/utils.d.ts +6 -0
  407. package/tooltip/utils.js +18 -0
  408. package/utils/context.d.ts +20 -0
  409. package/utils/context.js +84 -0
  410. package/utils/countries.d.ts +6 -0
  411. package/utils/countries.js +2 -0
  412. package/utils/csv.d.ts +5 -0
  413. package/utils/csv.js +22 -0
  414. package/utils/debounce.d.ts +8 -0
  415. package/utils/debounce.js +22 -0
  416. package/utils/dom.d.ts +34 -0
  417. package/utils/dom.js +154 -0
  418. package/utils/element.d.ts +16 -0
  419. package/utils/element.js +48 -0
  420. package/utils/event-target.d.ts +4 -0
  421. package/utils/event-target.js +26 -0
  422. package/utils/get-react-event-handler.d.ts +1 -0
  423. package/utils/get-react-event-handler.js +8 -0
  424. package/utils/index.d.ts +12 -0
  425. package/utils/index.js +12 -0
  426. package/utils/markdown.d.ts +19 -0
  427. package/utils/markdown.js +143 -0
  428. package/utils/rect.d.ts +4 -0
  429. package/utils/rect.js +28 -0
  430. package/utils/size.d.ts +5 -0
  431. package/utils/size.js +3 -0
  432. package/utils/slot.d.ts +4 -0
  433. package/utils/slot.js +38 -0
  434. package/utils/throttle.d.ts +4 -0
  435. package/utils/throttle.js +20 -0
  436. package/utils/uid.d.ts +1 -0
  437. package/utils/uid.js +13 -0
  438. package/vertical-stepper/index.d.ts +11 -0
  439. package/vertical-stepper/index.js +57 -0
  440. package/vertical-stepper/types.d.ts +13 -0
  441. package/vertical-stepper/types.js +1 -0
  442. package/vertical-stepper-item/index.d.ts +14 -0
  443. package/vertical-stepper-item/index.js +61 -0
  444. package/vertical-stepper-item/types.d.ts +24 -0
  445. package/vertical-stepper-item/types.js +1 -0
  446. package/vertical-stepper-item/utils.d.ts +2 -0
  447. package/vertical-stepper-item/utils.js +1 -0
@@ -0,0 +1,37 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ export type TSinchTileControlOptionElement = HTMLElement & {
3
+ /** Value */
4
+ value: string;
5
+ /** Text content */
6
+ text: string;
7
+ /** Disabled */
8
+ disabled: boolean;
9
+ /** Small */
10
+ small: boolean;
11
+ /** Focus event */
12
+ addEventListener(type: '-focus', listener: (e: CustomEvent<void>) => void): void;
13
+ /** Blur event */
14
+ addEventListener(type: '-blur', listener: (e: CustomEvent<void>) => void): void;
15
+ /** Value */
16
+ setAttribute(name: 'value', value: string): void;
17
+ /** Text content */
18
+ setAttribute(attr: 'text', value: string): void;
19
+ /** Disabled */
20
+ setAttribute(name: 'disabled', value: ''): void;
21
+ /** Small */
22
+ setAttribute(name: 'small', value: ''): void;
23
+ };
24
+ export type TSinchTileControlOptionReact = TSinchElementReact<TSinchTileControlOptionElement> & {
25
+ /** Value */
26
+ value: string;
27
+ /** Text content */
28
+ text: string;
29
+ /** Label that is used for a11y */
30
+ 'aria-label': string;
31
+ /** Disabled */
32
+ disabled?: boolean;
33
+ /** Focus handler */
34
+ 'on-focus'?: (e: CustomEvent<void>) => void;
35
+ /** Blur handler */
36
+ 'on-blur'?: (e: CustomEvent<void>) => void;
37
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import '../icon-button';
2
+ import '../icon';
3
+ import '../segmented-control';
4
+ import '../segmented-control-option';
5
+ import type { TSinchTimePickerElement, TSinchTimePickerReact } from './types';
6
+ declare global {
7
+ namespace JSX {
8
+ interface IntrinsicElements {
9
+ 'sinch-time-picker': TSinchTimePickerReact;
10
+ }
11
+ }
12
+ interface HTMLElementTagNameMap {
13
+ 'sinch-time-picker': TSinchTimePickerElement;
14
+ }
15
+ }
@@ -0,0 +1,337 @@
1
+ import '../icon-button';
2
+ import '../icon';
3
+ import '../segmented-control';
4
+ import '../segmented-control-option';
5
+ import { defineCustomElement, getAttribute, getBooleanAttribute, getReactEventHandler, getRect, isAttrEqual, isAttrTrue, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
6
+ const templateHTML = '<style>:host{display:block;outline:0}#wrapper{display:flex;flex-direction:column;width:248px;padding:16px;box-sizing:border-box;gap:16px}#header{position:relative;width:100%;height:48px;font:var(--sinch-comp-time-picker-header-font);line-height:48px;user-select:none;color:var(--sinch-comp-time-picker-header-color-default-text-initial)}#footer{display:flex;justify-content:center;width:100%;height:32px}#picker{position:relative;width:216px;height:216px;border-radius:50%;box-sizing:border-box;border:1px solid var(--sinch-comp-time-picker-watch-face-color-default-border-initial);background-color:var(--sinch-comp-time-picker-watch-face-color-default-background-initial)}#picker-hours,#picker-minutes{position:absolute;left:0;top:0;width:100%;height:100%;border-radius:50%;pointer-events:none;user-select:none}.digit-hour-12,.digit-hour-24,.digit-minute{position:absolute;width:28px;height:28px;text-align:center;top:calc(50% - 14px);left:calc(50% - 14px);z-index:1;cursor:pointer}.digit-hour-12{font:var(--sinch-comp-time-picker-digit-font-default-h12);color:var(--sinch-comp-time-picker-digit-color-default-h12-initial);line-height:28px}.digit-hour-12.selected{font:var(--sinch-comp-time-picker-digit-font-checked-h12);color:var(--sinch-comp-time-picker-digit-color-checked-h12-default)}.digit-hour-24{font:var(--sinch-comp-time-picker-digit-font-default-h24);color:var(--sinch-comp-time-picker-digit-color-default-h24-initial);line-height:28px}.digit-hour-24.selected{font:var(--sinch-comp-time-picker-digit-font-checked-h24);color:var(--sinch-comp-time-picker-digit-color-checked-h24-initial)}.digit-minute{font:var(--sinch-comp-time-picker-digit-font-default-minutes);color:var(--sinch-comp-time-picker-digit-color-default-minute-initial);line-height:28px}.digit-minute.selected{font:var(--sinch-comp-time-picker-digit-font-checked-minutes);color:var(--sinch-comp-time-picker-digit-color-checked-minute-initial)}#picker-touch{position:absolute;left:0;top:0;width:100%;height:100%;cursor:pointer;border-radius:50%}#needle-hour,#needle-minute,#picker-touch::after{background-color:var(--sinch-comp-time-picker-needle-color-default-background-initial)}#needle-hour,#needle-minute{position:absolute;transform-origin:bottom center;transform:rotate(0);bottom:50%;height:50px;transition-duration:.25s;transition-timing-function:ease-in-out;transition-property:transform height;z-index:2;outline:0}@media (prefers-reduced-motion){#needle-hour,#needle-minute{transition:none}}#needle-hour{width:4px;left:calc(50% - 2px);border-radius:2px}#needle-minute{width:2px;left:calc(50% - 1px);border-radius:1px}#needle-hour:focus-visible,#needle-minute:focus-visible{background-color:var(--sinch-comp-time-picker-needle-color-default-background-focus)}#needle-minute:not(.selected)::after{content:"";position:absolute;transform:translateX(-50%);left:0;top:-16px;width:4px;height:4px;border-radius:50%;background-color:var(--sinch-comp-time-picker-digit-color-checked-minute-initial)}#picker-touch::after{content:"";position:absolute;top:50%;left:50%;width:12px;height:12px;border-radius:50%;transform:translate(-50%,-50%)}#header-hours,#header-minutes{position:absolute;padding:0 4px;width:50px;outline:0}#header-hours{right:calc(50% + 8px);text-align:right}#header-minutes{left:calc(50% + 8px)}#header-colon{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%)}#submit{position:absolute;right:0;top:50%;transform:translateY(-50%)}#submit-icon{--sinch-global-color-icon:var(--sinch-comp-time-picker-header-color-default-icon-initial)}:host([ampm]) .digit-hour-24{display:none}:host(:not([ampm])) #footer{display:none}</style><div id="wrapper"><div id="header"><div id="header-hours" role="meter" aria-valuemin="0" aria-valuemax="23" aria-valuenow="0" aria-valuetext="0"><span>00</span></div><div id="header-colon">&colon;</div><div id="header-minutes" role="meter" aria-valuemin="0" aria-valuemax="59" aria-valuenow="0" aria-valuetext="0"><span>00</span></div><sinch-icon-button id="submit" size="s" aria-label="Submit"><sinch-icon id="icon-submit" slot="icon" name="done"></sinch-icon></sinch-icon-button></div><div id="picker" aria-hidden="true"><div id="picker-hours"></div><div id="picker-minutes"></div><div id="picker-touch"><div id="needle-hour" tabindex="0"></div><div id="needle-minute" tabindex="0"></div></div></div><div id="footer"><sinch-segmented-control id="ampm"><sinch-segmented-control-option value="am" text="AM" aria-label="AM"></sinch-segmented-control-option><sinch-segmented-control-option value="pm" text="PM" aria-label="PM"></sinch-segmented-control-option></sinch-segmented-control></div></div>';
7
+ import { getNeedleRotationDeg, getShortestCssDeg, hourToIndex, parseTime, stringifyHour, stringifyHourFace, stringifyMinute, stringifyTime } from './utils';
8
+ const template = document.createElement('template');
9
+ template.innerHTML = templateHTML;
10
+ const PICKER_RADIUS = 216 / 2;
11
+ const MINUTE_DIGIT_SIZE = 30;
12
+ const HOUR_12_DIGIT_SIZE = 26;
13
+ const HOUR_24_DIGIT_SIZE = 26;
14
+ const MINUTE_RADIUS = PICKER_RADIUS - MINUTE_DIGIT_SIZE;
15
+ const HOUR_12_RADIUS = MINUTE_RADIUS - HOUR_12_DIGIT_SIZE;
16
+ const HOUR_24_RADIUS = HOUR_12_RADIUS - HOUR_24_DIGIT_SIZE;
17
+ const NEEDLE_HOUR_12_LENGTH = HOUR_12_RADIUS;
18
+ const NEEDLE_HOUR_24_LENGTH = HOUR_24_RADIUS;
19
+ const NEEDLE_MINUTE_LENGTH = MINUTE_RADIUS;
20
+ defineCustomElement('sinch-time-picker', class extends NectaryElement {
21
+ #$pickerHours;
22
+ #$pickerMinutes;
23
+ #$pickerTouch;
24
+ #$needleHour;
25
+ #$needleMinute;
26
+ #$headerHours;
27
+ #$headerHoursText;
28
+ #$headerMinutes;
29
+ #$headerMinutesText;
30
+ #$ampm;
31
+ #$submitButton;
32
+ #hour = 0;
33
+ #minute = 0;
34
+ #controller = null;
35
+ constructor() {
36
+ super();
37
+ const shadowRoot = this.attachShadow();
38
+ shadowRoot.appendChild(template.content.cloneNode(true));
39
+ this.#$pickerHours = shadowRoot.querySelector('#picker-hours');
40
+ this.#$pickerMinutes = shadowRoot.querySelector('#picker-minutes');
41
+ this.#$pickerTouch = shadowRoot.querySelector('#picker');
42
+ this.#$needleHour = shadowRoot.querySelector('#needle-hour');
43
+ this.#$needleMinute = shadowRoot.querySelector('#needle-minute');
44
+ this.#$headerHours = shadowRoot.querySelector('#header-hours');
45
+ this.#$headerMinutes = shadowRoot.querySelector('#header-minutes');
46
+ this.#$headerHoursText = shadowRoot.querySelector('#header-hours > span');
47
+ this.#$headerMinutesText = shadowRoot.querySelector('#header-minutes > span');
48
+ this.#$ampm = shadowRoot.querySelector('#ampm');
49
+ this.#$submitButton = shadowRoot.querySelector('#submit');
50
+ this.#$needleMinute.style.height = `${NEEDLE_MINUTE_LENGTH}px`;
51
+ this.#$needleHour.style.height = `${NEEDLE_HOUR_12_LENGTH}px`;
52
+ const MINUTE_DIGIT_RADIUS = MINUTE_RADIUS + MINUTE_DIGIT_SIZE / 2;
53
+ const HOUR_12_DIGIT_RADIUS = HOUR_12_RADIUS + HOUR_12_DIGIT_SIZE / 2;
54
+ const HOUR_24_DIGIT_RADIUS = HOUR_24_RADIUS + HOUR_24_DIGIT_SIZE / 2;
55
+ const hours12Frag = document.createDocumentFragment();
56
+ for (let i = 0; i < 12; i++) {
57
+ const rad = Math.PI / 6 * (i - 3);
58
+ const el = document.createElement('div');
59
+ const x = Math.cos(rad) * HOUR_12_DIGIT_RADIUS;
60
+ const y = Math.sin(rad) * HOUR_12_DIGIT_RADIUS;
61
+ const hourDisplayValue = stringifyHourFace(i);
62
+ el.className = 'digit-hour-12';
63
+ el.style.transform = `translate(${x}px, ${y}px)`;
64
+ el.textContent = hourDisplayValue;
65
+ hours12Frag.appendChild(el);
66
+ }
67
+ this.#$pickerHours.appendChild(hours12Frag);
68
+ const hours24Frag = document.createDocumentFragment();
69
+ for (let i = 12; i < 24; i++) {
70
+ const rad = Math.PI / 6 * (i - 3);
71
+ const el = document.createElement('div');
72
+ const x = Math.cos(rad) * HOUR_24_DIGIT_RADIUS;
73
+ const y = Math.sin(rad) * HOUR_24_DIGIT_RADIUS;
74
+ const hourDisplayValue = stringifyHourFace(i);
75
+ el.className = 'digit-hour-24';
76
+ el.style.transform = `translate(${x}px, ${y}px)`;
77
+ el.textContent = hourDisplayValue;
78
+ hours24Frag.appendChild(el);
79
+ }
80
+ this.#$pickerHours.appendChild(hours24Frag);
81
+ const minutesFrag = document.createDocumentFragment();
82
+ for (let i = 0; i < 60; i += 5) {
83
+ const rad = Math.PI / 30 * (i - 15);
84
+ const el = document.createElement('div');
85
+ const x = Math.cos(rad) * MINUTE_DIGIT_RADIUS;
86
+ const y = Math.sin(rad) * MINUTE_DIGIT_RADIUS;
87
+ el.className = 'digit-minute';
88
+ el.style.transform = `translate(${x}px, ${y}px)`;
89
+ el.textContent = stringifyMinute(i);
90
+ minutesFrag.appendChild(el);
91
+ }
92
+ this.#$pickerMinutes.appendChild(minutesFrag);
93
+ }
94
+ connectedCallback() {
95
+ this.#controller = new AbortController();
96
+ const options = {
97
+ signal: this.#controller.signal
98
+ };
99
+ this.#$pickerTouch.addEventListener('click', this.#onPickerClick, options);
100
+ this.#$ampm.addEventListener('-change', this.#onAmPmChange, options);
101
+ this.#$submitButton.addEventListener('click', this.#onSubmitButtonClick, options);
102
+ this.#$needleHour.addEventListener('keydown', this.#onHoursKeydown, options);
103
+ this.#$needleMinute.addEventListener('keydown', this.#onMinutesKeydown, options);
104
+ this.addEventListener('-change', this.#onChangeReactHandler, options);
105
+ }
106
+ disconnectedCallback() {
107
+ this.#controller.abort();
108
+ this.#controller = null;
109
+ }
110
+ static get observedAttributes() {
111
+ return ['value', 'ampm', 'submit-aria-label'];
112
+ }
113
+ attributeChangedCallback(name, prevValue, newVal) {
114
+ if (isAttrEqual(prevValue, newVal)) {
115
+ return;
116
+ }
117
+ switch (name) {
118
+ case 'value':
119
+ {
120
+ const {
121
+ hours,
122
+ minutes
123
+ } = parseTime(newVal);
124
+ this.#hour = hours;
125
+ this.#minute = minutes;
126
+ this.#render();
127
+ break;
128
+ }
129
+ case 'ampm':
130
+ {
131
+ this.#render();
132
+ updateBooleanAttribute(this, 'ampm', isAttrTrue(newVal));
133
+ break;
134
+ }
135
+ case 'submit-aria-label':
136
+ {
137
+ updateAttribute(this.#$submitButton, 'aria-label', newVal);
138
+ break;
139
+ }
140
+ }
141
+ }
142
+ set value(value) {
143
+ updateAttribute(this, 'value', value);
144
+ }
145
+ get value() {
146
+ return getAttribute(this, 'value', '');
147
+ }
148
+ set ampm(value) {
149
+ updateBooleanAttribute(this, 'ampm', value);
150
+ }
151
+ get ampm() {
152
+ return getBooleanAttribute(this, 'ampm');
153
+ }
154
+ set submitAriaLabel(value) {
155
+ updateAttribute(this, 'submit-aria-label', value);
156
+ }
157
+ get submitAriaLabel() {
158
+ return getAttribute(this, 'submit-aria-label', '');
159
+ }
160
+ get submitButtonRect() {
161
+ return getRect(this.#$submitButton);
162
+ }
163
+ get amButtonRect() {
164
+ if (!this.ampm) {
165
+ return null;
166
+ }
167
+ const $am = this.#$ampm.querySelector('[value="am"]');
168
+ return $am != null ? getRect($am) : null;
169
+ }
170
+ get pmButtonRect() {
171
+ if (!this.ampm) {
172
+ return null;
173
+ }
174
+ const $pm = this.#$ampm.querySelector('[value="pm"]');
175
+ return $pm != null ? getRect($pm) : null;
176
+ }
177
+ hourDigitRect(hour) {
178
+ const $digit = this.#$pickerHours.children[hourToIndex(hour, !this.ampm)];
179
+ return $digit != null ? getRect($digit) : null;
180
+ }
181
+ minuteDigitRect(minute) {
182
+ const $digit = this.#$pickerMinutes.children[Math.round(minute / 5)];
183
+ return $digit != null ? getRect($digit) : null;
184
+ }
185
+ #getClickDegree(x, y) {
186
+ const touchRect = this.#$pickerTouch.getBoundingClientRect();
187
+ const cx = touchRect.width / 2;
188
+ const cy = touchRect.height / 2;
189
+ const px = x - touchRect.x;
190
+ const py = touchRect.height - y + touchRect.y;
191
+ const dx = px - cx;
192
+ const dy = py - cy;
193
+ const len = Math.sqrt(dx * dx + dy * dy);
194
+ const cosRad = dx / len;
195
+ const rad = Math.acos(cosRad * (dy < 0 ? -1 : 1));
196
+ const deg = rad * (180 / Math.PI);
197
+ let cssDeg = (deg - 90 - 360) % 360 * -1;
198
+ if (dy < 0) {
199
+ cssDeg += 180;
200
+ }
201
+ const rowIndex = len > MINUTE_RADIUS ? 0 : len > HOUR_12_RADIUS ? 1 : 2;
202
+ return [cssDeg, rowIndex];
203
+ }
204
+ #onPickerClick = e => {
205
+ const [cssDeg, rowIndex] = this.#getClickDegree(e.x, e.y);
206
+ const isHourRowClick = rowIndex > 0;
207
+ const isHour24RowClick = rowIndex > 1;
208
+ if (isHourRowClick) {
209
+ const digitIndex = Math.round(cssDeg / 30) % 12;
210
+ const is24 = getBooleanAttribute(this, 'ampm') === false;
211
+ if (is24) {
212
+ if (isHour24RowClick) {
213
+ this.#hour = digitIndex === 0 ? 0 : digitIndex + 12;
214
+ } else {
215
+ this.#hour = digitIndex === 0 ? 12 : digitIndex;
216
+ }
217
+ } else {
218
+ this.#hour = digitIndex + (this.#$ampm.value === 'pm' ? 12 : 0);
219
+ }
220
+ this.#$headerHours.focus();
221
+ } else {
222
+ this.#minute = Math.round(cssDeg / 6) % 60;
223
+ this.#$headerMinutes.focus();
224
+ }
225
+ this.#render();
226
+ };
227
+ #render() {
228
+ const is24 = getBooleanAttribute(this, 'ampm') === false;
229
+ this.#selectHour(is24);
230
+ this.#selectMinute();
231
+ this.#$headerHoursText.textContent = stringifyHour(this.#hour, is24);
232
+ this.#$headerMinutesText.textContent = stringifyMinute(this.#minute);
233
+ updateAttribute(this.#$headerHours, 'aria-valuenow', this.#hour);
234
+ updateAttribute(this.#$headerHours, 'aria-valuetext', this.#hour);
235
+ updateAttribute(this.#$headerMinutes, 'aria-valuenow', this.#minute);
236
+ updateAttribute(this.#$headerMinutes, 'aria-valuetext', this.#minute);
237
+ }
238
+ #selectHour(is24) {
239
+ const $hours = this.#$pickerHours.children;
240
+ const hourDigitIndex = this.#hour % 12;
241
+ const selectedIndex = hourToIndex(this.#hour, is24);
242
+ const currentCssDeg = getNeedleRotationDeg(this.#$needleHour);
243
+ const hourCssDeg = getShortestCssDeg(currentCssDeg, hourDigitIndex * 30);
244
+ for (let i = 0; i < $hours.length; i++) {
245
+ setClass($hours[i], 'selected', i === selectedIndex);
246
+ }
247
+ this.#$needleHour.style.transform = `rotate(${hourCssDeg}deg)`;
248
+ if (is24) {
249
+ if (this.#hour > 0 && this.#hour <= 12) {
250
+ this.#$needleHour.style.height = `${NEEDLE_HOUR_12_LENGTH}px`;
251
+ } else {
252
+ this.#$needleHour.style.height = `${NEEDLE_HOUR_24_LENGTH}px`;
253
+ }
254
+ } else {
255
+ this.#$needleHour.style.height = `${NEEDLE_HOUR_12_LENGTH}px`;
256
+ }
257
+ this.#$ampm.setAttribute('value', this.#hour >= 0 && this.#hour < 12 ? 'am' : 'pm');
258
+ }
259
+ #selectMinute() {
260
+ const $minutes = this.#$pickerMinutes.children;
261
+ const isNeedleSelected = this.#minute % 5 === 0;
262
+ const selectedIndex = this.#minute / 5;
263
+ const currentCssDeg = getNeedleRotationDeg(this.#$needleMinute);
264
+ const minuteCssDeg = getShortestCssDeg(currentCssDeg, this.#minute * 6);
265
+ for (let i = 0; i < $minutes.length; i++) {
266
+ setClass($minutes[i], 'selected', selectedIndex === i);
267
+ }
268
+ setClass(this.#$needleMinute, 'selected', isNeedleSelected);
269
+ this.#$needleMinute.style.transform = `rotate(${minuteCssDeg}deg)`;
270
+ }
271
+ #onAmPmChange = e => {
272
+ const value = e.detail;
273
+ switch (value) {
274
+ case 'am':
275
+ {
276
+ if (this.#hour >= 12) {
277
+ this.#hour -= 12;
278
+ this.#render();
279
+ }
280
+ break;
281
+ }
282
+ case 'pm':
283
+ {
284
+ if (this.#hour < 12) {
285
+ this.#hour += 12;
286
+ this.#render();
287
+ }
288
+ break;
289
+ }
290
+ }
291
+ };
292
+ #onSubmitButtonClick = () => {
293
+ const value = stringifyTime(this.#hour, this.#minute);
294
+ this.dispatchEvent(new CustomEvent('-change', {
295
+ detail: value
296
+ }));
297
+ };
298
+ #onHoursKeydown = e => {
299
+ switch (e.key) {
300
+ case 'ArrowUp':
301
+ {
302
+ e.preventDefault();
303
+ this.#hour = (this.#hour + 1) % 24;
304
+ this.#render();
305
+ break;
306
+ }
307
+ case 'ArrowDown':
308
+ {
309
+ e.preventDefault();
310
+ this.#hour = (this.#hour + 23) % 24;
311
+ this.#render();
312
+ break;
313
+ }
314
+ }
315
+ };
316
+ #onMinutesKeydown = e => {
317
+ switch (e.key) {
318
+ case 'ArrowUp':
319
+ {
320
+ e.preventDefault();
321
+ this.#minute = (this.#minute + 1) % 60;
322
+ this.#render();
323
+ break;
324
+ }
325
+ case 'ArrowDown':
326
+ {
327
+ e.preventDefault();
328
+ this.#minute = (this.#minute + 59) % 60;
329
+ this.#render();
330
+ break;
331
+ }
332
+ }
333
+ };
334
+ #onChangeReactHandler = e => {
335
+ getReactEventHandler(this, 'on-change')?.(e);
336
+ };
337
+ });
@@ -0,0 +1,34 @@
1
+ import type { TRect, TSinchElementReact } from '../types';
2
+ export type TSinchTimePickerElement = HTMLElement & {
3
+ /** Time value in ISO 8601 format */
4
+ value: string;
5
+ /** AM/PM 12-hour clock system, `false` by default */
6
+ ampm: boolean;
7
+ /** Submit button label that is used for a11y */
8
+ submitAriaLabel: string;
9
+ readonly submitButtonRect: TRect;
10
+ readonly amButtonRect: TRect | null;
11
+ readonly pmButtonRect: TRect | null;
12
+ hourDigitRect(hour: number): TRect | null;
13
+ minuteDigitRect(minute: number): TRect | null;
14
+ /** Change value handler, return time in ISO 8601 format */
15
+ addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
16
+ /** Time value in ISO 8601 format */
17
+ setAttribute(name: 'value', value: string): void;
18
+ /** AM/PM 12-hour clock system, `false` by default */
19
+ setAttribute(name: 'ampm', value: boolean): void;
20
+ /** Submit button label that is used for a11y */
21
+ setAttribute(name: 'submit-aria-label', value: string): void;
22
+ };
23
+ export type TSinchTimePickerReact = TSinchElementReact<TSinchTimePickerElement> & {
24
+ /** Time value in ISO 8601 format */
25
+ value: string;
26
+ /** AM/PM 12-hour clock system, `false` by default */
27
+ ampm?: boolean;
28
+ /** Label that is used for a11y */
29
+ 'aria-label': string;
30
+ /** Submit button label that is used for a11y */
31
+ 'submit-aria-label': string;
32
+ /** Change value handler, return time in ISO 8601 format */
33
+ 'on-change'?: (e: CustomEvent<string>) => void;
34
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export declare const parseTime: (value: string | null) => {
2
+ hours: number;
3
+ minutes: number;
4
+ };
5
+ export declare const stringifyTime: (hour: number, minute: number) => string;
6
+ export declare const stringifyHour: (hour: number, is24: boolean) => string;
7
+ export declare const stringifyHourFace: (hour: number) => string;
8
+ export declare const stringifyMinute: (minute: number) => string;
9
+ export declare const hourToIndex: (hour: number, is24: boolean) => number;
10
+ export declare const getNeedleRotationDeg: (elem: HTMLElement) => number;
11
+ export declare const getShortestCssDeg: (currentDeg: number, nextDeg: number) => number;
@@ -0,0 +1,75 @@
1
+ export const parseTime = value => {
2
+ if (value === '' || value === null) {
3
+ return {
4
+ hours: 0,
5
+ minutes: 0
6
+ };
7
+ }
8
+ const timeParts = value.split(':');
9
+ const hours = parseInt(timeParts[0] ?? '00');
10
+ const minutes = parseInt(timeParts[1] ?? '00');
11
+ if (isNaN(hours) || hours > 23 || hours < 0) {
12
+ return {
13
+ hours: 0,
14
+ minutes: 0
15
+ };
16
+ }
17
+ if (isNaN(minutes) || minutes > 59 || minutes < 0) {
18
+ return {
19
+ hours: 0,
20
+ minutes: 0
21
+ };
22
+ }
23
+ return {
24
+ hours,
25
+ minutes
26
+ };
27
+ };
28
+ const pad = value => {
29
+ return value.toString().padStart(2, '0');
30
+ };
31
+ export const stringifyTime = (hour, minute) => {
32
+ return `${pad(hour)}:${pad(minute)}:00`;
33
+ };
34
+ export const stringifyHour = (hour, is24) => {
35
+ if (is24) {
36
+ return pad(hour);
37
+ }
38
+ if (hour === 0 || hour === 12) {
39
+ return '12';
40
+ }
41
+ return pad(hour % 12);
42
+ };
43
+ export const stringifyHourFace = hour => {
44
+ return hour === 0 ? '12' : hour === 12 ? '24' : String(hour);
45
+ };
46
+ export const stringifyMinute = minute => {
47
+ return pad(minute);
48
+ };
49
+ export const hourToIndex = (hour, is24) => {
50
+ if (is24) {
51
+ if (hour === 0) {
52
+ return 12;
53
+ }
54
+ if (hour === 12) {
55
+ return 0;
56
+ }
57
+ return hour;
58
+ }
59
+ return hour % 12;
60
+ };
61
+ export const getNeedleRotationDeg = elem => {
62
+ const match = elem.style.transform.match(/^rotate\((-?\d+)deg\)$/);
63
+ if (match === null) {
64
+ return 0;
65
+ }
66
+ return Number(match[1]);
67
+ };
68
+ export const getShortestCssDeg = (currentDeg, nextDeg) => {
69
+ const angle = currentDeg % 360;
70
+ const diff = (360 - (angle - nextDeg)) % 360;
71
+ if (diff > 180) {
72
+ return currentDeg - 360 + diff;
73
+ }
74
+ return currentDeg + diff;
75
+ };
@@ -0,0 +1,11 @@
1
+ import type { TSinchTitleElement, TSinchTitleReact } from './types';
2
+ declare global {
3
+ namespace JSX {
4
+ interface IntrinsicElements {
5
+ 'sinch-title': TSinchTitleReact;
6
+ }
7
+ }
8
+ interface HTMLElementTagNameMap {
9
+ 'sinch-title': TSinchTitleElement;
10
+ }
11
+ }
package/title/index.js ADDED
@@ -0,0 +1,60 @@
1
+ import { defineCustomElement, getAttribute, updateAttribute, updateLiteralAttribute, getLiteralAttribute, NectaryElement, updateBooleanAttribute, getBooleanAttribute, isAttrTrue, isAttrEqual } from '../utils';
2
+ const templateHTML = '<style>:host{display:block;--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-m)}:host([type=xl]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-xl)}:host([type="l"]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-l)}:host([type="m"]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-m)}:host([type="s"]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-s)}:host([type=xs]){--sinch-comp-title-font:var(--sinch-sys-font-desktop-title-xs)}#text{letter-spacing:-2%;color:var(--sinch-global-color-text,var(--sinch-sys-color-text-default));font:var(--sinch-comp-title-font)}:host([ellipsis]) #text{display:block;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}</style><span id="text"></span>';
3
+ import { typeValues } from './utils';
4
+ const template = document.createElement('template');
5
+ template.innerHTML = templateHTML;
6
+ defineCustomElement('sinch-title', class extends NectaryElement {
7
+ #$text;
8
+ constructor() {
9
+ super();
10
+ const shadowRoot = this.attachShadow();
11
+ shadowRoot.appendChild(template.content.cloneNode(true));
12
+ this.#$text = shadowRoot.querySelector('#text');
13
+ }
14
+ connectedCallback() {
15
+ this.setAttribute('role', 'heading');
16
+ }
17
+ static get observedAttributes() {
18
+ return ['text', 'level', 'ellipsis'];
19
+ }
20
+ attributeChangedCallback(name, oldVal, newVal) {
21
+ switch (name) {
22
+ case 'text':
23
+ {
24
+ this.#$text.textContent = newVal;
25
+ break;
26
+ }
27
+ case 'level':
28
+ {
29
+ updateAttribute(this, 'aria-level', newVal);
30
+ break;
31
+ }
32
+ case 'ellipsis':
33
+ {
34
+ if (isAttrEqual(oldVal, newVal)) {
35
+ break;
36
+ }
37
+ updateBooleanAttribute(this, 'ellipsis', isAttrTrue(newVal));
38
+ break;
39
+ }
40
+ }
41
+ }
42
+ get text() {
43
+ return getAttribute(this, 'text', '');
44
+ }
45
+ set text(value) {
46
+ updateAttribute(this, 'text', value);
47
+ }
48
+ set type(value) {
49
+ updateLiteralAttribute(this, typeValues, 'type', value);
50
+ }
51
+ get type() {
52
+ return getLiteralAttribute(this, typeValues, 'type');
53
+ }
54
+ set ellipsis(isEllipsis) {
55
+ updateBooleanAttribute(this, 'ellipsis', isEllipsis);
56
+ }
57
+ get ellipsis() {
58
+ return getBooleanAttribute(this, 'ellipsis');
59
+ }
60
+ });
@@ -0,0 +1,31 @@
1
+ import type { TSinchElementReact } from '../types';
2
+ export type TSinchTitleType = 'xl' | 'l' | 'm' | 's' | 'xs';
3
+ export type TSinchTitleLevel = '1' | '2' | '3' | '4' | '5' | '6';
4
+ export type TSinchTitleElement = HTMLElement & {
5
+ /** Text */
6
+ text: string;
7
+ /** Type */
8
+ type: TSinchTitleType;
9
+ /** Semantical level */
10
+ level: TSinchTitleLevel;
11
+ /** Cuts the long title with “…” ellipsis */
12
+ ellipsis: boolean;
13
+ /** Text */
14
+ setAttribute(name: 'text', value: string): void;
15
+ /** Type */
16
+ setAttribute(name: 'type', value: TSinchTitleType): void;
17
+ /** Semantical level */
18
+ setAttribute(name: 'level', value: TSinchTitleLevel): void;
19
+ /** Cuts the long title with “…” ellipsis */
20
+ setAttribute(name: 'ellipsis', value: ''): void;
21
+ };
22
+ export type TSinchTitleReact = TSinchElementReact<TSinchTitleElement> & {
23
+ /** Text */
24
+ text: string;
25
+ /** Type */
26
+ type: TSinchTitleType;
27
+ /** Semantical level */
28
+ level: TSinchTitleLevel;
29
+ /** Cuts the long title with “…” ellipsis */
30
+ ellipsis?: boolean;
31
+ };
package/title/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { TSinchTitleLevel, TSinchTitleType } from './types';
2
+ export declare const typeValues: readonly TSinchTitleType[];
3
+ export declare const getTitleLevelFromType: (type: TSinchTitleType) => TSinchTitleLevel;
package/title/utils.js ADDED
@@ -0,0 +1,17 @@
1
+ export const typeValues = ['xl', 'l', 'm', 's', 'xs'];
2
+ export const getTitleLevelFromType = type => {
3
+ switch (type) {
4
+ case 'xl':
5
+ return '1';
6
+ case 'l':
7
+ return '2';
8
+ case 'm':
9
+ return '3';
10
+ case 's':
11
+ return '4';
12
+ case 'xs':
13
+ return '5';
14
+ default:
15
+ return '';
16
+ }
17
+ };
@@ -0,0 +1,13 @@
1
+ import '../icon';
2
+ import '../rich-text';
3
+ import type { TSinchToastElement, TSinchToastReact } from './types';
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ 'sinch-toast': TSinchToastReact;
8
+ }
9
+ }
10
+ interface HTMLElementTagNameMap {
11
+ 'sinch-toast': TSinchToastElement;
12
+ }
13
+ }