Skip to content

Commit e8ef533

Browse files
committed
Add icon for custom themes in themes dropdown
1 parent 1794914 commit e8ef533

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

components/editor/SnippngCodeArea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const SnippngCodeArea: React.FC<Props> = ({ underConstructionTheme }) => {
119119
/**
120120
*
121121
* @returns editor compatible theme object
122-
* @description Function is responsible for constructing theme based on if it is a
122+
* @description Function is responsible for constructing theme based on if it is
123123
* - `predefined` - theme in the `@uiw/codemirror-themes-all` library
124124
* - `localCustom` - Build by user and saved locally
125125
* - `underConstructionTheme` - user is currently constructing/configuring new theme

components/editor/SnippngControlHeader.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { useSnippngEditor } from "@/context/SnippngEditorContext";
22
import { useToast } from "@/context/ToastContext";
33
import { ColorPicker } from "@/lib/color-picker";
44
import {
5-
defaultEditorConfig,
65
DEFAULT_RANGES,
76
DOWNLOAD_OPTIONS,
8-
getAvailableThemes,
97
LANGUAGES,
8+
defaultEditorConfig,
9+
getAvailableThemes,
1010
predefinedConfig,
1111
} from "@/lib/constants";
1212
import { ImagePicker } from "@/lib/image-picker";
1313
import { SelectOptionInterface } from "@/types";
14-
import { getEditorWrapperBg, LocalStorage } from "@/utils";
14+
import { getEditorWrapperBg } from "@/utils";
1515
import { Menu, Transition } from "@headlessui/react";
1616
import {
1717
ArrowPathIcon,
@@ -21,6 +21,7 @@ import {
2121
Cog6ToothIcon,
2222
CommandLineIcon,
2323
DocumentDuplicateIcon,
24+
FireIcon,
2425
PhotoIcon,
2526
SparklesIcon,
2627
} from "@heroicons/react/24/outline";
@@ -129,7 +130,16 @@ const SnippngControlHeader: React.FC<{
129130
}
130131
handleConfigChange("selectedTheme")(val);
131132
}}
132-
options={getAvailableThemes()}
133+
options={getAvailableThemes()?.map((op) => {
134+
if (op?.isCustom) {
135+
// render icon for a custom theme
136+
return {
137+
...op,
138+
icon: FireIcon,
139+
};
140+
}
141+
return op;
142+
})}
133143
/>
134144
) : null}
135145
<Select

components/editor/SnippngThemeBuilder.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const SnippngThemeBuilder: React.FC<{
1313
}> = ({ themeConfig = { ...defaultCustomTheme } }) => {
1414
const [theme, setTheme] = useState<SnippngThemeAttributesInterface>({
1515
...themeConfig,
16+
isCustom: true,
1617
});
1718

1819
const { handleConfigChange, setEditorConfig } = useSnippngEditor();

components/form/Select.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { SelectOptionInterface } from "@/types";
22
import { clsx } from "@/utils";
33
import { Listbox, Transition } from "@headlessui/react";
44
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/20/solid";
5+
import { FireIcon } from "@heroicons/react/24/outline";
56
import React, { Fragment } from "react";
67

78
export interface SelectComponentProps {
89
value: SelectOptionInterface;
9-
options: { id: string; label: string }[];
10+
options: {
11+
id: string;
12+
label: string;
13+
icon?: (props: React.SVGProps<SVGSVGElement>) => JSX.Element;
14+
}[];
1015
onChange: (value: SelectOptionInterface) => void;
1116
children?: React.ReactNode;
1217
placeholder?: string | React.ReactNode;
@@ -73,9 +78,15 @@ const Select: React.FC<SelectComponentProps> = ({
7378
value.id === option.id
7479
? "font-semibold"
7580
: "font-normal",
76-
"block truncate"
81+
"inline-flex truncate justify-start items-center gap-2"
7782
)}
7883
>
84+
{option.icon ? (
85+
<option.icon
86+
className="h-5 w-5"
87+
aria-hidden="true"
88+
/>
89+
) : null}
7990
{option.label}
8091
</span>
8192

lib/constants.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { deepClone, LocalStorage } from "@/utils";
66

77
export const isBrowser = typeof window !== "undefined";
88

9-
export const THEMES = [
9+
export const THEMES: {
10+
id: string;
11+
label: string;
12+
isCustom?: boolean;
13+
}[] = [
1014
{
1115
id: "abcdef",
1216
label: "ABCDEF",
@@ -139,13 +143,15 @@ export const getAvailableThemes = () => {
139143
let localThemesToBeMerged: {
140144
id: string;
141145
label: string;
146+
isCustom?: boolean;
142147
}[] = [];
143148

144149
if (localThemes?.length) {
145150
// if there are locally retrieved themes then map them in correct format
146151
localThemesToBeMerged = localThemes?.map((x) => ({
147152
id: x.id,
148153
label: x.label,
154+
isCustom: x.isCustom || false,
149155
}));
150156
}
151157
return [

types/editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface SnippngThemeAttributesInterface {
3939
curlyBraces: string;
4040
controlFlow: string;
4141
};
42+
isCustom?: boolean;
4243
}
4344

4445
export type SnippngWindowControlsType =

0 commit comments

Comments
 (0)