Compare commits

...

2 Commits

Author SHA1 Message Date
Savanni D'Gerinel 907b34c496 Rename Launcher components 2024-08-20 12:07:38 -04:00
Savanni D'Gerinel b9d089e4e6 Add Activator groups 2024-08-20 12:02:25 -04:00
7 changed files with 87 additions and 34 deletions

View File

@ -1,12 +1,18 @@
import './App.css'; import './App.css';
import Card from './components/Card/Card'; import Card from './components/Card/Card';
import Activator from './components/Activator/Activator'; import Launcher from './components/Launcher/Launcher';
import LauncherGroup from './components/LauncherGroup/LauncherGroup';
const LightThemes = () => <Card name="Light Themes"> const LightThemes = () => <Card name="Light Themes">
<Activator title="Dark reds" activated={false} /> <LauncherGroup
<Activator title="Watery" activated={false} /> exclusive={true}
<Activator title="Sunset" activated={false} /> options={[
<Activator title="Darkness" activated={true} /> { title: "Dark reds" },
{ title: "Watery" },
{ title: "Sunset" },
{ title: "Darkness" },
]}
/>
</Card> </Card>
const LightSetup = () => <div> </div> const LightSetup = () => <div> </div>
@ -18,29 +24,39 @@ interface LightProps {
const Light = ({ name }: LightProps) => <div> <p> {name} </p> </div> const Light = ({ name }: LightProps) => <div> <p> {name} </p> </div>
const Tracks = () => <Card name="Tracks"> const Tracks = () => <Card name="Tracks">
<Track name="City BGM" /> <LauncherGroup
<Track name="Chat on the streets" /> exclusive={false}
<Track name="Abandoned structure" /> options={[
<Track name="Water dripping" /> { title: "City BGM" },
{ title: "Chat on the streets" },
{ title: "Abandoned structure" },
{ title: "Water dripping" },
]}
/>
</Card> </Card>
interface TrackProps { interface TrackProps {
name: string, name: string,
} }
const Track = ({ name }: TrackProps) => <Activator title={name} activated={false} /> const Track = ({ name }: TrackProps) => <Launcher title={name} />
const Presets = () => <Card name="Presets"> const Presets = () => <Card name="Presets">
<Scene name="Gilcrest Falls day" /> <LauncherGroup
<Scene name="Gilcrest Falls night" /> exclusive={true}
<Scene name="Empty colony" /> options={[
<Scene name="Surk colony" /> { title: "Gilcrest Falls day" },
{ title: "Gilcrest Falls night" },
{ title: "Empty colony" },
{ title: "Surk colony" },
]}
/>
</Card> </Card>
interface PresetProps { interface PresetProps {
name: string name: string
} }
const Scene = ({ name }: PresetProps) => <Activator title={name} activated={false} /> // const Scene = ({ name }: PresetProps) => <Launcher title={name} activated={false} />
const SceneEditor = () => <div> </div> const SceneEditor = () => <div> </div>

View File

@ -1,18 +0,0 @@
import './Activator.css';
import { PropsWithChildren } from 'react';
interface ActivatorProps {
title: string,
icon?: string,
activated: boolean,
}
const Activator = ({ title, icon, activated, children }: PropsWithChildren<ActivatorProps>) => {
const classnames = activated ? "activator activator_enabled" : "activator";
return (
<div className={classnames}>
<p> {title} </p>
</div>)
}
export default Activator;

View File

@ -11,6 +11,5 @@
} }
.card__body { .card__body {
display: flex;
} }

View File

@ -0,0 +1,20 @@
import './Launcher.css';
import React from 'react';
export interface LauncherProps {
title: string,
icon?: string,
activated?: boolean,
onSelected?: (key: string) => void,
}
const Launcher = ({ title, activated = false, onSelected = (key) => {} }: LauncherProps) => {
const classnames = activated ? "activator activator_enabled" : "activator";
console.log("classnames ", activated, classnames);
return (
<div className={classnames} onClick={() => onSelected(title)}>
<p> {title} </p>
</div>)
}
export default Launcher;

View File

@ -0,0 +1,36 @@
import React from 'react';
import Launcher, { LauncherProps } from '../Launcher/Launcher';
export interface Selectable {
onSelected?: (key: string) => void;
}
interface LauncherGroupProps {
options: Array<LauncherProps>;
exclusive: boolean;
}
const exclusiveSelect = (state: { [key: string]: boolean }, targetId: string) => {
console.log("running exclusiveSelect on ", targetId);
return { [targetId]: true };
}
const multiSelect = (state: { [key: string]: boolean }, targetId: string) => {
if (state[targetId]) {
return { ...state, [targetId]: false };
} else {
return { ...state, [targetId]: true };
}
}
const LauncherGroup = ({ options, exclusive }: LauncherGroupProps) => {
const [selected, dispatch] = React.useReducer(exclusive ? exclusiveSelect : multiSelect, {});
let tiedOptions = options.map(option =>
<Launcher key={option.title} title={option.title} onSelected={(key: string) => dispatch(key)} activated={selected[option.title]} />
);
return (<div> {tiedOptions} </div>)
}
export default LauncherGroup;