jrs-react 1.2.14 → 1.2.16

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jrs-react",
3
- "version": "1.2.14",
3
+ "version": "1.2.16",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.es.js",
package/public/data.json CHANGED
@@ -16,4 +16,14 @@
16
16
  }
17
17
  ,"father":"Lai"
18
18
  ,"mother":"Wong"
19
+
20
+ ,"checkbox": [
21
+ 1,
22
+ 3,
23
+ 5
24
+ ],
25
+ "select": [
26
+ 2
27
+ ]
28
+ ,"radio":1
19
29
  }
package/public/list.json CHANGED
@@ -1,6 +1,7 @@
1
1
  [
2
2
  {
3
3
  "name":"Joren"
4
+ ,"id":1
4
5
  ,"phone":"097459999"
5
6
  ,"address":{
6
7
  "no":"23"
@@ -10,6 +11,7 @@
10
11
  }
11
12
  ,{
12
13
  "name":"John"
14
+ ,"id":2
13
15
  ,"phone":"0124873737"
14
16
  ,"address":{
15
17
  "no":"36"
@@ -18,7 +20,8 @@
18
20
  }
19
21
  }
20
22
  ,{
21
- "name":"John"
23
+ "name":"Oliver"
24
+ ,"id":3
22
25
  ,"phone":"0124873737"
23
26
  ,"address":{
24
27
  "no":"36"
@@ -27,7 +30,8 @@
27
30
  }
28
31
  }
29
32
  ,{
30
- "name":"John"
33
+ "name":"Harry"
34
+ ,"id":4
31
35
  ,"phone":"0124873737"
32
36
  ,"address":{
33
37
  "no":"36"
@@ -36,7 +40,8 @@
36
40
  }
37
41
  }
38
42
  ,{
39
- "name":"John"
43
+ "name":"Jacob"
44
+ ,"id":5
40
45
  ,"phone":"0124873737"
41
46
  ,"address":{
42
47
  "no":"36"
@@ -45,7 +50,8 @@
45
50
  }
46
51
  }
47
52
  ,{
48
- "name":"John"
53
+ "name":"Charlie"
54
+ ,"id":6
49
55
  ,"phone":"0124873737"
50
56
  ,"address":{
51
57
  "no":"36"
@@ -54,7 +60,8 @@
54
60
  }
55
61
  }
56
62
  ,{
57
- "name":"John"
63
+ "name":"Thomas"
64
+ ,"id":7
58
65
  ,"phone":"0124873737"
59
66
  ,"address":{
60
67
  "no":"36"
@@ -63,7 +70,8 @@
63
70
  }
64
71
  }
65
72
  ,{
66
- "name":"John"
73
+ "name":"George"
74
+ ,"id":8
67
75
  ,"phone":"0124873737"
68
76
  ,"address":{
69
77
  "no":"36"
@@ -72,7 +80,8 @@
72
80
  }
73
81
  }
74
82
  ,{
75
- "name":"John"
83
+ "name":"Oscar"
84
+ ,"id":9
76
85
  ,"phone":"0124873737"
77
86
  ,"address":{
78
87
  "no":"36"
@@ -81,7 +90,8 @@
81
90
  }
82
91
  }
83
92
  ,{
84
- "name":"John"
93
+ "name":"James"
94
+ ,"id":10
85
95
  ,"phone":"0124873737"
86
96
  ,"address":{
87
97
  "no":"36"
@@ -90,7 +100,8 @@
90
100
  }
91
101
  }
92
102
  ,{
93
- "name":"John"
103
+ "name":"William"
104
+ ,"id":11
94
105
  ,"phone":"0124873737"
95
106
  ,"address":{
96
107
  "no":"36"
@@ -99,7 +110,8 @@
99
110
  }
100
111
  }
101
112
  ,{
102
- "name":"John"
113
+ "name":"Emily"
114
+ ,"id":12
103
115
  ,"phone":"0124873737"
104
116
  ,"address":{
105
117
  "no":"36"
@@ -108,7 +120,8 @@
108
120
  }
109
121
  }
110
122
  ,{
111
- "name":"John"
123
+ "name":"Isla"
124
+ ,"id":13
112
125
  ,"phone":"0124873737"
113
126
  ,"address":{
114
127
  "no":"36"
package/src/app/App.jsx CHANGED
@@ -7,10 +7,11 @@ import AxiosApp from './axios/AxiosApp'
7
7
  import AlertApp from './alert/AlertApp'
8
8
  import { po } from '../components/JRUtils'
9
9
  import TestApp from './test'
10
+ import InputApp from './input/InputApp'
10
11
 
11
12
  function App() {
12
13
  const apps={
13
- TableApp,FieldsApp,WindowApp,AxiosApp,AlertApp,TestApp
14
+ TableApp,FieldsApp,WindowApp,AxiosApp,AlertApp,InputApp,TestApp
14
15
  }
15
16
  return <BrowserRouter>
16
17
  {
@@ -24,14 +25,8 @@ function App() {
24
25
  return <Route path={`/${key}`} element={<App/>} key={key}/>
25
26
  })
26
27
  }
27
-
28
- <Route path="/table" element={<TableApp/>}/>
29
- <Route path="/fields" element={<FieldsApp/>}/>
30
- <Route path="/window" element={<WindowApp/>}/>
31
- <Route path="/axios" element={<AxiosApp/>}/>
32
- <Route path="/alert" element={<AlertApp/>}/>
33
28
  </Routes>
34
- <div id='play' style={{width:'500px',height:'500px',border:'1px solid gray'}}> </div>
29
+ {/* <div id='play' style={{width:'500px',height:'500px',border:'1px solid gray'}}> </div> */}
35
30
  </BrowserRouter>
36
31
  }
37
32
 
@@ -16,12 +16,16 @@ const StyledJRFields=styled(JRFields)`
16
16
  export default function FieldsApp() {
17
17
  return <>
18
18
  <JRFields
19
+ initValue={{
20
+ checkbox:[1,3,5]
21
+ ,select:[2]
22
+ }}
19
23
  {...devFields}
20
24
  {...withSomeButton}
21
25
  open={true}
22
- popup={true}
26
+ popup={false}
23
27
  width={900}
24
- height={800}
28
+ // height={800}
25
29
  title={'Fields'}
26
30
  />
27
31
  </>
@@ -5,6 +5,8 @@ import JRText from "../../components/JRInput/JRText";
5
5
  import JRTable from "../../components/JRTable/JRTable";
6
6
  import { po } from "../../components/JRUtils";
7
7
  import styled from "styled-components";
8
+ import JRCheckbox from "../../components/JRInput/JRCheckbox";
9
+ import { JRRadio } from "../../components/JRInput/JRRadio";
8
10
 
9
11
  export const fieldsConfig={
10
12
  popup:true
@@ -208,11 +210,45 @@ export const normalFields={
208
210
  }
209
211
  ]
210
212
  }
213
+ ,{
214
+ name:'select'
215
+ ,label:'Select'
216
+ ,type:JRSelect
217
+ ,valueName:'id'
218
+ ,get:{
219
+ url:'list.json'
220
+ ,autoRun:true
221
+ }
222
+ ,multiple:true
223
+ ,required:true
224
+ }
225
+ ,{}
226
+ ,{
227
+ name:'isMember'
228
+ ,label:'Is member'
229
+ ,type:JRCheckbox
230
+ ,option:{
231
+ value:1
232
+ ,label:'yes'
233
+ }
234
+ }
235
+ ,{
236
+ name:'checkbox'
237
+ ,label:'Checkbox'
238
+ ,type:JRCheckbox
239
+ ,valueName:'id'
240
+ ,get:{
241
+ url:'list.json'
242
+ ,autoRun:true
243
+ }
244
+ ,required:true
245
+ }
211
246
  ]
212
247
  ,cols:2
213
248
  ,style:{
214
249
  border:'1px solid gray'
215
250
  }
251
+
216
252
  }
217
253
  ////////////////////////////////////////////////////////////
218
254
  const StyledDiv=styled.div`
@@ -251,7 +287,7 @@ export const withSomeButton={
251
287
  onClick={()=>{
252
288
  this.validate()
253
289
  .then(()=>{
254
-
290
+ alert('is valid')
255
291
  })
256
292
  .catch(()=>{
257
293
 
@@ -305,7 +341,7 @@ export const labelLayout={
305
341
  export const devFields={
306
342
  get:{
307
343
  url:'data.json'
308
- ,autoRun:true
344
+ // ,autoRun:true
309
345
  ,callback(success,res){
310
346
  po('success,data',success,res)
311
347
  // setTimeout(()=>{
@@ -357,7 +393,68 @@ export const devFields={
357
393
  ,border:'1px solid black'
358
394
  ,borderRadius: '3px'
359
395
  }
396
+ ,colSpan:2
397
+ }
398
+ ,{
399
+ name:'isMember'
400
+ ,label:'Is member'
401
+ ,type:JRCheckbox
402
+ ,options:{
403
+ value:1
404
+ ,label:'yes'
405
+ }
406
+ ,required:true
407
+ }
408
+ ,{
409
+ name:'selectSingle'
410
+ ,label:'Select'
411
+ ,type:JRSelect
412
+ ,valueName:'id'
413
+ ,labelName:'name'
414
+ ,get:{
415
+ url:'list.json'
416
+ ,autoRun:true
417
+ }
418
+ ,required:true
419
+ }
420
+ ,{
421
+ name:'checkbox'
422
+ ,label:'Checkbox'
423
+ ,type:JRCheckbox
424
+ ,valueName:'id'
425
+ ,labelName:'name'
426
+ ,get:{
427
+ url:'list.json'
428
+ ,autoRun:true
429
+ }
430
+ ,required:true
431
+ }
432
+ ,{
433
+ name:'select'
434
+ ,label:'Select'
435
+ ,type:JRSelect
436
+ ,valueName:'id'
437
+ ,labelName:'name'
438
+ ,get:{
439
+ url:'list.json'
440
+ ,autoRun:true
441
+ }
442
+ ,multiple:true
443
+ ,required:true
444
+ }
445
+ ,{
446
+ name:'radio'
447
+ ,label:'Radio'
448
+ ,type:JRRadio
449
+ ,valueName:'id'
450
+ ,labelName:'name'
451
+ ,get:{
452
+ url:'list.json'
453
+ ,autoRun:true
454
+ }
455
+ ,multiple:true
456
+ ,required:true
360
457
  }
361
458
  ]
362
- ,cols:1
459
+ ,cols:2
363
460
  }
@@ -0,0 +1,43 @@
1
+ import { useEffect, useState } from "react";
2
+ import JRFields from "../../components/JRFields/JRFields";
3
+ import { required } from "../../components/JRFields/Validators";
4
+ import JRSelect from "../../components/JRInput/JRSelect";
5
+ export default function InputApp() {
6
+ const [selectedValue,setSelectedValue]=useState()
7
+ return <div>
8
+ <JRSelect
9
+ get={{
10
+ url:'list.json'
11
+ ,autoRun:true
12
+ }}
13
+ value={selectedValue}
14
+ onChange={(value)=>{
15
+ setSelectedValue(value)
16
+ }}
17
+ size={6}
18
+ multiple={true}
19
+ valueName={'name'}
20
+ />
21
+ [{selectedValue}]
22
+ <JRFields
23
+ valueName={'phone'}
24
+ columns={[
25
+ {name:'name',label:'Name'
26
+ ,type:JRSelect
27
+ ,get:{
28
+ url:'list.json'
29
+ ,autoRun:true
30
+ }
31
+ ,showBlank:true
32
+ ,multiple:true
33
+ ,valueName:'name'
34
+ // ,size:5
35
+ ,required:true
36
+ }
37
+ ]}
38
+ bottom={function(){
39
+ return JSON.stringify(this.getValue())
40
+ }}
41
+ />
42
+ </div>
43
+ }
@@ -1,3 +1,4 @@
1
+ import React from "react";
1
2
  import { createRoot } from "react-dom/client"
2
3
  import { po } from "../JRUtils"
3
4
  import { useEffect, useState } from "react";
@@ -0,0 +1,49 @@
1
+ import React from "react";
2
+ import JROptions from "../JROptions";
3
+ import styled from "styled-components";
4
+ import { StyledPick } from "./JRRadio";
5
+
6
+
7
+ export default class JRCheckbox extends JROptions{
8
+ renderer(){
9
+ const {valueName='value',labelName='label'}=this.props
10
+ const multiple=Array.isArray(this.getOptions()??[])
11
+ const options=multiple?this.getOptions():[this.getOptions()]
12
+ const value=multiple?[...this.getValue()??[]]:this.getValue()
13
+ const checked=multiple
14
+ ?(checkValue)=>{
15
+ return value.indexOf(checkValue)>-1
16
+ }
17
+ :(checkValue)=>{
18
+ return checkValue==value
19
+ }
20
+ return <StyledPick className={'jr-checkbox'}>
21
+ {
22
+ options?.map((record,key)=>{
23
+ const recordValue=record[valueName]
24
+ return <label key={key}>
25
+ <input
26
+ type={'checkbox'}
27
+ multiple={multiple}
28
+ value={recordValue}
29
+ checked={checked(recordValue)}
30
+ onChange={multiple
31
+ ?(e)=>{
32
+ if(e.target.checked){
33
+ value.push(recordValue)
34
+ }else{
35
+ value.splice(value.indexOf(recordValue),1)
36
+ }
37
+ this.setValue(value.length?value:null)
38
+ }
39
+ :(e)=>{
40
+ this.setValue(e.target.checked?recordValue:null)
41
+ }
42
+ }
43
+ />{record[labelName]}
44
+ </label>
45
+ })
46
+ }
47
+ </StyledPick>
48
+ }
49
+ }
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ import JROptions from "../JROptions";
3
+ import styled from "styled-components";
4
+
5
+
6
+ export const StyledPick=styled.div`
7
+ >label{
8
+ white-space: nowrap;
9
+ display: inline-flex;
10
+ align-items: center;
11
+ height: 30px;
12
+ padding-right: 12px;
13
+ }
14
+ `
15
+ export class JRRadio extends JROptions{
16
+ renderer(){
17
+ const {valueName='value',labelName='label',onChange,...props}=this.props
18
+ const options=this.getOptions()
19
+ return <StyledPick className={'jr-radio'}>
20
+ {
21
+ options?.map((record,key)=>{
22
+ const recordValue=record[valueName]
23
+ return <label key={key}>
24
+ <input
25
+ type={'radio'}
26
+ name={'radio'}
27
+ checked={this.getValue()==recordValue}
28
+ onClick={(e)=>{
29
+ if(this.getValue()==recordValue){
30
+ this.setValue(null)
31
+ e.target.checked=false
32
+ }else{
33
+ this.setValue(recordValue)
34
+ }
35
+ }}
36
+ />
37
+ {record[labelName]}
38
+ </label>
39
+ })
40
+ }
41
+ </StyledPick>
42
+ }
43
+ }
@@ -1,19 +1,64 @@
1
1
  import React from "react";
2
2
  import { po } from "../JRUtils";
3
3
  import JRInput from "./JRInput";
4
+ import JROptions from "../JROptions";
5
+ import styled from "styled-components";
4
6
 
5
- export default class JRSelect extends JRInput{
6
- input(){
7
- return <select value={this.props.value}
8
- style={{
9
- height: '30px'
10
- ,width: '100%'
11
- }}
7
+ const StyledOption=styled.option`
8
+ `
9
+ const StyledSelect=styled.select`
10
+ ${({size,multiple})=>`${size==1 || (size==undefined && multiple!=true)?'height:30px;':''}`}
11
+ width: 100%;
12
+
13
+ option{
14
+ padding: 4px;
15
+ height: 25px;
16
+ display: flex;
17
+ align-items: center;
18
+ }
19
+ `
20
+ export default class JRSelect extends JROptions{
21
+ renderer(){
22
+ const {showBlank,valueName='id',labelName='name',multiple,size}=this.props
23
+ const options=[...this.getOptions()??[]]
24
+ if(multiple!=true && showBlank!=false)options.unshift({[valueName]:'',[labelName]:''})
25
+ return <>
26
+ <StyledSelect
27
+ value={this.getValue()??(multiple?[]:'')}
28
+ className={'jr-select'}
12
29
  onChange={(e)=>{
13
- this.setValue(e.target.value)
30
+ if(multiple){
31
+ const selectedIndex=[...e.target.selectedOptions].map((option)=>option.index)
32
+ this.setValue(selectedIndex.length
33
+ ?selectedIndex.map((index)=>options[index][valueName])
34
+ :null
35
+ )
36
+ }else{
37
+ const selectedIndex=e.target.selectedOptions[0].index
38
+ this.setValue(selectedIndex?options[selectedIndex][valueName]:null)
39
+ }
14
40
  }}
41
+ size={size}
42
+ multiple={multiple}
15
43
  >
16
- <option value={1}>A</option>
17
- </select>
44
+ {
45
+ options.map((record,key)=>{
46
+ const props={
47
+ value:record[valueName]
48
+ ,key:key
49
+ }
50
+ if(
51
+ (multiple && this.getValue()?.indexOf(record[valueName])>-1)
52
+ || this.getValue()==record[valueName]
53
+ ){
54
+ props.className='selected'
55
+ }
56
+ return <StyledOption {...props}>
57
+ {record[labelName]}
58
+ </StyledOption>
59
+ })
60
+ }
61
+ </StyledSelect>
62
+ </>
18
63
  }
19
64
  }
@@ -0,0 +1,24 @@
1
+ import JRSubmit from "./JRSubmit"
2
+
3
+ export default class JROptions extends JRSubmit {
4
+ get optionsFrom(){
5
+ return this.props.options===undefined?'state':'props'
6
+ }
7
+ setOptions(options){
8
+ if(this.props.setOptions){
9
+ this.props.setOptions(options)
10
+ }else{
11
+ this.setState({options: options})
12
+ }
13
+ }
14
+ getOptions(){
15
+ return this[this.optionsFrom]?.options
16
+ }
17
+ setRes(isSuccess,response,config){
18
+ if (isSuccess ) {
19
+ const options=config.formatValue?.bind(this)(response.data)??response.data
20
+ response.data=options
21
+ this.setOptions(options)
22
+ }
23
+ }
24
+ }
@@ -142,6 +142,8 @@ export default class JRSubmit extends React.Component {
142
142
  const fullnamList=fullname.split('.')
143
143
  return this.#getValueByName(fullnamList,this[this.from]?.value)
144
144
  }else{
145
+ // po('ssssssssssssssssssssssssssssssssssssssssss')
146
+ // 忘記為甚麼這樣寫了 XDD
145
147
  return flexType(this[this.from]?.value,this,null,null)
146
148
  }
147
149
  }
@@ -2,40 +2,8 @@ import React from 'react'
2
2
  import styled from "styled-components";
3
3
  import JRSubmit from './JRSubmit'
4
4
 
5
- const StyledJRFrame=styled.div`
6
- display:flex;
7
- flex:1;
8
- overflow:hidden;
9
-
10
- > *{
11
- Xborder:1px solid gray;
12
- }
13
- >main{
14
- display:flex;
15
- flex:1;
16
- overflow:overlay;
17
- flex-direction: column;
18
- > *{
19
- XXborder:1px solid gray;
20
- min-height:30px;
21
- }
22
-
23
- >header{
24
- XXborder:1px solid red;
25
- XXoverflow: overlay;
26
- }
27
- >main{
28
- display:flex;
29
- flex:1;
30
- overflow:hidden;
31
- }
32
- >footer{
33
- XXborder:1px solid blue;
34
- overflow: overlay;
35
- }
36
-
37
- }
38
-
5
+ const StyledJRTest=styled.div`
6
+
39
7
  `
40
8
 
41
9
  const FreeType=({tag:Tag,config,me,className})=>{
@@ -51,19 +19,8 @@ const FreeType=({tag:Tag,config,me,className})=>{
51
19
 
52
20
  export default class JRTestReact extends JRSubmit {
53
21
  renderer(){
54
- return <StyledJRFrame style={this.props.style} className={`${this.props.className} jr-frame`} >
55
- <FreeType tag='div' config={this.props.start} me={this} className={'start'}/>
56
- <main>
57
- <FreeType tag='header' config={this.props.top} me={this}/>
58
- <main>
59
- <FreeType tag='div' config={this.props.left} me={this} className={'left'}/>
60
- {this.renderMe()}
61
- <FreeType tag='div' config={this.props.right} me={this} className={'right'}/>
62
- </main>
63
- <FreeType tag='footer' config={this.props.bottom} me={this}/>
64
- </main>
65
- <FreeType tag='div' config={this.props.end} me={this} className={'end'}/>
66
- </StyledJRFrame>
22
+ return <StyledJRTest style={this.props.style} className={`${this.props.className} jr-frame`} >
23
+ </StyledJRTest>
67
24
  }
68
25
  renderMe(){
69
26
  return <div style={{flex:1}}>Render me</div>
@@ -3,10 +3,7 @@ import JRFrame from "../JRFrame/JRFrame";
3
3
  import styled from "styled-components";
4
4
  import TitleBar from "./TitleBar";
5
5
  import { po } from "../JRUtils";
6
- import Slider from "./Slider";
7
6
  import Sliders from "./Slider";
8
- import Fields from "../JRFields/JRFields";
9
- import JRText from "../JRInput/JRText";
10
7
  import style from './Style.module.css'
11
8
 
12
9