@graphcommerce/next-ui 3.5.0 → 3.6.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
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.6.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/next-ui@3.5.0...@graphcommerce/next-ui@3.6.0) (2021-10-18)
7
+
8
+
9
+ ### Features
10
+
11
+ * **message-snackbar:** severity props ([c7be8a5](https://github.com/ho-nl/m2-pwa/commit/c7be8a51faf7a5937b7fab5bb352df2089ae4eea))
12
+
13
+
14
+
15
+
16
+
6
17
  # [3.5.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/next-ui@3.4.0...@graphcommerce/next-ui@3.5.0) (2021-10-18)
7
18
 
8
19
 
@@ -1,17 +1,16 @@
1
1
  import {
2
- Button,
3
2
  Fab,
4
3
  makeStyles,
5
- PropTypes,
6
4
  Snackbar,
7
5
  SnackbarContent,
8
6
  SnackbarProps,
9
7
  Theme,
8
+ Portal,
10
9
  } from '@material-ui/core'
11
10
  import clsx from 'clsx'
12
11
  import React, { useEffect, useState } from 'react'
13
- import SvgImage from '../SvgImage'
14
- import { iconClose } from '../icons'
12
+ import SvgImageSimple from '../SvgImage/SvgImageSimple'
13
+ import { iconClose, iconCheckmark, iconSadFace } from '../icons'
15
14
 
16
15
  type Size = 'normal' | 'wide'
17
16
  type Variant = 'contained' | 'pill'
@@ -42,10 +41,8 @@ const useStyles = makeStyles(
42
41
  },
43
42
  },
44
43
  rootPillLarge: {},
45
- rootPillColorPrimary: {
46
- backgroundColor: theme.palette.primary.main,
47
- color: theme.palette.primary.contrastText,
48
- },
44
+ rootPillSeverityInfo: {},
45
+ rootPillSeverityError: {},
49
46
  message: {
50
47
  width: '100%',
51
48
  padding: theme.spacings.xxs,
@@ -61,8 +58,9 @@ const useStyles = makeStyles(
61
58
  },
62
59
  },
63
60
  children: {
61
+ // display: 'flex',
64
62
  gridArea: 'children',
65
- ...theme.typography.h4,
63
+ ...theme.typography.h6,
66
64
  fontWeight: 400,
67
65
 
68
66
  '& .MuiSvgIcon-root': {
@@ -111,21 +109,26 @@ const useStyles = makeStyles(
111
109
  sticky: {
112
110
  position: 'sticky',
113
111
  },
112
+ messageIcon: {
113
+ display: 'inline-block',
114
+ marginRight: 5,
115
+ },
114
116
  }),
115
117
  { name: 'MessageSnackbar' },
116
118
  )
117
119
 
118
120
  export type MessageSnackbarImplProps = Omit<
119
121
  SnackbarProps,
120
- 'autoHideDuration' | 'onClose' | 'anchorOrigin'
122
+ 'autoHideDuration' | 'anchorOrigin' | 'color'
121
123
  > & {
122
124
  autoHide?: boolean
123
125
  sticky?: boolean
124
126
  variant?: Variant
125
127
  size?: Size
126
- color?: PropTypes.Color
128
+ severity?: 'success' | 'info' | 'warning' | 'error'
127
129
  action?: React.ReactNode
128
130
  children?: React.ReactNode
131
+ onClose?: () => void
129
132
  }
130
133
 
131
134
  export default function MessageSnackbarImpl(props: MessageSnackbarImplProps) {
@@ -134,13 +137,14 @@ export default function MessageSnackbarImpl(props: MessageSnackbarImplProps) {
134
137
  const {
135
138
  variant = 'contained',
136
139
  size = 'normal',
137
- color = 'default',
138
140
  autoHide,
139
141
  action,
140
142
  open,
141
143
  message,
142
144
  sticky,
143
145
  children,
146
+ onClose,
147
+ severity = 'info',
144
148
  ...snackbarProps
145
149
  } = props
146
150
 
@@ -150,53 +154,77 @@ export default function MessageSnackbarImpl(props: MessageSnackbarImplProps) {
150
154
  setShowSnackbar(!!open)
151
155
  }, [open])
152
156
 
157
+ const hideSnackbar = () => {
158
+ setShowSnackbar(false)
159
+ onClose?.()
160
+ }
161
+
153
162
  const clsxBonus = (base: string) => {
154
163
  const Size = size[0].toUpperCase() + size.slice(1)
155
- const Color = color[0].toUpperCase() + color.slice(1)
164
+ const Severity = severity[0].toUpperCase() + severity.slice(1)
156
165
  const Variant = variant[0].toUpperCase() + variant.slice(1)
157
166
 
158
167
  return clsx(
159
168
  classes[base],
160
169
  classes[`${base}${Variant}`],
161
170
  classes[`${base}${Variant}Size${Size}`],
162
- classes[`${base}${Variant}Color${Color}`],
171
+ classes[`${base}${Variant}Severity${Severity}`],
163
172
  )
164
173
  }
165
174
 
175
+ let icon = iconCheckmark
176
+ if (severity == 'error') icon = iconSadFace
177
+
166
178
  return (
167
- <Snackbar
168
- {...snackbarProps}
169
- message={message}
170
- anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
171
- open={showSnackbar}
172
- autoHideDuration={autoHide ? 6000 : null}
173
- classes={{
174
- root: classes.snackbarRoot,
175
- anchorOriginBottomCenter: clsx(classes.anchorOriginBottomCenter, sticky && classes.sticky),
176
- }}
177
- >
178
- <SnackbarContent
179
+ <Portal>
180
+ <Snackbar
181
+ {...snackbarProps}
182
+ message={message}
183
+ anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
184
+ open={showSnackbar}
185
+ autoHideDuration={autoHide ? 6000 : null}
179
186
  classes={{
180
- root: clsxBonus('root'),
181
- message: clsxBonus('message'),
182
- action: clsxBonus('action'),
187
+ root: classes.snackbarRoot,
188
+ anchorOriginBottomCenter: clsx(
189
+ classes.anchorOriginBottomCenter,
190
+ sticky && classes.sticky,
191
+ ),
183
192
  }}
184
- message={
185
- <>
186
- <div className={classes.children}>{children}</div>
187
- {action && (
188
- <div className={classes.actionButton} onClick={() => setShowSnackbar(false)}>
189
- {action}
193
+ onClose={hideSnackbar}
194
+ >
195
+ <SnackbarContent
196
+ classes={{
197
+ root: clsxBonus('root'),
198
+ message: clsxBonus('message'),
199
+ action: clsxBonus('action'),
200
+ }}
201
+ message={
202
+ <>
203
+ <div className={classes.children}>
204
+ <div>
205
+ <SvgImageSimple
206
+ src={icon}
207
+ alt='checkmark'
208
+ size='large'
209
+ className={classes.messageIcon}
210
+ />
211
+ {children}
212
+ </div>
213
+ </div>
214
+ {action && (
215
+ <div className={classes.actionButton} onClick={hideSnackbar}>
216
+ {action}
217
+ </div>
218
+ )}
219
+ <div className={classes.closeButton}>
220
+ <Fab aria-label='Close snackbar' size='medium' onClick={hideSnackbar}>
221
+ <SvgImageSimple src={iconClose} size='small' alt='close' />
222
+ </Fab>
190
223
  </div>
191
- )}
192
- <div className={classes.closeButton}>
193
- <Fab aria-label='Close snackbar' size='medium' onClick={() => setShowSnackbar(false)}>
194
- <SvgImage src={iconClose} size='small' alt='close' />
195
- </Fab>
196
- </div>
197
- </>
198
- }
199
- />
200
- </Snackbar>
224
+ </>
225
+ }
226
+ />
227
+ </Snackbar>
228
+ </Portal>
201
229
  )
202
230
  }
package/index.ts CHANGED
@@ -131,8 +131,6 @@ export * from './SectionHeader'
131
131
  export { default as SectionHeader } from './SectionHeader'
132
132
  export * from './Separator'
133
133
  export { default as Separator } from './Separator'
134
- export * from './Snackbar/ErrorSnackbar'
135
- export { default as ErrorSnackbar } from './Snackbar/ErrorSnackbar'
136
134
  export { default as MessageSnackbar } from './Snackbar/MessageSnackbar'
137
135
  export * from './Snackbar/MessageSnackbarImpl'
138
136
  export { default as MessageSnackbarImpl } from './Snackbar/MessageSnackbarImpl'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/next-ui",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "author": "",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -55,5 +55,5 @@
55
55
  "project": "./tsconfig.json"
56
56
  }
57
57
  },
58
- "gitHead": "08f4dbe739a38ece2c47aa1e94c10f8397da27fa"
58
+ "gitHead": "beb4b83268176f7c6579cee2fe844752315e2378"
59
59
  }
@@ -1,9 +0,0 @@
1
- import React from 'react'
2
- import MessageSnackbar from './MessageSnackbar'
3
- import { MessageSnackbarImplProps } from './MessageSnackbarImpl'
4
-
5
- export type ErrorSnackbarProps = Omit<MessageSnackbarImplProps, 'severity' | 'action'>
6
-
7
- export default function ErrorSnackbarImpl(props: ErrorSnackbarProps) {
8
- return <MessageSnackbar {...props} />
9
- }