Skip to content

Commit

Permalink
Merge branch 'main' of github.com:equinor/fusion-react-components int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
odinr committed Oct 13, 2021
2 parents 6f17464 + 26d3820 commit 911e71a
Show file tree
Hide file tree
Showing 28 changed files with 368 additions and 24 deletions.
11 changes: 11 additions & 0 deletions packages/button/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# 0.4.0 (2021-10-05)


### Features

* add new element creator ([efd2a2a](https://github.com/equinor/fusion-react-components/commit/efd2a2a3bfcf53c8cc640cafb8351bc137ecc677))





## 0.3.8 (2021-09-30)

**Note:** Version bump only for package @equinor/fusion-react-button
Expand Down
6 changes: 3 additions & 3 deletions packages/button/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/fusion-react-button",
"version": "0.3.8",
"version": "0.4.0",
"description": "React component for displaying a button",
"keywords": [
"button",
Expand Down Expand Up @@ -34,7 +34,7 @@
"url": "https://github.com/equinor/fusion-react-components/issues"
},
"dependencies": {
"@equinor/fusion-wc-button": "^1.1.18",
"@equinor/fusion-react-utils": "^1.1.18"
"@equinor/fusion-react-utils": "^1.1.18",
"@equinor/fusion-wc-button": "^1.1.18"
}
}
8 changes: 8 additions & 0 deletions packages/filterpane/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.1.8](https://github.com/equinor/fusion-react-components/compare/@equinor/[email protected]...@equinor/[email protected]) (2021-10-05)

**Note:** Version bump only for package @equinor/fusion-react-filter





## 1.1.7 (2021-10-05)


Expand Down
4 changes: 2 additions & 2 deletions packages/filterpane/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/fusion-react-filter",
"version": "1.1.7",
"version": "1.1.8",
"description": "component for Filtering data",
"author": "",
"homepage": "https://github.com/equinor/fusion-react-components/tree/master/packages/filterpane#readme",
Expand Down Expand Up @@ -38,7 +38,7 @@
"url": "https://github.com/equinor/fusion-react-components/issues"
},
"dependencies": {
"@equinor/fusion-react-button": "^0.3.8",
"@equinor/fusion-react-button": "^0.4.0",
"@equinor/fusion-react-checkbox": "^0.3.6",
"@equinor/fusion-react-radio": "^0.3.6",
"@equinor/fusion-react-styles": "^0.3.5",
Expand Down
8 changes: 8 additions & 0 deletions packages/hanging-garden/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.6.8](https://github.com/equinor/fusion-react-components/compare/@equinor/[email protected]...@equinor/[email protected]) (2021-10-11)

**Note:** Version bump only for package @equinor/fusion-react-hanging-garden





## [1.6.7](https://github.com/equinor/fusion-react-components/compare/@equinor/[email protected]...@equinor/[email protected]) (2021-09-30)

**Note:** Version bump only for package @equinor/fusion-react-hanging-garden
Expand Down
2 changes: 1 addition & 1 deletion packages/hanging-garden/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/fusion-react-hanging-garden",
"version": "1.6.7",
"version": "1.6.8",
"description": "component handling rendering of hanging gardens",
"author": "",
"homepage": "https://github.com/equinor/fusion-react-components/tree/master/packages/HangingGarden#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/hanging-garden/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const DEFAULT_ITEM_TEXT_STYLE = new PIXI.TextStyle({
export const createTextStyle = (style: PIXI.TextStyle): PIXI.TextStyle => new PIXI.TextStyle(style);

export const getMaxRowCount = <T extends HangingGardenColumnIndex>(columns: HangingGardenColumn<T>[]): number => {
return Math.max(...columns.map((column) => column.data.length));
return Math.max(...columns.map((column) => flattenColumn(column).length));
};

export const getExpandedWith = (width: number, c: ExpandedColumn): number =>
Expand Down Expand Up @@ -146,7 +146,7 @@ const flattenGroup = <T extends HangingGardenColumnIndex>(
/**
*
* @param column columns that might need to be flattened
* @returns columns, flattened into one array per column, without grouping, in correct order for rendering. May containar both Items and ColumnGrouPheaders
* @returns columns, flattened into one array per column, without grouping, in correct order for rendering. May contain both Items and ColumnGroupHeaders
*
* checks if the columns data is grouped, is not returns the columns.
* else reduces the Columns into a flat array of items and group by headers.
Expand Down
17 changes: 17 additions & 0 deletions packages/table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# 0.4.0 (2021-10-12)


### Bug Fixes

* remove some comments ([51e4f93](https://github.com/equinor/fusion-react-components/commit/51e4f938ab36233fa4f5cd7a0291e66143db6600))


### Features

* make pagination disabled by default and add option for pagesizes ([9888099](https://github.com/equinor/fusion-react-components/commit/98880994753c89ff5ebbdbb64a78e8cda74f3094))
* pagination for table ([f578745](https://github.com/equinor/fusion-react-components/commit/f578745abd916a36cdfb9bf618312f1563f18d66))





## [0.3.19](https://github.com/equinor/fusion-react-components/compare/@equinor/[email protected]...@equinor/[email protected]) (2021-09-30)

**Note:** Version bump only for package @equinor/fusion-react-table
Expand Down
3 changes: 2 additions & 1 deletion packages/table/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/fusion-react-table",
"version": "0.3.19",
"version": "0.4.0",
"description": "component for displaying tables",
"keywords": [
"table",
Expand Down Expand Up @@ -35,6 +35,7 @@
"url": "https://github.com/equinor/fusion-react-components/issues"
},
"dependencies": {
"@equinor/fusion-react-button": "^0.3.7",
"@equinor/fusion-react-styles": "^0.3.5",
"@equinor/fusion-wc-icon": "^1.0.12",
"@equinor/fusion-wc-popover": "^1.0.13",
Expand Down
3 changes: 2 additions & 1 deletion packages/table/src/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TableOptions, PluginHook } from 'react-table';
import { Layout, LayoutProps, TableLayout } from './layout';

import { TableData } from './types';
import { TableProvider } from './TableProvider';
import { PropsWithChildren } from 'react';
import Paginator from './components/pagination/Paginator';

export type TableProps<TData extends TableData> = LayoutProps & {
options: TableOptions<TData>;
Expand All @@ -20,6 +20,7 @@ export const Table = <TData extends TableData>(props: PropsWithChildren<TablePro
return (
<TableProvider options={options} plugins={plugins}>
<Template {...layoutProps} />
<Paginator />
{children}
</TableProvider>
);
Expand Down
6 changes: 5 additions & 1 deletion packages/table/src/TableProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useSortBy,
useTable,
TableState,
usePagination,
} from 'react-table';
import { useDefaultColumn } from './components';
import { useColumnMenu } from './plugins/menu';
Expand All @@ -34,7 +35,10 @@ export const TableProvider = <TData extends TableData = TableData>(
const { children, options } = props;

const _plugins = props.plugins || [];
const plugins = useMemo(() => [useResizeColumns, useColumnMenu, useFilters, useSortBy, ..._plugins], [..._plugins]);
const plugins = useMemo(
() => [useResizeColumns, useColumnMenu, useFilters, useSortBy, usePagination, ..._plugins],
[..._plugins]
);

const defaultColumn = useDefaultColumn(options);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Button from '@equinor/fusion-react-button';
import { useTableContext } from '../../../TableProvider';

export const PaginationBtnFirst = (): JSX.Element => {
const { instance } = useTableContext();
const { gotoPage, canPreviousPage } = instance;

return (
<Button
onClick={() => gotoPage(0)}
icon="first_page"
variant="ghost"
disabled={!canPreviousPage}
color={canPreviousPage ? 'primary' : 'secondary'}
dense
/>
);
};
export default PaginationBtnFirst;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Button from '@equinor/fusion-react-button';
import { useTableContext } from '../../../TableProvider';

export const PaginationBtnLast = (): JSX.Element => {
const { instance } = useTableContext();
const { gotoPage, pageCount, canNextPage } = instance;

return (
<Button
onClick={() => gotoPage(pageCount - 1)}
icon="last_page"
variant="ghost"
disabled={!canNextPage}
color={canNextPage ? 'primary' : 'secondary'}
dense
/>
);
};
export default PaginationBtnLast;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Button from '@equinor/fusion-react-button';
import { useTableContext } from '../../../TableProvider';

export const PaginationBtnNext = (): JSX.Element => {
const { instance } = useTableContext();
const { nextPage, canNextPage } = instance;

return (
<Button
onClick={() => nextPage()}
icon="chevron_right"
variant="ghost"
disabled={!canNextPage}
color={canNextPage ? 'primary' : 'secondary'}
dense
/>
);
};

export default PaginationBtnNext;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Button from '@equinor/fusion-react-button';
import { useTableContext } from '../../../TableProvider';

export const PaginationBtnPrev = (): JSX.Element => {
const { instance } = useTableContext();
const { previousPage, canPreviousPage } = instance;

return (
<Button
onClick={() => previousPage()}
icon="chevron_left"
variant="ghost"
disabled={!canPreviousPage}
color={canPreviousPage ? 'primary' : 'secondary'}
dense
/>
);
};
4 changes: 4 additions & 0 deletions packages/table/src/components/pagination/Buttons/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { PaginationBtnFirst } from './PaginationBtnFirst';
export { PaginationBtnNext } from './PaginationBtnNext';
export { PaginationBtnPrev } from './PaginationBtnPrev';
export { PaginationBtnLast } from './PaginationBtnLast';
27 changes: 27 additions & 0 deletions packages/table/src/components/pagination/Paginator.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { makeStyles, FusionTheme, createStyles, theme } from '@equinor/fusion-react-styles';

export type SpacingType = keyof typeof theme.spacing.comfortable;

export type StyleProps = {
spacing: SpacingType;
};

export const useStyles = makeStyles<FusionTheme, StyleProps>(
() =>
createStyles({
pagination: {
display: 'flex',
justifyContent: 'end',
alignItems: 'center',
},
select: {
fontFamily: 'inherit',
margin: '0 1em 0 1em',
padding: '0 .5em 0 0',
fontSize: '14px',
},
}),
{ name: 'fusion-table-pagination-layout' }
);

export default useStyles;
69 changes: 69 additions & 0 deletions packages/table/src/components/pagination/Paginator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { useTableContext } from '../../TableProvider';
import { PaginationBtnFirst, PaginationBtnPrev, PaginationBtnNext, PaginationBtnLast } from './Buttons';
import { StyleProps, useStyles } from './Paginator.style';

const defaultStyleProps: StyleProps = {
spacing: 'small',
};
type PaginatorProps = JSX.IntrinsicElements['div'];
/**
* Component for showing and controlling the pagination of the table component.
* Returns null if `disablePagination` is set to `true`.
* Set the boolean in the `options` prop to the `Table` component to enable pagination.
* The `pageSize` is by default 10 (showing 10 records on each page), but can be changed.
* Same goes for `pageSizes`
* @param JSX.InstrinsicElements - HTML Attributes, e.g. styling.
* @example
* ```jsx
* const options = {
* data: data,
* columns: columns,
* disablePagination: false,
* pageSizes: [20,30,40],
* initialState: {
* pageSize: 20
* },
* }
* return <Table options={options}/>
* ```
*/
export const Paginator = (props: PaginatorProps): JSX.Element | null => {
const { instance, state } = useTableContext();
const { pageOptions, setPageSize, disablePagination = true, pageSizes = [10, 20, 30, 40, 50] } = instance;
const { pageIndex, pageSize } = state;
const styles = useStyles({ ...defaultStyleProps });

if (disablePagination) {
return null;
}
return (
<div {...props} className={styles.pagination}>
<div>Items per page: </div>
{/*TODO: use fusion dropdown component */}
<select
className={styles.select}
value={pageSize}
onChange={(e) => {
setPageSize(Number(e.target.value));
}}
>
{pageSizes.map((pageSize) => (
<option key={pageSize} value={pageSize}>
{pageSize}
</option>
))}
</select>

<div>
{/*TODO: pageIndex should might not be undefined? See types.ts */}
{pageIndex !== undefined && `Page ${pageIndex + 1} of ${pageOptions.length}`}
</div>
<PaginationBtnFirst />
<PaginationBtnPrev />
<PaginationBtnNext />
<PaginationBtnLast />
</div>
);
};

export default Paginator;
1 change: 0 additions & 1 deletion packages/table/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './useTable';
export * from './components';
export * from './types';

export * from './Table';
export * from './TableProvider';
5 changes: 2 additions & 3 deletions packages/table/src/layout/TableLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { clsx } from '@equinor/fusion-react-styles';

import useStyles, { StyleProps } from './layout.style';

import { Layout, LayoutProps } from './types';
import { useTableContext } from '../TableProvider';
// import { useFlexLayout } from 'react-table';
Expand All @@ -13,7 +11,8 @@ const defaultStyleProps: StyleProps = {
export const TableLayoutTemplate = (props: LayoutProps): JSX.Element => {
const { spacing = 'small', style, className } = props;
const { instance } = useTableContext();
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = instance;
const { getTableProps, getTableBodyProps, headerGroups, prepareRow } = instance;
const rows = instance.disablePagination ? instance.rows : instance.page;
const styles = useStyles({ ...defaultStyleProps, spacing });
return (
<table {...getTableProps({ className: clsx(styles.root, className) })} style={style}>
Expand Down
Loading

0 comments on commit 911e71a

Please sign in to comment.