addon-ui 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 (129) hide show
  1. package/README.md +1197 -0
  2. package/package.json +113 -0
  3. package/src/components/Avatar/Avatar.tsx +56 -0
  4. package/src/components/Avatar/avatar.module.scss +78 -0
  5. package/src/components/Avatar/index.ts +2 -0
  6. package/src/components/Avatar/types.ts +11 -0
  7. package/src/components/BaseButton/BaseButton.tsx +36 -0
  8. package/src/components/BaseButton/base-button.module.scss +24 -0
  9. package/src/components/BaseButton/index.ts +1 -0
  10. package/src/components/Button/Button.tsx +51 -0
  11. package/src/components/Button/button.module.scss +140 -0
  12. package/src/components/Button/index.ts +2 -0
  13. package/src/components/Button/types.ts +24 -0
  14. package/src/components/Checkbox/Checkbox.tsx +58 -0
  15. package/src/components/Checkbox/checkbox.module.scss +82 -0
  16. package/src/components/Checkbox/index.ts +2 -0
  17. package/src/components/Checkbox/types.ts +15 -0
  18. package/src/components/Dialog/Dialog.tsx +126 -0
  19. package/src/components/Dialog/dialog.module.scss +55 -0
  20. package/src/components/Dialog/index.ts +1 -0
  21. package/src/components/Drawer/Drawer.tsx +53 -0
  22. package/src/components/Drawer/drawer.module.scss +170 -0
  23. package/src/components/Drawer/index.ts +2 -0
  24. package/src/components/Drawer/types.ts +6 -0
  25. package/src/components/Footer/Footer.tsx +59 -0
  26. package/src/components/Footer/footer.module.scss +45 -0
  27. package/src/components/Footer/index.ts +1 -0
  28. package/src/components/Header/Header.tsx +74 -0
  29. package/src/components/Header/header.module.scss +56 -0
  30. package/src/components/Header/index.ts +1 -0
  31. package/src/components/Highlight/Highlight.tsx +36 -0
  32. package/src/components/Highlight/highlight.module.scss +48 -0
  33. package/src/components/Highlight/index.ts +2 -0
  34. package/src/components/Highlight/types.ts +5 -0
  35. package/src/components/Icon/Icon.tsx +46 -0
  36. package/src/components/Icon/icon.module.scss +17 -0
  37. package/src/components/Icon/index.ts +1 -0
  38. package/src/components/IconButton/IconButton.tsx +50 -0
  39. package/src/components/IconButton/icon-button.module.scss +86 -0
  40. package/src/components/IconButton/index.ts +2 -0
  41. package/src/components/IconButton/types.ts +17 -0
  42. package/src/components/Layout/Provider.tsx +60 -0
  43. package/src/components/Layout/context.ts +24 -0
  44. package/src/components/Layout/index.ts +2 -0
  45. package/src/components/Layout/layout.module.scss +17 -0
  46. package/src/components/List/List.tsx +24 -0
  47. package/src/components/List/index.ts +1 -0
  48. package/src/components/List/list.module.scss +8 -0
  49. package/src/components/ListItem/ListItem.tsx +75 -0
  50. package/src/components/ListItem/index.ts +1 -0
  51. package/src/components/ListItem/list-item.module.scss +37 -0
  52. package/src/components/Modal/Modal.tsx +90 -0
  53. package/src/components/Modal/index.ts +2 -0
  54. package/src/components/Modal/modal.module.scss +97 -0
  55. package/src/components/Modal/types.ts +6 -0
  56. package/src/components/Odometer/Odometer.tsx +45 -0
  57. package/src/components/Odometer/hooks/useOdometer.tsx +24 -0
  58. package/src/components/Odometer/index.ts +2 -0
  59. package/src/components/Odometer/odometer.module.scss +81 -0
  60. package/src/components/Odometer/odometr.d.ts +9 -0
  61. package/src/components/ScrollArea/ScrollArea.tsx +75 -0
  62. package/src/components/ScrollArea/index.ts +1 -0
  63. package/src/components/ScrollArea/scroll-area.module.scss +58 -0
  64. package/src/components/SvgSprite/SvgSprite.tsx +21 -0
  65. package/src/components/SvgSprite/index.ts +1 -0
  66. package/src/components/Switch/Switch.tsx +24 -0
  67. package/src/components/Switch/index.ts +1 -0
  68. package/src/components/Switch/switch.module.scss +65 -0
  69. package/src/components/Tag/Tag.tsx +50 -0
  70. package/src/components/Tag/index.ts +2 -0
  71. package/src/components/Tag/tag.module.scss +118 -0
  72. package/src/components/Tag/types.ts +23 -0
  73. package/src/components/TextArea/TextArea.tsx +126 -0
  74. package/src/components/TextArea/index.ts +2 -0
  75. package/src/components/TextArea/text-area.module.scss +88 -0
  76. package/src/components/TextArea/types.ts +18 -0
  77. package/src/components/TextField/TextField.tsx +139 -0
  78. package/src/components/TextField/index.ts +2 -0
  79. package/src/components/TextField/text-field.module.scss +129 -0
  80. package/src/components/TextField/types.ts +24 -0
  81. package/src/components/Toast/Toast.tsx +124 -0
  82. package/src/components/Toast/index.ts +2 -0
  83. package/src/components/Toast/toast.module.scss +267 -0
  84. package/src/components/Toast/types.ts +20 -0
  85. package/src/components/Tooltip/Tooltip.tsx +82 -0
  86. package/src/components/Tooltip/index.ts +1 -0
  87. package/src/components/Tooltip/tooltip.module.scss +123 -0
  88. package/src/components/View/View.tsx +68 -0
  89. package/src/components/View/index.ts +1 -0
  90. package/src/components/View/view.module.scss +38 -0
  91. package/src/components/ViewDrawer/ViewDrawer.tsx +24 -0
  92. package/src/components/ViewDrawer/index.ts +1 -0
  93. package/src/components/ViewModal/ViewModal.tsx +24 -0
  94. package/src/components/ViewModal/index.ts +1 -0
  95. package/src/components/index.ts +27 -0
  96. package/src/components/types.ts +65 -0
  97. package/src/config/default.ts +3 -0
  98. package/src/config/index.ts +8 -0
  99. package/src/declaration.d.ts +8 -0
  100. package/src/index.ts +3 -0
  101. package/src/plugin/builder/ConfigBuilder.ts +32 -0
  102. package/src/plugin/builder/StyleBuilder.ts +35 -0
  103. package/src/plugin/builder/virtual.config.ts +5 -0
  104. package/src/plugin/finder/ConfigFinder.ts +26 -0
  105. package/src/plugin/finder/Finder.ts +76 -0
  106. package/src/plugin/finder/StyleFinder.ts +23 -0
  107. package/src/plugin/index.ts +73 -0
  108. package/src/plugin/types.ts +8 -0
  109. package/src/providers/extra/ExtraProvider.tsx +13 -0
  110. package/src/providers/extra/context.ts +14 -0
  111. package/src/providers/extra/index.ts +2 -0
  112. package/src/providers/icons/IconsProvider.tsx +35 -0
  113. package/src/providers/icons/context.ts +20 -0
  114. package/src/providers/icons/index.ts +2 -0
  115. package/src/providers/index.ts +4 -0
  116. package/src/providers/theme/ThemeProvider.tsx +60 -0
  117. package/src/providers/theme/ThemeStorage.tsx +36 -0
  118. package/src/providers/theme/context.ts +30 -0
  119. package/src/providers/theme/index.ts +3 -0
  120. package/src/providers/ui/UIProvider.tsx +41 -0
  121. package/src/providers/ui/index.ts +1 -0
  122. package/src/providers/ui/styles/default.scss +95 -0
  123. package/src/providers/ui/styles/reset.scss +127 -0
  124. package/src/styles/mixins.scss +23 -0
  125. package/src/types/config.ts +15 -0
  126. package/src/types/theme.ts +11 -0
  127. package/src/utils/index.ts +2 -0
  128. package/src/utils/react.ts +21 -0
  129. package/src/utils/utils.ts +12 -0
@@ -0,0 +1,36 @@
1
+ import React, {FC, memo} from "react";
2
+ import classnames from "classnames";
3
+ import Highlighter, {HighlighterProps} from "react-highlight-words";
4
+
5
+ import {useComponentProps} from "../../providers";
6
+
7
+ import {HighlightColor} from "./types";
8
+
9
+ import styles from "./highlight.module.scss";
10
+
11
+ export interface HighlightProps extends HighlighterProps {
12
+ color?: HighlightColor;
13
+ }
14
+
15
+ const Highlight: FC<HighlightProps> = props => {
16
+ const {color, activeClassName, highlightClassName, ...other} = {
17
+ ...useComponentProps("highlight"),
18
+ ...props,
19
+ };
20
+
21
+ return (
22
+ <Highlighter
23
+ highlightClassName={classnames(
24
+ styles["highlight"],
25
+ {
26
+ [styles[`highlight--${color}-color`]]: color,
27
+ },
28
+ highlightClassName
29
+ )}
30
+ activeClassName={classnames(styles["highlight--active"], activeClassName)}
31
+ {...other}
32
+ />
33
+ );
34
+ };
35
+
36
+ export default memo(Highlight);
@@ -0,0 +1,48 @@
1
+ $root: highlight;
2
+
3
+ .#{$root} {
4
+ font-size: var(--highlight-font-size, inherit);
5
+ font-weight: var(--highlight-font-weight, inherit);
6
+ font-family: var(--highlight-font-family, inherit), sans-serif;
7
+ line-height: var(--highlight-line-height, var(--line-height, 1 rem));
8
+ color: var(--highlight-color, #fff);
9
+ background-color: var(--highlight-bg-color, #ffd60a);
10
+ padding: var(--highlight-y-padding, 2px) var(--highlight-x-padding, 3px);
11
+ margin: 0 calc(-1 * var(--highlight-x-padding, 3px));
12
+ border-radius: var(--highlight-border-radius, 2px);
13
+
14
+ &--primary-color {
15
+ color: var(--highlight-primary-color, #fff);
16
+ background-color: var(--primary-color);
17
+ }
18
+
19
+ &--secondary-color {
20
+ color: var(--highlight-secondary-color, #fff);
21
+ background-color: var(--secondary-color);
22
+ }
23
+
24
+ &--accent-color {
25
+ color: var(--highlight-accent-color, #fff);
26
+ background-color: var(--accent-color);
27
+ }
28
+
29
+ &--active {
30
+ color: var(--highlight-active-color, var(--highlight-color, #fff));
31
+ background-color: var(--highlight-active-bg-color, #ff801f);
32
+
33
+ &.#{$root}--primary-color {
34
+ color: var(--highlight-active-primary-color, var(--highlight-primary-color, #fff));
35
+ background-color: color-mix(in srgb, black 40%, var(--primary-color));
36
+ }
37
+
38
+ &.#{$root}--secondary-color {
39
+ color: var(--highlight-active-secondary-color, var(--highlight-secondary-color, #fff));
40
+ background-color: color-mix(in srgb, black 40%, var(--secondary-color));
41
+ }
42
+
43
+ &.#{$root}--accent-color {
44
+ color: var(--highlight-active-accent-color, var(--highlight-accent-color, #fff));
45
+ background-color: color-mix(in srgb, black 40%, var(--accent-color));
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export {default as Highlight, type HighlightProps} from "./Highlight";
@@ -0,0 +1,5 @@
1
+ export enum HighlightColor {
2
+ Primary = "primary",
3
+ Secondary = "secondary",
4
+ Accent = "accent",
5
+ }
@@ -0,0 +1,46 @@
1
+ import React, {memo, useEffect, ComponentProps, forwardRef, ForwardRefRenderFunction} from "react";
2
+ import classnames from "classnames";
3
+ import {useComponentProps, useIcons} from "../../providers";
4
+
5
+ import styles from "./icon.module.scss";
6
+
7
+ export interface IconProps extends ComponentProps<"svg"> {
8
+ name: string;
9
+ size?: number;
10
+ }
11
+
12
+ const Icon: ForwardRefRenderFunction<SVGSVGElement, IconProps> = (props, ref) => {
13
+ const {
14
+ name,
15
+ className,
16
+ size = 24,
17
+ width = size,
18
+ height = size,
19
+ ...other
20
+ } = {...useComponentProps("icon"), ...props};
21
+
22
+ const {icons, registerIcon} = useIcons();
23
+
24
+ useEffect(() => icons[name] && registerIcon(name), [name, icons, registerIcon]);
25
+
26
+ if (!icons[name]) {
27
+ console.warn(`Icon "${name}" not found.`);
28
+
29
+ return (
30
+ <span
31
+ className={styles["icon--default"]}
32
+ style={{fontSize: `${width}px`, lineHeight: `${width}px`, width, height}}
33
+ >
34
+
35
+ </span>
36
+ );
37
+ }
38
+
39
+ return (
40
+ <svg ref={ref} className={classnames(styles["icon"], className)} width={width} height={height} {...other}>
41
+ <use href={`#${name}`} />
42
+ </svg>
43
+ );
44
+ };
45
+
46
+ export default memo(forwardRef(Icon));
@@ -0,0 +1,17 @@
1
+ .icon {
2
+ color: var(--icon-color);
3
+ transition:
4
+ transform var(--transition-speed-sm),
5
+ color var(--transition-speed-sm);
6
+
7
+ &:hover {
8
+ color: var(--icon-color-hover);
9
+ transform: scale(var(--icon-scale, 1));
10
+ }
11
+
12
+ &--default {
13
+ display: flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ export {default as Icon, type IconProps} from "./Icon";
@@ -0,0 +1,50 @@
1
+ import React, {memo, forwardRef, ForwardRefRenderFunction} from "react";
2
+ import classnames from "classnames";
3
+
4
+ import {Tooltip, TooltipProps} from "../Tooltip";
5
+ import {BaseButton, BaseButtonProps} from "../BaseButton";
6
+
7
+ import {useComponentProps} from "../../providers";
8
+
9
+ import {IconButtonVariant, IconButtonSize, IconButtonRadius} from "./types";
10
+
11
+ import styles from "./icon-button.module.scss";
12
+
13
+ export interface IconButtonProps extends BaseButtonProps {
14
+ size?: IconButtonSize;
15
+ radius?: IconButtonRadius;
16
+ variant?: IconButtonVariant;
17
+ tooltip?: Omit<TooltipProps, "children">;
18
+ }
19
+
20
+ const IconButton: ForwardRefRenderFunction<HTMLButtonElement, IconButtonProps> = (props, ref) => {
21
+ const {size, radius, variant, tooltip, className, children, ...other} = {
22
+ ...useComponentProps("iconButton"),
23
+ ...props,
24
+ };
25
+
26
+ const iconButton = (
27
+ <BaseButton
28
+ ref={ref}
29
+ {...other}
30
+ className={classnames(
31
+ styles["icon-button"],
32
+ {
33
+ [styles[`icon-button--${variant}`]]: variant,
34
+ [styles[`icon-button--${size}-size`]]: size,
35
+ [styles[`icon-button--${radius}-radius`]]: radius,
36
+ },
37
+ className
38
+ )}
39
+ >
40
+ {children}
41
+ </BaseButton>
42
+ );
43
+ if (tooltip) {
44
+ return <Tooltip {...tooltip}>{iconButton}</Tooltip>;
45
+ }
46
+
47
+ return iconButton;
48
+ };
49
+
50
+ export default memo(forwardRef(IconButton));
@@ -0,0 +1,86 @@
1
+ $root: icon-button;
2
+
3
+ .#{$root} {
4
+ border-radius: var(--icon-button-border-radius, 100%);
5
+ padding: var(--icon-button-padding, 5px);
6
+ width: var(--icon-button-size, 25px);
7
+ height: var(--icon-button-size, 25px);
8
+ color: var(--icon-button-color);
9
+ background: none;
10
+
11
+ &:hover:not(:disabled) {
12
+ color: var(--icon-button-color-hover);
13
+ }
14
+
15
+ &:active:not(:disabled) {
16
+ transform: scale(var(--icon-button-scale, 0.95));
17
+ }
18
+
19
+ &:disabled {
20
+ opacity: var(--icon-button-disabled-opacity, 0.75);
21
+ cursor: default;
22
+ }
23
+
24
+ // Variants
25
+ &--contained {
26
+ color: var(--icon-button-contained-color, var(--icon-button-color));
27
+ background: var(--icon-button-contained-bg-color, var(--icon-button-bg-color));
28
+
29
+ &:hover:not(:disabled) {
30
+ color: var(--icon-button-contained-color-hover, var(--icon-button-color-hover));
31
+ background-color: var(--icon-button-contained-bg-color-hover, var(--icon-button-bg-color-hover));
32
+ }
33
+ }
34
+
35
+ &--outlined {
36
+ color: var(--icon-button-outlined-color, var(--icon-button-color));
37
+ border-width: var(--icon-button-border-width, 1px);
38
+ border-color: var(--icon-button-border-color);
39
+ border-style: solid;
40
+ background: none;
41
+
42
+ &:hover:not(:disabled) {
43
+ color: var(--icon-button-outlined-color-hover, var(--icon-button-color-hover));
44
+ background-color: var(--icon-button-outlined-bg-color-hover, var(--icon-button-bg-color-hover));
45
+ }
46
+ }
47
+
48
+ &--ghost {
49
+ color: var(--icon-button-ghost-color, var(--icon-button-color));
50
+ background-color: transparent;
51
+
52
+ &:hover:not(:disabled) {
53
+ color: var(--icon-button-ghost-color-hover, var(--icon-button-color-hover));
54
+ background-color: var(--icon-button-ghost-bg-color-hover, var(--icon-button-bg-color-hover));
55
+ }
56
+ }
57
+
58
+ // Sizes
59
+ &--small-size {
60
+ width: var(--icon-button-size-sm, 20px);
61
+ height: var(--icon-button-size-sm, 20px);
62
+ }
63
+
64
+ &--medium-size {
65
+ width: var(--icon-button-size-md, 35px);
66
+ height: var(--icon-button-size-md, 35px);
67
+ }
68
+
69
+ &--large-size {
70
+ width: var(--icon-button-size-lg, 45px);
71
+ height: var(--icon-button-size-lg, 45px);
72
+ }
73
+
74
+ //Radius
75
+ &--small-radius {
76
+ border-radius: var(--icon-button-border-radius-sm, 20%);
77
+ }
78
+
79
+ &--medium-radius {
80
+ border-radius: var(--icon-button-border-radius-md, 30%);
81
+ }
82
+
83
+ &--large-radius {
84
+ border-radius: var(--icon-button-border-radius-lg, 40%);
85
+ }
86
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export {default as IconButton, type IconButtonProps} from "./IconButton";
@@ -0,0 +1,17 @@
1
+ export enum IconButtonVariant {
2
+ Contained = "contained",
3
+ Outlined = "outlined",
4
+ Ghost = "ghost",
5
+ }
6
+
7
+ export enum IconButtonSize {
8
+ Small = "small",
9
+ Medium = "medium",
10
+ Large = "large",
11
+ }
12
+
13
+ export enum IconButtonRadius {
14
+ Small = "small",
15
+ Medium = "medium",
16
+ Large = "large",
17
+ }
@@ -0,0 +1,60 @@
1
+ import React, {
2
+ ComponentProps,
3
+ forwardRef,
4
+ ForwardRefRenderFunction,
5
+ PropsWithChildren,
6
+ useCallback,
7
+ useState,
8
+ } from "react";
9
+
10
+ import {expandType, LayoutContext} from "./context";
11
+
12
+ import classnames from "classnames";
13
+
14
+ import styles from "./layout.module.scss";
15
+
16
+ export type LayoutProps = ComponentProps<"div">;
17
+
18
+ const Provider: ForwardRefRenderFunction<HTMLDivElement, PropsWithChildren<LayoutProps>> = (
19
+ {children, className, style, ...props},
20
+ ref
21
+ ) => {
22
+ const [isExpanded, setExpanded] = useState(false);
23
+ const [height, setHeight] = useState<number | string | undefined>(undefined);
24
+ const [width, setWidth] = useState<number | string | undefined>(undefined);
25
+
26
+ const expand = useCallback((value?: expandType) => {
27
+ setHeight(value?.height);
28
+ setWidth(value?.width);
29
+ setExpanded(true);
30
+ }, []);
31
+
32
+ const collapse = useCallback(() => {
33
+ setHeight(undefined);
34
+ setWidth(undefined);
35
+ setExpanded(false);
36
+ }, []);
37
+
38
+ return (
39
+ <LayoutContext.Provider value={{isExpanded, expand, collapse}}>
40
+ <div
41
+ ref={ref}
42
+ style={{minHeight: height, minWidth: width, ...style}}
43
+ className={classnames(
44
+ styles["layout"],
45
+ {
46
+ [styles["layout--expanded"]]: isExpanded,
47
+ },
48
+ className
49
+ )}
50
+ {...props}
51
+ >
52
+ {children}
53
+ </div>
54
+ </LayoutContext.Provider>
55
+ );
56
+ };
57
+
58
+ Provider.displayName = "ViewportProvider";
59
+
60
+ export default forwardRef(Provider);
@@ -0,0 +1,24 @@
1
+ import {createContext, useContext} from "react";
2
+
3
+ export type expandType = {
4
+ height?: number | string;
5
+ width?: number | string;
6
+ };
7
+
8
+ export interface LayoutContract {
9
+ isExpanded?: boolean;
10
+
11
+ expand(value?: expandType): void;
12
+
13
+ collapse(): void;
14
+ }
15
+
16
+ export const LayoutContext = createContext<LayoutContract>({
17
+ isExpanded: false,
18
+ expand() {},
19
+ collapse() {},
20
+ });
21
+
22
+ LayoutContext.displayName = "LayoutContext";
23
+
24
+ export const useLayout = () => useContext(LayoutContext);
@@ -0,0 +1,2 @@
1
+ export {default as LayoutProvider, type LayoutProps} from "./Provider";
2
+ export {useLayout} from "./context";
@@ -0,0 +1,17 @@
1
+ .layout {
2
+ display: flex;
3
+ flex-direction: column;
4
+ overflow: hidden;
5
+ min-width: var(--min-width);
6
+ max-width: var(--max-width);
7
+ min-height: var(--min-height);
8
+ max-height: var(--max-height);
9
+ transition:
10
+ min-height var(--transition-speed-md) ease-in-out,
11
+ min-width var(--transition-speed-md) ease-in-out;
12
+
13
+ &--expanded {
14
+ min-height: var(--max-height);
15
+ min-width: var(--max-width);
16
+ }
17
+ }
@@ -0,0 +1,24 @@
1
+ import React, {ComponentProps, forwardRef, memo, ReactElement} from "react";
2
+ import classnames from "classnames";
3
+
4
+ import {useComponentProps} from "../../providers";
5
+
6
+ import {ListItemProps} from "../ListItem";
7
+
8
+ import styles from "./list.module.scss";
9
+
10
+ export interface ListProps extends Omit<ComponentProps<"ul">, "children"> {
11
+ children: ReactElement<ListItemProps> | ReactElement<ListItemProps>[];
12
+ }
13
+
14
+ const List = forwardRef<HTMLUListElement, ListProps>((props, ref) => {
15
+ const {children, className, ...other} = {...useComponentProps("list"), ...props};
16
+
17
+ return (
18
+ <ul {...other} ref={ref} className={classnames(styles["list"], className)}>
19
+ {children}
20
+ </ul>
21
+ );
22
+ });
23
+
24
+ export default memo(List);
@@ -0,0 +1 @@
1
+ export {default as List, type ListProps} from "./List";
@@ -0,0 +1,8 @@
1
+ .list {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 10px;
5
+ padding: 0;
6
+ margin: 0;
7
+ list-style: none;
8
+ }
@@ -0,0 +1,75 @@
1
+ import React, {ComponentProps, forwardRef, JSX, memo, ReactNode} from "react";
2
+ import classnames from "classnames";
3
+
4
+ import {cloneOrCreateElement} from "../../utils";
5
+ import {useComponentProps} from "../../providers";
6
+
7
+ import styles from "./list-item.module.scss";
8
+
9
+ type TagType = keyof JSX.IntrinsicElements;
10
+ export type ListItemType = HTMLLIElement;
11
+
12
+ export interface ListItemProps extends ComponentProps<"li"> {
13
+ left?: ReactNode;
14
+ right?: ReactNode;
15
+ primary?: ReactNode;
16
+ secondary?: ReactNode;
17
+ leftTag?: TagType;
18
+ rightTag?: TagType;
19
+ primaryTag?: TagType;
20
+ secondaryTag?: TagType;
21
+ primaryClassName?: string;
22
+ secondaryClassName?: string;
23
+ centerClassName?: string;
24
+ leftClassName?: string;
25
+ rightClassName?: string;
26
+ }
27
+
28
+ const ListItem = forwardRef<ListItemType, ListItemProps>((props, ref) => {
29
+ const {
30
+ left,
31
+ right,
32
+ primary,
33
+ secondary,
34
+ leftTag = "div",
35
+ rightTag = "div",
36
+ primaryTag = "div",
37
+ secondaryTag = "div",
38
+ children,
39
+ className,
40
+ leftClassName,
41
+ rightClassName,
42
+ centerClassName,
43
+ primaryClassName,
44
+ secondaryClassName,
45
+ role = "list-item",
46
+ ...other
47
+ } = {...useComponentProps("listItem"), ...props};
48
+
49
+ return (
50
+ <li {...other} ref={ref} role={role} className={classnames(styles["list-item"], className)}>
51
+ {cloneOrCreateElement(left, {className: classnames(styles["list-item__left"], leftClassName)}, leftTag)}
52
+
53
+ {(primary || secondary) && (
54
+ <div className={classnames(styles["list-item__center"], centerClassName)}>
55
+ {cloneOrCreateElement(
56
+ primary,
57
+ {className: classnames(styles["list-item__primary"], primaryClassName)},
58
+ primaryTag
59
+ )}
60
+ {cloneOrCreateElement(
61
+ secondary,
62
+ {className: classnames(styles["list-item__secondary"], secondaryClassName)},
63
+ secondaryTag
64
+ )}
65
+ </div>
66
+ )}
67
+
68
+ {cloneOrCreateElement(right, {className: classnames(styles["list-item__right"], rightClassName)}, rightTag)}
69
+
70
+ {children}
71
+ </li>
72
+ );
73
+ });
74
+
75
+ export default memo(ListItem);
@@ -0,0 +1 @@
1
+ export {default as ListItem, type ListItemProps, type ListItemType} from "./ListItem";
@@ -0,0 +1,37 @@
1
+ .list-item {
2
+ display: flex;
3
+ flex-direction: row;
4
+ align-items: center;
5
+ gap: 10px;
6
+ flex-wrap: nowrap;
7
+ box-sizing: border-box;
8
+ line-height: var(--list-item-line-height, var(--line-height, 1 rem));
9
+
10
+ &__center {
11
+ flex-grow: 1;
12
+ display: flex;
13
+ overflow: hidden;
14
+ flex-direction: column;
15
+ justify-content: center;
16
+ }
17
+
18
+ &__primary,
19
+ &__secondary {
20
+ overflow: hidden;
21
+ white-space: nowrap;
22
+ text-overflow: ellipsis;
23
+ }
24
+ &__primary {
25
+ color: var(--list-item-primary-color, var(--text-primary-color));
26
+ }
27
+ &__secondary {
28
+ color: var(--list-item-secondary-color, var(--text-secondary-color));
29
+ }
30
+
31
+ &__left,
32
+ &__right {
33
+ display: flex;
34
+ align-items: center;
35
+ justify-content: center;
36
+ }
37
+ }
@@ -0,0 +1,90 @@
1
+ import React, {isValidElement, memo, ReactElement, useCallback, forwardRef, ForwardRefRenderFunction} from "react";
2
+ import classnames from "classnames";
3
+
4
+ import {useComponentProps} from "../../providers";
5
+ import {cloneOrCreateElement} from "../../utils";
6
+
7
+ import {Dialog, DialogProps, dialogPropsKeys} from "../Dialog";
8
+ import {IconButton, IconButtonProps} from "../IconButton";
9
+
10
+ import {ModalRadius} from "./types";
11
+
12
+ import styles from "./modal.module.scss";
13
+
14
+ export interface ModalProps extends DialogProps {
15
+ radius?: ModalRadius;
16
+ closeButton?: boolean | IconButtonProps | ReactElement;
17
+ onClose?: () => void;
18
+ }
19
+
20
+ export const modalPropsKeys = new Set<keyof ModalProps>(["radius", "closeButton", "onClose", ...dialogPropsKeys]);
21
+
22
+ const Modal: ForwardRefRenderFunction<HTMLDivElement, ModalProps> = (props, ref) => {
23
+ const {
24
+ radius,
25
+ fullscreen = true,
26
+ closeButton = true,
27
+ onClose,
28
+ onOpenChange,
29
+ children,
30
+ className,
31
+ overlayClassName,
32
+ childrenClassName,
33
+ ...other
34
+ } = {...useComponentProps("modal"), ...props};
35
+
36
+ const handleClose = useCallback(
37
+ (event: React.MouseEvent<HTMLButtonElement>) => {
38
+ onClose?.();
39
+ onOpenChange?.(false);
40
+ if (typeof closeButton === "object" && !isValidElement(closeButton)) {
41
+ closeButton?.onClick?.(event);
42
+ }
43
+ },
44
+ [onClose, onOpenChange, closeButton]
45
+ );
46
+
47
+ const renderCloseButton = useCallback(() => {
48
+ if (!closeButton) return null;
49
+
50
+ if (isValidElement(closeButton)) return closeButton;
51
+
52
+ const closeButtonProps = typeof closeButton === "object" ? closeButton : {};
53
+
54
+ return (
55
+ <IconButton
56
+ aria-label="Close"
57
+ children="✖"
58
+ {...closeButtonProps}
59
+ onClick={handleClose}
60
+ className={classnames(styles["modal-close"], closeButtonProps.className)}
61
+ />
62
+ );
63
+ }, [closeButton, handleClose]);
64
+
65
+ return (
66
+ <Dialog
67
+ ref={ref}
68
+ {...other}
69
+ onOpenChange={onOpenChange}
70
+ overlayClassName={classnames(styles["modal-overlay"], overlayClassName)}
71
+ className={classnames(
72
+ styles["modal-content"],
73
+ {
74
+ [styles["modal-content--fullscreen"]]: fullscreen,
75
+ [styles[`modal-content--${radius}-radius`]]: radius,
76
+ },
77
+ className
78
+ )}
79
+ >
80
+ {cloneOrCreateElement(
81
+ children,
82
+ {className: classnames(styles["modal-children"], childrenClassName)},
83
+ "div"
84
+ )}
85
+ {renderCloseButton()}
86
+ </Dialog>
87
+ );
88
+ };
89
+
90
+ export default memo(forwardRef(Modal));
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export {default as Modal, modalPropsKeys, type ModalProps} from "./Modal";