diff --git a/src/components/SearchBox/SearchBox.stories.tsx b/src/components/SearchBox/SearchBox.stories.tsx index c9690e5..158f7cf 100644 --- a/src/components/SearchBox/SearchBox.stories.tsx +++ b/src/components/SearchBox/SearchBox.stories.tsx @@ -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.', }, }, }, @@ -26,7 +26,7 @@ const meta = { }, appearance: { control: 'radio', - options: ['outline', 'transparent'], + options: ['filled', 'outline', 'transparent'], }, }, } satisfies Meta; @@ -68,7 +68,10 @@ export const AppearanceVariants: Story = { render: () => (
- + + + + @@ -87,6 +90,29 @@ export const AppearanceVariants: Story = { export const AppearanceBySize: Story = { render: () => (
+ + + + + + + + + + + & { - /** Visual style: outline (bordered) or transparent (underline only). */ + /** Visual style: filled, outline (bordered), or transparent (underline only). */ appearance?: VscSearchBoxAppearance; }; export const VscSearchBox = forwardRef( ( - { size = 'small', appearance = 'outline', disabled, className, ...rest }, + { size = 'small', appearance = 'filled', disabled, className, ...rest }, ref, ) => { const mergedClass = useSearchBoxStyles({ diff --git a/src/components/SearchBox/useSearchBoxStyles.ts b/src/components/SearchBox/useSearchBoxStyles.ts index 1e246fb..7b52560 100644 --- a/src/components/SearchBox/useSearchBoxStyles.ts +++ b/src/components/SearchBox/useSearchBoxStyles.ts @@ -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 @@ -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', @@ -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', @@ -239,7 +251,7 @@ export interface UseSearchBoxStylesOptions { export function useSearchBoxStyles(options: UseSearchBoxStylesOptions): string { const { size = 'small', - appearance = 'outline', + appearance = 'filled', disabled, className, } = options; @@ -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, diff --git a/test/VscSearchBox.test.tsx b/test/VscSearchBox.test.tsx index bea8a13..b53ea1c 100644 --- a/test/VscSearchBox.test.tsx +++ b/test/VscSearchBox.test.tsx @@ -63,30 +63,28 @@ describe('VscSearchBox', () => { expect(container.querySelector('.custom')).toBeTruthy(); }); - it('produces distinct classes for outline vs transparent appearance', () => { - const { container: outlineContainer } = render( - , - { wrapper }, - ); - const { container: transparentContainer } = render( - , - { 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(, { + 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(, { wrapper, }); - const { container: outlineContainer } = render( - , + const { container: filledContainer } = render( + , { 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); }); });