-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VisuallyHidden: Convert component to TypeScript (#42220)
* VisuallyHidden: Convert component to TypeScript * Update CHANGELOG.md
- Loading branch information
Petter Walbø Johnsgård
authored
Jul 9, 2022
1 parent
648e56e
commit d5de22f
Showing
10 changed files
with
124 additions
and
78 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,66 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { VisuallyHidden } from '..'; | ||
|
||
const meta: ComponentMeta< typeof VisuallyHidden > = { | ||
component: VisuallyHidden, | ||
title: 'Components/VisuallyHidden', | ||
argTypes: { | ||
children: { control: { type: null } }, | ||
as: { control: { type: 'text' } }, | ||
}, | ||
parameters: { | ||
controls: { | ||
expanded: true, | ||
}, | ||
docs: { source: { state: 'open' } }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
export const Default: ComponentStory< typeof VisuallyHidden > = ( args ) => ( | ||
<> | ||
<VisuallyHidden as="span" { ...args }> | ||
This should not show. | ||
</VisuallyHidden> | ||
<div> | ||
This text will{ ' ' } | ||
<VisuallyHidden as="span" { ...args }> | ||
but not inline{ ' ' } | ||
</VisuallyHidden>{ ' ' } | ||
always show. | ||
</div> | ||
</> | ||
); | ||
|
||
export const WithForwardedProps: ComponentStory< typeof VisuallyHidden > = ( | ||
args | ||
) => ( | ||
<> | ||
Additional props can be passed to VisuallyHidden and are forwarded to | ||
the rendered element.{ ' ' } | ||
<VisuallyHidden as="span" data-id="test" { ...args }> | ||
Check out my data attribute!{ ' ' } | ||
</VisuallyHidden> | ||
Inspect the HTML to see! | ||
</> | ||
); | ||
|
||
export const WithAdditionalClassNames: ComponentStory< | ||
typeof VisuallyHidden | ||
> = ( args ) => ( | ||
<> | ||
Additional class names passed to VisuallyHidden extend the component | ||
class name.{ ' ' } | ||
<VisuallyHidden as="label" className="test-input" { ...args }> | ||
Check out my class!{ ' ' } | ||
</VisuallyHidden> | ||
Inspect the HTML to see! | ||
</> | ||
); |
8 changes: 6 additions & 2 deletions
8
.../components/src/visually-hidden/styles.js → .../components/src/visually-hidden/styles.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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { VisuallyHidden } from '..'; | ||
|
||
describe( 'VisuallyHidden', () => { | ||
it( 'should render correctly', () => { | ||
const text = 'This is hidden'; | ||
render( <VisuallyHidden>{ text }</VisuallyHidden> ); | ||
expect( screen.getByText( text ) ).toMatchSnapshot(); | ||
} ); | ||
} ); |
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,11 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ReactNode } from 'react'; | ||
|
||
export type VisuallyHiddenProps = { | ||
/** | ||
* The children elements. | ||
*/ | ||
children: ReactNode; | ||
}; |