Skip to content

Commit 35d44d7

Browse files
committed
Refactor templates component to support custom icons labels and accent colors
- add missing translations to [Pasted text] - edit/ask templates should not use translations, should say edit/ask for all languages - templates should have <Templates rendered twice, provide label through templates object - should use css for [Pasted text] - a single <Templates component should render all various "templates for.." - template should show appropriate icon to the left of label for each prompt type - label in templates should use bangers mixin - style the opened template like active `packages/ui/src/components/editor/prompt/IconAccentButton/IconAccentButton.tsx` - `packages/ui/src/components/editor/settings/Templates/Templates.tsx` should receive details such like icons/colors from the outside (to be totally generic) - remove green color ├── apps │ └── editor │ └── src │ └── views │ ├── prompt │ │ └── frontend │ │ ├── Prompt.module.scss │ │ └── Prompt.tsx │ └── settings │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-create-template.ts │ │ │ ├── handle-delete-template.ts │ │ │ ├── handle-get-templates.ts │ │ │ ├── handle-update-templates.ts │ │ │ └── index.ts │ │ └── settings-view-provider.ts │ ├── frontend │ │ ├── Home │ │ │ ├── Home.tsx │ │ │ └── sections │ │ │ └── GeneralSection.tsx │ │ ├── Settings.tsx │ │ ├── forms │ │ │ └── EditTemplateForm │ │ │ ├── EditTemplateForm.module.scss │ │ │ ├── EditTemplateForm.tsx │ │ │ └── index.ts │ │ ├── hooks │ │ │ └── use-settings.ts │ │ └── i18n │ │ └── translations │ │ ├── edit-template-form.ts │ │ └── general.ts │ └── types │ └── messages.ts └── packages └── ui └── src └── components └── editor ├── prompt │ └── IconAccentButton │ ├── IconAccentButton.module.scss │ ├── IconAccentButton.stories.tsx │ ├── IconAccentButton.tsx │ └── index.ts └── settings └── Templates ├── Templates.module.scss ├── Templates.tsx └── index.ts
1 parent c73ac4c commit 35d44d7

10 files changed

Lines changed: 107 additions & 100 deletions

File tree

‎apps/editor/src/views/settings/frontend/Home/sections/GeneralSection.tsx‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,24 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
233233
<UiItem
234234
title={t('general.prompt-field.templates.title')}
235235
description={t('general.prompt-field.templates.description')}
236-
translations={{
237-
expand: t('common.expand'),
238-
collapse: t('common.collapse')
239-
}}
240236
>
241237
<Templates
242-
templates={props.templates}
238+
templates={[
239+
{
240+
key: 'templatesForEditFiles',
241+
label: 'Edit',
242+
icon: 'edit-sparkle',
243+
accent_color: 'blue',
244+
items: props.templates.templatesForEditFiles || []
245+
},
246+
{
247+
key: 'templatesForAskAboutFiles',
248+
label: 'Ask',
249+
icon: 'chat-sparkle',
250+
accent_color: 'orange',
251+
items: props.templates.templatesForAskAboutFiles || []
252+
}
253+
]}
243254
on_reorder={(key, templates) =>
244255
props.on_update_templates(key, templates)
245256
}
@@ -254,15 +265,7 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
254265
),
255266
expand: t('common.expand'),
256267
collapse: t('common.collapse'),
257-
add_new: t('action.add-new'),
258-
types: {
259-
templatesForEditFiles: t(
260-
'general.prompt-field.templates.types.templatesForEditFiles'
261-
),
262-
templatesForAskAboutFiles: t(
263-
'general.prompt-field.templates.types.templatesForAskAboutFiles'
264-
)
265-
}
268+
add_new: t('action.add-new')
266269
}}
267270
/>
268271
</UiItem>

‎apps/editor/src/views/settings/frontend/i18n/translations/general.ts‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,41 +1144,5 @@ export const translations = {
11441144
cs: 'šablon',
11451145
hu: 'sablon',
11461146
bg: 'шаблона'
1147-
},
1148-
'general.prompt-field.templates.types.templatesForAskAboutFiles': {
1149-
en: 'Ask About Files',
1150-
pl: 'Zapytaj o pliki',
1151-
'zh-cn': '询问关于文件',
1152-
ja: 'ファイルについて尋ねる',
1153-
'zh-tw': '詢問關於文件',
1154-
de: 'Nach Dateien fragen',
1155-
es: 'Preguntar sobre archivos',
1156-
fr: 'Demander à propos des fichiers',
1157-
'pt-br': 'Perguntar sobre arquivos',
1158-
ru: 'Спросить о файлах',
1159-
ko: '파일에 대해 물어보기',
1160-
it: 'Chiedi sui file',
1161-
tr: 'Dosyalar Hakkında Sor',
1162-
cs: 'Zeptat se na soubory',
1163-
hu: 'Kérdezz fájlokról',
1164-
bg: 'Попитай за файлове'
1165-
},
1166-
'general.prompt-field.templates.types.templatesForEditFiles': {
1167-
en: 'Edit Files',
1168-
pl: 'Edytuj pliki',
1169-
'zh-cn': '编辑文件',
1170-
ja: 'ファイルを編集',
1171-
'zh-tw': '編輯文件',
1172-
de: 'Dateien bearbeiten',
1173-
es: 'Editar archivos',
1174-
fr: 'Modifier des fichiers',
1175-
'pt-br': 'Editar arquivos',
1176-
ru: 'Редактировать файлы',
1177-
ko: '파일 편집',
1178-
it: 'Modifica file',
1179-
tr: 'Dosyaları Düzenle',
1180-
cs: 'Upravit soubory',
1181-
hu: 'Fájlok szerkesztése',
1182-
bg: 'Редактиране на файлове'
11831147
}
11841148
} as const

‎packages/ui/src/components/editor/prompt/IconAccentButton/IconAccentButton.module.scss‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,6 @@
5656
}
5757
}
5858

59-
&.button--green {
60-
background-color: var(--cwc-bg-green);
61-
62-
.button__icon,
63-
.button__label {
64-
color: var(--cwc-text-color-green);
65-
}
66-
67-
&:hover {
68-
background-color: var(--cwc-bg-green);
69-
}
70-
}
71-
7259
&.button--red {
7360
background-color: var(--cwc-bg-red);
7461

‎packages/ui/src/components/editor/prompt/IconAccentButton/IconAccentButton.stories.tsx‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ export const ActiveOrange = () => (
4949
/>
5050
)
5151

52-
export const ActiveGreen = () => (
53-
<IconAccentButton
54-
label="Active Green Button"
55-
icon="check"
56-
is_active
57-
active_color="green"
58-
on_click={() => console.log('Clicked')}
59-
/>
60-
)
61-
6252
export const ActiveRed = () => (
6353
<IconAccentButton
6454
label="Active Red Button"

‎packages/ui/src/components/editor/prompt/IconAccentButton/IconAccentButton.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export namespace IconAccentButton {
88
icon: string
99
is_compact?: boolean
1010
is_active?: boolean
11-
active_color?: 'blue' | 'orange' | 'green' | 'red'
11+
active_color?: 'blue' | 'orange' | 'red'
1212
on_click?: () => void
1313
}
1414
}
@@ -23,8 +23,6 @@ export const IconAccentButton: FC<IconAccentButton.Props> = (props) => {
2323
props.is_active && props.active_color == 'blue',
2424
[styles['button--orange']]:
2525
props.is_active && props.active_color == 'orange',
26-
[styles['button--green']]:
27-
props.is_active && props.active_color == 'green',
2826
[styles['button--red']]: props.is_active && props.active_color == 'red'
2927
})}
3028
onClick={props.on_click}

‎packages/ui/src/components/editor/settings/NavigationItemSection/NavigationItemSection.module.scss‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
justify-content: space-between;
55
gap: 8px;
66
padding: 0 8px;
7-
border-radius: 4px;
87
font-size: 18px;
98
@include accent-font;
10-
color: var(--vscode-textLink-foreground);
119
height: 32px;
12-
transition: background-color 0.1s;
1310
}
1411

1512
.label {

‎packages/ui/src/components/editor/settings/Section/Section.module.scss‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@
5656
}
5757

5858
&__title {
59+
@include accent-font;
5960
margin: 0;
6061
font-size: 24px;
61-
@include accent-font;
6262
white-space: nowrap;
63-
color: var(--vscode-textLink-foreground);
6463
overflow: hidden;
6564
text-overflow: ellipsis;
6665
}

‎packages/ui/src/components/editor/settings/Templates/Templates.module.scss‎

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
.groups {
1+
.container {
22
display: flex;
33
flex-direction: column;
44
gap: 8px;
5+
width: 100%;
56
}
67

78
.group {
@@ -17,6 +18,48 @@
1718
}
1819
}
1920

21+
&--accent-blue {
22+
border-color: var(--cwc-bg-blue);
23+
.group__header {
24+
background-color: var(--cwc-bg-blue);
25+
.group__icon,
26+
.group__label {
27+
color: var(--cwc-text-color-blue);
28+
}
29+
&:hover {
30+
background-color: var(--cwc-bg-blue);
31+
}
32+
}
33+
}
34+
35+
&--accent-orange {
36+
border-color: var(--cwc-bg-orange);
37+
.group__header {
38+
background-color: var(--cwc-bg-orange);
39+
.group__icon,
40+
.group__label {
41+
color: var(--cwc-text-color-orange);
42+
}
43+
&:hover {
44+
background-color: var(--cwc-bg-orange);
45+
}
46+
}
47+
}
48+
49+
&--accent-red {
50+
border-color: var(--cwc-bg-red);
51+
.group__header {
52+
background-color: var(--cwc-bg-red);
53+
.group__icon,
54+
.group__label {
55+
color: var(--cwc-text-color-red);
56+
}
57+
&:hover {
58+
background-color: var(--cwc-bg-red);
59+
}
60+
}
61+
}
62+
2063
&__header {
2164
position: relative;
2265
display: flex;
@@ -32,8 +75,21 @@
3275
}
3376

3477
&__title {
35-
font-size: 13px;
36-
font-weight: 600;
78+
display: flex;
79+
align-items: center;
80+
gap: 6px;
81+
}
82+
83+
&__label {
84+
@include accent-font;
85+
font-size: 16px;
86+
line-height: 1;
87+
padding-top: 2px;
88+
padding-right: 1px;
89+
}
90+
91+
&__icon {
92+
font-size: 14px;
3793
}
3894

3995
&__content {

‎packages/ui/src/components/editor/settings/Templates/Templates.tsx‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ export namespace Templates {
1111
}
1212

1313
export type Props = {
14-
templates: Record<string, Template[]>
14+
templates: {
15+
key: string
16+
label: string
17+
icon?: string
18+
accent_color?: 'blue' | 'orange' | 'red'
19+
items: Template[]
20+
}[]
1521
on_reorder: (key: string, templates: Template[]) => void
1622
on_delete: (key: string, index: number) => void
1723
on_edit: (key: string, index: number) => void
@@ -23,7 +29,6 @@ export namespace Templates {
2329
item_text: string
2430
items_text: string
2531
items_text_many: string
26-
types: Record<string, string>
2732
expand: string
2833
collapse: string
2934
add_new: string
@@ -32,41 +37,49 @@ export namespace Templates {
3237
}
3338

3439
export const Templates: React.FC<Templates.Props> = (props) => {
35-
const [expanded_keys, set_expanded_keys] = useState<Record<string, boolean>>(
36-
{}
37-
)
40+
const [expanded_keys, set_expanded_keys] = useState<string[]>([])
3841

3942
const toggle_expanded = (key: string) => {
40-
set_expanded_keys((prev) => ({
41-
...prev,
42-
[key]: !prev[key]
43-
}))
43+
set_expanded_keys((prev) =>
44+
prev.includes(key) ? prev.filter((k) => k !== key) : [...prev, key]
45+
)
4446
}
4547

4648
return (
47-
<div className={styles.groups}>
48-
{Object.entries(props.templates).map(([key, templates]) => {
49-
const sortable_items = templates.map((t, index) => ({
49+
<div className={styles.container}>
50+
{props.templates.map(({ key, label, icon, accent_color, items }) => {
51+
const is_expanded = expanded_keys.includes(key)
52+
const sortable_items = items.map((t, index) => ({
5053
id: `${index}-${t.name}-${t.template}`,
5154
original_index: index,
5255
...t
5356
}))
54-
const is_expanded = !!expanded_keys[key]
5557

5658
return (
5759
<div
5860
key={key}
5961
className={cn(styles.group, {
6062
[styles['group--expanded']]: is_expanded,
61-
[styles['group--hoverable']]: !is_expanded
63+
[styles['group--hoverable']]: !is_expanded,
64+
[styles[`group--accent-${accent_color}`]]:
65+
accent_color && is_expanded
6266
})}
6367
>
6468
<div
6569
className={styles.group__header}
6670
onClick={() => toggle_expanded(key)}
6771
>
6872
<div className={styles.group__title}>
69-
{props.translations.types[key] || key}
73+
{icon && (
74+
<span
75+
className={cn(
76+
'codicon',
77+
`codicon-${icon}`,
78+
styles.group__icon
79+
)}
80+
/>
81+
)}
82+
<span className={styles.group__label}>{label}</span>
7083
</div>
7184
<IconButton
7285
codicon_icon={is_expanded ? 'chevron-up' : 'chevron-down'}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@mixin accent-font {
22
font-family: 'Bangers', system-ui;
3-
font-weight: 600;
3+
font-weight: 500;
44
letter-spacing: 0.08em;
55
}

0 commit comments

Comments
 (0)