2020-08-12 21:44:28 +02:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { action } from '@storybook/addon-actions';
|
2020-06-19 01:12:15 +02:00
|
|
|
import BaseStyles from 'App/BaseStyles';
|
|
|
|
import NormalizeStyles from 'App/NormalizeStyles';
|
2020-08-23 19:27:56 +02:00
|
|
|
import theme from 'App/ThemeStyles';
|
2020-06-19 01:12:15 +02:00
|
|
|
import produce from 'immer';
|
2020-08-12 21:44:28 +02:00
|
|
|
import styled, { ThemeProvider } from 'styled-components';
|
2020-08-23 19:27:56 +02:00
|
|
|
import NOOP from 'shared/utils/noop';
|
2020-08-12 21:44:28 +02:00
|
|
|
import Checklist, { ChecklistItem } from '.';
|
2020-06-19 01:12:15 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
component: Checklist,
|
|
|
|
title: 'Checklist',
|
|
|
|
parameters: {
|
|
|
|
backgrounds: [
|
2020-08-12 21:44:28 +02:00
|
|
|
{ name: 'gray', value: '#f8f8f8', default: true },
|
|
|
|
{ name: 'white', value: '#ffffff' },
|
2020-06-19 01:12:15 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const Container = styled.div`
|
|
|
|
width: 552px;
|
|
|
|
margin: 25px;
|
|
|
|
border: 1px solid rgba(${props => props.theme.colors.bg.primary});
|
|
|
|
`;
|
|
|
|
|
|
|
|
const defaultItems = [
|
|
|
|
{
|
|
|
|
id: '1',
|
|
|
|
position: 1,
|
|
|
|
taskChecklistID: '1',
|
|
|
|
complete: false,
|
|
|
|
name: 'Tasks',
|
|
|
|
assigned: null,
|
|
|
|
dueDate: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '2',
|
|
|
|
taskChecklistID: '1',
|
|
|
|
position: 2,
|
|
|
|
complete: false,
|
|
|
|
name: 'Projects',
|
|
|
|
assigned: null,
|
|
|
|
dueDate: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '3',
|
|
|
|
position: 3,
|
|
|
|
taskChecklistID: '1',
|
|
|
|
complete: false,
|
|
|
|
name: 'Teams',
|
|
|
|
assigned: null,
|
|
|
|
dueDate: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: '4',
|
|
|
|
position: 4,
|
|
|
|
complete: false,
|
|
|
|
taskChecklistID: '1',
|
|
|
|
name: 'Organizations',
|
|
|
|
assigned: null,
|
|
|
|
dueDate: null,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const Default = () => {
|
|
|
|
const [checklistName, setChecklistName] = useState('Checklist');
|
|
|
|
const [items, setItems] = useState(defaultItems);
|
|
|
|
const onToggleItem = (itemID: string, complete: boolean) => {
|
|
|
|
setItems(
|
|
|
|
produce(items, draftState => {
|
|
|
|
const idx = items.findIndex(item => item.id === itemID);
|
|
|
|
if (idx !== -1) {
|
|
|
|
draftState[idx] = {
|
|
|
|
...draftState[idx],
|
|
|
|
complete,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<BaseStyles />
|
|
|
|
<NormalizeStyles />
|
|
|
|
<ThemeProvider theme={theme}>
|
|
|
|
<Container>
|
|
|
|
<Checklist
|
2020-07-12 09:06:11 +02:00
|
|
|
wrapperProps={{}}
|
|
|
|
handleProps={{}}
|
2020-06-19 01:12:15 +02:00
|
|
|
name={checklistName}
|
|
|
|
checklistID="checklist-one"
|
|
|
|
items={items}
|
|
|
|
onDeleteChecklist={action('delete checklist')}
|
|
|
|
onChangeName={currentName => {
|
|
|
|
setChecklistName(currentName);
|
|
|
|
}}
|
|
|
|
onAddItem={itemName => {
|
|
|
|
let position = 1;
|
|
|
|
const lastItem = items[-1];
|
|
|
|
if (lastItem) {
|
|
|
|
position = lastItem.position * 2 + 1;
|
|
|
|
}
|
|
|
|
setItems([
|
|
|
|
...items,
|
|
|
|
{
|
|
|
|
id: `${Math.random()}`,
|
|
|
|
name: itemName,
|
|
|
|
complete: false,
|
|
|
|
assigned: null,
|
|
|
|
dueDate: null,
|
|
|
|
position,
|
|
|
|
taskChecklistID: '1',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}}
|
|
|
|
onDeleteItem={itemID => {
|
|
|
|
setItems(items.filter(item => item.id !== itemID));
|
|
|
|
}}
|
|
|
|
onChangeItemName={(itemID, currentName) => {
|
|
|
|
setItems(
|
|
|
|
produce(items, draftState => {
|
|
|
|
const idx = items.findIndex(item => item.id === itemID);
|
|
|
|
if (idx !== -1) {
|
|
|
|
draftState[idx] = {
|
|
|
|
...draftState[idx],
|
|
|
|
name: currentName,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
onToggleItem={onToggleItem}
|
2020-07-12 09:06:11 +02:00
|
|
|
>
|
2020-08-23 19:27:56 +02:00
|
|
|
{items.map(item => (
|
2020-07-12 09:06:11 +02:00
|
|
|
<ChecklistItem
|
|
|
|
key={item.id}
|
|
|
|
wrapperProps={{}}
|
|
|
|
handleProps={{}}
|
2020-08-12 21:44:28 +02:00
|
|
|
checklistID="id"
|
2020-07-12 09:06:11 +02:00
|
|
|
itemID={item.id}
|
|
|
|
name={item.name}
|
|
|
|
complete={item.complete}
|
2020-08-23 19:27:56 +02:00
|
|
|
onDeleteItem={NOOP}
|
|
|
|
onChangeName={NOOP}
|
|
|
|
onToggleItem={NOOP}
|
2020-07-12 09:06:11 +02:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Checklist>
|
2020-06-19 01:12:15 +02:00
|
|
|
</Container>
|
|
|
|
</ThemeProvider>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|