Start on a GM dashboard application #246
|
@ -1,12 +1,18 @@
|
|||
import './App.css';
|
||||
import Card from './components/Card/Card';
|
||||
import Activator from './components/Activator/Activator';
|
||||
import Selector from './components/Selector/Selector';
|
||||
|
||||
const LightThemes = () => <Card name="Light Themes">
|
||||
<Activator title="Dark reds" activated={false} />
|
||||
<Activator title="Watery" activated={false} />
|
||||
<Activator title="Sunset" activated={false} />
|
||||
<Activator title="Darkness" activated={true} />
|
||||
<Selector
|
||||
exclusive={true}
|
||||
options={[
|
||||
{ title: "Dark reds" },
|
||||
{ title: "Watery" },
|
||||
{ title: "Sunset" },
|
||||
{ title: "Darkness" },
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
const LightSetup = () => <div> </div>
|
||||
|
@ -18,29 +24,39 @@ interface LightProps {
|
|||
const Light = ({ name }: LightProps) => <div> <p> {name} </p> </div>
|
||||
|
||||
const Tracks = () => <Card name="Tracks">
|
||||
<Track name="City BGM" />
|
||||
<Track name="Chat on the streets" />
|
||||
<Track name="Abandoned structure" />
|
||||
<Track name="Water dripping" />
|
||||
<Selector
|
||||
exclusive={false}
|
||||
options={[
|
||||
{ title: "City BGM" },
|
||||
{ title: "Chat on the streets" },
|
||||
{ title: "Abandoned structure" },
|
||||
{ title: "Water dripping" },
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
interface TrackProps {
|
||||
name: string,
|
||||
}
|
||||
const Track = ({ name }: TrackProps) => <Activator title={name} activated={false} />
|
||||
const Track = ({ name }: TrackProps) => <Activator title={name} />
|
||||
|
||||
const Presets = () => <Card name="Presets">
|
||||
<Scene name="Gilcrest Falls day" />
|
||||
<Scene name="Gilcrest Falls night" />
|
||||
<Scene name="Empty colony" />
|
||||
<Scene name="Surk colony" />
|
||||
<Selector
|
||||
exclusive={true}
|
||||
options={[
|
||||
{ title: "Gilcrest Falls day" },
|
||||
{ title: "Gilcrest Falls night" },
|
||||
{ title: "Empty colony" },
|
||||
{ title: "Surk colony" },
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
interface PresetProps {
|
||||
name: string
|
||||
}
|
||||
|
||||
const Scene = ({ name }: PresetProps) => <Activator title={name} activated={false} />
|
||||
// const Scene = ({ name }: PresetProps) => <Activator title={name} activated={false} />
|
||||
|
||||
const SceneEditor = () => <div> </div>
|
||||
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
import './Activator.css';
|
||||
import { PropsWithChildren } from 'react';
|
||||
import React from 'react';
|
||||
|
||||
interface ActivatorProps {
|
||||
export interface ActivatorProps {
|
||||
title: string,
|
||||
icon?: string,
|
||||
activated: boolean,
|
||||
activated?: boolean,
|
||||
onSelected?: (key: string) => void,
|
||||
}
|
||||
|
||||
const Activator = ({ title, icon, activated, children }: PropsWithChildren<ActivatorProps>) => {
|
||||
const Activator = ({ title, activated = false, onSelected = (key) => {} }: ActivatorProps) => {
|
||||
const classnames = activated ? "activator activator_enabled" : "activator";
|
||||
console.log("classnames ", activated, classnames);
|
||||
return (
|
||||
<div className={classnames}>
|
||||
<div className={classnames} onClick={() => onSelected(title)}>
|
||||
<p> {title} </p>
|
||||
</div>)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,5 @@
|
|||
}
|
||||
|
||||
.card__body {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import React from 'react';
|
||||
import Activator, { ActivatorProps } from '../Activator/Activator';
|
||||
|
||||
export interface Selectable {
|
||||
onSelected?: (key: string) => void;
|
||||
}
|
||||
|
||||
interface SelectorProps {
|
||||
options: Array<ActivatorProps>;
|
||||
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 Selector = ({ options, exclusive }: SelectorProps) => {
|
||||
const [selected, dispatch] = React.useReducer(exclusive ? exclusiveSelect : multiSelect, {});
|
||||
|
||||
let tiedOptions = options.map(option =>
|
||||
<Activator key={option.title} title={option.title} onSelected={(key: string) => dispatch(key)} activated={selected[option.title]} />
|
||||
);
|
||||
|
||||
return (<div> {tiedOptions} </div>)
|
||||
}
|
||||
|
||||
export default Selector;
|
Loading…
Reference in New Issue