@sensorario/sg-components 0.0.104 → 0.0.106

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 (36) hide show
  1. package/dist/auth/index.d.ts +10 -0
  2. package/dist/components/AuthPage/AuthPage.d.ts +11 -0
  3. package/dist/components/AuthPage/AuthPage.stories.d.ts +8 -0
  4. package/dist/components/Avatar/Avatar.d.ts +10 -0
  5. package/dist/components/Avatar/Avatar.stories.d.ts +8 -0
  6. package/dist/components/Badge/Badge.d.ts +17 -0
  7. package/dist/components/Badge/Badge.stories.d.ts +8 -0
  8. package/dist/components/Button/Button.d.ts +1 -0
  9. package/dist/components/Button/Button.stories.d.ts +1 -0
  10. package/dist/components/Card/Card.d.ts +20 -0
  11. package/dist/components/Card/Card.stories.d.ts +9 -0
  12. package/dist/components/ConfirmModal/ConfirmModal.d.ts +18 -0
  13. package/dist/components/ConfirmModal/ConfirmModal.stories.d.ts +7 -0
  14. package/dist/components/FormField/FormField.d.ts +19 -0
  15. package/dist/components/FormField/FormField.stories.d.ts +6 -0
  16. package/dist/components/LoginPrompt/LoginPrompt.d.ts +13 -0
  17. package/dist/components/LoginPrompt/LoginPrompt.stories.d.ts +8 -0
  18. package/dist/components/PasswordInput/PasswordInput.d.ts +1 -0
  19. package/dist/components/ProgressBar/ProgressBar.d.ts +16 -0
  20. package/dist/components/ProgressBar/ProgressBar.stories.d.ts +10 -0
  21. package/dist/components/RegisterForm/RegisterForm.d.ts +9 -0
  22. package/dist/components/Select/Select.d.ts +7 -0
  23. package/dist/components/StatusMessage/StatusMessage.d.ts +13 -0
  24. package/dist/components/StatusMessage/StatusMessage.stories.d.ts +10 -0
  25. package/dist/components/Table/Table.stories.d.ts +5 -0
  26. package/dist/components/Tabs/Tabs.d.ts +19 -0
  27. package/dist/components/Tabs/Tabs.stories.d.ts +8 -0
  28. package/dist/components/Textarea/Textarea.d.ts +7 -0
  29. package/dist/components/Toggle/Toggle.d.ts +5 -1
  30. package/dist/components/Toggle/Toggle.stories.d.ts +1 -0
  31. package/dist/components/VersionNumber/VersionNumber.d.ts +8 -0
  32. package/dist/components/VersionNumber/VersionNumber.stories.d.ts +5 -0
  33. package/dist/index.d.ts +16 -0
  34. package/dist/index.es.js +717 -354
  35. package/dist/sg-components.css +1 -1
  36. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ export declare const ACCESS_TOKEN_COOKIE = "simonegentili.com-access-token";
2
+ /** `domain` and `secure` only where the browser honors them: otherwise it drops the whole cookie (e.g. http://localhost). */
3
+ export declare const cookieScope: () => string;
4
+ export declare const writeCookie: (name: string, value: string, maxAgeSeconds: number, sameSite?: "strict" | "lax") => void;
5
+ /** The JWT shared by every .simonegentili.com app, or null when logged out. */
6
+ export declare const getAccessToken: (cookieName?: string) => string | null;
7
+ export declare const setAccessToken: (token: string, maxAgeSeconds?: number, cookieName?: string) => void;
8
+ export declare const clearAccessToken: (cookieName?: string) => void;
9
+ /** Reads one claim of the token payload without verifying it (the API does that). Default: the username. */
10
+ export declare const getTokenClaim: (token?: string | null, claim?: string) => string | null;
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from 'react';
2
+ import './AuthPage.css';
3
+ interface AuthPageProps {
4
+ title: ReactNode;
5
+ children?: ReactNode;
6
+ /** Links under the card, e.g. back to the home page (router-specific, so the app passes it). */
7
+ footer?: ReactNode;
8
+ className?: string;
9
+ }
10
+ export declare const AuthPage: ({ title, children, footer, className }: AuthPageProps) => import("react/jsx-runtime").JSX.Element;
11
+ export default AuthPage;
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { AuthPage } from './AuthPage';
3
+ declare const meta: Meta<typeof AuthPage>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof AuthPage>;
6
+ export declare const Register: Story;
7
+ export declare const RegisterError: Story;
8
+ export declare const Registered: Story;
@@ -0,0 +1,10 @@
1
+ import './Avatar.css';
2
+ interface AvatarProps {
3
+ src?: string | null;
4
+ /** Alt text, and its first letter is shown when there's no image. */
5
+ name?: string | null;
6
+ size?: number;
7
+ className?: string;
8
+ }
9
+ export declare const Avatar: ({ src, name, size, className }: AvatarProps) => import("react/jsx-runtime").JSX.Element;
10
+ export default Avatar;
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { Avatar } from './Avatar';
3
+ declare const meta: Meta<typeof Avatar>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof Avatar>;
6
+ export declare const Initial: Story;
7
+ export declare const Image: Story;
8
+ export declare const Sizes: Story;
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from 'react';
2
+ import './Badge.css';
3
+ export type BadgeTone = 'neutral' | 'accent' | 'success' | 'danger';
4
+ interface BadgeProps {
5
+ children: ReactNode;
6
+ tone?: BadgeTone;
7
+ /** Makes the badge a toggle button (e.g. a pickable tag); `selected` is its pressed state. */
8
+ onClick?: () => void;
9
+ selected?: boolean;
10
+ /** Adds a "×" button, e.g. to take a user off a role. */
11
+ onRemove?: () => void;
12
+ /** Accessible name of the "×" button. Default: the translated "Remove". */
13
+ removeLabel?: string;
14
+ className?: string;
15
+ }
16
+ export declare const Badge: ({ children, tone, onClick, selected, onRemove, removeLabel, className }: BadgeProps) => import("react/jsx-runtime").JSX.Element;
17
+ export default Badge;
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { Badge } from './Badge';
3
+ declare const meta: Meta<typeof Badge>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof Badge>;
6
+ export declare const Tones: Story;
7
+ export declare const Selectable: Story;
8
+ export declare const Removable: Story;
@@ -5,6 +5,7 @@ type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
5
5
  label: string;
6
6
  icon?: IconName;
7
7
  iconOnly?: boolean;
8
+ variant?: 'primary' | 'secondary' | 'danger';
8
9
  };
9
10
  export declare const Button: React.FC<ButtonProps>;
10
11
  export default Button;
@@ -4,3 +4,4 @@ declare const meta: Meta<typeof Button>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof Button>;
6
6
  export declare const Default: Story;
7
+ export declare const Variants: Story;
@@ -0,0 +1,20 @@
1
+ import { type ReactNode } from 'react';
2
+ import './Card.css';
3
+ interface CardProps {
4
+ /** Rendered next to each other at the top: title on the left, e.g. a date on the right. */
5
+ header?: ReactNode;
6
+ /** Row of links/buttons below the content. */
7
+ actions?: ReactNode;
8
+ children?: ReactNode;
9
+ variant?: 'default' | 'mini';
10
+ /** Lifts on hover, for cards that are themselves a link or a button. */
11
+ interactive?: boolean;
12
+ as?: 'div' | 'li' | 'article' | 'section' | 'a';
13
+ href?: string;
14
+ className?: string;
15
+ }
16
+ export declare const Card: ({ header, actions, children, variant, interactive, as, href, className, }: CardProps) => import("react").DetailedReactHTMLElement<{
17
+ className: string;
18
+ href: string | undefined;
19
+ }, HTMLElement>;
20
+ export default Card;
@@ -0,0 +1,9 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { Card } from './Card';
3
+ declare const meta: Meta<typeof Card>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof Card>;
6
+ export declare const Default: Story;
7
+ export declare const WithHeaderAndActions: Story;
8
+ export declare const Mini: Story;
9
+ export declare const InteractiveLink: Story;
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from 'react';
2
+ import './ConfirmModal.css';
3
+ interface ConfirmModalProps {
4
+ open: boolean;
5
+ title: string;
6
+ /** The question, e.g. "This can't be undone." */
7
+ children?: ReactNode;
8
+ onConfirm: () => void;
9
+ /** Also called on Escape, backdrop click and the "×". */
10
+ onCancel: () => void;
11
+ confirmLabel?: string;
12
+ cancelLabel?: string;
13
+ /** Red confirm button, for destructive actions. */
14
+ danger?: boolean;
15
+ icon?: ReactNode;
16
+ }
17
+ export declare const ConfirmModal: ({ open, title, children, onConfirm, onCancel, confirmLabel, cancelLabel, danger, icon, }: ConfirmModalProps) => import("react/jsx-runtime").JSX.Element;
18
+ export default ConfirmModal;
@@ -0,0 +1,7 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { ConfirmModal } from './ConfirmModal';
3
+ declare const meta: Meta<typeof ConfirmModal>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof ConfirmModal>;
6
+ export declare const Default: Story;
7
+ export declare const Danger: Story;
@@ -0,0 +1,19 @@
1
+ import { type ReactElement, type ReactNode } from 'react';
2
+ import './FormField.css';
3
+ type ControlProps = {
4
+ id?: string;
5
+ 'aria-describedby'?: string;
6
+ 'aria-invalid'?: boolean;
7
+ invalid?: boolean;
8
+ };
9
+ interface FormFieldProps {
10
+ label: ReactNode;
11
+ /** A single control: Input-like element, Textarea, Select, or a native one. */
12
+ children: ReactElement<ControlProps>;
13
+ hint?: ReactNode;
14
+ /** Replaces the hint and marks the control invalid. */
15
+ error?: ReactNode;
16
+ className?: string;
17
+ }
18
+ export declare const FormField: ({ label, children, hint, error, className }: FormFieldProps) => import("react/jsx-runtime").JSX.Element;
19
+ export default FormField;
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { FormField } from './FormField';
3
+ declare const meta: Meta<typeof FormField>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof FormField>;
6
+ export declare const Form: Story;
@@ -0,0 +1,13 @@
1
+ import type { ReactNode } from 'react';
2
+ import './LoginPrompt.css';
3
+ interface LoginPromptProps {
4
+ /** What logging in unlocks, e.g. "Accedi per vedere le sessioni." */
5
+ children?: ReactNode;
6
+ /** Shows a login button, e.g. `() => headerRef.current?.openLoginModal()`. */
7
+ onLogin?: () => void;
8
+ /** Extra content under the button, e.g. a link to the registration page. */
9
+ footer?: ReactNode;
10
+ className?: string;
11
+ }
12
+ export declare const LoginPrompt: ({ children, onLogin, footer, className }: LoginPromptProps) => import("react/jsx-runtime").JSX.Element;
13
+ export default LoginPrompt;
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { LoginPrompt } from './LoginPrompt';
3
+ declare const meta: Meta<typeof LoginPrompt>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof LoginPrompt>;
6
+ export declare const TextOnly: Story;
7
+ export declare const WithButton: Story;
8
+ export declare const WithRegisterLink: Story;
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import './PasswordInput.css';
3
3
  type PasswordInputProps = React.InputHTMLAttributes<HTMLInputElement> & {
4
4
  label?: string;
5
+ invalid?: boolean;
5
6
  };
6
7
  export declare const PasswordInput: React.FC<PasswordInputProps>;
7
8
  export default PasswordInput;
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from 'react';
2
+ import './ProgressBar.css';
3
+ export type ProgressTone = 'accent' | 'success' | 'danger';
4
+ interface ProgressBarProps {
5
+ value: number;
6
+ max?: number;
7
+ /** Shown next to the track, e.g. "3/10" or "120g / 200g". */
8
+ label?: ReactNode;
9
+ /** Accessible name when there's no visible label saying what is being measured. */
10
+ ariaLabel?: string;
11
+ tone?: ProgressTone;
12
+ size?: 'sm' | 'md';
13
+ className?: string;
14
+ }
15
+ export declare const ProgressBar: ({ value, max, label, ariaLabel, tone, size, className, }: ProgressBarProps) => import("react/jsx-runtime").JSX.Element;
16
+ export default ProgressBar;
@@ -0,0 +1,10 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { ProgressBar } from './ProgressBar';
3
+ declare const meta: Meta<typeof ProgressBar>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof ProgressBar>;
6
+ export declare const Default: Story;
7
+ export declare const Small: Story;
8
+ export declare const Success: Story;
9
+ export declare const Over: Story;
10
+ export declare const WithoutLabel: Story;
@@ -0,0 +1,9 @@
1
+ import './RegisterForm.css';
2
+ interface RegisterFormProps {
3
+ /** Calls the app's register endpoint; a thrown Error's message is shown to the user. */
4
+ onRegister: (email: string) => Promise<void>;
5
+ /** Called after a successful registration instead of showing the "check your email" message, e.g. to navigate. */
6
+ onRegistered?: (email: string) => void;
7
+ }
8
+ export declare const RegisterForm: ({ onRegister, onRegistered }: RegisterFormProps) => import("react/jsx-runtime").JSX.Element;
9
+ export default RegisterForm;
@@ -0,0 +1,7 @@
1
+ import type { SelectHTMLAttributes } from 'react';
2
+ import './Select.css';
3
+ type SelectProps = SelectHTMLAttributes<HTMLSelectElement> & {
4
+ invalid?: boolean;
5
+ };
6
+ export declare const Select: ({ invalid, className, children, ...props }: SelectProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default Select;
@@ -0,0 +1,13 @@
1
+ import type { ReactNode } from 'react';
2
+ import './StatusMessage.css';
3
+ export type StatusKind = 'info' | 'empty' | 'loading' | 'error';
4
+ interface StatusMessageProps {
5
+ kind?: StatusKind;
6
+ /** Draws a tinted box around the text instead of plain colored text. */
7
+ boxed?: boolean;
8
+ /** Defaults to the translated "Loading…" for `kind="loading"`. */
9
+ children?: ReactNode;
10
+ className?: string;
11
+ }
12
+ export declare const StatusMessage: ({ kind, boxed, children, className }: StatusMessageProps) => import("react/jsx-runtime").JSX.Element;
13
+ export default StatusMessage;
@@ -0,0 +1,10 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { StatusMessage } from './StatusMessage';
3
+ declare const meta: Meta<typeof StatusMessage>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof StatusMessage>;
6
+ export declare const Loading: Story;
7
+ export declare const Empty: Story;
8
+ export declare const Error: Story;
9
+ export declare const ErrorBoxed: Story;
10
+ export declare const InfoBoxed: Story;
@@ -0,0 +1,5 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import './Table.css';
3
+ declare const meta: Meta;
4
+ export default meta;
5
+ export declare const Default: StoryObj;
@@ -0,0 +1,19 @@
1
+ import { type ReactNode } from 'react';
2
+ import './Tabs.css';
3
+ export type TabItem<T extends string | number> = {
4
+ value: T;
5
+ label: ReactNode;
6
+ disabled?: boolean;
7
+ };
8
+ interface TabsProps<T extends string | number> {
9
+ items: TabItem<T>[];
10
+ value: T;
11
+ onChange: (value: T) => void;
12
+ /** underline: page sections; pills: filters; segmented: a few mutually exclusive views. */
13
+ variant?: 'underline' | 'pills' | 'segmented';
14
+ /** Accessible name of the tab list. */
15
+ ariaLabel?: string;
16
+ className?: string;
17
+ }
18
+ export declare const Tabs: <T extends string | number>({ items, value, onChange, variant, ariaLabel, className, }: TabsProps<T>) => import("react/jsx-runtime").JSX.Element;
19
+ export default Tabs;
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { Tabs } from './Tabs';
3
+ declare const meta: Meta<typeof Tabs>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof Tabs>;
6
+ export declare const Underline: Story;
7
+ export declare const Pills: Story;
8
+ export declare const Segmented: Story;
@@ -0,0 +1,7 @@
1
+ import type { TextareaHTMLAttributes } from 'react';
2
+ import './Textarea.css';
3
+ type TextareaProps = TextareaHTMLAttributes<HTMLTextAreaElement> & {
4
+ invalid?: boolean;
5
+ };
6
+ export declare const Textarea: ({ invalid, className, rows, ...props }: TextareaProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default Textarea;
@@ -1,9 +1,13 @@
1
- import React from 'react';
1
+ import React, { type ReactNode } from 'react';
2
2
  import './Toggle.css';
3
3
  export interface ToggleProps {
4
4
  checked: boolean;
5
5
  onChange: (checked: boolean) => void;
6
6
  label: string;
7
+ /** Shown between the label and the switch, e.g. a preview of what the setting changes. */
8
+ icons?: ReactNode;
9
+ /** "row": label on the left, switch on the right, full width - for a list of settings. */
10
+ layout?: 'inline' | 'row';
7
11
  }
8
12
  export declare const Toggle: React.FC<ToggleProps>;
9
13
  export default Toggle;
@@ -4,3 +4,4 @@ declare const meta: Meta<typeof Toggle>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof Toggle>;
6
6
  export declare const Default: Story;
7
+ export declare const Row: Story;
@@ -0,0 +1,8 @@
1
+ import './VersionNumber.css';
2
+ interface VersionNumberProps {
3
+ /** Usually the app's own __APP_VERSION__, defined in its vite.config. */
4
+ version: string;
5
+ className?: string;
6
+ }
7
+ export declare const VersionNumber: ({ version, className }: VersionNumberProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default VersionNumber;
@@ -0,0 +1,5 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { VersionNumber } from './VersionNumber';
3
+ declare const meta: Meta<typeof VersionNumber>;
4
+ export default meta;
5
+ export declare const Default: StoryObj<typeof VersionNumber>;
package/dist/index.d.ts CHANGED
@@ -20,3 +20,19 @@ export * from './components/AppAccessGate/AppAccessGate';
20
20
  export * from './components/LanguageSwitcher/LanguageSwitcher';
21
21
  export { createI18n, sgI18n, SUPPORTED_LANGUAGES, LANGUAGE_NAMES, LANGUAGE_COOKIE, readLanguageCookie } from './i18n';
22
22
  export type { SupportedLanguage } from './i18n';
23
+ export * from './components/ProgressBar/ProgressBar';
24
+ export * from './components/StatusMessage/StatusMessage';
25
+ export * from './components/Card/Card';
26
+ export * from './components/Badge/Badge';
27
+ export * from './components/Avatar/Avatar';
28
+ export * from './components/ConfirmModal/ConfirmModal';
29
+ export * from './components/Textarea/Textarea';
30
+ export * from './components/Select/Select';
31
+ export * from './components/FormField/FormField';
32
+ export * from './components/Tabs/Tabs';
33
+ import './components/Table/Table.css';
34
+ export * from './components/VersionNumber/VersionNumber';
35
+ export * from './components/LoginPrompt/LoginPrompt';
36
+ export * from './components/AuthPage/AuthPage';
37
+ export * from './components/RegisterForm/RegisterForm';
38
+ export { ACCESS_TOKEN_COOKIE, getAccessToken, setAccessToken, clearAccessToken, getTokenClaim } from './auth';