cozy-ui-plus 5.3.0 → 6.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.
@@ -3,6 +3,7 @@ import get from 'lodash/get'
3
3
  import PropTypes from 'prop-types'
4
4
  import React, { useEffect, useState } from 'react'
5
5
 
6
+ import { nameToColor } from 'cozy-ui/transpiled/react/Avatar/helpers'
6
7
  import Badge from 'cozy-ui/transpiled/react/Badge'
7
8
  import Icon from 'cozy-ui/transpiled/react/Icon'
8
9
  import IconCheckAnimated from 'cozy-ui/transpiled/react/Icons/IconCheckAnimated'
@@ -10,16 +11,14 @@ import SvgIconCrossAnimated from 'cozy-ui/transpiled/react/Icons/IconCrossAnimat
10
11
  import iconOut from 'cozy-ui/transpiled/react/Icons/LinkOut'
11
12
  import iconPlus from 'cozy-ui/transpiled/react/Icons/Plus'
12
13
  import iconWarning from 'cozy-ui/transpiled/react/Icons/WarningCircle'
13
- import InfosBadge from 'cozy-ui/transpiled/react/InfosBadge'
14
14
  import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
15
15
  import Spinner from 'cozy-ui/transpiled/react/Spinner'
16
16
  import Typography from 'cozy-ui/transpiled/react/Typography'
17
- import { nameToColor } from 'cozy-ui/transpiled/react/legacy/Avatar/helpers'
18
17
  import { alpha, makeStyles } from 'cozy-ui/transpiled/react/styles'
19
18
 
20
19
  import styles from './styles.styl'
21
20
  import AppIcon from '../AppIcon'
22
- import CozyTheme, { useCozyTheme } from '../providers/CozyTheme'
21
+ import { useCozyTheme } from '../providers/CozyTheme'
23
22
 
24
23
  const makeTwakeColor = theme =>
25
24
  theme.variant === 'inverted' || theme.type === 'dark'
@@ -46,9 +45,6 @@ const useStyles = makeStyles(theme => ({
46
45
  height: '2rem'
47
46
  }
48
47
  },
49
- nameInverted: {
50
- textShadow: theme.textShadows[1]
51
- },
52
48
  squareAppIconGhost: {
53
49
  backgroundColor: alpha(
54
50
  theme.palette.primary.main,
@@ -105,7 +101,7 @@ export const SquareAppIcon = ({
105
101
  hideShortcutBadge = false,
106
102
  ...appIconProps
107
103
  }) => {
108
- const { variant: themeVariant, type } = useCozyTheme()
104
+ const { type } = useCozyTheme()
109
105
  const classes = useStyles()
110
106
  const appName =
111
107
  name || get(appIconProps, 'app.name') || get(appIconProps, 'app') || ''
@@ -124,7 +120,6 @@ export const SquareAppIcon = ({
124
120
  if (curr === 'loading' && variant === 'error') setAnimationState('failed')
125
121
 
126
122
  if (curr === 'loading' && (variant === 'default' || variant === undefined))
127
- // eslint-disable-next-line react-hooks/set-state-in-effect
128
123
  setAnimationState('success')
129
124
 
130
125
  prevVariant.current = variant
@@ -132,10 +127,6 @@ export const SquareAppIcon = ({
132
127
 
133
128
  const exceptionVariant = ['ghost']
134
129
 
135
- const squareTheme = exceptionVariant.includes(variant)
136
- ? themeVariant
137
- : 'normal'
138
-
139
130
  return (
140
131
  <div
141
132
  data-testid="square-app-icon"
@@ -143,113 +134,111 @@ export const SquareAppIcon = ({
143
134
  [classes.detailedTileWrapper]: display === 'detailed'
144
135
  })}
145
136
  >
146
- <CozyTheme variant={squareTheme}>
147
- <InfosBadge
148
- badgeContent={
149
- variant === 'shortcut' && !hideShortcutBadge ? (
137
+ <Badge
138
+ badgeContent={
139
+ variant === 'shortcut' && !hideShortcutBadge ? (
140
+ <div
141
+ className="u-h-1-half u-miw-1-half u-bdrs-circle u-flex u-flex-items-center u-flex-justify-center"
142
+ style={{
143
+ backgroundColor: 'var(--paperBackgroundColor)',
144
+ color: 'var(--iconTextColor)',
145
+ boxShadow: 'var(--shadow3)'
146
+ }}
147
+ >
150
148
  <Icon size="10" icon={iconOut} />
151
- ) : null
149
+ </div>
150
+ ) : null
151
+ }
152
+ className={cx({ ['u-mr-1']: display === 'detailed' })}
153
+ overlap="rectangular"
154
+ invisible={variant !== 'shortcut' || hideShortcutBadge}
155
+ anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
156
+ >
157
+ <SquareAppIconSpinner
158
+ variant={variant}
159
+ animationState={animationState}
160
+ />
161
+ <Badge
162
+ className={cx(
163
+ styles[`SquareAppIcon-wrapper`],
164
+ styles[`SquareAppIcon-wrapper-${variant}`],
165
+ styles[`SquareAppIcon-wrapper--${type}`],
166
+ {
167
+ [classes.squareAppIconGhost]: exceptionVariant.includes(variant),
168
+ [classes.shadow]: !exceptionVariant.includes(variant)
169
+ }
170
+ )}
171
+ badgeContent={
172
+ variant === 'error' ? (
173
+ <Icon
174
+ size={16}
175
+ className={cx(classes.errorIcon)}
176
+ icon={iconWarning}
177
+ />
178
+ ) : (
179
+ ''
180
+ )
152
181
  }
153
- className={cx({ ['u-mr-1']: display === 'detailed' })}
182
+ color={variant === 'error' ? 'error' : undefined}
183
+ withBorder={false}
184
+ size="large"
154
185
  overlap="rectangular"
155
- invisible={variant !== 'shortcut' || hideShortcutBadge}
186
+ style={
187
+ variant === 'shortcut' && !IconContent
188
+ ? {
189
+ ['background']: nameToColor(name)
190
+ }
191
+ : null
192
+ }
156
193
  >
157
- <SquareAppIconSpinner
158
- variant={variant}
159
- animationState={animationState}
160
- />
161
- <Badge
162
- className={cx(
163
- styles[`SquareAppIcon-wrapper`],
164
- styles[`SquareAppIcon-wrapper-${variant}`],
165
- styles[`SquareAppIcon-wrapper--${type}`],
166
- {
167
- [classes.squareAppIconGhost]:
168
- exceptionVariant.includes(variant),
169
- [classes.shadow]: !exceptionVariant.includes(variant)
170
- }
171
- )}
172
- badgeContent={
173
- variant === 'error' ? (
174
- <Icon
175
- size={16}
176
- className={cx(classes.errorIcon)}
177
- icon={iconWarning}
178
- />
179
- ) : (
180
- ''
181
- )
182
- }
183
- color={variant === 'error' ? 'error' : undefined}
184
- withBorder={false}
185
- size="large"
186
- overlap="rectangular"
187
- style={
188
- variant === 'shortcut' && !IconContent
189
- ? {
190
- ['background']: nameToColor(name)
191
- }
192
- : null
193
- }
194
- >
195
- {variant === 'shortcut' && !IconContent ? (
196
- <Typography
197
- className={classes.letter}
198
- variant="h2"
199
- align="center"
200
- >
201
- {letter.toUpperCase()}
202
- </Typography>
203
- ) : (
194
+ {variant === 'shortcut' && !IconContent ? (
195
+ <Typography className={classes.letter} variant="h2" align="center">
196
+ {letter.toUpperCase()}
197
+ </Typography>
198
+ ) : (
199
+ <div
200
+ className={cx(styles['SquareAppIcon-icon-container'], [
201
+ styles['SquareAppIcon-icon-container-normal']
202
+ ])}
203
+ >
204
204
  <div
205
- className={cx(styles['SquareAppIcon-icon-container'], {
206
- [styles['SquareAppIcon-icon-container-normal']]:
207
- themeVariant === 'normal'
208
- })}
205
+ className={cx(
206
+ styles['onEnd'],
207
+ { [styles['isSuccess']]: animationState === 'success' },
208
+ { [styles['isFailed']]: animationState === 'failed' }
209
+ )}
210
+ onAnimationEnd={handleAnimationEnd}
209
211
  >
210
- <div
211
- className={cx(
212
- styles['onEnd'],
213
- { [styles['isSuccess']]: animationState === 'success' },
214
- { [styles['isFailed']]: animationState === 'failed' }
215
- )}
216
- onAnimationEnd={handleAnimationEnd}
217
- >
218
- {animationState && (
219
- <Icon
220
- size={32}
221
- icon={
222
- animationState === 'success'
223
- ? IconCheckAnimated
224
- : SvgIconCrossAnimated
225
- }
226
- />
227
- )}
228
- </div>
229
-
230
- {variant === 'add' ? (
231
- <Icon icon={iconPlus} color="var(--primaryColor)" />
232
- ) : IconContent ? (
233
- IconContent
234
- ) : (
235
- <div className="u-w-2 u-h-2">
236
- <AppIcon {...appIconProps} />
237
- </div>
212
+ {animationState && (
213
+ <Icon
214
+ size={32}
215
+ icon={
216
+ animationState === 'success'
217
+ ? IconCheckAnimated
218
+ : SvgIconCrossAnimated
219
+ }
220
+ />
238
221
  )}
239
222
  </div>
240
- )}
241
- </Badge>
242
- </InfosBadge>
243
- </CozyTheme>
223
+
224
+ {variant === 'add' ? (
225
+ <Icon icon={iconPlus} color="var(--primaryColor)" />
226
+ ) : IconContent ? (
227
+ IconContent
228
+ ) : (
229
+ <div className="u-w-2 u-h-2">
230
+ <AppIcon {...appIconProps} />
231
+ </div>
232
+ )}
233
+ </div>
234
+ )}
235
+ </Badge>
236
+ </Badge>
244
237
  {display === 'detailed' ? (
245
238
  <ListItemText primary={appName} secondary={description} />
246
239
  ) : (
247
240
  <Typography
248
- className={cx(
249
- classes.name,
250
- { [classes.nameInverted]: themeVariant === 'inverted' },
251
- 'u-spacellipsis'
252
- )}
241
+ className={cx(classes.name, 'u-spacellipsis')}
253
242
  variant="h6"
254
243
  align="center"
255
244
  >
@@ -17,7 +17,6 @@ const CozyTheme = ({ ignoreCozySettings, ...props }) => {
17
17
  }
18
18
 
19
19
  CozyTheme.propTypes = {
20
- variant: PropTypes.oneOf(['normal', 'inverted']),
21
20
  /** Causes this element's children to appear as if they were direct children of the element's parent, ignoring the element itself. */
22
21
  ignoreItself: PropTypes.bool,
23
22
  /** Bypasses the request that retrieves the app's settings in order to define the theme type */
@@ -27,7 +26,6 @@ CozyTheme.propTypes = {
27
26
  }
28
27
 
29
28
  CozyTheme.defaultProps = {
30
- variant: 'normal',
31
29
  ignoreCozySettings: false,
32
30
  ignoreItself: true
33
31
  }