forked from styleguidist/react-styleguidist
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Wrong union description with TypeScript styleguidist#1621
- Loading branch information
Showing
10 changed files
with
264 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
20 changes: 20 additions & 0 deletions
20
src/client/rsg-components/ComplexType/ComplexType.spec.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,20 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import ComplexType from './ComplexTypeRenderder'; | ||
|
||
function renderComponent(name = 'color', raw = 'red | blue') { | ||
return render(<ComplexType name={name} raw={raw} />); | ||
} | ||
|
||
describe('ComplexType', () => { | ||
test('should render name', () => { | ||
const { getByRole } = renderComponent(); | ||
expect(getByRole('button')).toHaveTextContent('color'); | ||
}); | ||
|
||
test('should render raw text in the tooltip', () => { | ||
const { container, getByRole } = renderComponent(); | ||
fireEvent.focus(getByRole('button')); | ||
expect(container.querySelector('[data-tippy-root]')).toHaveTextContent('red | blue'); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
src/client/rsg-components/ComplexType/ComplexTypeRenderder.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,36 @@ | ||
import React from 'react'; | ||
import Styled, { JssInjectedProps } from 'rsg-components/Styled'; | ||
import { MdInfoOutline } from 'react-icons/md'; | ||
import Text from 'rsg-components/Text'; | ||
import Tooltip from 'rsg-components/Tooltip'; | ||
import * as Rsg from '../../../typings'; | ||
|
||
export const styles = ({ space }: Rsg.Theme) => ({ | ||
complexType: { | ||
alignItems: 'center', | ||
cursor: 'pointer', | ||
display: 'inline-flex', | ||
'& span': { | ||
marginRight: space[0], | ||
cursor: 'pointer', | ||
}, | ||
}, | ||
}); | ||
|
||
export interface ComplexTypeProps extends JssInjectedProps { | ||
name: string; | ||
raw: string; | ||
} | ||
|
||
function ComplexTypeRenderer({ classes, name, raw }: ComplexTypeProps) { | ||
return ( | ||
<Tooltip placement="right" content={raw}> | ||
<span className={classes.complexType}> | ||
<Text>{name}</Text> | ||
<MdInfoOutline /> | ||
</span> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
export default Styled<ComplexTypeProps>(styles)(ComplexTypeRenderer); |
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 @@ | ||
export { default } from 'rsg-components/ComplexType/ComplexTypeRenderder'; |
Oops, something went wrong.