Skip to content

Commit 2652732

Browse files
committed
added npm2yarn & updated some docs
1 parent 2bb70ec commit 2652732

File tree

8 files changed

+133
-53
lines changed

8 files changed

+133
-53
lines changed

docs/addToast.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Use this method to render a toast on screen.
88

99
The available options are:
1010

11-
```javascript
11+
```jsx
1212
{
1313
type?: 'success' | 'error' | 'info' | 'warning'; // default: info
1414
title?: string;
@@ -18,7 +18,7 @@ The available options are:
1818

1919
For example, displaying a success toast would be:
2020

21-
```javascript
21+
```jsx
2222
import { addToast } from 'react-native-rooster';
2323

2424
addToast({

docs/installation.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ sidebar_label: Installation
66

77
To install react-native-rooster's package:
88

9-
### Using yarn
10-
11-
```bash
12-
yarn add react-native-rooster styled-components
9+
```bash npm2yarn
10+
npm install --save react-native-rooster styled-components
1311
```
1412

15-
### Using npm
16-
17-
```bash
18-
npm i react-native-rooster styled-components
19-
```
2013

2114
**NOTE:** RNRooster relies on styled-components because it makes easier to handle different kinds of style props and also helps making the code cleaner. You should install manually styled-components in your project (using one of the commands above).
2215

@@ -25,7 +18,7 @@ npm i react-native-rooster styled-components
2518
You must import and wrap your application using our provider. Check out this [example](https://github.com/mCodex/react-native-rooster/blob/master/example/src/routes/index.tsx#L18-L20).
2619

2720

28-
```javascript
21+
```jsx
2922
import { ToastProvider } from 'react-native-rooster';
3023

3124
<ToastProvider>

docs/removeToast.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ title: removeToast
44
sidebar_label: removeToast
55
---
66

7-
All toasts are automatically removed after 3s. However, you can manually pop the last toast from screen doing:
7+
All toasts are automatically removed after 1.5s. However, you can manually pop the last toast from screen doing:
88

9-
```javascript
9+
```jsx
1010
import { removeToast } from 'react-native-rooster';
1111

1212
removeToast();
1313
```
1414

15+
**NOTE:** You can also change the default time to dismiss by setting `timeToDismiss`option in `setToastConfig`, for more information check [here](setToastConfig#timetodismiss).

docs/setToastConfig.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar_label: setToastConfig
66

77
You can change some configs globally.
88

9-
# bgColor
9+
## bgColor
1010

1111
You can change the default bgColors for each type of toast.
1212

@@ -23,7 +23,7 @@ The default colors are:
2323

2424
An example changing the default success' bgColor to olive:
2525

26-
```javascript
26+
```jsx
2727
import { setToastConfig } from 'react-native-rooster';
2828

2929
setToastConfig({
@@ -33,7 +33,7 @@ setToastConfig({
3333
})
3434
```
3535

36-
# font
36+
## font
3737

3838
You can change the custom fontFamily for the texts.
3939

@@ -46,7 +46,7 @@ You can change the custom fontFamily for the texts.
4646

4747
An example changing `fontFamilyBold` to `Montserrat` family:
4848

49-
```javascript
49+
```jsx
5050
import { setToastConfig } from 'react-native-rooster';
5151

5252
setToastConfig({
@@ -56,7 +56,7 @@ setToastConfig({
5656
})
5757
```
5858

59-
# timeToDismiss
59+
## timeToDismiss
6060

6161
You can change the default toast's time to dismiss.
6262

@@ -66,7 +66,7 @@ You can change the default toast's time to dismiss.
6666

6767
To change this to 4000ms you can just do:
6868

69-
```javascript
69+
```jsx
7070
import { setToastConfig } from 'react-native-rooster';
7171

7272
setToastConfig({

docusaurus.config.js

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
11
module.exports = {
2-
title: "react-native-rooster 🐔",
3-
tagline: "An elegant and flexible toast solution for your react-native apps",
4-
url: "https://mcodex.dev",
5-
baseUrl: "/react-native-rooster/",
6-
onBrokenLinks: "throw",
7-
favicon: "img/favicon.ico",
8-
organizationName: "mcodex",
9-
projectName: "react-native-rooster",
2+
title: 'react-native-rooster 🐔',
3+
tagline: 'An elegant and flexible toast solution for your react-native apps',
4+
url: 'https://mcodex.dev',
5+
baseUrl: '/react-native-rooster/',
6+
onBrokenLinks: 'throw',
7+
favicon: 'img/favicon.ico',
8+
organizationName: 'mcodex',
9+
projectName: 'react-native-rooster',
1010
themeConfig: {
11+
prism: {
12+
theme: require('prism-react-renderer/themes/dracula'),
13+
},
1114
googleAnalytics: {
12-
trackingID: "UA-79205996-7",
15+
trackingID: 'UA-79205996-7',
1316
},
1417
navbar: {
15-
title: "react-native-rooster",
18+
title: 'react-native-rooster',
1619
logo: {
17-
alt: "react-native-rooster logo",
18-
src: "img/logo.svg",
20+
alt: 'react-native-rooster logo',
21+
src: 'img/logo.svg',
1922
},
2023
items: [
2124
{
22-
to: "docs/",
23-
activeBasePath: "docs",
24-
label: "Docs",
25-
position: "right",
25+
to: 'docs/',
26+
activeBasePath: 'docs',
27+
label: 'Docs',
28+
position: 'right',
2629
},
27-
// { to: 'blog', label: 'Blog', position: 'left' },
2830
{
29-
href: "https://github.com/mcodex/react-native-rooster",
30-
label: "GitHub",
31-
position: "right",
31+
href: 'https://github.com/mcodex/react-native-rooster',
32+
label: 'GitHub',
33+
position: 'right',
3234
},
3335
],
3436
},
3537
footer: {
36-
style: "dark",
38+
style: 'dark',
3739
copyright: `Copyright © ${new Date().getFullYear()} Made with ❤️ by mCodex`,
3840
},
3941
},
4042
presets: [
4143
[
42-
"@docusaurus/preset-classic",
44+
'@docusaurus/preset-classic',
4345
{
4446
docs: {
45-
homePageId: "overview",
46-
sidebarPath: require.resolve("./sidebars.js"),
47+
homePageId: 'overview',
48+
sidebarPath: require.resolve('./sidebars.js'),
4749
editUrl:
48-
"https://github.com/mcodex/react-native-rooster/edit/website/website/",
50+
'https://github.com/mcodex/react-native-rooster/edit/website/website/',
4951
showLastUpdateAuthor: true,
5052
showLastUpdateTime: true,
53+
remarkPlugins: [require('./src/plugins/remark-npm2yarn')],
54+
},
55+
pages: {
56+
remarkPlugins: [require('./src/plugins/remark-npm2yarn')],
5157
},
5258
theme: {
53-
customCss: require.resolve("./src/css/custom.css"),
59+
customCss: require.resolve('./src/css/custom.css'),
5460
},
5561
},
5662
],

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"dependencies": {
1414
"@docusaurus/core": "^2.0.0-alpha.61",
1515
"@docusaurus/preset-classic": "^2.0.0-alpha.61",
16-
"@mdx-js/react": "^1.6.16",
17-
"clsx": "^1.1.1",
16+
"npm-to-yarn": "^1.0.1",
1817
"react": "^16.13.1",
1918
"react-dom": "^16.13.1"
2019
},

src/plugins/remark-npm2yarn.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
const npmToYarn = require('npm-to-yarn');
9+
10+
// E.g. global install: 'npm i' -> 'yarn'
11+
const convertNpmToYarn = (npmCode) => npmToYarn(npmCode, 'yarn');
12+
13+
const transformNode = (node) => {
14+
const npmCode = node.value;
15+
const yarnCode = convertNpmToYarn(node.value);
16+
return [
17+
{
18+
type: 'jsx',
19+
value:
20+
'<Tabs groupId="npm2yarn" defaultValue="npm" '
21+
+ `values={[
22+
{ label: 'npm', value: 'npm', },
23+
{ label: 'Yarn', value: 'yarn', },
24+
]}
25+
>
26+
<TabItem value="npm">`,
27+
},
28+
{
29+
type: node.type,
30+
lang: node.lang,
31+
value: npmCode,
32+
},
33+
{
34+
type: 'jsx',
35+
value: '</TabItem>\n<TabItem value="yarn">',
36+
},
37+
{
38+
type: node.type,
39+
lang: node.lang,
40+
value: yarnCode,
41+
},
42+
{
43+
type: 'jsx',
44+
value: '</TabItem>\n</Tabs>',
45+
},
46+
];
47+
};
48+
49+
const matchNode = (node) => node.type === 'code' && node.meta === 'npm2yarn';
50+
const nodeForImport = {
51+
type: 'import',
52+
value:
53+
"import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';",
54+
};
55+
56+
module.exports = () => {
57+
let transformed = false;
58+
const transformer = (node) => {
59+
if (matchNode(node)) {
60+
transformed = true;
61+
return transformNode(node);
62+
}
63+
if (Array.isArray(node.children)) {
64+
let index = 0;
65+
while (index < node.children.length) {
66+
const result = transformer(node.children[index]);
67+
if (result) {
68+
node.children.splice(index, 1, ...result);
69+
index += result.length;
70+
} else {
71+
index += 1;
72+
}
73+
}
74+
}
75+
if (node.type === 'root' && transformed) {
76+
node.children.unshift(nodeForImport);
77+
}
78+
return null;
79+
};
80+
return transformer;
81+
};

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,11 +1435,6 @@
14351435
resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-1.6.14.tgz#20c64d6691a894227cd04006b620e5fff85f79b1"
14361436
integrity sha512-WN4OWXiSTN5x1Ee0ZeYQ9bjjSSgH3Mfx/ezcSV3T691C/PcHTNWwJa5qhcuq8V/NrVAeMc26aXuSdOAq6sRb1g==
14371437

1438-
"@mdx-js/react@^1.6.16":
1439-
version "1.6.16"
1440-
resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-1.6.16.tgz#538eb14473194d0b3c54020cb230e426174315cd"
1441-
integrity sha512-+FhuSVOPo7+4fZaRwWuCSRUcZkJOkZu0rfAbBKvoCg1LWb1Td8Vzi0DTLORdSvgWNbU6+EL40HIgwTOs00x2Jw==
1442-
14431438
"@mdx-js/util@1.6.14":
14441439
version "1.6.14"
14451440
resolved "https://registry.yarnpkg.com/@mdx-js/util/-/util-1.6.14.tgz#e3c14aef1c721b79ca7afa4d54ed7b5817a973c7"
@@ -6926,6 +6921,11 @@ npm-run-path@^4.0.0:
69266921
dependencies:
69276922
path-key "^3.0.0"
69286923

6924+
npm-to-yarn@^1.0.1:
6925+
version "1.0.1"
6926+
resolved "https://registry.yarnpkg.com/npm-to-yarn/-/npm-to-yarn-1.0.1.tgz#6cdb95114c4ff0be50a7a2381d4d16131a5f52df"
6927+
integrity sha512-bp8T8oNMfLW+N/fE0itFfSu7RReytwhqNd9skbkfHfzGYC+5CCdzS2HnaXz6JiG4AlK2eA0qlT6NJN1SoFvcWQ==
6928+
69296929
nprogress@^0.2.0:
69306930
version "0.2.0"
69316931
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"

0 commit comments

Comments
 (0)