Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"dependencies": {
"@babel/runtime": "^7.10.1",
"@rc-component/context": "^1.0.0",
"classnames": "^2.2.5",
"rc-resize-observer": "^1.1.0",
"rc-util": "^5.22.5",
Expand Down
6 changes: 3 additions & 3 deletions src/Body/BodyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import Cell from '../Cell';
import BodyContext from '../context/BodyContext';
import TableContext from '../context/TableContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import type {
ColumnType,
CustomizeComponent,
Expand Down Expand Up @@ -52,7 +52,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
scopeCellComponent,
childrenColumnName,
} = props;
const { prefixCls, fixedInfoList } = useContextSelector(TableContext, [
const { prefixCls, fixedInfoList } = useContext(TableContext, [
'prefixCls',
'fixedInfoList',
]);
Expand All @@ -67,7 +67,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
expandIcon,
expandedRowRender,
expandIconColumnIndex,
} = useContextSelector(BodyContext, [
} = useContext(BodyContext, [
'flattenColumns',
'expandableType',
'expandRowByClick',
Expand Down
6 changes: 3 additions & 3 deletions src/Body/ExpandedRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import Cell from '../Cell';
import ExpandedRowContext from '../context/ExpandedRowContext';
import TableContext from '../context/TableContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import type { CustomizeComponent } from '../interface';

export interface ExpandedRowProps {
Expand All @@ -26,8 +26,8 @@ function ExpandedRow({
colSpan,
isEmpty,
}: ExpandedRowProps) {
const scrollbarSize = useContextSelector(TableContext, 'scrollbarSize');
const { fixHeader, fixColumn, componentWidth, horizonScroll } = useContextSelector(
const scrollbarSize = useContext(TableContext, 'scrollbarSize');
const { fixHeader, fixColumn, componentWidth, horizonScroll } = useContext(
ExpandedRowContext,
['fixHeader', 'fixColumn', 'componentWidth', 'horizonScroll'],
);
Expand Down
8 changes: 4 additions & 4 deletions src/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PerfRecord } from '../context/PerfContext';
import PerfContext from '../context/PerfContext';
import ResizeContext from '../context/ResizeContext';
import TableContext from '../context/TableContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import useFlattenRecords from '../hooks/useFlattenRecords';
import type { GetComponentProps, GetRowKey, Key } from '../interface';
import { getColumnsKey } from '../utils/valueUtil';
Expand Down Expand Up @@ -34,12 +34,12 @@ function Body<RecordType>({
emptyNode,
childrenColumnName,
}: BodyProps<RecordType>) {
const onColumnResize = useContextSelector(ResizeContext, 'onColumnResize');
const { prefixCls, getComponent } = useContextSelector(TableContext, [
const onColumnResize = useContext(ResizeContext, 'onColumnResize');
const { prefixCls, getComponent } = useContext(TableContext, [
'prefixCls',
'getComponent',
]);
const flattenColumns = useContextSelector(BodyContext, 'flattenColumns');
const flattenColumns = useContext(BodyContext, 'flattenColumns');

const flattenData: { record: RecordType; indent: number; index: number }[] =
useFlattenRecords<RecordType>(data, childrenColumnName, expandedKeys, getRowKey);
Expand Down
6 changes: 3 additions & 3 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { HoverContextProps } from '../context/HoverContext';
import HoverContext from '../context/HoverContext';
import PerfContext from '../context/PerfContext';
import StickyContext from '../context/StickyContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import type {
AlignType,
CellEllipsisType,
Expand Down Expand Up @@ -146,7 +146,7 @@ function Cell<RecordType extends DefaultRecordType>(

const perfRecord = React.useContext(PerfContext);
const supportSticky = React.useContext(StickyContext);
const allColumnsFixedLeft = useContextSelector(BodyContext, 'allColumnsFixedLeft');
const allColumnsFixedLeft = useContext(BodyContext, 'allColumnsFixedLeft');

// ==================== Child Node ====================
const [childNode, legacyCellProps] = React.useMemo<
Expand Down Expand Up @@ -342,7 +342,7 @@ const WrappedCell = React.forwardRef((props: CellProps<any>, ref: React.Ref<any>
const mergedColSpan = colSpan ?? cellColSpan;
const mergedRowSpan = rowSpan ?? cellRowSpan;

const { onHover, hovering } = useContextSelector(HoverContext, cxt => {
const { onHover, hovering } = useContext(HoverContext, cxt => {
const isHovering = inHoverRange(index, mergedRowSpan || 1, cxt?.startRow, cxt?.endRow);

return {
Expand Down
113 changes: 0 additions & 113 deletions src/ContextSelector/index.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/FixedHolder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import { useMemo } from 'react';
import ColGroup from '../ColGroup';
import TableContext from '../context/TableContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import type { HeaderProps } from '../Header/Header';
import type { ColumnsType, ColumnType } from '../interface';

Expand Down Expand Up @@ -60,7 +60,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<unknown>>(
},
ref,
) => {
const { prefixCls, scrollbarSize, isSticky } = useContextSelector(TableContext, [
const { prefixCls, scrollbarSize, isSticky } = useContext(TableContext, [
'prefixCls',
'scrollbarSize',
'isSticky',
Expand Down
4 changes: 2 additions & 2 deletions src/Footer/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Cell from '../Cell';
import TableContext from '../context/TableContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import type { AlignType } from '../interface';
import { getCellFixedInfo } from '../utils/fixUtil';
import SummaryContext from './SummaryContext';
Expand All @@ -23,7 +23,7 @@ export default function SummaryCell({
rowSpan,
align,
}: SummaryCellProps) {
const { prefixCls, direction } = useContextSelector(TableContext, ['prefixCls', 'direction']);
const { prefixCls, direction } = useContext(TableContext, ['prefixCls', 'direction']);
const { scrollColumnIndex, stickyOffsets, flattenColumns } = React.useContext(SummaryContext);
const lastIndex = index + colSpan - 1;
const mergedColSpan = lastIndex + 1 === scrollColumnIndex ? colSpan + 1 : colSpan;
Expand Down
4 changes: 2 additions & 2 deletions src/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import TableContext from '../context/TableContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import type { ColumnType, StickyOffsets } from '../interface';
import Summary from './Summary';
import SummaryContext from './SummaryContext';
Expand All @@ -14,7 +14,7 @@ export interface FooterProps<RecordType> {
}

function Footer<RecordType>({ children, stickyOffsets, flattenColumns }: FooterProps<RecordType>) {
const prefixCls = useContextSelector(TableContext, 'prefixCls');
const prefixCls = useContext(TableContext, 'prefixCls');

const lastColumnIndex = flattenColumns.length - 1;
const scrollColumn = flattenColumns[lastColumnIndex];
Expand Down
4 changes: 2 additions & 2 deletions src/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import TableContext from '../context/TableContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import type {
CellType,
ColumnGroupType,
Expand Down Expand Up @@ -95,7 +95,7 @@ function Header<RecordType>({
flattenColumns,
onHeaderRow,
}: HeaderProps<RecordType>): React.ReactElement {
const { prefixCls, getComponent } = useContextSelector(TableContext, [
const { prefixCls, getComponent } = useContext(TableContext, [
'prefixCls',
'getComponent',
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Header/HeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Cell from '../Cell';
import TableContext from '../context/TableContext';
import { useContextSelector } from '../ContextSelector';
import { useContext } from '@rc-component/context';
import type {
CellType,
ColumnType,
Expand Down Expand Up @@ -33,7 +33,7 @@ function HeaderRow<RecordType>({
onHeaderRow,
index,
}: RowProps<RecordType>) {
const { prefixCls, direction } = useContextSelector(TableContext, ['prefixCls', 'direction']);
const { prefixCls, direction } = useContext(TableContext, ['prefixCls', 'direction']);

let rowProps: React.HTMLAttributes<HTMLElement>;
if (onHeaderRow) {
Expand Down
2 changes: 1 addition & 1 deletion src/context/BodyContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext } from '../ContextSelector';
import { createContext } from '@rc-component/context';
import type {
ColumnsType,
ColumnType,
Expand Down
2 changes: 1 addition & 1 deletion src/context/ExpandedRowContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext } from '../ContextSelector';
import { createContext } from '@rc-component/context';

export interface ExpandedRowProps {
componentWidth: number;
Expand Down
2 changes: 1 addition & 1 deletion src/context/HoverContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext } from '../ContextSelector';
import { createContext } from '@rc-component/context';

export interface HoverContextProps {
startRow: number;
Expand Down
2 changes: 1 addition & 1 deletion src/context/ResizeContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as React from 'react';
import { createContext } from '../ContextSelector';
import { createContext } from '@rc-component/context';

interface ResizeContextProps {
onColumnResize: (columnKey: React.Key, width: number) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/context/TableContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext } from '../ContextSelector';
import { createContext } from '@rc-component/context';
import type { GetComponent } from '../interface';
import type { FixedInfo } from '../utils/fixUtil';

Expand Down
4 changes: 2 additions & 2 deletions src/stickyScrollBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getOffset } from 'rc-util/lib/Dom/css';
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
import * as React from 'react';
import TableContext from './context/TableContext';
import { useContextSelector } from './ContextSelector';
import { useContext } from '@rc-component/context';
import { useLayoutState } from './hooks/useFrame';

interface StickyScrollBarProps {
Expand All @@ -18,7 +18,7 @@ const StickyScrollBar: React.ForwardRefRenderFunction<unknown, StickyScrollBarPr
{ scrollBodyRef, onScroll, offsetScroll, container },
ref,
) => {
const prefixCls = useContextSelector(TableContext, 'prefixCls');
const prefixCls = useContext(TableContext, 'prefixCls');
const bodyScrollWidth = scrollBodyRef.current?.scrollWidth || 0;
const bodyWidth = scrollBodyRef.current?.clientWidth || 0;
const scrollBarWidth = bodyScrollWidth && bodyWidth * (bodyWidth / bodyScrollWidth);
Expand Down
36 changes: 0 additions & 36 deletions tests/useContextSelector.spec.tsx

This file was deleted.