ywana-core8 0.0.508 → 0.0.509
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/dist/index.cjs +48 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +48 -3
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +48 -3
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/html/table.js +39 -16
package/package.json
CHANGED
package/src/html/table.js
CHANGED
@@ -13,7 +13,7 @@ const isFunction = value => value && (Object.prototype.toString.call(value) ===
|
|
13
13
|
*/
|
14
14
|
export const DataTable = (props) => {
|
15
15
|
|
16
|
-
const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined, expanded = false, className} = props
|
16
|
+
const { columns = [], rows = [], onRowSelection, onSort, onCheckAll, editable, outlined, expanded = false, className } = props
|
17
17
|
const [sortDir, setSortDir] = useState({})
|
18
18
|
const [allChecked, setAllChecked] = useState(false)
|
19
19
|
|
@@ -83,12 +83,12 @@ export const DataTable = (props) => {
|
|
83
83
|
<tr>
|
84
84
|
{columns.map(({ id, label, type, item, sortable }) => {
|
85
85
|
const sort = sortDir[id] ? sortDir[id] : null
|
86
|
-
const [rowspan, colspan] = type === TYPES.ENTITY ? [1, Object.values(item).filter(v=>v.column===true).length] : [2, 1]
|
86
|
+
const [rowspan, colspan] = type === TYPES.ENTITY ? [1, Object.values(item).filter(v => v.column === true).length] : [2, 1]
|
87
87
|
return (
|
88
88
|
<th key={id} rowSpan={rowspan} colSpan={colspan}>
|
89
89
|
<div>
|
90
90
|
{id === "checked" ? <CheckBox onChange={checkAll} value={allChecked} /> : <Text key={`th_${id}`}>{label}</Text>}
|
91
|
-
{sortable ? <Icon icon="expand_less" size="small" clickable action={() => changeSort(id)}/> : null}
|
91
|
+
{sortable ? <Icon icon="expand_less" size="small" clickable action={() => changeSort(id)} /> : null}
|
92
92
|
</div>
|
93
93
|
</th>
|
94
94
|
)
|
@@ -127,7 +127,7 @@ export const DataTable = (props) => {
|
|
127
127
|
const DataTableRow = (props) => {
|
128
128
|
|
129
129
|
const { row, columns = [], onSelect, editable, expanded = false } = props
|
130
|
-
const {
|
130
|
+
const { className } = row
|
131
131
|
const [isInfoOpen, toggleInfo] = useState(expanded)
|
132
132
|
const infoIcon = isInfoOpen ? 'expand_more' : 'expand_less'
|
133
133
|
|
@@ -180,7 +180,7 @@ const DataTableCell = ({ row, column, cell, editable }) => {
|
|
180
180
|
}
|
181
181
|
}
|
182
182
|
|
183
|
-
return column.type === TYPES.ENTITY ? <EntityCellViewer id={column.id} item={column.item} value={cell} /> : (
|
183
|
+
return column.type === TYPES.ENTITY ? <EntityCellViewer id={column.id} item={column.item} value={cell} format={format} /> : (
|
184
184
|
<td key={column.id} className={column.id}>{render(column.type)}</td>
|
185
185
|
)
|
186
186
|
}
|
@@ -190,10 +190,33 @@ const DataTableCell = ({ row, column, cell, editable }) => {
|
|
190
190
|
* @param {*} param0
|
191
191
|
* @returns
|
192
192
|
*/
|
193
|
-
const EntityCellViewer = ({ id, item, value }) => {
|
193
|
+
const EntityCellViewer = ({ id, item, value, format }) => {
|
194
194
|
const fields = Object.values(item).filter(field => field.column === true)
|
195
|
-
|
196
|
-
|
195
|
+
|
196
|
+
return fields.map(field => {
|
197
|
+
|
198
|
+
let text = value[field.id]
|
199
|
+
|
200
|
+
switch (format) {
|
201
|
+
case FORMATS.COLOR:
|
202
|
+
text = <input type="color" value={text} disabled />
|
203
|
+
case FORMATS.URL:
|
204
|
+
text = <a href={text} target="download" download >{text}</a>
|
205
|
+
break;
|
206
|
+
case FORMATS.IMG:
|
207
|
+
text = <img src={text} />
|
208
|
+
break;
|
209
|
+
case FORMATS.DATE:
|
210
|
+
let fecha = new Date(text)
|
211
|
+
fecha.setMinutes(fecha.getMinutes() + fecha.getTimezoneOffset() + 1)
|
212
|
+
text = fecha.toLocaleString(locale, { day: 'numeric', month: 'numeric', year: 'numeric' });
|
213
|
+
break;
|
214
|
+
case FORMATS.TIME:
|
215
|
+
text = new Date(text).toLocaleString(locale, { year: 'hour', month: 'minute', day: 'second' });
|
216
|
+
break;
|
217
|
+
}
|
218
|
+
|
219
|
+
return (<td key={field.id} className={`entity-cell ${field.id}`} >{text}</td>)
|
197
220
|
})
|
198
221
|
}
|
199
222
|
|
@@ -213,27 +236,27 @@ const StringCellViewer = ({ id, value, format, options }) => {
|
|
213
236
|
function buildOptions() {
|
214
237
|
const opts = typeof options === 'function' ? options() : options
|
215
238
|
return opts
|
216
|
-
|
217
|
-
|
239
|
+
}
|
240
|
+
|
218
241
|
const option = options ? buildOptions().find(o => o.value === value) : null
|
219
242
|
let text = option ? option.label : value
|
220
243
|
const locale = window.navigator.userLanguage || window.navigator.language;
|
221
244
|
switch (format) {
|
222
245
|
case FORMATS.COLOR:
|
223
|
-
text = <input type="color" value={text} disabled/>
|
246
|
+
text = <input type="color" value={text} disabled />
|
224
247
|
case FORMATS.URL:
|
225
248
|
text = <a href={text} target="download" download >{text}</a>
|
226
249
|
break;
|
227
|
-
case FORMATS.IMG:
|
250
|
+
case FORMATS.IMG:
|
228
251
|
text = <img src={text} />
|
229
252
|
break;
|
230
|
-
case FORMATS.DATE:
|
253
|
+
case FORMATS.DATE:
|
231
254
|
let fecha = new Date(text)
|
232
255
|
fecha.setMinutes(fecha.getMinutes() + fecha.getTimezoneOffset() + 1)
|
233
|
-
text = fecha.toLocaleString(
|
256
|
+
text = fecha.toLocaleString(locale, { day: 'numeric', month: 'numeric', year: 'numeric' });
|
234
257
|
break;
|
235
|
-
case FORMATS.TIME:
|
236
|
-
text = new Date(text).toLocaleString(
|
258
|
+
case FORMATS.TIME:
|
259
|
+
text = new Date(text).toLocaleString(locale, { year: 'hour', month: 'minute', day: 'second' });
|
237
260
|
break;
|
238
261
|
}
|
239
262
|
return (<div className="field-editor string-viewer">{text}</div>)
|