@teamturing/react-kit 2.52.2 → 2.53.1

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.
@@ -0,0 +1,225 @@
1
+ import { ExclamationPointInCircleIcon, VideoIcon, DocumentIcon, PictureIcon } from '@teamturing/icons';
2
+ import { forcePixelValue } from '@teamturing/utils';
3
+ import { useState, useEffect } from 'react';
4
+ import styled from 'styled-components';
5
+ import '../../node_modules/styled-system/dist/index.esm.js';
6
+ import { sx } from '../../utils/styled-system/index.js';
7
+ import Spinner from '../Spinner/index.js';
8
+ import StyledIcon from '../StyledIcon/index.js';
9
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
+ import { variant } from '../../node_modules/@styled-system/variant/dist/index.esm.js';
11
+
12
+ const FileItem = ({
13
+ file,
14
+ variant = 'default',
15
+ disabled,
16
+ loading,
17
+ validationStatus,
18
+ trailingAction,
19
+ ...props
20
+ }) => {
21
+ const fileType = file.type.match('image/*') ? 'image' : file.type.match('video/*') ? 'video' : 'whatever';
22
+ const fileName = 'name' in file ? file.name : '';
23
+ const FileIcon = fileType === 'image' ? PictureIcon : fileType === 'video' ? VideoIcon : DocumentIcon;
24
+ const [objectUrl, setObjectUrl] = useState('');
25
+ useEffect(() => {
26
+ setObjectUrl(URL.createObjectURL(file));
27
+ return () => {
28
+ URL.revokeObjectURL(objectUrl);
29
+ };
30
+ }, []);
31
+ return /*#__PURE__*/jsx(BaseFile, {
32
+ variant: variant,
33
+ disabled: disabled,
34
+ loading: disabled,
35
+ validationStatus: validationStatus,
36
+ trailingAction: trailingAction,
37
+ ...props,
38
+ children: variant === 'default' ? /*#__PURE__*/jsxs(Fragment, {
39
+ children: [/*#__PURE__*/jsx(FileIcon, {}), /*#__PURE__*/jsx("span", {
40
+ children: fileName
41
+ }), validationStatus === 'error' ? /*#__PURE__*/jsx(StyledIcon, {
42
+ icon: ExclamationPointInCircleIcon,
43
+ size: 24,
44
+ color: 'icon/danger'
45
+ }) : loading ? /*#__PURE__*/jsx(Spinner, {
46
+ width: 24,
47
+ height: 24
48
+ }) : null, trailingAction]
49
+ }) : variant === 'thumbnail' ? /*#__PURE__*/jsxs(Fragment, {
50
+ children: [fileType === 'image' ? /*#__PURE__*/jsx("img", {
51
+ src: objectUrl
52
+ }) : fileType === 'video' ? /*#__PURE__*/jsxs("div", {
53
+ className: 'file__thumbnail__video',
54
+ children: [/*#__PURE__*/jsx("video", {
55
+ src: objectUrl
56
+ }), /*#__PURE__*/jsx(VideoIcon, {})]
57
+ }) : /*#__PURE__*/jsx("div", {
58
+ className: 'file__thumbnail__whatever',
59
+ children: /*#__PURE__*/jsx(DocumentIcon, {})
60
+ }), validationStatus === 'error' || loading ? /*#__PURE__*/jsx("div", {
61
+ className: 'file__thumbnail__cover',
62
+ children: validationStatus === 'error' ? /*#__PURE__*/jsx(StyledIcon, {
63
+ icon: ExclamationPointInCircleIcon,
64
+ size: 24,
65
+ color: 'icon/danger'
66
+ }) : loading ? /*#__PURE__*/jsx(Spinner, {
67
+ width: 24,
68
+ height: 24
69
+ }) : null
70
+ }) : null, trailingAction]
71
+ }) : null
72
+ });
73
+ };
74
+ const BaseFile = styled.div({
75
+ position: 'relative'
76
+ }, ({
77
+ theme,
78
+ disabled
79
+ }) => variant({
80
+ prop: 'variant',
81
+ variants: {
82
+ default: {
83
+ 'backgroundColor': theme.colors['bg/neutral'],
84
+ 'borderRadius': theme.radii.xs,
85
+ 'width': '100%',
86
+ 'height': forcePixelValue(48),
87
+ 'py': 1,
88
+ 'pr': 2,
89
+ 'pl': 4,
90
+ 'display': 'flex',
91
+ 'columnGap': 2,
92
+ 'alignItems': 'center',
93
+ '& > svg': {
94
+ width: 24,
95
+ height: 24,
96
+ color: theme.colors['icon/neutral/bold']
97
+ },
98
+ '& > span': {
99
+ flex: 1,
100
+ fontSize: theme.fontSizes.xs,
101
+ fontWeight: theme.fontWeights.medium,
102
+ lineHeight: theme.lineHeights[2],
103
+ overflow: 'hidden',
104
+ textOverflow: 'ellipsis',
105
+ whiteSpace: 'nowrap',
106
+ color: theme.colors['text/neutral/subtle']
107
+ },
108
+ ...(disabled ? {
109
+ '& > svg': {
110
+ color: theme.colors['icon/disabled']
111
+ },
112
+ '& span': {
113
+ color: theme.colors['text/disabled']
114
+ }
115
+ } : {})
116
+ },
117
+ thumbnail: {
118
+ 'display': 'flex',
119
+ 'alignItems': 'center',
120
+ 'justifyContent': 'center',
121
+ 'width': forcePixelValue(160),
122
+ 'maxWidth': forcePixelValue(160),
123
+ 'aspectRatio': '16 / 9',
124
+ 'backgroundColor': theme.colors['bg/neutral'],
125
+ 'overflow': 'hidden',
126
+ 'borderRadius': 'xs',
127
+ '&:after': {
128
+ content: '""',
129
+ position: 'absolute',
130
+ top: forcePixelValue(0),
131
+ right: forcePixelValue(0),
132
+ bottom: forcePixelValue(0),
133
+ left: forcePixelValue(0),
134
+ borderWidth: 1,
135
+ borderColor: theme.colors['border/neutral'],
136
+ borderStyle: 'solid',
137
+ borderRadius: 'xs',
138
+ pointerEvents: 'none'
139
+ },
140
+ '& > .file__thumbnail__cover': {
141
+ position: 'absolute',
142
+ top: 0,
143
+ left: 0,
144
+ right: 0,
145
+ bottom: 0,
146
+ display: 'flex',
147
+ justifyContent: 'center',
148
+ alignItems: 'center',
149
+ pointerEvents: 'none',
150
+ backgroundColor: 'bg/neutral'
151
+ },
152
+ '& > img': {
153
+ width: '100%',
154
+ height: '100%',
155
+ objectFit: 'cover'
156
+ },
157
+ '& > .file__thumbnail__video': {
158
+ position: 'relative',
159
+ width: '100%',
160
+ height: '100%',
161
+ backgroundColor: 'transparent',
162
+ display: 'flex',
163
+ alignItems: 'center',
164
+ justifyContent: 'center',
165
+ svg: {
166
+ position: 'absolute',
167
+ top: '50%',
168
+ left: '50%',
169
+ transform: 'translate(-50%, -50%)',
170
+ width: 24,
171
+ height: 24,
172
+ color: 'icon/primary'
173
+ },
174
+ video: {
175
+ width: '100%'
176
+ }
177
+ },
178
+ '& > .file__thumbnail__whatever': {
179
+ width: '100%',
180
+ height: '100%',
181
+ backgroundColor: 'bg/neutral',
182
+ display: 'flex',
183
+ alignItems: 'center',
184
+ justifyContent: 'center',
185
+ svg: {
186
+ width: 24,
187
+ height: 24,
188
+ color: 'icon/neutral/bold'
189
+ }
190
+ },
191
+ '& > button': {
192
+ position: 'absolute',
193
+ top: 0,
194
+ right: 0
195
+ },
196
+ ...(disabled ? {} : {})
197
+ }
198
+ }
199
+ }), ({
200
+ theme,
201
+ variant: propVariant
202
+ }) => variant({
203
+ prop: 'validationStatus',
204
+ variants: {
205
+ error: {
206
+ ...(propVariant === 'thumbnail' ? {
207
+ '&:after': {
208
+ content: '""',
209
+ position: 'absolute',
210
+ top: forcePixelValue(0),
211
+ right: forcePixelValue(0),
212
+ bottom: forcePixelValue(0),
213
+ left: forcePixelValue(0),
214
+ borderWidth: 2,
215
+ borderColor: theme.colors['border/danger'],
216
+ borderStyle: 'solid',
217
+ borderRadius: 'xs',
218
+ pointerEvents: 'none'
219
+ }
220
+ } : {})
221
+ }
222
+ }
223
+ }), sx);
224
+
225
+ export { FileItem as default };
package/esm/index.js CHANGED
@@ -16,6 +16,7 @@ export { default as DescriptionList } from './core/DescriptionList/index.js';
16
16
  export { default as Dialog } from './core/Dialog/index.js';
17
17
  export { default as Drawer } from './core/Drawer/index.js';
18
18
  export { default as EmptyState } from './core/EmptyState/index.js';
19
+ export { default as FileItem } from './core/FileItem/index.js';
19
20
  export { default as Flash } from './core/Flash/index.js';
20
21
  export { default as FormControl } from './core/FormControl/index.js';
21
22
  export { default as GradientText } from './core/GradientText/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamturing/react-kit",
3
- "version": "2.52.2",
3
+ "version": "2.53.1",
4
4
  "description": "React components, hooks for create teamturing web application",
5
5
  "author": "Sungchang Park <psch300@gmail.com> (https://github.com/psch300)",
6
6
  "homepage": "https://github.com/weareteamturing/bombe#readme",
@@ -66,5 +66,5 @@
66
66
  "react-textarea-autosize": "^8.5.3",
67
67
  "styled-system": "^5.1.5"
68
68
  },
69
- "gitHead": "2390cfb6d3d1716e4c20b5580927e191827a0f9f"
69
+ "gitHead": "0b981b1312cf772c8bdd7aff43aa6f6e36620c87"
70
70
  }