Skip to content

Commit

Permalink
Make the default story work
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinNagpal committed Oct 25, 2021
1 parent cb5c8ad commit 9cbfb6f
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/components/Annotation.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ArgTypes } from '@storybook/addons/dist/ts3.9/types';
import { Meta, Story } from '@storybook/react';
import React from 'react';
import React, { useState } from 'react';
import { IAnnotation } from 'src/types';
import Annotation, { AnnotationPropsOptional } from './Annotation';

const defaultImageUrl =
'https://raw.githubusercontent.com/RobinNagpal/react-image-annotation-ts/HEAD/example/img.jpeg';

const argTypes: ArgTypes = {
src: {
defaultValue:
'https://raw.githubusercontent.com/RobinNagpal/react-image-annotation-ts/HEAD/demo.gif',
defaultValue: defaultImageUrl,
control: {
type: 'text',
},
Expand All @@ -24,15 +27,43 @@ const meta: Meta = {

export default meta;

const Template: Story<AnnotationPropsOptional> = (args) => (
<Annotation {...args} />
);
const Template: Story<AnnotationPropsOptional> = (args) => {
const [annotations, setAnnotations] = useState<any[]>([]);
const [annotation, setAnnotation] = useState<any>({});

const onSubmit = (annotation: IAnnotation) => {
const { geometry, data } = annotation;

setAnnotation({});

setAnnotations([
...annotations,
{
geometry,
data: {
...data,
id: Math.random(),
},
},
]);
};

return (
<Annotation
value={annotation}
annotations={annotations}
onChange={setAnnotation}
onSubmit={onSubmit}
{...args}
/>
);
};

// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/react/workflows/unit-testing

const defaultProps: AnnotationPropsOptional = {
src:
'https://raw.githubusercontent.com/RobinNagpal/react-image-annotation-ts/HEAD/demo.gif',
src: defaultImageUrl,
};
export const Default = Template.bind(defaultProps);

Expand Down

0 comments on commit 9cbfb6f

Please sign in to comment.