Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@rsuite/interactions
Advanced tools
Call RSuite Modals like a boss.
npm install @rsuite/interactions@next --save
alert()
, confirm()
, prompt()
styles modals as you already know how.alert
Use it like you are using window.alert()
, and you can await it.
const buyNewPhone = useCallback(async () => {
await alert("Congrats! You've got a new iPhone!");
console.log('alert closed');
}, []);
alert(
message?: React.ReactNode,
modalConfig?: AlertModalProps
): Promise<void>;
interface AlertModalProps {
okButtonText?: string;
onOk?: (() => void) | (() => Promise<any>);
}
okButtonText
: Customize "OK" button text.onOk
: Callback function when "OK" is clicked. If onOk
returns a Promise
, "OK" button shows loading status until the promise finishes.confirm
Use it like you are using window.confirm()
but await its return value.
const confirmSmashPhone = useCallback(async () => {
if (await confirm('Are you sure you what to do this?')) {
alert('Rest in pieces.');
}
}, []);
confirm(
message?: React.ReactNode,
modalConfig?: ConfirmModalProps
): Promise<boolean>;
interface ConfirmModalProps {
okButtonText?: string;
cancelButtonText?: string;
onOk?: (() => void) | (() => Promise<any>);
onCancel?: (isSubmitLoading?: boolean) => any;
canCancelOnLoading?: boolean;
}
okButtonText
: Customize "OK" button text.okButtonDangerous
: When set true
, "OK" button is red colored.cancelButtonText
: Customize "Cancel" button text.onOk
: Callback function when "OK" is clicked. If onOk
returns a Promise
, "OK" button shows loading status until the promise finishes.onCancel
: Callback function when "Cancel" is clicked. If not provided, "Cancel" is disabled when "OK" is loading.canCancelOnLoading
: When onCancel
is set, you can still use this option to force disable "Cancel" button.prompt
Use it like you are using window.prompt()
but await its return value.
const promptForName = useCallback(async () => {
const name = await prompt('What is your name?');
if (name) {
alert(`It\'s ok, ${name}.`);
}
}, []);
prompt(
message?: React.ReactNode,
_default?: string,
modalConfig?: PromptModalProps
): Promise<string | null>;
interface PromptModalProps {
okButtonText?: string;
cancelButtonText?: string;
valdiate?: (inputValue: string) => void;
onOk?: ((inputVal?: string) => void) | ((inputVal: string) => Promise<any>);
onCancel?: (isSubmitLoading?: boolean) => any;
canCancelOnLoading?: boolean;
inputProps?: InputProps;
}
okButtonText
: Customize "OK" button text.okButtonDangerous
: When set true
, "OK" button is red colored.cancelButtonText
: Customize "Cancel" button text.validate
: Validate current input value. Disable OK button if validation fails.onOk
: Callback function when "OK" is clicked, receiving a string representing the user input. If onOk
returns a Promise
, "OK" button shows loading status until the promise finishes.onCancel
: Callback function when "Cancel" is clicked. If not provided, "Cancel" is disabled when "OK" is loading.canCancelOnLoading
: When onCancel
is set, you can still use this option to force disable "Cancel" button.inputProps
: custom input properties, learn more information about InputProps
from hereIf you use @rsuite/interactions
to call alert dialogs in your app, you can easily test it with @testing-library/react
.
Say you want to show a confirm dialog when user clicks a button that will delete a post:
import { confirm } from '@rsuite/interactions';
function App() {
async function confirmDeletePost(id) {
if (await confirm('Are you sure?')) {
await api.deletePost(id);
}
}
return <button onClick={() => confirmDeletePost(1)}>Delete post 1</button>;
}
And you want to test that the dialog is shown when the button is clicked:
import { render, fireEvent, screen } from '@testing-library/react';
it('Should show a confirm dialog', () => {
const { getByRole } = render(<App />);
fireEvent.click(getByRole('button', { name: /delete post/i }));
// Assume you're using Jest with @testing-library/jest-dom
const dialog = screen.getByRole('alertdialog');
expect(dialog).toBeVisible();
// Assert on its a11y description
expect(dialog).toHaveAccessibleDescription('Are you sure?');
// Or if you're using jest-dom < 5.14, you can assert on its textContent
expect(dialog).toHaveTextContent('Are you sure?');
});
MIT licensed
FAQs
Call rsuite Modal at ease.
We found that @rsuite/interactions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.