jrs-react 1.0.3 → 1.0.4

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,226 @@
1
+ import React from "react"
2
+ import { flexType, po } from "../JRUtils"
3
+ import styled from "styled-components"
4
+
5
+ const StyledSeparator=styled.tbody`
6
+ th{
7
+ height:4px;
8
+ background:#c6c6c6;
9
+ }
10
+ `
11
+ const Separator=({length,children})=>{
12
+ return <StyledSeparator className={'separator'}>
13
+ <tr>
14
+ <th colSpan={length}>{children}</th>
15
+ </tr>
16
+ </StyledSeparator>
17
+ }
18
+
19
+ ////////////////////////////////////////////////////////////////////////////
20
+
21
+
22
+ const Ths=({table,groupData,groupIndex,deep,rowColumn,rowIndex})=>{
23
+ return rowColumn?.map(({style:_style,align,type,render,...column},colIndex)=>{
24
+ const style=flexType(_style,table,{},{})
25
+ let content
26
+ if(type){
27
+ content='type'
28
+ }else if(render){
29
+
30
+ content=render?.bind(table)({groupData,groupIndex,ths:111})
31
+ }else{
32
+ content=column.label
33
+ }
34
+ // style.textAlign=align
35
+ return <th key={colIndex}
36
+
37
+ style={{textAlign:align,...style}}
38
+ colSpan={column.colSpan}
39
+ rowSpan={column.isLeaf&&(deep>rowIndex)?deep-rowIndex+1:null}
40
+ >
41
+ {content}
42
+ </th>
43
+ })
44
+ }
45
+
46
+ const GroupColumns=({table,columns:_columns,trClassName,groupData,tbodyIndex})=>{
47
+ const columns=Array.isArray(_columns?.[0])
48
+ ?_columns
49
+ :[_columns]
50
+ return columns?.map((rowColumn,rowIndex)=>{
51
+ return <tr className={trClassName} key={rowIndex}>
52
+ <Ths
53
+ table={table}
54
+ groupData={groupData}
55
+ groupIndex={tbodyIndex}
56
+ deep={columns.length-1}
57
+ rowColumn={rowColumn}
58
+ rowIndex={rowIndex}
59
+ />
60
+ </tr>
61
+ })
62
+ }
63
+
64
+ const GroupHeaderTr=styled.tr`
65
+ z-index: 1;
66
+ XXposition: sticky;
67
+ XXtop: 50px;
68
+ th{
69
+ text-align: left;
70
+ border:1px solid #222222;
71
+ }
72
+ `
73
+ const GroupHeader=(props)=>{
74
+ return <GroupColumns
75
+ trClassName={'jr-group-header'}
76
+ {...props}
77
+ />
78
+ }
79
+
80
+ const GroupFooterTr=styled.tr`
81
+ th{
82
+ border:1px solid #222222;
83
+ text-align: left;
84
+ }
85
+ `
86
+ const GroupFooter=(props)=>{
87
+ return <GroupColumns
88
+ trClassName={'jr-group-footer'}
89
+ {...props}
90
+ />
91
+ }
92
+
93
+
94
+
95
+ ////////////////////////////////////////////////////////////////////////////
96
+ const Td=({column:_column,record,tbodyIndex,trIndex,tdIndex,table})=>{
97
+ let content
98
+ const {style:_style,align,vAlign='baseline',type,typeStyle:_typeStyle,render,setValue,getValue,onChange:_onChange,funcProps,...column}=_column
99
+ const onChange=(inputValue)=>{
100
+ const targetValue=inputValue?.target?.value ?? inputValue
101
+ setValue(record,targetValue)
102
+ table.setValue(table.getValue())
103
+ }
104
+
105
+
106
+ const value=getValue(record)
107
+ let style=render?{}:flexType(_style,table,{value,record},{})
108
+ const setStyle=(_style)=>{
109
+ style=_style
110
+ }
111
+ setStyle.bind(this)
112
+ render?.bind(table)
113
+ if(type){
114
+ const typeStyle=flexType(_typeStyle,table,{record},{})
115
+
116
+ content=React.createElement(type,{
117
+ onChange:_onChange
118
+ ?(e)=>{
119
+ _onChange?.bind(this)(e,{value,onChange,me:content})
120
+ }
121
+ :onChange
122
+ ,value
123
+ ,style:typeStyle
124
+ ,render
125
+ ,...column
126
+ ,...funcProps?.bind(this)({value})
127
+
128
+ })
129
+ }else if(render){
130
+ content=render({index:trIndex,groupIndex:tbodyIndex,value,record,onChange,setStyle})
131
+ }else{
132
+ content=value
133
+ }
134
+ return <td
135
+ colSpan={style.colSpan}
136
+ rowSpan={style.rowSpan}
137
+ style={{
138
+ textAlign:align
139
+ ,verticalAlign:vAlign
140
+ ,...style
141
+ }}
142
+ key={tdIndex}
143
+ >
144
+ {content}
145
+ </td>
146
+ }
147
+ const Tds=({leafColumns,record,table,tbodyIndex,trIndex})=>{
148
+ return leafColumns?.map((column,tdIndex)=>{
149
+
150
+ return <Td
151
+ column={column}
152
+ key={tdIndex}
153
+ record={record}
154
+ table={table}
155
+ tbodyIndex={tbodyIndex}
156
+ trIndex={trIndex}
157
+ tdIndex={tdIndex}
158
+ />
159
+ })
160
+ }
161
+ ////////////////////////////////////////////////////////////////////////////
162
+
163
+
164
+ const TBody=({groupData,groupHeader,leafColumns,groupFooter,table,tbodyIndex})=>{
165
+
166
+ const neededProps={table,tbodyIndex}
167
+ return <>
168
+ <tbody key={`tbody${tbodyIndex}`}>
169
+ {(groupData?.length >0 ) && <GroupHeader
170
+ groupData={groupData}
171
+ columns={groupHeader}
172
+ {...neededProps}
173
+ />}
174
+ {
175
+ groupData?.map((record,trIndex)=>{
176
+ const onRowClick=table.props.onRowClick?.bind(table)
177
+ return <tr key={trIndex}
178
+ onClick={()=>{
179
+ onRowClick?.({record,index:trIndex,groupIndex:tbodyIndex})
180
+ }}
181
+ >
182
+ <Tds
183
+ record={record}
184
+ trIndex={trIndex}
185
+
186
+ {...neededProps}
187
+ leafColumns={leafColumns}
188
+ />
189
+ </tr>
190
+ })
191
+ }
192
+ {(groupData?.length > 0) && <GroupFooter
193
+ groupData={groupData}
194
+ columns={groupFooter}
195
+ {...neededProps}
196
+ />}
197
+
198
+ </tbody>
199
+ {/* {(dataSource.length > (tbodyIndex+1)) && <Separator length={leafColumns.length} key={`sp-${tbodyIndex}`}></Separator>} */}
200
+ </>
201
+ }
202
+
203
+ export const TBodies=({groupHeader,leafColumns,groupFooter,dataSource:_dataSource,table})=>{
204
+ // po('--TBodies--')
205
+ const isGroupDataType=Array.isArray(_dataSource?.[0])
206
+
207
+ const dataSource=isGroupDataType
208
+ ?_dataSource
209
+ :[_dataSource]
210
+
211
+ // po('dataSource',dataSource)
212
+ return dataSource?.map((groupData,tbodyIndex,c)=>{
213
+ return <TBody
214
+ key={`tbody${tbodyIndex}`}
215
+ table={table}
216
+ // dataSource={dataSource}
217
+ // dataGroup={groupData}
218
+ groupData={groupData}
219
+ tbodyIndex={tbodyIndex}
220
+
221
+ groupHeader={groupHeader}
222
+ leafColumns={leafColumns}
223
+ groupFooter={groupFooter}
224
+ />
225
+ })
226
+ }
@@ -0,0 +1,102 @@
1
+ import React, { useRef } from "react"
2
+ import { flexType, po, whatType } from "../JRUtils"
3
+ import Slider from "./Slider"
4
+
5
+
6
+ const Colgroup=({leafColumns,colGroupRef})=>{
7
+ return <colgroup ref={colGroupRef}>
8
+ {
9
+ leafColumns?.map((_column,index)=>{
10
+ const {width,...column}=_column
11
+ const style={
12
+ width
13
+ }
14
+ return <col style={style} key={index}></col>
15
+ })
16
+ }
17
+ </colgroup>
18
+ }
19
+
20
+ const Ths=({deep,rowColumn,rowIndex,table})=>{
21
+ return rowColumn?.map((column,colIndex)=>{
22
+ const thRef=React.createRef()
23
+ return <th key={colIndex}
24
+ ref={thRef}
25
+ colSpan={column.colSpan}
26
+ rowSpan={column.rowSpan ?? (column.isLeaf&&(deep>rowIndex)?deep-rowIndex+1:null)}
27
+ >
28
+ {flexType(column.label,table)}
29
+ {/* [s={column.colSpan??0}]
30
+ [c={column.columnNo??0}] */}
31
+ {
32
+ table.props.resizableColumns===true
33
+ && <Slider table={table} thRef={thRef} column={column}/>
34
+ }
35
+ </th>
36
+ })
37
+ }
38
+
39
+ export const HeadTrs=({columns:_columns,trClassName,table})=>{
40
+ const columns=Array.isArray(_columns?.[0])
41
+ ?_columns
42
+ :[_columns]
43
+ return columns?.map((rowColumn,rowIndex)=>{
44
+ return <tr className={trClassName} key={rowIndex}>
45
+ <Ths deep={columns.length-1} rowColumn={rowColumn} rowIndex={rowIndex} table={table}/>
46
+ </tr>
47
+ })
48
+ }
49
+
50
+ export const THead=({columns,leafColumns,table})=>{
51
+ return <>
52
+ <thead>
53
+ <HeadTrs columns={columns} table={table}/>
54
+ </thead>
55
+ <Colgroup leafColumns={leafColumns} colGroupRef={table.colGroupRef}/>
56
+ </>
57
+ }
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+ const FootThs=({table,groupData,groupIndex,deep,columns,rowIndex})=>{
66
+ return columns?.map((column,colIndex)=>{
67
+ // let content
68
+ // if(type){
69
+ // content='type'
70
+ // }else if(render){
71
+
72
+ // content=render?.bind(table)({groupData,groupIndex,ths:111})
73
+ // }else{
74
+ // content=column.label
75
+ // }
76
+ let style=flexType(column.style,table,{},{})
77
+ const content=whatType(column,table,column.label)
78
+ return <th
79
+ style={style}
80
+ colSpan={column.colSpan}
81
+ rowSpan={column.rowSpan}
82
+ >
83
+ {content}
84
+ </th>
85
+ })
86
+ }
87
+
88
+
89
+ export const TFoot=({table,columns})=>{
90
+ const trs=columns?.map((rowColumn,rowIndex)=>{
91
+ return <tr key={rowIndex}>
92
+ <FootThs columns={rowColumn} table={table}/>
93
+ {/* <Ths deep={columns.length-1} rowColumn={rowColumn} rowIndex={rowIndex}/> */}
94
+ </tr>
95
+ })
96
+ return <>
97
+ <tfoot>
98
+ {trs}
99
+ </tfoot>
100
+ </>
101
+ }
102
+
package/src/index.js CHANGED
@@ -1,9 +1,6 @@
1
- import JRSubmit from './components/JRSubmit'
2
- import JRFields from './components/JRFields/JRFields'
3
- import JRTable from './components/JRTable/JRTable'
1
+ function Test(){
2
+ return <div>Test</div>
3
+ }
4
4
  export {
5
- JRSubmit
6
- ,JRFields
7
- ,JRTable
8
-
5
+ Test
9
6
  }
@@ -1,7 +0,0 @@
1
- import JRSubmit from "../JRSubmit";
2
-
3
- export default class JRFields extends JRSubmit {
4
- render(){
5
- return 'JRFields'
6
- }
7
- }
@@ -1,14 +0,0 @@
1
- import React from "react";
2
-
3
- class Test extends React.Component {
4
- render(){
5
- return 'JRSubmit'
6
- }
7
- }
8
-
9
-
10
- // function Test(){
11
- // return <div>AAAAAAAAA</div>
12
- // }
13
-
14
- export { Test}
File without changes