Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add arg table for ReferenceArea stories #3486

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions storybook/stories/API/cartesian/ReferenceArea.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ArgTypes } from '@storybook/blocks';
import * as ReferenceAreaStories from './ReferenceArea.stories';

# ReferenceArea

## Parent Component
The ReferenceArea can be used within the following parent components:

`<AreaChart/>` `<BarChart/>` `<LineChart/>` `<ComposedChart/>` `<ScatterChart/>`

## Child component
The ReferenceArea can be used with the following child components: `<Label/>`

## Properties

Properties in the groups Other and Internal are not recommended to be used.

<ArgTypes of={ReferenceAreaStories} sort={'requiredFirst'}/>
127 changes: 126 additions & 1 deletion storybook/stories/API/cartesian/ReferenceArea.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,137 @@
import { expect } from '@storybook/jest';
import { within } from '@storybook/testing-library';
import { Args } from '@storybook/react';
import React from 'react';
import { Line, LineChart, ReferenceArea, CartesianGrid, XAxis, YAxis, ResponsiveContainer } from '../../../../src';
import { pageData } from '../../data';
import { isUpdateAnimationActive, radius } from '../props/RectangleProps';
import {
onClick,
onMouseDown,
onMouseEnter,
onMouseLeave,
onMouseMove,
onMouseOut,
onMouseOver,
onMouseUp,
} from '../props/EventHandlers';
import { animationBegin, animationDuration, animationEasing, isAnimationActive } from '../props/AnimationProps';

const StyleProps: Args = {
ifOverflow: {
description: `Defines how to draw the reference area if it falls partly outside the canvas. If set to 'discard', the reference area will not be drawn at all. If set to 'hidden', the reference area will be clipped to the canvas. If set to 'visible', the reference area will be drawn completely. If set to 'extendDomain', the domain of the overflown axis will be extended such that the reference area fits into the canvas.`,
table: { category: 'Style' },
},
label: {
description: `If set a string or a number, default label will be drawn, and the option is content. If set a React element, the option is the custom react element of drawing label. If set a function, the function will be called to render customized label.`,
table: {
type: {
summary: 'String | Number | ReactElement | Function',
detail:
'<ReferenceArea x1="01" x2="08" label="MAX"/>\n' +
'<ReferenceArea y1={100} y2={500} label={<CustomizedLabel />}/>',
},
category: 'Style',
},
},
shape: {
description: `Renders a svg returned by the react element or function.`,
table: {
type: {
summary: 'ReactElement | Function',
detail: '<ReferenceArea shape={<CustomSvgShape/>}/>',
},
category: 'Style',
},
},
isFront: {
description: `If set true, the line will be rendered in front of bars in BarChart, etc.`,
table: { category: 'Style' },
},
};

const GeneralProps: Args = {
xAxisId: {
description: 'The id of x-axis which is corresponding to the data.',
table: { type: { summary: 'string | number' }, category: 'General' },
},
yAxisId: {
description: 'The id of y-axis which is corresponding to the data.',
table: { type: { summary: 'string | number' }, category: 'General' },
},
x1: {
description:
'A boundary value of the area. If the specified x-axis is a number axis, the type of x must be Number. If the specified x-axis is a category axis, the value of x must be one of the categories. If x1 is not set, the first value on the x-axis is used instead. If one of x1 or x2 is invalid, the area will not be drawn.',
table: { type: { summary: 'string | number' }, category: 'General' },
},
x2: {
description:
'A boundary value of the area. If the specified x-axis is a number axis, the type of x must be Number. If the specified x-axis is a category axis, the value of x must be one of the categories. If x2 is not set, the last value on the x-axis is used instead. If one of x1 or x2 is invalid, the area will not be drawn.',
table: { type: { summary: 'string | number' }, category: 'General' },
},
y1: {
description:
'A boundary value of the area. If the specified y-axis is a number axis, the type of y must be Number. If the specified y-axis is a category axis, the value of y must be one of the categories. If y1 is not set, the first value on the y-axis is used instead. If one of y1 or y2 is invalid, the area will not be drawn.',
table: { type: { summary: 'string | number' }, category: 'General' },
},
y2: {
description:
'A boundary value of the area. If the specified y-axis is a number axis, the type of y must be Number. If the specified y-axis is a category axis, the value of y must be one of the categories. If y2 is not set, the last value on the y-axis is used instead. If one of y1 or y2 is invalid, the area will not be drawn.',
table: { type: { summary: 'string | number' }, category: 'General' },
},
};

const InternalProps: Args = {
viewBox: {
description: 'The box of the viewing area, usually calculated internally.',
table: { type: { summary: '{x: number, y: number, width: number, height: number}' }, category: 'Internal' },
},
xAxis: {
description: 'The configuration of the corresponding x-axis, usually calculated internally.',
table: { type: { summary: 'Object' }, category: 'Internal' },
},
yAxis: {
description: 'The configuration of the corresponding y-axis, usually calculated internally.',
table: { type: { summary: 'Object' }, category: 'Internal' },
},
clipPathId: {
description:
"Used as the id for the clip path which is used to clip the reference box if 'ifOverflow' is set to 'hidden'",
table: { type: { summary: 'number | string' }, category: 'Internal' },
},
};

export default {
argTypes: {
...StyleProps,
...GeneralProps,
...InternalProps,
// Rectangle
radius,
// Deprecated
alwaysShow: {
description: "Use 'ifOverflow' instead.",
table: { category: 'Deprecated' },
hide: true,
disable: true,
},
// Event handlers
onClick,
onMouseDown,
onMouseUp,
onMouseMove,
onMouseOver,
onMouseOut,
onMouseEnter,
onMouseLeave,
// Animation
animationBegin,
animationDuration,
animationEasing,
isAnimationActive,
isUpdateAnimationActive,
},
component: ReferenceArea,
tags: ['autodocs'],
};

export const Simple = {
Expand Down
21 changes: 17 additions & 4 deletions storybook/stories/API/props/AnimationProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,37 @@ export const animationBegin = {
description: 'Specifies when the animation should begin, the unit of this option is ms.',
type: { name: 'number' },
defaultValue: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the defaultValue seems to be defined twice. Is that necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nikolasrieble, without the defaultValue in the table prop, the default value in the args table is not set to the manually set defaultValue of the argType, but only to the inferred default value.

According to storybookjs/storybook#11983 (comment) (which also refers to https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#no-longer-inferring-default-values-of-args):

To affect the Default column in the ArgsTable, you should set the argTypes..table.defaultValue field. The value should be an object with the keys summary and optionally details, which are both strings.

table: { category: 'Animation' },
table: {
defaultValue: { summary: '0' },
category: 'Animation',
},
};
export const animationDuration = {
description: 'Specifies the duration of animation, the unit of this option is ms.',
type: { name: 'number' },
defaultValue: 1500,
table: { category: 'Animation' },
table: {
defaultValue: { summary: '1500' },
category: 'Animation',
},
};
export const animationEasing = {
description: 'The type of easing function.',
type: { name: 'ease | ease-in | ease-out | ease-in-out | linear' },
defaultValue: 'ease',
table: { category: 'Animation' },
table: {
defaultValue: { summary: 'ease' },
category: 'Animation',
},
};
export const animationId = { table: { category: 'Animation' } };
export const isAnimationActive = {
description: 'If set false, animation of component will be disabled.',
table: { type: { summary: 'boolean' }, category: 'Animation' },
table: {
type: { summary: 'boolean' },
defaultValue: { summary: 'true in CSR, and false in SSR' },
category: 'Animation',
},
defaultValue: 'true in CSR, and false in SSR',
};

Expand Down
30 changes: 30 additions & 0 deletions storybook/stories/API/props/RectangleProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file both exports the documentation of shared props separately, to be reused in places where only single props
* are documented, as well as grouped in case a whole group is needed.
*/
import { Args } from '@storybook/react';

export const radius = {
description:
'If set a value, the option is the radius of all the rounderd corners. If set a array, the option are in turn the radiuses of top-left corner, top-right corner, bottom-right corner, bottom-left corner.',
table: {
type: { summary: 'number | number[]' },
defaultValue: { summary: 0 },
category: 'Style',
},
};

export const isUpdateAnimationActive = {
description: 'If set false, animation of component updates will be disabled.',
table: { category: 'Animation' },
};

/**
* Caveat: If any prop is added here, it would falsely be add to the documentation of the component where this group
* is used. If the group is to be extended, then only single props should be imported by each component that does not
* use all of them.
* */
export const RectangleProps: Args = {
radius,
isUpdateAnimationActive,
};