Skip to content

Commit 0f50cbd

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
refactor(emcn): own compact code search field chrome
1 parent 613699a commit 0f50cbd

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/components/code-search-overlay/code-search-overlay.test.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ describe('CodeSearchOverlay', () => {
9898
expect(overlay.getAttribute('data-toolbar-root')).toBe('true')
9999
expect(overlay.getAttribute('data-search-active')).toBe('true')
100100
expect(overlay.hasAttribute('role')).toBe(false)
101-
expect(input.className).toContain('h-[23px] w-[94px] text-caption')
101+
expect(input.parentElement?.className).toContain('h-[23px]')
102+
expect(input.parentElement?.className).toContain('w-[94px]')
103+
expect(input.className).toContain('text-caption')
102104
expect(overlay.textContent).toContain('No results')
103105
expect(overlay.querySelector('span.w-\\[58px\\]')).not.toBeNull()
104106
const previous = overlay.querySelector<HTMLButtonElement>('[aria-label="Previous match"]')

‎apps/sim/app/workspace/[workspaceId]/components/code-search-overlay/code-search-overlay.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { ChangeEvent, Ref } from 'react'
2-
import { Button, ChipInput, cn, Input } from '@sim/emcn'
2+
import { Button, ChipInput, cn } from '@sim/emcn'
33
import { ArrowDown, ArrowUp, X } from '@sim/emcn/icons'
44

55
export interface CodeSearchOverlayProps {
66
/** The attached terminal panel has a joined lower edge and wider result tally. */
77
appearance?: 'floating' | 'attached'
88
/** Position relative to the owning code panel. */
99
className: string
10-
/** Logs use the chip field; previews and terminal output use the plain field. */
10+
/** Logs use the 30px chip field; previews and terminal output use compact search. */
1111
inputKind: 'chip' | 'plain'
1212
inputRef: Ref<HTMLInputElement>
1313
query: string
@@ -65,7 +65,7 @@ export function CodeSearchOverlay({
6565
{inputKind === 'chip' ? (
6666
<ChipInput {...inputProps} className='mr-0.5 w-[94px]' />
6767
) : (
68-
<Input {...inputProps} className='mr-0.5 h-[23px] w-[94px] text-caption' />
68+
<ChipInput {...inputProps} appearance='compactSearch' className='mr-0.5 w-[94px]' />
6969
)}
7070
<span
7171
className={cn(

‎packages/emcn/src/components/chip-input/chip-input.tsx‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* same 1.5 gap as `Chip`. It shares the chip-field chrome with
1515
* {@link ChipTextarea}, shows no focus ring — keep the surface calm and rely on
1616
* the caret for focus. Pass `error` to swap the border to the error token.
17+
* `appearance='compactSearch'` owns the existing 23px code-search field
18+
* treatment without changing the 30px chip default.
1719
*
1820
* @example
1921
* ```tsx
@@ -27,12 +29,29 @@
2729
* ```
2830
*/
2931
import * as React from 'react'
32+
import { cva, type VariantProps } from 'class-variance-authority'
3033
import { cn } from '../../lib/cn'
3134
import { chipFieldSurfaceClass, chipFieldTextClass, chipGeometryClass } from '../chip/chip-chrome'
3235

3336
type ChipInputIcon = React.ComponentType<{ className?: string }>
3437

35-
export interface ChipInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
38+
/** The compact search field keeps the existing code-viewer input geometry. */
39+
export const chipInputVariants = cva('', {
40+
variants: {
41+
appearance: {
42+
chip: '',
43+
compactSearch:
44+
'h-[23px] items-center rounded-sm border border-[var(--border-1)] bg-[var(--surface-5)] px-2 transition-colors',
45+
},
46+
},
47+
defaultVariants: { appearance: 'chip' },
48+
})
49+
50+
export interface ChipInputProps
51+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'>,
52+
VariantProps<typeof chipInputVariants> {
53+
/** The default chip field or the compact code-search field. */
54+
appearance?: VariantProps<typeof chipInputVariants>['appearance']
3655
/** Leading icon component (e.g. `Search` from `@sim/emcn/icons`). Rendered at 14px in `--text-icon`, with the chip's 1.5 gap. */
3756
icon?: ChipInputIcon
3857
/** Custom leading content, such as a color swatch. Takes precedence over `icon`. */
@@ -54,6 +73,7 @@ export interface ChipInputProps extends Omit<React.InputHTMLAttributes<HTMLInput
5473
export const ChipInput = React.forwardRef<HTMLInputElement, ChipInputProps>(
5574
(
5675
{
76+
appearance = 'chip',
5777
className,
5878
inputClassName,
5979
icon: Icon,
@@ -69,8 +89,9 @@ export const ChipInput = React.forwardRef<HTMLInputElement, ChipInputProps>(
6989
<div
7090
className={cn(
7191
'flex w-full',
72-
chipGeometryClass,
73-
chipFieldSurfaceClass,
92+
appearance === 'chip' && chipGeometryClass,
93+
appearance === 'chip' && chipFieldSurfaceClass,
94+
chipInputVariants({ appearance }),
7495
error && 'border-[var(--text-error)]',
7596
disabled && 'opacity-50',
7697
className
@@ -83,8 +104,12 @@ export const ChipInput = React.forwardRef<HTMLInputElement, ChipInputProps>(
83104
type={type}
84105
disabled={disabled}
85106
className={cn(
86-
'-ml-1 h-full w-full bg-transparent indent-1 disabled:cursor-not-allowed',
87-
chipFieldTextClass,
107+
appearance === 'compactSearch'
108+
? 'h-full w-full touch-manipulation scroll-pr-1 bg-transparent font-sans text-[var(--text-primary)] text-caption outline-hidden [letter-spacing:inherit] placeholder:text-[var(--text-muted)] disabled:cursor-not-allowed'
109+
: cn(
110+
'-ml-1 h-full w-full bg-transparent indent-1 disabled:cursor-not-allowed',
111+
chipFieldTextClass
112+
),
88113
inputClassName
89114
)}
90115
{...props}

‎packages/emcn/src/components/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export {
6464
ChipEmailsInput,
6565
type ChipEmailsInputProps,
6666
} from './chip-emails-input/chip-emails-input'
67-
export { ChipInput, type ChipInputProps } from './chip-input/chip-input'
67+
export { ChipInput, type ChipInputProps, chipInputVariants } from './chip-input/chip-input'
6868
export {
6969
type ChipConfirmAction,
7070
type ChipConfirmDefaultAction,

0 commit comments

Comments
 (0)