Skip to content

Commit 85e9442

Browse files
authored
Merge pull request #897 from amitamrutiya/fix-promt
fix: issue with the prompt component
2 parents a54c20d + 12967c4 commit 85e9442

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

src/custom/Prompt/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import PromptComponent from './promt-component';
2-
1+
import PromptComponent, { PROMPT_VARIANTS } from './promt-component';
2+
export { PROMPT_VARIANTS, PromptComponent };
33
export default PromptComponent;

src/custom/Prompt/promt-component.tsx

+40-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
2-
import { Typography } from '../../base';
2+
import { Checkbox, FormControlLabel, Typography } from '../../base';
33
import { useTheme } from '../../theme';
44
import { Modal, ModalBody, ModalButtonPrimary, ModalButtonSecondary, ModalFooter } from '../Modal';
55
import { ActionComponent, Subtitle } from './style';
@@ -26,6 +26,8 @@ interface State {
2626
showInfoIcon?: string;
2727
variant?: PromptVariant;
2828
headerIcon?: React.ReactNode;
29+
showCheckbox?: boolean;
30+
isChecked?: boolean;
2931
}
3032

3133
interface ShowParams {
@@ -34,11 +36,13 @@ interface ShowParams {
3436
primaryOption: string;
3537
variant: PromptVariant;
3638
showInfoIcon?: string;
39+
showCheckbox?: boolean;
3740
headerIcon?: React.ReactNode;
3841
}
3942

4043
export interface PromptRef {
4144
show: (params: ShowParams) => Promise<string>;
45+
getCheckboxState: () => boolean;
4246
}
4347

4448
const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) => {
@@ -49,7 +53,9 @@ const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) =>
4953
primaryOption: '',
5054
showInfoIcon: '',
5155
variant,
52-
headerIcon: undefined
56+
headerIcon: undefined,
57+
isChecked: false,
58+
showCheckbox: false
5359
});
5460

5561
/* This ref is used to store the resolve and reject functions of the promise returned by the show method */
@@ -67,7 +73,8 @@ const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) =>
6773
setState({
6874
...params,
6975
isOpen: true,
70-
showInfoIcon: params.showInfoIcon || ''
76+
showInfoIcon: params.showInfoIcon || '',
77+
showCheckbox: !!params.showCheckbox
7178
});
7279
});
7380
};
@@ -77,11 +84,20 @@ const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) =>
7784
setState((prevState) => ({ ...prevState, isOpen: false }));
7885
};
7986

87+
const handleCheckboxChange = () => {
88+
setState((prevState) => ({ ...prevState, isChecked: !prevState.isChecked }));
89+
};
90+
91+
const getCheckboxState = () => {
92+
return !!state.isChecked;
93+
};
94+
8095
useImperativeHandle(ref, () => ({
81-
show
96+
show,
97+
getCheckboxState
8298
}));
8399

84-
const { isOpen, primaryOption, title, subtitle, showInfoIcon, headerIcon } = state;
100+
const { isOpen, primaryOption, title, subtitle, showInfoIcon, headerIcon, showCheckbox } = state;
85101
const { resolve } = promiseInfoRef.current;
86102

87103
return (
@@ -96,10 +112,28 @@ const PromptComponent = forwardRef<PromptRef, PromptProps>(({ variant }, ref) =>
96112
{subtitle && (
97113
<ModalBody>
98114
<Subtitle id="alert-dialog-description" variant="body1" component="div">
99-
<Typography variant="body1" component="div">
115+
<Typography
116+
variant="body1"
117+
component="div"
118+
style={{
119+
color: theme.palette.text.primary
120+
}}
121+
>
100122
{subtitle}
101123
</Typography>
102124
</Subtitle>
125+
{showCheckbox && (
126+
<FormControlLabel
127+
control={
128+
<Checkbox
129+
checked={getCheckboxState()}
130+
onChange={handleCheckboxChange}
131+
color="primary"
132+
/>
133+
}
134+
label={<span style={{ fontSize: '1rem' }}>Do not show again</span>}
135+
/>
136+
)}
103137
</ModalBody>
104138
)}
105139
<ModalFooter variant="filled" helpText={showInfoIcon}>

src/custom/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { LearningCard } from './LearningCard';
3636
import { BasicMarkdown, RenderMarkdown } from './Markdown';
3737
import { ModalCard } from './ModalCard';
3838
import PopperListener, { IPopperListener } from './PopperListener';
39-
import PromptComponent from './Prompt';
39+
import { PROMPT_VARIANTS, PromptComponent } from './Prompt';
4040
import ResponsiveDataTable, {
4141
DataTableEllipsisMenu,
4242
ResponsiveDataTableProps
@@ -90,6 +90,7 @@ export {
9090
InfoTooltip,
9191
LearningCard,
9292
ModalCard,
93+
PROMPT_VARIANTS,
9394
PopperListener,
9495
PromptComponent,
9596
ResponsiveDataTable,

0 commit comments

Comments
 (0)