@hw-component/table 1.9.88 → 1.9.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ import { MutableRefObject } from "react";
2
+ interface HeaderStyleParams {
3
+ bodyRef: MutableRefObject<HTMLDivElement | null>;
4
+ titleContentRef: MutableRefObject<HTMLDivElement | null>;
5
+ rightNodeRef: MutableRefObject<HTMLDivElement | null>;
6
+ }
7
+ export declare const useHeaderStyle: ({ bodyRef, titleContentRef, rightNodeRef }: HeaderStyleParams) => {};
8
+ export {};
@@ -0,0 +1,54 @@
1
+ // welcome to hoo hoo hoo
2
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
3
+ import { useState, useLayoutEffect, useEffect } from 'react';
4
+
5
+ var useHeaderStyle = function useHeaderStyle(_ref) {
6
+ var bodyRef = _ref.bodyRef,
7
+ titleContentRef = _ref.titleContentRef,
8
+ rightNodeRef = _ref.rightNodeRef;
9
+ var _useState = useState({}),
10
+ _useState2 = _slicedToArray(_useState, 2),
11
+ style = _useState2[0],
12
+ setStyle = _useState2[1];
13
+ var setHeaderStyle = function setHeaderStyle() {
14
+ var _bodyRef$current, _titleContentRef$curr, _rightNodeRef$current;
15
+ var headerWidth = ((_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.clientWidth) || 0;
16
+ console.log(headerWidth, "headerWidth");
17
+ var titleWidth = ((_titleContentRef$curr = titleContentRef.current) === null || _titleContentRef$curr === void 0 ? void 0 : _titleContentRef$curr.clientWidth) || 0;
18
+ var rightNodeWidth = ((_rightNodeRef$current = rightNodeRef.current) === null || _rightNodeRef$current === void 0 ? void 0 : _rightNodeRef$current.clientWidth) || 0;
19
+ if (rightNodeWidth + titleWidth >= headerWidth) {
20
+ setStyle({
21
+ overflow: "auto"
22
+ });
23
+ return;
24
+ }
25
+ setStyle({});
26
+ };
27
+ useLayoutEffect(function () {
28
+ setHeaderStyle();
29
+ }, []);
30
+ useEffect(function () {
31
+ var resizeFn = function resizeFn() {
32
+ setHeaderStyle();
33
+ };
34
+ window.addEventListener("resize", resizeFn);
35
+ return function () {
36
+ window.removeEventListener("resize", resizeFn);
37
+ };
38
+ }, []);
39
+ useEffect(function () {
40
+ var element = titleContentRef.current;
41
+ if (!element || !window.ResizeObserver) return;
42
+ var observer = new ResizeObserver(function () {
43
+ setHeaderStyle();
44
+ });
45
+ observer.observe(element);
46
+ return function () {
47
+ observer.disconnect();
48
+ };
49
+ }, []);
50
+ return style;
51
+ };
52
+
53
+ export { useHeaderStyle };
54
+ // powered by hdj
@@ -1,9 +1,9 @@
1
1
  // welcome to hoo hoo hoo
2
- import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
3
2
  import { jsxs, jsx } from 'react/jsx-runtime';
4
- import React, { useRef, useState, useLayoutEffect, useEffect } from 'react';
3
+ import React, { useRef } from 'react';
5
4
  import { useHTableContext } from '../../context.js';
6
5
  import { useClassName } from '../../hooks/index.js';
6
+ import { useHeaderStyle } from './hooks.js';
7
7
 
8
8
  var HeaderTitle = (function (_ref) {
9
9
  var headerTitle = _ref.headerTitle,
@@ -17,39 +17,15 @@ var HeaderTitle = (function (_ref) {
17
17
  var bodyRef = useRef();
18
18
  var titleContentRef = useRef();
19
19
  var rightNodeRef = useRef();
20
- var _useState = useState({}),
21
- _useState2 = _slicedToArray(_useState, 2),
22
- style = _useState2[0],
23
- setStyle = _useState2[1];
24
20
  var headerBox = useClassName("hw-table-header-title-box");
25
21
  var headerBoxContent = useClassName("hw-table-header-title-box-content");
26
22
  var titleClassname = useClassName("hw-table-header-title");
27
23
  var rightNodeClassname = useClassName("hw-table-header-right-node");
28
- var setHeaderStyle = function setHeaderStyle() {
29
- var _bodyRef$current, _titleContentRef$curr, _rightNodeRef$current;
30
- var headerWidth = ((_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.clientWidth) || 0;
31
- var titleWidth = ((_titleContentRef$curr = titleContentRef.current) === null || _titleContentRef$curr === void 0 ? void 0 : _titleContentRef$curr.clientWidth) || 0;
32
- var rightNodeWidth = ((_rightNodeRef$current = rightNodeRef.current) === null || _rightNodeRef$current === void 0 ? void 0 : _rightNodeRef$current.clientWidth) || 0;
33
- if (rightNodeWidth + titleWidth >= headerWidth) {
34
- setStyle({
35
- overflow: "auto"
36
- });
37
- return;
38
- }
39
- setStyle({});
40
- };
41
- useLayoutEffect(function () {
42
- setHeaderStyle();
43
- }, []);
44
- useEffect(function () {
45
- var resizeFn = function resizeFn() {
46
- setHeaderStyle();
47
- };
48
- window.addEventListener("resize", resizeFn);
49
- return function () {
50
- window.removeEventListener("resize", resizeFn);
51
- };
52
- }, []);
24
+ var style = useHeaderStyle({
25
+ bodyRef: bodyRef,
26
+ titleContentRef: titleContentRef,
27
+ rightNodeRef: rightNodeRef
28
+ });
53
29
  if (!headerTitle && !rNode) {
54
30
  return null;
55
31
  }
@@ -1,2 +1,3 @@
1
+ /// <reference types="react" />
1
2
  declare const _default: () => JSX.Element;
2
3
  export default _default;
@@ -0,0 +1,8 @@
1
+ import { MutableRefObject } from "react";
2
+ interface HeaderStyleParams {
3
+ bodyRef: MutableRefObject<HTMLDivElement | null>;
4
+ titleContentRef: MutableRefObject<HTMLDivElement | null>;
5
+ rightNodeRef: MutableRefObject<HTMLDivElement | null>;
6
+ }
7
+ export declare const useHeaderStyle: ({ bodyRef, titleContentRef, rightNodeRef }: HeaderStyleParams) => {};
8
+ export {};
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
4
+ var React = require('react');
5
+
6
+ var useHeaderStyle = function useHeaderStyle(_ref) {
7
+ var bodyRef = _ref.bodyRef,
8
+ titleContentRef = _ref.titleContentRef,
9
+ rightNodeRef = _ref.rightNodeRef;
10
+ var _useState = React.useState({}),
11
+ _useState2 = _slicedToArray(_useState, 2),
12
+ style = _useState2[0],
13
+ setStyle = _useState2[1];
14
+ var setHeaderStyle = function setHeaderStyle() {
15
+ var _bodyRef$current, _titleContentRef$curr, _rightNodeRef$current;
16
+ var headerWidth = ((_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.clientWidth) || 0;
17
+ console.log(headerWidth, "headerWidth");
18
+ var titleWidth = ((_titleContentRef$curr = titleContentRef.current) === null || _titleContentRef$curr === void 0 ? void 0 : _titleContentRef$curr.clientWidth) || 0;
19
+ var rightNodeWidth = ((_rightNodeRef$current = rightNodeRef.current) === null || _rightNodeRef$current === void 0 ? void 0 : _rightNodeRef$current.clientWidth) || 0;
20
+ if (rightNodeWidth + titleWidth >= headerWidth) {
21
+ setStyle({
22
+ overflow: "auto"
23
+ });
24
+ return;
25
+ }
26
+ setStyle({});
27
+ };
28
+ React.useLayoutEffect(function () {
29
+ setHeaderStyle();
30
+ }, []);
31
+ React.useEffect(function () {
32
+ var resizeFn = function resizeFn() {
33
+ setHeaderStyle();
34
+ };
35
+ window.addEventListener("resize", resizeFn);
36
+ return function () {
37
+ window.removeEventListener("resize", resizeFn);
38
+ };
39
+ }, []);
40
+ React.useEffect(function () {
41
+ var element = titleContentRef.current;
42
+ if (!element || !window.ResizeObserver) return;
43
+ var observer = new ResizeObserver(function () {
44
+ setHeaderStyle();
45
+ });
46
+ observer.observe(element);
47
+ return function () {
48
+ observer.disconnect();
49
+ };
50
+ }, []);
51
+ return style;
52
+ };
53
+
54
+ exports.useHeaderStyle = useHeaderStyle;
55
+ // powered by h
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
6
5
  var jsxRuntime = require('react/jsx-runtime');
7
6
  var React = require('react');
8
7
  var context = require('../../context.js');
9
8
  var index = require('../../hooks/index.js');
9
+ var hooks = require('./hooks.js');
10
10
 
11
11
  var HeaderTitle = (function (_ref) {
12
12
  var headerTitle = _ref.headerTitle,
@@ -20,39 +20,15 @@ var HeaderTitle = (function (_ref) {
20
20
  var bodyRef = React.useRef();
21
21
  var titleContentRef = React.useRef();
22
22
  var rightNodeRef = React.useRef();
23
- var _useState = React.useState({}),
24
- _useState2 = _slicedToArray(_useState, 2),
25
- style = _useState2[0],
26
- setStyle = _useState2[1];
27
23
  var headerBox = index.useClassName("hw-table-header-title-box");
28
24
  var headerBoxContent = index.useClassName("hw-table-header-title-box-content");
29
25
  var titleClassname = index.useClassName("hw-table-header-title");
30
26
  var rightNodeClassname = index.useClassName("hw-table-header-right-node");
31
- var setHeaderStyle = function setHeaderStyle() {
32
- var _bodyRef$current, _titleContentRef$curr, _rightNodeRef$current;
33
- var headerWidth = ((_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.clientWidth) || 0;
34
- var titleWidth = ((_titleContentRef$curr = titleContentRef.current) === null || _titleContentRef$curr === void 0 ? void 0 : _titleContentRef$curr.clientWidth) || 0;
35
- var rightNodeWidth = ((_rightNodeRef$current = rightNodeRef.current) === null || _rightNodeRef$current === void 0 ? void 0 : _rightNodeRef$current.clientWidth) || 0;
36
- if (rightNodeWidth + titleWidth >= headerWidth) {
37
- setStyle({
38
- overflow: "auto"
39
- });
40
- return;
41
- }
42
- setStyle({});
43
- };
44
- React.useLayoutEffect(function () {
45
- setHeaderStyle();
46
- }, []);
47
- React.useEffect(function () {
48
- var resizeFn = function resizeFn() {
49
- setHeaderStyle();
50
- };
51
- window.addEventListener("resize", resizeFn);
52
- return function () {
53
- window.removeEventListener("resize", resizeFn);
54
- };
55
- }, []);
27
+ var style = hooks.useHeaderStyle({
28
+ bodyRef: bodyRef,
29
+ titleContentRef: titleContentRef,
30
+ rightNodeRef: rightNodeRef
31
+ });
56
32
  if (!headerTitle && !rNode) {
57
33
  return null;
58
34
  }
@@ -1,2 +1,3 @@
1
+ /// <reference types="react" />
1
2
  declare const _default: () => JSX.Element;
2
3
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "1.9.88",
3
+ "version": "1.9.89",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -0,0 +1,48 @@
1
+ import {MutableRefObject, useEffect, useLayoutEffect, useState} from "react";
2
+
3
+ interface HeaderStyleParams {
4
+ bodyRef:MutableRefObject<HTMLDivElement|null>;
5
+ titleContentRef:MutableRefObject<HTMLDivElement|null>;
6
+ rightNodeRef:MutableRefObject<HTMLDivElement|null>;
7
+ }
8
+
9
+ export const useHeaderStyle = ({bodyRef,titleContentRef,rightNodeRef}:HeaderStyleParams) => {
10
+ const [style, setStyle] = useState({});
11
+ const setHeaderStyle = () => {
12
+ const headerWidth = bodyRef.current?.clientWidth || 0;
13
+ console.log(headerWidth,"headerWidth")
14
+ const titleWidth = titleContentRef.current?.clientWidth || 0;
15
+ const rightNodeWidth = rightNodeRef.current?.clientWidth || 0;
16
+ if (rightNodeWidth + titleWidth >= headerWidth) {
17
+ setStyle({
18
+ overflow: "auto",
19
+ });
20
+ return;
21
+ }
22
+ setStyle({});
23
+ };
24
+ useLayoutEffect(() => {
25
+ setHeaderStyle();
26
+ }, []);
27
+ useEffect(() => {
28
+ const resizeFn = () => {
29
+ setHeaderStyle();
30
+ };
31
+ window.addEventListener("resize", resizeFn);
32
+ return () => {
33
+ window.removeEventListener("resize", resizeFn);
34
+ };
35
+ }, []);
36
+ useEffect(() => {
37
+ const element = titleContentRef.current;
38
+ if (!element||!window.ResizeObserver) return;
39
+ const observer = new ResizeObserver(() => {
40
+ setHeaderStyle();
41
+ });
42
+ observer.observe(element);
43
+ return () => {
44
+ observer.disconnect();
45
+ }
46
+ }, []);
47
+ return style;
48
+ }
@@ -1,53 +1,32 @@
1
- import { Row } from "antd";
2
1
  import type { HTableBodyProps } from "../modal";
3
- import type { DetailedReactHTMLElement } from "react";
4
- import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
2
+ import {DetailedReactHTMLElement, useLayoutEffect} from "react";
3
+ import React, { useRef } from "react";
5
4
  import { useHTableContext } from "../../context";
6
5
  import { useClassName } from "../../hooks";
6
+ import {useHeaderStyle} from "./hooks";
7
+
7
8
  interface IProps {
8
9
  headerTitle: HTableBodyProps["headerTitle"];
9
10
  contentStyle?: React.CSSProperties;
10
11
  rNode?: React.ReactNode;
11
12
  }
12
13
  export default ({ headerTitle, contentStyle, rNode }: IProps) => {
13
- const { tableInstance, selectedRowData, rowOnChange, allSelectChange } =
14
- useHTableContext();
14
+ const { tableInstance, selectedRowData, rowOnChange, allSelectChange } = useHTableContext();
15
15
  const bodyRef = useRef<any>();
16
16
  const titleContentRef = useRef<any>();
17
17
  const rightNodeRef = useRef<any>();
18
- const [style, setStyle] = useState({});
19
18
  const headerBox = useClassName("hw-table-header-title-box");
20
19
  const headerBoxContent = useClassName("hw-table-header-title-box-content");
21
20
  const titleClassname = useClassName("hw-table-header-title");
22
21
  const rightNodeClassname = useClassName("hw-table-header-right-node");
23
- const setHeaderStyle = () => {
24
- const headerWidth = bodyRef.current?.clientWidth || 0;
25
- const titleWidth = titleContentRef.current?.clientWidth || 0;
26
- const rightNodeWidth = rightNodeRef.current?.clientWidth || 0;
27
- if (rightNodeWidth + titleWidth >= headerWidth) {
28
- setStyle({
29
- overflow: "auto",
30
- });
31
- return;
32
- }
33
- setStyle({});
34
- };
35
- useLayoutEffect(() => {
36
- setHeaderStyle();
37
- }, []);
38
- useEffect(() => {
39
- const resizeFn = () => {
40
- setHeaderStyle();
41
- };
42
- window.addEventListener("resize", resizeFn);
43
- return () => {
44
- window.removeEventListener("resize", resizeFn);
45
- };
46
- }, []);
22
+ const style=useHeaderStyle({
23
+ bodyRef,
24
+ titleContentRef,
25
+ rightNodeRef
26
+ });
47
27
  if (!headerTitle && !rNode) {
48
28
  return null;
49
29
  }
50
-
51
30
  return (
52
31
  <div ref={bodyRef} className={titleClassname} style={contentStyle}>
53
32
  <div className={headerBox} style={style}>
@@ -77,6 +77,7 @@ const maker = (name) => {
77
77
  };
78
78
  export default () => {
79
79
  const hTable = useHTable();
80
+ const [width,setWidth]=useState(0);
80
81
  const { loading, data } = useRequest(() => {
81
82
  const arrayData: any[] = [];
82
83
  for (let i = 0; i < 10; i = i + 1) {
@@ -153,29 +154,19 @@ export default () => {
153
154
  dataSource={[{}, {}, {}]}
154
155
  headerTitle={
155
156
  <Space size={8}>
156
- <div style={{ width: 1000 }}>
157
- <Button
157
+ <Button
158
158
  onClick={() => {
159
+ setTimeout(()=>{
160
+ setWidth(1000);
161
+ },1000)
159
162
  console.log(hTable.table.getColSettingKeys());
160
163
  }}
161
- >
162
- 操作
163
- </Button>
164
- </div>
165
- <Button
166
- onClick={() => {
167
- console.log(hTable.table.getColSettingKeys());
168
- }}
169
- >
170
- 操作
171
- </Button>
172
- <Button
173
- onClick={() => {
174
- console.log(hTable.table.getColSettingKeys());
175
- }}
176
164
  >
177
165
  操作
178
166
  </Button>
167
+ <div>
168
+ <div style={{width,height:50,backgroundColor:"red"}}></div>
169
+ </div>
179
170
  </Space>
180
171
  }
181
172
  options={{