Skip to content

Commit

Permalink
Merge pull request #25 from bbc/adds-transcript-form
Browse files Browse the repository at this point in the history
Adds transcript form
  • Loading branch information
allishultes authored Sep 12, 2019
2 parents 9d950c2 + 3df2645 commit df3069c
Show file tree
Hide file tree
Showing 15 changed files with 438 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .storybook/addons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@storybook/addon-knobs/register';
import '@storybook/addon-viewport/register';
import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
import '@storybook/addon-a11y/register';

2 changes: 0 additions & 2 deletions .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import { configure, addDecorator, addParameters } from '@storybook/react';
import { withA11y } from '@storybook/addon-a11y';

// automatically import all files ending in *.stories.js
// https://webpack.js.org/guides/dependency-management/
const components = require.context('../packages/components/', true, /.stories.js$/);
// const demo = require.context('../demo/', true, /.stories.js$/);
const styles = require.context('./styles', true, /\.scss$/);
Expand Down
169 changes: 161 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@babel/core": "^7.5.5",
"@storybook/addon-a11y": "^5.0.8",
"@storybook/addon-actions": "^5.1.9",
"@storybook/addon-knobs": "^5.0.8",
"@storybook/addon-links": "^5.1.9",
"@storybook/addon-viewport": "^5.0.8",
"@storybook/addons": "^5.1.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/Breadcrumb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const CustomBreadcrumb = (props) => {
};

CustomBreadcrumb.propTypes = {
items: PropTypes.list,
items: PropTypes.array,
};

CustomBreadcrumb.defaultProps = {
Expand Down
48 changes: 48 additions & 0 deletions packages/components/CustomAlert/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import Alert from 'react-bootstrap/Alert';

const CustomAlert = ({ ...props } ) => {

const [ showAlert, toggleShowAlert ] = useState(props.show);

const handleDismiss = () => {
toggleShowAlert(false);
};

const setAlertHeading = () => {
return props.heading ? <Alert.Heading>{props.heading}</Alert.Heading> : null;
};

const setAlert = () => {
if (showAlert) {
return (
<Alert
variant={ props.variant }
onClose={ handleDismiss }
dismissible
>
{setAlertHeading()}
{props.message}
</Alert>
);
} else {
return null;
}
};

return setAlert();
};

CustomAlert.propTypes = {
show: PropTypes.bool.isRequired,
heading: PropTypes.string,
message: PropTypes.string,
vatiant: PropTypes.string,
};

CustomAlert.defaultProps = {
show: true,
};

export default CustomAlert;
21 changes: 21 additions & 0 deletions packages/components/CustomAlert/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import CustomAlert from '../index.js';

export const alertProps = {
variant: 'danger',
heading: 'Error could not contact the server',
message: 'There was an error trying to create this transcript on the server',
show: true
};

storiesOf('Custom Alert', module)
.add('Default', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<CustomAlert
{ ...alertProps }
/>
</section>
);
});
11 changes: 6 additions & 5 deletions packages/components/FormModal/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import React, { useState } from 'react';
import { withKnobs, text, boolean, number } from '@storybook/addon-knobs';
import PropTypes from 'prop-types';
import Modal from 'react-bootstrap/Modal';
import ItemForm from './ItemForm/index.js';
import ItemForm from '../ItemForm/index.js';
import TranscriptForm from '../TranscriptForm/index.js';

const ItemFormModal = (props) => {


const [ showModal, toggleShowModal ] = useState(props.showModal);

const form = (props.type === 'transcript') ? <TranscriptForm { ...props }/> : <ItemForm { ...props }/>;

return (
<Modal show={ showModal } onHide={ () => toggleShowModal(!showModal) }>
<Modal.Header closeButton>
<Modal.Title>{props.modalTitle}</Modal.Title>
</Modal.Header>
<Modal.Body>
<ItemForm
{ ...props }
/>
{form}
</Modal.Body>
</Modal>
);
Expand Down
25 changes: 15 additions & 10 deletions packages/components/FormModal/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import React from 'react';

import { storiesOf } from '@storybook/react';
import { actions } from '@storybook/addon-actions';
import StoryRouter from 'storybook-react-router';
import FormModal from '../index.js';
import ItemForm from '../ItemForm';

export const modalItems = [ {
id: 1,
itemType: 'project',
showModal: true,
title: 'Example Transcript Title',
title: 'Example Project Title',
description: 'This is a sample card description. This is fun!',
url: '/projects/1/transcripts/1234',
modalTitle: 'Edit Project',
}, {
showModal: true,
modalTitle: 'New Project',
id: 2
}, {
projectId: 123,
title: '',
description: '',
uploadCompleted: true,
showModal: true,
modalTitle: 'New Transcript',
id: 3,
type: 'transcript'
} ];

export const modalActions = actions({ handleSaveForm: 'Form saved' });
Expand All @@ -42,16 +50,13 @@ storiesOf('Form Modal', module)
/>
</section>
);
});

storiesOf('Form Modal / Item Form', module)
.addDecorator(StoryRouter())
.add('Edit Project', () => {
})
.add('New Transcript', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<ItemForm
<FormModal
{ ...modalActions }
{ ...modalItems[0] }
{ ...modalItems[2] }
/>
</section>
);
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions packages/components/ItemForm/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import StoryRouter from 'storybook-react-router';
import ItemForm from '../index.js';
import { modalActions, modalItems } from '../../FormModal/stories/index.stories.js';

storiesOf('Item Form', module)
.addDecorator(StoryRouter())
.add('Edit Project', () => {
return (
<section style={ { height: '90vh', overflow: 'scroll' } }>
<ItemForm
{ ...modalActions }
{ ...modalItems[0] }
/>
</section>
);
});
Loading

0 comments on commit df3069c

Please sign in to comment.