@nebulahome/package-sdk 0.0.0-stage → 1.0.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,381 @@
1
+ import { ButtonHTMLAttributes, ComponentType, InputHTMLAttributes, ReactElement, ReactNode, SVGProps } from "react";
2
+ //#region src/components/types.d.ts
3
+ /** What a button does: the one thing a screen is for, anything else, or a destructive action. */
4
+ type ButtonVariant = 'primary' | 'ghost' | 'danger';
5
+ /** A button's size. */
6
+ type ButtonSize = 'compact' | 'medium' | 'large';
7
+ /** A button: a native button's attributes, a variant and a size. */
8
+ type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
9
+ readonly variant?: ButtonVariant;
10
+ readonly size?: ButtonSize;
11
+ /** Draws a spinner and refuses presses while true. */
12
+ readonly isBusy?: boolean;
13
+ readonly children: ReactNode;
14
+ };
15
+ /** A button with an icon and no text, named by `label`. */
16
+ type IconButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'aria-label'> & {
17
+ readonly variant?: 'bare' | 'danger';
18
+ readonly size?: 'small' | 'medium' | 'large';
19
+ /** What pressing it does, for a screen reader and the tooltip. */
20
+ readonly label: string;
21
+ /** The glyph: an `Icon`. */
22
+ readonly children: ReactNode;
23
+ };
24
+ /** A catalogue icon, by the ids `icon` fields take. */
25
+ type IconProps = Omit<SVGProps<SVGSVGElement>, 'id' | 'width' | 'height' | 'viewBox'> & {
26
+ readonly id: string;
27
+ /** In pixels; 20 when not said. */
28
+ readonly size?: number;
29
+ };
30
+ /** What a badge means. */
31
+ type BadgeTone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger';
32
+ /** A short state. */
33
+ type BadgeProps = {
34
+ readonly tone?: BadgeTone;
35
+ readonly size?: 'small' | 'medium';
36
+ readonly icon?: ReactNode;
37
+ readonly children: ReactNode;
38
+ readonly className?: string;
39
+ };
40
+ /** A titled section. */
41
+ type PanelProps = {
42
+ readonly title: string;
43
+ /** `flat` for a panel inside another. */
44
+ readonly elevation?: 'raised' | 'flat';
45
+ /** What sits in the title's row: a button. */
46
+ readonly action?: ReactNode;
47
+ readonly children: ReactNode;
48
+ readonly className?: string;
49
+ };
50
+ /** A row of a panel: a title, a note under it, a control opposite. */
51
+ type PanelRowProps = {
52
+ readonly title: ReactNode;
53
+ readonly note?: ReactNode;
54
+ readonly control?: ReactNode;
55
+ readonly children?: ReactNode;
56
+ readonly className?: string;
57
+ };
58
+ /** A note under a panel. */
59
+ type PanelNoteProps = {
60
+ readonly children: ReactNode;
61
+ };
62
+ /** A card's two-line heading. */
63
+ type CardHeadingProps = {
64
+ readonly title: string;
65
+ readonly subtitle?: string | null | undefined;
66
+ /** What sits opposite: a switch, a badge. */
67
+ readonly tail?: ReactNode;
68
+ /** Draws the title quieter, for something that cannot be read. */
69
+ readonly isMuted?: boolean;
70
+ };
71
+ /** A reading as a number and its unit. */
72
+ type FigureProps = {
73
+ /** The number, already written. */
74
+ readonly value: string;
75
+ readonly unit?: string | null | undefined;
76
+ readonly size?: 'large' | 'medium' | 'small';
77
+ /** A colour for the number, when what it measures has one. */
78
+ readonly color?: string | undefined;
79
+ };
80
+ /** A state at a glance. */
81
+ type StatusDotProps = {
82
+ readonly tone: 'success' | 'warning' | 'danger' | 'neutral' | 'accent';
83
+ /** What it means, for the tooltip and a screen reader. */
84
+ readonly title: string;
85
+ /** Pulses while something is being done. */
86
+ readonly isBusy?: boolean;
87
+ };
88
+ /** How far something has come. */
89
+ type ProgressBarProps = {
90
+ /** 0 to 100; null pulses the whole bar. */
91
+ readonly percent: number | null;
92
+ /** What it is, for a screen reader. */
93
+ readonly label: string;
94
+ };
95
+ /** An explanation behind a small `i`. */
96
+ type HintProps = {
97
+ readonly text: string;
98
+ readonly className?: string;
99
+ };
100
+ /** A labelled text input: an input's attributes, a label, and what it says under it. */
101
+ type TextFieldProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'id' | 'size'> & {
102
+ readonly label: string;
103
+ readonly isLabelHidden?: boolean;
104
+ readonly size?: 'compact' | 'medium' | 'large';
105
+ readonly error?: string | undefined;
106
+ readonly warning?: string | undefined;
107
+ readonly hint?: ReactNode;
108
+ };
109
+ /** One choice of a select or a segmented control. */
110
+ type ControlOption<TValue extends string = string> = {
111
+ readonly value: TValue;
112
+ readonly label: string;
113
+ };
114
+ /** A labelled choice from a list. */
115
+ type SelectFieldProps = {
116
+ readonly label: string;
117
+ readonly isLabelHidden?: boolean;
118
+ readonly options: readonly ControlOption[];
119
+ readonly value: string;
120
+ readonly onChange: (value: string) => void;
121
+ readonly disabled?: boolean;
122
+ readonly size?: 'compact' | 'medium' | 'large';
123
+ readonly error?: string | undefined;
124
+ readonly hint?: ReactNode;
125
+ readonly className?: string;
126
+ };
127
+ /** On or off. */
128
+ type SwitchProps = {
129
+ readonly label: string;
130
+ readonly isOn: boolean;
131
+ readonly onChange: (isOn: boolean) => void;
132
+ readonly size?: 'small' | 'medium';
133
+ readonly disabled?: boolean;
134
+ readonly isBusy?: boolean;
135
+ readonly className?: string;
136
+ };
137
+ /** One of a few, side by side. */
138
+ type SegmentedProps<TValue extends string = string> = {
139
+ readonly label: string;
140
+ readonly options: readonly ControlOption<TValue>[];
141
+ readonly value: TValue;
142
+ readonly onChange: (value: TValue) => void;
143
+ readonly size?: 'compact' | 'medium';
144
+ readonly disabled?: boolean;
145
+ readonly className?: string;
146
+ };
147
+ /** A value in a range. */
148
+ type SliderProps = {
149
+ readonly label: string;
150
+ readonly isLabelHidden?: boolean;
151
+ readonly value: number;
152
+ readonly min: number;
153
+ readonly max: number;
154
+ readonly step?: number;
155
+ /** The value, written: `40 %`. */
156
+ readonly display: string;
157
+ readonly onChange: (value: number) => void;
158
+ /** Once the knob is let go. */
159
+ readonly onCommit?: ((value: number) => void) | undefined;
160
+ readonly fill?: 'accent' | 'warm';
161
+ readonly disabled?: boolean;
162
+ readonly className?: string;
163
+ };
164
+ /** A value by steps. */
165
+ type StepperProps = {
166
+ readonly label: string;
167
+ readonly value: number;
168
+ readonly min: number;
169
+ readonly max: number;
170
+ readonly step: number;
171
+ /**
172
+ * Writes a value.
173
+ *
174
+ * @param value - The value.
175
+ * @returns It, written.
176
+ */
177
+ readonly format: (value: number) => string;
178
+ readonly onChange: (value: number) => void;
179
+ readonly disabled?: boolean;
180
+ readonly className?: string;
181
+ };
182
+ /** A colour of the tag palette. */
183
+ type TagColor = 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'teal' | 'cyan' | 'blue' | 'indigo' | 'violet' | 'pink';
184
+ /** A coloured tag. */
185
+ type TagChipProps = {
186
+ readonly color: TagColor;
187
+ readonly children: string;
188
+ readonly size?: 'small' | 'medium';
189
+ /** Shows a remove button that calls this. */
190
+ readonly onRemove?: (() => void) | undefined;
191
+ readonly className?: string;
192
+ };
193
+ /** A dialog, drawn inside the package's scope. */
194
+ type ModalProps = {
195
+ readonly isOpen: boolean;
196
+ readonly onClose: () => void;
197
+ readonly title: string;
198
+ readonly description?: ReactNode;
199
+ readonly size?: 'small' | 'medium' | 'large';
200
+ readonly closesOnBackdrop?: boolean;
201
+ readonly children: ReactNode;
202
+ /** Its buttons. */
203
+ readonly footer?: ReactNode;
204
+ };
205
+ /** What `cn` joins: classes, conditions, lists of them. */
206
+ type ClassValue = string | number | bigint | boolean | null | undefined | readonly ClassValue[] | Readonly<Record<string, unknown>>;
207
+ /** What the interface lends to implement `/components`. */
208
+ type ComponentsHost = {
209
+ readonly Button: ComponentType<ButtonProps>;
210
+ readonly IconButton: ComponentType<IconButtonProps>;
211
+ readonly Icon: ComponentType<IconProps>;
212
+ readonly Badge: ComponentType<BadgeProps>;
213
+ readonly Panel: ComponentType<PanelProps>;
214
+ readonly PanelRow: ComponentType<PanelRowProps>;
215
+ readonly PanelNote: ComponentType<PanelNoteProps>;
216
+ readonly CardHeading: ComponentType<CardHeadingProps>;
217
+ readonly Figure: ComponentType<FigureProps>;
218
+ readonly StatusDot: ComponentType<StatusDotProps>;
219
+ readonly ProgressBar: ComponentType<ProgressBarProps>;
220
+ readonly Hint: ComponentType<HintProps>;
221
+ readonly TextField: ComponentType<TextFieldProps>;
222
+ readonly SelectField: ComponentType<SelectFieldProps>;
223
+ readonly Switch: ComponentType<SwitchProps>;
224
+ readonly Segmented: ComponentType<SegmentedProps>;
225
+ readonly Slider: ComponentType<SliderProps>;
226
+ readonly Stepper: ComponentType<StepperProps>;
227
+ readonly TagChip: ComponentType<TagChipProps>;
228
+ readonly Modal: ComponentType<ModalProps>;
229
+ readonly cn: (...classes: readonly ClassValue[]) => string;
230
+ };
231
+ //#endregion
232
+ //#region src/components/index.d.ts
233
+ /**
234
+ * An action.
235
+ *
236
+ * @param props - A native button's attributes, a variant and a size.
237
+ * @returns The button.
238
+ */
239
+ export declare function Button(props: ButtonProps): ReactElement;
240
+ /**
241
+ * An action with an icon and no text.
242
+ *
243
+ * @param props - What it does, its glyph, its variant and size.
244
+ * @returns The button.
245
+ */
246
+ export declare function IconButton(props: IconButtonProps): ReactElement;
247
+ /**
248
+ * A catalogue icon.
249
+ *
250
+ * @param props - Its id and size.
251
+ * @returns The icon.
252
+ */
253
+ export declare function Icon(props: IconProps): ReactElement;
254
+ /**
255
+ * A short state.
256
+ *
257
+ * @param props - Its tone, size and text.
258
+ * @returns The badge.
259
+ */
260
+ export declare function Badge(props: BadgeProps): ReactElement;
261
+ /**
262
+ * A titled section.
263
+ *
264
+ * @param props - Its title, action and content.
265
+ * @returns The panel.
266
+ */
267
+ export declare function Panel(props: PanelProps): ReactElement;
268
+ /**
269
+ * A row of a panel.
270
+ *
271
+ * @param props - Its title, note and control.
272
+ * @returns The row.
273
+ */
274
+ export declare function PanelRow(props: PanelRowProps): ReactElement;
275
+ /**
276
+ * A note under a panel.
277
+ *
278
+ * @param props - What it says.
279
+ * @returns The note.
280
+ */
281
+ export declare function PanelNote(props: PanelNoteProps): ReactElement;
282
+ /**
283
+ * A card's two-line heading, as the dashboard's own cards draw it.
284
+ *
285
+ * @param props - Its title, subtitle and tail.
286
+ * @returns The heading.
287
+ */
288
+ export declare function CardHeading(props: CardHeadingProps): ReactElement;
289
+ /**
290
+ * A reading as a number and its unit.
291
+ *
292
+ * @param props - The number, its unit and size.
293
+ * @returns The figure.
294
+ */
295
+ export declare function Figure(props: FigureProps): ReactElement;
296
+ /**
297
+ * A state at a glance.
298
+ *
299
+ * @param props - Its tone and meaning.
300
+ * @returns The dot.
301
+ */
302
+ export declare function StatusDot(props: StatusDotProps): ReactElement;
303
+ /**
304
+ * How far something has come.
305
+ *
306
+ * @param props - The percentage and what it is.
307
+ * @returns The bar.
308
+ */
309
+ export declare function ProgressBar(props: ProgressBarProps): ReactElement;
310
+ /**
311
+ * An explanation behind a small `i`.
312
+ *
313
+ * @param props - The explanation.
314
+ * @returns The hint.
315
+ */
316
+ export declare function Hint(props: HintProps): ReactElement;
317
+ /**
318
+ * A labelled text input.
319
+ *
320
+ * @param props - An input's attributes, its label and what it says under it.
321
+ * @returns The field.
322
+ */
323
+ export declare function TextField(props: TextFieldProps): ReactElement;
324
+ /**
325
+ * A labelled choice from a list.
326
+ *
327
+ * @param props - Its label, options and value.
328
+ * @returns The field.
329
+ */
330
+ export declare function SelectField(props: SelectFieldProps): ReactElement;
331
+ /**
332
+ * On or off.
333
+ *
334
+ * @param props - Its label and state.
335
+ * @returns The switch.
336
+ */
337
+ export declare function Switch(props: SwitchProps): ReactElement;
338
+ /**
339
+ * One of a few, side by side.
340
+ *
341
+ * @param props - Its label, options and value.
342
+ * @returns The control.
343
+ */
344
+ export declare function Segmented<TValue extends string>(props: SegmentedProps<TValue>): ReactElement;
345
+ /**
346
+ * A value in a range.
347
+ *
348
+ * @param props - Its label, range, value and how it is written.
349
+ * @returns The slider.
350
+ */
351
+ export declare function Slider(props: SliderProps): ReactElement;
352
+ /**
353
+ * A value by steps.
354
+ *
355
+ * @param props - Its label, range, step and how it is written.
356
+ * @returns The stepper.
357
+ */
358
+ export declare function Stepper(props: StepperProps): ReactElement;
359
+ /**
360
+ * A coloured tag.
361
+ *
362
+ * @param props - Its colour and text.
363
+ * @returns The tag.
364
+ */
365
+ export declare function TagChip(props: TagChipProps): ReactElement;
366
+ /**
367
+ * A dialog, drawn inside the package's scope.
368
+ *
369
+ * @param props - Whether it is open, its title, content and buttons.
370
+ * @returns The dialog.
371
+ */
372
+ export declare function Modal(props: ModalProps): ReactElement;
373
+ /**
374
+ * Joins class names, resolving Tailwind conflicts: the later class wins.
375
+ *
376
+ * @param classes - Classes, conditions, lists of them.
377
+ * @returns The class names.
378
+ */
379
+ export declare function cn(...classes: readonly ClassValue[]): string;
380
+ //#endregion
381
+ export type { BadgeProps, BadgeTone, ButtonProps, ButtonSize, ButtonVariant, CardHeadingProps, ClassValue, ComponentsHost, ControlOption, FigureProps, HintProps, IconButtonProps, IconProps, ModalProps, PanelNoteProps, PanelProps, PanelRowProps, ProgressBarProps, SegmentedProps, SelectFieldProps, SliderProps, StatusDotProps, StepperProps, SwitchProps, TagChipProps, TagColor, TextFieldProps };
@@ -0,0 +1,210 @@
1
+ import { r as hostMember, t as COMPONENTS_MODULE } from "./chunks/host.js";
2
+ import { createElement } from "react";
3
+ //#region src/components/index.ts
4
+ /**
5
+ * `@nebulahome/package-sdk/components`: the part of the interface's design system a package may
6
+ * draw with (PACKAGES_DOCS.md 7.1), lent at run time like React. A convenience, never a
7
+ * constraint: a package may draw anything, with any CSS.
8
+ */
9
+ /**
10
+ * An action.
11
+ *
12
+ * @param props - A native button's attributes, a variant and a size.
13
+ * @returns The button.
14
+ */
15
+ function Button(props) {
16
+ return createElement(hostMember(COMPONENTS_MODULE, "Button", "1.0"), props);
17
+ }
18
+ /**
19
+ * An action with an icon and no text.
20
+ *
21
+ * @param props - What it does, its glyph, its variant and size.
22
+ * @returns The button.
23
+ */
24
+ function IconButton(props) {
25
+ return createElement(hostMember(COMPONENTS_MODULE, "IconButton", "1.0"), props);
26
+ }
27
+ /**
28
+ * A catalogue icon.
29
+ *
30
+ * @param props - Its id and size.
31
+ * @returns The icon.
32
+ */
33
+ function Icon(props) {
34
+ return createElement(hostMember(COMPONENTS_MODULE, "Icon", "1.0"), props);
35
+ }
36
+ /**
37
+ * A short state.
38
+ *
39
+ * @param props - Its tone, size and text.
40
+ * @returns The badge.
41
+ */
42
+ function Badge(props) {
43
+ return createElement(hostMember(COMPONENTS_MODULE, "Badge", "1.0"), props);
44
+ }
45
+ /**
46
+ * A titled section.
47
+ *
48
+ * @param props - Its title, action and content.
49
+ * @returns The panel.
50
+ */
51
+ function Panel(props) {
52
+ return createElement(hostMember(COMPONENTS_MODULE, "Panel", "1.0"), props);
53
+ }
54
+ /**
55
+ * A row of a panel.
56
+ *
57
+ * @param props - Its title, note and control.
58
+ * @returns The row.
59
+ */
60
+ function PanelRow(props) {
61
+ return createElement(hostMember(COMPONENTS_MODULE, "PanelRow", "1.0"), props);
62
+ }
63
+ /**
64
+ * A note under a panel.
65
+ *
66
+ * @param props - What it says.
67
+ * @returns The note.
68
+ */
69
+ function PanelNote(props) {
70
+ return createElement(hostMember(COMPONENTS_MODULE, "PanelNote", "1.0"), props);
71
+ }
72
+ /**
73
+ * A card's two-line heading, as the dashboard's own cards draw it.
74
+ *
75
+ * @param props - Its title, subtitle and tail.
76
+ * @returns The heading.
77
+ */
78
+ function CardHeading(props) {
79
+ return createElement(hostMember(COMPONENTS_MODULE, "CardHeading", "1.0"), props);
80
+ }
81
+ /**
82
+ * A reading as a number and its unit.
83
+ *
84
+ * @param props - The number, its unit and size.
85
+ * @returns The figure.
86
+ */
87
+ function Figure(props) {
88
+ return createElement(hostMember(COMPONENTS_MODULE, "Figure", "1.0"), props);
89
+ }
90
+ /**
91
+ * A state at a glance.
92
+ *
93
+ * @param props - Its tone and meaning.
94
+ * @returns The dot.
95
+ */
96
+ function StatusDot(props) {
97
+ return createElement(hostMember(COMPONENTS_MODULE, "StatusDot", "1.0"), props);
98
+ }
99
+ /**
100
+ * How far something has come.
101
+ *
102
+ * @param props - The percentage and what it is.
103
+ * @returns The bar.
104
+ */
105
+ function ProgressBar(props) {
106
+ return createElement(hostMember(COMPONENTS_MODULE, "ProgressBar", "1.0"), props);
107
+ }
108
+ /**
109
+ * An explanation behind a small `i`.
110
+ *
111
+ * @param props - The explanation.
112
+ * @returns The hint.
113
+ */
114
+ function Hint(props) {
115
+ return createElement(hostMember(COMPONENTS_MODULE, "Hint", "1.0"), props);
116
+ }
117
+ /**
118
+ * A labelled text input.
119
+ *
120
+ * @param props - An input's attributes, its label and what it says under it.
121
+ * @returns The field.
122
+ */
123
+ function TextField(props) {
124
+ return createElement(hostMember(COMPONENTS_MODULE, "TextField", "1.0"), props);
125
+ }
126
+ /**
127
+ * A labelled choice from a list.
128
+ *
129
+ * @param props - Its label, options and value.
130
+ * @returns The field.
131
+ */
132
+ function SelectField(props) {
133
+ return createElement(hostMember(COMPONENTS_MODULE, "SelectField", "1.0"), props);
134
+ }
135
+ /**
136
+ * On or off.
137
+ *
138
+ * @param props - Its label and state.
139
+ * @returns The switch.
140
+ */
141
+ function Switch(props) {
142
+ return createElement(hostMember(COMPONENTS_MODULE, "Switch", "1.0"), props);
143
+ }
144
+ /**
145
+ * One of a few, side by side.
146
+ *
147
+ * @param props - Its label, options and value.
148
+ * @returns The control.
149
+ */
150
+ function Segmented(props) {
151
+ return createElement(hostMember(COMPONENTS_MODULE, "Segmented", "1.0"), {
152
+ ...props,
153
+ /**
154
+ * Hands the choice on, as the value it is.
155
+ *
156
+ * @param value - The choice.
157
+ */
158
+ onChange: (value) => {
159
+ const chosen = props.options.find((option) => option.value === value);
160
+ if (chosen !== void 0) props.onChange(chosen.value);
161
+ }
162
+ });
163
+ }
164
+ /**
165
+ * A value in a range.
166
+ *
167
+ * @param props - Its label, range, value and how it is written.
168
+ * @returns The slider.
169
+ */
170
+ function Slider(props) {
171
+ return createElement(hostMember(COMPONENTS_MODULE, "Slider", "1.0"), props);
172
+ }
173
+ /**
174
+ * A value by steps.
175
+ *
176
+ * @param props - Its label, range, step and how it is written.
177
+ * @returns The stepper.
178
+ */
179
+ function Stepper(props) {
180
+ return createElement(hostMember(COMPONENTS_MODULE, "Stepper", "1.0"), props);
181
+ }
182
+ /**
183
+ * A coloured tag.
184
+ *
185
+ * @param props - Its colour and text.
186
+ * @returns The tag.
187
+ */
188
+ function TagChip(props) {
189
+ return createElement(hostMember(COMPONENTS_MODULE, "TagChip", "1.0"), props);
190
+ }
191
+ /**
192
+ * A dialog, drawn inside the package's scope.
193
+ *
194
+ * @param props - Whether it is open, its title, content and buttons.
195
+ * @returns The dialog.
196
+ */
197
+ function Modal(props) {
198
+ return createElement(hostMember(COMPONENTS_MODULE, "Modal", "1.0"), props);
199
+ }
200
+ /**
201
+ * Joins class names, resolving Tailwind conflicts: the later class wins.
202
+ *
203
+ * @param classes - Classes, conditions, lists of them.
204
+ * @returns The class names.
205
+ */
206
+ function cn(...classes) {
207
+ return hostMember(COMPONENTS_MODULE, "cn", "1.0")(...classes);
208
+ }
209
+ //#endregion
210
+ export { Badge, Button, CardHeading, Figure, Hint, Icon, IconButton, Modal, Panel, PanelNote, PanelRow, ProgressBar, Segmented, SelectField, Slider, StatusDot, Stepper, Switch, TagChip, TextField, cn };