cozy-ui 85.0.2 → 85.2.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,28 @@
1
+ # [85.2.0](https://github.com/cozy/cozy-ui/compare/v85.1.0...v85.2.0) (2023-05-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Remove usage of theme.mixin.gutters ([faa161d](https://github.com/cozy/cozy-ui/commit/faa161d))
7
+
8
+
9
+ ### Features
10
+
11
+ * **MidEllipsis:** We can now spread any prop and ref to the first child ([8082cec](https://github.com/cozy/cozy-ui/commit/8082cec))
12
+ * Move default props def from theme creation to components ([233ea87](https://github.com/cozy/cozy-ui/commit/233ea87))
13
+
14
+ # [85.1.0](https://github.com/cozy/cozy-ui/compare/v85.0.2...v85.1.0) (2023-05-17)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * FullScreenCozyDialog on flagship ([273db8e](https://github.com/cozy/cozy-ui/commit/273db8e))
20
+
21
+
22
+ ### Features
23
+
24
+ * Add className in order to be able to target them ([8ead89c](https://github.com/cozy/cozy-ui/commit/8ead89c))
25
+
1
26
  ## [85.0.2](https://github.com/cozy/cozy-ui/compare/v85.0.1...v85.0.2) (2023-05-17)
2
27
 
3
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "85.0.2",
3
+ "version": "85.2.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -201,9 +201,47 @@ const initialVariants = [{
201
201
  withBackground: false
202
202
  }]
203
203
 
204
+ // The goal of this method is to simulate the
205
+ // immersive mode of the flagship app. So we
206
+ // add the flagship-app class to the body and
207
+ // we set 2 css variables:
208
+ // flagship-top-height
209
+ // flagship-bottom-height
210
+ const setFlagshipVars = () => {
211
+ const root = document.getElementsByTagName('body')[0]
212
+ root.style.setProperty('--flagship-top-height', "40px");
213
+ root.style.setProperty('--flagship-bottom-height', "40px");
214
+ root.classList.add('flagship-app')
215
+
216
+ const statusBarDiv = document.createElement("div");
217
+ statusBarDiv.style.cssText = "position:fixed;top:0;height:40px;z-index:10000000;background-color:red;width:100%"
218
+ // and give it some content
219
+ const statusBarDivContent = document.createTextNode("Top Status Bar with clock");
220
+
221
+ // add the text node to the newly created div
222
+ statusBarDiv.appendChild(statusBarDivContent);
223
+
224
+
225
+ const bottomBarDiv = document.createElement("div");
226
+ bottomBarDiv.style.cssText = "position:fixed;bottom:0;height:40px;z-index:10000000;background-color:red;width:100%"
227
+ // and give it some content
228
+ const bottomBarDivContent = document.createTextNode("BottomBar");
229
+
230
+ // add the text node to the newly created div
231
+ bottomBarDiv.appendChild(bottomBarDivContent);
232
+
233
+ // add the newly created element and its content into the DOM
234
+ const currentDiv = document.getElementById("rsg-root");
235
+ document.body.insertBefore(statusBarDiv, currentDiv);
236
+ document.body.insertBefore(bottomBarDiv, currentDiv);
237
+ }
204
238
  ;
205
239
 
206
240
  <BreakpointsProvider>
241
+ <Button
242
+ onClick={() => setFlagshipVars()}
243
+ variant="secondary"
244
+ label={'Simulate Immersive Flagship Mode'} />
207
245
  <Variants initialVariants={initialVariants}>
208
246
  {variant => (
209
247
  <>
@@ -71,15 +71,17 @@ const useCozyDialog = props => {
71
71
  id: `modal-title-${id}`,
72
72
  ref: titleRef,
73
73
  disableTypography: true,
74
- className: cx(
75
- {
76
- 'u-ellipsis': !isFluidTitle,
77
- dialogTitleFluid: isFluidTitle,
78
- dialogTitleWithClose: showCloseButton && !disableTitleAutoPadding,
79
- dialogTitleWithBack: showBackButton && !disableTitleAutoPadding
80
- },
81
- componentsProps?.dialogTitle?.className
82
- )
74
+ className:
75
+ 'cozyDialogTitle ' +
76
+ cx(
77
+ {
78
+ 'u-ellipsis': !isFluidTitle,
79
+ dialogTitleFluid: isFluidTitle,
80
+ dialogTitleWithClose: showCloseButton && !disableTitleAutoPadding,
81
+ dialogTitleWithBack: showBackButton && !disableTitleAutoPadding
82
+ },
83
+ componentsProps?.dialogTitle?.className
84
+ )
83
85
  }
84
86
 
85
87
  const listItemClassName = 'listItem--dialog'
@@ -108,7 +110,8 @@ const useCozyDialog = props => {
108
110
  root: cx({
109
111
  disableGutters
110
112
  })
111
- }
113
+ },
114
+ className: 'cozyDialogContent'
112
115
  }
113
116
 
114
117
  return {
@@ -1,4 +1,4 @@
1
- import React from 'react'
1
+ import React, { forwardRef } from 'react'
2
2
  import cx from 'classnames'
3
3
  import PropTypes from 'prop-types'
4
4
 
@@ -14,32 +14,34 @@ import PropTypes from 'prop-types'
14
14
  * */
15
15
  const LRM = <>&#8206;</>
16
16
 
17
- const MidEllipsis = props => {
18
- const { text, className, children } = props
19
-
20
- if (text && typeof text !== 'string')
21
- throw new Error('The "text" prop of MidEllipsis can only be a string')
22
-
23
- if (children && typeof children !== 'string')
24
- throw new Error('The children of MidEllipsis can only be a string')
25
-
26
- const str = text || children
27
-
28
- const partLength = Math.round(str.length / 2)
29
- const firstPart = str.substr(0, partLength)
30
- const lastPart = str.substr(partLength, str.length)
31
-
32
- return (
33
- <div className={cx('u-midellipsis', className)}>
34
- <span>{firstPart}</span>
35
- <span>
36
- {LRM}
37
- {lastPart}
38
- {LRM}
39
- </span>
40
- </div>
41
- )
42
- }
17
+ const MidEllipsis = forwardRef(
18
+ ({ text, className, children, ...props }, ref) => {
19
+ if (text && typeof text !== 'string')
20
+ throw new Error('The "text" prop of MidEllipsis can only be a string')
21
+
22
+ if (children && typeof children !== 'string')
23
+ throw new Error('The children of MidEllipsis can only be a string')
24
+
25
+ const str = text || children
26
+
27
+ const partLength = Math.round(str.length / 2)
28
+ const firstPart = str.substr(0, partLength)
29
+ const lastPart = str.substr(partLength, str.length)
30
+
31
+ return (
32
+ <div className={cx('u-midellipsis', className)} ref={ref} {...props}>
33
+ <span>{firstPart}</span>
34
+ <span>
35
+ {LRM}
36
+ {lastPart}
37
+ {LRM}
38
+ </span>
39
+ </div>
40
+ )
41
+ }
42
+ )
43
+
44
+ MidEllipsis.displayName = 'MidEllipsis'
43
45
 
44
46
  MidEllipsis.propTypes = {
45
47
  text: PropTypes.string,
@@ -1,9 +1,11 @@
1
1
  See [Material UI documentation](https://material-ui.com/demos/expansion-panels/) to learn more about Accordion.
2
2
 
3
3
  ```jsx
4
- import Accordion from '@material-ui/core/Accordion';
5
- import AccordionSummary from '@material-ui/core/AccordionSummary';
6
- import AccordionDetails from '@material-ui/core/AccordionDetails';
4
+ import Accordion from 'cozy-ui/transpiled/react/MuiCozyTheme/Accordion'
5
+ import AccordionSummary from 'cozy-ui/transpiled/react/MuiCozyTheme/AccordionSummary'
6
+ import AccordionDetails from 'cozy-ui/transpiled/react/MuiCozyTheme/AccordionDetails'
7
+
8
+ ;
7
9
 
8
10
  <>
9
11
  <Accordion>
@@ -1,3 +1,10 @@
1
+ import React from 'react'
1
2
  import AccordionSummary from '@material-ui/core/AccordionSummary'
2
3
 
4
+ import AccordionExpandIcon from '../AccordionExpandIcon'
5
+
6
+ AccordionSummary.defaultProps = {
7
+ expandIcon: <AccordionExpandIcon />
8
+ }
9
+
3
10
  export default AccordionSummary
@@ -0,0 +1,212 @@
1
+ import { alpha, lighten, darken } from '../styles'
2
+
3
+ export const makeAlertColor = (theme, color) => {
4
+ const themeColorByColor = {
5
+ primary: theme.palette[color].main,
6
+ secondary: theme.palette.text.primary
7
+ }
8
+
9
+ // same approach as Mui, see https://github.com/mui/material-ui/blob/v4.x/packages/material-ui-lab/src/Alert/Alert.js#L28
10
+ return {
11
+ '&-standard': {
12
+ color: darken(themeColorByColor[color], 0.6),
13
+ backgroundColor: lighten(themeColorByColor[color], 0.9),
14
+ '& $icon': {
15
+ color: themeColorByColor[color]
16
+ },
17
+ '& $action': {
18
+ '& button[title="Close"]': {
19
+ color: theme.palette.text.secondary
20
+ }
21
+ }
22
+ },
23
+ '&-outlined': {
24
+ color: darken(themeColorByColor[color], 0.6),
25
+ border: `1px solid ${themeColorByColor[color]}`,
26
+ '& $icon': {
27
+ color: themeColorByColor[color]
28
+ }
29
+ },
30
+ '&-filled': {
31
+ backgroundColor:
32
+ color === 'secondary'
33
+ ? theme.palette.grey[600]
34
+ : themeColorByColor[color]
35
+ }
36
+ }
37
+ }
38
+
39
+ export const makeAlertInvertedColor = (theme, color) => {
40
+ return {
41
+ '&-standard': {
42
+ color: theme.palette.primary.main,
43
+ backgroundColor: theme.palette.background.default,
44
+ '& $icon': {
45
+ color: theme.palette[color].main
46
+ }
47
+ },
48
+ '&-outlined': {
49
+ color: theme.palette.primary.main,
50
+ border: `1px solid ${theme.palette.primary.main}`,
51
+ '& $icon': {
52
+ color: theme.palette[color].main
53
+ }
54
+ },
55
+ '&-filled': {
56
+ color: theme.palette[color].contrastText,
57
+ backgroundColor:
58
+ color === 'secondary'
59
+ ? theme.palette.grey[200]
60
+ : theme.palette[color].main,
61
+ '& $icon': {
62
+ color: theme.palette[color].contrastText
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ export const makeChipStyleByColor = (theme, color) => ({
69
+ color: theme.palette.text[color] || theme.palette[color].main,
70
+ borderColor:
71
+ color === 'primary'
72
+ ? theme.palette.border.main
73
+ : alpha(theme.palette[color].main, theme.palette.border.opacity),
74
+ '&$clickable, &$deletable': {
75
+ '&:hover, &:focus': {
76
+ borderColor:
77
+ color === 'primary'
78
+ ? theme.palette.border.main
79
+ : alpha(theme.palette[color].main, theme.palette.border.opacity),
80
+ backgroundColor:
81
+ color === 'primary'
82
+ ? theme.palette.action.hover
83
+ : alpha(theme.palette[color].main, theme.palette.action.hoverOpacity)
84
+ }
85
+ },
86
+ '& $icon': {
87
+ color:
88
+ color === 'primary' ? theme.palette.text.icon : theme.palette[color].main,
89
+ fill:
90
+ color === 'primary' ? theme.palette.text.icon : theme.palette[color].main
91
+ },
92
+ '& $deleteIcon': {
93
+ color:
94
+ color === 'primary'
95
+ ? theme.palette.text.secondary
96
+ : theme.palette[color].main,
97
+ fill:
98
+ color === 'primary'
99
+ ? theme.palette.text.secondary
100
+ : theme.palette[color].main
101
+ },
102
+ '&$colorPrimary': {
103
+ padding: '0 1px',
104
+ color: theme.palette[color].contrastText,
105
+ backgroundColor: theme.palette[color].main,
106
+ '& $icon, & $deleteIcon': {
107
+ color: theme.palette[color].contrastText,
108
+ fill: theme.palette[color].contrastText
109
+ },
110
+ '&$disabled': {
111
+ opacity: 1,
112
+ color: theme.palette.text.disabled,
113
+ backgroundColor: theme.palette.action.disabledBackground,
114
+ '& $icon, & $deleteIcon': {
115
+ color: theme.palette.text.disabled,
116
+ fill: theme.palette.text.disabled
117
+ }
118
+ },
119
+ '&$clickable, &$deletable': {
120
+ '&:hover, &:focus': {
121
+ backgroundColor: theme.palette[color].dark
122
+ }
123
+ }
124
+ },
125
+ '&.ghost': {
126
+ borderWidth: '1px',
127
+ borderStyle: 'dashed',
128
+ '&:not($disabled)': {
129
+ color: theme.palette[color].main,
130
+ borderColor: alpha(
131
+ theme.palette[color].main,
132
+ theme.palette.border.ghostOpacity
133
+ ),
134
+ backgroundColor: alpha(
135
+ theme.palette[color].main,
136
+ theme.palette.action.ghostOpacity
137
+ ),
138
+ '& $icon, & $deleteIcon': {
139
+ color: theme.palette[color].main,
140
+ fill: theme.palette[color].main
141
+ }
142
+ },
143
+ '&$clickable, &$deletable': {
144
+ '&:hover, &:focus': {
145
+ borderColor: alpha(
146
+ theme.palette[color].main,
147
+ theme.palette.border.ghostOpacity
148
+ ),
149
+ backgroundColor: alpha(
150
+ theme.palette[color].main,
151
+ theme.palette.action.hoverGhostOpacity
152
+ )
153
+ }
154
+ }
155
+ }
156
+ })
157
+
158
+ export const makeSecondaryButtonStyle = (theme, color) => ({
159
+ color: theme.palette[color].main,
160
+ borderColor: theme.palette[color].main,
161
+ '&:hover': {
162
+ backgroundColor: alpha(
163
+ theme.palette[color].main,
164
+ theme.palette.action.hoverOpacity
165
+ ),
166
+ '@media (hover: none)': {
167
+ backgroundColor: 'transparent'
168
+ }
169
+ },
170
+ '&.ghost': {
171
+ backgroundColor: alpha(
172
+ theme.palette[color].main,
173
+ theme.palette.action.ghostOpacity
174
+ ),
175
+ '&:hover': {
176
+ backgroundColor: alpha(
177
+ theme.palette[color].main,
178
+ theme.palette.action.hoverGhostOpacity
179
+ ),
180
+ '@media (hover: none)': {
181
+ backgroundColor: alpha(
182
+ theme.palette[color].main,
183
+ theme.palette.action.ghostOpacity
184
+ )
185
+ }
186
+ }
187
+ }
188
+ })
189
+
190
+ export const makeTextButtonStyle = (theme, color) => ({
191
+ color: theme.palette[color].main,
192
+ '&:hover': {
193
+ backgroundColor: alpha(
194
+ theme.palette[color].main,
195
+ theme.palette.action.hoverOpacity
196
+ ),
197
+ '@media (hover: none)': {
198
+ backgroundColor: 'transparent'
199
+ }
200
+ }
201
+ })
202
+
203
+ export const makeContainedButtonStyle = (theme, color) => ({
204
+ color: theme.palette[color].contrastText,
205
+ backgroundColor: theme.palette[color].main,
206
+ '&:hover': {
207
+ backgroundColor: theme.palette[color].dark,
208
+ '@media (hover: none)': {
209
+ backgroundColor: theme.palette[color].main
210
+ }
211
+ }
212
+ })
@@ -0,0 +1,112 @@
1
+ import merge from 'lodash/merge'
2
+
3
+ import { makeAlertInvertedColor } from './helpers'
4
+ import { makeOverrides } from './makeOverrides'
5
+
6
+ export const makeInvertedOverrides = invertedTheme => {
7
+ const makeOverridesForInvertedTheme = invertedTheme => ({
8
+ MuiOutlinedInput: {
9
+ root: {
10
+ boxSizing: 'border-box',
11
+ '&$disabled': {
12
+ background: 'initial'
13
+ },
14
+ '&$focused $notchedOutline': {
15
+ borderColor: invertedTheme.palette.text.primary,
16
+ borderWidth: '0.0625rem'
17
+ },
18
+ '& $notchedOutline': {
19
+ borderColor: invertedTheme.palette.text.primary
20
+ }
21
+ }
22
+ },
23
+ MuiFormLabel: {
24
+ root: {
25
+ '&$focused': {
26
+ color: invertedTheme.palette.text.primary
27
+ }
28
+ }
29
+ },
30
+ MuiLinearProgress: {
31
+ colorPrimary: {
32
+ backgroundColor: 'rgba(255,255,255,0.2)'
33
+ },
34
+ colorSecondary: {
35
+ backgroundColor: 'rgba(255,255,255,0.2)'
36
+ }
37
+ },
38
+ MuiCheckbox: {
39
+ colorPrimary: {
40
+ '&$checked:not($disabled)': {
41
+ color: invertedTheme.palette.primary.light
42
+ }
43
+ },
44
+ colorSecondary: {
45
+ '&$checked:not($disabled)': {
46
+ color: invertedTheme.palette.error.main
47
+ }
48
+ }
49
+ },
50
+ MuiAlert: {
51
+ root: {
52
+ '&.cozyAlert': {
53
+ '&-primary': makeAlertInvertedColor(invertedTheme, 'primary'),
54
+ '&-secondary': makeAlertInvertedColor(invertedTheme, 'secondary'),
55
+ '&-success': makeAlertInvertedColor(invertedTheme, 'success'),
56
+ '&-error': makeAlertInvertedColor(invertedTheme, 'error'),
57
+ '&-warning': makeAlertInvertedColor(invertedTheme, 'warning'),
58
+ '&-info': makeAlertInvertedColor(invertedTheme, 'info')
59
+ }
60
+ }
61
+ },
62
+ MuiSnackbarContent: {
63
+ root: {
64
+ backgroundColor: invertedTheme.palette.grey[200]
65
+ }
66
+ },
67
+ MuiTabs: {
68
+ root: {
69
+ '&.segmented': {
70
+ '& $indicator': {
71
+ backgroundColor: invertedTheme.palette.primary.main
72
+ }
73
+ }
74
+ }
75
+ },
76
+ MuiTab: {
77
+ root: {
78
+ '&.segmented': {
79
+ '&$selected': {
80
+ color: invertedTheme.palette.primary.contrastText
81
+ }
82
+ }
83
+ }
84
+ },
85
+ MuiSwitch: {
86
+ switchBase: {
87
+ color: invertedTheme.palette.grey[100]
88
+ },
89
+ colorPrimary: {
90
+ '&$checked': {
91
+ '& + $track': {
92
+ backgroundColor: invertedTheme.palette.success.dark
93
+ }
94
+ }
95
+ },
96
+ colorSecondary: {
97
+ '&$checked': {
98
+ '& + $track': {
99
+ backgroundColor: invertedTheme.palette.success.dark
100
+ }
101
+ }
102
+ }
103
+ }
104
+ })
105
+
106
+ const invertedOverrides = merge(
107
+ makeOverrides(invertedTheme),
108
+ makeOverridesForInvertedTheme(invertedTheme)
109
+ )
110
+
111
+ return invertedOverrides
112
+ }