@sito/ui 0.1.6 → 0.3.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 (79) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +88 -2
  3. package/dist/components/Button/Button.d.ts +2 -3
  4. package/dist/components/Button/index.d.ts +2 -2
  5. package/dist/components/Button/types.d.ts +33 -6
  6. package/dist/components/Dialog/Dialog.d.ts +7 -0
  7. package/dist/components/Dialog/DialogActions.d.ts +7 -0
  8. package/dist/components/Dialog/constants.d.ts +3 -0
  9. package/dist/components/Dialog/index.d.ts +3 -0
  10. package/dist/components/Dialog/types.d.ts +61 -0
  11. package/dist/components/Dialog/utils.d.ts +19 -0
  12. package/dist/components/IconButton/IconButton.d.ts +2 -3
  13. package/dist/components/IconButton/index.d.ts +2 -2
  14. package/dist/components/IconButton/types.d.ts +21 -5
  15. package/dist/components/index.d.ts +6 -10
  16. package/dist/hooks/index.d.ts +2 -2
  17. package/dist/hooks/useDialog/index.d.ts +2 -0
  18. package/dist/hooks/useDialog/types.d.ts +7 -0
  19. package/dist/hooks/useDialog/useDialog.d.ts +7 -0
  20. package/dist/main.d.ts +4 -3
  21. package/dist/styles.css +398 -0
  22. package/dist/theme.css +83 -0
  23. package/dist/ui.cjs +1 -11
  24. package/dist/ui.d.ts +2 -1
  25. package/dist/ui.js +261 -1732
  26. package/dist/utils/classNames.d.ts +6 -0
  27. package/dist/utils/index.d.ts +1 -0
  28. package/package.json +94 -54
  29. package/dist/components/Button/styles.d.ts +0 -5
  30. package/dist/components/Error/Error.d.ts +0 -3
  31. package/dist/components/Error/Handler.d.ts +0 -3
  32. package/dist/components/Error/index.d.ts +0 -4
  33. package/dist/components/Error/styles.d.ts +0 -4
  34. package/dist/components/Error/types.d.ts +0 -18
  35. package/dist/components/Image/Image.d.ts +0 -3
  36. package/dist/components/Image/index.d.ts +0 -3
  37. package/dist/components/Image/styles.d.ts +0 -9
  38. package/dist/components/Image/types.d.ts +0 -4
  39. package/dist/components/InputControl/Input.d.ts +0 -4
  40. package/dist/components/InputControl/Select.d.ts +0 -4
  41. package/dist/components/InputControl/Textarea.d.ts +0 -4
  42. package/dist/components/InputControl/index.d.ts +0 -5
  43. package/dist/components/InputControl/styles.d.ts +0 -4
  44. package/dist/components/InputControl/types.d.ts +0 -33
  45. package/dist/components/Loading/Loading.d.ts +0 -3
  46. package/dist/components/Loading/index.d.ts +0 -3
  47. package/dist/components/Loading/styles.d.ts +0 -11
  48. package/dist/components/Loading/types.d.ts +0 -8
  49. package/dist/components/Notification/Notification.d.ts +0 -2
  50. package/dist/components/Notification/index.d.ts +0 -3
  51. package/dist/components/Notification/styles.d.ts +0 -9
  52. package/dist/components/Notification/types.d.ts +0 -4
  53. package/dist/components/PrintAfter/PrintAfter.d.ts +0 -4
  54. package/dist/components/PrintAfter/index.d.ts +0 -3
  55. package/dist/components/PrintAfter/types.d.ts +0 -7
  56. package/dist/components/SplashScreen/SplashScreen.d.ts +0 -3
  57. package/dist/components/SplashScreen/index.d.ts +0 -3
  58. package/dist/components/SplashScreen/styles.d.ts +0 -9
  59. package/dist/components/SplashScreen/types.d.ts +0 -9
  60. package/dist/components/Switch/Switch.d.ts +0 -4
  61. package/dist/components/Switch/index.d.ts +0 -3
  62. package/dist/components/Switch/styles.d.ts +0 -4
  63. package/dist/components/Switch/types.d.ts +0 -8
  64. package/dist/hooks/useIsElementInViewport/index.d.ts +0 -5
  65. package/dist/hooks/useScreenHandler/index.d.ts +0 -7
  66. package/dist/lib/Notification.d.ts +0 -11
  67. package/dist/lib/index.d.ts +0 -3
  68. package/dist/main.css +0 -1
  69. package/dist/providers/ModeProvider/ModeProvider.d.ts +0 -3
  70. package/dist/providers/ModeProvider/index.d.ts +0 -2
  71. package/dist/providers/ModeProvider/types.d.ts +0 -10
  72. package/dist/providers/NotificationProvider/NotificationProvider.d.ts +0 -7
  73. package/dist/providers/NotificationProvider/index.d.ts +0 -2
  74. package/dist/providers/NotificationProvider/types.d.ts +0 -20
  75. package/dist/providers/StyleProvider/StyleProvider.d.ts +0 -4
  76. package/dist/providers/StyleProvider/data.d.ts +0 -4
  77. package/dist/providers/StyleProvider/index.d.ts +0 -3
  78. package/dist/providers/StyleProvider/types.d.ts +0 -27
  79. package/dist/providers/index.d.ts +0 -3
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Sito Nimbus
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Sito Nimbus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,2 +1,88 @@
1
- # @sito/ui
2
- React library for easy front end development
1
+ # @sito/ui
2
+
3
+ Low-level React UI primitives for Sito packages and apps.
4
+
5
+ ## Install Styles
6
+
7
+ Styles are optional. Import the full stylesheet when you want the default theme
8
+ and component styles:
9
+
10
+ ```ts
11
+ import "@sito/ui/styles.css";
12
+ ```
13
+
14
+ Import only the theme variables when you want to provide component CSS yourself:
15
+
16
+ ```ts
17
+ import "@sito/ui/theme.css";
18
+ ```
19
+
20
+ ## Public API
21
+
22
+ ```ts
23
+ import { Button, Dialog, DialogActions, IconButton, useDialog } from "@sito/ui";
24
+ ```
25
+
26
+ Exported types include `ButtonProps`, `ButtonSize`, `IconButtonProps`,
27
+ `DialogProps`, `DialogActionsProps`, `DialogState`, `IconButtonSize`, and
28
+ `UseDialogReturn`.
29
+
30
+ ## Button Sizes
31
+
32
+ `Button` supports `size="sm" | "md" | "lg"` for padding and height. `md` is
33
+ the default size.
34
+
35
+ ```tsx
36
+ <Button size="sm">Small</Button>
37
+ <Button size="md">Medium</Button>
38
+ <Button size="lg">Large</Button>
39
+ ```
40
+
41
+ ## Icon Button Sizes
42
+
43
+ `IconButton` supports `size="sm" | "md" | "lg"` for the button container.
44
+ `md` is the default size.
45
+
46
+ ```tsx
47
+ <IconButton aria-label="Add" icon="+" size="sm" />
48
+ <IconButton aria-label="Add" icon="+" size="md" />
49
+ <IconButton aria-label="Add" icon="+" size="lg" />
50
+ ```
51
+
52
+ The container sizes are `28px`, `40px`, and `48px`. Icon size is separate:
53
+ override `iconSize` or `--sito-ui-icon-button-icon-size`.
54
+
55
+ ## Development
56
+
57
+ Run the component test suite with:
58
+
59
+ ```sh
60
+ pnpm test:run
61
+ ```
62
+
63
+ Start Storybook with:
64
+
65
+ ```sh
66
+ pnpm storybook
67
+ ```
68
+
69
+ ## Dialog Exit Transitions
70
+
71
+ `Dialog` unmounts immediately by default. Pass `exitDurationMs` when a consumer
72
+ needs to keep the portal mounted long enough for a CSS exit animation:
73
+
74
+ ```tsx
75
+ <Dialog open={open} onClose={close} exitDurationMs={220}>
76
+ Dialog content
77
+ </Dialog>
78
+ ```
79
+
80
+ During that delay, the backdrop and dialog expose `data-state="closing"` plus
81
+ `sito-ui-dialog-backdrop--closing` and `sito-ui-dialog--closing` classes.
82
+ Use those hooks from consumer CSS to define the actual animation.
83
+
84
+ ## Scope
85
+
86
+ This package only exposes generic primitives. It does not include dashboard
87
+ workflows, forms, translations, icon packs, routing, storage, providers, or data
88
+ fetching.
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
- import { ButtonProps } from "./types";
3
- declare const Button: import("react").ForwardRefExoticComponent<Omit<ButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
1
+ import { ButtonProps } from './types';
2
+ declare const Button: import('react').ForwardRefExoticComponent<ButtonProps & import('react').RefAttributes<HTMLButtonElement>>;
4
3
  export default Button;
@@ -1,3 +1,3 @@
1
- import Button from "./Button";
1
+ import { default as Button } from './Button';
2
+ export type { ButtonBaseProps, ButtonColor, ButtonProps, ButtonSize, ButtonVariant, } from './types';
2
3
  export { Button };
3
- export * from "./types";
@@ -1,8 +1,35 @@
1
- import { HTMLProps } from "react";
2
- import { ColorVariants } from '../../providers/StyleProvider/types';
3
- export type ButtonShapes = "filled" | "outlined" | "text";
4
- export interface ButtonProps extends Omit<HTMLProps<HTMLButtonElement>, "size"> {
5
- color?: ColorVariants | undefined;
6
- shape?: ButtonShapes | undefined;
1
+ import { ButtonHTMLAttributes, ReactNode } from 'react';
2
+ export declare const BUTTON_COLOR_VARIANTS: {
3
+ readonly DEFAULT: "default";
4
+ readonly PRIMARY: "primary";
5
+ readonly SECONDARY: "secondary";
6
+ readonly ERROR: "error";
7
+ readonly WARNING: "warning";
8
+ readonly SUCCESS: "success";
9
+ readonly INFO: "info";
10
+ };
11
+ export declare const BUTTON_VARIANTS: {
12
+ readonly TEXT: "text";
13
+ readonly SUBMIT: "submit";
14
+ readonly OUTLINED: "outlined";
15
+ };
16
+ export declare const BUTTON_SIZES: {
17
+ readonly SM: "sm";
18
+ readonly MD: "md";
19
+ readonly LG: "lg";
20
+ };
21
+ export type ButtonColor = (typeof BUTTON_COLOR_VARIANTS)[keyof typeof BUTTON_COLOR_VARIANTS];
22
+ export type ButtonSize = (typeof BUTTON_SIZES)[keyof typeof BUTTON_SIZES];
23
+ export type ButtonVariant = (typeof BUTTON_VARIANTS)[keyof typeof BUTTON_VARIANTS];
24
+ export type ButtonBaseProps = {
25
+ color?: ButtonColor | undefined;
26
+ size?: ButtonSize | undefined;
27
+ variant?: ButtonVariant | undefined;
28
+ loading?: boolean | undefined;
29
+ loadingIndicator?: ReactNode;
30
+ loadingLabel?: string | undefined;
31
+ [key: `data-${string}`]: string | number | boolean | undefined;
32
+ };
33
+ export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "color" | "type">, ButtonBaseProps {
7
34
  type?: "button" | "submit" | "reset" | undefined;
8
35
  }
@@ -0,0 +1,7 @@
1
+ import { DialogProps } from './types';
2
+ /**
3
+ * Renders an accessible modal dialog in a portal.
4
+ * @param props Dialog configuration and content.
5
+ * @returns The dialog portal when open, otherwise null.
6
+ */
7
+ export declare const Dialog: (props: DialogProps) => import('react').ReactPortal | null;
@@ -0,0 +1,7 @@
1
+ import { DialogActionsProps } from './types';
2
+ /**
3
+ * Renders primary, extra, and cancel actions for a dialog.
4
+ * @param props Action labels, handlers, and button state.
5
+ * @returns The dialog actions container.
6
+ */
7
+ export declare const DialogActions: (props: DialogActionsProps) => import("react").JSX.Element;
@@ -0,0 +1,3 @@
1
+ export declare const focusableInputSelector = "input:not([type=\"hidden\"]):not([disabled]), textarea:not([disabled]), select:not([disabled])";
2
+ export declare const submitSelector = "button[type=\"submit\"]:not([disabled]), input[type=\"submit\"]:not([disabled])";
3
+ export declare const focusableSelector: string;
@@ -0,0 +1,3 @@
1
+ export { Dialog } from './Dialog';
2
+ export { DialogActions } from './DialogActions';
3
+ export type { DialogActionButtonProps, DialogActionsProps, DialogInitialFocus, DialogProps, DialogState, DialogSubmitHandler, } from './types';
@@ -0,0 +1,61 @@
1
+ import { FormEvent, ReactNode } from 'react';
2
+ import { ButtonProps } from '../Button';
3
+ export declare const DIALOG_INITIAL_FOCUS: {
4
+ readonly NONE: "none";
5
+ readonly FIRST_INPUT: "first-input";
6
+ readonly SUBMIT: "submit";
7
+ };
8
+ export type DialogInitialFocus = (typeof DIALOG_INITIAL_FOCUS)[keyof typeof DIALOG_INITIAL_FOCUS];
9
+ export type DialogState = "open" | "closing";
10
+ export type DialogSubmitHandler = (event: FormEvent<HTMLFormElement>) => void | Promise<void>;
11
+ type DialogAccessibleNameProps = {
12
+ title: ReactNode;
13
+ ariaLabel?: string;
14
+ } | {
15
+ title?: undefined;
16
+ ariaLabel: string;
17
+ };
18
+ type DialogBaseProps = {
19
+ dialogId?: string;
20
+ open?: boolean;
21
+ children?: ReactNode;
22
+ onClose: () => void;
23
+ initialFocus?: DialogInitialFocus;
24
+ closeOnBackdropClick?: boolean;
25
+ closeOnEscape?: boolean;
26
+ lockBodyScroll?: boolean;
27
+ onSubmit?: DialogSubmitHandler;
28
+ mobileFullScreen?: boolean;
29
+ containerClassName?: string;
30
+ className?: string;
31
+ closeLabel?: string;
32
+ closeIcon?: ReactNode;
33
+ showCloseButton?: boolean;
34
+ portalContainer?: Element | DocumentFragment | null;
35
+ exitDurationMs?: number;
36
+ onExitComplete?: () => void;
37
+ };
38
+ export type DialogProps = DialogBaseProps & DialogAccessibleNameProps;
39
+ export type DialogActionButtonProps = ButtonProps & {
40
+ id: string;
41
+ };
42
+ export type DialogActionsProps = {
43
+ primaryText: ReactNode;
44
+ cancelText: ReactNode;
45
+ onPrimaryClick?: () => void;
46
+ onCancel: () => void;
47
+ isLoading?: boolean;
48
+ loadingIndicator?: ReactNode;
49
+ disabled?: boolean;
50
+ primaryType?: "button" | "submit" | "reset";
51
+ containerClassName?: string;
52
+ primaryClassName?: string;
53
+ cancelClassName?: string;
54
+ alignEnd?: boolean;
55
+ primaryName?: string;
56
+ primaryAriaLabel?: string;
57
+ cancelName?: string;
58
+ cancelAriaLabel?: string;
59
+ extraActions?: DialogActionButtonProps[];
60
+ };
61
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Prevents document body scrolling while a dialog is open.
3
+ */
4
+ export declare const lockBodyScroll: () => void;
5
+ /**
6
+ * Restores document body scrolling after dialogs close.
7
+ */
8
+ export declare const unlockBodyScroll: () => void;
9
+ /**
10
+ * Finds enabled focusable descendants inside an element.
11
+ * @param element Root element to search inside.
12
+ * @returns Focusable descendants that are not aria-disabled.
13
+ */
14
+ export declare const getFocusableElements: (element: HTMLElement) => HTMLElement[];
15
+ /**
16
+ * Gets the active element when it is an HTMLElement.
17
+ * @returns Active HTMLElement, or null when unavailable.
18
+ */
19
+ export declare const getActiveElement: () => HTMLElement | null;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
- import { IconButtonProps } from "./types";
3
- declare const IconButton: import("react").ForwardRefExoticComponent<Omit<IconButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
1
+ import { IconButtonProps } from './types';
2
+ declare const IconButton: import('react').ForwardRefExoticComponent<IconButtonProps & import('react').RefAttributes<HTMLButtonElement>>;
4
3
  export default IconButton;
@@ -1,3 +1,3 @@
1
- import IconButton from "./IconButton";
2
- export type { IconButtonProps } from "./types";
1
+ import { default as IconButton } from './IconButton';
2
+ export type { IconButtonProps, IconButtonSize } from './types';
3
3
  export { IconButton };
@@ -1,6 +1,22 @@
1
- import { ReactNode } from "react";
2
- import { ButtonProps } from '../Button/';
3
- export interface IconButtonProps extends ButtonProps {
1
+ import { ReactNode } from 'react';
2
+ import { ButtonProps } from '../Button';
3
+ export declare const ICON_BUTTON_SIZES: {
4
+ readonly SM: "sm";
5
+ readonly MD: "md";
6
+ readonly LG: "lg";
7
+ };
8
+ export type IconButtonSize = (typeof ICON_BUTTON_SIZES)[keyof typeof ICON_BUTTON_SIZES];
9
+ type IconButtonAccessibleLabelProps = {
10
+ "aria-label": string;
11
+ children?: ReactNode;
12
+ } | {
13
+ "aria-label"?: string;
14
+ children: ReactNode;
15
+ };
16
+ export type IconButtonProps = Omit<ButtonProps, "aria-label" | "children" | "size"> & IconButtonAccessibleLabelProps & {
4
17
  icon: ReactNode;
5
- size: "small" | "normal" | "large";
6
- }
18
+ iconClassName?: string;
19
+ iconSize?: number | string;
20
+ size?: IconButtonSize;
21
+ };
22
+ export {};
@@ -1,10 +1,6 @@
1
- export * from './Button/';
2
- export * from "./IconButton";
3
- export * from "./InputControl";
4
- export * from "./Switch/";
5
- export * from "./Image";
6
- export * from "./PrintAfter";
7
- export * from "./Notification";
8
- export * from "./Loading";
9
- export * from "./SplashScreen";
10
- export * from "./Error";
1
+ export type { ButtonBaseProps, ButtonColor, ButtonProps, ButtonSize, ButtonVariant, } from './Button';
2
+ export { Button } from './Button';
3
+ export type { DialogActionButtonProps, DialogActionsProps, DialogInitialFocus, DialogProps, DialogState, DialogSubmitHandler, } from './Dialog';
4
+ export { Dialog, DialogActions } from './Dialog';
5
+ export type { IconButtonProps, IconButtonSize } from './IconButton';
6
+ export { IconButton } from './IconButton';
@@ -1,2 +1,2 @@
1
- export * from "./useIsElementInViewport";
2
- export * from "./useScreenHandler";
1
+ export type { UseDialogReturn } from './useDialog';
2
+ export { useDialog } from './useDialog';
@@ -0,0 +1,2 @@
1
+ export type { UseDialogReturn } from './types';
2
+ export { useDialog } from './useDialog';
@@ -0,0 +1,7 @@
1
+ import { Dispatch, SetStateAction } from 'react';
2
+ export type UseDialogReturn = {
3
+ open: boolean;
4
+ setOpen: Dispatch<SetStateAction<boolean>>;
5
+ handleOpen: () => void;
6
+ handleClose: () => void;
7
+ };
@@ -0,0 +1,7 @@
1
+ import { UseDialogReturn } from './types';
2
+ /**
3
+ * Manages dialog open state and common open/close handlers.
4
+ * @param initialOpen Initial open state for the dialog.
5
+ * @returns Current state and helpers to update it.
6
+ */
7
+ export declare const useDialog: (initialOpen?: boolean) => UseDialogReturn;
package/dist/main.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from "./components";
2
- export * from "./providers";
3
- export * from "./hooks";
1
+ export type { ButtonBaseProps, ButtonColor, ButtonProps, ButtonSize, ButtonVariant, DialogActionButtonProps, DialogActionsProps, DialogInitialFocus, DialogProps, DialogState, DialogSubmitHandler, IconButtonProps, IconButtonSize, } from './components';
2
+ export { Button, Dialog, DialogActions, IconButton } from './components';
3
+ export type { UseDialogReturn } from './hooks';
4
+ export { useDialog } from './hooks';