|
1 | 1 | <script lang="ts"> |
2 | | - import { Button, Modal, SectionCard } from '@gitbutler/ui'; |
| 2 | + import { Modal, Segment, SegmentControl, Icon, Button } from '@gitbutler/ui'; |
| 3 | + import { copyToClipboard } from '@gitbutler/ui/utils/clipboard'; |
3 | 4 | import type { PromptDir } from '$lib/codegen/types'; |
4 | 5 |
|
5 | 6 | type Props = { |
|
14 | 15 | } |
15 | 16 |
|
16 | 17 | const { promptDirs, openPromptConfigDir }: Props = $props(); |
| 18 | +
|
| 19 | + let selectedSegment = $state<string>(promptDirs[0]?.label || ''); |
17 | 20 | </script> |
18 | 21 |
|
19 | | -<Modal bind:this={modal} title="Configure prompt templates"> |
20 | | - <div class="flex flex-col gap-16"> |
21 | | - <p class="text-13"> |
| 22 | +{#snippet pathContent({ path, caption }: { path: string; caption: string })} |
| 23 | + <div class="prompt-path"> |
| 24 | + <button type="button" class="prompt-path__copy" onclick={() => copyToClipboard(path)}> |
| 25 | + <Icon name="copy" /> |
| 26 | + </button> |
| 27 | + |
| 28 | + <span class="prompt-path__label"> Location: </span> |
| 29 | + <span class="prompt-path__path">{path}</span> |
| 30 | + </div> |
| 31 | + |
| 32 | + <p class="text-13 text-body clr-text-2">{caption}</p> |
| 33 | +{/snippet} |
| 34 | + |
| 35 | +<Modal bind:this={modal} width={420} title="Configure prompt templates"> |
| 36 | + <div class="stack-v gap-16"> |
| 37 | + <p class="text-13 text-body clr-text-2"> |
| 38 | + Prompts are searched in two locations. Project prompts override global prompts. Files ending |
| 39 | + in <code class="code-string">.local.md</code> override regular project prompts. |
| 40 | + </p> |
| 41 | + |
| 42 | + <SegmentControl defaultIndex={0}> |
| 43 | + {#each promptDirs as dir} |
| 44 | + <Segment |
| 45 | + onselect={() => (selectedSegment = dir.label)} |
| 46 | + id={dir.label} |
| 47 | + icon={dir.label === 'Global' ? 'global-small' : 'folder'} |
| 48 | + > |
| 49 | + {dir.label} |
| 50 | + </Segment> |
| 51 | + {/each} |
| 52 | + </SegmentControl> |
| 53 | + |
| 54 | + {#if selectedSegment === 'Global'} |
| 55 | + {@render pathContent({ |
| 56 | + path: promptDirs.find((d) => d.label === 'Global')?.path || '', |
| 57 | + caption: 'Contains global prompt templates available to all projects.' |
| 58 | + })} |
| 59 | + {:else if selectedSegment === 'Project'} |
| 60 | + {@render pathContent({ |
| 61 | + path: promptDirs.find((d) => d.label === 'Project')?.path || '', |
| 62 | + caption: 'Contains project-specific prompt templates that override global prompts.' |
| 63 | + })} |
| 64 | + {/if} |
| 65 | + |
| 66 | + <Button |
| 67 | + icon="open-editor-small" |
| 68 | + onclick={() => { |
| 69 | + const dir = promptDirs.find((d) => d.label === selectedSegment); |
| 70 | + if (dir) { |
| 71 | + openPromptConfigDir(dir.path); |
| 72 | + } |
| 73 | + }}>Open in editor</Button |
| 74 | + > |
| 75 | + |
| 76 | + <!-- <p class="text-13"> |
22 | 77 | We have a tierd prompt configuration setup. Prompts are expected to be found in the following |
23 | 78 | locations. |
24 | 79 | </p> |
|
54 | 109 | {/snippet} |
55 | 110 | </SectionCard> |
56 | 111 | {/each} |
57 | | - </div> |
| 112 | + </div> --> |
58 | 113 | </div> |
59 | 114 | </Modal> |
| 115 | + |
| 116 | +<style lang="postcss"> |
| 117 | + .prompt-path { |
| 118 | + display: flex; |
| 119 | + position: relative; |
| 120 | + flex-direction: column; |
| 121 | + padding: 10px; |
| 122 | + gap: 4px; |
| 123 | + border-radius: var(--radius-m); |
| 124 | + background-color: var(--clr-bg-2); |
| 125 | + font-family: var(--font-mono); |
| 126 | + } |
| 127 | +
|
| 128 | + .prompt-path__copy { |
| 129 | + position: absolute; |
| 130 | + top: 12px; |
| 131 | + right: 12px; |
| 132 | + color: var(--clr-text-3); |
| 133 | + transition: color var(--transition-fast); |
| 134 | +
|
| 135 | + &:hover { |
| 136 | + color: var(--clr-text-2); |
| 137 | + } |
| 138 | + } |
| 139 | +
|
| 140 | + .prompt-path__label { |
| 141 | + color: var(--clr-text-2); |
| 142 | + font-size: 12px; |
| 143 | + } |
| 144 | +
|
| 145 | + .prompt-path__path { |
| 146 | + color: var(--clr-text-1); |
| 147 | + font-size: 13px; |
| 148 | + } |
| 149 | +</style> |
0 commit comments