@@ -15,7 +15,6 @@ import {
1515}  from  "@/client/components/Tooltip" ; 
1616import  {  useStore  }  from  "@/client/store" ; 
1717import  { 
18- BookIcon , 
1918CheckIcon , 
2019ChevronDownIcon , 
2120CopyIcon , 
@@ -25,8 +24,9 @@ import {
2524SquareMousePointerIcon , 
2625TextCursorInputIcon , 
2726ToggleLeftIcon , 
27+ ZapIcon , 
2828}  from  "lucide-react" ; 
29- import  {  type  FC ,  useEffect ,  useRef ,  useState  }  from  "react" ; 
29+ import  {  type  FC ,  useCallback ,   useEffect ,  useRef ,  useState  }  from  "react" ; 
3030import  CodeEditor  from  "react-simple-code-editor" ; 
3131
3232// The following imports can't be re-ordered otherwise things break 
@@ -35,6 +35,8 @@ import { highlight, languages } from "prismjs/components/prism-core";
3535import  "prismjs/components/prism-hcl" ; 
3636import  "prismjs/themes/prism.css" ; 
3737import  {  cn  }  from  "@/utils/cn" ; 
38+ import  type  {  ParameterFormType  }  from  "@/gen/types" ; 
39+ import  {  multiSelect ,  radio ,  switchInput ,  textInput  }  from  "@/client/snippets" ; 
3840
3941// Adds line numbers to the highlight. 
4042const  hightlightWithLineNumbers  =  ( input : string ,  language : unknown )  => 
@@ -62,6 +64,20 @@ export const Editor: FC = () => {
6264setCodeCopied ( ( )  =>  true ) ; 
6365} ; 
6466
67+ const  onAddSnippet  =  useCallback ( 
68+ ( formType : ParameterFormType )  =>  { 
69+ if  ( formType  ===  "input" )  { 
70+ $setCode ( `${ $code . trimEnd ( ) } ${ textInput }  ) ; 
71+ }  else  if  ( formType  ===  "radio" )  { 
72+ $setCode ( `${ $code . trimEnd ( ) } ${ radio }  ) ; 
73+ }  else  if  ( formType  ===  "multi-select" )  { 
74+ $setCode ( `${ $code . trimEnd ( ) } ${ multiSelect }  ) ; 
75+ }  else  if  ( formType  ===  "switch" )  { 
76+ $setCode ( `${ $code . trimEnd ( ) } ${ switchInput }  ) ; 
77+ } 
78+ } , 
79+ [ $code ,  $setCode ] , 
80+ ) ; 
6581
6682useEffect ( ( )  =>  { 
6783if  ( ! codeCopied )  { 
@@ -105,27 +121,29 @@ export const Editor: FC = () => {
105121< DropdownMenu > 
106122< DropdownMenuTrigger  className = "flex w-fit min-w-[140px] cursor-pointer items-center justify-between rounded-md border bg-surface-primary px-2 py-1.5 text-content-secondary transition-colors hover:text-content-primary data-[state=open]:text-content-primary" > 
107123< div  className = "flex items-center justify-center gap-2" > 
108- < BookIcon  width = { 18 }  height = { 18 }  /> 
109- < p  className = "text-xs" > Examples </ p > 
124+ < ZapIcon  width = { 18 }  height = { 18 }  /> 
125+ < p  className = "text-xs" > Snippets </ p > 
110126</ div > 
111127< ChevronDownIcon  width = { 18 }  height = { 18 }  /> 
112128</ DropdownMenuTrigger > 
113129
114130< DropdownMenuPortal > 
115131< DropdownMenuContent  align = "start" > 
116- < DropdownMenuItem > 
132+ < DropdownMenuItem   onClick = { ( )   =>   onAddSnippet ( "input" ) } > 
117133< TextCursorInputIcon  width = { 24 }  height = { 24 }  /> 
118134Text input
119135</ DropdownMenuItem > 
120- < DropdownMenuItem > 
136+ < DropdownMenuItem 
137+ onClick = { ( )  =>  onAddSnippet ( "multi-select" ) } 
138+ > 
121139< SquareMousePointerIcon  width = { 24 }  height = { 24 }  /> 
122140Multi-select
123141</ DropdownMenuItem > 
124- < DropdownMenuItem > 
142+ < DropdownMenuItem   onClick = { ( )   =>   onAddSnippet ( "radio" ) } > 
125143< RadioIcon  width = { 24 }  height = { 24 }  /> 
126144Radio
127145</ DropdownMenuItem > 
128- < DropdownMenuItem > 
146+ < DropdownMenuItem   onClick = { ( )   =>   onAddSnippet ( "switch" ) } > 
129147< ToggleLeftIcon  width = { 24 }  height = { 24 }  />  Switches
130148</ DropdownMenuItem > 
131149</ DropdownMenuContent > 
0 commit comments