@seanyeh77/ui 0.7.1 → 0.8.0

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.d.ts CHANGED
@@ -520,6 +520,9 @@ interface ColumnBase<R extends Row> {
520
520
  mobile?: 'title' | 'status' | 'hide';
521
521
  /** Long text: 2 lines with 「顯示全部」 on phone cards, one line with an ellipsis on desktop. */
522
522
  long?: boolean;
523
+ /** Hidden at first; still listed in the 「欄位」 menu, where people can turn it on. Back to hidden on a new
524
+ * `resetKey`. Not for the first column, which is always shown. Default false. */
525
+ hidden?: boolean;
523
526
  }
524
527
  /** A column shows a field of the row (key is checked against the row type), or computes its cell with render (any key). */
525
528
  type DataTableColumn<R extends Row = Record<string, unknown>> = ColumnBase<R> & ({
package/dist/index.js CHANGED
@@ -2928,7 +2928,7 @@ function DataTable(p) {
2928
2928
  const [q, setQ] = React.useState(() => fromUrl().q);
2929
2929
  const [values, setValues] = React.useState(() => fromUrl().values);
2930
2930
  const [view, setView] = React.useState(p.views?.[0]?.id ?? null);
2931
- const [hidden, setHidden] = React.useState({});
2931
+ const [toggled, setToggled] = React.useState({});
2932
2932
  const [sel, setSel] = React.useState({});
2933
2933
  const [sumVal, setSumVal] = React.useState("all");
2934
2934
  const [resetKey, setResetKey] = React.useState(p.resetKey);
@@ -2944,6 +2944,7 @@ function DataTable(p) {
2944
2944
  key: null,
2945
2945
  dir: "desc"
2946
2946
  });
2947
+ setToggled({});
2947
2948
  }
2948
2949
  const valuesKey = JSON.stringify(values);
2949
2950
  React.useEffect(() => {
@@ -2951,7 +2952,11 @@ function DataTable(p) {
2951
2952
  }, [valuesKey, q]);
2952
2953
  devWarn(cols.some((c) => c.format === "percent" && !c.unit), "DataTable", "format: 'percent' sets 1 decimal and shows no % sign; add unit: '%' to that column.");
2953
2954
  devWarn(rows.length > 1 && rows.every((r) => get(r, "id") == null) && selectable, "DataTable", "rows have no id, so a selection follows the position, not the row. Add an id to each row.");
2954
- const shownCols = cols.filter((c, i) => i === 0 || !hidden[c.key]);
2955
+ devWarn(!!cols[0]?.hidden, "DataTable", "the first column is always shown, so its hidden: true does nothing. Move the column, or drop hidden.");
2956
+ devWarn((p.columnMenu === false || cols.length <= 2) && cols.some((c, i) => i > 0 && c.hidden), "DataTable", "a column has hidden: true but there is no 「欄位」 menu (columnMenu is false, or the table has 2 columns or fewer), so nobody can turn it on. Turn the menu on, or leave the column out.");
2957
+ const hidden = {};
2958
+ cols.forEach((c, i) => hidden[c.key] = i > 0 && (toggled[c.key] ?? !!c.hidden));
2959
+ const shownCols = cols.filter((c) => !hidden[c.key]);
2955
2960
  const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
2956
2961
  const bodyRef = React.useRef(null);
2957
2962
  const rowEls = React.useRef({});
@@ -3347,8 +3352,8 @@ function DataTable(p) {
3347
3352
  p.columnMenu !== false && cols.length > 2 ? /* @__PURE__ */ jsx(ColumnMenu, {
3348
3353
  cols,
3349
3354
  hidden,
3350
- onToggle: (k) => setHidden({
3351
- ...hidden,
3355
+ onToggle: (k) => setToggled({
3356
+ ...toggled,
3352
3357
  [k]: !hidden[k]
3353
3358
  })
3354
3359
  }) : null