@modul/mbui 0.0.1 → 0.0.2-beta-pv-52768-9b2131f6

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 (258) hide show
  1. package/package.json +38 -3
  2. package/src/@/config/button.ts +89 -0
  3. package/src/@/config/index.ts +99 -0
  4. package/src/@/lib/utils.ts +7 -0
  5. package/src/Audio/Audio.styl +115 -0
  6. package/src/Audio/Audio.tsx +359 -0
  7. package/src/Audio/index.ts +4 -0
  8. package/src/Audio/types.ts +40 -0
  9. package/src/Base/Buttons/Button.tsx +66 -41
  10. package/src/Base/Buttons/index.ts +2 -1
  11. package/src/Base/Input/Base.tsx +35 -0
  12. package/src/Base/Input/Input.tsx +31 -11
  13. package/src/Base/Input/types.ts +3 -2
  14. package/src/Collapse/Collapse.tsx +88 -0
  15. package/src/Collapse/ant-collapse.styl +93 -0
  16. package/src/Collapse/index.ts +5 -0
  17. package/src/Input-OTP/Input.tsx +71 -0
  18. package/src/Input-OTP/index.ts +3 -0
  19. package/src/Logo/Logo.tsx +16 -0
  20. package/src/Logo/index.ts +3 -0
  21. package/src/Popover/Popover.tsx +42 -0
  22. package/src/Popover/index.ts +5 -0
  23. package/src/Slider/Slider.tsx +21 -0
  24. package/src/Slider/index.ts +4 -0
  25. package/src/Slider/slider.styl +62 -0
  26. package/src/Tabs/Tabs.tsx +63 -0
  27. package/src/Tabs/ant-tabs.styl +91 -0
  28. package/src/Tabs/index.ts +5 -0
  29. package/src/Tooltip/Tooltip.tsx +47 -0
  30. package/src/Tooltip/index.ts +5 -0
  31. package/src/assets/css/global.css +125 -0
  32. package/src/assets/fonts/Roboto-Italic.ttf +0 -0
  33. package/src/assets/fonts/Roboto-Italic.woff2 +0 -0
  34. package/src/assets/fonts/Roboto.ttf +0 -0
  35. package/src/assets/fonts/Roboto.woff2 +0 -0
  36. package/src/assets/images/logo/bank/emblem-white.svg +1 -0
  37. package/src/assets/images/logo/bank/emblem.svg +1 -0
  38. package/src/assets/images/logo/bank/logo-white.svg +1 -0
  39. package/src/assets/images/logo/bank/logo.svg +1 -0
  40. package/src/assets/images/logo/garant/emblem-white.svg +1 -0
  41. package/src/assets/images/logo/garant/emblem.svg +1 -0
  42. package/src/assets/images/logo/garant/logo-white.svg +1 -0
  43. package/src/assets/images/logo/garant/logo.svg +1 -0
  44. package/src/assets/images/logo/kassa/emblem-white.svg +1 -0
  45. package/src/assets/images/logo/kassa/emblem.svg +1 -0
  46. package/src/assets/images/logo/kassa/logo-white.svg +1 -0
  47. package/src/assets/images/logo/kassa/logo.svg +1 -0
  48. package/src/components/BottonNavigation/BottonNavigation.tsx +55 -0
  49. package/src/components/BottonNavigation/index.ts +6 -0
  50. package/src/components/SvgIcon/SvgIcon.tsx +32 -0
  51. package/src/components/SvgIcon/icons/AddList.tsx +18 -0
  52. package/src/components/SvgIcon/icons/AlertCircle.tsx +18 -0
  53. package/src/components/SvgIcon/icons/AlertCircleSolid.tsx +18 -0
  54. package/src/components/SvgIcon/icons/AlertDiamond.tsx +18 -0
  55. package/src/components/SvgIcon/icons/AlertDiamondSolid.tsx +18 -0
  56. package/src/components/SvgIcon/icons/AlertShield.tsx +18 -0
  57. package/src/components/SvgIcon/icons/Android.tsx +18 -0
  58. package/src/components/SvgIcon/icons/Apple.tsx +18 -0
  59. package/src/components/SvgIcon/icons/Archive.tsx +18 -0
  60. package/src/components/SvgIcon/icons/ArrowCircle.tsx +18 -0
  61. package/src/components/SvgIcon/icons/ArrowDown.tsx +18 -0
  62. package/src/components/SvgIcon/icons/ArrowLeft.tsx +18 -0
  63. package/src/components/SvgIcon/icons/ArrowRight.tsx +18 -0
  64. package/src/components/SvgIcon/icons/ArrowUp.tsx +18 -0
  65. package/src/components/SvgIcon/icons/ArrowUpCorner.tsx +18 -0
  66. package/src/components/SvgIcon/icons/ArrowsChange.tsx +18 -0
  67. package/src/components/SvgIcon/icons/Atm.tsx +18 -0
  68. package/src/components/SvgIcon/icons/Attach.tsx +18 -0
  69. package/src/components/SvgIcon/icons/Bank.tsx +18 -0
  70. package/src/components/SvgIcon/icons/Bold.tsx +18 -0
  71. package/src/components/SvgIcon/icons/Bonus.tsx +18 -0
  72. package/src/components/SvgIcon/icons/Building.tsx +18 -0
  73. package/src/components/SvgIcon/icons/Calendar.tsx +18 -0
  74. package/src/components/SvgIcon/icons/CalendarCancel.tsx +18 -0
  75. package/src/components/SvgIcon/icons/Call.tsx +18 -0
  76. package/src/components/SvgIcon/icons/CallEnd.tsx +18 -0
  77. package/src/components/SvgIcon/icons/CallMissed.tsx +18 -0
  78. package/src/components/SvgIcon/icons/Callback.tsx +18 -0
  79. package/src/components/SvgIcon/icons/Camera.tsx +18 -0
  80. package/src/components/SvgIcon/icons/Cancel.tsx +18 -0
  81. package/src/components/SvgIcon/icons/CancelSolid.tsx +18 -0
  82. package/src/components/SvgIcon/icons/Card.tsx +18 -0
  83. package/src/components/SvgIcon/icons/CardLock.tsx +18 -0
  84. package/src/components/SvgIcon/icons/CardRefill.tsx +18 -0
  85. package/src/components/SvgIcon/icons/CardReissue.tsx +18 -0
  86. package/src/components/SvgIcon/icons/CardScan.tsx +18 -0
  87. package/src/components/SvgIcon/icons/CardToCard.tsx +18 -0
  88. package/src/components/SvgIcon/icons/CardUnlock.tsx +18 -0
  89. package/src/components/SvgIcon/icons/Change.tsx +18 -0
  90. package/src/components/SvgIcon/icons/Chart.tsx +18 -0
  91. package/src/components/SvgIcon/icons/Chat.tsx +18 -0
  92. package/src/components/SvgIcon/icons/ChatSolid.tsx +18 -0
  93. package/src/components/SvgIcon/icons/Check.tsx +18 -0
  94. package/src/components/SvgIcon/icons/CheckCircle.tsx +18 -0
  95. package/src/components/SvgIcon/icons/CheckCircleSolid.tsx +18 -0
  96. package/src/components/SvgIcon/icons/CheckShield.tsx +20 -0
  97. package/src/components/SvgIcon/icons/CheckSmall.tsx +18 -0
  98. package/src/components/SvgIcon/icons/Checklist.tsx +18 -0
  99. package/src/components/SvgIcon/icons/Circle.tsx +18 -0
  100. package/src/components/SvgIcon/icons/Clock.tsx +18 -0
  101. package/src/components/SvgIcon/icons/Close.tsx +18 -0
  102. package/src/components/SvgIcon/icons/Coins.tsx +18 -0
  103. package/src/components/SvgIcon/icons/Collapse.tsx +18 -0
  104. package/src/components/SvgIcon/icons/Copy.tsx +18 -0
  105. package/src/components/SvgIcon/icons/Cup.tsx +18 -0
  106. package/src/components/SvgIcon/icons/CurrencyChange.tsx +18 -0
  107. package/src/components/SvgIcon/icons/CurrencyTransfer.tsx +18 -0
  108. package/src/components/SvgIcon/icons/Deposit.tsx +18 -0
  109. package/src/components/SvgIcon/icons/Diamond.tsx +18 -0
  110. package/src/components/SvgIcon/icons/Dislike.tsx +18 -0
  111. package/src/components/SvgIcon/icons/DislikeSolid.tsx +18 -0
  112. package/src/components/SvgIcon/icons/Doc.tsx +18 -0
  113. package/src/components/SvgIcon/icons/DocCancel.tsx +18 -0
  114. package/src/components/SvgIcon/icons/Dollar.tsx +18 -0
  115. package/src/components/SvgIcon/icons/DoubleArrow.tsx +18 -0
  116. package/src/components/SvgIcon/icons/DoubleTick.tsx +18 -0
  117. package/src/components/SvgIcon/icons/Download.tsx +18 -0
  118. package/src/components/SvgIcon/icons/Dropdown.tsx +18 -0
  119. package/src/components/SvgIcon/icons/DropdownSmallOld.tsx +20 -0
  120. package/src/components/SvgIcon/icons/Dropup.tsx +18 -0
  121. package/src/components/SvgIcon/icons/Edit.tsx +18 -0
  122. package/src/components/SvgIcon/icons/Email.tsx +18 -0
  123. package/src/components/SvgIcon/icons/Excel.tsx +18 -0
  124. package/src/components/SvgIcon/icons/Expand.tsx +18 -0
  125. package/src/components/SvgIcon/icons/Eye.tsx +18 -0
  126. package/src/components/SvgIcon/icons/EyeOff.tsx +18 -0
  127. package/src/components/SvgIcon/icons/Favorite.tsx +18 -0
  128. package/src/components/SvgIcon/icons/FavoriteSolid.tsx +18 -0
  129. package/src/components/SvgIcon/icons/Fb.tsx +18 -0
  130. package/src/components/SvgIcon/icons/FbCircle.tsx +18 -0
  131. package/src/components/SvgIcon/icons/File.tsx +18 -0
  132. package/src/components/SvgIcon/icons/FileAdd.tsx +18 -0
  133. package/src/components/SvgIcon/icons/Files.tsx +18 -0
  134. package/src/components/SvgIcon/icons/Filter.tsx +18 -0
  135. package/src/components/SvgIcon/icons/Folder.tsx +18 -0
  136. package/src/components/SvgIcon/icons/Geolocation.tsx +18 -0
  137. package/src/components/SvgIcon/icons/Gift.tsx +18 -0
  138. package/src/components/SvgIcon/icons/Globe.tsx +18 -0
  139. package/src/components/SvgIcon/icons/Heart.tsx +18 -0
  140. package/src/components/SvgIcon/icons/HeartSolid.tsx +18 -0
  141. package/src/components/SvgIcon/icons/Help.tsx +18 -0
  142. package/src/components/SvgIcon/icons/Home.tsx +18 -0
  143. package/src/components/SvgIcon/icons/Housing.tsx +18 -0
  144. package/src/components/SvgIcon/icons/Ig.tsx +18 -0
  145. package/src/components/SvgIcon/icons/IgCircle.tsx +18 -0
  146. package/src/components/SvgIcon/icons/Info.tsx +18 -0
  147. package/src/components/SvgIcon/icons/InfoBook.tsx +18 -0
  148. package/src/components/SvgIcon/icons/InfoSolid.tsx +18 -0
  149. package/src/components/SvgIcon/icons/Italic.tsx +18 -0
  150. package/src/components/SvgIcon/icons/Key.tsx +18 -0
  151. package/src/components/SvgIcon/icons/Left.tsx +18 -0
  152. package/src/components/SvgIcon/icons/Lightbulb.tsx +18 -0
  153. package/src/components/SvgIcon/icons/Like.tsx +18 -0
  154. package/src/components/SvgIcon/icons/LikeSolid.tsx +18 -0
  155. package/src/components/SvgIcon/icons/Link.tsx +18 -0
  156. package/src/components/SvgIcon/icons/Lock.tsx +18 -0
  157. package/src/components/SvgIcon/icons/Logout.tsx +18 -0
  158. package/src/components/SvgIcon/icons/MagicWand.tsx +18 -0
  159. package/src/components/SvgIcon/icons/Mail.tsx +18 -0
  160. package/src/components/SvgIcon/icons/MailSend.tsx +18 -0
  161. package/src/components/SvgIcon/icons/Map.tsx +18 -0
  162. package/src/components/SvgIcon/icons/MapPin.tsx +18 -0
  163. package/src/components/SvgIcon/icons/Menu.tsx +18 -0
  164. package/src/components/SvgIcon/icons/Mic.tsx +18 -0
  165. package/src/components/SvgIcon/icons/MicOff.tsx +18 -0
  166. package/src/components/SvgIcon/icons/Minus.tsx +18 -0
  167. package/src/components/SvgIcon/icons/MinusCircle.tsx +18 -0
  168. package/src/components/SvgIcon/icons/MinusShort.tsx +18 -0
  169. package/src/components/SvgIcon/icons/Moneybox.tsx +18 -0
  170. package/src/components/SvgIcon/icons/More.tsx +18 -0
  171. package/src/components/SvgIcon/icons/Move.tsx +18 -0
  172. package/src/components/SvgIcon/icons/Newbie.tsx +20 -0
  173. package/src/components/SvgIcon/icons/News.tsx +18 -0
  174. package/src/components/SvgIcon/icons/Notes.tsx +18 -0
  175. package/src/components/SvgIcon/icons/Notification.tsx +18 -0
  176. package/src/components/SvgIcon/icons/Ok.tsx +18 -0
  177. package/src/components/SvgIcon/icons/OkCircle.tsx +18 -0
  178. package/src/components/SvgIcon/icons/Order.tsx +18 -0
  179. package/src/components/SvgIcon/icons/OrderLoad.tsx +18 -0
  180. package/src/components/SvgIcon/icons/OrderSend.tsx +18 -0
  181. package/src/components/SvgIcon/icons/Pause.tsx +18 -0
  182. package/src/components/SvgIcon/icons/PauseCircle.tsx +18 -0
  183. package/src/components/SvgIcon/icons/Payment.tsx +18 -0
  184. package/src/components/SvgIcon/icons/PhoneShake.tsx +18 -0
  185. package/src/components/SvgIcon/icons/Play.tsx +18 -0
  186. package/src/components/SvgIcon/icons/PlaySolid.tsx +18 -0
  187. package/src/components/SvgIcon/icons/Plus.tsx +18 -0
  188. package/src/components/SvgIcon/icons/PlusCircle.tsx +18 -0
  189. package/src/components/SvgIcon/icons/Pos.tsx +18 -0
  190. package/src/components/SvgIcon/icons/Print.tsx +18 -0
  191. package/src/components/SvgIcon/icons/QrPay.tsx +18 -0
  192. package/src/components/SvgIcon/icons/Redirect.tsx +18 -0
  193. package/src/components/SvgIcon/icons/Refill.tsx +18 -0
  194. package/src/components/SvgIcon/icons/Refund.tsx +18 -0
  195. package/src/components/SvgIcon/icons/Reload.tsx +18 -0
  196. package/src/components/SvgIcon/icons/Reply.tsx +18 -0
  197. package/src/components/SvgIcon/icons/ReplyShape.tsx +18 -0
  198. package/src/components/SvgIcon/icons/ReplyShapeSolid.tsx +18 -0
  199. package/src/components/SvgIcon/icons/Request.tsx +18 -0
  200. package/src/components/SvgIcon/icons/Right.tsx +18 -0
  201. package/src/components/SvgIcon/icons/Route.tsx +18 -0
  202. package/src/components/SvgIcon/icons/Ruble.tsx +18 -0
  203. package/src/components/SvgIcon/icons/Sbp.tsx +18 -0
  204. package/src/components/SvgIcon/icons/Search.tsx +18 -0
  205. package/src/components/SvgIcon/icons/Send.tsx +18 -0
  206. package/src/components/SvgIcon/icons/Services.tsx +18 -0
  207. package/src/components/SvgIcon/icons/Settings.tsx +18 -0
  208. package/src/components/SvgIcon/icons/Share.tsx +18 -0
  209. package/src/components/SvgIcon/icons/ShoppingCart.tsx +18 -0
  210. package/src/components/SvgIcon/icons/Sign.tsx +18 -0
  211. package/src/components/SvgIcon/icons/SlotMachine.tsx +18 -0
  212. package/src/components/SvgIcon/icons/SortDown.tsx +18 -0
  213. package/src/components/SvgIcon/icons/SortDownSolid.tsx +18 -0
  214. package/src/components/SvgIcon/icons/SortUp.tsx +18 -0
  215. package/src/components/SvgIcon/icons/SortUpSolid.tsx +18 -0
  216. package/src/components/SvgIcon/icons/Stop.tsx +18 -0
  217. package/src/components/SvgIcon/icons/Support.tsx +18 -0
  218. package/src/components/SvgIcon/icons/Sync.tsx +18 -0
  219. package/src/components/SvgIcon/icons/Table.tsx +18 -0
  220. package/src/components/SvgIcon/icons/Tariffs.tsx +18 -0
  221. package/src/components/SvgIcon/icons/Tg.tsx +18 -0
  222. package/src/components/SvgIcon/icons/TgCircle.tsx +18 -0
  223. package/src/components/SvgIcon/icons/Timeout.tsx +18 -0
  224. package/src/components/SvgIcon/icons/Timer.tsx +18 -0
  225. package/src/components/SvgIcon/icons/Trash.tsx +18 -0
  226. package/src/components/SvgIcon/icons/TurnOff.tsx +18 -0
  227. package/src/components/SvgIcon/icons/Twitter.tsx +18 -0
  228. package/src/components/SvgIcon/icons/TwitterCircle.tsx +18 -0
  229. package/src/components/SvgIcon/icons/Underline.tsx +18 -0
  230. package/src/components/SvgIcon/icons/Unlink.tsx +18 -0
  231. package/src/components/SvgIcon/icons/Unsorted.tsx +18 -0
  232. package/src/components/SvgIcon/icons/UnsortedSolid.tsx +18 -0
  233. package/src/components/SvgIcon/icons/Upload.tsx +18 -0
  234. package/src/components/SvgIcon/icons/User.tsx +18 -0
  235. package/src/components/SvgIcon/icons/UserAdd.tsx +18 -0
  236. package/src/components/SvgIcon/icons/UserCard.tsx +18 -0
  237. package/src/components/SvgIcon/icons/UserEdit.tsx +18 -0
  238. package/src/components/SvgIcon/icons/UserQueue.tsx +18 -0
  239. package/src/components/SvgIcon/icons/Viber.tsx +18 -0
  240. package/src/components/SvgIcon/icons/ViberCircle.tsx +18 -0
  241. package/src/components/SvgIcon/icons/ViewGrid.tsx +18 -0
  242. package/src/components/SvgIcon/icons/ViewHorizontal.tsx +18 -0
  243. package/src/components/SvgIcon/icons/ViewList.tsx +18 -0
  244. package/src/components/SvgIcon/icons/ViewRows.tsx +18 -0
  245. package/src/components/SvgIcon/icons/ViewVertical.tsx +18 -0
  246. package/src/components/SvgIcon/icons/Vk.tsx +18 -0
  247. package/src/components/SvgIcon/icons/VkCircle.tsx +18 -0
  248. package/src/components/SvgIcon/icons/Wallet.tsx +18 -0
  249. package/src/components/SvgIcon/icons/Warning.tsx +18 -0
  250. package/src/components/SvgIcon/icons/WarningClean.tsx +18 -0
  251. package/src/components/SvgIcon/icons/Whatsapp.tsx +18 -0
  252. package/src/components/SvgIcon/icons/WhatsappCircle.tsx +18 -0
  253. package/src/components/SvgIcon/icons/Wheelchair.tsx +18 -0
  254. package/src/components/SvgIcon/icons/index.ts +203 -0
  255. package/src/components/SvgIcon/index.ts +1 -0
  256. package/src/DatePicker/index.tsx +0 -4
  257. package/src/DatePicker/test.ts +0 -0
  258. package/src/index.ts +0 -6
@@ -0,0 +1,359 @@
1
+ import React from 'react'
2
+ import Slider from '../Slider'
3
+ // import './Audio.styl'
4
+ import {EAudioStatuses, IAudioProps, IState} from "./types";
5
+
6
+ /**
7
+ * Функция отображения продолжительности записи в "мм:cc"
8
+ * @param {number} value Значение в секундах
9
+ * @returns {string}
10
+ */
11
+ function Duration(value) {
12
+ let result = '––:––'
13
+ if (value || value === 0) {
14
+ const minutes = Math.floor(value / 60)
15
+ const seconds = Math.round(value - minutes * 60)
16
+ const leadZero = (value) => `${value < 10 ? '0' : ''}${value}`
17
+ result = `${leadZero(minutes)}:${leadZero(seconds)}`
18
+ }
19
+ return result
20
+ }
21
+
22
+ /**
23
+ * Компонент прослушивания аудиозаписей
24
+ */
25
+ export class Audio extends React.Component<IAudioProps, IState> {
26
+ /* начальное состояние */
27
+ state: any = {
28
+ loadingProgress: 0,
29
+ progress: 0,
30
+ duration: 0,
31
+ status: EAudioStatuses.PAUSED,
32
+ currentTime: 0,
33
+ drag: false,
34
+ }
35
+
36
+ // static defaultProps = {
37
+ // onlyOneIsPlayed: true,
38
+ // }
39
+
40
+ /**
41
+ * ссылка на аудио элемент на странице
42
+ * @memberof Audio
43
+ */
44
+ audioRef = React.createRef<HTMLAudioElement>()
45
+
46
+ componentDidMount() {
47
+ this.changeVolume(this.props.volume)
48
+ this.setState({
49
+ duration: this.props.duration,
50
+ })
51
+ }
52
+
53
+ componentDidUpdate(prevProps) {
54
+ if (prevProps.changeVolume !== this.props.volume) {
55
+ this.changeVolume(this.props.volume)
56
+ }
57
+ }
58
+
59
+ changeVolume(value) {
60
+ const audio = this.audioRef.current
61
+ if (audio.volume) {
62
+ audio.volume = value || 0.5
63
+ }
64
+ }
65
+
66
+ getDuration = () => {
67
+ const audio = this.audioRef.current
68
+ return Number(this.state.duration || audio.duration)
69
+ }
70
+
71
+ /**
72
+ * Метод включение записи на проигрывание
73
+ * @memberof Audio
74
+ */
75
+ play() {
76
+ const audio = this.audioRef.current
77
+ if (audio && (!audio.src || audio.src.indexOf('_abortedAudio') >= 0)) {
78
+ audio.src = this.props.src
79
+ }
80
+ /** Останавливаем проигрывание остальных записей */
81
+ const allAudioElements = document.getElementsByTagName('audio')
82
+ for (let i = allAudioElements.length - 1; i >= 0; i--) {
83
+ const audioElement = allAudioElements.item(i)
84
+ if (audioElement !== this.audioRef.current && !!audioElement.getAttribute('data-only-one-is-played')) {
85
+ audioElement.pause()
86
+ }
87
+ }
88
+ audio.play().catch(() => {
89
+ audio.pause()
90
+ })
91
+ }
92
+
93
+ /**
94
+ * Метод постановки проигрываемой записи на паузу
95
+ * @memberof Audio
96
+ */
97
+ pause() {
98
+ const audio = this.audioRef.current
99
+ audio.pause()
100
+ }
101
+
102
+ /**
103
+ * Метод прерывания процесса загрузки записи
104
+ * @memberof Audio
105
+ */
106
+ loadCancel() {
107
+ this.pause()
108
+ const audio = this.audioRef.current
109
+ if (audio.src) {
110
+ audio.src = '_abortedAudio'
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Метод перемотки записи до нужной секунды
116
+ * @param {number} sec значение в секундах
117
+ * @memberof Audio
118
+ */
119
+ seek(sec) {
120
+ const audio = this.audioRef.current
121
+ audio.currentTime = Math.min(Math.max(sec, 0), this.getDuration())
122
+ }
123
+
124
+ /**
125
+ * Обработчик изменения позиции слайдера момента исполнения записи
126
+ * @param {*} value значение слайдера
127
+ * @memberof Audio
128
+ */
129
+ onSliderChange = (value) => {
130
+ const duration = this.getDuration()
131
+ const newTimeValue = (value / 100) * duration
132
+ this.seek(newTimeValue)
133
+ const audio = this.audioRef.current
134
+ const progress = audio ? (audio.currentTime / duration) * 100 : 0
135
+ this.setState({ progress, drag: true, currentTime: newTimeValue })
136
+ }
137
+
138
+ onAfterChange = () => {
139
+ this.setState({ drag: false })
140
+ }
141
+
142
+ /**
143
+ * Обработчик нажатия кнопки управления
144
+ * @memberof Audio
145
+ */
146
+ onButtonClick = () => {
147
+ switch (this.state.status) {
148
+ case EAudioStatuses.LOADING:
149
+ this.loadCancel()
150
+ break
151
+ case EAudioStatuses.PLAYING:
152
+ this.pause()
153
+ break
154
+ default:
155
+ this.play()
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Обработчик события загрузки метаданных записи
161
+ * @param {*} event дескриптор события
162
+ * @memberof Audio
163
+ */
164
+ onLoadedMetaData = ({ target }) => {
165
+ const { duration } = target || {}
166
+ this.setState({
167
+ duration: duration,
168
+ })
169
+ }
170
+
171
+ /**
172
+ * Обработчик изменения отметки времени исполнения
173
+ * @param {*} event дексриптор события
174
+ * @memberof Audio
175
+ */
176
+ onTimeUpdate = (event) => {
177
+ const { currentTime } = event.target
178
+ const progress = (currentTime / this.getDuration()) * 100
179
+ this.setState({ progress, currentTime })
180
+ }
181
+
182
+ /**
183
+ * Метод расчета прогресса загруженной записи
184
+ * @param {TimeRanges} timeRanges загруженные промежутки
185
+ * @param {number} duration длительность записи
186
+ * @returns {number}
187
+ * @memberof Audio
188
+ */
189
+ calcProgress(timeRanges, duration) {
190
+ let buffered = 0
191
+ if (timeRanges && timeRanges.length) {
192
+ for (let i = timeRanges.length - 1; 0 <= i; i--) {
193
+ buffered += timeRanges.end(i) - timeRanges.start(i) + 1
194
+ }
195
+ }
196
+ return Math.min(duration && buffered !== duration ? (buffered / duration) * 100 : 0, 100)
197
+ }
198
+
199
+ updateLoadingProgress(buffered, duration) {
200
+ this.setState({
201
+ loadingProgress: this.calcProgress(buffered, duration),
202
+ })
203
+ }
204
+
205
+ /**
206
+ * Обработчик загрузки нового фрагмента записи
207
+ * @param {*} event
208
+ * @memberof Audio
209
+ */
210
+ onProgress = ({ target }) => {
211
+ const { buffered, duration } = target || {}
212
+ /* считаем и записываем процент загрузки аудиозаписи*/
213
+ this.updateLoadingProgress(buffered, duration)
214
+ }
215
+
216
+ /**
217
+ * Обработчик при включении проигрывания записи
218
+ * @param {*} event
219
+ * @memberof Audio
220
+ */
221
+ onPlay = () => {
222
+ this.setState({ status: EAudioStatuses.PLAYING })
223
+ }
224
+
225
+ /**
226
+ * Обработчик при постновки записи на паузу
227
+ * @param {*} event дескриптор события
228
+ * @memberof Audio
229
+ */
230
+ onPause = () => {
231
+ this.setState({ status: EAudioStatuses.PAUSED })
232
+ }
233
+
234
+ /**
235
+ * Обработчик перехода к проигрыванию записи
236
+ * @memberof Audio
237
+ */
238
+ onPlaying = () => {
239
+ if (this.state.waitingTimerId) {
240
+ clearTimeout(this.state.waitingTimerId)
241
+ }
242
+ this.setState({ status: EAudioStatuses.PLAYING })
243
+ }
244
+
245
+ /**
246
+ * Обработчик события ожидания, когда что-то грузится
247
+ * @param {*} event дескриптор события
248
+ * @memberof Audio
249
+ */
250
+ onWaiting = (event) => {
251
+ const { buffered, duration } = event.target || {}
252
+ /* устанавливаем статус "загрузка" через задержку, чтобы не видеть моргания "||" -> "Х" -> "||" при переходе к уже загруженному фрагменту */
253
+ this.setState({
254
+ waitingTimerId: setTimeout(() => {
255
+ this.setState({
256
+ status: EAudioStatuses.LOADING,
257
+ })
258
+ }, 5),
259
+ })
260
+ this.updateLoadingProgress(buffered, duration)
261
+ }
262
+
263
+ /**
264
+ * Обработчик достижения конца проигрываемой записи
265
+ * @param {*} event дескриптор события
266
+ * @memberof Audio
267
+ */
268
+ onEnded = (event) => {
269
+ event.target.currentTime = 0
270
+ this.setState({ status: EAudioStatuses.PAUSED })
271
+ }
272
+
273
+ /**
274
+ * Обработчик возникновения ошибки аудио элемента
275
+ * @memberof Audio
276
+ */
277
+ onError = () => {
278
+ this.setState({ status: EAudioStatuses.PAUSED })
279
+ }
280
+
281
+ /**
282
+ * Метод рендера содержимого кнопки управления
283
+ * @returns
284
+ * @memberof Audio
285
+ */
286
+ getButtonCaption() {
287
+ switch (this.state.status) {
288
+ case EAudioStatuses.PAUSED:
289
+ return <i className="icon-play-solid" />
290
+ case EAudioStatuses.PLAYING:
291
+ return <i className="icon-pause" />
292
+ case EAudioStatuses.LOADING:
293
+ return (
294
+ <div>
295
+ <i className="icon-close" />
296
+ </div>
297
+ )
298
+ }
299
+ }
300
+
301
+ durationRender = () => {
302
+ const duration = this.state.currentTime || this.state.drag ? this.state.currentTime : this.state.duration
303
+ return Duration(duration)
304
+ }
305
+
306
+ render() {
307
+ let { src, fileName, durationView = 'right', onlyOneIsPlayed } = this.props
308
+ return (
309
+ <>
310
+ <div className="player">
311
+ {/* кнопка */}
312
+ <button
313
+ className="player__btn"
314
+ onClick={this.onButtonClick}
315
+ >
316
+ {this.getButtonCaption()}
317
+ </button>
318
+ {/* полоса прогресса и перемотки */}
319
+ <div className="player__progress">
320
+ <div
321
+ className="player__progress-buffer"
322
+ style={{ width: `${this.state.loadingProgress}%` }}
323
+ />
324
+ <Slider
325
+ value={[this.state.progress ? this.state.progress : 0]}
326
+ onValueChange={this.onSliderChange}
327
+ onValueCommit={this.onAfterChange}
328
+ />
329
+ {durationView === 'bottom' && <div className="player__time">{this.durationRender()}</div>}
330
+ </div>
331
+ {/* продолжительность аудиозаписи */}
332
+ {durationView === 'right' && <div className="player__time">{this.durationRender()}</div>}
333
+ {/* HTML5 элемент аудио */}
334
+ <audio
335
+ ref={this.audioRef}
336
+ preload="none"
337
+ onLoadedMetadata={this.onLoadedMetaData}
338
+ onDurationChange={this.onLoadedMetaData}
339
+ onTimeUpdate={this.onTimeUpdate}
340
+ onProgress={this.onProgress}
341
+ onPlay={this.onPlay}
342
+ onPause={this.onPause}
343
+ onPlaying={this.onPlaying}
344
+ onWaiting={this.onWaiting}
345
+ onEnded={this.onEnded}
346
+ onAbort={this.onError}
347
+ onError={this.onError}
348
+ src={src}
349
+ data-only-one-is-played={onlyOneIsPlayed ? 'true' : ''}
350
+ >
351
+ <p>
352
+ <a href={src}>{fileName}</a>
353
+ </p>
354
+ </audio>
355
+ </div>
356
+ </>
357
+ )
358
+ }
359
+ }
@@ -0,0 +1,4 @@
1
+ import { Audio } from './Audio'
2
+
3
+ export default Audio
4
+ export { Audio }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * статусы состояния аудио компонента
3
+ */
4
+ export enum EAudioStatuses {
5
+ LOADING,
6
+ PLAYING,
7
+ PAUSED
8
+ }
9
+
10
+ export interface IState {
11
+ /* текущий статус */
12
+ status: EAudioStatuses;
13
+ /* процесс загрузки */
14
+ loadingProgress: number;
15
+ /* прогресс прослушивания */
16
+ progress: number;
17
+ /** Продолжительность записи (инициализация), будет пересчитано при получении метаданных */
18
+ duration: number;
19
+ /* ИД таймера задержки перед показом лоадера */
20
+ waitingTimerId?: ReturnType<typeof setTimeout>;
21
+ /** Текущее время воспроизведения */
22
+ currentTime: number,
23
+ /** признак когда пользователь взял ползунок перемотки */
24
+ drag: boolean,
25
+ }
26
+
27
+ export interface IAudioProps {
28
+ /** Продолжительность записи (инициализация), будет пересчитано при получении метаданных */
29
+ duration: number;
30
+ /** Источник аудиозаписи */
31
+ src: string,
32
+ /** Имя файла, отображаемое когда невозможно отобразить контрол аудиозаписи */
33
+ fileName: string,
34
+ /** Уровень звука [0,1] */
35
+ volume: number,
36
+ /** Расположение продолжительности аудиозаписи */
37
+ durationView: 'right' | 'bottom',
38
+ /** Только один элемент проигрывается на странице */
39
+ onlyOneIsPlayed: boolean,
40
+ }
@@ -1,47 +1,72 @@
1
- import React from 'react'
2
- import classNames from 'classnames'
1
+ import * as React from "react"
2
+ import { Slot } from "@radix-ui/react-slot"
3
+ import { cva, type VariantProps } from "class-variance-authority"
3
4
 
4
- interface IProps {
5
- children?: React.ReactNode
6
- loading?: boolean
7
- sizeType?: 'normal' | 'big' | 'small' | 'xsmall' | 'xxsmall'
8
- variant?: 'primary' | 'green' | 'light' | 'lightPrimary' | 'grey' | 'clean'
9
- icon?: string
10
- wide?: boolean
11
- }
12
-
13
- type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & IProps
5
+ import { cn } from "../../@/lib/utils"
6
+ // import { cn } from "@/lib/utils" порешать с алиасами
14
7
 
15
- export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
16
- (
17
- {
18
- children,
19
- loading = false,
20
- sizeType = 'normal',
21
- variant = 'primary',
22
- className,
23
- icon,
24
- wide = false,
25
- ...props
8
+ const buttonVariants = cva(
9
+ 'inline-flex items-center border-[2px] justify-center whitespace-nowrap font-medium transition-colors focus-visible:outline-none focus-visible:ring ring-offset-1 disabled:pointer-events-none disabled:opacity-[.24]',
10
+ {
11
+ variants: {
12
+ variant: {
13
+ primary: 'text-btn-primary bg-btn-primary hover:bg-btn-primary-hover focus:bg-btn-primary-focus active:bg-btn-primary-active border-btn-primary hover:border-btn-primary-hover focus:border-btn-primary-focus active:border-btn-primary-active',
14
+ secondary: 'text-btn-secondary bg-btn-secondary hover:bg-btn-secondary-hover focus:bg-btn-secondary-focus active:bg-btn-secondary-active border-btn-secondary hover:border-btn-secondary-hover focus:border-btn-secondary-focus active:border-btn-secondary-active',
15
+ success: 'text-btn-success bg-btn-success hover:bg-btn-success-hover focus:bg-btn-success-focus active:bg-btn-success-active border-btn-success hover:border-btn-success-hover focus:border-btn-success-focus active:border-btn-success-active',
16
+ 'primary-outline': 'text-btn-primary-outline hover:text-btn-primary-outline-hover focus:text-btn-primary-outline-focus active:text-btn-primary-outline-active bg-btn-primary-outline hover:bg-btn-primary-outline-hover focus:bg-btn-primary-outline-focus active:bg-btn-primary-outline-active border-btn-primary-outline hover:border-btn-primary-outline-hover focus:border-btn-primary-outline-focus active:border-btn-primary-outline-active',
17
+ outline: 'border-[1px] text-btn-outline border-btn-outline ring-[currentColor]',
18
+ ghost: 'text-btn-ghost bg-btn-ghost hover:bg-btn-ghost-hover focus:bg-btn-ghost-focus active:bg-btn-ghost-active border-transparent',
19
+ // link: 'text-primary underline-offset-4 hover:underline',
20
+ },
21
+ size: {
22
+ lg: 'h-[52px] px-[32px] text-[16px] leading-[1.08] rounded-[4px]',
23
+ md: 'h-[44px] px-[24px] text-[14px] leading-[1.08] rounded-[4px]',
24
+ sm: 'h-[36px] px-[20px] text-[12px] leading-none rounded-[3px]',
25
+ xs: 'h-[28px] px-[12px] text-[11px] leading-none rounded-[2px]',
26
+ xxs: 'h-[20px] px-[8px] text-[9px] leading-none rounded-[2px]'
27
+ }
28
+ },
29
+ defaultVariants: {
30
+ variant: 'primary',
31
+ size: 'md',
26
32
  },
27
- ref
28
- ) => {
29
- const styles = classNames('button', sizeType, variant, className, {
30
- loader: loading,
31
- [`icon-${icon}`]: !!icon,
32
- wide,
33
- })
34
-
35
- return (
36
- <button
37
- ref={ref}
38
- className={styles}
39
- {...props}
40
- >
41
- {children}
42
- </button>
43
- )
44
33
  }
45
34
  )
35
+ const textVariants = cva(
36
+ 'inline-flex whitespace-nowrap transition-colors focus-visible:outline-current rounded-[.25em] disabled:pointer-events-none disabled:opacity-[.24]',
37
+ {
38
+ variants: {
39
+ variant: {
40
+ primary: 'text-primary hover:text-primary-hover focus:text-primary-focus active:text-primary-active disabled:pointer-events-none',
41
+ }
42
+ },
43
+ defaultVariants: {
44
+ variant: 'primary'
45
+ },
46
+ }
47
+ )
48
+
49
+ export interface ButtonProps
50
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
51
+ VariantProps<typeof buttonVariants> {
52
+ asChild?: boolean,
53
+ asText?: boolean
54
+ }
55
+
56
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
57
+ ({ className, variant, size, asText = false, asChild = false, ...props }, ref) => {
58
+ const Comp = asChild ? Slot : "button"
59
+ const classes = asText ? textVariants({ variant, className }) : buttonVariants({ variant, size, className });
60
+ return (
61
+ <Comp
62
+ className={cn(classes)}
63
+ ref={ref}
64
+ {...props}
65
+ />
66
+ )
67
+ }
68
+ )
69
+
70
+ Button.displayName = "Button"
46
71
 
47
- export default Button
72
+ export { Button, buttonVariants }
@@ -1,3 +1,4 @@
1
- import Button from './Button'
1
+ import {Button} from './Button'
2
2
 
3
3
  export { Button }
4
+ export default Button
@@ -0,0 +1,35 @@
1
+ import React, { ChangeEvent, ForwardedRef } from 'react'
2
+ import { IMaskInput } from 'react-imask'
3
+ import { IInputProps } from './types'
4
+
5
+ const Base = React.forwardRef<HTMLInputElement, IInputProps>(
6
+ ({ onChange, type = 'text', mask, ...props }: IInputProps, ref: ForwardedRef<HTMLInputElement>) => {
7
+ const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
8
+ const val = event.target.value
9
+ onChange?.(val, event)
10
+ }
11
+
12
+ if (!mask) {
13
+ return (
14
+ <input
15
+ type={type}
16
+ ref={ref}
17
+ onChange={handleChange}
18
+ {...props}
19
+ />
20
+ )
21
+ }
22
+
23
+ return (
24
+ <IMaskInput
25
+ type={type}
26
+ inputRef={ref}
27
+ mask={mask}
28
+ onChange={handleChange}
29
+ {...props}
30
+ />
31
+ )
32
+ }
33
+ )
34
+
35
+ export default Base
@@ -1,20 +1,40 @@
1
- import React, { ChangeEvent, ForwardedRef } from 'react'
2
- import { IMaskInput } from 'react-imask'
1
+ import React, { ForwardedRef } from 'react'
2
+ import Base from './Base'
3
3
  import { IInputProps } from './types'
4
4
 
5
5
  const Input = React.forwardRef<HTMLInputElement, IInputProps>(
6
- ({ onChange, ...props }: IInputProps, ref: ForwardedRef<HTMLInputElement>) => {
7
- const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
8
- const val = event.target.value
9
- onChange?.(val, event)
6
+ ({ onChange, value, clearable, ...props }: IInputProps, ref: ForwardedRef<HTMLInputElement>) => {
7
+ const handleClearClick = (): void => {
8
+ onChange?.('')
9
+ }
10
+
11
+ if (!clearable) {
12
+ return (
13
+ <Base
14
+ ref={ref}
15
+ onChange={onChange}
16
+ value={value}
17
+ {...props}
18
+ />
19
+ )
10
20
  }
11
21
 
12
22
  return (
13
- <IMaskInput
14
- ref={ref}
15
- {...props}
16
- onChange={handleChange}
17
- />
23
+ <div className="input_wrap_clear">
24
+ <Base
25
+ ref={ref}
26
+ onChange={onChange}
27
+ value={value}
28
+ {...props}
29
+ />
30
+ {value && (
31
+ <a
32
+ className="input_clear icon-cancel"
33
+ onClick={handleClearClick}
34
+ style={{ visibility: 'initial' }}
35
+ />
36
+ )}
37
+ </div>
18
38
  )
19
39
  }
20
40
  )
@@ -1,10 +1,11 @@
1
1
  import React, { ChangeEvent, ChangeEventHandler } from 'react'
2
2
 
3
- type CustomChangeEventHandler = (value: string, event: ChangeEvent<HTMLInputElement>) => void
3
+ type CustomChangeEventHandler = (value: string, event?: ChangeEvent<HTMLInputElement>) => void
4
4
 
5
5
  type CombinedChangeEventHandler = ChangeEventHandler<HTMLInputElement> & CustomChangeEventHandler
6
6
 
7
7
  export interface IInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
8
8
  onChange?: CombinedChangeEventHandler
9
- mask?: string | RegExp | (string | RegExp)[]
9
+ mask?: string | RegExp | (string | RegExp)[] | NumberConstructor
10
+ clearable?: boolean
10
11
  }