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

Sorting and Grouping Options #10

Merged
merged 21 commits into from
May 26, 2021
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
'prettier',
],
parserOptions: {
project: './tsconfig.json',
project: './tsconfig.eslint.json',
},
settings: {
react: {
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@rescripts/cli": "^0.0.16",
"@rescripts/utilities": "^0.0.8",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react": "^17.0.7",
"@types/react-dom": "^17.0.5",
"react-refresh": "^0.10.0",
"react-scripts": "^4.0.3",
Expand Down
10 changes: 10 additions & 0 deletions examples/animation/tsconfig.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": false,
"noEmit": false,
"composite": true
}
}
4 changes: 4 additions & 0 deletions examples/animation/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.c.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.js"]
}
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rescripts/cli": "^0.0.16",
"@rescripts/utilities": "^0.0.8",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react": "^17.0.7",
"@types/react-dom": "^17.0.5",
"react-refresh": "^0.10.0",
"react-scripts": "^4.0.3",
Expand Down
10 changes: 10 additions & 0 deletions examples/basic/tsconfig.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": false,
"noEmit": false,
"composite": true
}
}
4 changes: 4 additions & 0 deletions examples/basic/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.c.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.js"]
}
2 changes: 1 addition & 1 deletion examples/column-resizing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rescripts/cli": "^0.0.16",
"@rescripts/utilities": "^0.0.8",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react": "^17.0.7",
"@types/react-dom": "^17.0.5",
"react-refresh": "^0.10.0",
"react-scripts": "^4.0.3",
Expand Down
10 changes: 10 additions & 0 deletions examples/column-resizing/tsconfig.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": false,
"noEmit": false,
"composite": true
}
}
4 changes: 4 additions & 0 deletions examples/column-resizing/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.c.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.js"]
}
2 changes: 1 addition & 1 deletion examples/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rescripts/cli": "^0.0.16",
"@rescripts/utilities": "^0.0.8",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react": "^17.0.7",
"@types/react-dom": "^17.0.5",
"react-refresh": "^0.10.0",
"react-scripts": "^4.0.3",
Expand Down
10 changes: 10 additions & 0 deletions examples/components/tsconfig.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": false,
"noEmit": false,
"composite": true
}
}
4 changes: 4 additions & 0 deletions examples/components/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.c.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.js"]
}
2 changes: 1 addition & 1 deletion examples/controlled-state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rescripts/cli": "^0.0.16",
"@rescripts/utilities": "^0.0.8",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react": "^17.0.7",
"@types/react-dom": "^17.0.5",
"react-refresh": "^0.10.0",
"react-scripts": "^4.0.3",
Expand Down
10 changes: 10 additions & 0 deletions examples/controlled-state/tsconfig.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": false,
"noEmit": false,
"composite": true
}
}
4 changes: 4 additions & 0 deletions examples/controlled-state/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.c.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.js"]
}
2 changes: 1 addition & 1 deletion examples/filter-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rescripts/cli": "^0.0.16",
"@rescripts/utilities": "^0.0.8",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react": "^17.0.7",
"@types/react-dom": "^17.0.5",
"react-refresh": "^0.10.0",
"react-scripts": "^4.0.3",
Expand Down
67 changes: 36 additions & 31 deletions examples/filter-action/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,47 @@ import LineUpLite, {
LineUpLiteColumn,
featureDefault,
actionIconsRemixicon,
ColumnInstance,
ActionIcons,
LineUpLiteFilterAction,
UseFiltersColumnProps,
ActionLineUpProps,
} from '@lineup-lite/table';
import { defaultDarkColorScale, defaultColorScale } from '@lineup-lite/components';
import '@lineup-lite/table/dist/table.css';
import { data, Row } from './data';

function MyFilterAction(props: { col: ColumnInstance<Row>; icons: ActionIcons }) {
const col = props.col as unknown as ColumnInstance<Row> & UseFiltersColumnProps<Row>;
function useVisibleHelper() {
const [visible, setVisible] = useState([] as string[]);

const [visible, setVisible] = useState(false);
const showFilterDialog = useCallback(() => {
setVisible(!visible);
}, [visible, setVisible]);

return (
<>
<LineUpLiteFilterAction {...col} iconFilter={props.icons.filterColumn} toggleFilterColumn={showFilterDialog} />
{visible && (
<div className="filter-dialog">
{col.render('Summary')}
<button onClick={showFilterDialog} type="button">
Close
</button>
</div>
)}
</>
const toggleVisibility = useCallback(
(col: { id: string }) => {
setVisible((v) => (v.indexOf(col.id) >= 0 ? v.filter((d) => d !== col.id) : [...v, col.id]));
},
[setVisible]
);
const isVisible = useCallback((col: { id: string }) => visible.indexOf(col.id) >= 0, [visible]);
return { toggleVisibility, isVisible };
}

function useFilterAction() {
const { toggleVisibility, isVisible } = useVisibleHelper();
return useMemo(() => {
const f: ActionLineUpProps<Row>['actionFilter'] = (col) => {
if (!col.canFilter) {
return undefined;
}
const handler = () => toggleVisibility(col);
return {
handler,
children: isVisible(col) ? (
<div className="filter-dialog">
{col.render('Summary')}
<button onClick={handler} type="button">
Close
</button>
</div>
) : undefined,
};
};
return f;
}, [isVisible, toggleVisibility]);
}

function Table({ isDarkTheme }: { isDarkTheme: boolean }) {
Expand All @@ -63,13 +74,7 @@ function Table({ isDarkTheme }: { isDarkTheme: boolean }) {
const features = useMemo(() => featureDefault<Row>(), []);
const icons = useMemo(() => actionIconsRemixicon(), []);

const filterAction = useCallback((col: ColumnInstance<Row>, givenIcons: ActionIcons) => {
return (
<>
<MyFilterAction col={col} icons={givenIcons} />
</>
);
}, []);
const actionFilter = useFilterAction();

return (
<LineUpLite<Row>
Expand All @@ -78,7 +83,7 @@ function Table({ isDarkTheme }: { isDarkTheme: boolean }) {
features={features}
icons={icons}
dark={isDarkTheme}
actions={filterAction}
actionFilter={actionFilter}
/>
);
}
Expand Down
10 changes: 10 additions & 0 deletions examples/filter-action/tsconfig.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": false,
"noEmit": false,
"composite": true
}
}
4 changes: 4 additions & 0 deletions examples/filter-action/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.c.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.js"]
}
2 changes: 1 addition & 1 deletion examples/flex-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rescripts/cli": "^0.0.16",
"@rescripts/utilities": "^0.0.8",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react": "^17.0.7",
"@types/react-dom": "^17.0.5",
"react-refresh": "^0.10.0",
"react-scripts": "^4.0.3",
Expand Down
10 changes: 10 additions & 0 deletions examples/flex-layout/tsconfig.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": false,
"noEmit": false,
"composite": true
}
}
4 changes: 4 additions & 0 deletions examples/flex-layout/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.c.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.js"]
}
2 changes: 1 addition & 1 deletion examples/fontawesome/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@rescripts/cli": "^0.0.16",
"@rescripts/utilities": "^0.0.8",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react": "^17.0.7",
"@types/react-dom": "^17.0.5",
"react-refresh": "^0.10.0",
"react-scripts": "^4.0.3",
Expand Down
10 changes: 10 additions & 0 deletions examples/fontawesome/tsconfig.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": false,
"noEmit": false,
"composite": true
}
}
4 changes: 4 additions & 0 deletions examples/fontawesome/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.c.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.js"]
}
4 changes: 4 additions & 0 deletions examples/group-options/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
/node_modules
!/src/react-app-env.d.ts
.eslintcache
6 changes: 6 additions & 0 deletions examples/group-options/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/build
/dist
/docs
/coverage
/.prettierignore
.browserslistrc
25 changes: 25 additions & 0 deletions examples/group-options/.rescriptsrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { removeWebpackPlugin } = require('@rescripts/utilities');
const fs = require('fs');
const path = require('path');

function isWorkspace() {
return (
fs.existsSync('../../package.json') && JSON.parse(fs.readFileSync('../../package.json')).name === 'lineup-lite'
);
}

module.exports = [
(config) => {
config.resolve = removeWebpackPlugin('ModuleScopePlugin', config.resolve);

if (isWorkspace()) {
// create a shared cache directory
for (const loader of config.module.rules[1].oneOf) {
if (loader.options && loader.options.cacheDirectory) {
loader.options.cacheDirectory = path.resolve(__dirname, '../.cache/babel-loader');
}
}
}
return config;
},
];
Loading