# All files / src/components/snippet-manager SnippetToolbar.tsx

0% Statements 0/144
0% Branches 0/1
0% Functions 0/1
0% Lines 0/144

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145

     import { Button } from '@/components/ui/button'
    import { Input } from '@/components/ui/input'
    import { Plus, MagnifyingGlass, CaretDown, CheckSquare, X } from '@phosphor-icons/react'
    import {
      DropdownMenu,
      DropdownMenuContent,
      DropdownMenuItem,
      DropdownMenuSeparator,
      DropdownMenuTrigger,
      DropdownMenuLabel,
    } from '@/components/ui/dropdown-menu'
    import { strings } from '@/lib/config'
    import { SnippetTemplate } from '@/lib/types'

    interface SnippetToolbarProps {
      searchQuery: string
      onSearchChange: (value: string) => void
      selectionMode: boolean
      onToggleSelectionMode: () => void
      onCreateNew: () => void
      onCreateFromTemplate: (templateId: string) => void
      templates: SnippetTemplate[]
    }

    export function SnippetToolbar({
      searchQuery,
      onSearchChange,
      selectionMode,
      onToggleSelectionMode,
      onCreateNew,
      onCreateFromTemplate,
      templates,
    }: SnippetToolbarProps) {
      return (
        <div className="flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between">
          <div className="relative flex-1 w-full sm:max-w-md">
            <MagnifyingGlass
              className="absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-muted-foreground"
              aria-hidden="true"
            />
            <Input
              placeholder={strings.app.search.placeholder}
              value={searchQuery}
              onChange={(e) => onSearchChange(e.target.value)}
              className="pl-10"
              data-testid="snippet-search-input"
              aria-label="Search snippets"
            />
          </div>
          <div className="flex gap-2 w-full sm:w-auto">
            <Button
              variant={selectionMode ? "filled" : "outline"}
              onClick={onToggleSelectionMode}
              className="gap-2"
              data-testid="snippet-selection-mode-btn"
              aria-pressed={selectionMode}
              aria-label={selectionMode ? "Cancel selection mode" : "Enter selection mode"}
            >
              {selectionMode ? (
                <>
                  <X weight="bold" aria-hidden="true" />
                  Cancel
                </>
              ) : (
                <>
                  <CheckSquare weight="bold" aria-hidden="true" />
                  Select
                </>
              )}
            </Button>
            <DropdownMenu>
              <DropdownMenuTrigger asChild>
                <Button
                  className="gap-2 w-full sm:w-auto"
                  data-testid="snippet-create-menu-trigger"
                  aria-label="Create new snippet"
                >
                  <Plus weight="bold" aria-hidden="true" />
                  {strings.app.header.newSnippetButton}
                  <CaretDown weight="bold" aria-hidden="true" />
                </Button>
              </DropdownMenuTrigger>
              <DropdownMenuContent align="end" className="w-72 max-h-[500px] overflow-y-auto">
                <DropdownMenuItem
                  onClick={onCreateNew}
                  data-testid="snippet-create-blank-item"
                >
                  <Plus className="mr-2 h-4 w-4" weight="bold" aria-hidden="true" />
                  Blank Snippet
                </DropdownMenuItem>
                <DropdownMenuSeparator />
                <DropdownMenuLabel>React Components</DropdownMenuLabel>
                {templates.filter((t) => t.category === 'react').map((template) => (
                  <DropdownMenuItem
                    key={template.id}
                    onClick={() => onCreateFromTemplate(template.id)}
                    data-testid={`snippet-template-react-${template.id}`}
                  >
                    <div className="flex flex-col gap-1 py-1">
                      <span className="font-medium">{template.title}</span>
                      <span className="text-xs text-muted-foreground line-clamp-1">
                        {template.description}
                      </span>
                    </div>
                  </DropdownMenuItem>
                ))}
                <DropdownMenuSeparator />
                <DropdownMenuLabel>Python Scripts</DropdownMenuLabel>
                {templates.filter((t) => t.category === 'python').map((template) => (
                  <DropdownMenuItem
                    key={template.id}
                    onClick={() => onCreateFromTemplate(template.id)}
                    data-testid={`snippet-template-python-${template.id}`}
                  >
                    <div className="flex flex-col gap-1 py-1">
                      <span className="font-medium">{template.title}</span>
                      <span className="text-xs text-muted-foreground line-clamp-1">
                        {template.description}
                      </span>
                    </div>
                  </DropdownMenuItem>
                ))}
                <DropdownMenuSeparator />
                <DropdownMenuLabel>JavaScript Utils</DropdownMenuLabel>
                {templates.filter((t) => t.category === 'javascript').map((template) => (
                  <DropdownMenuItem
                    key={template.id}
                    onClick={() => onCreateFromTemplate(template.id)}
                    data-testid={`snippet-template-javascript-${template.id}`}
                  >
                    <div className="flex flex-col gap-1 py-1">
                      <span className="font-medium">{template.title}</span>
                      <span className="text-xs text-muted-foreground line-clamp-1">
                        {template.description}
                      </span>
                    </div>
                  </DropdownMenuItem>
                ))}
              </DropdownMenuContent>
            </DropdownMenu>
          </div>
        </div>
      )
    }