Skip to content

Commit 4dbda94

Browse files
committed
Integrate KeycapWrapper into TargetButton via keycap_char prop
- when sticky, the keycap is underneath label - keycaps are not perfectly aligned over sticky target buttons - keycap should appear always over target's label, not just in the middle of the overal button ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── frontend │ └── Home │ ├── Home.module.scss │ └── Home.tsx └── packages └── ui └── src └── components └── editor └── prompt ├── KeycapWrapper │ ├── KeycapWrapper.module.scss │ ├── KeycapWrapper.stories.tsx │ ├── KeycapWrapper.tsx │ └── index.ts └── TargetButton ├── TargetButton.module.scss └── TargetButton.tsx
1 parent 8ca4fd3 commit 4dbda94

4 files changed

Lines changed: 64 additions & 61 deletions

File tree

‎apps/editor/src/views/prompt/frontend/Home/Home.tsx‎

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import styles from './Home.module.scss'
33
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
44
import { Tabs as UiTabs } from '@ui/components/editor/prompt/Tabs'
55
import { TargetButton as UiTargetButton } from '@ui/components/editor/prompt/TargetButton'
6-
import { KeycapWrapper as UiKeycapWrapper } from '@ui/components/editor/prompt/KeycapWrapper'
76
import cn from 'classnames'
87
import { post_message } from '../utils/post-message'
98
import { BackendMessage } from '@/views/prompt/types/messages'
@@ -187,76 +186,64 @@ export const Home: React.FC<Props> = (props) => {
187186
[styles['header__targets--visible']]: has_scrolled_past_target_button
188187
})}
189188
>
190-
<UiKeycapWrapper char={is_alt_pressed ? 'W' : undefined} full_width>
191-
<UiTargetButton
192-
label={TARGET.WEB}
193-
on_click={props.on_chatbots_click}
194-
is_compact
195-
hover_color={
196-
props.web_prompt_type == 'edit-files' ? 'blue' : 'purple'
197-
}
198-
/>
199-
</UiKeycapWrapper>
200-
<UiKeycapWrapper char={is_alt_pressed ? 'A' : undefined} full_width>
201-
<UiTargetButton
202-
label={TARGET.API}
203-
on_click={props.on_api_calls_click}
204-
is_compact
205-
hover_color={
206-
props.api_prompt_type == 'edit-files' ? 'blue' : 'purple'
207-
}
208-
/>
209-
</UiKeycapWrapper>
210-
<UiKeycapWrapper char={is_alt_pressed ? 'C' : undefined} full_width>
211-
<UiTargetButton
212-
label={TARGET.CLI}
213-
on_click={props.on_cli_calls_click}
214-
is_compact
215-
hover_color={
216-
props.cli_prompt_type == 'edit-files' ? 'blue' : 'purple'
217-
}
218-
/>
219-
</UiKeycapWrapper>
220-
</div>
221-
</div>
222-
)
223-
224-
const targets_section = (
225-
<div className={styles.inner__target} ref={target_ref}>
226-
<UiKeycapWrapper char={is_alt_pressed ? 'W' : undefined} full_width>
227189
<UiTargetButton
228190
label={TARGET.WEB}
229-
description={
230-
props.is_connected
231-
? t('home.target.web.description-connected')
232-
: t('home.target.web.description')
233-
}
234191
on_click={props.on_chatbots_click}
192+
is_compact
235193
hover_color={
236194
props.web_prompt_type == 'edit-files' ? 'blue' : 'purple'
237195
}
196+
keycap_char={is_alt_pressed ? 'W' : undefined}
238197
/>
239-
</UiKeycapWrapper>
240-
<UiKeycapWrapper char={is_alt_pressed ? 'A' : undefined} full_width>
241198
<UiTargetButton
242199
label={TARGET.API}
243-
description={t('home.target.api.description')}
244200
on_click={props.on_api_calls_click}
201+
is_compact
245202
hover_color={
246203
props.api_prompt_type == 'edit-files' ? 'blue' : 'purple'
247204
}
205+
keycap_char={is_alt_pressed ? 'A' : undefined}
248206
/>
249-
</UiKeycapWrapper>
250-
<UiKeycapWrapper char={is_alt_pressed ? 'C' : undefined} full_width>
251207
<UiTargetButton
252208
label={TARGET.CLI}
253-
description={t('home.target.cli.description')}
254209
on_click={props.on_cli_calls_click}
210+
is_compact
255211
hover_color={
256212
props.cli_prompt_type == 'edit-files' ? 'blue' : 'purple'
257213
}
214+
keycap_char={is_alt_pressed ? 'C' : undefined}
258215
/>
259-
</UiKeycapWrapper>
216+
</div>
217+
</div>
218+
)
219+
220+
const targets_section = (
221+
<div className={styles.inner__target} ref={target_ref}>
222+
<UiTargetButton
223+
label={TARGET.WEB}
224+
description={
225+
props.is_connected
226+
? t('home.target.web.description-connected')
227+
: t('home.target.web.description')
228+
}
229+
on_click={props.on_chatbots_click}
230+
hover_color={props.web_prompt_type == 'edit-files' ? 'blue' : 'purple'}
231+
keycap_char={is_alt_pressed ? 'W' : undefined}
232+
/>
233+
<UiTargetButton
234+
label={TARGET.API}
235+
description={t('home.target.api.description')}
236+
on_click={props.on_api_calls_click}
237+
hover_color={props.api_prompt_type == 'edit-files' ? 'blue' : 'purple'}
238+
keycap_char={is_alt_pressed ? 'A' : undefined}
239+
/>
240+
<UiTargetButton
241+
label={TARGET.CLI}
242+
description={t('home.target.cli.description')}
243+
on_click={props.on_cli_calls_click}
244+
hover_color={props.cli_prompt_type == 'edit-files' ? 'blue' : 'purple'}
245+
keycap_char={is_alt_pressed ? 'C' : undefined}
246+
/>
260247
</div>
261248
)
262249

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
font-family: var(--vscode-font-family);
2424
line-height: 1;
2525
pointer-events: none;
26+
z-index: 1;
2627
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
height: 100%;
2929
gap: 8px;
3030
border-radius: 0;
31+
padding: 0;
3132

3233
.button__label {
3334
font-size: 18px;
@@ -116,6 +117,13 @@
116117
flex-shrink: 0;
117118
}
118119

120+
&__keycap-wrapper {
121+
flex-shrink: 0;
122+
height: auto;
123+
align-items: center;
124+
z-index: 1;
125+
}
126+
119127
&__label-char {
120128
display: inline-block;
121129
position: relative;

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import styles from './TargetButton.module.scss'
22
import cn from 'classnames'
33
import { AsciiArtEffect } from '../AsciiArtEffect'
4+
import { KeycapWrapper } from '../KeycapWrapper'
45

56
type Props = {
67
label: string
@@ -9,6 +10,7 @@ type Props = {
910
is_compact?: boolean
1011
disabled?: boolean
1112
hover_color?: 'blue' | 'purple'
13+
keycap_char?: string
1214
}
1315

1416
export const TargetButton: React.FC<Props> = (props) => {
@@ -27,17 +29,22 @@ export const TargetButton: React.FC<Props> = (props) => {
2729
disabled={!!props.disabled}
2830
>
2931
<AsciiArtEffect />
30-
<div className={styles['button__label']}>
31-
{props.label.split('').map((char, index) => (
32-
<span
33-
key={index}
34-
className={styles['button__label-char']}
35-
style={{ animationDelay: `${index * 0.05}s` }}
36-
>
37-
{char == ' ' ? '\u00A0' : char}
38-
</span>
39-
))}
40-
</div>
32+
<KeycapWrapper
33+
char={props.keycap_char}
34+
className={styles['button__keycap-wrapper']}
35+
>
36+
<div className={styles['button__label']}>
37+
{props.label.split('').map((char, index) => (
38+
<span
39+
key={index}
40+
className={styles['button__label-char']}
41+
style={{ animationDelay: `${index * 0.05}s` }}
42+
>
43+
{char == ' ' ? '\u00A0' : char}
44+
</span>
45+
))}
46+
</div>
47+
</KeycapWrapper>
4148
{props.description && !props.is_compact && (
4249
<div className={styles['button__description']}>
4350
<span>{props.description}</span>

0 commit comments

Comments
 (0)