ywana-core8 0.0.393 → 0.0.394

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": "ywana-core8",
3
- "version": "0.0.393",
3
+ "version": "0.0.394",
4
4
  "description": "ywana-core8",
5
5
  "author": "Ernesto Roldan Garcia",
6
6
  "license": "MIT",
@@ -246,7 +246,7 @@ export const StringEditor = ({ field, value = '', onChange, content, outlined })
246
246
 
247
247
  function renderFormat(format, options) {
248
248
  switch (format) {
249
- case FORMATS.COLOR: return <ColorField id={id} onChange={change} />
249
+ case FORMATS.COLOR: return <ColorField id={id} onChange={change} value={value}/>
250
250
  case FORMATS.HTML: return <Editor id={id} value={value} onChange={change} content={content} />
251
251
  case FORMATS.DATE: return <TextField outlined={outlined} id={id} type="date" label={label} value={value} onChange={change} readOnly={!editable} />
252
252
  default:
@@ -7,7 +7,6 @@ const ColorFieldTest = (prop) => {
7
7
  })
8
8
 
9
9
  function change(id, value) {
10
- console.log(id, value)
11
10
  const next = Object.assign({}, form, { [id] : value })
12
11
  setForm(next)
13
12
  }
@@ -54,7 +54,7 @@ export const TextField = (props) => {
54
54
  return (
55
55
  <div className={`${style}`} onClick={onClick}>
56
56
  <input id={id} type={type} placeholder={placeholder} value={value} required onChange={change} onKeyDown={onKeyPress} onFocus={focus} onBlur={blur} readOnly={readOnly} />
57
- {canClear && value && value.length > 0 ? <Icon icon="close" clickable size="small" action={clear} /> : null }
57
+ {canClear && value && value.length > 0 ? <Icon icon="close" clickable size="small" action={clear} /> : null}
58
58
  <span className="bar"></span>
59
59
  {label ? <label>{labelTxt}</label> : null}
60
60
  </div>
@@ -65,7 +65,7 @@ export const TextField = (props) => {
65
65
  /**
66
66
  * Text Area
67
67
  */
68
- export const TextArea = (props) => {
68
+ export const TextArea = (props) => {
69
69
 
70
70
  const site = useContext(SiteContext)
71
71
  const { id, type = 'text', label, placeholder, value, outlined, readOnly = false, canClear = true, onChange, onEnter, onClick } = props
@@ -105,7 +105,7 @@ export const TextField = (props) => {
105
105
  return (
106
106
  <div className={`${style}`} onClick={onClick}>
107
107
  <textarea id={id} placeholder={placeholder} value={value} required onChange={change} onKeyDown={onKeyPress} onFocus={focus} readOnly={readOnly} />
108
- {canClear && value && value.length > 0 ? <Icon icon="close" clickable size="small" action={clear} /> : null }
108
+ {canClear && value && value.length > 0 ? <Icon icon="close" clickable size="small" action={clear} /> : null}
109
109
  <span className="bar"></span>
110
110
  {label ? <label>{labelTxt}</label> : null}
111
111
  </div>
@@ -119,11 +119,12 @@ export const TextField = (props) => {
119
119
  export const DropDown = (props) => {
120
120
 
121
121
  const site = useContext(SiteContext)
122
- const { id, options = [], value, onChange, predictive = false, readOnly = false } = props
122
+ const { id, options = [], value, onChange, predictive = false, readOnly = false, verbose = true, onBlur } = props
123
123
  const [open, setOpen] = useState(false)
124
124
  const [label, setLabel] = useState()
125
125
 
126
126
  useEffect(() => {
127
+ console.log('DD change value', label)
127
128
  if (Array.isArray(options)) {
128
129
  const option = options.find(option => option.value === value)
129
130
  const label = option ? option.label : ""
@@ -153,14 +154,14 @@ export const DropDown = (props) => {
153
154
  function select(event) {
154
155
  const next = event.target.getAttribute("value")
155
156
  const option = options.find(option => option.value === next)
156
- if (onChange) onChange(id, next)
157
- setLabel(option.label)
158
157
  setOpen(false)
158
+ const label = verbose ? option.label : ""
159
+ setLabel(label)
160
+ if (onChange) onChange(id, next)
159
161
  }
160
162
 
161
163
  function blur() {
162
- console.log("BLUR DD")
163
- site.clearFocus()
164
+ if (onBlur) onBlur()
164
165
  }
165
166
 
166
167
  function renderOptions() {
@@ -177,8 +178,8 @@ export const DropDown = (props) => {
177
178
 
178
179
  return (
179
180
  <div className="dropdown">
180
- <TextField {...props} onClick={toggle} value={label} onChange={change} onBlur={blur} readOnly={!predictive}/>
181
- {!readOnly ? <Icon icon="expand_more" clickable size="small" action={toggle} /> : null }
181
+ <TextField {...props} onClick={toggle} value={label} onChange={change} onBlur={blur} readOnly={!predictive} />
182
+ {!readOnly ? <Icon icon="expand_more" clickable size="small" action={toggle} /> : null}
182
183
  {renderOptions()}
183
184
  </div>
184
185
  )
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react'
2
- import { DropDown, TextField, TextArea } from '.'
2
+ import { DropDown, TextField, TextArea, TokenField } from '.'
3
3
  import { Wrapper } from '../../__reactpreview__/Wrapper'
4
4
 
5
5
  const TextFieldTest = (prop) => {
@@ -22,12 +22,12 @@ const TextFieldTest = (prop) => {
22
22
 
23
23
  return (
24
24
  <>
25
+ <TokenField id="token1" label="Tokens" onChange={change} options={options}/>
25
26
  <TextField id="name" label="Name" value={form.name} onChange={change} />
26
27
  <DropDown id="gender1" label="Dropdown 1" value={form.gender1} onChange={change} options={options} predictive={false}/>
27
28
  <DropDown id="gender2" label="Dropdown 2" value={form.gender2} onChange={change} options={options} predictive={true}/>
28
29
  <TextArea id="text1" label="Text 1" value={form.text1} onChange={change} />
29
30
  <TextField id="date1" type="DATE" label="Date" value={form.date1} onChange={change} />
30
- <TextField id="color1" type="COLOR" label="Color" value={form.date1} onChange={change} />
31
31
  </>
32
32
  )
33
33
  }
@@ -1,11 +1,11 @@
1
1
  .tokenField {
2
+ max-height: 3.8rem;
3
+ min-height: 3.8;
2
4
  position: relative;
3
- border: solid 1px var(--divider-color);
5
+ border-bottom: solid 1px var(--divider-color);
4
6
  display: flex;
5
7
  align-items: center;
6
- border-radius: .3rem;
7
- padding: 1rem;
8
- margin: 1rem 0;
8
+ margin: 1rem 0 0 0;
9
9
  display: flex;
10
10
  flex-wrap: wrap;
11
11
  }
@@ -19,7 +19,8 @@
19
19
  color: var(--text-color-light)
20
20
  }
21
21
 
22
- .tokenField input {
22
+ .tokenField input,
23
+ .tokenField .dropdown {
23
24
  border: 0px;
24
25
  padding: .5rem 0;
25
26
  font-size: 1rem;
@@ -1,15 +1,17 @@
1
1
  import React, { useEffect, useRef, useState } from 'react'
2
2
  import { Icon } from './icon';
3
3
  import { Text } from './text';
4
+ import { DropDown } from './textfield';
4
5
  import './tokenfield.css'
5
6
 
6
7
  /**
7
8
  * Token Field
8
9
  */
9
- export const TokenField = ({ id, label, init = [], readOnly, onChange }) => {
10
+ export const TokenField = ({ id, label, init = [], readOnly, options, onChange }) => {
10
11
  const mounted = useRef(false)
11
12
  const [value, setValue] = useState()
12
13
  const [tokens, setTokens] = useState(init)
14
+ const [open, setOpen] = useState(false)
13
15
 
14
16
  useEffect(() => {
15
17
  if (mounted.current) {
@@ -32,6 +34,12 @@ export const TokenField = ({ id, label, init = [], readOnly, onChange }) => {
32
34
  setValue(value)
33
35
  }
34
36
 
37
+ function changeDropDown(id, value) {
38
+ const next = tokens.concat(value)
39
+ setTokens(next)
40
+ setValue('xxx')
41
+ }
42
+
35
43
  function onEnter(event) {
36
44
  if (event.key === 'Enter') {
37
45
  event.preventDefault()
@@ -42,7 +50,7 @@ export const TokenField = ({ id, label, init = [], readOnly, onChange }) => {
42
50
  setValue('')
43
51
  }
44
52
 
45
- if (value === '' && tokens.length> 0 && event.key === 'Backspace') {
53
+ if (value === '' && tokens.length > 0 && event.key === 'Backspace') {
46
54
  const next = tokens.slice(0, -1)
47
55
  setTokens(next)
48
56
  }
@@ -51,10 +59,14 @@ export const TokenField = ({ id, label, init = [], readOnly, onChange }) => {
51
59
  return (
52
60
  <div className='tokenField'>
53
61
  <label>{label}</label>
54
- {tokens.map((text, index) => (
55
- <Token text={text} onDelete={() => remove(index)} />
56
- ))}
57
- <input type='text' value={value} onChange={change} onKeyDown={onEnter} readOnly={readOnly}/>
62
+
63
+ {tokens.map((text, index) => <Token text={text} onDelete={() => remove(index)} />)}
64
+
65
+ {options ? (
66
+ <DropDown onChange={changeDropDown} options={options} predictive={true} verbose={false} />
67
+ ) : (
68
+ <input type='text' value={value} onChange={change} onKeyDown={onEnter} readOnly={readOnly} />)
69
+ }
58
70
  </div>
59
71
  )
60
72
  }
@@ -68,7 +80,7 @@ const Token = ({ text, onDelete }) => {
68
80
  <Text use='caption' tag='div'>
69
81
  {text}
70
82
  </Text>
71
- <Icon icon='close' clickable action={onDelete} size="small"/>
83
+ <Icon icon='close' clickable action={onDelete} size="small" />
72
84
  </div>
73
85
  )
74
86
  }