Skip to content

Commit

Permalink
Fix Wrong union description with TypeScript styleguidist#1621
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuruog committed Aug 24, 2020
1 parent 53bc4bb commit fef57c8
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 58 deletions.
83 changes: 52 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -28,6 +28,7 @@
"node": ">=10"
},
"dependencies": {
"@tippyjs/react": "4.1.0",
"@vxna/mini-html-webpack-template": "^1.0.0",
"acorn": "^6.4.1",
"acorn-jsx": "^5.1.0",
Expand Down
20 changes: 20 additions & 0 deletions src/client/rsg-components/ComplexType/ComplexType.spec.tsx
@@ -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 src/client/rsg-components/ComplexType/ComplexTypeRenderder.tsx
@@ -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);
1 change: 1 addition & 0 deletions src/client/rsg-components/ComplexType/index.ts
@@ -0,0 +1 @@
export { default } from 'rsg-components/ComplexType/ComplexTypeRenderder';

0 comments on commit fef57c8

Please sign in to comment.