Skip to content

Commit 0e35030

Browse files
authored
Add types to ApiView.tsx and its imports (#360)
1 parent 1fdbc84 commit 0e35030

File tree

15 files changed

+120
-40
lines changed

15 files changed

+120
-40
lines changed

src/docs/api/AreaChart.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { ApiDoc } from './types.ts';
2+
3+
const AreaChartExample: ApiDoc = {
24
name: 'AreaChart',
35
desc: {
46
'en-US': 'All svg elements can be added into the AreaChart component, such as defs, linearGradient, etc.',
@@ -185,3 +187,5 @@ export default {
185187
'validate svg elements...',
186188
],
187189
};
190+
191+
export default AreaChartExample;

src/docs/api/BarChart.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { ApiDoc } from './types.ts';
2+
3+
const BarChart: ApiDoc = {
24
name: 'BarChart',
35
props: [
46
{
@@ -236,3 +238,4 @@ export default {
236238
'validate svg elements...',
237239
],
238240
};
241+
export default BarChart;

src/docs/api/ComposedChart.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { ApiDoc } from './types.ts';
2+
3+
const ComposedChart: ApiDoc = {
24
name: 'ComposedChart',
35
desc: 'A chart composed of line, area, and bar charts. When you just want to draw a chart of a single type like line, then LineChart is recommended.',
46
props: [
@@ -206,3 +208,4 @@ export default {
206208
'validate svg elements...',
207209
],
208210
};
211+
export default ComposedChart;

src/docs/api/Line.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { ApiDoc } from './types.ts';
2+
3+
const Line: ApiDoc = {
24
name: 'Line',
35
props: [
46
{
@@ -212,7 +214,7 @@ export default {
212214
type: 'String | Number',
213215
defaultVal: 'null',
214216
isOptional: true,
215-
esc: {
217+
desc: {
216218
'en-US': 'The unit of data. This option will be used in tooltip.',
217219
'zh-CN': '对应数据的单位,这个单位会展示在 Tooltip 的数值后面。',
218220
},
@@ -391,3 +393,4 @@ export default {
391393
parentComponents: ['LineChart', 'ComposedChart'],
392394
childrenComponents: ['LabelList', 'ErrorBar'],
393395
};
396+
export default Line;

src/docs/api/RadialBarChart.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { ApiDoc } from './types.ts';
2+
3+
const RadialBarChart: ApiDoc = {
24
name: 'RadialBarChart',
35
props: [
46
{
@@ -200,3 +202,4 @@ export default {
200202
'validate svg elements...',
201203
],
202204
};
205+
export default RadialBarChart;

src/docs/api/SankeyChart.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { ApiDoc } from './types.ts';
2+
3+
const SankeyChart: ApiDoc = {
24
name: 'SankeyChart',
35
props: [
46
{
@@ -222,3 +224,4 @@ export default {
222224
],
223225
childrenComponents: ['Tooltip'],
224226
};
227+
export default SankeyChart;

src/docs/api/Text.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { ApiDoc } from './types.ts';
2+
3+
const Text: ApiDoc = {
24
name: 'Text',
35
props: [
46
{
@@ -46,3 +48,4 @@ export default {
4648
},
4749
],
4850
};
51+
export default Text;

src/docs/api/Treemap.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export default {
1+
import { ApiDoc } from './types.ts';
2+
3+
const Treemap: ApiDoc = {
24
name: 'Treemap',
35
props: [
46
{
@@ -112,3 +114,4 @@ export default {
112114
],
113115
parentComponents: ['ResponsiveContainer'],
114116
};
117+
export default Treemap;

src/docs/api/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ import Dot from './Dot';
4848
import Polygon from './Polygon';
4949
import Rectangle from './Rectangle';
5050
import Sector from './Sector';
51+
import { ApiDoc } from './types.ts';
5152

52-
export default {
53+
const allExamples: Record<string, ApiDoc> = {
5354
AreaChart,
5455
BarChart,
5556
LineChart,
@@ -101,3 +102,5 @@ export default {
101102
Rectangle,
102103
Sector,
103104
};
105+
106+
export default allExamples;

src/docs/api/types.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ReactNode } from 'react';
2+
import { SupportedLocale } from '../../locale';
3+
4+
export type PropExample = {
5+
name: string;
6+
url: string;
7+
isExternal?: boolean;
8+
};
9+
10+
export type ApiProps = {
11+
name: string;
12+
type: string;
13+
defaultVal?: string | number | null;
14+
isOptional?: boolean;
15+
desc?: string | Partial<Record<SupportedLocale, string>>;
16+
format?: ReadonlyArray<string>;
17+
examples?: ReadonlyArray<PropExample>;
18+
deprecated?: boolean;
19+
};
20+
21+
export type ApiDoc = {
22+
name: string;
23+
desc?: string | Record<SupportedLocale, string>;
24+
props: ReadonlyArray<ApiProps>;
25+
parentComponents?: ReadonlyArray<string>;
26+
childrenComponents?: ReadonlyArray<string>;
27+
};
28+
29+
export type ApiExample = {
30+
demo: (locale: SupportedLocale) => ReactNode;
31+
code: string;
32+
dataCode?: string;
33+
};

0 commit comments

Comments
 (0)