Advertisement
Guest User

Mock Windows Interface Version 2

a guest
Jul 8th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. import React, { useState } from 'react';
  2. import { X, Minus, Square, Settings, Power } from 'lucide-react';
  3.  
  4. const Windows95Interface = () => {
  5. const [windows, setWindows] = useState([
  6. { id: 1, title: 'My Computer', x: 20, y: 20, width: 300, height: 200, minimized: false },
  7. { id: 2, title: 'Notepad', x: 100, y: 100, width: 250, height: 180, minimized: false },
  8. ]);
  9.  
  10. const [activeWindow, setActiveWindow] = useState(null);
  11. const [dragStart, setDragStart] = useState({ x: 0, y: 0 });
  12. const [startMenuOpen, setStartMenuOpen] = useState(false);
  13. const [settingsOpen, setSettingsOpen] = useState(false);
  14. const [backgroundColor, setBackgroundColor] = useState('#008080');
  15. const [shutdownPrompt, setShutdownPrompt] = useState(false);
  16.  
  17. const handleMouseDown = (e, id) => {
  18. setActiveWindow(id);
  19. setDragStart({ x: e.clientX, y: e.clientY });
  20. };
  21.  
  22. const handleMouseMove = (e) => {
  23. if (activeWindow !== null) {
  24. const dx = e.clientX - dragStart.x;
  25. const dy = e.clientY - dragStart.y;
  26. setWindows(windows.map(w =>
  27. w.id === activeWindow
  28. ? { ...w, x: w.x + dx, y: w.y + dy }
  29. : w
  30. ));
  31. setDragStart({ x: e.clientX, y: e.clientY });
  32. }
  33. };
  34.  
  35. const handleMouseUp = () => {
  36. setActiveWindow(null);
  37. };
  38.  
  39. const minimizeWindow = (id) => {
  40. setWindows(windows.map(w =>
  41. w.id === id ? { ...w, minimized: !w.minimized } : w
  42. ));
  43. };
  44.  
  45. const closeWindow = (id) => {
  46. setWindows(windows.filter(w => w.id !== id));
  47. };
  48.  
  49. const openWindow = (title) => {
  50. const newWindow = {
  51. id: Date.now(),
  52. title,
  53. x: 50 + Math.random() * 100,
  54. y: 50 + Math.random() * 100,
  55. width: 300,
  56. height: 200,
  57. minimized: false
  58. };
  59. setWindows([...windows, newWindow]);
  60. setStartMenuOpen(false);
  61. };
  62.  
  63. const toggleStartMenu = () => {
  64. setStartMenuOpen(!startMenuOpen);
  65. };
  66.  
  67. const openSettings = () => {
  68. setSettingsOpen(true);
  69. setStartMenuOpen(false);
  70. };
  71.  
  72. const closeSettings = () => {
  73. setSettingsOpen(false);
  74. };
  75.  
  76. const changeBackgroundColor = (color) => {
  77. setBackgroundColor(color);
  78. };
  79.  
  80. const initiateShutdown = () => {
  81. setShutdownPrompt(true);
  82. setStartMenuOpen(false);
  83. };
  84.  
  85. const cancelShutdown = () => {
  86. setShutdownPrompt(false);
  87. };
  88.  
  89. const confirmShutdown = () => {
  90. // In a real system, this would trigger a shutdown.
  91. // For this mock-up, we'll just close all windows and show a message.
  92. setWindows([]);
  93. setShutdownPrompt(false);
  94. alert("Windows is shutting down. It's now safe to turn off your computer.");
  95. };
  96.  
  97. return (
  98. <div
  99. className="w-full h-screen relative overflow-hidden"
  100. style={{ backgroundColor }}
  101. onMouseMove={handleMouseMove}
  102. onMouseUp={handleMouseUp}
  103. >
  104. {windows.map(window => (
  105. <div
  106. key={window.id}
  107. className={`absolute bg-gray-200 border-2 border-gray-400 shadow-lg ${window.minimized ? 'hidden' : ''}`}
  108. style={{
  109. left: `${window.x}px`,
  110. top: `${window.y}px`,
  111. width: `${window.width}px`,
  112. height: `${window.height}px`,
  113. zIndex: activeWindow === window.id ? 10 : 1
  114. }}
  115. >
  116. <div
  117. className="bg-blue-900 text-white px-2 py-1 flex justify-between items-center cursor-move"
  118. onMouseDown={(e) => handleMouseDown(e, window.id)}
  119. >
  120. <span>{window.title}</span>
  121. <div className="flex space-x-1">
  122. <button onClick={() => minimizeWindow(window.id)} className="focus:outline-none">
  123. <Minus size={16} />
  124. </button>
  125. <button className="focus:outline-none">
  126. <Square size={16} />
  127. </button>
  128. <button onClick={() => closeWindow(window.id)} className="focus:outline-none">
  129. <X size={16} />
  130. </button>
  131. </div>
  132. </div>
  133. <div className="p-2">
  134. {window.title === 'My Computer' ? (
  135. <div className="flex flex-col items-center">
  136. <img src="/api/placeholder/64/64" alt="My Computer" className="mb-2" />
  137. <span>My Computer</span>
  138. </div>
  139. ) : (
  140. <textarea className="w-full h-32 p-2 border border-gray-400 resize-none" placeholder="Type here..."></textarea>
  141. )}
  142. </div>
  143. </div>
  144. ))}
  145.  
  146. {settingsOpen && (
  147. <div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-gray-200 border-2 border-gray-400 shadow-lg p-4 w-80">
  148. <div className="flex justify-between items-center mb-4">
  149. <h2 className="text-lg font-bold">Settings</h2>
  150. <button onClick={closeSettings} className="focus:outline-none">
  151. <X size={16} />
  152. </button>
  153. </div>
  154. <div className="mb-4">
  155. <label className="block mb-2">Background Color:</label>
  156. <div className="flex space-x-2">
  157. <button onClick={() => changeBackgroundColor('#008080')} className="w-6 h-6 bg-teal-600"></button>
  158. <button onClick={() => changeBackgroundColor('#000080')} className="w-6 h-6 bg-blue-900"></button>
  159. <button onClick={() => changeBackgroundColor('#008000')} className="w-6 h-6 bg-green-700"></button>
  160. </div>
  161. </div>
  162. </div>
  163. )}
  164.  
  165. {shutdownPrompt && (
  166. <div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-gray-200 border-2 border-gray-400 shadow-lg p-4 w-80">
  167. <h2 className="text-lg font-bold mb-4">Shut Down Windows</h2>
  168. <p className="mb-4">Are you sure you want to shut down your computer?</p>
  169. <div className="flex justify-end space-x-2">
  170. <button onClick={cancelShutdown} className="px-4 py-2 bg-gray-300 hover:bg-gray-400">Cancel</button>
  171. <button onClick={confirmShutdown} className="px-4 py-2 bg-red-500 text-white hover:bg-red-600">OK</button>
  172. </div>
  173. </div>
  174. )}
  175.  
  176. <div className="absolute bottom-0 left-0 right-0 bg-gray-300 h-10 flex items-center px-2">
  177. <button onClick={toggleStartMenu} className="bg-green-600 text-white px-4 py-1 rounded">Start</button>
  178. {startMenuOpen && (
  179. <div className="absolute bottom-10 left-0 w-56 bg-gray-200 border-2 border-gray-400 shadow-lg">
  180. <button onClick={() => openWindow('Programs')} className="w-full text-left px-4 py-2 hover:bg-blue-600 hover:text-white">Programs</button>
  181. <button onClick={() => openWindow('Documents')} className="w-full text-left px-4 py-2 hover:bg-blue-600 hover:text-white">Documents</button>
  182. <button onClick={openSettings} className="w-full text-left px-4 py-2 hover:bg-blue-600 hover:text-white flex items-center">
  183. <Settings size={16} className="mr-2" />
  184. Settings
  185. </button>
  186. <hr className="my-2 border-gray-400" />
  187. <button onClick={initiateShutdown} className="w-full text-left px-4 py-2 hover:bg-blue-600 hover:text-white flex items-center">
  188. <Power size={16} className="mr-2" />
  189. Shut Down...
  190. </button>
  191. </div>
  192. )}
  193. </div>
  194. </div>
  195. );
  196. };
  197.  
  198. export default Windows95Interface;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement