File tree Expand file tree Collapse file tree 6 files changed +37
-8
lines changed Expand file tree Collapse file tree 6 files changed +37
-8
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -2,16 +2,16 @@ import { useSnippngEditor } from "@/context/SnippngEditorContext";
22import { useToast } from "@/context/ToastContext" ;
33import { ColorPicker } from "@/lib/color-picker" ;
44import {
5- defaultEditorConfig ,
65 DEFAULT_RANGES ,
76 DOWNLOAD_OPTIONS ,
8- getAvailableThemes ,
97 LANGUAGES ,
8+ defaultEditorConfig ,
9+ getAvailableThemes ,
1010 predefinedConfig ,
1111} from "@/lib/constants" ;
1212import { ImagePicker } from "@/lib/image-picker" ;
1313import { SelectOptionInterface } from "@/types" ;
14- import { getEditorWrapperBg , LocalStorage } from "@/utils" ;
14+ import { getEditorWrapperBg } from "@/utils" ;
1515import { Menu , Transition } from "@headlessui/react" ;
1616import {
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
Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff line change @@ -2,11 +2,16 @@ import { SelectOptionInterface } from "@/types";
22import { clsx } from "@/utils" ;
33import { Listbox , Transition } from "@headlessui/react" ;
44import { CheckIcon , ChevronUpDownIcon } from "@heroicons/react/20/solid" ;
5+ import { FireIcon } from "@heroicons/react/24/outline" ;
56import React , { Fragment } from "react" ;
67
78export 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
Original file line number Diff line number Diff line change @@ -6,7 +6,11 @@ import { deepClone, LocalStorage } from "@/utils";
66
77export 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 [
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ export interface SnippngThemeAttributesInterface {
3939 curlyBraces : string ;
4040 controlFlow : string ;
4141 } ;
42+ isCustom ?: boolean ;
4243}
4344
4445export type SnippngWindowControlsType =
You can’t perform that action at this time.
0 commit comments