cozy-ui-plus 7.0.0 → 8.0.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 (33) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/stylesheet.css +0 -231
  3. package/package.json +2 -2
  4. package/dist/UploadQueue/FileUploadProgress.js +0 -86
  5. package/dist/UploadQueue/Item.js +0 -132
  6. package/dist/UploadQueue/Pending.js +0 -23
  7. package/dist/UploadQueue/RemainingTime.js +0 -59
  8. package/dist/UploadQueue/helpers.js +0 -13
  9. package/dist/UploadQueue/index.js +0 -275
  10. package/dist/UploadQueue/useStatusIcon.js +0 -60
  11. package/dist/src/UploadQueue/FileUploadProgress.d.ts +0 -4
  12. package/dist/src/UploadQueue/Item.d.ts +0 -3
  13. package/dist/src/UploadQueue/Pending.d.ts +0 -3
  14. package/dist/src/UploadQueue/RemainingTime.d.ts +0 -4
  15. package/dist/src/UploadQueue/helpers.d.ts +0 -1
  16. package/dist/src/UploadQueue/index.d.ts +0 -42
  17. package/dist/src/UploadQueue/index.spec.d.ts +0 -1
  18. package/dist/src/UploadQueue/useStatusIcon.d.ts +0 -1
  19. package/src/UploadQueue/FileUploadProgress.jsx +0 -50
  20. package/src/UploadQueue/Item.jsx +0 -99
  21. package/src/UploadQueue/Pending.jsx +0 -12
  22. package/src/UploadQueue/Readme.md +0 -95
  23. package/src/UploadQueue/RemainingTime.jsx +0 -27
  24. package/src/UploadQueue/helpers.js +0 -3
  25. package/src/UploadQueue/index.jsx +0 -160
  26. package/src/UploadQueue/index.spec.jsx +0 -177
  27. package/src/UploadQueue/locales/en.json +0 -10
  28. package/src/UploadQueue/locales/es.json +0 -10
  29. package/src/UploadQueue/locales/fr.json +0 -10
  30. package/src/UploadQueue/locales/ru.json +0 -10
  31. package/src/UploadQueue/locales/vi.json +0 -10
  32. package/src/UploadQueue/styles.styl +0 -155
  33. package/src/UploadQueue/useStatusIcon.js +0 -32
@@ -1,27 +0,0 @@
1
- import cx from 'classnames'
2
- import React from 'react'
3
-
4
- import Typography from 'cozy-ui/transpiled/react/Typography'
5
- import { useI18n } from 'twake-i18n'
6
-
7
- import { numberOfReferencesForPluralForm } from './helpers'
8
- import { formatRemainingTime } from './index'
9
- import styles from './styles.styl'
10
-
11
- const RemainingTime = ({ durationInSec }) => {
12
- const { t } = useI18n()
13
-
14
- return (
15
- <Typography
16
- variant="caption"
17
- className={cx(styles['upload-queue__progress-caption'], 'u-ellipsis')}
18
- >
19
- {t('item.remainingTime', {
20
- time: formatRemainingTime(durationInSec),
21
- smart_count: numberOfReferencesForPluralForm(durationInSec)
22
- })}
23
- </Typography>
24
- )
25
- }
26
-
27
- export default RemainingTime
@@ -1,3 +0,0 @@
1
- // https://date-fns.org/v2.28.0/docs/formatDistanceToNow
2
- export const numberOfReferencesForPluralForm = durationInSec =>
3
- durationInSec < 90 || (durationInSec > 2670 && durationInSec < 5370) ? 1 : 2
@@ -1,160 +0,0 @@
1
- import cx from 'classnames'
2
- import React, { Component } from 'react'
3
-
4
- import LinearProgress from 'cozy-ui/transpiled/react/LinearProgress'
5
- import List from 'cozy-ui/transpiled/react/List'
6
- import Typography from 'cozy-ui/transpiled/react/Typography'
7
- import Button from 'cozy-ui/transpiled/react/deprecated/Button'
8
- import { withStyles } from 'cozy-ui/transpiled/react/styles'
9
- import { formatLocallyDistanceToNow, withLocales } from 'twake-i18n'
10
-
11
- import Item from './Item'
12
- import localeEn from './locales/en.json'
13
- import localeEs from './locales/es.json'
14
- import localeFr from './locales/fr.json'
15
- import localeRu from './locales/ru.json'
16
- import localeVi from './locales/vi.json'
17
- import styles from './styles.styl'
18
-
19
- const locales = {
20
- en: localeEn,
21
- es: localeEs,
22
- fr: localeFr,
23
- ru: localeRu,
24
- vi: localeVi
25
- }
26
-
27
- const CANCEL = 'cancel'
28
- const PENDING = 'pending'
29
- const LOADING = 'loading'
30
- const CREATED = 'created'
31
- const UPDATED = 'updated'
32
- const FAILED = 'failed'
33
- const CONFLICT = 'conflict'
34
- const QUOTA = 'quota'
35
- const NETWORK = 'network'
36
- const DONE_STATUSES = [CREATED, UPDATED]
37
- const ERROR_STATUSES = [CONFLICT, NETWORK, QUOTA, FAILED]
38
-
39
- export const uploadStatus = {
40
- CANCEL,
41
- PENDING,
42
- LOADING,
43
- CREATED,
44
- UPDATED,
45
- FAILED,
46
- CONFLICT,
47
- QUOTA,
48
- NETWORK,
49
- DONE_STATUSES,
50
- ERROR_STATUSES
51
- }
52
-
53
- export const formatRemainingTime = durationInSec => {
54
- const later = Date.now() + durationInSec * 1000
55
- return formatLocallyDistanceToNow(later)
56
- }
57
-
58
- const QueueLinearProgress = withStyles({
59
- root: {
60
- height: '2px'
61
- }
62
- })(LinearProgress)
63
-
64
- export class UploadQueue extends Component {
65
- state = {
66
- collapsed: false
67
- }
68
-
69
- toggleCollapsed = () => {
70
- this.setState(state => ({ collapsed: !state.collapsed }))
71
- }
72
-
73
- render() {
74
- const {
75
- t,
76
- queue,
77
- doneCount,
78
- successCount,
79
- purgeQueue,
80
- popover,
81
- getMimeTypeIcon,
82
- app
83
- } = this.props
84
- const { collapsed } = this.state
85
- return (
86
- <div
87
- data-testid="upload-queue"
88
- className={cx(styles['upload-queue'], {
89
- [styles['upload-queue--visible']]: queue.length !== 0,
90
- [styles['upload-queue--collapsed']]: collapsed,
91
- [styles['upload-queue--popover']]: popover
92
- })}
93
- >
94
- <h4
95
- className={styles['upload-queue-header']}
96
- onDoubleClick={this.toggleCollapsed}
97
- >
98
- {doneCount < queue.length && (
99
- <div className={styles['upload-queue-header-inner']}>
100
- <Typography variant="h6" className="u-hide--mob">
101
- {t('header', { smart_count: queue.length, app: app })}
102
- </Typography>
103
- <Typography
104
- color="primary"
105
- variant="h6"
106
- className="u-hide--tablet"
107
- >
108
- {t('header_mobile', {
109
- done: doneCount,
110
- smart_count: queue.length
111
- })}
112
- </Typography>
113
- </div>
114
- )}
115
- {doneCount >= queue.length && (
116
- <div
117
- data-testid="upload-queue-success"
118
- className={styles['upload-queue-header-inner']}
119
- >
120
- <Typography variant="h6">
121
- {t('header_done', {
122
- done: successCount,
123
- smart_count: queue.length
124
- })}
125
- </Typography>
126
- <Button
127
- subtle
128
- className="u-mv-0"
129
- label={t('close')}
130
- onClick={purgeQueue}
131
- />
132
- </div>
133
- )}
134
- </h4>
135
- <QueueLinearProgress
136
- variant="determinate"
137
- value={(doneCount / queue.length) * 100}
138
- />
139
- <div className={styles['upload-queue-content']}>
140
- <List className="u-pv-0">
141
- {queue.map((item, index) => (
142
- <Item key={index} {...item} getMimeTypeIcon={getMimeTypeIcon} />
143
- ))}
144
- </List>
145
- </div>
146
- </div>
147
- )
148
- }
149
- }
150
-
151
- UploadQueue.defaultProps = {
152
- /**
153
- * @type {Boolean}
154
- * Displays the queue in a popover at the bottom right of the screen
155
- * Use false to disable
156
- */
157
- popover: true
158
- }
159
-
160
- export default withLocales(locales)(UploadQueue)
@@ -1,177 +0,0 @@
1
- import { render } from '@testing-library/react'
2
- import React from 'react'
3
-
4
- import DemoProvider from 'cozy-ui/transpiled/react/providers/DemoProvider'
5
-
6
- import { UploadQueue, formatRemainingTime } from '.'
7
- import localeEn from './locales/en.json'
8
-
9
- describe('UploadQueue', () => {
10
- describe('formatRemainingTime', () => {
11
- it('should return correct remaining time', () => {
12
- const time = formatRemainingTime(29)
13
-
14
- expect(time).toEqual('less than a minute')
15
- })
16
- })
17
-
18
- describe('UploadQueue', () => {
19
- it('should set singular value when "1 minute remaining"', () => {
20
- const item = {
21
- file: { name: 'file' },
22
- status: 'status',
23
- isDirectory: 'isDirectory',
24
- progress: { loaded: 1234, total: 5678, remainingTime: 89 },
25
- getMimeTypeIcon: 'getMimeTypeIcon'
26
- }
27
-
28
- const { container } = render(
29
- <DemoProvider dictRequire={() => localeEn}>
30
- <UploadQueue queue={[item]} />
31
- </DemoProvider>
32
- )
33
-
34
- expect(
35
- container.getElementsByClassName('u-flex-shrink')[0]
36
- ).toHaveTextContent('1 minute remaining')
37
- })
38
-
39
- it('should set singular value when "moins d 1 minute remaining"', () => {
40
- const item = {
41
- file: { name: 'file' },
42
- status: 'status',
43
- isDirectory: 'isDirectory',
44
- progress: { loaded: 1234, total: 5678, remainingTime: 29 },
45
- getMimeTypeIcon: 'getMimeTypeIcon'
46
- }
47
-
48
- const { container } = render(
49
- <DemoProvider dictRequire={() => localeEn}>
50
- <UploadQueue queue={[item]} />
51
- </DemoProvider>
52
- )
53
-
54
- expect(
55
- container.getElementsByClassName('u-flex-shrink')[0]
56
- ).toHaveTextContent('less than a minute remaining')
57
- })
58
-
59
- it('should set plural value when "44 minutes remainings"', () => {
60
- const item = {
61
- file: { name: 'file' },
62
- status: 'status',
63
- isDirectory: 'isDirectory',
64
- progress: { loaded: 1234, total: 5678, remainingTime: 2669 },
65
- getMimeTypeIcon: 'getMimeTypeIcon'
66
- }
67
-
68
- const { container } = render(
69
- <DemoProvider dictRequire={() => localeEn}>
70
- <UploadQueue queue={[item]} />
71
- </DemoProvider>
72
- )
73
-
74
- expect(
75
- container.getElementsByClassName('u-flex-shrink')[0]
76
- ).toHaveTextContent('44 minutes remaining')
77
- })
78
-
79
- it('should set singular value when "1 hour remaining" - low limit', () => {
80
- const item = {
81
- file: { name: 'file' },
82
- status: 'status',
83
- isDirectory: 'isDirectory',
84
- progress: { loaded: 1234, total: 5678, remainingTime: 2671 },
85
- getMimeTypeIcon: 'getMimeTypeIcon'
86
- }
87
-
88
- const { container } = render(
89
- <DemoProvider dictRequire={() => localeEn}>
90
- <UploadQueue queue={[item]} />
91
- </DemoProvider>
92
- )
93
-
94
- expect(
95
- container.getElementsByClassName('u-flex-shrink')[0]
96
- ).toHaveTextContent('about 1 hour remaining')
97
- })
98
-
99
- it('should set singular value when "about 1 hour remaining" - high limit', () => {
100
- const item = {
101
- file: { name: 'file' },
102
- status: 'status',
103
- isDirectory: 'isDirectory',
104
- progress: { loaded: 1234, total: 5678, remainingTime: 5369 },
105
- getMimeTypeIcon: 'getMimeTypeIcon'
106
- }
107
-
108
- const { container } = render(
109
- <DemoProvider dictRequire={() => localeEn}>
110
- <UploadQueue queue={[item]} />
111
- </DemoProvider>
112
- )
113
-
114
- expect(
115
- container.getElementsByClassName('u-flex-shrink')[0]
116
- ).toHaveTextContent('about 1 hour remaining')
117
- })
118
-
119
- it('should set plural value when more than "2 hours remainings"', () => {
120
- const item = {
121
- file: { name: 'file' },
122
- status: 'status',
123
- isDirectory: 'isDirectory',
124
- progress: { loaded: 1234, total: 5678, remainingTime: 5371 },
125
- getMimeTypeIcon: 'getMimeTypeIcon'
126
- }
127
-
128
- const { container } = render(
129
- <DemoProvider dictRequire={() => localeEn}>
130
- <UploadQueue queue={[item]} />
131
- </DemoProvider>
132
- )
133
-
134
- expect(
135
- container.getElementsByClassName('u-flex-shrink')[0]
136
- ).toHaveTextContent('about 2 hours remaining')
137
- })
138
-
139
- it('should not update time and bar everytime loaded/remaining time update', () => {
140
- const item = (remainingTime, loaded) => ({
141
- file: { name: 'file' },
142
- status: 'status',
143
- isDirectory: 'isDirectory',
144
- progress: { loaded, total: 4936, remainingTime },
145
- getMimeTypeIcon: 'getMimeTypeIcon'
146
- })
147
-
148
- const { rerender, getAllByRole, container } = render(
149
- <DemoProvider dictRequire={() => localeEn}>
150
- <UploadQueue queue={[item(5371, 1234)]} />
151
- </DemoProvider>
152
- )
153
-
154
- expect(
155
- container.getElementsByClassName('u-flex-shrink')[0]
156
- ).toHaveTextContent('about 2 hours remaining')
157
- expect(getAllByRole('progressbar')[1]).toHaveAttribute(
158
- 'aria-valuenow',
159
- '25'
160
- )
161
-
162
- rerender(
163
- <DemoProvider dictRequire={() => localeEn}>
164
- <UploadQueue queue={[item(1, 5677)]} />
165
- </DemoProvider>
166
- )
167
-
168
- expect(
169
- container.getElementsByClassName('u-flex-shrink')[0]
170
- ).toHaveTextContent('about 2 hours remaining')
171
- expect(getAllByRole('progressbar')[1]).toHaveAttribute(
172
- 'aria-valuenow',
173
- '25'
174
- )
175
- })
176
- })
177
- })
@@ -1,10 +0,0 @@
1
- {
2
- "header": "Uploading %{smart_count} photo to %{app} |||| Uploading %{smart_count} photos to %{app}",
3
- "header_mobile": "Uploading %{done} of %{smart_count}",
4
- "header_done": "Uploaded %{done} out of %{smart_count} successfully",
5
- "close": "close",
6
- "item": {
7
- "pending": "Pending",
8
- "remainingTime": "%{time} remaining"
9
- }
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "header": "Subiendo %{smart_count} foto a %{app} |||| Subiendo %{smart_count} fotos a %{app}",
3
- "header_mobile": "Subiendo %{done} de %{smart_count}",
4
- "header_done": "Subidos %{done} de %{smart_count} con éxito",
5
- "close": "cerrar",
6
- "item": {
7
- "pending": "Pendiente",
8
- "remainingTime": "%{time} restante |||| %{time} restantes"
9
- }
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "header": "Import de %{smart_count} fichier dans votre %{app} |||| Import de %{smart_count} fichiers dans votre %{app}",
3
- "header_mobile": "Import de %{done} sur %{smart_count}",
4
- "header_done": "%{done} sur %{smart_count} élément importé |||| %{done} sur %{smart_count} éléments importés",
5
- "close": "Fermer",
6
- "item": {
7
- "pending": "En attente",
8
- "remainingTime": "%{time} restante |||| %{time} restantes"
9
- }
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "header": "Загрузка %{smart_count} фото в %{app} |||| Загрузка %{smart_count} фото в %{app}",
3
- "header_mobile": "Загружено %{done} из %{smart_count}",
4
- "header_done": "Успешно загружено %{done} из %{smart_count}",
5
- "close": "закрыть",
6
- "item": {
7
- "pending": "В ожидании",
8
- "remainingTime": "Осталось %{time}"
9
- }
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "header": "Đang tải lên %{smart_count} ảnh vào %{app} |||| Đang tải lên %{smart_count} ảnh vào %{app}",
3
- "header_mobile": "Đã tải lên %{done} trong số %{smart_count}",
4
- "header_done": "Đã tải lên thành công %{done} trong số %{smart_count}",
5
- "close": "đóng",
6
- "item": {
7
- "pending": "Đang chờ",
8
- "remainingTime": "Còn lại %{time}"
9
- }
10
- }
@@ -1,155 +0,0 @@
1
- @require 'settings/icons.styl'
2
- @require 'settings/breakpoints.styl'
3
- @require 'settings/spaces.styl'
4
- @require 'settings/typography.styl'
5
-
6
- $coz-bar-size=3rem
7
-
8
- .upload-queue
9
- border .0625rem solid var(--dividerColor)
10
- border-radius .5rem
11
- background-color var(--paperBackgroundColor)
12
- display flex
13
- flex-direction column
14
- max-width 90%
15
- width 30rem
16
- overflow hidden
17
-
18
- .upload-queue__threshold-bar
19
- min-width 10rem
20
- margin-right 1rem
21
-
22
- .upload-queue__progress-caption
23
- line-height $caption-font-size
24
- height 1rem
25
-
26
- .upload-queue__upload-progress
27
- align-items center
28
- display flex
29
- margin-top 0.125rem // Must tweak a bit the margin-top
30
-
31
-
32
- .upload-queue--popover
33
- z-index var(--zIndex-popover)
34
- border rem(1) solid var(--dividerColor)
35
- border-radius .5rem
36
- box-shadow rem(0 1 3 0) rgba(50, 54, 63, .19), rem(0 6 18 0) rgba(50, 54, 63, .19)
37
- background-color var(--paperBackgroundColor)
38
- position fixed
39
- bottom .5rem
40
- right 1.5rem
41
- height 13.125rem
42
- transform translateY(18.75rem)
43
- transition 0.5s
44
- opacity 0
45
- visibility hidden
46
-
47
-
48
- .upload-queue--popover.upload-queue--visible
49
- opacity 1
50
- visibility visible
51
- transform translate(0)
52
-
53
- .upload-queue-header
54
- display flex
55
- flex-direction column
56
- justify-content center
57
- height 2rem
58
- min-height 2rem
59
- background-color var(--defaultBackgroundColor)
60
- font-weight bold
61
- margin 0
62
- padding .5rem 1rem .5rem
63
-
64
- .upload-queue-header-inner
65
- display flex
66
- justify-content space-between
67
- align-items center
68
-
69
-
70
- progress.upload-queue-progress
71
- -webkit-appearance none
72
- -moz-appearance none
73
- border none
74
- display block
75
- width 100%
76
- height .125rem
77
- margin 0
78
-
79
-
80
- .upload-queue-content
81
- overflow auto
82
-
83
- .upload-queue--collapsed
84
- height 2.5rem
85
-
86
- .upload-queue-content
87
- visibility none
88
-
89
- .upload-queue-list
90
- flex 1 1 auto
91
- display flex
92
- flex-direction column
93
-
94
- .upload-queue-item--error
95
- background-color var(--errorBackground)
96
-
97
- .upload-queue-item--done
98
- background-color var(--defaultBackgroundColor)
99
-
100
- .item-file
101
- user-select none
102
- overflow hidden
103
-
104
- .item-status
105
- flex 0 0 15%
106
- text-align right
107
- white-space nowrap
108
- padding-left (spacing_values.m)
109
-
110
- +medium-screen()
111
- // we need to cover the border-bottom of the cozy-bar
112
- $coz-bar-border-size = .0625rem
113
-
114
- .upload-queue
115
- border-radius 0
116
- border 0
117
- background-color var(--paperBackgroundColor)
118
- box-shadow none
119
- width 100%
120
- max-width 100%
121
- height auto
122
- transform none
123
-
124
-
125
- .upload-queue-header
126
- background 0
127
- text-transform uppercase
128
- padding .5rem
129
-
130
- .upload-queue-content
131
- display none
132
-
133
- .upload-queue--popover
134
- top $coz-bar-size
135
- bottom auto
136
- right 0
137
- left 0
138
- z-index calc(var(--zIndex-app) + 3)
139
- max-height 0
140
-
141
- &:before
142
- position fixed
143
- top $coz-bar-size - $coz-bar-border-size
144
- z-index var(--zIndex-nav)
145
- width 100%
146
- height $coz-bar-border-size
147
- content ''
148
- background var(--paperBackgroundColor)
149
-
150
- &.upload-queue--visible
151
- max-height 30%
152
-
153
- .upload-queue-content
154
- display none
155
-
@@ -1,32 +0,0 @@
1
- import React from 'react'
2
-
3
- import Icon from 'cozy-ui/transpiled/react/Icon'
4
- import CheckCircleIcon from 'cozy-ui/transpiled/react/Icons/CheckCircle'
5
- import CrossCircleIcon from 'cozy-ui/transpiled/react/Icons/CrossCircle'
6
- import WarningIcon from 'cozy-ui/transpiled/react/Icons/Warning'
7
- import Spinner from 'cozy-ui/transpiled/react/Spinner'
8
-
9
- import { uploadStatus } from './index'
10
-
11
- export const useStatusIcon = (statusToUse, progress) => {
12
- const { CANCEL, LOADING, DONE_STATUSES, ERROR_STATUSES, PENDING } =
13
- uploadStatus
14
- const SuccessIcon = CheckCircleIcon
15
- const ErrorIcon = CrossCircleIcon
16
-
17
- let statusIcon
18
-
19
- if (statusToUse === LOADING) {
20
- statusIcon = !progress ? <Spinner color="var(--primaryColor)" /> : null
21
- } else if (statusToUse === CANCEL) {
22
- statusIcon = <Icon icon={ErrorIcon} color="var(--errorColor)" />
23
- } else if (ERROR_STATUSES.includes(statusToUse)) {
24
- statusIcon = <Icon icon={WarningIcon} color="var(--errorColor)" />
25
- } else if (DONE_STATUSES.includes(statusToUse)) {
26
- statusIcon = <Icon icon={SuccessIcon} color="var(--successColor)" />
27
- } else if (statusToUse === PENDING) {
28
- statusIcon = null
29
- }
30
-
31
- return statusIcon
32
- }