Skip to content

Commit

Permalink
fix themes for starter layout
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-cup committed May 12, 2021
1 parent 4d28ef1 commit 4937ae2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export const LayoutProperty: React.FC<{
onChange={e => setLayoutConfig({ [p.name]: e.target.value })}
/>
) : p.type === "select" ? (
<Select options={p.options.map(value => ({ value }))} />
<Select
options={p.options.map(value => ({ value }))}
value={(layoutConfig[p.name] as string) ?? ""}
onChange={value => setLayoutConfig({ [p.name]: value })}
/>
) : null}
</Field>
);
Expand Down
9 changes: 8 additions & 1 deletion src/layouts/colours.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export const colourThemes = {
export interface ColourTheme {
fg: string;
bg: string;
gray: string;
pink: string;
}

export const colourThemes: Record<string, ColourTheme> = {
light: {
fg: "#131126",
bg: "#ffffff",
Expand Down
12 changes: 9 additions & 3 deletions src/layouts/starterLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { GetCSSFn, ILayout, LayoutComponent } from "../types";
import { colourThemes } from "./colours";
import { gString } from "./utils";

const defaultTheme = "dark";

const getCSS: GetCSSFn = config => {
const theme = gString(config, "theme", "light");
const colours = colourThemes[theme.toLowerCase()];
const theme = gString(config, "Theme", defaultTheme).toLowerCase();
const colours = colourThemes[theme];

return `
.top {
Expand All @@ -13,6 +15,8 @@ const getCSS: GetCSSFn = config => {
display: flex;
align-items: flex-end;
justify-content: flex-end;
background-color: ${colours.bg};
color: ${colours.fg};
}
.rlogo {
Expand Down Expand Up @@ -54,8 +58,9 @@ const getCSS: GetCSSFn = config => {
};

const Component: LayoutComponent = ({ config }) => {
const theme = gString(config, "Theme", defaultTheme).toLowerCase();
const rlogo =
config.theme === "dark"
theme === "dark"
? "https://railway.app/brand/logo-light.svg"
: "https://railway.app/brand/logo-dark.svg";

Expand Down Expand Up @@ -88,6 +93,7 @@ export const starterLayout: ILayout = {
name: "Theme",
type: "select",
options: ["Light", "Dark"],
default: defaultTheme,
},
{
name: "Name",
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const gString = (
name: string,
defaultValue?: string,
): string => {
const value = layoutConfig[name];
return (Array.isArray(value) ? value.join(", ") : value) ?? defaultValue;
const value = layoutConfig[name] ?? defaultValue;
return Array.isArray(value) ? value.join(", ") : value;
};
4 changes: 2 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Home: NextPage = () => {
{isMounted && (
<section tw="grid gap-8 grid-cols-1 md:grid-cols-3">
<Config />
<OGImage />
<Viewer />
</section>
)}
</main>
Expand Down Expand Up @@ -73,7 +73,7 @@ export const Config: React.FC = () => {
);
};

export const OGImage: React.FC = () => {
export const Viewer: React.FC = () => {
const [config] = useConfig();
const [layoutConfig] = useLayoutConfig();

Expand Down

0 comments on commit 4937ae2

Please sign in to comment.