cozy-ui 74.7.0 → 75.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ # [75.0.0](https://github.com/cozy/cozy-ui/compare/v74.7.0...v75.0.0) (2022-09-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **DropdownText:** Icon and text was misaligned for `body1` variant ([53cd532](https://github.com/cozy/cozy-ui/commit/53cd532))
7
+
8
+
9
+ ### Features
10
+
11
+ * **DropdownButton:** Add ripple effect and some props ([cecf1f0](https://github.com/cozy/cozy-ui/commit/cecf1f0))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * **DropdownButton:** Horizontal alignment could be different. You have to use `className="u-mh-half"` if you want the old behavior.
17
+
1
18
  # [74.7.0](https://github.com/cozy/cozy-ui/compare/v74.6.1...v74.7.0) (2022-09-16)
2
19
 
3
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "74.7.0",
3
+ "version": "75.0.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -1,29 +1,77 @@
1
- This component can be used as a trigger to open menus, for example an ActionMenu component.
1
+ This component can be used as a trigger to open menus, for example an ActionMenu component. It uses `DropdownText` so you can use all its props.
2
2
 
3
3
  ```jsx
4
- import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton';
5
- import Typography from "cozy-ui/transpiled/react/Typography";
4
+ import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton'
5
+ import Typography from 'cozy-ui/transpiled/react/Typography'
6
+ import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
6
7
 
7
- <div>
8
- <div>
8
+ const variants = [
9
+ 'h1',
10
+ 'h2',
11
+ 'h3',
12
+ 'h4',
13
+ 'h5',
14
+ 'subtitle1',
15
+ 'subtitle2',
16
+ 'body1',
17
+ 'body2',
18
+ 'caption'
19
+ ]
20
+
21
+ ;
22
+
23
+ <>
24
+ <Grid container>
25
+ <Grid item xs={6}>
26
+ Default
27
+ {variants.map((variant, index) => (
28
+ <div key={index} className='u-mb-1'>
29
+ <DropdownButton textVariant={variant}>
30
+ {variant}
31
+ </DropdownButton>
32
+ </div>
33
+ ))}
34
+ </Grid>
35
+ <Grid item xs={6}>
36
+ Disabled
37
+ {variants.map((variant, index) => (
38
+ <div key={index} className='u-mb-1'>
39
+ <DropdownButton textVariant={variant} disabled>
40
+ {variant}
41
+ </DropdownButton>
42
+ </div>
43
+ ))}
44
+ </Grid>
45
+ </Grid>
46
+ <div style={{ border: '1px dashed var(--borderMainColor)', marginBottom: '1rem' }}>
9
47
  <DropdownButton>
10
- <Typography variant="h3" component="h1">Cozy</Typography>
48
+ This is a long text without ellipsis without restrictive container
11
49
  </DropdownButton>
12
50
  </div>
13
- <div>
51
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
14
52
  <DropdownButton>
15
- <Typography variant="h4">Cozy</Typography>
53
+ This is a long text without ellipsis inside a restrictive container
16
54
  </DropdownButton>
17
55
  </div>
18
- <div>
19
- <DropdownButton>
20
- <Typography variant="h5">Cozy</Typography>
56
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
57
+ <DropdownButton noWrap>
58
+ This is a long text with ellipsis inside a container
21
59
  </DropdownButton>
22
60
  </div>
23
- <div>
61
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '100%', marginBottom: '1rem' }}>
24
62
  <DropdownButton>
25
- <Typography variant="body1">Cozy</Typography>
63
+ Text with<br />breaking spaces<br />inside content
64
+ </DropdownButton>
65
+ </div>
66
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '100%', marginBottom: '1rem' }}>
67
+ <DropdownButton fullWidth spaceBetween>
68
+ Space between text and icon (fullWidth needed)
69
+ </DropdownButton>
70
+ </div>
71
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '100%' }}>
72
+ <DropdownButton fullWidth>
73
+ Full width but no space between text and icon
26
74
  </DropdownButton>
27
75
  </div>
28
- </div>
76
+ </>
29
77
  ```
@@ -1,26 +1,85 @@
1
- import React from 'react'
2
- import cx from 'classnames'
3
- import styles from './styles.styl'
4
- import Icon from '../Icon'
1
+ import React, { forwardRef } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import Button from '@material-ui/core/Button'
5
4
 
6
- import BottomIcon from 'cozy-ui/transpiled/react/Icons/Bottom'
5
+ import { makeStyles } from '../styles'
6
+ import DropdownText from '../DropdownText'
7
7
 
8
- const DropdownButton = React.forwardRef(
9
- ({ children, className, ...props }, ref) => (
10
- <button
11
- role="button"
12
- className={cx(styles['c-DropdownButton'], className)}
13
- ref={ref}
14
- {...props}
15
- >
16
- {children}
17
- <Icon
18
- icon={BottomIcon}
19
- size="12"
20
- className={styles['c-DropdownButton-Icon']}
21
- />
22
- </button>
23
- )
8
+ const useStyles = makeStyles({
9
+ root: {
10
+ height: 'auto',
11
+ width: ({ fullWidth, noWrap }) =>
12
+ fullWidth || noWrap ? `calc(100% + 16px)` : 'auto',
13
+ margin: '-8px',
14
+ padding: '8px'
15
+ },
16
+ text: {
17
+ textTransform: 'none',
18
+ textAlign: 'left'
19
+ }
20
+ })
21
+
22
+ const DropdownButton = forwardRef(
23
+ (
24
+ {
25
+ spaceBetween,
26
+ textVariant,
27
+ disabled,
28
+ fullWidth,
29
+ noWrap,
30
+ children,
31
+ className,
32
+ dropdownTextProps,
33
+ ...props
34
+ },
35
+ ref
36
+ ) => {
37
+ const { root, text } = useStyles({ fullWidth, noWrap })
38
+
39
+ return (
40
+ <Button
41
+ ref={ref}
42
+ classes={{ root, text }}
43
+ disabled={disabled}
44
+ className={className}
45
+ {...props}
46
+ >
47
+ <DropdownText
48
+ variant={textVariant}
49
+ spaceBetween={spaceBetween}
50
+ disabled={disabled}
51
+ noWrap={noWrap}
52
+ {...dropdownTextProps}
53
+ >
54
+ {children}
55
+ </DropdownText>
56
+ </Button>
57
+ )
58
+ }
24
59
  )
25
60
 
61
+ DropdownButton.defaultProps = {
62
+ spaceBetween: false,
63
+ textVariant: 'body1',
64
+ disabled: false,
65
+ fullWidth: false,
66
+ noWrap: false
67
+ }
68
+
69
+ DropdownButton.propTypes = {
70
+ /** Weither there is a space between the label and the icon */
71
+ spaceBetween: PropTypes.bool,
72
+ /** Like variant from Typography component */
73
+ textVariant: PropTypes.string,
74
+ /** Whether the component is disabled */
75
+ disabled: PropTypes.bool,
76
+ fullWidth: PropTypes.bool,
77
+ /** Whether using ellipsis on text */
78
+ noWrap: PropTypes.bool,
79
+ /** Props assigned to the DropdownText inner component */
80
+ dropdownTextProps: PropTypes.object,
81
+ className: PropTypes.string,
82
+ children: PropTypes.node
83
+ }
84
+
26
85
  export default DropdownButton
@@ -43,17 +43,30 @@ const variants = [
43
43
  ))}
44
44
  </Grid>
45
45
  </Grid>
46
- <DropdownText style={{ border: '1px solid var(--borderMainColor)', width: '150px', marginBottom: '1rem' }} color="error">
47
- This is a long text without ellipsis
48
- </DropdownText>
49
- <DropdownText noWrap style={{ border: '1px solid var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
50
- This is a long text with ellipsis
51
- </DropdownText>
52
- <DropdownText spaceBetween style={{ border: '1px solid var(--borderMainColor)', width: '100%', marginBottom: '1rem' }}>
53
- Space between text and icon
54
- </DropdownText>
55
- <DropdownText style={{ border: '1px solid var(--borderMainColor)' }}>
56
- Text with<br />breaking spaces<br />inside content
57
- </DropdownText>
46
+ <div style={{ border: '1px dashed var(--borderMainColor)', marginBottom: '1rem' }}>
47
+ <DropdownText>
48
+ This is a long text without ellipsis without restrictive container
49
+ </DropdownText>
50
+ </div>
51
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
52
+ <DropdownText>
53
+ This is a long text without ellipsis inside a restrictive container
54
+ </DropdownText>
55
+ </div>
56
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '150px', marginBottom: '1rem' }}>
57
+ <DropdownText noWrap>
58
+ This is a long text with ellipsis inside a container
59
+ </DropdownText>
60
+ </div>
61
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '100%', marginBottom: '1rem' }}>
62
+ <DropdownText>
63
+ Text with<br />breaking spaces<br />inside content
64
+ </DropdownText>
65
+ </div>
66
+ <div style={{ border: '1px dashed var(--borderMainColor)', width: '100%' }}>
67
+ <DropdownText spaceBetween>
68
+ Space between text and icon
69
+ </DropdownText>
70
+ </div>
58
71
  </>
59
72
  ```
@@ -21,6 +21,7 @@ const useStyles = makeStyles(theme => ({
21
21
  endIcon: {
22
22
  display: 'flex',
23
23
  marginLeft: '5px',
24
+ marginTop: ({ variant }) => (variant === 'body1' ? '3px' : undefined),
24
25
  color: ({ disabled }) =>
25
26
  theme.palette.text[disabled ? 'disabled' : 'primary']
26
27
  }
@@ -56,7 +57,7 @@ const DropdownText = forwardRef(
56
57
  },
57
58
  ref
58
59
  ) => {
59
- const styles = useStyles({ spaceBetween, disabled, color })
60
+ const styles = useStyles({ spaceBetween, disabled, color, variant })
60
61
 
61
62
  return (
62
63
  <div ref={ref} className={styles.container} {...props}>