Skip to content

Commit a486b73

Browse files
committed
feat: improve example
1 parent d87864e commit a486b73

File tree

6 files changed

+31
-50
lines changed

6 files changed

+31
-50
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
import React from 'react';
2+
import styled from 'styled-components';
23

3-
export const Base = () => <button>Hello</button>;
4+
export const Base = styled.button`
5+
background-color: blue;
6+
color: white;
7+
border-radius: 6px;
8+
`;

example/src/woly/atoms/button/usage.mdx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ Button allow users to take actions, and make choices, with a single tap.
1717

1818
### Usage
1919

20-
```tsx
21-
const Example = () => (
22-
<button.Primary text="Hello world" onClick={(event) => console.info('Hi!')} />
23-
);
24-
```
25-
2620
First
2721

2822
<Frame>
2923
<New />
30-
<button.Base />
24+
<button.Base>Demooo</button.Base>
3125
</Frame>
3226

3327
Second

gatsby-theme-woly/plugins/remark-plugin.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,15 @@ module.exports = (options) => {
44
// console.log('REMARK PLUGIN', options);
55

66
function transformer(tree) {
7-
const codes = [];
8-
97
visit(tree, 'jsx', (node, index, parent) => {
10-
codes.push({
11-
at: index,
12-
node: {
13-
type: 'code',
14-
lang: 'jsx',
15-
meta: null,
16-
value: node.value,
17-
},
18-
parent,
8+
parent.children.splice(index + 1, 0, {
9+
type: 'code',
10+
lang: 'jsx',
11+
meta: null,
12+
value: node.value,
1913
});
2014
});
2115

22-
// When new element added to AST list, other elements is moved down
23-
// Absolute index of each element in `codes` has incorrect `at` position
24-
let shift = 0;
25-
codes.forEach(({ at, node, parent }) => {
26-
parent.children.splice(at + 1 + shift, 0, node);
27-
shift++;
28-
});
29-
30-
delete codes;
31-
3216
// console.log('REMARK PLUGIN TRANSFORMER', tree);
3317
}
3418

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
/**
2-
* Creates iFrame with react components content inside .mdx docs
2+
* Creates Frame with react components content inside .mdx docs
33
* usage: usage.mdx
44
*/
55

6-
import * as React from 'react';
76
import styled from 'styled-components';
8-
import { createPortal } from 'react-dom';
97

10-
export const Frame = ({ children, title, ...props }) => {
11-
const [contentRef, setContentRef] = React.useState(null)
12-
const mountNode =
13-
contentRef?.contentWindow?.document?.body
14-
15-
return (
16-
<StyledIframe title={title} {...props} ref={setContentRef}>
17-
{mountNode && createPortal(children, mountNode)}
18-
</StyledIframe>
19-
)
20-
}
21-
22-
const StyledIframe = styled.iframe`
8+
export const Frame = styled.div`
239
resize: both;
2410
width: 100%;
11+
border: 2px solid var(--base, rgb(246, 248, 250));
12+
padding: 1rem;
13+
box-sizing: border-box;
14+
border-radius: 4px;
15+
16+
border-bottom-left-radius: 0;
17+
border-bottom-right-radius: 0;
18+
19+
& + .prism-code {
20+
margin-top: 0;
21+
border-top-left-radius: 0;
22+
border-top-right-radius: 0;
23+
}
2524
`;

gatsby-theme-woly/src/styles/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ body {
1414
}
1515

1616
pre {
17-
background: var(--base);
17+
background: var(--base) !important;
1818
padding: 1rem;
1919
margin-bottom: 30px;
2020
border-radius: 3px;

gatsby-theme-woly/src/templates/usage.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ const ComponentPage = ({ data, pageContext }) => {
1515
<Layout>
1616
<div>
1717
<h2>{frontmatter.name}</h2>
18-
<h3>Use it</h3>
1918
<pre>
2019
import {'{'} {pascalCase(frontmatter.name)} {'}'} from "
2120
{frontmatter.package}";
2221
</pre>
23-
<h3>Installation</h3>
22+
{/* <h3>Installation</h3> */}
2423
{/* prettier-ignore */}
25-
<pre>
24+
{/* <pre>
2625
{installation(frontmatter)}
27-
</pre>
26+
</pre> */}
2827
<MDXRenderer>{body}</MDXRenderer>
2928
</div>
3029
</Layout>

0 commit comments

Comments
 (0)