Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/components/SearchBox/SearchBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const meta = {
docs: {
description: {
component:
'A search-specific input with a built-in search icon and dismiss action, styled to match VS Code. Defaults to `small` size and `outline` appearance.',
'A search-specific input with a built-in search icon and dismiss action, styled to match VS Code. Defaults to `small` size and `filled` appearance.',
},
},
},
Expand All @@ -26,7 +26,7 @@ const meta = {
},
appearance: {
control: 'radio',
options: ['outline', 'transparent'],
options: ['filled', 'outline', 'transparent'],
},
},
} satisfies Meta<typeof VscSearchBox>;
Expand Down Expand Up @@ -68,7 +68,10 @@ export const AppearanceVariants: Story = {
render: () => (
<Section title="Appearance Variants">
<Row>
<Inline label="Outline (default)">
<Inline label="Filled (default)">
<VscSearchBox appearance="filled" placeholder="Placeholder text" />
</Inline>
<Inline label="Outline">
<VscSearchBox appearance="outline" placeholder="Placeholder text" />
</Inline>
<Inline label="Transparent">
Expand All @@ -87,6 +90,29 @@ export const AppearanceVariants: Story = {
export const AppearanceBySize: Story = {
render: () => (
<Section title="Appearance × Size">
<Row>
<Inline label="Filled Small">
<VscSearchBox
appearance="filled"
size="small"
placeholder="Placeholder text"
/>
</Inline>
<Inline label="Filled Medium">
<VscSearchBox
appearance="filled"
size="medium"
placeholder="Placeholder text"
/>
</Inline>
<Inline label="Filled Large">
<VscSearchBox
appearance="filled"
size="large"
placeholder="Placeholder text"
/>
</Inline>
</Row>
<Row>
<Inline label="Outline Small">
<VscSearchBox
Expand Down
4 changes: 2 additions & 2 deletions src/components/SearchBox/VscSearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
} from './useSearchBoxStyles';

export type VscSearchBoxProps = Omit<SearchBoxProps, 'appearance'> & {
/** Visual style: outline (bordered) or transparent (underline only). */
/** Visual style: filled, outline (bordered), or transparent (underline only). */
appearance?: VscSearchBoxAppearance;
};

export const VscSearchBox = forwardRef<HTMLInputElement, VscSearchBoxProps>(
(
{ size = 'small', appearance = 'outline', disabled, className, ...rest },
{ size = 'small', appearance = 'filled', disabled, className, ...rest },
ref,
) => {
const mergedClass = useSearchBoxStyles({
Expand Down
19 changes: 16 additions & 3 deletions src/components/SearchBox/useSearchBoxStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

import { vscFontFamily } from '../../styles/tokens';

export type VscSearchBoxAppearance = 'outline' | 'transparent';
export type VscSearchBoxAppearance = 'filled' | 'outline' | 'transparent';

// ---------------------------------------------------------------------------
// Base – root override styles via makeStyles
Expand Down Expand Up @@ -113,7 +113,7 @@ const useBaseStyles = makeStyles({
// ---------------------------------------------------------------------------

const useAppearanceStyles = makeStyles({
outline: {
filled: {
backgroundColor: 'var(--vscode-input-background)',
border: '1px solid var(--vscode-input-border)',
borderRadius: '2px',
Expand All @@ -125,6 +125,18 @@ const useAppearanceStyles = makeStyles({
},
},

outline: {
backgroundColor: 'transparent',
border: '1px solid var(--vscode-input-border)',
borderRadius: '2px',

'&.fui-Input:focus-within': {
borderTopColor: 'var(--vscode-input-border)',
borderLeftColor: 'var(--vscode-input-border)',
borderRightColor: 'var(--vscode-input-border)',
},
},

transparent: {
backgroundColor: 'transparent',
border: 'none',
Expand Down Expand Up @@ -239,7 +251,7 @@ export interface UseSearchBoxStylesOptions {
export function useSearchBoxStyles(options: UseSearchBoxStylesOptions): string {
const {
size = 'small',
appearance = 'outline',
appearance = 'filled',
disabled,
className,
} = options;
Expand All @@ -250,6 +262,7 @@ export function useSearchBoxStyles(options: UseSearchBoxStylesOptions): string {

return mergeClasses(
base.root,
appearance === 'filled' && appearanceClasses.filled,
appearance === 'outline' && appearanceClasses.outline,
appearance === 'transparent' && appearanceClasses.transparent,
size === 'medium' && classes.medium,
Expand Down
32 changes: 15 additions & 17 deletions test/VscSearchBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,28 @@ describe('VscSearchBox', () => {
expect(container.querySelector('.custom')).toBeTruthy();
});

it('produces distinct classes for outline vs transparent appearance', () => {
const { container: outlineContainer } = render(
<VscSearchBox appearance="outline" />,
{ wrapper },
);
const { container: transparentContainer } = render(
<VscSearchBox appearance="transparent" />,
{ wrapper },
);
const outlineRoot = outlineContainer.querySelector('.fui-Input')!;
const transparentRoot = transparentContainer.querySelector('.fui-Input')!;
expect(outlineRoot.className).not.toBe(transparentRoot.className);
it('produces distinct classes for each appearance', () => {
const appearances = ['filled', 'outline', 'transparent'] as const;
const classNames = appearances.map((appearance) => {
const { container } = render(<VscSearchBox appearance={appearance} />, {
wrapper,
});
return container.querySelector('.fui-Input')!.className;
});

expect(new Set(classNames).size).toBe(appearances.length);
});

it('defaults to outline appearance', () => {
it('defaults to filled appearance', () => {
const { container: defaultContainer } = render(<VscSearchBox />, {
wrapper,
});
const { container: outlineContainer } = render(
<VscSearchBox appearance="outline" />,
const { container: filledContainer } = render(
<VscSearchBox appearance="filled" />,
{ wrapper },
);
const defaultRoot = defaultContainer.querySelector('.fui-Input')!;
const outlineRoot = outlineContainer.querySelector('.fui-Input')!;
expect(defaultRoot.className).toBe(outlineRoot.className);
const filledRoot = filledContainer.querySelector('.fui-Input')!;
expect(defaultRoot.className).toBe(filledRoot.className);
});
});
Loading