@xaypay/tui 0.0.73 → 0.0.74

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.73",
3
+ "version": "0.0.74",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ const SvgClose = ({ title, titleId, ...props }) => (
3
+ <svg
4
+ width="18"
5
+ height="18"
6
+ viewBox="0 0 18 18"
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
+ d="m10.47 8.95 7.29-7.29A1 1 0 0 0 16.35.25L9.06 7.54 1.77.24A1 1 0 0 0 .36 1.65l7.29 7.3-7.3 7.29a.999.999 0 1 0 1.41 1.41l7.3-7.29 7.29 7.29a1 1 0 0 0 1.41-1.41l-7.29-7.29Z"
15
+ fill="#3C393E"
16
+ />
17
+ </svg>
18
+ );
19
+ export default SvgClose;
@@ -1,2 +1 @@
1
- export { default as Jpeg } from "./Jpeg";
2
- export { default as Png } from "./Png";
1
+
@@ -1,95 +1,260 @@
1
- import React, { useState } from "react";
2
- import PropTypes from "prop-types";
3
- import classnames from "classnames";
4
- import styles from "./modal.module.css";
5
- import Icon from "../icon/Icon";
6
- import { Typography, TypographyType } from "../typography";
1
+ import React, { useState, useEffect } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classnames from 'classnames';
4
+
5
+ import SvgCloseIcon from './../icon/CloseIcon';
6
+ import SvgNextarrow from './../icon/Nextarrow';
7
7
 
8
8
  export const Modal = ({
9
- setShow,
10
- headerText,
11
- className,
12
9
  type,
13
10
  data,
11
+ setShow,
14
12
  selected,
15
13
  children,
14
+ className,
15
+ headerText,
16
16
  }) => {
17
- const classProps = classnames(styles.modal, className);
18
- const [select, setSelect] = useState(selected);
17
+ const classProps = classnames(className);
18
+
19
+ const [select, setSelect] = useState(0);
20
+ const [innerData, setInnerData] = useState([]);
21
+
22
+ const handleCloseModal = () => {
23
+ setShow(false)
24
+ };
25
+
26
+ const handleStopClosing = (e) => {
27
+ e.stopPropagation();
28
+ };
29
+
30
+ const handleGoTo = (e) => {
31
+ const goTo = e.target.getAttribute('data-go');
32
+ if (goTo === 'next') {
33
+ if (select >= data.length - 1) {
34
+ setSelect(0);
35
+ } else {
36
+ setSelect(select + 1);
37
+ }
38
+ } else {
39
+ if (select <= 0) {
40
+ setSelect(data.length - 1);
41
+ } else {
42
+ setSelect(select - 1);
43
+ }
44
+ }
45
+ };
46
+
47
+ useEffect(() => {
48
+ if (type === 'images') {
49
+ if (data) {
50
+ if (data.length === 0) {
51
+ alert('Please fill data prop');
52
+ } else {
53
+ setInnerData(data);
54
+ }
55
+ } else {
56
+ alert('Please add data prop on Modal component');
57
+ }
58
+ }
59
+ }, [type, data, data?.length]);
60
+
61
+ useEffect(() => {
62
+ if (selected) {
63
+ if (selected <= 0) {
64
+ setSelect(0);
65
+ } else if (selected >= data.length - 1) {
66
+ setSelect(data.length - 1);
67
+ } else {
68
+ setSelect(selected);
69
+ }
70
+ }
71
+ }, [selected]);
72
+
73
+ useEffect(() => {
74
+ return () => {
75
+ setSelect(0);
76
+ setInnerData([]);
77
+ }
78
+ }, []);
79
+
19
80
  return (
20
- <div className={`${styles["modal-wrap"]} modal-wrap-rem`} onClick={() => setShow(false)}>
21
- {type == "content" ? (
81
+ <div
82
+ onClick={handleCloseModal}
83
+ style={{
84
+ position: 'fixed',
85
+ top: '0px',
86
+ left: '0px',
87
+ zIndex: 999,
88
+ width: '100%',
89
+ height: '100vh',
90
+ backgroundColor: 'rgba(0,0,0,0.4)' // TODO: config
91
+ }}
92
+ >
93
+ <div
94
+ style={{
95
+ position: 'relative',
96
+ width: '100%',
97
+ height: '100vh'
98
+ }}
99
+ >
22
100
  <div
23
- className={`${styles["modal-content"]} modal-content-rem`}
24
- onClick={(e) => {
25
- e.stopPropagation();
101
+ className={classProps}
102
+ onClick={handleStopClosing}
103
+ style={{
104
+ position: 'absolute',
105
+ top: '0px',
106
+ left: '0px',
107
+ right: '0px',
108
+ bottom: '0px',
109
+ margin: 'auto',
110
+ maxWidth: '95%',
111
+ overflow: 'auto',
112
+ maxHeight: '95vh',
113
+ width: 'fit-content',
114
+ borderRadius: '14px',
115
+ height: 'fit-content',
116
+ boxSizing: 'border-box',
117
+ backgroundColor: 'white',
118
+ padding: '10px 20px 20px',
119
+ // TODO: animation
26
120
  }}
27
121
  >
28
- <div className={`${styles["modal-top"]} modal-top-rem`}>
29
- <div className={`${styles["modal-title"]} modal-title-rem`}>
30
- <Typography variant={TypographyType.p} color="#00236A">{headerText}</Typography>
31
- </div>
122
+ <div
123
+ style={{
124
+ display: 'flex',
125
+ width: '100%',
126
+ height: '27px',
127
+ alignItems: 'center',
128
+ backgroundColor: '#fbfbfb',
129
+ justifyContent: headerText && type === 'content' ? 'space-between' : 'flex-end'
130
+ }}
131
+ >
132
+ {
133
+ headerText && type === 'content' && <p
134
+ style={{
135
+ color: '#00236a',
136
+ fontSize: '20px',
137
+ fontWeight: '600',
138
+ overflow: 'hidden',
139
+ whiteSpace: 'nowrap',
140
+ textOverflow: 'ellipsis',
141
+ margin: '0px 16px 0px 0px',
142
+ maxWidth: 'calc(100% - 30px)'
143
+ }}
144
+ >{headerText}</p>
145
+ }
32
146
  <div
33
- className={`${styles["close-btn"]} close-btn-rem`}
34
- onClick={() => setShow(false)}
147
+ onClick={handleCloseModal}
148
+ style={{
149
+ width: '14px',
150
+ height: '14px',
151
+ cursor: 'pointer'
152
+ }}
35
153
  >
36
- <i className="icon-close" />
154
+ <SvgCloseIcon />
37
155
  </div>
38
156
  </div>
39
- <div className={`${styles["modal-section"]} modal-section-rem`}>{children}</div>
40
- </div>
41
- ) : type == "images" ? (
42
- <div
43
- className={`${styles["modal-content"]} modal-content-rem`}
44
- onClick={(e) => {
45
- e.stopPropagation();
46
- }}
47
- >
157
+
48
158
  <div
49
- className={`${styles["close-btn"]} close-btn-rem`}
50
- onClick={() => setShow(false)}
159
+ style={{
160
+ display: 'flex',
161
+ paddingTop: '10px',
162
+ alignItems: 'center',
163
+ boxSizing: 'border-box',
164
+ justifyContent: 'center'
165
+ }}
51
166
  >
52
- <i className="icon-close" />
53
- </div>
54
-
55
- <div className={`${styles["modal-section"]} modal-section-rem`}>
56
- <div>
57
- {select > 1 ? (
58
- <h1 onClick={() => setSelect(select - 1)}>-</h1>
59
- ) : null}
60
- {data.map((elem) => {
61
- if (select == elem.id) {
62
- return (
63
- <img
64
- width="600px"
65
- key={elem.id}
66
- src={elem.url}
67
- />
68
- );
69
- }
70
- })}
71
- {select < data.length ? (
72
- <h1
73
- onClick={() => {
74
- setSelect(select + 1);
167
+ {
168
+ type === 'content'
169
+ ?
170
+ children ? children : ''
171
+ :
172
+ <div
173
+ style={{
174
+ width: '100%'
75
175
  }}
76
176
  >
77
- +
78
- </h1>
79
- ) : null}
80
- </div>
177
+ {
178
+ innerData && innerData.length > 0 && innerData.map((item, index) => {
179
+ if (select === index) {
180
+ if (!item.hasOwnProperty('url')) {
181
+ alert('Please add url property in data prop on each element');
182
+ } else {
183
+ return (
184
+ <img
185
+ style={{
186
+ width: '600px',
187
+ height: '300px',
188
+ objectFit: 'cover',
189
+ objectPosition: 'center'
190
+ }}
191
+ src={item.url}
192
+ />
193
+ )
194
+ }
195
+ }
196
+ })
197
+ }
198
+ <div
199
+ style={{
200
+ marginTop: '10px'
201
+ }}
202
+ >
203
+ <button
204
+ onClick={handleGoTo}
205
+ data-go='prev'
206
+ style={{
207
+ padding: '8px',
208
+ outline: 'none',
209
+ cursor: 'pointer',
210
+ marginRight: '10px',
211
+ borderRadius: '6px',
212
+ alignItems: 'center',
213
+ display: 'inline-flex',
214
+ justifyContent: 'center',
215
+ backgroundColor: 'white',
216
+ transform: 'rotate(180deg)',
217
+ border: '1px solid #979090'
218
+ }}
219
+ >
220
+ <SvgNextarrow />
221
+ </button>
222
+ <button
223
+ onClick={handleGoTo}
224
+ data-go='next'
225
+ style={{
226
+ padding: '8px',
227
+ outline: 'none',
228
+ cursor: 'pointer',
229
+ borderRadius: '6px',
230
+ alignItems: 'center',
231
+ display: 'inline-flex',
232
+ justifyContent: 'center',
233
+ backgroundColor: 'white',
234
+ border: '1px solid #979090'
235
+ }}
236
+ >
237
+ <SvgNextarrow />
238
+ </button>
239
+ </div>
240
+ </div>
241
+ }
81
242
  </div>
82
243
  </div>
83
- ) : null}
244
+ </div>
84
245
  </div>
85
246
  );
86
247
  };
87
248
 
88
249
  Modal.propTypes = {
250
+ data: PropTypes.array,
251
+ type: PropTypes.string,
89
252
  setShow: PropTypes.func,
90
- headerText: PropTypes.string,
253
+ selected: PropTypes.number,
91
254
  className: PropTypes.string,
92
- type: PropTypes.string,
93
- selected: PropTypes.string,
94
- data: PropTypes.array,
255
+ headerText: PropTypes.string,
256
+ };
257
+
258
+ Modal.defaultProps = {
259
+ type: 'content'
95
260
  };
@@ -8,6 +8,7 @@ export default {
8
8
 
9
9
  const Template = ({ headerText, className }) => {
10
10
  const [show, setShow] = useState(false);
11
+ const [type, setType] = useState('content');
11
12
  const data = [
12
13
  {
13
14
  url: 'https://images.pexels.com/photos/268533/pexels-photo-268533.jpeg?cs=srgb&dl=pexels-pixabay-268533.jpg&fm=jpg',
@@ -29,18 +30,32 @@ const Template = ({ headerText, className }) => {
29
30
  url: 'https://media.istockphoto.com/id/500221043/photo/cascade-yerevan.jpg?s=612x612&w=0&k=20&c=vaULCkIZaIbetZlkFnP20ELnD8cyhlc9cRsvt-X5YAk=',
30
31
  id: 5
31
32
  }
32
- ]
33
+ ];
34
+
33
35
  const handleClick = () => {
34
36
  setShow(true);
35
37
  };
38
+
39
+ const handleChangeType = () => {
40
+ if (type === 'content') {
41
+ setType('images');
42
+ } else {
43
+ setType('content');
44
+ }
45
+ };
46
+
36
47
  return (
37
48
  <>
38
- <button onClick={handleClick}>Click</button>
49
+ <button
50
+ onClick={handleClick}
51
+ style={{ cursor: 'pointer', padding: '8px', fontSize: '16px', marginRight: '10px' }}
52
+ >Click</button>
53
+ <button
54
+ onClick={handleChangeType}
55
+ style={{ cursor: 'pointer', padding: '8px', fontSize: '16px' }}
56
+ >Change type to {type === 'content' ? 'images' : 'content'}</button>
39
57
  {show && (
40
- // <Modal type='images' selected={4} data={data} setShow={setShow} headerText={headerText} className={className} />
41
- <Modal type='content' headerText="test">
42
- <div>TEst</div>
43
- </Modal>
58
+ <Modal type={type} selected={0} data={data} setShow={setShow} headerText={headerText} className={className}></Modal>
44
59
  )}
45
60
  </>
46
61
  );
@@ -49,6 +64,6 @@ const Template = ({ headerText, className }) => {
49
64
  export const Default = Template.bind({});
50
65
 
51
66
  Default.args = {
52
- headerText: "Hi...",
67
+ headerText: "Modal header text",
53
68
  className: "Modal",
54
69
  };
@@ -28,7 +28,7 @@ const Template = (args) => {
28
28
  method: 'GET',
29
29
  headers: {
30
30
  'Content-Type': 'application/json',
31
- 'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIwMjE0NzEyYTllNzQwZWMyMjNhYzE2MGQyNGVkY2UzNyIsImp0aSI6ImY2N2FjNmNiYjI2YWM3NTRhMDhhOTgxOTZkOTZjNjFjNWI3YTA1NzUyN2U4MGE3NzM0ZDJlOGFlZjNkMjY0ZmRiMGZkN2QwZjllZjA1MmE4IiwiaWF0IjoxNjgwNzYzMzU3LjUyMzI5OCwibmJmIjoxNjgwNzYzMzU3LjUyMzMwNSwiZXhwIjoxNjgwNzg4NTU3LjQ5NjQzLCJzdWIiOiJtaW5hc0BtYWlsLnJ1Iiwic2NvcGVzIjpbImVtYWlsIl19.XLp4N1C9XYnX8EITknJs-j684GkppCVrREA5ttTAEyloxCftJUEo6KQGp-2grZDZvWvwvsgD9NF5lecdPOIYuSEgp7NP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L6_uFBANj1v0bi_g-RlzzeqF0FqlUqf1YZ_8S4c-l8nLsqfSDzPJs3nRB6oJVo7Di2O3fS_ka5MCkTXShzI6UJUZEvV4j60_QD7SmqmnDiij2rnfWt76YrNXZpDHt-zWMw6d7gD_pnX5RJ0YHUaXi2-M9ip-OcJfX4e_w7iMnckecaCfUolIO_rYNnHy6mleHX6Dimu6_niyMr0dj1ph9glv7fOHrIDwXx69AfJ4nuUQBa-G_AE9abot8cVzlPXAkwVa8WVkvH2mtzDgQuBLbQDM2VISqxO8j5jZhC9JDuXKN8TGukiBbePkWmpd9ASYaLQC02OqzZxqCaBBXCd72XMrwIynyjyTAW9t-VeraxFJgZwlqCnwZ7eTiIWSpPT7B5CLVumC24kz_ll8Tdbz4tMo0xdHNggD-hdPhciyVsaLk0q0Hx-vyIlKMS0KPez4EULQT2C3HaR5t81Pf4Qq06zLPXnKXXnoFc_p3u8TGDdqVXQBPdV1W8ck_3-hwIe-QzM5TbqTJjehiiH64QMcFTsJs--2APXNy3nBmU0D98is_eBGgHbgLJgck5v7MgYBaAaPjPf2lxtS-DF76ynQQ',
32
32
  },
33
33
  }).then((res)=> {
34
34
  return res.json()
@@ -46,5 +46,6 @@ const Template = (args) => {
46
46
  };
47
47
  export const Default = Template.bind({});
48
48
  Default.args = {
49
- searchCount: 3
49
+ searchCount: 3,
50
+ selected: 'Jhon'
50
51
  }
@@ -12,6 +12,7 @@ export const NewAutocomplete = ({
12
12
  getItem,
13
13
  required,
14
14
  disabled,
15
+ selected,
15
16
  errorSize,
16
17
  labelSize,
17
18
  errorColor,
@@ -140,7 +141,7 @@ export const NewAutocomplete = ({
140
141
  const optionList = (
141
142
  <>
142
143
  {
143
- show && innerOptions
144
+ show && innerOptions && !disabled
144
145
  ?
145
146
  innerOptions.length > 0
146
147
  ?
@@ -248,7 +249,7 @@ export const NewAutocomplete = ({
248
249
  }
249
250
 
250
251
  options && setInnerOptions(options);
251
- }, [options, options.length, getItem]);
252
+ }, [options, options?.length, getItem]);
252
253
 
253
254
  useEffect(() => {
254
255
  if (!change) {
@@ -256,6 +257,14 @@ export const NewAutocomplete = ({
256
257
  }
257
258
  }, [change]);
258
259
 
260
+ useEffect(() => {
261
+ if (selected) {
262
+ setInnerValue(selected);
263
+ } else {
264
+ setInnerValue('');
265
+ }
266
+ }, [selected, selected?.length]);
267
+
259
268
  return (
260
269
  <>
261
270
  {
@@ -354,6 +363,7 @@ NewAutocomplete.propTypes = {
354
363
  label: PropTypes.string,
355
364
  required: PropTypes.bool,
356
365
  disabled: PropTypes.bool,
366
+ selected: PropTypes.string,
357
367
  errorSize: PropTypes.string,
358
368
  labelSize: PropTypes.string,
359
369
  errorColor: PropTypes.string,
@@ -194,7 +194,7 @@ export const Select = ({
194
194
  });
195
195
  setExistOptions(modifiedOptions);
196
196
  }
197
- }, [options, multiple, selected, selected.length]);
197
+ }, [options, multiple, selected, selected?.length]);
198
198
 
199
199
  return (
200
200
  <div className={classProps}>