Skip to content

Commit 5e8f27c

Browse files
tatinachersergeysova
authored andcommitted
docs: add images support to mdx
1 parent 9bff3fe commit 5e8f27c

File tree

9 files changed

+2068
-55
lines changed

9 files changed

+2068
-55
lines changed

example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"license": "MIT",
1212
"scripts": {
13-
"develop": "gatsby develop",
13+
"start": "gatsby develop",
1414
"build": "gatsby build"
1515
},
1616
"dependencies": {
@@ -23,4 +23,4 @@
2323
"react-dom": "^16.13.1",
2424
"styled-components": "^5.2.0"
2525
}
26-
}
26+
}

example/src/assets/images/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as React from 'react';
2+
import { graphql, useStaticQuery } from 'gatsby';
3+
4+
/** To add new image inside query:
5+
/*
6+
/* imageName: file(relativePath: { regex: "PATH_TO_IMAGE" }) {
7+
/* childImageSharp {
8+
/* resize(width: 180, height: 180, cropFocus: CENTER) {
9+
/* src
10+
/* }
11+
/* }
12+
/* }
13+
*/
14+
15+
export const Image = ({ image }) => {
16+
const data = useStaticQuery(graphql`
17+
query {
18+
allImageSharp {
19+
edges {
20+
node {
21+
... on ImageSharp {
22+
resize(width: 125, height: 125, rotate: 180) {
23+
src
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
30+
`);
31+
32+
const imageSrc = data[image]?.childImageSharp?.resize?.src;
33+
34+
return imageSrc ? <img src={imageSrc} alt={image} /> : null;
35+
};

example/src/woly/atoms/button/example.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react';
22
import styled from 'styled-components';
3+
import { Image } from '../../../assets/images';
4+
5+
export const ButtonImage = () => <Image image="imageName" />;
36

47
const Icon = () => (
58
<svg

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ package: 'woly'
66

77
import * as button from './index';
88
import { New } from './new';
9-
import { Example } from './example';
9+
import { ButtonImage, Example } from './example';
1010

1111
Button allow users to take actions, and make choices, with a single tap.
1212

1313
## Using buttons
1414

15+
<ButtonImage />
16+
1517
### Usage
1618

1719
```tsx
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as React from 'react';
2+
import { Image } from '../../../assets/images';
3+
4+
export const ChipImage = () => <Image image="imageName" />;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ category: atoms
44
package: 'woly'
55
---
66

7+
import { ChipImage } from './example';
8+
79
Hello! It is chips
810

11+
<ChipImage />
12+
913
### Props
1014

1115
| Name | Type | Default | Description |

gatsby-theme-woly/gatsby-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module.exports = (themeOptions) => {
1919
remarkPlugins: [require('./plugins/remark-plugin.js')],
2020
},
2121
},
22+
`gatsby-plugin-sharp`,
23+
`gatsby-transformer-sharp`,
2224
{
2325
resolve: 'gatsby-plugin-styled-components',
2426
options: { displayName: IS_DEV },

gatsby-theme-woly/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
"devDependencies": {
4343
"babel-plugin-styled-components": "^1.11.1",
4444
"gatsby": "^2.24.47",
45+
"gatsby-plugin-sharp": "^2.6.38",
46+
"gatsby-transformer-sharp": "^2.5.16",
4547
"react": "^16.13.1",
4648
"react-dom": "^16.13.1",
4749
"styled-components": "^5.1.1"

0 commit comments

Comments
 (0)