@xaypay/tui 0.0.112 → 0.0.114

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaypay/tui",
3
- "version": "0.0.112",
3
+ "version": "0.0.114",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -0,0 +1,21 @@
1
+ import * as React from 'react'
2
+ const SvgZoom = ({ title, titleId, ...props }) => (
3
+ <svg
4
+ width="32"
5
+ height="32"
6
+ viewBox="0 0 32 32"
7
+ fill="none"
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ aria-labelledby={titleId}
10
+ {...props}
11
+ >
12
+ {title ? <title id={titleId}>{title}</title> : null}
13
+ <path
14
+ fillRule="evenodd"
15
+ clipRule="evenodd"
16
+ d="M3 14C3 7.925 7.925 3 14 3s11 4.925 11 11-4.925 11-11 11S3 20.075 3 14ZM14 1C6.82 1 1 6.82 1 14s5.82 13 13 13c3.23 0 6.185-1.178 8.458-3.128l6.835 6.835a1 1 0 0 0 1.414-1.414l-6.835-6.835A12.949 12.949 0 0 0 27 14c0-7.18-5.82-13-13-13Zm1 9a1 1 0 1 0-2 0v3h-3a1 1 0 1 0 0 2h3v3a1 1 0 1 0 2 0v-3h3a1 1 0 1 0 0-2h-3v-3Z"
17
+ fill="#fff"
18
+ />
19
+ </svg>
20
+ )
21
+ export default SvgZoom
@@ -52,6 +52,7 @@ export const Input = ({
52
52
  maxNumSize,
53
53
  labelColor,
54
54
  errorColor,
55
+ withoutDot,
55
56
  borderRight,
56
57
  placeholder,
57
58
  errorZindex,
@@ -215,6 +216,17 @@ export const Input = ({
215
216
  change(newStr)
216
217
  }
217
218
  }
219
+
220
+ if (withoutDot && !/^\d+$/.test(currentValue)) {
221
+ const newStr = currentValue.replace(/[^0-9]/g, '').replace(/^([^.]*\.)(.*)$/, function (_, b, c) {
222
+ return b + c.replace(/\./g, '')
223
+ })
224
+ setInnerValue(newStr)
225
+ if (change) {
226
+ change(newStr)
227
+ }
228
+ }
229
+
218
230
  if (currentValue === '') {
219
231
  setInnerValue('')
220
232
  if (change) {
@@ -357,6 +369,17 @@ export const Input = ({
357
369
  change(newStr)
358
370
  }
359
371
  }
372
+
373
+ if (withoutDot && !/^\d+$/.test(value)) {
374
+ const newStr = value.replace(/[^0-9]/g, '').replace(/^([^.]*\.)(.*)$/, function (_, b, c) {
375
+ return b + c.replace(/\./g, '')
376
+ })
377
+ setInnerValue(newStr)
378
+ if (change) {
379
+ change(newStr)
380
+ }
381
+ }
382
+
360
383
  if (value === '') {
361
384
  setInnerValue('')
362
385
  if (change) {
@@ -591,6 +614,7 @@ Input.propTypes = {
591
614
  padding: PropTypes.string,
592
615
  fontSize: PropTypes.string,
593
616
  tooltip: PropTypes.element,
617
+ withoutDot: PropTypes.bool,
594
618
  marginTop: PropTypes.string,
595
619
  transform: PropTypes.string,
596
620
  className: PropTypes.string,
@@ -23,6 +23,4 @@ const Template = (args) => {
23
23
  export const Default = Template.bind({})
24
24
  Default.args = {
25
25
  type: InputTypes.TEXT,
26
- minNumSize: 1,
27
- maxNumSize: 8.8,
28
26
  }
@@ -2,11 +2,12 @@ import React, { useState, useEffect } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classnames from 'classnames'
4
4
 
5
- import { compereConfigs } from './../../utils'
5
+ import { compereConfigs, hasOwnerProperty } from './../../utils'
6
6
  import styles from './modal.module.css'
7
7
 
8
8
  import SvgNext from './../icon/Next'
9
9
  import SvgPrev from './../icon/Prev'
10
+ import SvgZoom from './../icon/Zoom'
10
11
  import SvgCloseIcon from './../icon/CloseIcon'
11
12
  import SvgCloseSlide from './../icon/CloseSlide'
12
13
 
@@ -18,6 +19,7 @@ export const Modal = ({
18
19
  height,
19
20
  padding,
20
21
  setShow,
22
+ zoomIcon,
21
23
  selected,
22
24
  children,
23
25
  minWidth,
@@ -34,17 +36,18 @@ export const Modal = ({
34
36
  borderStyle,
35
37
  borderWidth,
36
38
  borderColor,
39
+ imageMargin,
40
+ showZoomIcon,
37
41
  outsideClose,
38
42
  headerWeight,
39
43
  headerHeight,
44
+ imageMaxWidth,
40
45
  justifyContent,
46
+ imageWrapWidth,
41
47
  backgroundColor,
48
+ imageWrapHeight,
42
49
  grayDecorHeight,
43
50
  layerBackgroundColor,
44
- imageMargin,
45
- imageMaxWidth,
46
- imageWrapWidth,
47
- imageWrapHeight,
48
51
  }) => {
49
52
  const [select, setSelect] = useState(0)
50
53
  const [innerData, setInnerData] = useState([])
@@ -82,6 +85,12 @@ export const Modal = ({
82
85
  }
83
86
  }
84
87
 
88
+ const handleOpenInNewTab = (url) => {
89
+ const imageLink = document.createElement('a')
90
+ ;(imageLink.href = url), (imageLink.target = '_blank')
91
+ imageLink.click()
92
+ }
93
+
85
94
  useEffect(() => {
86
95
  if (type === 'images') {
87
96
  if (data) {
@@ -266,35 +275,60 @@ export const Modal = ({
266
275
  innerData.length > 0 &&
267
276
  innerData.map((item, index) => {
268
277
  if (select === index) {
269
- // eslint-disable-next-line no-prototype-builtins
270
- if (!item.hasOwnProperty('url')) {
278
+ if (!hasOwnerProperty(item, 'url')) {
271
279
  alert('Please add url property in data prop on each element')
272
280
  } else {
273
281
  return (
274
- <img
275
- style={{
276
- display: 'block',
277
- objectFit: 'cover',
278
- objectPosition: 'center',
279
- margin: imageMargin
280
- ? imageMargin
281
- : configStyles.MODAL.imageMargin,
282
- borderRadius: radius
283
- ? radius
284
- : configStyles.MODAL.radius,
285
- width: imageWidth
286
- ? imageWidth
287
- : configStyles.MODAL.imageWidth,
288
- height: imageHeight
289
- ? imageHeight
290
- : configStyles.MODAL.imageHeight,
291
- maxWidth: imageMaxWidth
292
- ? imageMaxWidth
293
- : configStyles.MODAL.imageMaxWidth,
294
- }}
295
- src={item.url}
296
- key={item.id ? item.id : index}
297
- />
282
+ <span key={`${item.url}_${item.id ? item.id : '007'}_${index}`}>
283
+ <img
284
+ style={{
285
+ display: 'block',
286
+ objectFit: 'cover',
287
+ objectPosition: 'center',
288
+ margin: imageMargin
289
+ ? imageMargin
290
+ : configStyles.MODAL.imageMargin,
291
+ borderRadius: radius
292
+ ? radius
293
+ : configStyles.MODAL.radius,
294
+ width: imageWidth
295
+ ? imageWidth
296
+ : configStyles.MODAL.imageWidth,
297
+ height: imageHeight
298
+ ? imageHeight
299
+ : configStyles.MODAL.imageHeight,
300
+ maxWidth: imageMaxWidth
301
+ ? imageMaxWidth
302
+ : configStyles.MODAL.imageMaxWidth,
303
+ }}
304
+ src={item.url}
305
+ />
306
+ {showZoomIcon ? (
307
+ <div
308
+ style={{
309
+ top: '0px',
310
+ left: '0px',
311
+ zIndex: '10',
312
+ right: '0px',
313
+ bottom: '0px',
314
+ margin: 'auto',
315
+ display: 'flex',
316
+ maxWidth: '40px',
317
+ maxHeight: '40px',
318
+ cursor: 'pointer',
319
+ overflow: 'hidden',
320
+ position: 'absolute',
321
+ alignItems: 'center',
322
+ justifyContent: 'center',
323
+ }}
324
+ onClick={() => handleOpenInNewTab(item.url)}
325
+ >
326
+ {zoomIcon ? zoomIcon : <SvgZoom />}
327
+ </div>
328
+ ) : (
329
+ ''
330
+ )}
331
+ </span>
298
332
  )
299
333
  }
300
334
  }
@@ -361,26 +395,28 @@ Modal.propTypes = {
361
395
  mMaxWidth: PropTypes.string,
362
396
  minHeight: PropTypes.string,
363
397
  className: PropTypes.string,
398
+ zoomIcon: PropTypes.element,
364
399
  alignItems: PropTypes.string,
365
400
  mMaxHeight: PropTypes.string,
366
401
  headerText: PropTypes.string,
367
402
  imageWidth: PropTypes.string,
368
403
  headerSize: PropTypes.string,
369
404
  outsideClose: PropTypes.bool,
405
+ showZoomIcon: PropTypes.bool,
406
+ imageMargin: PropTypes.string,
370
407
  borderStyle: PropTypes.string,
371
408
  borderWidth: PropTypes.string,
372
409
  headerColor: PropTypes.string,
373
410
  imageHeight: PropTypes.string,
374
411
  headerWeight: PropTypes.string,
375
412
  headerHeight: PropTypes.string,
413
+ imageMaxWidth: PropTypes.string,
376
414
  justifyContent: PropTypes.string,
415
+ imageWrapWidth: PropTypes.string,
377
416
  backgroundColor: PropTypes.string,
378
417
  grayDecorHeight: PropTypes.string,
379
- layerBackgroundColor: PropTypes.string,
380
- imageMargin: PropTypes.string,
381
- imageMaxWidth: PropTypes.string,
382
- imageWrapWidth: PropTypes.string,
383
418
  imageWrapHeight: PropTypes.string,
419
+ layerBackgroundColor: PropTypes.string,
384
420
  }
385
421
 
386
422
  Modal.defaultProps = {
@@ -64,7 +64,7 @@ const Template = ({ className }) => {
64
64
  Change type to {type === 'content' ? 'images' : 'content'}
65
65
  </button>
66
66
  {show && (
67
- <Modal type={type} selected={0} data={data} setShow={setShow} className={className}>
67
+ <Modal type={type} selected={0} showZoomIcon data={data} setShow={setShow} className={className}>
68
68
  <div
69
69
  style={{
70
70
  width: '400px',
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
4
  import classnames from 'classnames'
5
- import { compereConfigs } from './../../utils'
5
+ import { compereConfigs, hasOwnerProperty } from './../../utils'
6
6
 
7
7
  import SvgRequired from './../icon/Required'
8
8
 
@@ -351,8 +351,7 @@ export const NewAutocomplete = ({
351
351
  options &&
352
352
  options.length > 0 &&
353
353
  options.map((item) => {
354
- // eslint-disable-next-line no-prototype-builtins
355
- if (!item.hasOwnProperty(keyNames.name)) {
354
+ if (!hasOwnerProperty(item, keyNames.name)) {
356
355
  alert(`Please add ${keyNames.name} property in items of options array`)
357
356
  }
358
357
  })
@@ -64,6 +64,7 @@ const FileItem = React.memo(
64
64
  )
65
65
  return () => {
66
66
  setI((_) => _)
67
+ setT((_) => _)
67
68
  clearTimeout(t)
68
69
  clearInterval(i)
69
70
  }
@@ -1,5 +1,4 @@
1
1
  import React, { useRef, useState, useEffect, useMemo } from 'react'
2
- import ReactDOM from 'react-dom'
3
2
  import PropTypes from 'prop-types'
4
3
  import { v4 as uuidv4 } from 'uuid'
5
4
 
@@ -56,6 +55,7 @@ export const NewFile = ({
56
55
  listItemPadding,
57
56
  progressFontSize,
58
57
  borderHoverColor,
58
+ maxCHoosenLength,
59
59
  listItemErrorSize,
60
60
  progressTrackColor,
61
61
  fileAreaImageWidth,
@@ -66,9 +66,11 @@ export const NewFile = ({
66
66
  progressSuccessColor,
67
67
  progressLoadingColor,
68
68
  hiddenBackgroundColor,
69
+ maxCHoosenLengthError,
69
70
  extentionsRowMarginTop,
70
71
  listItemBackgroundColor,
71
72
  listItemBackgroundErrorColor,
73
+ maxCHoosenLengthErrorHideTime,
72
74
  }) => {
73
75
  const ref = useRef(null)
74
76
  const inpRef = useRef(null)
@@ -77,6 +79,7 @@ export const NewFile = ({
77
79
  const [error, setError] = useState('')
78
80
  const [isHover, setIsHover] = useState(false)
79
81
  const [singleFile, setSingleFile] = useState(null)
82
+ const [choosenFileCount, setChoosenFileCount] = useState(0)
80
83
  const [image, setImage] = useState(
81
84
  !multiple ? (defaultData ? (defaultData.type !== 'application/pdf' ? defaultData.url : 'pdf') : null) : null
82
85
  )
@@ -84,10 +87,6 @@ export const NewFile = ({
84
87
  const configStyles = compereConfigs()
85
88
 
86
89
  const handleRemoveComponent = () => {
87
- // eslint-disable-next-line react/no-find-dom-node
88
- const node = ReactDOM.findDOMNode(ref.current)
89
- const parent = node.parentNode
90
- parent.removeChild(node)
91
90
  if (!multiple) {
92
91
  removeFile && removeFile(singleFile)
93
92
  } else {
@@ -101,12 +100,59 @@ export const NewFile = ({
101
100
  removeFile && removeFile(singleFile)
102
101
  }
103
102
 
104
- const handleChange = (e) => {
105
- const file = e.target.files
106
-
107
- if (multiple) {
108
- setError('')
109
- setImage(null)
103
+ const handleUploadFiles = (file) => {
104
+ if (maxCHoosenLength && choosenFileCount > 0) {
105
+ if (file.length > choosenFileCount || file.length + memoizedItems.length > choosenFileCount) {
106
+ setError(
107
+ maxCHoosenLengthError
108
+ ? maxCHoosenLengthError
109
+ : `Դիմումին կարող եք կցել առավելագույնը ${choosenFileCount} ֆայլ`
110
+ )
111
+ const clearFunc = () => {
112
+ clearTimeout(time)
113
+ }
114
+ const time = setTimeout(
115
+ () => {
116
+ setError('')
117
+ clearFunc()
118
+ },
119
+ maxCHoosenLengthErrorHideTime && typeof maxCHoosenLengthErrorHideTime === 'number'
120
+ ? Math.round(maxCHoosenLengthErrorHideTime)
121
+ : 3000
122
+ )
123
+ } else {
124
+ for (let ix = 0; ix < file.length; ix++) {
125
+ if (file[ix]) {
126
+ if (file[ix].size <= maxSize * Math.pow(2, 20)) {
127
+ if (
128
+ fileExtensions.includes(file[ix].type.split('/')[1]) ||
129
+ (fileExtensions.includes('heic') && file[ix].type.split('/')[1] === 'heif')
130
+ ) {
131
+ change({
132
+ id: '',
133
+ check: '',
134
+ status: '',
135
+ file: file[ix],
136
+ uuid: uuidv4(),
137
+ })
138
+ } else {
139
+ change({
140
+ file: file[ix],
141
+ uuid: uuidv4(),
142
+ check: formatError,
143
+ })
144
+ }
145
+ } else {
146
+ change({
147
+ file: file[ix],
148
+ uuid: uuidv4(),
149
+ check: maxSizeError,
150
+ })
151
+ }
152
+ }
153
+ }
154
+ }
155
+ } else {
110
156
  for (let ix = 0; ix < file.length; ix++) {
111
157
  if (file[ix]) {
112
158
  if (file[ix].size <= maxSize * Math.pow(2, 20)) {
@@ -137,6 +183,17 @@ export const NewFile = ({
137
183
  }
138
184
  }
139
185
  }
186
+ }
187
+ }
188
+
189
+ const handleChange = (e) => {
190
+ const file = e.target.files
191
+
192
+ if (multiple) {
193
+ setError('')
194
+ setImage(null)
195
+ handleUploadFiles(file)
196
+
140
197
  if (file.length === 0 && memoizedItems.length === 0) {
141
198
  setError(noChoosenFile)
142
199
  }
@@ -229,7 +286,19 @@ export const NewFile = ({
229
286
  if (multiple && !removeFile) {
230
287
  alert('Please add removeFile prop on NewFile component, it is a require in multiple mode')
231
288
  }
232
- }, [multiple, removeFile, filesArray && filesArray.length, defaultData])
289
+
290
+ if (maxCHoosenLength) {
291
+ if (typeof maxCHoosenLength !== 'number') {
292
+ alert('maxCHoosenLength prop must be a number, please check it!')
293
+ } else {
294
+ if (maxCHoosenLength <= 0) {
295
+ setChoosenFileCount(1)
296
+ } else {
297
+ setChoosenFileCount(Math.round(maxCHoosenLength))
298
+ }
299
+ }
300
+ }
301
+ }, [multiple, removeFile, filesArray && filesArray.length, defaultData, maxCHoosenLength])
233
302
 
234
303
  useEffect(() => {
235
304
  if (deleteComponent && !removeComponent) {
@@ -556,6 +625,7 @@ NewFile.propTypes = {
556
625
  backgroundColor: PropTypes.string,
557
626
  change: PropTypes.func.isRequired,
558
627
  listItemPadding: PropTypes.string,
628
+ maxCHoosenLength: PropTypes.number,
559
629
  progressFontSize: PropTypes.string,
560
630
  borderHoverColor: PropTypes.string,
561
631
  listItemErrorSize: PropTypes.string,
@@ -568,9 +638,11 @@ NewFile.propTypes = {
568
638
  progressSuccessColor: PropTypes.string,
569
639
  progressLoadingColor: PropTypes.string,
570
640
  hiddenBackgroundColor: PropTypes.string,
641
+ maxCHoosenLengthError: PropTypes.string,
571
642
  extentionsRowMarginTop: PropTypes.string,
572
643
  listItemBackgroundColor: PropTypes.string,
573
644
  listItemBackgroundErrorColor: PropTypes.string,
645
+ maxCHoosenLengthErrorHideTime: PropTypes.number,
574
646
  filesArray: PropTypes.arrayOf(PropTypes.object),
575
647
  fileExtensions: PropTypes.arrayOf(PropTypes.string),
576
648
  }
@@ -25,12 +25,13 @@ const Template = (args) => {
25
25
  }
26
26
 
27
27
  const handleRemoveComponent = (componentId) => {
28
- console.log(componentId)
28
+ alert(`You want to remove component with id, ${componentId}`)
29
29
  }
30
30
 
31
31
  return (
32
32
  <NewFile
33
33
  {...args}
34
+ removeFromDOM
34
35
  componentId={2}
35
36
  filesArray={files}
36
37
  change={handleChange}
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState, useRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classnames from 'classnames'
4
- import { compereConfigs } from './../../utils'
4
+ import { compereConfigs, hasOwnerProperty } from './../../utils'
5
5
  import { SingleCheckbox } from '../singleCheckbox'
6
6
 
7
7
  import ReactArrowIcon from '../icon/Arrow'
@@ -152,8 +152,7 @@ export const Select = ({
152
152
 
153
153
  const isObjectEmpty = (obj) => {
154
154
  for (var key in obj) {
155
- // eslint-disable-next-line no-prototype-builtins
156
- if (obj.hasOwnProperty(key)) {
155
+ if (hasOwnerProperty(obj, key)) {
157
156
  return false
158
157
  }
159
158
  }