-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use correct pattern for fasade components
- Loading branch information
Showing
3 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { type ForwardedRef } from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import type { StudioSearchProps } from './StudioSearch'; | ||
import { StudioSearch } from './StudioSearch'; | ||
import { testRefForwarding } from '../../test-utils/testRefForwarding'; | ||
import { testRootClassNameAppending } from '../../test-utils/testRootClassNameAppending'; | ||
import { testCustomAttributes } from '../../test-utils/testCustomAttributes'; | ||
|
||
describe('StudioSearch', () => { | ||
it('should support forwarding the ref', () => { | ||
testRefForwarding<HTMLInputElement>((ref) => renderTestSearch({}, ref), getSearchBox); | ||
}); | ||
|
||
it('should append classname to root', () => { | ||
testRootClassNameAppending((className) => renderTestSearch({ className })); | ||
}); | ||
|
||
it('should allow custom attributes', () => { | ||
testCustomAttributes( | ||
(customAttributes) => renderTestSearch({ ...customAttributes }), | ||
getSearchBox, | ||
); | ||
}); | ||
}); | ||
|
||
const renderTestSearch = ( | ||
props: Partial<StudioSearchProps> = {}, | ||
ref?: ForwardedRef<HTMLInputElement>, | ||
) => { | ||
return render(<StudioSearch {...props} ref={ref} />); | ||
}; | ||
|
||
function getSearchBox(): HTMLInputElement { | ||
return screen.getByRole('searchbox'); | ||
} |
15 changes: 15 additions & 0 deletions
15
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, { forwardRef } from 'react'; | ||
import { Search, type SearchProps } from '@digdir/designsystemet-react'; | ||
import type { WithoutAsChild } from '../../types/WithoutAsChild'; | ||
|
||
export type StudioSearchProps = WithoutAsChild<SearchProps>; | ||
|
||
const StudioSearch = forwardRef<HTMLInputElement, StudioSearchProps>( | ||
({ size = 'sm', ...rest }, ref) => { | ||
return <Search {...rest} size={size} ref={ref} />; | ||
}, | ||
); | ||
|
||
StudioSearch.displayName = 'StudioSearch'; | ||
|
||
export { StudioSearch }; |
5 changes: 1 addition & 4 deletions
5
frontend/libs/studio-components/src/components/StudioSearch/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
export { | ||
Search as StudioSearch, | ||
type SearchProps as StudioSearchProps, | ||
} from '@digdir/designsystemet-react'; | ||
export { StudioSearch } from './StudioSearch'; |