@wso2/oxygen-ui 0.16.0 → 0.18.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,185 @@
1
+ import * as React from 'react';
2
+ import type { ButtonProps } from '@mui/material/Button';
3
+ import type { LocalizationProviderProps } from '@mui/x-date-pickers/LocalizationProvider';
4
+ import type { Locale } from 'date-fns';
5
+ /**
6
+ * A closed time range. `end` is later than `start`.
7
+ */
8
+ export interface TimeRange {
9
+ start: Date;
10
+ end: Date;
11
+ }
12
+ /**
13
+ * A quick choice that spans a fixed duration ending now (e.g. "Last 24 hours").
14
+ */
15
+ export interface TimeRangePreset {
16
+ /** Stable identifier of the preset. */
17
+ id: string;
18
+ /** Text shown in the list. */
19
+ label: string;
20
+ /** Length of the range in milliseconds. */
21
+ durationMs: number;
22
+ }
23
+ /**
24
+ * Props for the TimeRangeFilter component
25
+ */
26
+ export interface TimeRangeFilterProps extends Omit<ButtonProps, 'onChange' | 'value' | 'children'> {
27
+ /**
28
+ * The selected range, or `null` when no range is selected. The button does not display it, so show
29
+ * it elsewhere (for example in a chip).
30
+ */
31
+ value: TimeRange | null;
32
+ /**
33
+ * Called with the new range when the user picks a preset or applies a custom range.
34
+ * Clearing the range is up to the consumer (for example, from the remove icon of a chip).
35
+ */
36
+ onChange: (range: TimeRange) => void;
37
+ /**
38
+ * Presets listed before the custom range.
39
+ * @default Last hour, Last 24 hours, Last 7 days, Last 30 days
40
+ */
41
+ presets?: TimeRangePreset[];
42
+ /**
43
+ * Longest range, in milliseconds, that a custom range may span. Unlimited when omitted.
44
+ */
45
+ maxRangeMs?: number;
46
+ /**
47
+ * Text of the trigger button.
48
+ * @default 'Time range'
49
+ */
50
+ label?: string;
51
+ /**
52
+ * Text of the list item that shows the custom range fields.
53
+ * @default 'Custom'
54
+ */
55
+ customRangeLabel?: string;
56
+ /**
57
+ * Heading of the custom range fields.
58
+ * @default 'Select date range'
59
+ */
60
+ panelTitle?: string;
61
+ /**
62
+ * Label of the custom range start. Custom values are read as UTC.
63
+ * @default 'Start from (UTC)'
64
+ */
65
+ fromLabel?: string;
66
+ /**
67
+ * Label of the custom range end. Custom values are read as UTC.
68
+ * @default 'End on (UTC)'
69
+ */
70
+ untilLabel?: string;
71
+ /**
72
+ * Label of each date field.
73
+ * @default 'Date'
74
+ */
75
+ dateLabel?: string;
76
+ /**
77
+ * Label of each time field.
78
+ * @default 'Time'
79
+ */
80
+ timeLabel?: string;
81
+ /**
82
+ * Text of the button that applies a custom range.
83
+ * @default 'Apply'
84
+ */
85
+ applyLabel?: string;
86
+ /**
87
+ * Text of the button that closes the picker without applying a custom range.
88
+ * @default 'Cancel'
89
+ */
90
+ cancelLabel?: string;
91
+ /**
92
+ * Error shown when the custom range is empty or reversed, or a date or time is missing.
93
+ * @default 'Choose a valid time range.'
94
+ */
95
+ invalidRangeLabel?: string;
96
+ /**
97
+ * Error shown when the custom range is longer than `maxRangeMs`. The default names the limit, for
98
+ * example 'Choose a range of at most 30 days.'; set it to translate that text.
99
+ */
100
+ rangeTooLongLabel?: string;
101
+ /**
102
+ * The date-fns locale of the date and time fields and their calendars, for example `fr` from
103
+ * `date-fns/locale`. It sets the month names, the first day of the week and the like. The pickers
104
+ * are in English when it is not set.
105
+ */
106
+ adapterLocale?: Locale;
107
+ /**
108
+ * Text of the pickers' own controls (the calendar buttons, and the OK and Cancel of the dialog
109
+ * shown on touch screens), for example `frFR.components.MuiLocalizationProvider.defaultProps.localeText`
110
+ * from `@mui/x-date-pickers/locales`.
111
+ */
112
+ localeText?: LocalizationProviderProps<Locale>['localeText'];
113
+ /**
114
+ * Format of the date fields, as a date-fns format string.
115
+ * @default 'dd MMM, yyyy'
116
+ */
117
+ dateFormat?: string;
118
+ /**
119
+ * Format of the time fields, as a date-fns format string. Keep the seconds in it: the fields pick
120
+ * the hour, the minute and the second.
121
+ * @default 'HH:mm:ss'
122
+ */
123
+ timeFormat?: string;
124
+ /**
125
+ * Whether the picker is open. Set it, with `onOpen` and `onClose`, to control the picker, for
126
+ * example to reopen it from a chip that shows the range. Leave it out and the picker opens and
127
+ * closes itself.
128
+ */
129
+ open?: boolean;
130
+ /**
131
+ * Called when the trigger button asks to open the picker.
132
+ */
133
+ onOpen?: () => void;
134
+ /**
135
+ * Called when the picker asks to close: after a choice is applied, on Cancel, on Escape, and on a
136
+ * click outside.
137
+ */
138
+ onClose?: () => void;
139
+ /**
140
+ * The element the open picker is placed under. Defaults to the trigger button. Set it when the
141
+ * picker is opened from somewhere else, such as a chip.
142
+ */
143
+ anchorEl?: HTMLElement | null;
144
+ }
145
+ /**
146
+ * TimeRangeFilter component - A button that opens a list of quick time ranges and, beside it, the
147
+ * fields of a custom range.
148
+ *
149
+ * Custom ranges are entered and read as UTC. The component never fetches data or clears the
150
+ * range itself; it reports choices through `onChange`.
151
+ *
152
+ * The button does not show the selected range: its text stays the same after a choice. Show the
153
+ * range yourself, for example in a chip or as text beside the button, so readers can see which
154
+ * range is applied.
155
+ *
156
+ * @example
157
+ * ```tsx
158
+ * const [range, setRange] = React.useState<TimeRange | null>(null);
159
+ *
160
+ * <TimeRangeFilter value={range} onChange={setRange} maxRangeMs={30 * 24 * 60 * 60 * 1000} />
161
+ * ```
162
+ *
163
+ * @example
164
+ * ```tsx
165
+ * // Reopen the picker from a chip: control `open` and `anchorEl`
166
+ * const [anchor, setAnchor] = React.useState<HTMLElement | null>(null);
167
+ * const [open, setOpen] = React.useState(false);
168
+ *
169
+ * <TimeRangeFilter
170
+ * value={range}
171
+ * onChange={setRange}
172
+ * open={open}
173
+ * anchorEl={anchor}
174
+ * onOpen={() => { setAnchor(null); setOpen(true); }}
175
+ * onClose={() => setOpen(false)}
176
+ * />
177
+ * <Chip
178
+ * label="Time: Last 24 hours"
179
+ * onClick={(event) => { setAnchor(event.currentTarget); setOpen(true); }}
180
+ * onDelete={() => setRange(null)}
181
+ * />
182
+ * ```
183
+ */
184
+ declare const TimeRangeFilter: React.ForwardRefExoticComponent<Omit<TimeRangeFilterProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
185
+ export default TimeRangeFilter;
@@ -0,0 +1,2 @@
1
+ export { default } from './TimeRangeFilter';
2
+ export * from './TimeRangeFilter';
@@ -0,0 +1,192 @@
1
+ import React from 'react';
2
+ import type { BoxProps } from '@mui/material';
3
+ /**
4
+ * Visual status of a trial, derived from the days remaining.
5
+ */
6
+ export type TrialBadgeStatus = 'active' | 'ending-soon' | 'critical' | 'expired';
7
+ /**
8
+ * Props for the TrialBadge component
9
+ */
10
+ export interface TrialBadgeProps extends Omit<BoxProps, 'children'> {
11
+ /**
12
+ * Number of days left in the trial. Fractional values are allowed: the exact value drives
13
+ * the status and ring, and the displayed count is rounded up. Values below 0 are treated as 0 (expired).
14
+ */
15
+ daysLeft: number;
16
+ /**
17
+ * Total length of the trial in days. Used to compute the progress ring.
18
+ * @default 14
19
+ */
20
+ totalDays?: number;
21
+ /**
22
+ * Days left at or below which the badge switches to the "ending soon" state.
23
+ * @default 7
24
+ */
25
+ endingSoonThreshold?: number;
26
+ /**
27
+ * Days left at or below which the badge switches to the "critical" state
28
+ * and shows the upgrade link.
29
+ * @default 3
30
+ */
31
+ criticalThreshold?: number;
32
+ /**
33
+ * Called when the badge is clicked, in addition to any `onClick`. When set (or when
34
+ * `upgradeHref` or `onClick` is set) the whole badge is rendered as a button.
35
+ */
36
+ onUpgrade?: React.MouseEventHandler<HTMLElement>;
37
+ /**
38
+ * When set, the whole badge renders as an anchor pointing to this URL.
39
+ */
40
+ upgradeHref?: string;
41
+ /**
42
+ * Whether to show the "Upgrade now" text in the critical and expired states.
43
+ * @default true
44
+ */
45
+ showUpgrade?: boolean;
46
+ /**
47
+ * Primary line while the trial is running. Receives the days left.
48
+ * @default (days) => `${days} day(s) left`
49
+ */
50
+ getTitle?: (daysLeft: number) => React.ReactNode;
51
+ /**
52
+ * Primary line once the trial has expired.
53
+ * @default 'Trial expired'
54
+ */
55
+ expiredLabel?: React.ReactNode;
56
+ /**
57
+ * Secondary line while no upgrade prompt is shown.
58
+ * @default 'of free trial'
59
+ */
60
+ subtitle?: React.ReactNode;
61
+ /**
62
+ * Text of the upgrade link.
63
+ * @default 'Upgrade now'
64
+ */
65
+ upgradeLabel?: React.ReactNode;
66
+ /**
67
+ * Optional usage summary. When set, hovering or focusing the badge opens a panel listing
68
+ * how much of each resource is used, with an upgrade button. When omitted, no panel is shown.
69
+ */
70
+ usage?: TrialBadgeUsage;
71
+ }
72
+ /**
73
+ * A resource listed in the usage panel, shown as `count/limit`.
74
+ */
75
+ export interface TrialBadgeUsageItem {
76
+ /**
77
+ * Stable key for the row. Falls back to the label.
78
+ */
79
+ key?: string;
80
+ /**
81
+ * Name of the resource, e.g. "REST APIs".
82
+ */
83
+ label: React.ReactNode;
84
+ /**
85
+ * The count shown for this resource, out of `limit`. The bar and its color follow
86
+ * `count / limit`: a higher share means more of the quota is taken, so it turns yellow and then red.
87
+ */
88
+ count: number;
89
+ /**
90
+ * The total allowed for this resource.
91
+ */
92
+ limit: number;
93
+ }
94
+ /**
95
+ * A titled group of resources in the usage panel.
96
+ */
97
+ export interface TrialBadgeUsageSection {
98
+ /**
99
+ * Stable key for the section. Falls back to the title.
100
+ */
101
+ key?: string;
102
+ /**
103
+ * Heading of the section.
104
+ */
105
+ title: React.ReactNode;
106
+ /**
107
+ * The resources to list. The section total is the sum of their counts and limits.
108
+ */
109
+ items: TrialBadgeUsageItem[];
110
+ /**
111
+ * Text after the section total, e.g. `left` gives "14 of 30 left".
112
+ * The total is shown only when this is passed.
113
+ */
114
+ totalSuffix?: React.ReactNode;
115
+ }
116
+ /**
117
+ * Content of the usage panel shown when hovering or focusing the badge.
118
+ * Pass `sections` for several titled groups, or `items` (with an optional `title`) for one.
119
+ */
120
+ export interface TrialBadgeUsage {
121
+ /**
122
+ * Titled groups of resources. Takes precedence over `items`.
123
+ */
124
+ sections?: TrialBadgeUsageSection[];
125
+ /**
126
+ * The resources to list when there is a single group and no `sections`.
127
+ */
128
+ items?: TrialBadgeUsageItem[];
129
+ /**
130
+ * Heading of the single group made from `items`.
131
+ * @default 'Components left'
132
+ */
133
+ title?: React.ReactNode;
134
+ /**
135
+ * Text after the total of the single group made from `items`.
136
+ * The total is shown only when this is passed.
137
+ */
138
+ totalSuffix?: React.ReactNode;
139
+ /**
140
+ * Text shown at the bottom left of the panel. Pass `null` to hide it.
141
+ * @default 'Unlimited on Pro'
142
+ */
143
+ footerText?: React.ReactNode;
144
+ /**
145
+ * Label of the panel's upgrade button.
146
+ * @default 'Upgrade'
147
+ */
148
+ upgradeLabel?: React.ReactNode;
149
+ /**
150
+ * Called when the panel's upgrade button is clicked.
151
+ */
152
+ onUpgrade?: React.MouseEventHandler<HTMLElement>;
153
+ /**
154
+ * When set, the panel's upgrade button renders as an anchor pointing to this URL.
155
+ */
156
+ upgradeHref?: string;
157
+ /**
158
+ * Share (0-1) of the limit above which a bar turns yellow. At or below it the bar is green.
159
+ * @default 0.5
160
+ */
161
+ warningThreshold?: number;
162
+ /**
163
+ * Share (0-1) of the limit at or above which a bar turns red.
164
+ * @default 0.75
165
+ */
166
+ criticalThreshold?: number;
167
+ }
168
+ /**
169
+ * Color tone of a quota, from the share of its limit that is taken.
170
+ */
171
+ export type TrialBadgeUsageTone = 'error' | 'warning' | 'success';
172
+ /**
173
+ * Resolve the status of a trial from the days left and thresholds.
174
+ */
175
+ export declare function getTrialBadgeStatus(daysLeft: number, endingSoonThreshold?: number, criticalThreshold?: number): TrialBadgeStatus;
176
+ /**
177
+ * TrialBadge component - A compact pill showing the remaining days of a free trial.
178
+ * The color changes with the time left, and in the last days (and after expiry)
179
+ * the second line becomes an "Upgrade now" link.
180
+ *
181
+ * @example
182
+ * ```tsx
183
+ * <TrialBadge daysLeft={12} />
184
+ * ```
185
+ *
186
+ * @example
187
+ * ```tsx
188
+ * <TrialBadge daysLeft={2} onUpgrade={() => navigate('/billing')} />
189
+ * ```
190
+ */
191
+ declare const TrialBadge: React.FC<TrialBadgeProps>;
192
+ export default TrialBadge;
@@ -0,0 +1,2 @@
1
+ export { default } from './TrialBadge';
2
+ export * from './TrialBadge';
@@ -34,8 +34,12 @@ export { default as RelativeTime } from './RelativeTime';
34
34
  export type { RelativeTimeProps } from './RelativeTime';
35
35
  export { default as StatCard } from './StatCard';
36
36
  export type { StatCardProps } from './StatCard';
37
+ export { default as TrialBadge, getTrialBadgeStatus } from './TrialBadge';
38
+ export type { TrialBadgeProps, TrialBadgeStatus, TrialBadgeUsage, TrialBadgeUsageItem, TrialBadgeUsageSection, TrialBadgeUsageTone, } from './TrialBadge';
37
39
  export { default as ThemeSwitcher, ThemeSelect } from './ThemeSwitcher';
38
40
  export type { ThemeSwitcherProps, ThemeSelectProps } from './ThemeSwitcher';
41
+ export { default as TimeRangeFilter } from './TimeRangeFilter';
42
+ export type { TimeRange, TimeRangeFilterProps, TimeRangePreset, } from './TimeRangeFilter';
39
43
  export { default as SearchBarWithAdvancedFilter } from './SearchBar/SearchBarWithAdvancedFilter';
40
44
  export type { SearchBarWithAdvancedFilterProps, AdvancedFilterState } from './SearchBar/SearchBarWithAdvancedFilter';
41
45
  export { default as SearchBar } from './SearchBar/SearchBar';
@@ -59,4 +63,4 @@ export { AppShell } from './AppShell';
59
63
  export type { AppShellProps } from './AppShell';
60
64
  export { default as ListingTable } from './ListingTable';
61
65
  export { useListingTable, useListingTableRequired, ListingTableContext, ListingTableProvider, } from './ListingTable';
62
- export type { ListingTableProps, ListingTableContainerProps, ListingTableHeadProps, ListingTableBodyProps, ListingTableFooterProps, ListingTableRowProps, ListingTableCellProps, ListingTableDensity, ListingTableVariant, ListingTableToolbarProps, ListingTableEmptyStateProps, ListingTableDensityControlProps, ListingTableSortLabelProps, ListingSortDirection, ListingTableRowActionsProps, ListingTableCellIconProps, ListingTableContextValue, ListingTableSortDirection, ListingTableProviderProps, ListingTableDataGridProps, } from './ListingTable';
66
+ export type { ListingTableProps, ListingTableContainerProps, ListingTableHeadProps, ListingTableBodyProps, ListingTableFooterProps, ListingTableRowProps, ListingTableCellProps, ListingTableDensity, ListingTableVariant, ListingTableToolbarProps, ListingTableEmptyStateProps, ListingTableDensityControlProps, ListingTableSortLabelProps, ListingSortDirection, ListingTableFilterProps, ListingTableFilterOption, ListingTableRowActionsProps, ListingTableCellIconProps, ListingTableContextValue, ListingTableSortDirection, ListingTableProviderProps, ListingTableDataGridProps, } from './ListingTable';