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

adding examples for mixed sizes #1618

Merged
merged 1 commit into from
Nov 19, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions stories/55-mixed-sizes.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @flow
import React from 'react';
import { storiesOf } from '@storybook/react';
import MixedSizedItems from './src/mixed-sizes/mixed-size-items';
import MixedSizedLists from './src/mixed-sizes/mixed-size-lists';

storiesOf('mixed sizes', module)
.add('with a super large draggable', () => <MixedSizedItems />)
.add('with a super large droppable', () => <MixedSizedLists />);
35 changes: 35 additions & 0 deletions stories/src/mixed-sizes/mixed-size-items.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// @flow
import React, { useState } from 'react';
import { quotes as initial } from '../data';
import type { Quote } from '../types';
import QuoteList from '../primatives/quote-list';
import { DragDropContext, type DropResult } from '../../../src';
import reorder from '../reorder';

function getQuotes() {
const large: Quote = {
...initial[0],
content: Array.from({ length: 20 })
.map(() => 'some really long text')
.join(' '),
};

const quotes: Quote[] = [large, ...initial.slice(1)];
return quotes;
}

export default function App() {
const [quotes, setQuotes] = useState(() => getQuotes());
function onDragEnd(result: DropResult) {
if (!result.destination) {
return;
}
setQuotes(reorder(quotes, result.source.index, result.destination.index));
}
return (
<DragDropContext onDragEnd={onDragEnd}>
<p>This is a bit lame right now</p>
<QuoteList quotes={quotes} />
</DragDropContext>
);
}
25 changes: 25 additions & 0 deletions stories/src/mixed-sizes/mixed-size-lists.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @flow
import React, { useState } from 'react';
import styled from '@emotion/styled';
import { getQuotes } from '../data';
import QuoteList from '../primatives/quote-list';
import { DragDropContext } from '../../../src';
import { noop } from '../../../src/empty';

const Parent = styled.div`
display: flex;
`;

export default function App() {
const [first] = useState(() => getQuotes(3));
const [second] = useState(() => getQuotes(3));
return (
<DragDropContext onDragEnd={noop}>
<p>This is a bit lame right now</p>
<Parent>
<QuoteList listId="first" quotes={first} />
<QuoteList listId="second" quotes={second} style={{ width: 800 }} />
</Parent>
</DragDropContext>
);
}