mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 12:13:11 +00:00
Add reload button, rename reset to clear (#7954)
This commit is contained in:
3
next-env.d.ts
vendored
3
next-env.d.ts
vendored
@@ -1,5 +1,6 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
/// <reference types="next/navigation-types/compat/navigation" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
|
||||
22
src/components/MDX/Sandpack/ClearButton.tsx
Normal file
22
src/components/MDX/Sandpack/ClearButton.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import {IconClose} from '../../Icon/IconClose';
|
||||
export interface ClearButtonProps {
|
||||
onClear: () => void;
|
||||
}
|
||||
|
||||
export function ClearButton({onClear}: ClearButtonProps) {
|
||||
return (
|
||||
<button
|
||||
className="text-sm text-primary dark:text-primary-dark inline-flex items-center hover:text-link duration-100 ease-in transition mx-1"
|
||||
onClick={onClear}
|
||||
title="Clear all edits and reload sandbox"
|
||||
type="button">
|
||||
<IconClose className="inline mx-1 relative" />
|
||||
<span className="hidden md:block">Clear</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -17,7 +17,8 @@ import {
|
||||
useSandpackNavigation,
|
||||
} from '@codesandbox/sandpack-react/unstyled';
|
||||
import {OpenInCodeSandboxButton} from './OpenInCodeSandboxButton';
|
||||
import {ResetButton} from './ResetButton';
|
||||
import {ReloadButton} from './ReloadButton';
|
||||
import {ClearButton} from './ClearButton';
|
||||
import {DownloadButton} from './DownloadButton';
|
||||
import {IconChevron} from '../../Icon/IconChevron';
|
||||
import {Listbox} from '@headlessui/react';
|
||||
@@ -95,7 +96,7 @@ export function NavigationBar({providedFiles}: {providedFiles: Array<string>}) {
|
||||
// Note: in a real useEvent, onContainerResize would be omitted.
|
||||
}, [isMultiFile, onContainerResize]);
|
||||
|
||||
const handleReset = () => {
|
||||
const handleClear = () => {
|
||||
/**
|
||||
* resetAllFiles must come first, otherwise
|
||||
* the previous content will appear for a second
|
||||
@@ -103,13 +104,13 @@ export function NavigationBar({providedFiles}: {providedFiles: Array<string>}) {
|
||||
*
|
||||
* Plus, it should only prompt if there's any file changes
|
||||
*/
|
||||
if (
|
||||
sandpack.editorState === 'dirty' &&
|
||||
confirm('Reset all your edits too?')
|
||||
) {
|
||||
if (sandpack.editorState === 'dirty' && confirm('Clear all your edits?')) {
|
||||
sandpack.resetAllFiles();
|
||||
}
|
||||
refresh();
|
||||
};
|
||||
|
||||
const handleReload = () => {
|
||||
refresh();
|
||||
};
|
||||
|
||||
@@ -188,7 +189,8 @@ export function NavigationBar({providedFiles}: {providedFiles: Array<string>}) {
|
||||
className="px-3 flex items-center justify-end text-start"
|
||||
translate="yes">
|
||||
<DownloadButton providedFiles={providedFiles} />
|
||||
<ResetButton onReset={handleReset} />
|
||||
<ReloadButton onReload={handleReload} />
|
||||
<ClearButton onClear={handleClear} />
|
||||
<OpenInCodeSandboxButton />
|
||||
{activeFile.endsWith('.tsx') && (
|
||||
<OpenInTypeScriptPlaygroundButton
|
||||
|
||||
@@ -4,18 +4,19 @@
|
||||
|
||||
import * as React from 'react';
|
||||
import {IconRestart} from '../../Icon/IconRestart';
|
||||
export interface ResetButtonProps {
|
||||
onReset: () => void;
|
||||
export interface ReloadButtonProps {
|
||||
onReload: () => void;
|
||||
}
|
||||
|
||||
export function ResetButton({onReset}: ResetButtonProps) {
|
||||
export function ReloadButton({onReload}: ReloadButtonProps) {
|
||||
return (
|
||||
<button
|
||||
className="text-sm text-primary dark:text-primary-dark inline-flex items-center hover:text-link duration-100 ease-in transition mx-1"
|
||||
onClick={onReset}
|
||||
title="Reset Sandbox"
|
||||
onClick={onReload}
|
||||
title="Keep your edits and reload sandbox"
|
||||
type="button">
|
||||
<IconRestart className="inline mx-1 relative" /> Reset
|
||||
<IconRestart className="inline mx-1 relative" />
|
||||
<span className="hidden md:block">Reload</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user