Skip to content

Commit

Permalink
add extended story
Browse files Browse the repository at this point in the history
  • Loading branch information
exced committed Jan 9, 2018
1 parent 3648c20 commit afeaae5
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 163 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See [Example App](https://github.com/exced/react-file-manager/blob/master/src/Ap

| Name | Type | Default | Required | Description |
| :----------:| :-------------: | :-----------------: | :----------:| :------------:|
| initial | Object. See [Example](https://github.com/exced/react-file-manager/blob/master/src/App.js) | None | true | normalized data map |
| map | Files object. See [Example](https://github.com/exced/react-file-manager/blob/master/src/App.js) Mandatory fields : "id", "children", "parent" | None | true | normalized data map (You can use easily setup a normalizr schema. |
| rootId | Number | None | true | Id of root folder |
| onChange | Object => void | None | true | Triggered when file structure changes |
| onChangeRow | (itemId, source, destination) => void | (a,b,c) => {} | false | Triggered when item change of row |
Expand Down
167 changes: 6 additions & 161 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const initial = {
"1": {
id: "1",
title: "title1",
children: ["2", "3", "4", "5"],
children: ["2", "3"],
parent: "0",
},
"2": {
Expand All @@ -26,171 +26,21 @@ const initial = {
"3": {
id: "3",
title: "title3",
children: ["6", "7"],
children: ["4", "5"],
parent: "1",
},
"4": {
id: "4",
title: "title4",
children: ["8", "9"],
parent: "1",
children: [],
parent: "3",
},
"5": {
id: "5",
title: "title5",
children: [],
parent: "1",
},
"6": {
id: "6",
title: "title6",
children: [],
parent: "3",
},
"7": {
id: "7",
title: "title7",
children: [],
parent: "3",
},
"8": {
id: "8",
title: "title8",
children: [],
parent: "4",
},
"9": {
id: "9",
title: "title9",
children: ["10"],
parent: "4",
},
"10": {
id: "10",
title: "title10",
children: ["11"],
parent: "9",
},
"11": {
id: "11",
title: "title11",
children: ["12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"],
parent: "10",
},
"12": {
id: "12",
title: "title12",
children: [],
parent: "11",
},
"13": {
id: "13",
title: "title13",
children: [],
parent: "11",
},
"14": {
id: "14",
title: "title14",
children: [],
parent: "11",
},
"15": {
id: "15",
title: "title15",
children: [],
parent: "11",
},
"16": {
id: "16",
title: "title16",
children: [],
parent: "11",
},
"17": {
id: "17",
title: "title17",
children: [],
parent: "11",
},
"18": {
id: "18",
title: "title18",
children: [],
parent: "11",
},
"19": {
id: "19",
title: "title19",
children: [],
parent: "11",
},
"20": {
id: "20",
title: "title20",
children: [],
parent: "11",
},
"21": {
id: "21",
title: "title21",
children: [],
parent: "11",
},
"22": {
id: "22",
title: "title22",
children: [],
parent: "11",
},
"23": {
id: "23",
title: "title23",
children: [],
parent: "11",
},
"24": {
id: "24",
title: "title24",
children: [],
parent: "11",
},
"25": {
id: "25",
title: "title25",
children: [],
parent: "11",
},
"26": {
id: "26",
title: "title26",
children: [],
parent: "11",
},
"27": {
id: "27",
title: "title27",
children: [],
parent: "11",
},
"28": {
id: "28",
title: "title28",
children: [],
parent: "11",
},
"29": {
id: "29",
title: "title29",
children: [],
parent: "11",
},
"30": {
id: "30",
title: "title30",
children: [],
parent: "11",
},
}

const images = {
Expand All @@ -209,18 +59,13 @@ export default class App extends Component {
renderItem = (item, index) => (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<div style={{ flex: 1 }}>
<div style={{ float: 'left' }}>
<img src={item.children.length > 0 ? images.folder : images.file} alt={item.title} style={{ width: 22, height: 22 }} />
</div>
<img src={item.children.length > 0 ? images.folder : images.file} alt={item.title} style={{ width: 22, height: 22, float: 'left' }} />
</div>
<div style={{ flex: 5 }}>
<span style={{ width: 150, textAlign: 'left', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}>{item.title}</span>
</div>
<div style={{ flex: 1 }}>
{item.children.length > 0 &&
<div style={{ float: 'right' }}>
<Icon type="right" />
</div>}
{item.children.length > 0 && <Icon style={{ float: 'right' }} type="right" />}
</div>
</div>
)
Expand Down
4 changes: 3 additions & 1 deletion stories/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import Extended from './src/Extended'
import Default from './src/Default'
import Stress from './src/Stress'
import Color from './src/Color'

storiesOf('File Manager', module)
.add('Extended', () => <Extended />)
.add('Default', () => <Default />)
.add('Stress', () => <Stress />)
.add('Color', () => <Color itemSelectedColor='#66ff99' dropBackgroundColor='#99ddff'/>)
.add('Color', () => <Color itemSelectedColor='#66ff99' dropBackgroundColor='#99ddff' />)
48 changes: 48 additions & 0 deletions stories/src/Components/CreateFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Modal, Form, Input, Icon } from 'antd'

const FormItem = Form.Item

const CreateFile = Form.create()(
({ form, visible, onCancel, onSubmit }) => {
const handleSubmit = (e) => {
e.preventDefault()
form.validateFieldsAndScroll((err, values) => {
if (!err) {
onSubmit(values)
}
})
}
return (
<Modal
visible={visible}
title="Create new file"
cancelText="Cancel"
okText="Create"
onCancel={onCancel}
onOk={handleSubmit}
>
<Form>
<FormItem>
{form.getFieldDecorator('title', {
rules: [{
required: true, message: "Title required",
}],
})(
<Input prefix={<Icon type="file-text" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="File title" />
)}
</FormItem>
</Form>
</Modal>
)
}
)

CreateFile.propTypes = {
visible: PropTypes.bool.isRequired,
onCancel: PropTypes.func.isRequired,
onSubmit: PropTypes.func.isRequired,
}

export default CreateFile
48 changes: 48 additions & 0 deletions stories/src/Components/CreateFolder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Modal, Form, Input, Icon } from 'antd'

const FormItem = Form.Item

const CreateFolder = Form.create()(
({ form, visible, onCancel, onSubmit }) => {
const handleSubmit = (e) => {
e.preventDefault()
form.validateFieldsAndScroll((err, values) => {
if (!err) {
onSubmit(values)
}
})
}
return (
<Modal
visible={visible}
title="Create new folder"
cancelText="Cancel"
okText="Create"
onCancel={onCancel}
onOk={handleSubmit}
>
<Form>
<FormItem>
{form.getFieldDecorator('title', {
rules: [{
required: true, message: "Title required",
}],
})(
<Input prefix={<Icon type="file-text" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="Folder title" />
)}
</FormItem>
</Form>
</Modal>
)
}
)

CreateFolder.propTypes = {
visible: PropTypes.bool.isRequired,
onCancel: PropTypes.func.isRequired,
onSubmit: PropTypes.func.isRequired,
}

export default CreateFolder
42 changes: 42 additions & 0 deletions stories/src/Components/EditText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Input } from 'antd'
import styled from 'styled-components'

const StyledInput = styled(Input) `
color: ${props => props.color ? props.color : '#181919'};
font-size: 1.25em;
padding: 0.25em 1em;
border-width: 1px;
border-color: ${props => props.focused ? '#181919' : 'transparent'};
background-color: transparent;
width: auto;
height: auto;
text-align: center;
`

const EditText = ({ onChange, value, size, placeholder, textAlign }) => (
<StyledInput
onFocus={e => e.target.select()}
onBlur={e => e.target.blur()}
onPressEnter={e => e.target.blur()}
size={size}
value={value}
onChange={e => onChange(e.target.value)}
placeholder={placeholder}
/>
)

EditText.propTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
size: PropTypes.oneOf(["small", "large"]),
placeholder: PropTypes.string,
}

EditText.defaultProps = {
size: "small",
placeholder: "placeholder"
}

export default EditText
Loading

0 comments on commit afeaae5

Please sign in to comment.