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

Typescript + API Cleanup + Simple Components #30

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3a8c533
bump version
Nov 25, 2020
723ebee
* Converted files to TS.
Nov 30, 2020
ec52265
* Added files missing in last commit
Nov 30, 2020
5ca4d7a
* Fixed remaining TS errors
Nov 30, 2020
fe28492
* Added StickyList and AutoSizedStickyList
Nov 30, 2020
9913158
* [BREAKING CHANGE] - changed API so that it returns the node that yo…
Dec 1, 2020
38c141c
* Prevent key errors.
Dec 1, 2020
16b5530
Point to the code!
Dec 1, 2020
ee0f2df
Externalise the callback props to make it easier to use
Dec 1, 2020
3895940
We need to export everything.
Dec 1, 2020
1e0c799
Revert back to target
Dec 2, 2020
45551e1
Break out props so they can be used individually.
Dec 2, 2020
f7c05f6
Remove need to specify key by using node.id
Dec 2, 2020
dc3c842
Added meta and isLeafNode to info. Added types for react-measure
Dec 3, 2020
18d12c8
Added meta and isLeafNode to info. Added types for react-measure
Dec 23, 2020
23022fc
Use render function which will be more performant.
Dec 31, 2020
11edaa5
Port fix from master
Dec 31, 2020
d382c28
Moved @types/react-measure from dependencies to devDependencies
Feb 27, 2021
91a7dee
Add a prop to allow the inline width/height to not be set on the stic…
Mar 23, 2021
a04d4ed
bump version
Mar 23, 2021
7f99192
Merge pull request #33 from marchaos/prop_for_not_setting_inline_widt…
marchaos Mar 23, 2021
c5b5c92
Fixed issue in StickyList were the root node didn't have a height cau…
Nov 2, 2022
53e8ff9
allow passed in items to have node info on them for a sticky list
Nov 3, 2022
e549b44
Add getting and setting scrollLeft
Jan 20, 2023
57c9f66
Build for both esm and cjs
Mar 11, 2024
616b349
Add extensions so that webpack does not complain when using the mjs v…
Mar 12, 2024
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
14 changes: 3 additions & 11 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"env": {
"production": {
"plugins": [
"transform-react-remove-prop-types",
"transform-react-constant-elements",
"transform-react-inline-elements"
]
}
},
"presets": ["airbnb", "es2015", "stage-0", "react"]
}
"presets": ["@babel/preset-env", "@babel/preset-typescript", "@babel/preset-react"],
"plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-export-default-from"]
}
14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
node_modules
.idea
*.iml
dist/
dist
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 140,
"tabWidth": 4,
"singleQuote": true
}
5 changes: 5 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"baseUrl": "http://localhost:9000",
"viewportWidth": 1280,
"video": false
}
9 changes: 9 additions & 0 deletions cypress/integration/stickyList/scrolling.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Sticky List Scrolling', () => {
beforeEach(() => {
cy.visit('/?render=cities');
});
it('can scroll to the bottom and see the last node', () => {
cy.get('.rv-sticky-tree').scrollTo(0, 10000000);
cy.contains('Territorio Federal Delta Amacuro').should('be.visible');
});
});
9 changes: 9 additions & 0 deletions cypress/integration/stickyTree/scrolling.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Sticky Tree Scrolling', () => {
beforeEach(() => {
cy.visit('/?render=countries');
});
it('can scroll to the bottom and see the last node', () => {
cy.get('.rv-sticky-tree').scrollTo(0, 10000000);
cy.contains('Territorio Federal Delta Amacuro').should('be.visible');
});
});
21 changes: 21 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
38 changes: 38 additions & 0 deletions example/CitiesList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useCallback } from 'react';
import countries from './countries.json';
import { AutoSizedStickyList } from '../src/';
import { StickyTreeRowRenderer } from '../src';

export interface CityTreeNode {
id: number;
name: string;
depth: number;
}

const cities = countries.filter((node) => node.depth === 3).map((city, index) => ({ id: index, ...city }));

const CitiesList: React.FC = () => {
const rowRenderer: StickyTreeRowRenderer<CityTreeNode> = useCallback(({ node, style }) => {
style = { ...style, backgroundColor: '#87ceeb' };

return (
<div className="node-row" style={style} key={node.id}>
{node.name}
</div>
);
}, []);

const getRowHeight = useCallback((node: CityTreeNode) => {
return 30;
}, []);

return (
<AutoSizedStickyList<CityTreeNode>
className="sticky-tree-wrapper"
getRowHeight={getRowHeight}
rowRenderer={rowRenderer}
items={cities}
/>
);
};
export default CitiesList;
3 changes: 3 additions & 0 deletions example/CountriesTree.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';
declare const CountriesTree: React.FC<{}>;
export default CountriesTree;
38 changes: 38 additions & 0 deletions example/CountriesTree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useCallback, useState } from 'react';
import Measure from 'react-measure';
import countries from './countries.json';
import StickyTree from "../src/StickyTree";
const backgroundColors = [
'#45b3e0',
'#5bbce4',
'#71c5e7',
'#87ceeb'
];
const CountriesTree = () => {
const [dimensions, setDimensions] = useState({});
const rowRenderer = useCallback(({ id, style }) => {
const node = countries[id];
style = Object.assign(Object.assign({}, style), { backgroundColor: backgroundColors[node.depth] });
return (React.createElement("div", { className: "my-sticky-row", style: style }, node.name));
}, []);
const getChildren = useCallback((id) => {
var _a;
if (countries[id].children) {
return (_a = countries[id].children) === null || _a === void 0 ? void 0 : _a.map(childId => ({
id: childId,
height: 30,
isSticky: !!countries[childId].children,
stickyTop: 30 * countries[childId].depth,
zIndex: 4 - countries[childId].depth,
}));
}
}, []);
return (React.createElement(Measure, { bounds: true, onResize: (contentRect) => {
var _a, _b;
setDimensions({ width: (_a = contentRect.bounds) === null || _a === void 0 ? void 0 : _a.width, height: (_b = contentRect.bounds) === null || _b === void 0 ? void 0 : _b.height });
} }, ({ measureRef }) => {
return (React.createElement("div", { ref: measureRef, className: "sticky-tree-wrapper" },
React.createElement(StickyTree, { width: dimensions.width, height: dimensions.height, root: { id: 0, height: 30, isSticky: true, top: 0, zIndex: 4 }, renderRoot: true, rowRenderer: rowRenderer, getChildren: getChildren, overscanRowCount: 20 })));
}));
};
export default CountriesTree;
54 changes: 54 additions & 0 deletions example/CountriesTree.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useCallback, useMemo } from 'react';
import countries from './countries.json';
import { StickyTreeGetChildren, StickyTreeRowRenderer } from '../src';
import { AutoSizedStickyTree } from '../src';

const backgroundColors: string[] = ['#45b3e0', '#5bbce4', '#71c5e7', '#87ceeb'];

interface CountriesTreeNode {
id: number;
name: string;
index: number;
depth: number;
children?: number[];
}

const countryNodes: CountriesTreeNode[] = countries.map((country) => ({ ...country, id: country.index }));
const rootNode = countryNodes[0];

const CountriesTree: React.FC = () => {
const rowRenderer: StickyTreeRowRenderer<CountriesTreeNode> = useCallback(({ node, style }) => {
style = { ...style, backgroundColor: backgroundColors[node.depth] };

return (
<div className="node-row" key={node.id} style={style}>
{node.name}
</div>
);
}, []);

const getChildren: StickyTreeGetChildren<CountriesTreeNode> = useCallback((node, nodeInfo) => {
if (node.children) {
return node.children?.map((childId) => ({
isSticky: !!countryNodes[childId].children,
stickyTop: 30 * countryNodes[childId].depth,
zIndex: 4 - countryNodes[childId].depth,
node: countryNodes[childId],
}));
}
}, []);

const root = useMemo(() => ({ isSticky: true, stickyTop: 0, zIndex: 4, node: rootNode }), []);

return (
<AutoSizedStickyTree<CountriesTreeNode>
className="sticky-tree-wrapper"
root={root}
renderRoot={true}
rowHeight={30}
rowRenderer={rowRenderer}
getChildren={getChildren}
/>
);
};
export default CountriesTree;
1 change: 1 addition & 0 deletions example/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
9 changes: 9 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import CountriesTree from './CountriesTree';
class App extends React.PureComponent {
render() {
return (React.createElement(CountriesTree, null));
}
}
ReactDOM.render(React.createElement(App, null), document.getElementById('app'));
29 changes: 29 additions & 0 deletions example/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import ReactDOM from 'react-dom';
import CountriesTree from './CountriesTree';
import CitiesList from "./CitiesList";

class App extends React.PureComponent {

render() {
const url = new URL(window.location.href);
const render = url.searchParams.get('render');

if (render === 'cities') {
return <CitiesList />
} else if (render === 'countries') {
return <CountriesTree />
}

return (
<div style={{width: '80%', margin: '0 auto', padding: '20px'}}>
<div><a href="/?render=countries">Sticky Tree Example</a></div>
<div><a href="/?render=cities">List Example</a></div>
</div>
);
}
}

ReactDOM.render(
<App />,
document.getElementById('app'));
Loading