@funcd-dev/ui 0.6.0 → 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.
@@ -0,0 +1,26 @@
1
+ import { JSONData } from '@/types';
2
+ import { IChartSeries } from '../types';
3
+ export interface IChartPivotSeries extends IChartSeries {
4
+ /** One [x value, sum] pair per category; the sum is null without a value */
5
+ data: [string | number, number | null][];
6
+ /** First row of each category, as it is in `data` */
7
+ rows: JSONData[];
8
+ }
9
+ interface IChartPivotParams {
10
+ /** The chart's rows, as they are in `data` */
11
+ rows: JSONData[];
12
+ /** The same rows, flattened */
13
+ flatRows: JSONData[];
14
+ xKey: string;
15
+ series: IChartSeries[];
16
+ splitBy?: string;
17
+ xValues?: (string | number)[];
18
+ }
19
+ /**
20
+ * Sums the rows' values per x value and series, for `splitBy` and `xValues`.
21
+ * Every series gets one pair per category, in the same order, so the
22
+ * category axis collects the categories in that order and a listed x value
23
+ * without a row keeps its slot.
24
+ */
25
+ export declare const getChartPivot: (params: IChartPivotParams) => IChartPivotSeries[];
26
+ export {};
@@ -8,4 +8,26 @@ export type BarChartCustomProps<TRow extends JSONData = JSONData> = {
8
8
  stacked?: boolean;
9
9
  /** Draws the bars from left to right */
10
10
  horizontal?: boolean;
11
+ /**
12
+ * Row key whose values each draw one series, for rows in long form (one
13
+ * row per x value and split value). `series` then holds exactly one entry:
14
+ * its `key` holds the values and its `format` applies to every series;
15
+ * otherwise the chart shows an error card. The series follow the order in
16
+ * which their values first appear and take the theme's colors in that
17
+ * order, so `series[0].color` is ignored. Rows whose split value is empty
18
+ * (null, undefined or '') draw the series named after `series[0].name`,
19
+ * and rows with the same x value and split value add up to one bar. Rows
20
+ * without an x value are left out. With `stacked`, the series stack. The
21
+ * legend shows when there is more than one series. `onChartClick` gets the
22
+ * first row of `data` with the bar's x value and split value.
23
+ */
24
+ splitBy?: NestedKeyOf<TRow>;
25
+ /**
26
+ * The x values of the axis, in order, drawn as categories even when they
27
+ * are dates. A listed value without a row keeps its slot and draws no bar,
28
+ * and a row whose x value isn't listed is left out. Values match by their
29
+ * text, so `1` matches `'1'`, and rows with the same x value add up to one
30
+ * bar.
31
+ */
32
+ xValues?: (string | number)[];
11
33
  };
@@ -9,4 +9,11 @@ export type PieChartCustomProps<TRow extends JSONData = JSONData> = {
9
9
  donut?: boolean;
10
10
  /** Theme palette per slice name, for slices that mean a status; by default the chart theme picks one */
11
11
  colors?: Record<string, PyColorsType>;
12
+ /**
13
+ * Number format of the slice values in the tooltip and of the donut's
14
+ * total, in the browser's locale: `{ style: 'currency', currency: 'EUR' }`.
15
+ * A format that `Intl.NumberFormat` rejects shows an error card instead of
16
+ * the chart.
17
+ */
18
+ format?: Intl.NumberFormatOptions;
12
19
  };
@@ -16,6 +16,15 @@ export interface IChartSeries<TRow extends JSONData = JSONData> {
16
16
  name: string;
17
17
  /** Theme palette of the series; by default the chart theme picks one */
18
18
  color?: PyColorsType;
19
+ /**
20
+ * Number format of the values in the tooltip and on the value axis, in the
21
+ * browser's locale: `{ style: 'currency', currency: 'EUR' }`, or
22
+ * `{ style: 'unit', unit: 'percent' }` for values from 0 to 100. The value
23
+ * axis takes the first series' format, in compact notation (€1.5K) unless
24
+ * the format sets its own `notation`. A format that `Intl.NumberFormat`
25
+ * rejects shows an error card instead of the chart.
26
+ */
27
+ format?: Intl.NumberFormatOptions;
19
28
  }
20
29
  export type CommonChartProps<TChartProps extends JSONData> = {
21
30
  hidden?: boolean;
@@ -7,3 +7,25 @@ export declare const getChartAxisType: (rows: JSONData[], key: string) => ChartA
7
7
  * item by item, so an override can change one series and keep the others.
8
8
  */
9
9
  export declare const mergeChartOptions: <TOption extends JSONData>(option: TOption, override?: JSONData) => TOption;
10
+ /**
11
+ * A chart value as a number, read the way ECharts reads data values: a
12
+ * numeric string such as a SQL decimal is a number, and an empty value is NaN
13
+ */
14
+ export declare const getChartNumber: (value: unknown) => number;
15
+ /**
16
+ * Formats chart values with `format`, in the browser's locale. A value that
17
+ * isn't a number shows as a dash, as in ECharts' own tooltip.
18
+ */
19
+ export declare const getValueFormatter: (format?: Intl.NumberFormatOptions) => (value: unknown) => string;
20
+ /**
21
+ * Value axis labels in a series' `format`, compact like the labels without
22
+ * a format (€1.5K) unless the format sets its own `notation`
23
+ */
24
+ export declare const getValueAxisLabel: (format: Intl.NumberFormatOptions) => {
25
+ formatter: (value: unknown) => string;
26
+ };
27
+ /**
28
+ * Message of the error card for the first format that `Intl.NumberFormat`
29
+ * rejects, such as a currency code that isn't three letters
30
+ */
31
+ export declare const getFormatError: (formats: (Intl.NumberFormatOptions | undefined)[]) => string | undefined;
@@ -5,6 +5,7 @@ export * from './reactive-number-field';
5
5
  export * from './reactive-password-field';
6
6
  export * from './reactive-radio';
7
7
  export * from './reactive-range';
8
+ export * from './reactive-range-slider';
8
9
  export * from './reactive-select';
9
10
  export * from './reactive-switch';
10
11
  export * from './reactive-text-field';
@@ -0,0 +1,2 @@
1
+ export { default as ReactiveRangeSlider } from './reactive-range-slider';
2
+ export * from './types';
@@ -0,0 +1,5 @@
1
+ import { FC } from 'react';
2
+ import { IReactiveField } from '../types';
3
+ import { RangeSliderCustomProps } from './types';
4
+ declare const ReactiveRangeSlider: FC<IReactiveField<RangeSliderCustomProps>>;
5
+ export default ReactiveRangeSlider;
@@ -0,0 +1,25 @@
1
+ import { MantineSize } from '@mantine/core';
2
+ import { ReactNode } from 'react';
3
+ export type RangeSliderCustomProps = {
4
+ /** Marks which will be placed on the track */
5
+ marks?: {
6
+ value: number;
7
+ label?: ReactNode;
8
+ }[];
9
+ size?: MantineSize;
10
+ step?: number;
11
+ max?: number;
12
+ min?: number;
13
+ /** Smallest gap between the two thumbs, 10 by default */
14
+ minRange?: number;
15
+ /** Largest gap between the two thumbs */
16
+ maxRange?: number;
17
+ /** Thumb label, or a function that makes it from the value; null hides it */
18
+ label?: ReactNode | ((value: number) => ReactNode);
19
+ thumbSize?: number;
20
+ /** Thumb children, can be used to add icon */
21
+ thumbChildren?: ReactNode;
22
+ inverted?: boolean;
23
+ /** A transformation function, to change the scale of the slider */
24
+ scale?: (value: number) => number;
25
+ };
@@ -16,6 +16,7 @@ export interface IConditionalProp<TFormValues extends JSONData> {
16
16
  select: ConditionalProp<'select', TFormValues, true>;
17
17
  radio: ConditionalProp<'radio', TFormValues>;
18
18
  range: ConditionalProp<'range', TFormValues>;
19
+ 'range-slider': ConditionalProp<'range-slider', TFormValues>;
19
20
  'multi-select': ConditionalProp<'multi-select', TFormValues>;
20
21
  list: ConditionalProp<'list'>;
21
22
  }
@@ -6,6 +6,7 @@ import { NumberFieldCustomProps } from '../reactive-number-field';
6
6
  import { PasswordFieldCustomProps } from '../reactive-password-field';
7
7
  import { RadioCustomProps } from '../reactive-radio';
8
8
  import { RangeCustomProps } from '../reactive-range';
9
+ import { RangeSliderCustomProps } from '../reactive-range-slider';
9
10
  import { SelectCustomProps } from '../reactive-select';
10
11
  import { SwitchCustomProps } from '../reactive-switch';
11
12
  import { TextFieldCustomProps } from '../reactive-text-field';
@@ -24,6 +25,7 @@ export interface ICustomProps<TFormValues extends JSONData> {
24
25
  select: CommonProps<SelectCustomProps, TFormValues>;
25
26
  radio: CommonProps<RadioCustomProps, TFormValues>;
26
27
  range: CommonProps<RangeCustomProps, TFormValues>;
28
+ 'range-slider': CommonProps<RangeSliderCustomProps, TFormValues>;
27
29
  'multi-select': CommonProps<MultiSelectCustomProps, TFormValues>;
28
30
  list: CommonProps<ListFieldCustomProps<TFormValues>, TFormValues>;
29
31
  }
@@ -2,7 +2,7 @@ import { Ref } from 'react';
2
2
  import { RegisterOptions } from 'react-hook-form';
3
3
  import { JSONData, Simplify } from '@/types';
4
4
  import { FormProps } from '../../../types/form';
5
- export type InputType = 'text' | 'textarea' | 'number' | 'password' | 'checkbox' | 'switch' | 'select' | 'multi-select' | 'radio' | 'range' | 'autocomplete' | 'list';
5
+ export type InputType = 'text' | 'textarea' | 'number' | 'password' | 'checkbox' | 'switch' | 'select' | 'multi-select' | 'radio' | 'range' | 'range-slider' | 'autocomplete' | 'list';
6
6
  export type FormFieldOption<TFieldValues extends JSONData> = RegisterOptions<TFieldValues>;
7
7
  export type ErrorFormType = {
8
8
  type: string;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@funcd-dev/ui",
3
3
  "type": "module",
4
4
  "description": "React components for funcd: Mantine-based layouts, reactive forms, reactive charts and a flow editor",
5
- "version": "0.6.0",
5
+ "version": "0.8.0",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",