Skip to content

Commit 5769068

Browse files
committed
extract feature context
1 parent 700fe25 commit 5769068

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 align="center">Build better Tables with React&nbsp;&nbsp;&nbsp;🍱</h1>
1+
<h1 align="center">Build better Tables with React&nbsp;🍱</h1>
22

33
<br>
44

src/common/context/Feature.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as React from 'react';
2+
3+
import { SelectContext } from '@table-library/react-table-library/common/context/Select';
4+
import { TreeContext } from '@table-library/react-table-library/common/context/Tree';
5+
import { SortContext } from '@table-library/react-table-library/common/context/Sort';
6+
import { PaginationContext } from '@table-library/react-table-library/common/context/Pagination';
7+
8+
export const useFeatures = () => {
9+
const select = React.useContext(SelectContext);
10+
const tree = React.useContext(TreeContext);
11+
const sort = React.useContext(SortContext);
12+
const pagination = React.useContext(PaginationContext);
13+
14+
return {
15+
select,
16+
tree,
17+
sort,
18+
pagination,
19+
// others
20+
};
21+
};

src/common/context/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './Feature';
12
export * from './Table';
23
export * from './Theme';
34
export * from './Layout';

src/table/Row/Row.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import cs from 'clsx';
55
/** @jsx jsx */
66
import { css, jsx } from '@emotion/react';
77

8-
import { RowContainer } from '@table-library/react-table-library/common/components/Row';
98
import { isRowClick } from '@table-library/react-table-library/common/util/isRowClick';
9+
import { RowContainer } from '@table-library/react-table-library/common/components/Row';
1010
import { ThemeContext } from '@table-library/react-table-library/common/context/Theme';
11-
import { SelectContext } from '@table-library/react-table-library/common/context/Select';
12-
import { TreeContext } from '@table-library/react-table-library/common/context/Tree';
13-
import { SortContext } from '@table-library/react-table-library/common/context/Sort';
14-
import { PaginationContext } from '@table-library/react-table-library/common/context/Pagination';
11+
import { useFeatures } from '@table-library/react-table-library/common/context/Feature';
1512

1613
import { useConsumeRowLayout } from '@table-library/react-table-library/resize/useConsumeRowLayout';
1714

@@ -77,19 +74,7 @@ const evaluateProps = (rowPropsByFeature: FeatureProps[], onSingleClick: OnClick
7774
export const Row: React.FC<RowProps> = (props: RowProps) => {
7875
const { item, className, disabled, onClick, onDoubleClick, children, ...rest } = props;
7976

80-
const select = React.useContext(SelectContext);
81-
const tree = React.useContext(TreeContext);
82-
const sort = React.useContext(SortContext);
83-
const pagination = React.useContext(PaginationContext);
84-
85-
const features = {
86-
select,
87-
tree,
88-
sort,
89-
pagination,
90-
// others
91-
};
92-
77+
const features = useFeatures();
9378
const rowPropsByFeature = getRowProps(features, props);
9479

9580
const theme = React.useContext(ThemeContext);

0 commit comments

Comments
 (0)