macos_window.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * MacosWindow — macOS应用窗口边框(含traffic lights)
  3. *
  4. * 用法:
  5. * <MacosWindow title="Finder">
  6. * <YourAppContent />
  7. * </MacosWindow>
  8. */
  9. const macosWindowStyles = {
  10. window: {
  11. display: 'inline-block',
  12. background: '#fff',
  13. borderRadius: 10,
  14. overflow: 'hidden',
  15. boxShadow: '0 30px 80px rgba(0,0,0,0.25), 0 0 0 0.5px rgba(0,0,0,0.15)',
  16. },
  17. titleBar: {
  18. height: 38,
  19. background: 'linear-gradient(to bottom, #e8e8e8, #d8d8d8)',
  20. display: 'flex',
  21. alignItems: 'center',
  22. padding: '0 14px',
  23. borderBottom: '0.5px solid rgba(0,0,0,0.1)',
  24. position: 'relative',
  25. userSelect: 'none',
  26. },
  27. trafficLights: {
  28. display: 'flex',
  29. gap: 8,
  30. alignItems: 'center',
  31. },
  32. light: {
  33. width: 12,
  34. height: 12,
  35. borderRadius: '50%',
  36. border: '0.5px solid rgba(0,0,0,0.15)',
  37. },
  38. close: { background: '#ff5f57' },
  39. minimize: { background: '#febc2e' },
  40. maximize: { background: '#28c840' },
  41. title: {
  42. position: 'absolute',
  43. left: 0,
  44. right: 0,
  45. textAlign: 'center',
  46. fontSize: 13,
  47. color: '#333',
  48. fontWeight: 500,
  49. fontFamily: '-apple-system, "SF Pro Text", sans-serif',
  50. pointerEvents: 'none',
  51. },
  52. content: {
  53. position: 'relative',
  54. overflow: 'auto',
  55. },
  56. titleBarDark: {
  57. background: 'linear-gradient(to bottom, #3c3c3c, #2c2c2c)',
  58. borderBottom: '0.5px solid rgba(255,255,255,0.1)',
  59. },
  60. titleDark: {
  61. color: '#ddd',
  62. },
  63. };
  64. function MacosWindow({ title = '', width = 900, height = 600, darkMode = false, children }) {
  65. return (
  66. <div style={{ ...macosWindowStyles.window, background: darkMode ? '#1e1e1e' : '#fff' }}>
  67. <div style={{
  68. ...macosWindowStyles.titleBar,
  69. ...(darkMode ? macosWindowStyles.titleBarDark : {}),
  70. }}>
  71. <div style={macosWindowStyles.trafficLights}>
  72. <div style={{ ...macosWindowStyles.light, ...macosWindowStyles.close }} />
  73. <div style={{ ...macosWindowStyles.light, ...macosWindowStyles.minimize }} />
  74. <div style={{ ...macosWindowStyles.light, ...macosWindowStyles.maximize }} />
  75. </div>
  76. {title && (
  77. <div style={{
  78. ...macosWindowStyles.title,
  79. ...(darkMode ? macosWindowStyles.titleDark : {}),
  80. }}>
  81. {title}
  82. </div>
  83. )}
  84. </div>
  85. <div style={{ ...macosWindowStyles.content, width, height }}>
  86. {children}
  87. </div>
  88. </div>
  89. );
  90. }
  91. if (typeof window !== 'undefined') {
  92. window.MacosWindow = MacosWindow;
  93. }