gristlabs_grist-core/app/client/widgets/ErrorDom.ts
Paul Fitzpatrick 1654a2681f (core) move client code to core
Summary:
This moves all client code to core, and makes minimal fix-ups to
get grist and grist-core to compile correctly.  The client works
in core, but I'm leaving clean-up around the build and bundles to
follow-up.

Test Plan: existing tests pass; server-dev bundle looks sane

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2627
2020-10-02 13:24:21 -04:00

20 lines
895 B
TypeScript

import {DataRowModel} from 'app/client/models/DataRowModel';
import {ViewFieldRec} from 'app/client/models/entities/ViewFieldRec';
import {getObjCode} from 'app/common/gristTypes';
import {formatUnknown} from 'app/common/ValueFormatter';
import {dom} from 'grainjs';
export function buildErrorDom(row: DataRowModel, field: ViewFieldRec) {
const value = row.cells[field.colId.peek()];
const options = field.widgetOptionsJson;
// The "invalid" class sets the pink background, as long as the error text is non-empty.
return dom('div.field_clip.invalid',
// Sets CSS class field-error-P, field-error-U, etc.
dom.clsPrefix('field-error-', (use) => getObjCode(use(value)) || ''),
dom.style('text-align', options.prop('alignment')),
dom.cls('text_wrapping', (use) => Boolean(use(options.prop('wrap')))),
dom.text((use) => formatUnknown(value ? use(value) : '???'))
);
}