cozy-ui 97.0.0 → 97.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 +25 -0
- package/package.json +1 -1
- package/react/Alert/Readme.md +11 -4
- package/react/Alert/index.jsx +8 -3
- package/react/MuiCozyTheme/helpers.js +30 -44
- package/react/MuiCozyTheme/makeInvertedOverrides.js +0 -13
- package/react/MuiCozyTheme/makeOverrides.js +6 -2
- package/react/MuiCozyTheme/makePalette.js +1 -0
- package/react/PointerAlert/Readme.md +164 -0
- package/react/PointerAlert/index.jsx +114 -0
- package/react/__snapshots__/examples.spec.jsx.snap +44 -44
- package/react/index.js +1 -0
- package/transpiled/react/Alert/index.js +6 -3
- package/transpiled/react/MuiCozyTheme/helpers.js +33 -38
- package/transpiled/react/MuiCozyTheme/makeInvertedOverrides.js +0 -13
- package/transpiled/react/MuiCozyTheme/makeOverrides.js +6 -2
- package/transpiled/react/MuiCozyTheme/makePalette.js +1 -0
- package/transpiled/react/PointerAlert/index.js +154 -0
- package/transpiled/react/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
# [97.2.0](https://github.com/cozy/cozy-ui/compare/v97.1.0...v97.2.0) (2023-11-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **PointerAlert:** Reserve space for arrow ([3d7e4b4](https://github.com/cozy/cozy-ui/commit/3d7e4b4))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **PointerAlert:** Make arrow position customisable ([2ed2cac](https://github.com/cozy/cozy-ui/commit/2ed2cac))
|
|
12
|
+
|
|
13
|
+
# [97.1.0](https://github.com/cozy/cozy-ui/compare/v97.0.0...v97.1.0) (2023-11-28)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **Alert:** Adjust colors ([29a3b80](https://github.com/cozy/cozy-ui/commit/29a3b80))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* **MuiPalette:** Add `theme.palette.background.contrastOpacity` ([a09926b](https://github.com/cozy/cozy-ui/commit/a09926b))
|
|
24
|
+
* **PointerAlert:** Add this new component based on Alert ([9d73f68](https://github.com/cozy/cozy-ui/commit/9d73f68))
|
|
25
|
+
|
|
1
26
|
# [97.0.0](https://github.com/cozy/cozy-ui/compare/v96.2.0...v97.0.0) (2023-11-28)
|
|
2
27
|
|
|
3
28
|
|
package/package.json
CHANGED
package/react/Alert/Readme.md
CHANGED
|
@@ -17,6 +17,7 @@ const initialVariants = [{
|
|
|
17
17
|
square: false,
|
|
18
18
|
actionOne: false,
|
|
19
19
|
actionTwo: false,
|
|
20
|
+
filled: false,
|
|
20
21
|
close: false
|
|
21
22
|
}]
|
|
22
23
|
|
|
@@ -26,6 +27,7 @@ const initialVariants = [{
|
|
|
26
27
|
{variant => (
|
|
27
28
|
<Alert
|
|
28
29
|
color={variant.color ? "#EFA82D" : undefined}
|
|
30
|
+
variant={variant.filled ? 'filled' : undefined}
|
|
29
31
|
block={variant.block}
|
|
30
32
|
square={variant.square}
|
|
31
33
|
icon={variant.noIcon ? false : variant.largeIcon ? <Icon icon={DeviceLaptopIcon} color="var(--errorColor)" size={32} /> : undefined}
|
|
@@ -81,7 +83,7 @@ const makeButtonColor = color => ['primary', 'secondary'].includes(color) ? unde
|
|
|
81
83
|
)}
|
|
82
84
|
onClose={variant.close ? () => {} : undefined}
|
|
83
85
|
>
|
|
84
|
-
{variant.title && <AlertTitle>{color
|
|
86
|
+
{variant.title && <AlertTitle>{color}</AlertTitle>}
|
|
85
87
|
This is a {color} alert
|
|
86
88
|
</Alert>
|
|
87
89
|
</div>
|
|
@@ -97,11 +99,16 @@ const makeButtonColor = color => ['primary', 'secondary'].includes(color) ? unde
|
|
|
97
99
|
severity={color}
|
|
98
100
|
block={variant.block}
|
|
99
101
|
action={variant.close ? undefined : (
|
|
100
|
-
<Button
|
|
102
|
+
<Button
|
|
103
|
+
variant='text'
|
|
104
|
+
style={{ color: `var(--${color}ContrastTextColor)` }}
|
|
105
|
+
size="small"
|
|
106
|
+
label="ACTION"
|
|
107
|
+
/>
|
|
101
108
|
)}
|
|
102
109
|
onClose={variant.close ? () => {} : undefined}
|
|
103
110
|
>
|
|
104
|
-
{variant.title && <AlertTitle>{color
|
|
111
|
+
{variant.title && <AlertTitle>{color}</AlertTitle>}
|
|
105
112
|
This is a {color} alert
|
|
106
113
|
</Alert>
|
|
107
114
|
</div>
|
|
@@ -121,7 +128,7 @@ const makeButtonColor = color => ['primary', 'secondary'].includes(color) ? unde
|
|
|
121
128
|
)}
|
|
122
129
|
onClose={variant.close ? () => {} : undefined}
|
|
123
130
|
>
|
|
124
|
-
{variant.title && <AlertTitle>{color
|
|
131
|
+
{variant.title && <AlertTitle>{color}</AlertTitle>}
|
|
125
132
|
This is a {color} alert
|
|
126
133
|
</Alert>
|
|
127
134
|
</div>
|
package/react/Alert/index.jsx
CHANGED
|
@@ -57,6 +57,7 @@ const Alert = forwardRef(
|
|
|
57
57
|
},
|
|
58
58
|
ref
|
|
59
59
|
) => {
|
|
60
|
+
// as primary and secondary doesn't exist on Mui Alert, we force success severity for those
|
|
60
61
|
const madeSeverity = ['primary', 'secondary'].includes(severity)
|
|
61
62
|
? 'success'
|
|
62
63
|
: severity
|
|
@@ -70,7 +71,7 @@ const Alert = forwardRef(
|
|
|
70
71
|
style={{ backgroundColor: color, borderRadius: square && 0 }}
|
|
71
72
|
className={cx(
|
|
72
73
|
className,
|
|
73
|
-
`
|
|
74
|
+
`cozyStyles-${severity}-${variant}`,
|
|
74
75
|
{ block },
|
|
75
76
|
{ action: Boolean(action) }
|
|
76
77
|
)}
|
|
@@ -90,7 +91,7 @@ const Alert = forwardRef(
|
|
|
90
91
|
|
|
91
92
|
Alert.displayName = 'Alert'
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
export const AlertPropTypes = {
|
|
94
95
|
className: PropTypes.string,
|
|
95
96
|
icon: PropTypes.oneOfType([PropTypes.element, PropTypes.bool]),
|
|
96
97
|
severity: PropTypes.oneOf([
|
|
@@ -107,11 +108,15 @@ Alert.propTypes = {
|
|
|
107
108
|
variant: PropTypes.oneOf(['standard', 'outlined', 'filled'])
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
|
|
111
|
+
export const AlertDefaultProps = {
|
|
111
112
|
severity: 'primary',
|
|
112
113
|
block: false,
|
|
113
114
|
square: false,
|
|
114
115
|
variant: 'standard'
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
Alert.propTypes = AlertPropTypes
|
|
119
|
+
|
|
120
|
+
Alert.defaultProps = AlertDefaultProps
|
|
121
|
+
|
|
117
122
|
export default Alert
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import { alpha
|
|
1
|
+
import { alpha } from '../styles'
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export const makeAlertBackgroundColor = ({ theme, severity }) => ({
|
|
4
|
+
standard: alpha(
|
|
5
|
+
theme.palette[severity].main,
|
|
6
|
+
theme.palette.background.contrastOpacity
|
|
7
|
+
),
|
|
8
|
+
outlined: theme.palette[severity].main,
|
|
9
|
+
filled: theme.palette[severity].main
|
|
10
|
+
})
|
|
8
11
|
|
|
12
|
+
export const makeAlertColor = (theme, severity) => {
|
|
9
13
|
// same approach as Mui, see https://github.com/mui/material-ui/blob/v4.x/packages/material-ui-lab/src/Alert/Alert.js#L28
|
|
10
14
|
return {
|
|
11
15
|
'&-standard': {
|
|
12
|
-
color:
|
|
13
|
-
backgroundColor:
|
|
16
|
+
color: theme.palette.text.primary,
|
|
17
|
+
backgroundColor: makeAlertBackgroundColor({ theme, severity }).standard,
|
|
14
18
|
'& $icon': {
|
|
15
|
-
color:
|
|
19
|
+
color:
|
|
20
|
+
severity === 'secondary'
|
|
21
|
+
? theme.palette.text.primary
|
|
22
|
+
: theme.palette[severity].main
|
|
16
23
|
},
|
|
17
24
|
'& $action': {
|
|
18
25
|
'& button[title="Close"]': {
|
|
@@ -21,45 +28,24 @@ export const makeAlertColor = (theme, color) => {
|
|
|
21
28
|
}
|
|
22
29
|
},
|
|
23
30
|
'&-outlined': {
|
|
24
|
-
color:
|
|
25
|
-
border: `1px solid ${
|
|
31
|
+
color: theme.palette.text.primary,
|
|
32
|
+
border: `1px solid ${
|
|
33
|
+
makeAlertBackgroundColor({ theme, severity }).outlined
|
|
34
|
+
}`,
|
|
26
35
|
'& $icon': {
|
|
27
|
-
color:
|
|
36
|
+
color:
|
|
37
|
+
severity === 'secondary'
|
|
38
|
+
? theme.palette.text.primary
|
|
39
|
+
: theme.palette[severity].main
|
|
28
40
|
}
|
|
29
41
|
},
|
|
30
42
|
'&-filled': {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
43
|
+
color: theme.palette[severity].contrastText,
|
|
44
|
+
backgroundColor: makeAlertBackgroundColor({ theme, severity }).filled,
|
|
45
|
+
'& $action': {
|
|
46
|
+
'& button[title="Close"]': {
|
|
47
|
+
color: theme.palette[severity].contrastText
|
|
48
|
+
}
|
|
63
49
|
}
|
|
64
50
|
}
|
|
65
51
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import merge from 'lodash/merge'
|
|
2
2
|
|
|
3
|
-
import { makeAlertInvertedColor } from './helpers'
|
|
4
3
|
import { makeOverrides } from './makeOverrides'
|
|
5
4
|
|
|
6
5
|
export const makeInvertedOverrides = invertedTheme => {
|
|
@@ -28,18 +27,6 @@ export const makeInvertedOverrides = invertedTheme => {
|
|
|
28
27
|
backgroundColor: 'rgba(255,255,255,0.2)'
|
|
29
28
|
}
|
|
30
29
|
},
|
|
31
|
-
MuiAlert: {
|
|
32
|
-
root: {
|
|
33
|
-
'&.cozyAlert': {
|
|
34
|
-
'&-primary': makeAlertInvertedColor(invertedTheme, 'primary'),
|
|
35
|
-
'&-secondary': makeAlertInvertedColor(invertedTheme, 'secondary'),
|
|
36
|
-
'&-success': makeAlertInvertedColor(invertedTheme, 'success'),
|
|
37
|
-
'&-error': makeAlertInvertedColor(invertedTheme, 'error'),
|
|
38
|
-
'&-warning': makeAlertInvertedColor(invertedTheme, 'warning'),
|
|
39
|
-
'&-info': makeAlertInvertedColor(invertedTheme, 'info')
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
30
|
MuiSnackbarContent: {
|
|
44
31
|
root: {
|
|
45
32
|
backgroundColor: invertedTheme.palette.grey[200]
|
|
@@ -760,9 +760,13 @@ export const makeOverrides = theme => ({
|
|
|
760
760
|
MuiAlert: {
|
|
761
761
|
root: {
|
|
762
762
|
padding: '8px 16px',
|
|
763
|
-
'&.
|
|
763
|
+
'&.cozyStyles': {
|
|
764
764
|
'&-primary': makeAlertColor(theme, 'primary'),
|
|
765
|
-
'&-secondary': makeAlertColor(theme, 'secondary')
|
|
765
|
+
'&-secondary': makeAlertColor(theme, 'secondary'),
|
|
766
|
+
'&-success': makeAlertColor(theme, 'success'),
|
|
767
|
+
'&-error': makeAlertColor(theme, 'error'),
|
|
768
|
+
'&-warning': makeAlertColor(theme, 'warning'),
|
|
769
|
+
'&-info': makeAlertColor(theme, 'info')
|
|
766
770
|
},
|
|
767
771
|
'& $icon': {
|
|
768
772
|
paddingTop: '9px'
|
|
@@ -124,6 +124,7 @@ export const makePalette = type => {
|
|
|
124
124
|
default: getCssValue('defaultBackgroundColor'),
|
|
125
125
|
paper: getCssValue('paperBackgroundColor'),
|
|
126
126
|
contrast: getCssValue('contrastBackgroundColor'),
|
|
127
|
+
contrastOpacity: type === 'dark' ? 0.24 : 0.12,
|
|
127
128
|
selected: '#F5FAFF' // deprecated, should be removed. Use action.selected instead
|
|
128
129
|
}
|
|
129
130
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Displays a Alert with an Arrow pointing to a direction (top, right, bottom, left). It is essentially based on Alert so it inherits its props and defaultProps.
|
|
2
|
+
|
|
3
|
+
### Basic usage
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
import PointerAlert from 'cozy-ui/transpiled/react/PointerAlert'
|
|
7
|
+
|
|
8
|
+
<PointerAlert direction="bottom" severity="primary">
|
|
9
|
+
Your PointerAlert content
|
|
10
|
+
</PointerAlert>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Demo
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import PointerAlert from 'cozy-ui/transpiled/react/PointerAlert'
|
|
17
|
+
import AlertTitle from 'cozy-ui/transpiled/react/AlertTitle'
|
|
18
|
+
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
19
|
+
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
20
|
+
import TextField from 'cozy-ui/transpiled/react/TextField'
|
|
21
|
+
import Variants from 'cozy-ui/docs/components/Variants'
|
|
22
|
+
import DeviceLaptopIcon from 'cozy-ui/transpiled/react/Icons/DeviceLaptop'
|
|
23
|
+
import DownloadIcon from 'cozy-ui/transpiled/react/Icons/Download'
|
|
24
|
+
|
|
25
|
+
const initialVariants = [{
|
|
26
|
+
longText: false,
|
|
27
|
+
title: false,
|
|
28
|
+
block: true,
|
|
29
|
+
color: false,
|
|
30
|
+
largeIcon: false,
|
|
31
|
+
noIcon: false,
|
|
32
|
+
square: false,
|
|
33
|
+
actionOne: true,
|
|
34
|
+
actionTwo: false,
|
|
35
|
+
close: false
|
|
36
|
+
}]
|
|
37
|
+
|
|
38
|
+
const directions = ['top', 'bottom', 'left', 'right']
|
|
39
|
+
|
|
40
|
+
const initialState = {
|
|
41
|
+
position: '50%'
|
|
42
|
+
}
|
|
43
|
+
const handleChangePosition = el => {
|
|
44
|
+
setState({ position: el.target.value })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
;
|
|
48
|
+
|
|
49
|
+
<Variants initialVariants={initialVariants} screenshotAllVariants>
|
|
50
|
+
{variant => (
|
|
51
|
+
<>
|
|
52
|
+
<div>
|
|
53
|
+
<TextField
|
|
54
|
+
className="u-mb-1-half"
|
|
55
|
+
type="string"
|
|
56
|
+
margin="dense"
|
|
57
|
+
label="position"
|
|
58
|
+
variant="outlined"
|
|
59
|
+
helperText="Arrow position"
|
|
60
|
+
onChange={handleChangePosition}
|
|
61
|
+
value={state.position}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
{directions.map(direction =>
|
|
65
|
+
<div className="u-mb-half" key={direction}>
|
|
66
|
+
<PointerAlert
|
|
67
|
+
direction={direction}
|
|
68
|
+
position={state.position}
|
|
69
|
+
color={variant.color ? "#EFA82D" : undefined}
|
|
70
|
+
block={variant.block}
|
|
71
|
+
square={variant.square}
|
|
72
|
+
icon={variant.noIcon ? false : variant.largeIcon ? <Icon icon={DeviceLaptopIcon} color="var(--errorColor)" size={32} /> : undefined}
|
|
73
|
+
action={(variant.actionOne || variant.actionTwo) ?
|
|
74
|
+
<>
|
|
75
|
+
{variant.actionOne &&
|
|
76
|
+
<Button variant="text" size="small" label="Download" startIcon={<Icon icon={DownloadIcon} />} />
|
|
77
|
+
}
|
|
78
|
+
{variant.actionTwo &&
|
|
79
|
+
<Button variant="text" size="small" label="No, thanks!" />
|
|
80
|
+
}
|
|
81
|
+
</>
|
|
82
|
+
: undefined
|
|
83
|
+
}
|
|
84
|
+
onClose={variant.close ? () => {} : undefined}
|
|
85
|
+
>
|
|
86
|
+
{variant.title && <AlertTitle>This is the title</AlertTitle>}
|
|
87
|
+
{variant.longText
|
|
88
|
+
? content.ada.short
|
|
89
|
+
: "Get Cozy Drive for Desktop and synchronise your files safely to make them accessible at all times."
|
|
90
|
+
}
|
|
91
|
+
</PointerAlert>
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
</>
|
|
95
|
+
)}
|
|
96
|
+
</Variants>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Colors
|
|
100
|
+
|
|
101
|
+
```jsx
|
|
102
|
+
import Alert from 'cozy-ui/transpiled/react/Alert'
|
|
103
|
+
import AlertTitle from 'cozy-ui/transpiled/react/AlertTitle'
|
|
104
|
+
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
105
|
+
import Typography from 'cozy-ui/transpiled/react/Typography'
|
|
106
|
+
|
|
107
|
+
const colors = ['primary', 'secondary','success', 'error', 'warning', 'info']
|
|
108
|
+
|
|
109
|
+
const makeButtonColor = color => ['primary', 'secondary'].includes(color) ? undefined : color
|
|
110
|
+
|
|
111
|
+
;
|
|
112
|
+
|
|
113
|
+
<>
|
|
114
|
+
{colors.map(color =>
|
|
115
|
+
<div className="u-mb-half" key={color}>
|
|
116
|
+
<PointerAlert
|
|
117
|
+
severity={color}
|
|
118
|
+
action={<Button variant="text" size="small" color={makeButtonColor(color)} label="ACTION" />}
|
|
119
|
+
>
|
|
120
|
+
<AlertTitle>{color}</AlertTitle>
|
|
121
|
+
This is a {color} alert
|
|
122
|
+
</PointerAlert>
|
|
123
|
+
</div>
|
|
124
|
+
)}
|
|
125
|
+
|
|
126
|
+
<hr />
|
|
127
|
+
<Typography variant="h4" paragraph>Filled variant</Typography>
|
|
128
|
+
|
|
129
|
+
{colors.map(color =>
|
|
130
|
+
<div className="u-mb-half" key={color}>
|
|
131
|
+
<PointerAlert
|
|
132
|
+
variant="filled"
|
|
133
|
+
severity={color}
|
|
134
|
+
action={
|
|
135
|
+
<Button
|
|
136
|
+
variant='text'
|
|
137
|
+
style={{ color: `var(--${color}ContrastTextColor)` }}
|
|
138
|
+
size="small"
|
|
139
|
+
label="ACTION"
|
|
140
|
+
/>}
|
|
141
|
+
>
|
|
142
|
+
<AlertTitle>{color}</AlertTitle>
|
|
143
|
+
This is a {color} alert
|
|
144
|
+
</PointerAlert>
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
|
|
148
|
+
<hr />
|
|
149
|
+
<Typography variant="h4" paragraph>Outlined variant</Typography>
|
|
150
|
+
|
|
151
|
+
{colors.map(color =>
|
|
152
|
+
<div className="u-mb-half" key={color}>
|
|
153
|
+
<PointerAlert
|
|
154
|
+
variant="outlined"
|
|
155
|
+
severity={color}
|
|
156
|
+
action={<Button variant="text" size="small" color={makeButtonColor(color)} label="ACTION" />}
|
|
157
|
+
>
|
|
158
|
+
<AlertTitle>{color.toUpperCase()}</AlertTitle>
|
|
159
|
+
This is a {color} alert
|
|
160
|
+
</PointerAlert>
|
|
161
|
+
</div>
|
|
162
|
+
)}
|
|
163
|
+
</>
|
|
164
|
+
```
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import cx from 'classnames'
|
|
4
|
+
|
|
5
|
+
import { makeStyles } from '../styles'
|
|
6
|
+
import { makeAlertBackgroundColor } from '../MuiCozyTheme/helpers'
|
|
7
|
+
import { AlertPropTypes, AlertDefaultProps } from '../Alert'
|
|
8
|
+
|
|
9
|
+
import Alert from '../Alert'
|
|
10
|
+
|
|
11
|
+
const useStyles = makeStyles(theme => ({
|
|
12
|
+
topArrow: {
|
|
13
|
+
// create the arrow
|
|
14
|
+
borderLeft: '0.75rem solid transparent',
|
|
15
|
+
borderRight: '0.75rem solid transparent',
|
|
16
|
+
borderBottom: ({ variant, severity }) =>
|
|
17
|
+
`0.75rem solid ${makeAlertBackgroundColor({ theme, severity })[variant]}`,
|
|
18
|
+
// position the arrow
|
|
19
|
+
position: 'absolute',
|
|
20
|
+
top: '-0.75rem',
|
|
21
|
+
left: ({ position }) => position,
|
|
22
|
+
marginLeft: '-0.75rem'
|
|
23
|
+
},
|
|
24
|
+
bottomArrow: {
|
|
25
|
+
// create the arrow
|
|
26
|
+
borderLeft: '0.75rem solid transparent',
|
|
27
|
+
borderRight: '0.75rem solid transparent',
|
|
28
|
+
borderTop: ({ variant, severity }) =>
|
|
29
|
+
`0.75rem solid ${makeAlertBackgroundColor({ theme, severity })[variant]}`,
|
|
30
|
+
// position the arrow
|
|
31
|
+
position: 'absolute',
|
|
32
|
+
bottom: '-0.75rem',
|
|
33
|
+
left: ({ position }) => position,
|
|
34
|
+
marginLeft: '-0.75rem'
|
|
35
|
+
},
|
|
36
|
+
leftArrow: {
|
|
37
|
+
// create the arrow
|
|
38
|
+
borderTop: '0.75rem solid transparent',
|
|
39
|
+
borderBottom: '0.75rem solid transparent',
|
|
40
|
+
borderRight: ({ variant, severity }) =>
|
|
41
|
+
`0.75rem solid ${makeAlertBackgroundColor({ theme, severity })[variant]}`,
|
|
42
|
+
// position the arrow
|
|
43
|
+
position: 'absolute',
|
|
44
|
+
left: '-0.75rem',
|
|
45
|
+
top: ({ position }) => position,
|
|
46
|
+
marginTop: '-0.75rem'
|
|
47
|
+
},
|
|
48
|
+
rightArrow: {
|
|
49
|
+
// create the arrow
|
|
50
|
+
borderTop: '0.75rem solid transparent',
|
|
51
|
+
borderBottom: '0.75rem solid transparent',
|
|
52
|
+
borderLeft: ({ variant, severity }) =>
|
|
53
|
+
`0.75rem solid ${makeAlertBackgroundColor({ theme, severity })[variant]}`,
|
|
54
|
+
// position the arrow
|
|
55
|
+
position: 'absolute',
|
|
56
|
+
right: '-0.75rem',
|
|
57
|
+
top: ({ position }) => position,
|
|
58
|
+
marginTop: '-0.75rem'
|
|
59
|
+
},
|
|
60
|
+
topAlert: {
|
|
61
|
+
marginTop: '0.75rem'
|
|
62
|
+
},
|
|
63
|
+
bottomAlert: {
|
|
64
|
+
marginBottom: '0.75rem'
|
|
65
|
+
},
|
|
66
|
+
leftAlert: {
|
|
67
|
+
marginLeft: '0.75rem'
|
|
68
|
+
},
|
|
69
|
+
rightAlert: {
|
|
70
|
+
marginRight: '0.75rem'
|
|
71
|
+
}
|
|
72
|
+
}))
|
|
73
|
+
|
|
74
|
+
const PointerAlert = forwardRef(
|
|
75
|
+
(
|
|
76
|
+
{ className, variant, severity, children, direction, position, ...props },
|
|
77
|
+
ref
|
|
78
|
+
) => {
|
|
79
|
+
const styles = useStyles({ variant, severity, position })
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Alert
|
|
83
|
+
ref={ref}
|
|
84
|
+
className={cx(className, styles[`${direction}Alert`], 'u-pos-relative')}
|
|
85
|
+
variant={variant}
|
|
86
|
+
severity={severity}
|
|
87
|
+
{...props}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
<span className={styles[`${direction}Arrow`]}></span>
|
|
91
|
+
</Alert>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
PointerAlert.displayName = 'PointerAlert'
|
|
97
|
+
|
|
98
|
+
PointerAlert.propTypes = {
|
|
99
|
+
...AlertPropTypes,
|
|
100
|
+
/** Direction of the arrow.*/
|
|
101
|
+
direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
|
|
102
|
+
/** Position of the arrow. Can be any length or percentage value like "100px" or "30%".
|
|
103
|
+
* If you want to position the arrow on the edge, you need to pay attention to the arrow width.
|
|
104
|
+
* For example, "calc(0% + 0.75rem)" will position the arrow at the starting edge. */
|
|
105
|
+
position: PropTypes.string
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
PointerAlert.defaultProps = {
|
|
109
|
+
...AlertDefaultProps,
|
|
110
|
+
direction: 'bottom',
|
|
111
|
+
position: '50%'
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default PointerAlert
|