adnbn-ui 0.0.1 → 0.0.2

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 (145) hide show
  1. package/.prettierignore +3 -0
  2. package/.prettierrc +28 -0
  3. package/.storybook/main.ts +22 -0
  4. package/.storybook/preview.tsx +100 -0
  5. package/.storybook/styles/custom.scss +59 -0
  6. package/.storybook/styles/preview.css +58 -0
  7. package/.storybook/vitest.setup.ts +9 -0
  8. package/eslint.config.js +39 -0
  9. package/package.json +77 -2
  10. package/src/components/Avatar/Avatar.stories.tsx +118 -0
  11. package/src/components/Avatar/Avatar.tsx +65 -0
  12. package/src/components/Avatar/avatar.module.scss +77 -0
  13. package/src/components/Avatar/index.ts +2 -0
  14. package/src/components/BaseButton/BaseButton.tsx +36 -0
  15. package/src/components/BaseButton/base-button.module.scss +24 -0
  16. package/src/components/BaseButton/index.ts +2 -0
  17. package/src/components/Button/Button.stories.tsx +148 -0
  18. package/src/components/Button/Button.tsx +73 -0
  19. package/src/components/Button/button.module.scss +140 -0
  20. package/src/components/Button/index.ts +2 -0
  21. package/src/components/Checkbox/Checkbox.stories.tsx +180 -0
  22. package/src/components/Checkbox/Checkbox.tsx +71 -0
  23. package/src/components/Checkbox/checkbox.module.scss +82 -0
  24. package/src/components/Checkbox/index.ts +2 -0
  25. package/src/components/Dialog/Dialog.tsx +125 -0
  26. package/src/components/Dialog/dialog.module.scss +55 -0
  27. package/src/components/Dialog/index.ts +2 -0
  28. package/src/components/Drawer/Drawer.stories.tsx +89 -0
  29. package/src/components/Drawer/Drawer.tsx +57 -0
  30. package/src/components/Drawer/drawer.module.scss +170 -0
  31. package/src/components/Drawer/index.ts +2 -0
  32. package/src/components/Footer/Footer.stories.tsx +118 -0
  33. package/src/components/Footer/Footer.tsx +58 -0
  34. package/src/components/Footer/footer.module.scss +44 -0
  35. package/src/components/Footer/index.ts +2 -0
  36. package/src/components/Header/Header.stories.tsx +49 -0
  37. package/src/components/Header/Header.tsx +73 -0
  38. package/src/components/Header/header.module.scss +56 -0
  39. package/src/components/Header/index.ts +2 -0
  40. package/src/components/Highlight/Highlight.stories.tsx +83 -0
  41. package/src/components/Highlight/Highlight.tsx +40 -0
  42. package/src/components/Highlight/highlight.module.scss +47 -0
  43. package/src/components/Highlight/index.ts +2 -0
  44. package/src/components/Icon/Icon.tsx +46 -0
  45. package/src/components/Icon/icon.module.scss +17 -0
  46. package/src/components/Icon/index.ts +2 -0
  47. package/src/components/IconButton/IconButton.stories.tsx +179 -0
  48. package/src/components/IconButton/IconButton.tsx +65 -0
  49. package/src/components/IconButton/icon-button.module.scss +86 -0
  50. package/src/components/IconButton/index.ts +2 -0
  51. package/src/components/Layout/Layout.stories.tsx +88 -0
  52. package/src/components/Layout/Provider.tsx +47 -0
  53. package/src/components/Layout/context.ts +24 -0
  54. package/src/components/Layout/index.ts +2 -0
  55. package/src/components/Layout/layout.module.scss +17 -0
  56. package/src/components/List/List.stories.tsx +81 -0
  57. package/src/components/List/List.tsx +24 -0
  58. package/src/components/List/index.ts +2 -0
  59. package/src/components/List/list.module.scss +8 -0
  60. package/src/components/ListItem/ListItem.tsx +75 -0
  61. package/src/components/ListItem/index.ts +2 -0
  62. package/src/components/ListItem/list-item.module.scss +36 -0
  63. package/src/components/Modal/Modal.stories.tsx +95 -0
  64. package/src/components/Modal/Modal.tsx +94 -0
  65. package/src/components/Modal/index.ts +2 -0
  66. package/src/components/Modal/modal.module.scss +97 -0
  67. package/src/components/Odometer/Odometer.stories.tsx +66 -0
  68. package/src/components/Odometer/Odometer.tsx +45 -0
  69. package/src/components/Odometer/hooks/useOdometer.tsx +24 -0
  70. package/src/components/Odometer/index.ts +3 -0
  71. package/src/components/Odometer/odometer.module.scss +81 -0
  72. package/src/components/Odometer/odometr.d.ts +9 -0
  73. package/src/components/ScrollArea/ScrollArea.stories.tsx +58 -0
  74. package/src/components/ScrollArea/ScrollArea.tsx +63 -0
  75. package/src/components/ScrollArea/index.ts +2 -0
  76. package/src/components/ScrollArea/scroll-area.module.scss +54 -0
  77. package/src/components/SvgSprite/SvgSprite.tsx +21 -0
  78. package/src/components/SvgSprite/index.ts +2 -0
  79. package/src/components/Switch/Switch.stories.tsx +25 -0
  80. package/src/components/Switch/Switch.tsx +23 -0
  81. package/src/components/Switch/index.ts +2 -0
  82. package/src/components/Switch/switch.module.scss +65 -0
  83. package/src/components/Tag/Tag.stories.tsx +157 -0
  84. package/src/components/Tag/Tag.tsx +71 -0
  85. package/src/components/Tag/index.ts +2 -0
  86. package/src/components/Tag/tag.module.scss +118 -0
  87. package/src/components/TextArea/TextArea.stories.tsx +145 -0
  88. package/src/components/TextArea/TextArea.tsx +143 -0
  89. package/src/components/TextArea/index.ts +2 -0
  90. package/src/components/TextArea/text-area.module.scss +88 -0
  91. package/src/components/TextField/TextField.stories.tsx +177 -0
  92. package/src/components/TextField/TextField.tsx +162 -0
  93. package/src/components/TextField/index.ts +2 -0
  94. package/src/components/TextField/text-field.module.scss +129 -0
  95. package/src/components/Toast/Toast.stories.tsx +209 -0
  96. package/src/components/Toast/Toast.tsx +142 -0
  97. package/src/components/Toast/index.ts +2 -0
  98. package/src/components/Toast/toast.module.scss +267 -0
  99. package/src/components/Tooltip/Tooltip.stories.tsx +80 -0
  100. package/src/components/Tooltip/Tooltip.tsx +79 -0
  101. package/src/components/Tooltip/index.ts +2 -0
  102. package/src/components/Tooltip/tooltip.module.scss +93 -0
  103. package/src/components/View/View.stories.tsx +47 -0
  104. package/src/components/View/View.tsx +68 -0
  105. package/src/components/View/index.ts +2 -0
  106. package/src/components/View/view.module.scss +38 -0
  107. package/src/components/ViewDrawer/ViewDrawer.stories.tsx +75 -0
  108. package/src/components/ViewDrawer/ViewDrawer.tsx +24 -0
  109. package/src/components/ViewDrawer/index.ts +2 -0
  110. package/src/components/ViewModal/ViewModal.stories.tsx +68 -0
  111. package/src/components/ViewModal/ViewModal.tsx +24 -0
  112. package/src/components/ViewModal/index.ts +2 -0
  113. package/src/components/index.ts +29 -0
  114. package/src/components/types.ts +65 -0
  115. package/src/config/default.ts +3 -0
  116. package/src/config/index.ts +26 -0
  117. package/src/declaration.d.ts +8 -0
  118. package/src/index.ts +3 -0
  119. package/src/plugin/builder/ConfigBuilder.ts +32 -0
  120. package/src/plugin/builder/StyleBuilder.ts +34 -0
  121. package/src/plugin/builder/virtual.config.ts +7 -0
  122. package/src/plugin/finder/ConfigFinder.ts +26 -0
  123. package/src/plugin/finder/Finder.ts +76 -0
  124. package/src/plugin/finder/StyleFinder.ts +23 -0
  125. package/src/plugin/index.ts +70 -0
  126. package/src/plugin/types.ts +8 -0
  127. package/src/providers/UIProvider.tsx +26 -0
  128. package/src/providers/icons/IconsProvider.tsx +34 -0
  129. package/src/providers/icons/context.ts +22 -0
  130. package/src/providers/icons/index.ts +3 -0
  131. package/src/providers/index.ts +3 -0
  132. package/src/providers/theme/ThemeProvider.tsx +39 -0
  133. package/src/providers/theme/context.ts +30 -0
  134. package/src/providers/theme/index.ts +2 -0
  135. package/src/providers/theme/styles/default.scss +95 -0
  136. package/src/providers/theme/styles/reset.css +111 -0
  137. package/src/styles/mixins.scss +23 -0
  138. package/src/types/theme.ts +4 -0
  139. package/src/utils/index.ts +2 -0
  140. package/src/utils/react.ts +21 -0
  141. package/src/utils/utils.ts +12 -0
  142. package/tsconfig.json +18 -0
  143. package/vite.config.ts +11 -0
  144. package/vitest.workspace.ts +19 -0
  145. package/components/Button/index.ts +0 -0
@@ -0,0 +1,36 @@
1
+ import React, {ComponentProps, FC, memo, ReactNode} from "react";
2
+ import classnames from "classnames";
3
+
4
+ import {cloneOrCreateElement} from "../../utils";
5
+
6
+ import styles from "./base-button.module.scss";
7
+
8
+ export interface BaseButtonProps extends ComponentProps<"button"> {
9
+ after?: ReactNode;
10
+ before?: ReactNode;
11
+ afterClassName?: string;
12
+ beforeClassName?: string;
13
+ childrenClassName?: string;
14
+ }
15
+
16
+ const BaseButton: FC<BaseButtonProps> = props => {
17
+ const {after, before, children, className, afterClassName, beforeClassName, childrenClassName, ...other} = props;
18
+
19
+ return (
20
+ <button className={classnames(styles["base-button"], className)} {...other}>
21
+ {cloneOrCreateElement(before, {
22
+ className: classnames(styles["base-button__before"], beforeClassName),
23
+ })}
24
+
25
+ {cloneOrCreateElement(children, {
26
+ className: classnames(styles["base-button__children"], childrenClassName),
27
+ })}
28
+
29
+ {cloneOrCreateElement(after, {
30
+ className: classnames(styles["base-button__after"], afterClassName),
31
+ })}
32
+ </button>
33
+ );
34
+ };
35
+
36
+ export default memo(BaseButton);
@@ -0,0 +1,24 @@
1
+ .base-button {
2
+ box-sizing: border-box;
3
+ border: none;
4
+ cursor: pointer;
5
+ position: relative;
6
+ display: inline-flex;
7
+ flex-direction: row;
8
+ align-items: center;
9
+ vertical-align: middle;
10
+ justify-content: center;
11
+ gap: var(--base-button-gap, 8px);
12
+ will-change: background, color, transform;
13
+ transition:
14
+ background var(--transition-speed-sm),
15
+ color var(--transition-speed-sm),
16
+ transform var(--transition-speed-sm);
17
+
18
+ &__after,
19
+ &__before,
20
+ &__children {
21
+ position: relative;
22
+ display: inline;
23
+ }
24
+ }
@@ -0,0 +1,2 @@
1
+ export {default as BaseButton} from "./BaseButton";
2
+ export type {BaseButtonProps} from "./BaseButton";
@@ -0,0 +1,148 @@
1
+ import {Meta, StoryObj} from "@storybook/react";
2
+
3
+ import {capitalizeFirstLetter, hideInTable} from "../../utils";
4
+
5
+ import ButtonComponent, {ButtonColor, ButtonRadius, ButtonSize, ButtonVariant} from "./Button";
6
+
7
+ const variants: ButtonVariant[] = [ButtonVariant.Contained, ButtonVariant.Outlined, ButtonVariant.Text];
8
+ const colors: (ButtonColor | "default")[] = ["default", ButtonColor.Primary, ButtonColor.Secondary, ButtonColor.Accent];
9
+ const sizes: (ButtonSize | "default")[] = [ButtonSize.Small, "default", ButtonSize.Medium, ButtonSize.Large];
10
+ const radius: (ButtonRadius | "default")[] = [
11
+ ButtonRadius.Small,
12
+ "default",
13
+ ButtonRadius.Medium,
14
+ ButtonRadius.Large,
15
+ ButtonRadius.Full,
16
+ ];
17
+
18
+ const meta: Meta<typeof ButtonComponent> = {
19
+ title: "Components/Button",
20
+ component: ButtonComponent,
21
+ tags: ["autodocs"],
22
+ argTypes: {
23
+ variant: {
24
+ options: variants,
25
+ control: {type: "select"},
26
+ },
27
+ color: {
28
+ options: colors,
29
+ control: {type: "select"},
30
+ },
31
+ size: {
32
+ options: sizes,
33
+ control: {type: "select"},
34
+ },
35
+ radius: {
36
+ options: radius,
37
+ control: {type: "select"},
38
+ },
39
+
40
+ after: hideInTable,
41
+ before: hideInTable,
42
+ afterClassName: hideInTable,
43
+ beforeClassName: hideInTable,
44
+ childrenClassName: hideInTable,
45
+ },
46
+ };
47
+
48
+ export default meta;
49
+
50
+ export const Button: StoryObj<typeof ButtonComponent> = {
51
+ args: {
52
+ children: "Button",
53
+ },
54
+ };
55
+
56
+ export const VariantColor = () => {
57
+ return (
58
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
59
+ {variants.map(variant =>
60
+ colors.map(color => (
61
+ <div key={`${variant}-${color}`}>
62
+ <ButtonComponent variant={variant} color={color !== "default" ? color : undefined}>
63
+ {capitalizeFirstLetter(color)}
64
+ </ButtonComponent>
65
+ </div>
66
+ ))
67
+ )}
68
+ </div>
69
+ );
70
+ };
71
+
72
+ export const VariantColorDisabled = () => {
73
+ return (
74
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
75
+ {variants.map(variant =>
76
+ colors.map(color => (
77
+ <div key={`${variant}-${color}`}>
78
+ <ButtonComponent disabled variant={variant} color={color !== "default" ? color : undefined}>
79
+ {capitalizeFirstLetter(color)}
80
+ </ButtonComponent>
81
+ </div>
82
+ ))
83
+ )}
84
+ </div>
85
+ );
86
+ };
87
+
88
+ export const VariantSize = () => {
89
+ return (
90
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
91
+ {variants.map(variant =>
92
+ sizes.map(size => (
93
+ <div key={`${variant}-${size}`}>
94
+ <ButtonComponent variant={variant} size={size !== "default" ? size : undefined}>
95
+ {capitalizeFirstLetter(size)}
96
+ </ButtonComponent>
97
+ </div>
98
+ ))
99
+ )}
100
+ </div>
101
+ );
102
+ };
103
+
104
+ export const VariantRadius = () => {
105
+ return (
106
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(5, auto)"}}>
107
+ {variants.map(variant =>
108
+ radius.map(radius => (
109
+ <div key={`${variant}-${radius}`}>
110
+ <ButtonComponent variant={variant} radius={radius !== "default" ? radius : undefined}>
111
+ {capitalizeFirstLetter(radius)}
112
+ </ButtonComponent>
113
+ </div>
114
+ ))
115
+ )}
116
+ </div>
117
+ );
118
+ };
119
+
120
+ export const SizeRadius = () => {
121
+ return (
122
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(5, auto)"}}>
123
+ <span className="item-card__title"> Radius \ Size </span>
124
+ {sizes.map(size => (
125
+ <span key={size} className="item-card__title">
126
+ {capitalizeFirstLetter(size)} size
127
+ </span>
128
+ ))}
129
+ {radius.map(radius => (
130
+ <>
131
+ <span key={radius} className="item-card__title">
132
+ {capitalizeFirstLetter(radius)} radius
133
+ </span>
134
+ {sizes.map(size => (
135
+ <div key={`${size}-${radius}`} className="item-card">
136
+ <ButtonComponent
137
+ size={size !== "default" ? size : undefined}
138
+ radius={radius !== "default" ? radius : undefined}
139
+ >
140
+ Button
141
+ </ButtonComponent>
142
+ </div>
143
+ ))}
144
+ </>
145
+ ))}
146
+ </div>
147
+ );
148
+ };
@@ -0,0 +1,73 @@
1
+ import React, {FC, memo} from "react";
2
+ import classnames from "classnames";
3
+ import {BaseButton, BaseButtonProps} from "../BaseButton";
4
+
5
+ import {useComponentProps} from "../../providers";
6
+
7
+ import styles from "./button.module.scss";
8
+
9
+ export enum ButtonVariant {
10
+ Contained = "contained",
11
+ Outlined = "outlined",
12
+ Text = "text",
13
+ }
14
+
15
+ export enum ButtonColor {
16
+ Primary = "primary",
17
+ Secondary = "secondary",
18
+ Accent = "accent",
19
+ }
20
+
21
+ export enum ButtonSize {
22
+ Small = "small",
23
+ Medium = "medium",
24
+ Large = "large",
25
+ }
26
+
27
+ export enum ButtonRadius {
28
+ Small = "small",
29
+ Medium = "medium",
30
+ Large = "large",
31
+ Full = "full",
32
+ }
33
+
34
+ export interface ButtonProps extends BaseButtonProps {
35
+ variant?: ButtonVariant;
36
+ color?: ButtonColor;
37
+ size?: ButtonSize;
38
+ radius?: ButtonRadius;
39
+ }
40
+
41
+ const Button: FC<ButtonProps> = props => {
42
+ const {
43
+ variant = ButtonVariant.Contained,
44
+ color,
45
+ size,
46
+ radius,
47
+ childrenClassName,
48
+ className,
49
+ children,
50
+ ...other
51
+ } = {...useComponentProps("button"), ...props};
52
+
53
+ return (
54
+ <BaseButton
55
+ {...other}
56
+ className={classnames(
57
+ styles["button"],
58
+ {
59
+ [styles[`button--${variant}`]]: variant,
60
+ [styles[`button--${radius}-radius`]]: radius,
61
+ [styles[`button--${color}-color`]]: color,
62
+ [styles[`button--${size}-size`]]: size,
63
+ },
64
+ className
65
+ )}
66
+ childrenClassName={classnames(styles["button__text"], childrenClassName)}
67
+ >
68
+ {children}
69
+ </BaseButton>
70
+ );
71
+ };
72
+
73
+ export default memo(Button);
@@ -0,0 +1,140 @@
1
+ $root: button;
2
+
3
+ .#{$root} {
4
+ font-family: var(--button-font-family, var(--font-family)), sans-serif;
5
+ font-weight: var(--button-font-weight, 500);
6
+ font-size: var(--button-font-size, var(--font-size, 14px));
7
+ letter-spacing: var(--button-letter-spacing, 0.5px);
8
+ line-height: var(--button-line-height, var(--line-height, 14px));
9
+ height: var(--button-height, 34px);
10
+ border-radius: var(--button-border-radius, 10px);
11
+ padding: var(--button-padding, 0 16px);
12
+
13
+ &:active:not(:disabled) {
14
+ transform: scale(var(--button-scale, 0.98));
15
+ }
16
+
17
+ &:disabled {
18
+ opacity: var(--button-disabled-opacity, 0.75);
19
+ cursor: default;
20
+ }
21
+
22
+ // Variants
23
+ &--contained {
24
+ color: var(--button-contained-text-color, var(--bg-primary-color));
25
+ background: var(--button-contained-bg-color, var(--text-primary-color));
26
+
27
+ &.#{$root}--primary-color {
28
+ color: #fff;
29
+ background: var(--primary-color);
30
+ }
31
+
32
+ &.#{$root}--secondary-color {
33
+ color: #fff;
34
+ background: var(--secondary-color);
35
+ }
36
+
37
+ &.#{$root}--accent-color {
38
+ color: #fff;
39
+ background: var(--accent-color);
40
+ }
41
+ }
42
+
43
+ &--outlined {
44
+ color: var(--button-outlined-text-color, var(--text-primary-color));
45
+ border: 1px solid var(--button-outlined-border-color, var(--button-outlined-text-color, var(--text-primary-color)));
46
+ background: none;
47
+
48
+ &:hover {
49
+ background-color: var(--button-outlined-bg-color-hover);
50
+ }
51
+
52
+ &:active {
53
+ background-color: var(--button-outlined-bg-color-active);
54
+ }
55
+
56
+ &.#{$root}--primary-color {
57
+ color: var(--primary-color);
58
+ border-color: var(--button-outlined-border-primary-color);
59
+ }
60
+
61
+ &.#{$root}--secondary-color {
62
+ color: var(--secondary-color);
63
+ border-color: var(--button-outlined-border-secondary-color);
64
+ }
65
+
66
+ &.#{$root}--accent-color {
67
+ color: var(--accent-color);
68
+ border-color: var(--button-outlined-border-accent-color);
69
+ }
70
+ }
71
+
72
+ &--text {
73
+ color: var(--button-text-text-color, var(--text-primary-color));
74
+ background-color: transparent;
75
+
76
+ &:hover {
77
+ color: var(--button-text-text-color-hover, var(--text-secondary-color));
78
+ }
79
+
80
+ &:active {
81
+ color: var(--button-text-text-color-active, var(--text-secondary-color));
82
+ }
83
+
84
+ &.#{$root}--primary-color {
85
+ color: var(--primary-color);
86
+ }
87
+
88
+ &.#{$root}--secondary-color {
89
+ color: var(--secondary-color);
90
+ }
91
+
92
+ &.#{$root}--accent-color {
93
+ color: var(--accent-color);
94
+ }
95
+ }
96
+
97
+ // Sizes
98
+ &--small-size {
99
+ height: var(--button-height-sm, 24px);
100
+ font-size: var(--button-font-size-sm, 12px);
101
+ }
102
+
103
+ &--medium-size {
104
+ height: var(--button-height-md, 44px);
105
+ font-size: var(--button-font-size-sm, 16px);
106
+ }
107
+
108
+ &--large-size {
109
+ height: var(--button-height-lg, 54px);
110
+ min-width: 95px;
111
+ font-size: var(--button-font-size-sm, 18px);
112
+ }
113
+
114
+ //Radius
115
+ &--small-radius {
116
+ border-radius: var(--button-border-radius-sm, 5px);
117
+ }
118
+
119
+ &--medium-radius {
120
+ border-radius: var(--button-border-radius-md, 12px);
121
+ }
122
+
123
+ &--large-radius {
124
+ border-radius: var(--button-border-radius-lg, 15px);
125
+ }
126
+
127
+ &--full-radius {
128
+ border-radius: var(--button-height, 999px);
129
+ }
130
+
131
+ &__text {
132
+ position: relative;
133
+ z-index: 3;
134
+ white-space: nowrap;
135
+ text-overflow: ellipsis;
136
+ overflow: hidden;
137
+ max-width: var(--button-max-width, 160px);
138
+ line-height: initial;
139
+ }
140
+ }
@@ -0,0 +1,2 @@
1
+ export {default as Button, ButtonVariant, ButtonRadius, ButtonColor, ButtonSize} from "./Button";
2
+ export type {ButtonProps} from "./Button";
@@ -0,0 +1,180 @@
1
+ import {useState} from "react";
2
+ import {Meta, StoryObj} from "@storybook/react";
3
+
4
+ import {capitalizeFirstLetter, hideInTable} from "../../utils";
5
+
6
+ import CheckboxComponent, {CheckboxRadius, CheckboxSize, CheckboxVariant, CheckedState} from "./Checkbox";
7
+
8
+ const variants: (CheckboxVariant | "default")[] = ["default", CheckboxVariant.Classic, CheckboxVariant.Soft];
9
+ const size: (CheckboxSize | "default")[] = [CheckboxSize.Small, "default", CheckboxSize.Medium, CheckboxSize.Large];
10
+ const radius: (CheckboxRadius | "default")[] = [CheckboxRadius.Small, "default", CheckboxRadius.Large];
11
+
12
+ const meta: Meta<typeof CheckboxComponent> = {
13
+ title: "Components/Checkbox",
14
+ component: CheckboxComponent,
15
+ tags: ["autodocs"],
16
+ argTypes: {
17
+ checked: {
18
+ options: [true, false, "indeterminate"],
19
+ control: {type: "select"},
20
+ },
21
+ variant: {
22
+ options: variants,
23
+ control: {type: "select"},
24
+ },
25
+ size: {
26
+ options: size,
27
+ control: {type: "select"},
28
+ },
29
+ radius: {
30
+ options: radius,
31
+ control: {type: "select"},
32
+ },
33
+
34
+ checkedIcon: hideInTable,
35
+ indeterminateIcon: hideInTable,
36
+ children: hideInTable,
37
+ className: hideInTable,
38
+ indicatorClassName: hideInTable,
39
+ },
40
+ };
41
+
42
+ export default meta;
43
+
44
+ export const Checkbox: StoryObj<typeof CheckboxComponent> = {
45
+ args: {
46
+ checked: true,
47
+ disabled: false,
48
+ variant: CheckboxVariant.Classic,
49
+ },
50
+ };
51
+
52
+ export const CheckboxClickable = () => {
53
+ const [checked, setChecked] = useState<CheckedState>("indeterminate");
54
+
55
+ return <CheckboxComponent variant={CheckboxVariant.Classic} checked={checked} onCheckedChange={setChecked} />;
56
+ };
57
+
58
+ export const Variant = () => {
59
+ return (
60
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(3, auto)"}}>
61
+ {variants.map(variant => (
62
+ <span key={variant} className="item-card__title">
63
+ {capitalizeFirstLetter(variant)}
64
+ </span>
65
+ ))}
66
+
67
+ {variants.map(variant => (
68
+ <div key={variant} className="item-card">
69
+ <CheckboxComponent variant={variant !== "default" ? variant : undefined} checked={false} />
70
+ </div>
71
+ ))}
72
+
73
+ {variants.map(variant => (
74
+ <div key={variant} className="item-card">
75
+ <CheckboxComponent variant={variant !== "default" ? variant : undefined} checked={true} />
76
+ </div>
77
+ ))}
78
+
79
+ {variants.map(variant => (
80
+ <div key={variant} className="item-card">
81
+ <CheckboxComponent variant={variant !== "default" ? variant : undefined} checked="indeterminate" />
82
+ </div>
83
+ ))}
84
+ </div>
85
+ );
86
+ };
87
+
88
+ export const VariantDisabled = () => {
89
+ return (
90
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(3, auto)"}}>
91
+ {variants.map(variant => (
92
+ <span key={variant} className="item-card__title">
93
+ {capitalizeFirstLetter(variant)}
94
+ </span>
95
+ ))}
96
+
97
+ {variants.map(variant => (
98
+ <div key={variant} className="item-card">
99
+ <CheckboxComponent disabled variant={variant !== "default" ? variant : undefined} checked={false} />
100
+ </div>
101
+ ))}
102
+
103
+ {variants.map(variant => (
104
+ <div key={variant} className="item-card">
105
+ <CheckboxComponent disabled variant={variant !== "default" ? variant : undefined} checked={true} />
106
+ </div>
107
+ ))}
108
+
109
+ {variants.map(variant => (
110
+ <div key={variant} className="item-card">
111
+ <CheckboxComponent
112
+ disabled
113
+ variant={variant !== "default" ? variant : undefined}
114
+ checked="indeterminate"
115
+ />
116
+ </div>
117
+ ))}
118
+ </div>
119
+ );
120
+ };
121
+
122
+ export const Size = () => {
123
+ return (
124
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
125
+ {size.map(size => (
126
+ <span key={size} className="item-card__title">
127
+ {capitalizeFirstLetter(size)}
128
+ </span>
129
+ ))}
130
+
131
+ {size.map(size => (
132
+ <div key={size} className="item-card">
133
+ <CheckboxComponent size={size !== "default" ? size : undefined} checked={false} />
134
+ </div>
135
+ ))}
136
+
137
+ {size.map(size => (
138
+ <div key={size} className="item-card">
139
+ <CheckboxComponent size={size !== "default" ? size : undefined} checked={true} />
140
+ </div>
141
+ ))}
142
+
143
+ {size.map(size => (
144
+ <div key={size} className="item-card">
145
+ <CheckboxComponent size={size !== "default" ? size : undefined} checked="indeterminate" />
146
+ </div>
147
+ ))}
148
+ </div>
149
+ );
150
+ };
151
+
152
+ export const Radius = () => {
153
+ return (
154
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(3, auto)"}}>
155
+ {radius.map(radius => (
156
+ <span key={radius} className="item-card__title">
157
+ {capitalizeFirstLetter(radius)}
158
+ </span>
159
+ ))}
160
+
161
+ {radius.map(radius => (
162
+ <div key={radius} className="item-card">
163
+ <CheckboxComponent radius={radius !== "default" ? radius : undefined} checked={false} />
164
+ </div>
165
+ ))}
166
+
167
+ {radius.map(radius => (
168
+ <div key={radius} className="item-card">
169
+ <CheckboxComponent radius={radius !== "default" ? radius : undefined} checked={true} />
170
+ </div>
171
+ ))}
172
+
173
+ {radius.map(radius => (
174
+ <div key={radius} className="item-card">
175
+ <CheckboxComponent radius={radius !== "default" ? radius : undefined} checked="indeterminate" />
176
+ </div>
177
+ ))}
178
+ </div>
179
+ );
180
+ };
@@ -0,0 +1,71 @@
1
+ import React, {FC, memo, ReactElement} from "react";
2
+ import classnames from "classnames";
3
+ import {CheckboxProps as CheckboxRootProps, Indicator, Root} from "@radix-ui/react-checkbox";
4
+
5
+ import {useComponentProps} from "../../providers";
6
+
7
+ import styles from "./checkbox.module.scss";
8
+
9
+ export type {CheckedState} from "@radix-ui/react-checkbox";
10
+
11
+ export enum CheckboxVariant {
12
+ Classic = "classic",
13
+ Soft = "soft",
14
+ }
15
+
16
+ export enum CheckboxSize {
17
+ Small = "small",
18
+ Medium = "medium",
19
+ Large = "large",
20
+ }
21
+
22
+ export enum CheckboxRadius {
23
+ Small = "small",
24
+ Large = "large",
25
+ }
26
+
27
+ export interface CheckboxProps extends CheckboxRootProps {
28
+ indicatorClassName?: string;
29
+ size?: CheckboxSize;
30
+ radius?: CheckboxRadius;
31
+ variant?: CheckboxVariant;
32
+ checkedIcon?: ReactElement;
33
+ indeterminateIcon?: ReactElement;
34
+ }
35
+
36
+ const Checkbox: FC<CheckboxProps> = props => {
37
+ const {
38
+ checked,
39
+ size,
40
+ radius,
41
+ variant,
42
+ className,
43
+ indicatorClassName,
44
+ checkedIcon = "✔",
45
+ indeterminateIcon = "―",
46
+ ...other
47
+ } = {...useComponentProps("checkbox"), ...props};
48
+
49
+ return (
50
+ <Root
51
+ {...other}
52
+ checked={checked}
53
+ className={classnames(
54
+ styles["checkbox"],
55
+ {
56
+ [styles[`checkbox--${variant}`]]: variant,
57
+ [styles[`checkbox--${radius}-radius`]]: radius,
58
+ [styles[`checkbox--${size}-size`]]: size,
59
+ },
60
+ className
61
+ )}
62
+ >
63
+ <Indicator className={classnames(styles["checkbox__indicator"], indicatorClassName)}>
64
+ {checked === "indeterminate" && indeterminateIcon}
65
+ {checked === true && checkedIcon}
66
+ </Indicator>
67
+ </Root>
68
+ );
69
+ };
70
+
71
+ export default memo(Checkbox);