@lucasromero/matrix-ui 0.10.0 → 0.12.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -0
  3. package/dist/components/AreaChart/AreaChart.d.ts +3 -0
  4. package/dist/components/AreaChart/AreaChart.js +14 -0
  5. package/dist/components/AreaChart/index.d.ts +1 -0
  6. package/dist/components/BarChart/BarChart.d.ts +3 -0
  7. package/dist/components/BarChart/BarChart.js +134 -0
  8. package/dist/components/BarChart/index.d.ts +1 -0
  9. package/dist/components/Chart/ChartAxes.d.ts +2 -0
  10. package/dist/components/Chart/ChartAxes.js +28 -0
  11. package/dist/components/Chart/ChartFrame.d.ts +7 -0
  12. package/dist/components/Chart/ChartFrame.js +108 -0
  13. package/dist/components/Chart/ChartPatterns.d.ts +3 -0
  14. package/dist/components/Chart/ChartPatterns.js +27 -0
  15. package/dist/components/Chart/ChartPlot.d.ts +2 -0
  16. package/dist/components/Chart/ChartPlot.js +101 -0
  17. package/dist/components/Chart/LinearChart.d.ts +3 -0
  18. package/dist/components/Chart/LinearChart.js +133 -0
  19. package/dist/components/Chart/RadialChart.d.ts +20 -0
  20. package/dist/components/Chart/RadialChart.js +112 -0
  21. package/dist/components/Chart/index.module.js +38 -0
  22. package/dist/components/Chart/math.d.ts +19 -0
  23. package/dist/components/Chart/math.js +82 -0
  24. package/dist/components/Chart/useChartSize.d.ts +3 -0
  25. package/dist/components/Chart/useChartSize.js +24 -0
  26. package/dist/components/DonutChart/DonutChart.d.ts +19 -0
  27. package/dist/components/DonutChart/DonutChart.js +12 -0
  28. package/dist/components/DonutChart/index.d.ts +1 -0
  29. package/dist/components/LineChart/LineChart.d.ts +3 -0
  30. package/dist/components/LineChart/LineChart.js +14 -0
  31. package/dist/components/LineChart/index.d.ts +1 -0
  32. package/dist/components/PieChart/PieChart.d.ts +17 -0
  33. package/dist/components/PieChart/PieChart.js +12 -0
  34. package/dist/components/PieChart/index.d.ts +1 -0
  35. package/dist/components/Sparkline/Sparkline.d.ts +7 -0
  36. package/dist/components/Sparkline/Sparkline.js +56 -0
  37. package/dist/components/Sparkline/index.d.ts +1 -0
  38. package/dist/components/Sparkline/index.module.js +9 -0
  39. package/dist/components/Table/Table.js +145 -34
  40. package/dist/components/Table/TableSelectAll.d.ts +9 -0
  41. package/dist/components/Table/TableSelectAll.js +18 -0
  42. package/dist/components/Table/index.module.js +14 -3
  43. package/dist/index.d.ts +13 -1
  44. package/dist/index.js +66 -60
  45. package/dist/styles.css +1 -1
  46. package/dist/types/areaChartType.d.ts +5 -0
  47. package/dist/types/barChartType.d.ts +8 -0
  48. package/dist/types/chartType.d.ts +156 -0
  49. package/dist/types/donutChartType.d.ts +6 -0
  50. package/dist/types/index.d.ts +8 -1
  51. package/dist/types/lineChartType.d.ts +5 -0
  52. package/dist/types/pieChartType.d.ts +2 -0
  53. package/dist/types/sparklineType.d.ts +14 -0
  54. package/dist/types/tableType.d.ts +71 -3
  55. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ import type { CartesianChartProps } from "./chartType.js";
2
+ export type AreaChartProps<Row extends object> = CartesianChartProps<Row> & {
3
+ /** Stacks the series, so the top edge is their total. Use it with values that are not negative. Defaults to `false`. */
4
+ stacked?: boolean;
5
+ };
@@ -0,0 +1,8 @@
1
+ import type { CartesianChartProps } from "./chartType.js";
2
+ export type BarChartOrientation = "vertical" | "horizontal";
3
+ export type BarChartProps<Row extends object> = CartesianChartProps<Row> & {
4
+ /** Direction the bars grow in. Horizontal bars suit long category names. Defaults to `"vertical"`. */
5
+ orientation?: BarChartOrientation;
6
+ /** Stacks the series in one bar per category. Defaults to `false`, which shows them side by side. */
7
+ stacked?: boolean;
8
+ };
@@ -0,0 +1,156 @@
1
+ import type { HTMLAttributes, PointerEvent, ReactNode } from "react";
2
+ /** A step of the chart palette, from `--matrix-chart-color-1` to `--matrix-chart-color-8`. */
3
+ export type ChartColor = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
4
+ export type ChartSeries<Row> = {
5
+ /** Key of the number in each row. A missing, `null`, or invalid number is left out. */
6
+ key: Extract<keyof Row, string>;
7
+ /** Name of the series, shown in the legend, the tooltip, and the table. */
8
+ label: string;
9
+ /**
10
+ * Color of the series. Defaults to its position in `series`. Set it when
11
+ * series can be filtered, so each one keeps its color. Series after the
12
+ * eighth are gray without one.
13
+ */
14
+ color?: ChartColor;
15
+ };
16
+ export type ChartBaseProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
17
+ /** Visible title of the chart, which names it, such as "Revenue by month". */
18
+ label: string;
19
+ /** Hides the title visually. It still names the chart. Defaults to `false`. */
20
+ hideLabel?: boolean;
21
+ /** Height of the chart in pixels, without its title, legend, and table. Defaults to `240`. */
22
+ height?: number;
23
+ /** Formats values in the tooltip, the table, and announcements. Defaults to English number formatting. */
24
+ formatValue?: (value: number) => string;
25
+ /** Shows the data as a visible table below the chart. Without it, the table is only for assistive technology. Defaults to `false`. */
26
+ showTable?: boolean;
27
+ /** Header of the table's first column. Defaults to "Category". */
28
+ categoryLabel?: string;
29
+ /** Adds a pattern to each filled area, so they can be told apart without color. Patterns always show in forced-colors mode. Defaults to `false`. */
30
+ patterns?: boolean;
31
+ /** Shown instead of the chart when there is no data. Defaults to "No data to show". */
32
+ emptyMessage?: ReactNode;
33
+ /** Instructions read when the chart is focused. Defaults to "Use the arrow keys to read each value." */
34
+ keyboardHint?: string;
35
+ };
36
+ export type CartesianChartProps<Row extends object> = ChartBaseProps & {
37
+ /** Rows of data, in display order. */
38
+ data: readonly Row[];
39
+ /** Key of the category in each row, such as a month. */
40
+ categoryKey: Extract<keyof Row, string>;
41
+ /** Series to show, in display order. */
42
+ series: readonly ChartSeries<Row>[];
43
+ /** Formats categories. Defaults to the category as text. */
44
+ formatCategory?: (category: string) => string;
45
+ /** Formats values on the axis. Defaults to `formatValue`, or to short numbers such as "20K". */
46
+ formatAxisValue?: (value: number) => string;
47
+ /** Shows the legend. Defaults to `true` with more than one series. */
48
+ showLegend?: boolean;
49
+ };
50
+ export type ChartSlice = {
51
+ /** Name of the slice, shown in the legend, the tooltip, and the table. */
52
+ label: string;
53
+ /** Size of the slice. Zero, negative, and invalid values are left out. */
54
+ value: number;
55
+ /** Color of the slice. Defaults to its position in `data`. Slices after the eighth are gray without one. */
56
+ color?: ChartColor;
57
+ };
58
+ export type RadialChartProps = ChartBaseProps & {
59
+ /** Slices, in display order, clockwise from the top. */
60
+ data: readonly ChartSlice[];
61
+ /** Header of the table's value column. Defaults to "Value". */
62
+ valueLabel?: string;
63
+ /** Header of the table's share column. Defaults to "Share". */
64
+ shareLabel?: string;
65
+ /** Formats a slice's share, from 0 to 1. Defaults to a percentage, such as "25%". */
66
+ formatShare?: (share: number) => string;
67
+ /** Shows the legend, with each slice's share. Defaults to `true`. */
68
+ showLegend?: boolean;
69
+ };
70
+ export type ChartSize = {
71
+ width: number;
72
+ fontSize: number;
73
+ };
74
+ export type ChartScale = {
75
+ min: number;
76
+ max: number;
77
+ ticks: number[];
78
+ };
79
+ export type ChartBox = {
80
+ left: number;
81
+ top: number;
82
+ width: number;
83
+ height: number;
84
+ };
85
+ export type ChartPoint = {
86
+ x: number;
87
+ y: number;
88
+ };
89
+ export type ChartLegendItem = {
90
+ label: string;
91
+ color: string;
92
+ slot: number;
93
+ mark: "line" | "fill";
94
+ value?: string;
95
+ };
96
+ export type ChartTooltip = {
97
+ title?: string;
98
+ rows: {
99
+ label: string;
100
+ value: string;
101
+ color: string;
102
+ }[];
103
+ };
104
+ export type ChartTable = {
105
+ headers: string[];
106
+ rows: string[][];
107
+ };
108
+ export type ChartFrameProps = Omit<ChartBaseProps, "height" | "formatValue" | "categoryLabel" | "keyboardHint"> & {
109
+ children: ReactNode;
110
+ legend: ChartLegendItem[];
111
+ patternId: string;
112
+ table: ChartTable;
113
+ isEmpty: boolean;
114
+ };
115
+ export type ChartPlotProps = {
116
+ label: string;
117
+ height: number;
118
+ hint: string;
119
+ count: number;
120
+ patternId: string;
121
+ findIndex: (point: ChartPoint, size: ChartSize) => number | null;
122
+ getAnchor: (index: number, size: ChartSize) => ChartPoint;
123
+ getTooltip: (index: number) => ChartTooltip;
124
+ render: (size: ChartSize, active: number | null) => ReactNode;
125
+ overlay?: ReactNode;
126
+ };
127
+ export type ChartPointerEvent = PointerEvent<HTMLDivElement>;
128
+ export type ChartSeriesValues = {
129
+ label: string;
130
+ color: string;
131
+ slot: number;
132
+ values: (number | null)[];
133
+ };
134
+ export type ChartSwatchProps = {
135
+ item: ChartLegendItem;
136
+ patternId: string;
137
+ };
138
+ export type ChartAxesProps = {
139
+ box: ChartBox;
140
+ scale: ChartScale;
141
+ size: ChartSize;
142
+ categories: string[];
143
+ positions: number[];
144
+ formatTick: (value: number) => string;
145
+ alignEnds: boolean;
146
+ };
147
+ export type RadialChartBaseProps = RadialChartProps & {
148
+ innerRatio: number;
149
+ center?: ReactNode;
150
+ };
151
+ export type LinearChartKind = "line" | "area";
152
+ export type LinearChartBaseProps<Row extends object> = CartesianChartProps<Row> & {
153
+ kind: LinearChartKind;
154
+ includeZero: boolean;
155
+ stacked: boolean;
156
+ };
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from "react";
2
+ import type { RadialChartProps } from "./chartType.js";
3
+ export type DonutChartProps = RadialChartProps & {
4
+ /** Content in the middle, such as a total. Keep it short enough to fit. */
5
+ center?: ReactNode;
6
+ };
@@ -47,7 +47,7 @@ export type { SpinnerProps, SpinnerSize } from "./spinnerType.js";
47
47
  export type { LayoutElement, StackAlign, StackProps } from "./stackType.js";
48
48
  export type { StepperOrientation, StepperProps, StepperStatusLabels, StepperStep, } from "./stepperType.js";
49
49
  export type { SwitchProps } from "./switchType.js";
50
- export type { TableColumn, TableProps } from "./tableType.js";
50
+ export type { TableColumn, TableProps, TableRowAction, TableSort, TableSortDirection, } from "./tableType.js";
51
51
  export type { TabsActivation, TabsItem, TabsProps } from "./tabsType.js";
52
52
  export type { TextareaProps } from "./textareaType.js";
53
53
  export type { TextTagProps } from "./textTagType.js";
@@ -59,3 +59,10 @@ export type { TooltipProps } from "./tooltipType.js";
59
59
  export type { UseDisclosureButtonProps, UseDisclosureOptions, UseDisclosurePanelProps, UseDisclosureResult, } from "./useDisclosureType.js";
60
60
  export type { UseMediaQueryOptions } from "./useMediaQueryType.js";
61
61
  export type { VisuallyHiddenProps } from "./visuallyHiddenType.js";
62
+ export type { AreaChartProps } from "./areaChartType.js";
63
+ export type { BarChartOrientation, BarChartProps } from "./barChartType.js";
64
+ export type { CartesianChartProps, ChartAxesProps, ChartBaseProps, ChartBox, ChartColor, ChartFrameProps, ChartLegendItem, ChartPlotProps, ChartPoint, ChartPointerEvent, ChartScale, ChartSeries, ChartSeriesValues, ChartSize, ChartSlice, ChartSwatchProps, ChartTable, ChartTooltip, LinearChartBaseProps, LinearChartKind, RadialChartBaseProps, RadialChartProps, } from "./chartType.js";
65
+ export type { DonutChartProps } from "./donutChartType.js";
66
+ export type { LineChartProps } from "./lineChartType.js";
67
+ export type { PieChartProps } from "./pieChartType.js";
68
+ export type { SparklineProps } from "./sparklineType.js";
@@ -0,0 +1,5 @@
1
+ import type { CartesianChartProps } from "./chartType.js";
2
+ export type LineChartProps<Row extends object> = CartesianChartProps<Row> & {
3
+ /** Starts the value axis at zero. Turn it off to show small changes between large values. Defaults to `true`. */
4
+ includeZero?: boolean;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { RadialChartProps } from "./chartType.js";
2
+ export type PieChartProps = RadialChartProps;
@@ -0,0 +1,14 @@
1
+ import type { HTMLAttributes } from "react";
2
+ import type { ChartColor } from "./chartType.js";
3
+ export type SparklineProps = Omit<HTMLAttributes<HTMLSpanElement>, "children" | "color"> & {
4
+ /** Values, in order. Invalid values are left out of the line. */
5
+ data: readonly number[];
6
+ /** Accessible name, which should say what the trend shows, such as "Revenue rose from $2K to $8K this year". */
7
+ label: string;
8
+ /** Color of the line. Defaults to `1`. */
9
+ color?: ChartColor;
10
+ /** Fills the area below the line. Defaults to `false`. */
11
+ area?: boolean;
12
+ /** Height in pixels. Defaults to `32`. The width fills the container. */
13
+ height?: number;
14
+ };
@@ -1,13 +1,46 @@
1
1
  import type { Key, ReactNode, TableHTMLAttributes } from "react";
2
2
  export type TableColumn<Row> = {
3
- /** Unique key of the column. */
3
+ /** Unique key of the column. It is also the key passed to `onSortChange`. */
4
4
  key: string;
5
5
  /** Content of the column's header cell. */
6
6
  header: ReactNode;
7
7
  /** Returns the content of this column's cell for a row. */
8
8
  cell: (row: Row) => ReactNode;
9
- /** Renders this column's cells as row headers. Defaults to `false`. */
9
+ /**
10
+ * Renders this column's cells as row headers. Defaults to `false`. The first
11
+ * row header also names each row's checkbox and actions.
12
+ */
10
13
  rowHeader?: boolean;
14
+ /**
15
+ * Makes the header a button that asks to sort by this column, through
16
+ * `onSortChange`. Defaults to `false`.
17
+ */
18
+ sortable?: boolean;
19
+ /** Keeps each cell's content on one line, for short values such as dates. Defaults to `false`. */
20
+ noWrap?: boolean;
21
+ /**
22
+ * Hides the column on screens 640px wide and narrower. Defaults to `false`.
23
+ * Show its content elsewhere if people still need it there, such as under
24
+ * the row header.
25
+ */
26
+ hideOnMobile?: boolean;
27
+ };
28
+ export type TableSortDirection = "ascending" | "descending";
29
+ export type TableSort = {
30
+ /** Key of the sorted column. */
31
+ key: string;
32
+ /** Order of the rows. */
33
+ direction: TableSortDirection;
34
+ };
35
+ export type TableRowAction = {
36
+ /** Visible text. With the row header, it names the action, such as "Remove Ana Silva". */
37
+ label: string;
38
+ /** Called when the action is chosen. */
39
+ onSelect: () => void;
40
+ /** Shows the action in the danger color, for destructive actions. Defaults to `false`. */
41
+ danger?: boolean;
42
+ /** Prevents choosing the action. Defaults to `false`. */
43
+ disabled?: boolean;
11
44
  };
12
45
  export type TableProps<Row> = Omit<TableHTMLAttributes<HTMLTableElement>, "children"> & {
13
46
  /**
@@ -19,8 +52,43 @@ export type TableProps<Row> = Omit<TableHTMLAttributes<HTMLTableElement>, "child
19
52
  columns: readonly TableColumn<Row>[];
20
53
  /** Rows of data. Each row is passed to every column's `cell`. */
21
54
  rows: readonly Row[];
22
- /** Returns a unique, stable key for a row. */
55
+ /** Returns a unique, stable key for a row. Selection uses these keys. */
23
56
  getRowKey: (row: Row, index: number) => Key;
24
57
  /** Shown in a single cell when there are no rows. Defaults to "No rows to show". */
25
58
  emptyMessage?: ReactNode;
59
+ /**
60
+ * The current order, shown on its column's header. Table does not reorder
61
+ * `rows`; sort them, and pass them in that order.
62
+ */
63
+ sort?: TableSort | null;
64
+ /**
65
+ * Called with the order to show when a sortable header is pressed: ascending,
66
+ * or descending when that column is already ascending. Without it, sortable
67
+ * headers show the order but are not buttons.
68
+ */
69
+ onSortChange?: (sort: TableSort) => void;
70
+ /** Keys of the selected rows. Use it with `onSelectionChange`. */
71
+ selectedKeys?: readonly Key[];
72
+ /**
73
+ * Adds a checkbox to each row and a "Select all rows" checkbox, and is called
74
+ * with the keys of the selected rows when they change. Selecting all selects
75
+ * the rows passed in `rows`.
76
+ */
77
+ onSelectionChange?: (keys: Key[]) => void;
78
+ /** Accessible name of the checkbox that selects every row. Defaults to "Select all rows". */
79
+ selectAllLabel?: string;
80
+ /**
81
+ * Returns the accessible name of a row's checkbox. Defaults to the row's
82
+ * first row header, or "Select row 1" when there is none.
83
+ */
84
+ getSelectLabel?: (row: Row, index: number) => string;
85
+ /**
86
+ * Returns a row's actions. They are buttons in the last column, and on
87
+ * screens 640px wide and narrower they move into one menu per row, so the
88
+ * table needs less room. When an action removes its row, move focus
89
+ * somewhere sensible, as the focused button disappears with it.
90
+ */
91
+ rowActions?: (row: Row, index: number) => TableRowAction[];
92
+ /** Header of the actions column, visually hidden, which also names each row's menu. Defaults to "Actions". */
93
+ actionsLabel?: string;
26
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucasromero/matrix-ui",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Reusable, accessible React and TypeScript components.",
5
5
  "keywords": [
6
6
  "react",