Skip to content

Commit f00e704

Browse files
committed
Refactor drawer UI from CD-ROM list into a reusable component
Also hide the CD-ROM drawer for emulators that don't support it (just DingusPPC). Updates #337
1 parent 248faf6 commit f00e704

File tree

6 files changed

+323
-219
lines changed

6 files changed

+323
-219
lines changed

src/Mac.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ import {
4141
import {type Appearance} from "./controls/Appearance";
4242
import {
4343
emulatorNeedsMouseDeltas,
44+
emulatorSupportsCDROMs,
4445
emulatorSupportsDownloadsFolder,
4546
} from "./emulator/emulator-common-emulators";
4647
import {type ScreenSize} from "./run-def";
4748
import {viewTransitionNameForDisk} from "./view-transitions";
49+
import {DrawersContainer} from "./controls/Drawer";
4850

4951
export type MacProps = {
5052
disks: SystemDiskDef[];
@@ -690,11 +692,15 @@ export default function Mac({
690692
)}
691693
</ScreenFrame>
692694
{!fullscreen && disks[0]?.infiniteHdSubset !== "mfs" && (
693-
<MacCDROMs
694-
onRun={loadCDROM}
695-
appearance={appearance}
696-
platform={machine.platform}
697-
/>
695+
<DrawersContainer>
696+
{emulatorSupportsCDROMs(machine.emulatorType) && (
697+
<MacCDROMs
698+
onRun={loadCDROM}
699+
appearance={appearance}
700+
platform={machine.platform}
701+
/>
702+
)}
703+
</DrawersContainer>
698704
)}
699705
</>
700706
);

src/MacCDROMs.css

Lines changed: 0 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,3 @@
1-
.Mac-CDROMs {
2-
position: fixed;
3-
bottom: 0;
4-
left: 0;
5-
right: 0;
6-
display: flex;
7-
flex-direction: column;
8-
align-items: center;
9-
z-index: 2;
10-
filter: drop-shadow(1px 1px 5px rgba(0, 0, 0, 0.5));
11-
pointer-events: none;
12-
}
13-
14-
.Mac-CDROMs-Title {
15-
padding: 4px 4px 4px 28px;
16-
cursor: pointer;
17-
background-image: url(./Images/CD-ROM.png);
18-
background-position: 4px 50%;
19-
background-repeat: no-repeat;
20-
image-rendering: pixelated;
21-
border-radius: 4px 4px 0 0;
22-
border: solid 1px black;
23-
border-bottom-width: 0;
24-
position: relative;
25-
top: 1px; /* to cover up the border of the list */
26-
pointer-events: auto;
27-
}
28-
29-
.Mac-CDROMs-Classic .Mac-CDROMs-Title {
30-
background-color: white;
31-
}
32-
33-
.Mac-CDROMs-Classic .Mac-CDROMs-Title:active {
34-
background-color: #eee;
35-
}
36-
37-
.Mac-CDROMs-Platinum .Mac-CDROMs-Title {
38-
background-color: #ddd;
39-
}
40-
41-
.Mac-CDROMs-Platinum .Mac-CDROMs-Title:active {
42-
background-color: #dadada;
43-
}
44-
45-
.Mac-CDROMs-NeXT .Mac-CDROMs-Title {
46-
background-color: #aaa;
47-
border: solid 1px;
48-
border-color: #fff #555 #555 #fff;
49-
color: #000;
50-
border-radius: 0;
51-
font-family: Helvetica, sans-serif;
52-
font-weight: bold;
53-
}
54-
55-
.Mac-CDROMs-Expanded.Mac-CDROMs-NeXT .Mac-CDROMs-Title {
56-
box-sizing: border-box;
57-
width: 80vw;
58-
background-color: #000;
59-
border-color: #aaa #555 #555 #aaa;
60-
color: #fff;
61-
outline: solid 1px #000;
62-
}
63-
64-
.Mac-CDROMs-Contents {
65-
background: white;
66-
border: solid 1px black;
67-
border-bottom-width: 0;
68-
border-radius: 4px 4px 0 0;
69-
height: 50vh;
70-
width: 80vw;
71-
pointer-events: auto;
72-
overflow: hidden;
73-
display: flex;
74-
flex-direction: column;
75-
}
76-
77-
.Mac-CDROMs-NeXT .Mac-CDROMs-Contents {
78-
border-radius: 0;
79-
background: #aaa;
80-
}
81-
82-
.Mac-CDROMs-List {
83-
overflow: auto;
84-
}
85-
86-
.Mac-CDROMs-Header {
87-
padding: 8px;
88-
display: flex;
89-
gap: 8px;
90-
align-items: center;
91-
width: 100%;
92-
justify-content: space-between;
93-
box-sizing: border-box;
94-
font-size: 12px;
95-
}
96-
971
.Mac-CDROMs-Instructions {
982
flex-grow: 1;
993
}
@@ -102,77 +6,12 @@
1026
width: 60px;
1037
}
1048

105-
.Mac-CDROMs-Classic .Mac-CDROMs-Header {
106-
border-bottom: solid 1px #9e9e9e;
107-
}
108-
109-
.Mac-CDROMs-Platinum .Mac-CDROMs-Header {
110-
background: #ddd;
111-
border-bottom: solid 1px #a5a5a5;
112-
}
113-
114-
.Mac-CDROMs-NeXT .Mac-CDROMs-Header {
115-
background: #aaa;
116-
border-top: solid 1px #000;
117-
border-bottom: solid 1px #555;
118-
position: relative;
119-
}
120-
121-
.Mac-CDROMs-NeXT .Mac-CDROMs-Header:after {
122-
content: "";
123-
display: block;
124-
width: 100%;
125-
height: 1px;
126-
background: #fff;
127-
position: absolute;
128-
bottom: -2px;
129-
left: 0;
130-
}
131-
1329
.Mac-CDROMs-Contents .link {
13310
cursor: pointer;
13411
text-decoration: underline;
13512
color: #00c;
13613
}
13714

138-
.Mac-CDROMs-Category {
139-
margin: 8px 0;
140-
}
141-
142-
.Mac-CDROMs-Category h3 {
143-
margin: 8px 0;
144-
background: linear-gradient(to right, #ddd, #fff);
145-
padding: 1px 8px;
146-
}
147-
148-
.Mac-CDROMs-NeXT .Mac-CDROMs-Category h3 {
149-
/* Simulate a 2x2 gray and clear checkerboard, similar to a disabled scrollbar in NeXTSTEP 3.3 */
150-
background-position: 0px 0px, 1px 1px;
151-
background-size: 2px 2px;
152-
background-image: linear-gradient(
153-
45deg,
154-
#555 25%,
155-
transparent 25%,
156-
transparent 75%,
157-
#555 75%,
158-
#555 100%
159-
),
160-
linear-gradient(
161-
45deg,
162-
#555 25%,
163-
transparent 25%,
164-
transparent 75%,
165-
#555 75%,
166-
#555 100%
167-
);
168-
}
169-
170-
.Mac-CDROMs-Category-Contents {
171-
display: flex;
172-
flex-direction: row;
173-
flex-wrap: wrap;
174-
}
175-
17615
.Mac-Custom-CDROM-URL {
17716
width: 100%;
17817
box-sizing: border-box;
@@ -206,19 +45,3 @@
20645
border-radius: 50%;
20746
overflow: hidden;
20847
}
209-
210-
@media (max-width: 440px) {
211-
.Mac-CDROMs {
212-
align-items: start;
213-
margin-left: 10px;
214-
margin-right: 10px;
215-
}
216-
217-
.Mac-CDROMs-Title {
218-
margin-left: 20px;
219-
}
220-
221-
.Mac-CDROMs-Contents {
222-
width: 100%;
223-
}
224-
}

src/MacCDROMs.tsx

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import {type Appearance} from "./controls/Appearance";
1010
import {type MachinePlatform} from "./machines";
1111
import defaultCDROMImage from "./Images/DefaultCDROM.png";
1212
import defaultCDROMNeXTImage from "./Images/DefaultCDROM-NeXT.png";
13+
import cdromsIcon from "./Images/CD-ROM.png";
14+
import {
15+
Drawer,
16+
DrawerContents,
17+
DrawerHeader,
18+
DrawerList,
19+
DrawerListCategory,
20+
} from "./controls/Drawer";
1321

1422
export function MacCDROMs({
1523
onRun,
@@ -20,28 +28,22 @@ export function MacCDROMs({
2028
appearance: Appearance;
2129
platform?: MachinePlatform;
2230
}) {
23-
const [expanded, setExpanded] = useState(false);
24-
const toggleExpanded = () => setExpanded(value => !value);
25-
const className = classNames("Mac-CDROMs", `Mac-CDROMs-${appearance}`, {
26-
"Mac-CDROMs-Expanded": expanded,
27-
});
28-
2931
return (
30-
<div className={className}>
31-
<div className="Mac-CDROMs-Title" onClick={toggleExpanded}>
32-
CD-ROMs
33-
</div>
34-
{expanded && (
32+
<Drawer
33+
title="CD-ROMs"
34+
titleIconUrl={cdromsIcon}
35+
appearance={appearance}
36+
contents={collapse => (
3537
<MacCDROMsContents
3638
onRun={cdrom => {
37-
setExpanded(false);
39+
collapse();
3840
onRun(cdrom);
3941
}}
4042
appearance={appearance}
4143
platform={platform}
4244
/>
4345
)}
44-
</div>
46+
/>
4547
);
4648
}
4749

@@ -108,23 +110,22 @@ function MacCDROMsContents({
108110
const [customCDROMVisible, setCustomCDROMVisible] = useState(false);
109111

110112
return (
111-
<div className="Mac-CDROMs-Contents">
113+
<DrawerContents>
112114
{customCDROMVisible && (
113115
<MacCustomCDROM
114116
onRun={onRun}
115117
onDone={() => setCustomCDROMVisible(false)}
116118
appearance={appearance}
117119
/>
118120
)}
119-
<div className="Mac-CDROMs-Header">
121+
<DrawerHeader>
120122
<div className="Mac-CDROMs-Instructions">
121123
Load CD-ROM images into the emulated Mac to access software
122124
that is too large to pre-install on Infinite HD.
123125
</div>
124126
<Button
125127
appearance={appearance}
126-
onClick={() => setCustomCDROMVisible(true)}
127-
>
128+
onClick={() => setCustomCDROMVisible(true)}>
128129
Load from URL…
129130
</Button>
130131
<Input
@@ -134,28 +135,25 @@ function MacCDROMsContents({
134135
value={search}
135136
onChange={e => setSearch(e.target.value)}
136137
/>
137-
</div>
138-
<div className="Mac-CDROMs-List">
138+
</DrawerHeader>
139+
<DrawerList>
139140
{Object.entries(sortedCdromsByCategory).map(
140141
([category, cdroms]) => (
141-
<div key={category} className="Mac-CDROMs-Category">
142-
<h3>{category}</h3>
143-
<div className="Mac-CDROMs-Category-Contents">
144-
{cdroms.map(cdrom => (
145-
<MacCDROM
146-
key={cdrom.name}
147-
cdrom={cdrom}
148-
onRun={() => {
149-
onRun(cdrom);
150-
}}
151-
/>
152-
))}
153-
</div>
154-
</div>
142+
<DrawerListCategory key={category} title={category}>
143+
{cdroms.map(cdrom => (
144+
<MacCDROM
145+
key={cdrom.name}
146+
cdrom={cdrom}
147+
onRun={() => {
148+
onRun(cdrom);
149+
}}
150+
/>
151+
))}
152+
</DrawerListCategory>
155153
)
156154
)}
157-
</div>
158-
</div>
155+
</DrawerList>
156+
</DrawerContents>
159157
);
160158
}
161159

@@ -191,8 +189,7 @@ function MacCustomCDROM({
191189
doneLabel="Run"
192190
doneEnabled={url !== "" && inputRef.current?.validity.valid}
193191
onCancel={onDone}
194-
appearance={appearance}
195-
>
192+
appearance={appearance}>
196193
<p>
197194
Infinite Mac supports loading of CD-ROM images from URLs. Be
198195
aware of the following caveats:

0 commit comments

Comments
 (0)