Skip to content

Commit

Permalink
allow message and header to be null
Browse files Browse the repository at this point in the history
  • Loading branch information
jamal-khey committed May 15, 2024
1 parent 9fbd4e6 commit 2df7060
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
19 changes: 13 additions & 6 deletions demo/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ const getMuiTheme = (theme) => {
}
};

const style = {
button: {
float: 'left',
margin: '5px',
},
};

/**
* @param {import('@mui/material/styles').Theme} theme Theme from ThemeProvider
*/
Expand Down Expand Up @@ -194,7 +201,7 @@ function SnackErrorButton() {
<Button
variant="contained"
color="error"
style={{ float: 'left', margin: '5px' }}
style={style.button}
onClick={() => {
snackError({
messageTxt: 'Snack error message',
Expand All @@ -213,7 +220,7 @@ function SnackWarningButton() {
<Button
variant="contained"
color="warning"
style={{ float: 'left', margin: '5px' }}
style={style.button}
onClick={() => {
snackWarning({
messageTxt: 'Snack warning message',
Expand All @@ -232,7 +239,7 @@ function SnackInfoButton() {
<Button
variant="contained"
color="info"
style={{ float: 'left', margin: '5px' }}
style={style.button}
onClick={() => {
snackInfo({
messageTxt: 'Snack info message',
Expand All @@ -253,10 +260,10 @@ function PermanentSnackButton() {
<Button
variant="contained"
color="info"
style={{ float: 'left', margin: '5px' }}
style={style.button}
onClick={() => {
const key = snackInfo({
messageTxt: 'Snack info message',
messageTxt: 'Permanent Snack info message',
headerTxt: 'Header',
persist: true,
});
Expand All @@ -268,7 +275,7 @@ function PermanentSnackButton() {
<Button
variant="contained"
color="info"
style={{ float: 'left', margin: '5px' }}
style={style.button}
onClick={() => {
closeSnackbar(snackKey);
setSnackKey(undefined);
Expand Down
21 changes: 9 additions & 12 deletions src/hooks/useSnackMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,16 @@ function makeMessage(
snackInputs.headerId,
snackInputs.headerValues
);
if (message !== null && header !== null) {
let fullMessage = '';

let fullMessage = '';
if (header) {
fullMessage += header;
}
if (message) {
if (header) {
fullMessage += header;
}
if (message) {
if (header) {
fullMessage += '\n\n';
}
fullMessage += message;
fullMessage += '\n\n';
}
return fullMessage;
} else {
return null;
fullMessage += message;
}
return fullMessage;
}

0 comments on commit 2df7060

Please sign in to comment.