@foris/avocado-suite 1.10.2 → 1.11.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.
@@ -1,18 +1,45 @@
1
- import { FC } from 'react';
2
- export interface IDonutItem {
3
- name: string;
4
- percentage: number;
5
- value: number;
6
- }
1
+ import { type FC, type ReactNode } from 'react';
2
+ import { type DonutCenterMode, type DonutSegment, type DonutSize, type IDonutItem } from './donut.util';
7
3
  export interface DonutProps {
8
- /** overwrite className */
4
+ /** Overwrite className */
9
5
  className?: string;
10
- /** data */
11
- data: IDonutItem[];
12
- /** height */
13
- height?: string;
14
- /** width */
6
+ /** Slices of the ring; proportions come from `value`. */
7
+ segments?: DonutSegment[];
8
+ /** @deprecated Use `segments`. Proportions come from `percentage`, as in the SVG Donut. */
9
+ data?: IDonutItem[];
10
+ /** Ring diameter: `xs` 40, `sm` 56, `md` 96, `lg` 160 px, or `auto` to fill the parent. @default 'sm' */
11
+ size?: DonutSize;
12
+ /** Show the content inside the hole. @default true, false with legacy props */
13
+ showCenter?: boolean;
14
+ /** Custom center content; replaces `centerValue` and `centerLabel`. */
15
+ children?: ReactNode;
16
+ /**
17
+ * `fixed` shows `centerValue` (or the first segment share); `activeSegment` shows the hovered
18
+ * slice label and falls back to `centerValue`, so without it the center is empty until hover.
19
+ * @default 'activeSegment' from 160 px, 'fixed' below
20
+ */
21
+ centerMode?: DonutCenterMode;
22
+ /** Main center text, e.g. a total. */
23
+ centerValue?: string;
24
+ /** Secondary text below `centerValue`. */
25
+ centerLabel?: string;
26
+ /** Enable hover on the slices. @default true from 160 px, false below */
27
+ interactive?: boolean;
28
+ /** Show the hovered slice value and share outside the ring. Requires `interactive`. @default true from 160 px */
29
+ showCallout?: boolean;
30
+ /** Chart adapters only: Recharts nodes rendered inside the PieChart (e.g. Legend). */
31
+ chartChildren?: ReactNode;
32
+ /** Chart adapters only: slice highlighted before user interaction. */
33
+ defaultIndex?: number;
34
+ /** Chart adapters only: caps `size="auto"`. */
35
+ autoMaxDiameter?: number;
36
+ /** Chart adapters only: height reserved below the ring when `size="auto"`. */
37
+ autoLegendReserve?: number;
38
+ /** @deprecated Use `size`. Without `size`: px maps to a diameter, relative values to `'auto'`, none to 300 px. */
15
39
  width?: string;
40
+ /** @deprecated Use `size`. See `width`. */
41
+ height?: string;
16
42
  }
17
43
  declare const Donut: FC<DonutProps>;
18
44
  export default Donut;
45
+ export type { DonutSegment, DonutSize, DonutCenterMode, IDonutItem, } from './donut.util';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { IDonutItem } from '../Donut';
2
+ import { type IDonutItem } from '../donut.util';
3
3
  export interface DonutLabelsProps {
4
4
  /** overwrite className */
5
5
  className?: string;
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { IDonutItem } from '../Donut';
2
+ import { type IDonutItem } from '../donut.util';
3
3
  export interface DonutLegendProps {
4
4
  /** overwrite className */
5
5
  className?: string;
@@ -0,0 +1,58 @@
1
+ import type { Color } from '../../../../avocado-icons';
2
+ export declare const DONUT_PALETTE: `${Color}`[];
3
+ /** Colors of the SVG Donut (core `$donutColors`), kept for the deprecated `data` API. */
4
+ export declare const LEGACY_DONUT_COLORS: `${Color}`[];
5
+ export declare const DONUT_ANALYTIC_THRESHOLD = 160;
6
+ export declare const ACTIVE_CENTER_MAX_FONT_SIZE = 14;
7
+ /** Size of the legacy SVG Donut when no dimension was passed. */
8
+ export declare const LEGACY_DONUT_DIAMETER = 300;
9
+ export declare const DONUT_SIZE_MAP: {
10
+ readonly xs: 40;
11
+ readonly sm: 56;
12
+ readonly md: 96;
13
+ readonly lg: 160;
14
+ };
15
+ export type DonutSize = keyof typeof DONUT_SIZE_MAP | 'auto';
16
+ export type DonutCenterMode = 'fixed' | 'activeSegment';
17
+ export interface DonutSegment {
18
+ label: string;
19
+ value: number;
20
+ /** Design-system color name, e.g. `'success-50'`. Defaults to the palette by index. */
21
+ color?: `${Color}`;
22
+ }
23
+ /** Item consumed by `DonutLegend` and `DonutLabels`. */
24
+ export interface IDonutItem {
25
+ name: string;
26
+ percentage: number;
27
+ value: number;
28
+ /** Design-system color name. Defaults to the legacy SVG Donut colors by index. */
29
+ color?: `${Color}`;
30
+ }
31
+ interface DonutBehavior {
32
+ interactive: boolean;
33
+ showCallout: boolean;
34
+ centerMode: DonutCenterMode;
35
+ }
36
+ interface DonutLayout {
37
+ containerSize: number;
38
+ innerRadius: number;
39
+ outerRadius: number;
40
+ }
41
+ export declare const toColorVar: (color: `${Color}`) => string;
42
+ export declare const getSegmentColor: ({ color }: DonutSegment, index: number) => `${Color}`;
43
+ export declare const getDonutItemColor: ({ color }: IDonutItem, index: number) => `${Color}`;
44
+ export declare const resolveAutoDiameter: (width: number, height: number, { maxDiameter, legendReserve }?: {
45
+ maxDiameter?: number | undefined;
46
+ legendReserve?: number | undefined;
47
+ }) => number;
48
+ export declare const resolveLegacySize: (width?: string, height?: string) => DonutSize | number;
49
+ export declare const fromLegacyData: (data: IDonutItem[]) => DonutSegment[];
50
+ export declare const resolveDonutDiameter: (size: DonutSize | number, autoDiameter?: number) => number;
51
+ export declare const getDonutLayout: (diameter: number, showCallout: boolean) => DonutLayout;
52
+ export declare const getCenterFontSize: (diameter: number, innerDiameter: number, centerMode: DonutCenterMode) => number;
53
+ export declare const getDatumPercent: (datum: DonutSegment, segments: DonutSegment[]) => number;
54
+ export declare const resolveDonutBehavior: (analytic: boolean, overrides?: Partial<DonutBehavior>) => DonutBehavior;
55
+ /** Maps `segments` to the items of `DonutLegend` and `DonutLabels`, keeping the ring colors. */
56
+ export declare const toDonutLegendItems: (segments: DonutSegment[]) => IDonutItem[];
57
+ export declare const getDonutAriaLabel: (segments: DonutSegment[], centerText?: string) => string;
58
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -14,6 +14,19 @@ export type HeaderNavigationVisual = {
14
14
  src: string;
15
15
  alt: string;
16
16
  };
17
+ /** Solid preset, or a decorative photo with a fixed contrast overlay shape. */
18
+ export type HeaderNavigationImageBackground = {
19
+ type: 'image';
20
+ src: string;
21
+ /**
22
+ * CSS color for the tinted overlay gradient (`rgb()`, `hsl()`, hex, or
23
+ * `var(--color-*)`). When omitted, the packaged brand gradient on
24
+ * `web-cyan-100` is used. Also paints the header surface when the photograph
25
+ * is loading or fails.
26
+ */
27
+ overlayColor?: string;
28
+ };
29
+ export type HeaderNavigationBackground = 'default' | 'brand' | HeaderNavigationImageBackground;
17
30
  /** Reusable page navigation, with content and actions supplied by its host. */
18
31
  export interface HeaderNavigationProps extends HTMLAttributes<HTMLElement> {
19
32
  /** Page title, rendered as the primary heading. */
@@ -28,8 +41,8 @@ export interface HeaderNavigationProps extends HTMLAttributes<HTMLElement> {
28
41
  menuLabel?: string;
29
42
  /** Disables the overflow trigger. */
30
43
  menuDisabled?: boolean;
31
- /** Gray by default; brand selects the Figma blue in either theme. */
32
- background?: 'default' | 'brand';
44
+ /** Gray by default, brand blue, or a full-bleed hero photograph. */
45
+ background?: HeaderNavigationBackground;
33
46
  /** Optional leading icon or image. */
34
47
  leadingVisual?: HeaderNavigationVisual;
35
48
  /** Displays the packaged pattern when true, or a caller-provided pattern URL. */
@@ -1,2 +1,2 @@
1
1
  export { default } from './HeaderNavigation';
2
- export type { HeaderNavigationProps, HeaderNavigationVisual, } from './HeaderNavigation';
2
+ export type { HeaderNavigationBackground, HeaderNavigationImageBackground, HeaderNavigationProps, HeaderNavigationVisual, } from './HeaderNavigation';
@@ -0,0 +1,76 @@
1
+ import type { HTMLAttributes, Key, ReactElement, ReactNode, RefAttributes } from 'react';
2
+ /** Supported pinning edge, relative to the document direction. */
3
+ export type MatrixTablePinnedSide = 'start';
4
+ /**
5
+ * Inline alignment of a column's header and body cells. Logical, so `start` and
6
+ * `end` follow the document direction. Narrow numeric columns want `center`.
7
+ */
8
+ export type MatrixTableAlign = 'start' | 'center' | 'end';
9
+ /** What a group column and a detail column declare in common. */
10
+ interface MatrixTableColumnBase {
11
+ /** Stable identity, unique across both groupColumns and columns. */
12
+ key: string;
13
+ /** Content of the column header. */
14
+ header: ReactNode;
15
+ /** Declared width in px. Applied to the `col`, the header cell and the body cell. */
16
+ width: number;
17
+ /**
18
+ * Pins the column at the logical start. Only a contiguous prefix of
19
+ * `groupColumns` followed by `columns` can be pinned; a later marker is
20
+ * ignored and warned about in development.
21
+ */
22
+ pinned?: MatrixTablePinnedSide;
23
+ /**
24
+ * Alignment of this column's header and body cells. Defaults to the matrix
25
+ * defaults: `center` for detail columns, whose values are short and read as a
26
+ * grid, and `start` for group columns, which hold blocks of text.
27
+ */
28
+ align?: MatrixTableAlign;
29
+ /** Class added to this column's header and body cells; modifiers may take precedence. */
30
+ className?: string;
31
+ }
32
+ /** A column whose single cell spans every detail row of its group. */
33
+ export interface MatrixTableGroupColumn<TGroup> extends MatrixTableColumnBase {
34
+ /** Receives its own definition too, so one factory can serve many columns. */
35
+ renderGroupCell: (group: TGroup, column: MatrixTableGroupColumn<TGroup>) => ReactNode;
36
+ }
37
+ /** A column that renders one cell per detail row. */
38
+ export interface MatrixTableColumn<TGroup, TRow> extends MatrixTableColumnBase {
39
+ /**
40
+ * Receives the row, its group and the column itself. The third argument is
41
+ * what lets a shared handler build a full payload — which row, which group,
42
+ * which column — without a closure per column.
43
+ */
44
+ renderCell: (row: TRow, group: TGroup, column: MatrixTableColumn<TGroup, TRow>) => ReactNode;
45
+ /**
46
+ * Renders the cell as the row's header (`th scope="row"`). Opt in for the
47
+ * value that names the row — a component name, a code — not for data.
48
+ */
49
+ isRowHeader?: boolean;
50
+ }
51
+ /** Grouped matrix data and native attributes applied to the root div. */
52
+ export interface MatrixTableProps<TGroup, TRow> extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'dangerouslySetInnerHTML'> {
53
+ /** Consumer-owned group data. Never mutated, never copied into state. */
54
+ groups: readonly TGroup[];
55
+ /** Columns rendered once per group, spanning its detail rows. */
56
+ groupColumns: readonly MatrixTableGroupColumn<TGroup>[];
57
+ /** Columns rendered once per detail row. The scrolling matrix axis. */
58
+ columns: readonly MatrixTableColumn<TGroup, TRow>[];
59
+ /** Stable identity, unique within groups. */
60
+ getGroupKey: (group: TGroup) => Key;
61
+ /** Detail rows belonging to a group; an empty collection is supported. */
62
+ getRows: (group: TGroup) => readonly TRow[];
63
+ /** Stable detail-row identity, unique within its group. */
64
+ getRowKey: (row: TRow, group: TGroup) => Key;
65
+ /** Accessible name of the table and of its scroll region. Required. */
66
+ accessibleLabel: string;
67
+ /** Content of a spanning body cell when groups is empty. */
68
+ emptyContent?: ReactNode;
69
+ /** Exposed as `aria-busy`. The component ships no loader and no copy. */
70
+ isBusy?: boolean;
71
+ /** Class added to the root div alongside the component's own class. */
72
+ className?: string;
73
+ }
74
+ /** A grouped matrix table; ref and native div attributes target the root container. */
75
+ declare const MatrixTable: <TGroup, TRow>(props: MatrixTableProps<TGroup, TRow> & RefAttributes<HTMLDivElement>) => ReactElement;
76
+ export default MatrixTable;
@@ -0,0 +1,2 @@
1
+ export { default } from './MatrixTable';
2
+ export type { MatrixTableAlign, MatrixTableColumn, MatrixTableGroupColumn, MatrixTablePinnedSide, MatrixTableProps, } from './MatrixTable';
package/dist/index.d.ts CHANGED
@@ -25,6 +25,7 @@ import DropdownButton from './components/dropdown-button/DropdownButton';
25
25
  import Heading from './components/heading/Heading';
26
26
  import Link from './components/link/Link';
27
27
  import Loading from './components/loading/Loading';
28
+ import MatrixTable from './components/matrix-table';
28
29
  import Menu from './components/menu/Menu';
29
30
  import Modal from './components/modal/Modal';
30
31
  import Pager from './components/pager/Pager';
@@ -67,7 +68,7 @@ import { toast } from 'react-toastify';
67
68
  * Hooks
68
69
  */
69
70
  export { useFloatingPortal } from './hooks/useFloatingPortal';
70
- export { Banner, Beacon, Header, HeaderNavigation, ContextualNavigation, Hotspot, NavList, Drawer, AccessPanel, AccountMenu, SidebarMenu, Weekly, WeeklyGroup, Accordion, Box, Breadcrumbs, Button, Card, CardAccordion, CardNotification, Checkbox, DataCard, DataTable, DatePicker, Divider, Dropzone, FileUpload, Donut, DonutLabels, DonutLegend, DropdownButton, Heading, Link, Loading, Menu, Modal, Pager, Pill, PreviewerMarkdown, Processing, ProgressBar, RadioButton, RoundButton, Select, SelectPagination, SkeletonBase, SkeletonCircle, Stepper, Switch, Tabs, Tag, Text, TextField, Textarea, ThemeProvider, ThemeStore, LocaleStore, Timer, Toaster, Tooltip, Table, toast, };
71
+ export { Banner, Beacon, Header, HeaderNavigation, ContextualNavigation, Hotspot, NavList, Drawer, AccessPanel, AccountMenu, SidebarMenu, Weekly, WeeklyGroup, Accordion, Box, Breadcrumbs, Button, Card, CardAccordion, CardNotification, Checkbox, DataCard, DataTable, DatePicker, Divider, Dropzone, FileUpload, Donut, DonutLabels, DonutLegend, DropdownButton, Heading, Link, Loading, MatrixTable, Menu, Modal, Pager, Pill, PreviewerMarkdown, Processing, ProgressBar, RadioButton, RoundButton, Select, SelectPagination, SkeletonBase, SkeletonCircle, Stepper, Switch, Tabs, Tag, Text, TextField, Textarea, ThemeProvider, ThemeStore, LocaleStore, Timer, Toaster, Tooltip, Table, toast, };
71
72
  /**
72
73
  * Types
73
74
  */
@@ -81,10 +82,13 @@ export type { DataCardProps, DataCardV1Props, DataCardV1Variant, DataCardV2Props
81
82
  export type { DividerProps } from './components/divider/Divider';
82
83
  export type { DropzoneDisplay, DropzoneProps, DropzoneUploadStatus, } from './components/dropzone/Dropzone';
83
84
  export type { FileUploadProps } from './components/file-upload/FileUpload';
85
+ export type { DonutProps, DonutSegment, DonutSize, DonutCenterMode, IDonutItem, } from './components/donut/Donut';
86
+ export { toDonutLegendItems } from './components/donut/donut.util';
84
87
  export type { HeadingProps } from './components/heading/Heading';
85
- export type { HeaderNavigationProps, HeaderNavigationVisual, } from './components/header-navigation';
88
+ export type { HeaderNavigationBackground, HeaderNavigationImageBackground, HeaderNavigationProps, HeaderNavigationVisual, } from './components/header-navigation';
86
89
  export type { ContextualNavigationProps, ContextualNavigationItem, } from './components/contextual-navigation';
87
90
  export type { LinkProps } from './components/link/Link';
91
+ export type { MatrixTableAlign, MatrixTableColumn, MatrixTableGroupColumn, MatrixTablePinnedSide, MatrixTableProps, } from './components/matrix-table';
88
92
  export type { MenuItem } from './types/menu.types';
89
93
  export type { RoundButtonProps } from './components/round-button/RoundButton';
90
94
  export type { SelectProps } from './components/select/Select';