-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
5,646 additions
and
3,613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["../.babelrc.js"] | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/patternfly-3/patternfly-react-wooden-tree/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src | ||
build |
13 changes: 13 additions & 0 deletions
13
packages/patternfly-3/patternfly-react-wooden-tree/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# react-wooden-tree | ||
|
||
## Getting Started | ||
|
||
``` | ||
yarn add patternfly-react-wooden-tree | ||
``` | ||
|
||
or | ||
|
||
``` | ||
npm install patternfly-react-wooden-tree --save | ||
``` |
38 changes: 38 additions & 0 deletions
38
packages/patternfly-3/patternfly-react-wooden-tree/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "patternfly-react-wooden-tree", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "dist/js/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/js/index.d.ts", | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/patternfly/patternfly-react.git" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"patternfly" | ||
], | ||
"author": "Red Hat", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/patternfly/patternfly-react/issues" | ||
}, | ||
"homepage": "https://github.com/patternfly/patternfly-react#readme", | ||
"scripts": { | ||
"build": "yarn build:babel", | ||
"build:babel": "concurrently \"yarn build:babel:cjs\" \"yarn build:babel:esm\"", | ||
"build:babel:cjs": "cross-env BABEL_ENV=production:cjs babel src --out-dir dist/js", | ||
"build:babel:esm": "cross-env BABEL_ENV=production:esm babel src --out-dir dist/esm" | ||
}, | ||
"dependencies": { | ||
"prop-types": "^15.6.2", | ||
"react": "^16.6.1", | ||
"react-wooden-tree": "^1.1.2" | ||
}, | ||
"devDependencies": {} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ges/patternfly-3/patternfly-react-wooden-tree/src/components/TreeView/TreeView.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { withInfo } from '@storybook/addon-info/dist/index'; | ||
import { defaultTemplate } from 'storybook/decorators/storyTemplates'; | ||
import { storybookPackageName } from 'storybook/constants/siteConstants'; | ||
import { name } from '../../../package.json'; | ||
import TreeViewExample from './TreeViewExample'; | ||
|
||
const stories = storiesOf(`${storybookPackageName(name)}/Tree View`, module); | ||
|
||
stories.addDecorator( | ||
defaultTemplate({ | ||
title: 'Catalog Tile', | ||
description: | ||
'This is a Tree View component to display trees and hierarchical data using React Wooden Tree.' + | ||
'The tree uses the https://www.npmjs.com/package/react-wooden-tree component.' | ||
}) | ||
); | ||
|
||
stories.add( | ||
'Tree View', | ||
withInfo({ | ||
source: false, | ||
propTables: [TreeViewExample] | ||
})(() => ( | ||
<div style={{ display: 'flex' }}> | ||
<TreeViewExample /> | ||
</div> | ||
)) | ||
); |
87 changes: 87 additions & 0 deletions
87
...ages/patternfly-3/patternfly-react-wooden-tree/src/components/TreeView/TreeViewExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from 'react'; | ||
import TreeView from './index'; | ||
|
||
const data = [ | ||
{ | ||
text: 'Parent 1', | ||
icon: 'fa fa-folder', | ||
nodes: [ | ||
{ | ||
text: 'Child 1', | ||
nodes: [{ text: 'Grandchild 1' }, { text: 'Grandchild 2' }] | ||
}, | ||
{ | ||
text: 'Child 2', | ||
nodes: [{ text: 'Grandchild 1' }, { text: 'Grandchild 2' }] | ||
} | ||
] | ||
}, | ||
{ | ||
text: 'Parent 2', | ||
icon: 'fa fa-folder', | ||
nodes: [{ text: 'Child 1' }] | ||
}, | ||
{ | ||
text: 'Parent 3', | ||
icon: 'fa fa-folder' | ||
}, | ||
{ | ||
text: 'Parent 4', | ||
icon: 'fa fa-folder' | ||
}, | ||
{ | ||
text: 'Parent 5', | ||
icon: 'fa fa-folder' | ||
} | ||
]; | ||
|
||
const EXPANDED = 'state.expanded'; | ||
const CHECKED = 'state.checked'; | ||
const DISABLED = 'state.disabled'; | ||
const SELECTED = 'state.selected'; | ||
const NODES = 'nodes'; | ||
const LOADING = 'loading'; | ||
|
||
const actionMapper = { | ||
[EXPANDED]: TreeView.nodeExpanded, | ||
[CHECKED]: TreeView.nodeChecked, | ||
[DISABLED]: TreeView.nodeDisabled, | ||
[SELECTED]: TreeView.nodeSelected, | ||
[NODES]: TreeView.nodeChildren, | ||
[LOADING]: TreeView.nodeLoading | ||
}; | ||
|
||
class TreeViewExample extends React.Component { | ||
state = { | ||
tree: TreeView.initTree(data) | ||
}; | ||
|
||
/** | ||
* The callback function for changing data in the tree. | ||
* | ||
* @param {string} nodeId The nodeId of the node. | ||
* @param {string} type The field name which changed. | ||
* @param {boolean} value The new value to assign. | ||
*/ | ||
onDataChange = (nodeId, type, value) => { | ||
let node = TreeView.nodeSelector(this.state.tree, nodeId); | ||
if (node == null) { | ||
return; | ||
} | ||
|
||
if (actionMapper.hasOwnProperty(type)) { | ||
node = actionMapper[type](node, value); | ||
this.setState({ tree: TreeView.nodeUpdater(this.state.tree, node) }); | ||
} | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="App"> | ||
<TreeView nodeIcon="fa fa-file-o" data={this.state.tree} onDataChange={this.onDataChange} {...this.props} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default TreeViewExample; |
8 changes: 8 additions & 0 deletions
8
packages/patternfly-3/patternfly-react-wooden-tree/src/components/TreeView/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Tree } from 'react-wooden-tree'; | ||
|
||
require('react-wooden-tree/dist/react-wooden-tree.css'); | ||
require('./style.css'); | ||
|
||
class TreeView extends Tree {} | ||
|
||
export default TreeView; |
7 changes: 7 additions & 0 deletions
7
packages/patternfly-3/patternfly-react-wooden-tree/src/components/TreeView/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.Icon { | ||
margin-right: 0; | ||
} | ||
|
||
.NoOpenButton { | ||
margin-left: 1em; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/patternfly-3/patternfly-react-wooden-tree/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as TreeView } from './components/TreeView'; |
Oops, something went wrong.