aio-table 11.0.0 → 11.0.1

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/index.css CHANGED
@@ -182,7 +182,10 @@
182
182
  border: none;
183
183
  background: none;
184
184
  }
185
-
185
+ .aio-table-toolbar-button .aio-input{
186
+ border:none;
187
+ background: none;
188
+ }
186
189
 
187
190
 
188
191
  .aio-table-remove {
package/index.d.ts CHANGED
@@ -45,6 +45,7 @@ export type I_table_column<T> = {
45
45
  show?: boolean;
46
46
  pattern?: string;
47
47
  data?: any;
48
+ toggle?: boolean;
48
49
  };
49
50
  export type I_table<T> = {
50
51
  fa?: boolean;
package/index.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { createContext, createRef, Fragment, useContext, useEffect, useRef, useState } from "react";
12
- import AIOInput from "aio-input";
12
+ import AIOInput, { AISelect } from "aio-input";
13
13
  import * as UT from 'aio-utils';
14
14
  import usePopup from "aio-popup";
15
15
  import AIODate from "aio-date";
@@ -24,6 +24,7 @@ const AIOTable = (props) => {
24
24
  const [searchColumns, setSearchColumns] = useState([]);
25
25
  const [excelColumns, setExcelColumns] = useState([]);
26
26
  const [filterColumns, setFilterColumns] = useState([]);
27
+ const [toggleColumns, setToggleColumns] = useState([]);
27
28
  const filterColumnsRef = useRef(filterColumns);
28
29
  filterColumnsRef.current = filterColumns;
29
30
  const rowsIndexDicRef = useRef({});
@@ -108,12 +109,13 @@ const AIOTable = (props) => {
108
109
  });
109
110
  function getColumns() {
110
111
  let { columns = [] } = props;
111
- let searchColumns = [], excelColumns = [], filterColumns = [];
112
+ let searchColumns = [], excelColumns = [], filterColumns = [], toggleColumns = [];
112
113
  let updatedColumns = columns.map((column, i) => {
113
114
  const cellDetail = tableHook.getCellDetail({ column });
114
115
  const filterId = getColumnOption('filterId', cellDetail);
115
116
  const search = getColumnOption('search', cellDetail);
116
117
  const excel = getColumnOption('excel', cellDetail);
118
+ const toggle = getColumnOption('toggle', cellDetail);
117
119
  const id = getColumnOption('id', cellDetail);
118
120
  if (id === undefined) {
119
121
  console.error(`aio-table error => missing column id in props.columns[${i}]`);
@@ -127,6 +129,9 @@ const AIOTable = (props) => {
127
129
  if (filterId) {
128
130
  filterColumns.push(column);
129
131
  }
132
+ if (toggle) {
133
+ toggleColumns.push(column);
134
+ }
130
135
  return column;
131
136
  });
132
137
  if (props.onChangeColumns) {
@@ -135,6 +140,7 @@ const AIOTable = (props) => {
135
140
  setSearchColumns(searchColumns);
136
141
  setExcelColumns(excelColumns);
137
142
  setFilterColumns(filterColumns);
143
+ setToggleColumns(toggleColumns);
138
144
  return updatedColumns;
139
145
  }
140
146
  useEffect(() => {
@@ -253,7 +259,7 @@ const AIOTable = (props) => {
253
259
  const { gap = [0, 1] } = props;
254
260
  let attrs = UT.AddToAttrs(props.attrs, { className: ['aio-table', props.className], style: Object.assign({ gap: gap[1] }, props.style), attrs: { ref: dom } });
255
261
  const context = {
256
- rootProps: props, excelColumns, filterColumns, tableHook, sortHook, ROWS,
262
+ rootProps: props, excelColumns, filterColumns, tableHook, sortHook, ROWS, toggleColumns,
257
263
  getRowsIndexDic, add, remove, search, exportToExcel, DragColumns, getIcon, popup, getColumnOption
258
264
  };
259
265
  return (_jsxs(Provider, { value: context, children: [_jsxs("div", Object.assign({}, attrs, { children: [_jsx(TableToolbar, {}), !!props.filter &&
@@ -302,10 +308,12 @@ const TableRows = () => {
302
308
  return _jsx("div", { className: 'aio-table-rows', style: { gap: gap[1] }, children: content });
303
309
  };
304
310
  const TableToolbar = () => {
305
- let { add, exportToExcel, search, rootProps, excelColumns, getIcon, sortHook } = useProvider();
306
- let { toolbarAttrs, toolbar, onAdd, onSearch, value } = rootProps;
311
+ let { add, exportToExcel, search, rootProps, excelColumns, toggleColumns, getIcon, sortHook, getColumnOption, tableHook } = useProvider();
312
+ let { toolbarAttrs, toolbar, onAdd, onSearch, value, onChangeColumns, columns } = rootProps;
313
+ const columnsRef = useRef(columns);
314
+ columnsRef.current = columns;
307
315
  toolbarAttrs = UT.AddToAttrs(toolbarAttrs, { className: 'aio-table-toolbar' });
308
- if (!onAdd && !toolbar && !onSearch && !sortHook.sorts.length && !excelColumns.length) {
316
+ if (!onAdd && !toolbar && !onSearch && !sortHook.sorts.length && !excelColumns.length && !toggleColumns.length) {
309
317
  return null;
310
318
  }
311
319
  function getAddText() {
@@ -315,8 +323,25 @@ const TableToolbar = () => {
315
323
  }
316
324
  return typeof addText === 'function' ? addText(value) : addText;
317
325
  }
326
+ const getColumnOptionWrapper = (columnId, key) => {
327
+ const columns = columnsRef.current || [];
328
+ const column = columns.find((o) => o.id === columnId);
329
+ return getColumnOption(key, tableHook.getCellDetail({ column }));
330
+ };
318
331
  return (_jsxs("div", Object.assign({}, toolbarAttrs, { children: [toolbar && _jsx("div", { className: 'aio-table-toolbar-content', children: typeof toolbar === 'function' ? toolbar() : toolbar }), !!onSearch &&
319
- _jsx("div", { className: 'aio-table-search', children: _jsx(AIOInput, { type: 'text', onChange: (value) => search(value), after: getIcon('mdiMagnify', 0.7) }) }), sortHook.renderSortButton(), !!excelColumns.length && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => exportToExcel(), children: getIcon('mdiFileExcel', 0.8) }), !!onAdd && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => add(), children: getAddText() })] })));
332
+ _jsx("div", { className: 'aio-table-search', children: _jsx(AIOInput, { type: 'text', onChange: (value) => search(value), after: getIcon('mdiMagnify', 0.7) }) }), sortHook.renderSortButton(), !!excelColumns.length && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => exportToExcel(), children: getIcon('mdiFileExcel', 0.8) }), !!toggleColumns.length &&
333
+ _jsx("div", { className: 'aio-table-toolbar-button', children: _jsx(AISelect, { text: getIcon('mdiEye', 0.8), hideTags: true, options: toggleColumns, caret: false, option: {
334
+ text: (column) => getColumnOptionWrapper(column.id, 'title'),
335
+ checked: (column) => getColumnOptionWrapper(column.id, 'show'),
336
+ onClick: (column) => {
337
+ if (!onChangeColumns) {
338
+ return;
339
+ }
340
+ const columns = columnsRef.current || [];
341
+ onChangeColumns(columns.map((o) => column.id === o.id ? Object.assign(Object.assign({}, o), { show: !getColumnOptionWrapper(o.id, 'show') }) : o));
342
+ },
343
+ close: () => false
344
+ } }) }), !!onAdd && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => add(), children: getAddText() })] })));
320
345
  };
321
346
  const TableHeader = () => {
322
347
  let { rootProps, getColumnOption, tableHook } = useProvider();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-table",
3
- "version": "11.0.0",
3
+ "version": "11.0.1",
4
4
  "description": "all in one table. tree mode , simple mode , tree mode, gantt mode , groupby mode, freeze mode.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",