@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
260 lines • 11.1 kB
TypeScript
/**
*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { z } from 'zod';
/** A scalar literal that can appear as an operand in a style-rule where clause. */
export declare const DataGridStyleRuleLiteralSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
export type DataGridStyleRuleLiteral = z.infer<typeof DataGridStyleRuleLiteralSchema>;
/** A reference to a column whose cell value is resolved at evaluation time. */
export declare const DataGridColumnRefSchema: z.ZodObject<{
column: z.ZodString;
}, z.core.$strip>;
export type DataGridColumnRef = z.infer<typeof DataGridColumnRefSchema>;
/**
* An ISO 8601 or RFC 9557 datetime literal that resolves to a Unix millisecond
* timestamp at evaluation time. Wraps the shared `DatetimeLiteralSchema` with a
* DataGrid-specific name. Supported formats:
* - RFC 9557 with IANA timezone: `"2024-06-15T14:00:00[Europe/Stockholm]"` (offset
* inferred) or `"2024-06-15T14:00:00+02:00[Europe/Stockholm]"` (offset explicit)
* - UTC or offset datetime: `"2024-01-01T00:00:00Z"`, `"2024-01-01T00:00:00+02:00"`
* - Plain datetime (treated as UTC): `"2024-01-01T14:30:00"`
* - Date-only (treated as UTC midnight): `"2024-01-01"`
*
* Unzoned datetimes without `Z` or an offset are treated as UTC wall-clock time.
*/
export declare const DataGridDatetimeLiteralSchema: z.ZodObject<{
datetime: z.ZodString;
}, z.core.$strip>;
export type DataGridDatetimeLiteral = z.infer<typeof DataGridDatetimeLiteralSchema>;
/**
* A plain (unzoned) ISO 8601 date or datetime literal that resolves to a Unix
* millisecond timestamp in the browser's local timezone at evaluation time.
* Wraps the shared `LocalDatetimeLiteralSchema` with a DataGrid-specific name.
*
* Only plain date/datetime strings without timezone qualifiers are accepted:
* - Plain datetime: `"2024-01-01T14:30:00"`
* - Date-only (treated as local midnight): `"2024-01-01"`
*
* Strings with `Z`, a UTC offset, or an IANA bracket are rejected — use
* `{ datetime }` for timezone-aware instants.
*/
export declare const DataGridLocalDatetimeLiteralSchema: z.ZodObject<{
localdatetime: z.ZodString;
}, z.core.$strip>;
export type DataGridLocalDatetimeLiteral = z.infer<typeof DataGridLocalDatetimeLiteralSchema>;
/**
* An ISO 8601 time literal that resolves to milliseconds since UTC midnight at
* evaluation time. Wraps the shared `TimeLiteralSchema` with a DataGrid-specific
* name. Supported formats:
* - Local time (treated as UTC): `"14:30:00"`, `"14:30:00.500"`
* - Offset time (UTC-normalised): `"14:30:00+02:00"`
*/
export declare const DataGridTimeLiteralSchema: z.ZodObject<{
time: z.ZodString;
}, z.core.$strip>;
export type DataGridTimeLiteral = z.infer<typeof DataGridTimeLiteralSchema>;
/** An operand in a style-rule where clause -- either a literal value, a datetime literal, a localdatetime literal, a time literal, or a column reference. */
export declare const DataGridStyleRuleOperandSchema: z.ZodUnion<readonly [z.ZodObject<{
column: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
datetime: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
localdatetime: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
time: z.ZodString;
}, z.core.$strip>, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>]>;
export type DataGridStyleRuleOperand = DataGridColumnRef | DataGridDatetimeLiteral | DataGridLocalDatetimeLiteral | DataGridTimeLiteral | DataGridStyleRuleLiteral;
/**
* Recursive WHERE clause for conditional expressions.
* Inspired by the graph visualization style rule system but adapted for tabular data.
*
* The type is manually defined for the export, since zod doesn't support
* exporting inferred recursive types.
*/
export type DataGridStyleRuleWhere = {
not: DataGridStyleRuleWhere;
} | {
and: DataGridStyleRuleWhere[];
} | {
or: DataGridStyleRuleWhere[];
} | {
equal: [DataGridStyleRuleOperand, DataGridStyleRuleOperand];
} | {
lessThan: [DataGridStyleRuleOperand, DataGridStyleRuleOperand];
} | {
lessThanOrEqual: [DataGridStyleRuleOperand, DataGridStyleRuleOperand];
} | {
greaterThan: [DataGridStyleRuleOperand, DataGridStyleRuleOperand];
} | {
greaterThanOrEqual: [DataGridStyleRuleOperand, DataGridStyleRuleOperand];
} | {
contains: [DataGridStyleRuleOperand, DataGridStyleRuleOperand];
} | {
startsWith: [DataGridStyleRuleOperand, DataGridStyleRuleOperand];
} | {
endsWith: [DataGridStyleRuleOperand, DataGridStyleRuleOperand];
} | {
isNull: DataGridStyleRuleOperand;
};
export declare const DataGridStyleRuleWhereSchema: z.ZodType<DataGridStyleRuleWhere>;
/**
* Gradient coloring based on a continuous numeric column value.
* Colors should be hex strings (#rrggbb).
* If the column value is missing or non-numeric, the colorRange is ignored.
*/
export declare const DataGridColorRangeSchema: z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
maxColor: z.ZodString;
maxValue: z.ZodNumber;
midColor: z.ZodOptional<z.ZodString>;
midValue: z.ZodOptional<z.ZodNumber>;
minColor: z.ZodString;
minValue: z.ZodNumber;
onColumn: z.ZodString;
}, z.core.$strip>;
export type DataGridColorRange = z.infer<typeof DataGridColorRangeSchema>;
/** A disable-able static color value. */
export declare const DataGridDisableableColorSchema: z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
value: z.ZodString;
}, z.core.$strip>;
export type DataGridDisableableColor = z.infer<typeof DataGridDisableableColorSchema>;
/** Visual properties that a style rule can apply to a cell or row. */
export declare const DataGridCellStyleSchema: z.ZodObject<{
color: z.ZodOptional<z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
value: z.ZodString;
}, z.core.$strip>>;
colorRange: z.ZodOptional<z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
maxColor: z.ZodString;
maxValue: z.ZodNumber;
midColor: z.ZodOptional<z.ZodString>;
midValue: z.ZodOptional<z.ZodNumber>;
minColor: z.ZodString;
minValue: z.ZodNumber;
onColumn: z.ZodString;
}, z.core.$strip>>;
textColor: z.ZodOptional<z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
value: z.ZodString;
}, z.core.$strip>>;
textColorRange: z.ZodOptional<z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
maxColor: z.ZodString;
maxValue: z.ZodNumber;
midColor: z.ZodOptional<z.ZodString>;
midValue: z.ZodOptional<z.ZodNumber>;
minColor: z.ZodString;
minValue: z.ZodNumber;
onColumn: z.ZodString;
}, z.core.$strip>>;
}, z.core.$strip>;
export type DataGridCellStyle = z.infer<typeof DataGridCellStyleSchema>;
/**
* A function that converts a complex or non-scalar cell value into a
* `DataGridStyleRuleLiteral` so it can participate in where-clause evaluation
* and color-range interpolation.
*
* The function receives the raw cell value (`unknown`) and must return a scalar
* (`string | number | boolean | null`). Return `null` to signal that the value
* is missing or cannot be represented.
*
* Note: converter functions are TypeScript-only — they cannot be serialized as
* JSON, so no Zod schema is provided.
*/
export type DataGridStyleRuleValueConverter = (value: unknown) => DataGridStyleRuleLiteral;
/**
* A map of column id → converter function.
* Pass this as the `styleRuleValueConverters` prop on `DataGrid` to teach the
* style-rule engine how to interpret complex cell values for specific columns.
*
* @example
* ```ts
* const converters: DataGridStyleRuleValueConverters = {
* priority: (v) => {
* const s = v as { min: number; max: number };
* return s.max - s.min;
* },
* };
* ```
*/
export type DataGridStyleRuleValueConverters = Record<string, DataGridStyleRuleValueConverter>;
/** A single declarative rule that conditionally applies styles to DataGrid cells. */
export declare const DataGridStyleRuleSchema: z.ZodObject<{
apply: z.ZodObject<{
color: z.ZodOptional<z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
value: z.ZodString;
}, z.core.$strip>>;
colorRange: z.ZodOptional<z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
maxColor: z.ZodString;
maxValue: z.ZodNumber;
midColor: z.ZodOptional<z.ZodString>;
midValue: z.ZodOptional<z.ZodNumber>;
minColor: z.ZodString;
minValue: z.ZodNumber;
onColumn: z.ZodString;
}, z.core.$strip>>;
textColor: z.ZodOptional<z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
value: z.ZodString;
}, z.core.$strip>>;
textColorRange: z.ZodOptional<z.ZodObject<{
isDisabled: z.ZodOptional<z.ZodBoolean>;
maxColor: z.ZodString;
maxValue: z.ZodNumber;
midColor: z.ZodOptional<z.ZodString>;
midValue: z.ZodOptional<z.ZodNumber>;
minColor: z.ZodString;
minValue: z.ZodNumber;
onColumn: z.ZodString;
}, z.core.$strip>>;
}, z.core.$strip>;
column: z.ZodNullable<z.ZodString>;
isDisabled: z.ZodOptional<z.ZodBoolean>;
metaData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
priority: z.ZodOptional<z.ZodNumber>;
where: z.ZodOptional<z.ZodType<DataGridStyleRuleWhere, unknown, z.core.$ZodTypeInternals<DataGridStyleRuleWhere, unknown>>>;
}, z.core.$strip>;
export type DataGridStyleRule = z.infer<typeof DataGridStyleRuleSchema>;
/**
* Runtime type guard for {@link DataGridStyleRule}, backed by the internal Zod
* schema. Narrows an `unknown` value to `DataGridStyleRule` when it is a valid
* style rule.
*
* This lets consumers validate values without taking a dependency on Zod or on
* our schema export. For example, it can be passed to another validation
* library's custom check:
*
* @example
* ```ts
* import { z } from 'zod';
* import { isDataGridStyleRule, type DataGridStyleRule } from '@neo4j-ndl/react';
*
* const formSchema = z.object({
* rule: z.custom<DataGridStyleRule>(isDataGridStyleRule),
* notes: z.string(),
* });
* ```
*/
export declare const isDataGridStyleRule: (value: unknown) => value is DataGridStyleRule;
//# sourceMappingURL=types.d.ts.map