forked from styleguidist/react-styleguidist
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
213 additions
and
88 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { ComplexTypeRenderer, styles } from './ComplexTypeRenderer'; | ||
|
||
const props = { | ||
classes: classes(styles), | ||
name: 'color', | ||
raw: '"blue" | "red"', | ||
}; | ||
|
||
it('renderer should render complex type', () => { | ||
const actual = shallow(<ComplexTypeRenderer {...props} />); | ||
|
||
expect(actual).toMatchSnapshot(); | ||
}); |
75 changes: 75 additions & 0 deletions
75
src/client/rsg-components/ComplexType/ComplexTypeRenderer.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,75 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { MdInfoOutline } from 'react-icons/md'; | ||
import Tippy from '@tippyjs/react'; | ||
import 'tippy.js/dist/tippy.css'; | ||
import 'tippy.js/themes/light-border.css'; | ||
|
||
import Styled, { JssInjectedProps } from 'rsg-components/Styled'; | ||
import Text from 'rsg-components/Text'; | ||
|
||
import * as Rsg from '../../../typings'; | ||
|
||
export const styles = ({ fontFamily, fontSize, color, space, borderRadius }: Rsg.Theme) => ({ | ||
type: { | ||
position: 'relative', | ||
fontFamily: fontFamily.monospace, | ||
fontSize: fontSize.small, | ||
color: color.base, | ||
'& span': { | ||
marginRight: space[0], | ||
cursor: 'pointer', | ||
}, | ||
'& .tippy-content': { | ||
fontSize: fontSize.small, | ||
color: color.type, | ||
}, | ||
'& .tippy-box': { | ||
padding: space[1], | ||
border: `1px ${color.border} solid`, | ||
borderRadius, | ||
background: color.baseBackground, | ||
boxShadow: [[0, 2, 4, 'rgba(0,0,0,.15)']], | ||
}, | ||
'& .tippy-box[data-placement^=right]>.tippy-arrow': { | ||
left: 1, | ||
width: 16, | ||
height: 16, | ||
}, | ||
}, | ||
name: { | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
cursor: 'pointer', | ||
}, | ||
}); | ||
|
||
interface ComplexTypeProps extends JssInjectedProps { | ||
name: string; | ||
raw: string; | ||
} | ||
|
||
export const ComplexTypeRenderer: React.FunctionComponent<ComplexTypeProps> = ({ | ||
classes, | ||
name, | ||
raw, | ||
}) => { | ||
return ( | ||
<div className={classes.type}> | ||
<Tippy content={raw} interactive theme="light-border" placement="right"> | ||
<div className={classes.name} role="button" tabIndex={0}> | ||
<Text>{name}</Text> | ||
<MdInfoOutline /> | ||
</div> | ||
</Tippy> | ||
</div> | ||
); | ||
}; | ||
|
||
ComplexTypeRenderer.propTypes = { | ||
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired, | ||
name: PropTypes.string.isRequired, | ||
raw: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default Styled<ComplexTypeProps>(styles)(ComplexTypeRenderer); |
25 changes: 25 additions & 0 deletions
25
src/client/rsg-components/ComplexType/__snapshots__/ComplexType.spec.tsx.snap
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,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renderer should render complex type 1`] = ` | ||
<div | ||
className="type" | ||
> | ||
<ForwardRef(TippyWrapper) | ||
content="\\"blue\\" | \\"red\\"" | ||
interactive={true} | ||
placement="right" | ||
theme="light-border" | ||
> | ||
<div | ||
className="name" | ||
role="button" | ||
tabIndex={0} | ||
> | ||
<Styled(Text)> | ||
color | ||
</Styled(Text)> | ||
<MdInfoOutline /> | ||
</div> | ||
</ForwardRef(TippyWrapper)> | ||
</div> | ||
`; |
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/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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |