@headless-adminapp/fluent 0.0.17-alpha.40 → 0.0.17-alpha.41

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.
@@ -0,0 +1,15 @@
1
+ import { ChoiceAttribute } from '@headless-adminapp/core/attributes';
2
+ import { ViewColumn } from '@headless-adminapp/core/experience/view';
3
+ import { Schema } from '@headless-adminapp/core/schema';
4
+ import { UniqueRecord } from '../types';
5
+ interface TableCellChoiceProps {
6
+ column: ViewColumn;
7
+ schema: Schema;
8
+ record: UniqueRecord;
9
+ value: unknown;
10
+ attribute: ChoiceAttribute<string | number>;
11
+ formattedValue: string;
12
+ width: number;
13
+ }
14
+ export declare function TableCellChoice(props: TableCellChoiceProps): import("react/jsx-runtime").JSX.Element;
15
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TableCellChoice = TableCellChoice;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_components_1 = require("@fluentui/react-components");
6
+ const react_1 = require("react");
7
+ const TableCellBase_1 = require("./TableCellBase");
8
+ function isColorDark(color) {
9
+ const rgb = parseInt(color, 16);
10
+ const r = (rgb >> 16) & 0xff;
11
+ const g = (rgb >> 8) & 0xff;
12
+ const b = (rgb >> 0) & 0xff;
13
+ const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
14
+ return luma < 128;
15
+ }
16
+ function TableCellChoice(props) {
17
+ const bgColor = (0, react_1.useMemo)(() => {
18
+ var _a;
19
+ if (!props.value || !props.attribute.options) {
20
+ return;
21
+ }
22
+ return (_a = props.attribute.options.find((option) => option.value === props.value)) === null || _a === void 0 ? void 0 : _a.color;
23
+ }, [props.formattedValue]);
24
+ const color = (0, react_1.useMemo)(() => {
25
+ if (!bgColor) {
26
+ return;
27
+ }
28
+ return isColorDark(bgColor) ? '#FFFFFF' : '#000000';
29
+ }, [bgColor]);
30
+ return ((0, jsx_runtime_1.jsx)(TableCellBase_1.TableCellBase, { style: {
31
+ textOverflow: 'ellipsis',
32
+ overflow: 'hidden',
33
+ whiteSpace: 'nowrap',
34
+ width: props.width,
35
+ minWidth: props.width,
36
+ maxWidth: props.width,
37
+ }, children: (0, jsx_runtime_1.jsx)(react_components_1.Tag, { size: "small", style: { backgroundColor: bgColor, color }, children: props.formattedValue }) }));
38
+ }
@@ -0,0 +1,5 @@
1
+ import { InferredSchemaType, SchemaAttributes } from '@headless-adminapp/core/schema';
2
+ import { Data } from '@headless-adminapp/core/transport';
3
+ export type UniqueRecord = Data<InferredSchemaType<SchemaAttributes>> & {
4
+ __uuid: string;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,4 @@
1
- import { InferredSchemaType, SchemaAttributes } from '@headless-adminapp/core/schema';
2
- import { Data } from '@headless-adminapp/core/transport';
3
- export type UniqueRecord = Data<InferredSchemaType<SchemaAttributes>> & {
4
- __uuid: string;
5
- };
1
+ import { UniqueRecord } from './types';
6
2
  export declare function useTableColumns({ disableSelection, disableContextMenu, disableColumnResize, disableColumnFilter, disableColumnSort, tableWrapperRef, }: {
7
3
  disableSelection?: boolean;
8
4
  disableContextMenu?: boolean;
@@ -21,6 +21,7 @@ const GridColumnHeader_1 = require("../DataGrid/GridColumnHeader");
21
21
  const TableCell_1 = require("../DataGrid/TableCell");
22
22
  const TableCellLink_1 = require("../DataGrid/TableCell/TableCellLink");
23
23
  const ActionCell_1 = require("./ActionCell");
24
+ const TableCellChoice_1 = require("./TableCell/TableCellChoice");
24
25
  const columnHelper = (0, react_table_1.createColumnHelper)();
25
26
  const useStyles = (0, react_components_1.makeStyles)({
26
27
  selectionCell: {
@@ -74,7 +75,7 @@ function useTableColumns({ disableSelection, disableContextMenu, disableColumnRe
74
75
  const router = (0, hooks_5.useRouter)();
75
76
  const recordSetSetter = (0, hooks_4.useRecordSetSetter)();
76
77
  const openRecord = (0, useOpenRecord_1.useOpenRecord)();
77
- const { currency, dateFormats, timezone } = (0, locale_1.useLocale)();
78
+ const { currency, dateFormats, timezone, timeFormats } = (0, locale_1.useLocale)();
78
79
  const dataRef = (0, react_1.useRef)(data);
79
80
  dataRef.current = data;
80
81
  const headingSelectionState = (0, react_1.useMemo)(() => {
@@ -206,14 +207,18 @@ function useTableColumns({ disableSelection, disableContextMenu, disableColumnRe
206
207
  const formattedValue = (_c = (0, utils_1.getAttributeFormattedValue)(attribute, value, {
207
208
  currency: currency.currency,
208
209
  dateFormat: dateFormats.short,
210
+ timeFormat: timeFormats.short,
209
211
  timezone,
210
212
  })) !== null && _c !== void 0 ? _c : '';
213
+ if (column.plainText) {
214
+ return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: formattedValue, width: info.column.getSize() }, column.id));
215
+ }
211
216
  if (column.component) {
212
217
  const Component = componentStore_1.componentStore.getComponent(column.component);
213
218
  if (!Component) {
214
219
  throw new Error(`Component with name ${column.component} not found`);
215
220
  }
216
- return ((0, jsx_runtime_1.jsx)(Component, { column: column, schema: schema, record: info.row.original, value: value, attribute: attribute, formattedValue: formattedValue }));
221
+ return ((0, jsx_runtime_1.jsx)(Component, { column: column, schema: schema, record: info.row.original, value: value, attribute: attribute, formattedValue: formattedValue, width: info.column.getSize() }));
217
222
  }
218
223
  if (schema.primaryAttribute === column.name) {
219
224
  const path = routeResolver({
@@ -247,6 +252,8 @@ function useTableColumns({ disableSelection, disableContextMenu, disableColumnRe
247
252
  return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: "", width: info.column.getSize() }, column.id));
248
253
  }
249
254
  return ((0, jsx_runtime_1.jsx)(TableCellLink_1.TableCellLink, { value: formattedValue, width: info.column.getSize(), href: url, target: "_blank" }, column.id));
255
+ case 'choice':
256
+ return ((0, jsx_runtime_1.jsx)(TableCellChoice_1.TableCellChoice, { column: column, schema: schema, record: info.row.original, value: value, attribute: attribute, formattedValue: formattedValue, width: info.column.getSize() }));
250
257
  }
251
258
  return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: formattedValue, width: info.column.getSize() }, column.id));
252
259
  },
@@ -260,6 +267,7 @@ function useTableColumns({ disableSelection, disableContextMenu, disableColumnRe
260
267
  columnWidths,
261
268
  currency.currency,
262
269
  dateFormats.short,
270
+ timeFormats.short,
263
271
  disableColumnFilter,
264
272
  disableColumnResize,
265
273
  disableColumnSort,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/fluent",
3
- "version": "0.0.17-alpha.40",
3
+ "version": "0.0.17-alpha.41",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -48,5 +48,5 @@
48
48
  "uuid": "11.0.3",
49
49
  "yup": "^1.4.0"
50
50
  },
51
- "gitHead": "5141e4c378ed0b2aac011927e4d6c10c797624e0"
51
+ "gitHead": "2feaed5c73b0732b74518d37af5b5f26925e89d8"
52
52
  }