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,3 @@
1
+ node_modules/
2
+ dist/
3
+ build/
package/.prettierrc ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "es5",
4
+ "singleQuote": false,
5
+ "printWidth": 120,
6
+ "tabWidth": 4,
7
+ "useTabs": false,
8
+ "bracketSpacing": false,
9
+ "arrowParens": "avoid",
10
+ "endOfLine": "lf",
11
+ "overrides": [
12
+ {
13
+ "files": "*.json",
14
+ "options": {
15
+ "tabWidth": 2,
16
+ "bracketSpacing": true,
17
+ "bracketSameLine": false,
18
+ "printWidth": 40
19
+ }
20
+ },
21
+ {
22
+ "files": "*.scss",
23
+ "options": {
24
+ "tabWidth": 2
25
+ }
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,22 @@
1
+ import path from "path";
2
+ import {mergeConfig} from "vite";
3
+ import type {StorybookConfig} from "@storybook/react-vite";
4
+
5
+ const config: StorybookConfig = {
6
+ stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
7
+ addons: ["@storybook/addon-essentials"],
8
+ framework: {
9
+ name: "@storybook/react-vite",
10
+ options: {},
11
+ },
12
+ viteFinal: config => {
13
+ return mergeConfig(config, {
14
+ resolve: {
15
+ alias: {
16
+ "adnbn-ui-config": path.resolve("src", "config", "default.ts"),
17
+ },
18
+ },
19
+ });
20
+ },
21
+ };
22
+ export default config;
@@ -0,0 +1,100 @@
1
+ import React, {useEffect} from "react";
2
+ import type {Preview, StoryContext, StoryFn} from "@storybook/react";
3
+ import {ThemeProvider} from "../src/providers";
4
+ import "./styles/preview.css";
5
+
6
+ const ThemeDecorator = (Story: StoryFn, context: StoryContext) => {
7
+ const dir = context.globals.dir || "ltr";
8
+ const theme = context.globals.theme || "light";
9
+ const cssVariables = context.globals.cssVariables || "default";
10
+
11
+ useEffect(() => {
12
+ document.documentElement.setAttribute("dir", dir);
13
+ return () => {
14
+ document.documentElement.removeAttribute("dir");
15
+ };
16
+ }, [dir]);
17
+
18
+ useEffect(() => {
19
+ document.documentElement.setAttribute("theme", theme);
20
+ return () => {
21
+ document.documentElement.removeAttribute("theme");
22
+ };
23
+ }, [theme]);
24
+
25
+ useEffect(() => {
26
+ if (cssVariables === "default") return;
27
+
28
+ const linkElement = document.createElement("link");
29
+ linkElement.rel = "stylesheet";
30
+ linkElement.href = "../.storybook/styles/custom.scss";
31
+ document.head.appendChild(linkElement);
32
+
33
+ return () => {
34
+ document.head.removeChild(linkElement);
35
+ };
36
+ }, [cssVariables]);
37
+
38
+ return (
39
+ <ThemeProvider>
40
+ <div className="story-wrapper">{Story(context.args, context)}</div>
41
+ </ThemeProvider>
42
+ );
43
+ };
44
+
45
+ const globalTypes = {
46
+ dir: {
47
+ name: "Direction",
48
+ description: "Choose direction",
49
+ defaultValue: "ltr",
50
+ toolbar: {
51
+ icon: "transfer",
52
+ items: [
53
+ {value: "ltr", title: "Left to right"},
54
+ {value: "rtl", title: "Right to left"},
55
+ ],
56
+ showName: true,
57
+ },
58
+ },
59
+ theme: {
60
+ name: "Theme",
61
+ description: "Global theme for components",
62
+ defaultValue: "light",
63
+ toolbar: {
64
+ icon: "star",
65
+ items: [
66
+ {value: "light", title: "Light theme"},
67
+ {value: "dark", title: "Dark theme"},
68
+ ],
69
+ showName: true,
70
+ },
71
+ },
72
+ cssVariables: {
73
+ name: "CSS Variables",
74
+ description: "Choose CSS variables set",
75
+ defaultValue: "default",
76
+ toolbar: {
77
+ icon: "paintbrush",
78
+ items: [
79
+ {value: "default", title: "Default Variables"},
80
+ {value: "custom", title: "Custom Variables"},
81
+ ],
82
+ showName: true,
83
+ },
84
+ },
85
+ };
86
+
87
+ const preview: Preview = {
88
+ parameters: {
89
+ controls: {
90
+ matchers: {
91
+ color: /(background|color)$/i,
92
+ date: /Date$/i,
93
+ },
94
+ },
95
+ },
96
+ decorators: [ThemeDecorator],
97
+ globalTypes,
98
+ };
99
+
100
+ export default preview;
@@ -0,0 +1,59 @@
1
+ @use "../../src/styles/mixins" as theme;
2
+
3
+ @include theme.light {
4
+ --button-height-sm: 20px;
5
+ --button-height: 25px;
6
+ --button-height-md: 30px;
7
+ --button-height-lg: 40px;
8
+
9
+ --switch-border-radius: 5px;
10
+ --switch-width: 40px;
11
+ --switch-height: 20px;
12
+ --switch-thumb-width: 20px;
13
+ --switch-thumb-height: 16px;
14
+
15
+ --tooltip-border-radius: 10px;
16
+ --tooltip-padding: 5px 10px;
17
+
18
+ --toast-viewport-padding: 5px;
19
+
20
+ /* Common colors */
21
+ --primary-color: #29a383;
22
+ --secondary-color: #20573e;
23
+ --accent-color: #f76b15;
24
+
25
+ --bg-primary-color: #f5f6f7;
26
+
27
+ --text-primary-color: #111111;
28
+
29
+ /* Components colors */
30
+ --avatar-fallback-bg-color: #ffe7b3;
31
+ --avatar-fallback-color: #2e2f3b;
32
+
33
+ --icon-button-color: #004074;
34
+ --icon-button-bg-color: #70b8ff;
35
+ --icon-button-border-color: #c2e6ff;
36
+ --icon-button-color-hover: #104d87;
37
+ --icon-button-bg-color-hover: #70b8ff;
38
+
39
+ --tooltip-bg-color: #a39073;
40
+ }
41
+
42
+ @include theme.dark {
43
+ /* Common colors */
44
+ --bg-primary-color: #191919;
45
+
46
+ --text-primary-color: #b4b4b4;
47
+
48
+ /* Components colors */
49
+ --avatar-fallback-bg-color: #3f2700;
50
+ --avatar-fallback-color: #f5f6f7;
51
+
52
+ --icon-button-color: #0bd8b6;
53
+ --icon-button-bg-color: #023b37;
54
+ --icon-button-border-color: #084843;
55
+ --icon-button-color-hover: #adf0dd;
56
+ --icon-button-bg-color-hover: #0b3b2c;
57
+
58
+ --tooltip-bg-color: #d4b3a5;
59
+ }
@@ -0,0 +1,58 @@
1
+ body {
2
+ height: 100%;
3
+ width: 100%;
4
+ padding: 0 !important;
5
+ }
6
+
7
+ body.sb-main-padded {
8
+ height: 100vh;
9
+ }
10
+
11
+ .docs-story > div {
12
+ padding: 0;
13
+ overflow: hidden;
14
+ }
15
+
16
+ .docs-story .innerZoomElementWrapper > div {
17
+ width: 100%;
18
+ border: none !important;
19
+ }
20
+
21
+ #storybook-root {
22
+ height: 100%;
23
+ display: flex;
24
+ justify-content: center;
25
+ align-items: center;
26
+ }
27
+
28
+ /*Custom classes*/
29
+ .story-wrapper {
30
+ font-family: "Arial", sans-serif;
31
+ box-sizing: border-box;
32
+ width: 100%;
33
+ height: 100%;
34
+ padding: 50px 30px;
35
+ display: flex;
36
+ justify-content: center;
37
+ align-items: center;
38
+ background: var(--bg-primary-color);
39
+ }
40
+
41
+ .grid-wrapper {
42
+ display: grid;
43
+ gap: 25px;
44
+ justify-content: center;
45
+ align-items: center;
46
+ }
47
+
48
+ .item-card {
49
+ display: flex;
50
+ flex-direction: column;
51
+ gap: 15px;
52
+ justify-content: center;
53
+ align-items: center;
54
+ }
55
+
56
+ .item-card__title {
57
+ color: var(--text-primary-color);
58
+ }
@@ -0,0 +1,9 @@
1
+ import {beforeAll} from "vitest";
2
+ import {setProjectAnnotations} from "@storybook/react";
3
+ import * as projectAnnotations from "./preview";
4
+
5
+ // This is an important step to apply the right configuration when testing your stories.
6
+ // More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
7
+ const project = setProjectAnnotations([projectAnnotations]);
8
+
9
+ beforeAll(project.beforeAll);
@@ -0,0 +1,39 @@
1
+ import js from "@eslint/js";
2
+ import tseslint from "typescript-eslint";
3
+
4
+ import globals from "globals";
5
+
6
+ import reactHooks from "eslint-plugin-react-hooks";
7
+ import reactRefresh from "eslint-plugin-react-refresh";
8
+
9
+ export default tseslint.config(
10
+ {
11
+ ignores: [
12
+ "dist",
13
+ "addon",
14
+ ".adnbn",
15
+ "build",
16
+ "node_modules",
17
+ "coverage",
18
+ ".storybook",
19
+ "public",
20
+ "*.config.js"
21
+ ]
22
+ },
23
+ {
24
+ extends: [js.configs.recommended, ...tseslint.configs.recommended],
25
+ files: ["**/*.{ts,tsx}"],
26
+ languageOptions: {
27
+ ecmaVersion: 2020,
28
+ globals: globals.browser,
29
+ },
30
+ plugins: {
31
+ "react-hooks": reactHooks,
32
+ "react-refresh": reactRefresh,
33
+ },
34
+ rules: {
35
+ ...reactHooks.configs.recommended.rules,
36
+ "react-refresh/only-export-components": "off",
37
+ },
38
+ }
39
+ );
package/package.json CHANGED
@@ -1,7 +1,82 @@
1
1
  {
2
2
  "name": "adnbn-ui",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "UI Libs for AddonBone",
5
5
  "author": "AddonBone",
6
- "license": "MIT"
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./src/index.ts",
10
+ "./config": "./src/config/index.ts",
11
+ "./plugin": "./src/plugin/index.ts",
12
+ "./theme": "./src/styles/mixins.scss"
13
+ },
14
+ "sideEffects": [
15
+ "*.css",
16
+ "*.scss"
17
+ ],
18
+ "scripts": {
19
+ "dev": "vite",
20
+ "build": "tsc -b && vite build",
21
+ "lint": "eslint .",
22
+ "preview": "vite preview",
23
+ "storybook": "storybook dev -p 6006",
24
+ "build-storybook": "storybook build",
25
+ "format": "prettier --write ."
26
+ },
27
+ "dependencies": {
28
+ "adnbn": "^0.0.54",
29
+ "autosize": "^6.0.1",
30
+ "classnames": "^2.5.1",
31
+ "odometer": "^0.4.8",
32
+ "radix-ui": "^1.1.3",
33
+ "sass": "^1.85.1",
34
+ "react-highlight-words": "^0.21.0",
35
+ "ts-deepmerge": "^7.0.3"
36
+ },
37
+ "devDependencies": {
38
+ "@eslint/js": "^9.21.0",
39
+ "@storybook/addon-essentials": "^8.6.4",
40
+ "@storybook/react": "^8.6.4",
41
+ "@storybook/react-vite": "^8.6.4",
42
+ "@storybook/test": "^8.6.4",
43
+ "@svgr/webpack": "^8.1.0",
44
+ "@types/autosize": "^4.0.3",
45
+ "@types/node": "^22.13.10",
46
+ "@types/react": "^19.0.10",
47
+ "@types/react-dom": "^19.0.4",
48
+ "@types/react-highlight-words": "^0.20.0",
49
+ "@vitejs/plugin-react": "^4.3.4",
50
+ "@vitest/browser": "^3.0.8",
51
+ "@vitest/coverage-v8": "^3.0.8",
52
+ "eslint": "^9.21.0",
53
+ "eslint-plugin-react-hooks": "^5.1.0",
54
+ "eslint-plugin-react-refresh": "^0.4.19",
55
+ "globals": "^15.15.0",
56
+ "playwright": "^1.51.0",
57
+ "rspack-plugin-virtual-module": "^1.0.0",
58
+ "storybook": "^8.6.4",
59
+ "typescript": "~5.7.2",
60
+ "typescript-eslint": "^8.24.1",
61
+ "vite": "^6.2.1",
62
+ "vitest": "^3.0.8",
63
+ "prettier": "^3.5.3"
64
+ },
65
+ "peerDependencies": {
66
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
67
+ "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "@types/react": {
71
+ "optional": true
72
+ },
73
+ "@types/react-dom": {
74
+ "optional": true
75
+ }
76
+ },
77
+ "eslintConfig": {
78
+ "extends": [
79
+ "plugin:storybook/recommended"
80
+ ]
81
+ }
7
82
  }
@@ -0,0 +1,118 @@
1
+ import {Meta, StoryObj} from "@storybook/react";
2
+
3
+ import {capitalizeFirstLetter, hideInTable} from "../../utils";
4
+
5
+ import AvatarComponent, {AvatarRadius, AvatarSize} from "./Avatar";
6
+
7
+ const sizes: (AvatarSize | "default")[] = [AvatarSize.Small, "default", AvatarSize.Medium, AvatarSize.Large];
8
+ const radius: (AvatarRadius | "default")[] = [AvatarRadius.Small, AvatarRadius.Medium, AvatarRadius.Large, "default"];
9
+
10
+ const meta: Meta<typeof AvatarComponent> = {
11
+ title: "Components/Avatar",
12
+ component: AvatarComponent,
13
+ tags: ["autodocs"],
14
+ argTypes: {
15
+ size: {
16
+ options: sizes,
17
+ control: {type: "select"},
18
+ },
19
+ radius: {
20
+ options: radius,
21
+ control: {type: "select"},
22
+ },
23
+ fallbackClassName: hideInTable,
24
+ imageClassName: hideInTable,
25
+ children: hideInTable,
26
+ },
27
+ };
28
+
29
+ export default meta;
30
+
31
+ export const Avatar: StoryObj<typeof AvatarComponent> = {
32
+ args: {
33
+ src: "https://images.unsplash.com/photo-1492633423870-43d1cd2775eb?&w=128&h=128&dpr=2&q=80",
34
+ fallback: "CT",
35
+ },
36
+ };
37
+
38
+ export const AvatarRadiusGrid = () => {
39
+ return (
40
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
41
+ {radius.map(radius => (
42
+ <div key={radius} className="item-card">
43
+ <span className="item-card__title">{capitalizeFirstLetter(radius)}</span>
44
+ <AvatarComponent
45
+ src="https://images.unsplash.com/photo-1492633423870-43d1cd2775eb?&w=128&h=128&dpr=2&q=80"
46
+ radius={radius !== "default" ? radius : undefined}
47
+ fallback="CT"
48
+ />
49
+ </div>
50
+ ))}
51
+ </div>
52
+ );
53
+ };
54
+
55
+ export const Size = () => {
56
+ return (
57
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
58
+ {sizes.map(size => (
59
+ <div key={size} className="item-card">
60
+ <span className="item-card__title">{capitalizeFirstLetter(size)}</span>
61
+ <AvatarComponent
62
+ src="https://images.unsplash.com/photo-1492633423870-43d1cd2775eb?&w=128&h=128&dpr=2&q=80"
63
+ size={size !== "default" ? size : undefined}
64
+ fallback="CT"
65
+ />
66
+ </div>
67
+ ))}
68
+ </div>
69
+ );
70
+ };
71
+
72
+ export const SizeWithSVG = () => {
73
+ return (
74
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
75
+ {sizes.map(size => (
76
+ <div key={size} className="item-card">
77
+ <span className="item-card__title">{capitalizeFirstLetter(size)}</span>
78
+ <AvatarComponent
79
+ src="https://freesvg.org/img/Female-Avatar-5.png"
80
+ size={size !== "default" ? size : undefined}
81
+ fallback="CT"
82
+ />
83
+ </div>
84
+ ))}
85
+ </div>
86
+ );
87
+ };
88
+
89
+ export const SizeWithFallback = () => {
90
+ return (
91
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
92
+ {sizes.map(size => (
93
+ <div key={size} className="item-card">
94
+ <span className="item-card__title">{capitalizeFirstLetter(size)}</span>
95
+ <AvatarComponent src="" size={size !== "default" ? size : undefined} fallback="CT" />
96
+ </div>
97
+ ))}
98
+ </div>
99
+ );
100
+ };
101
+
102
+ export const SizeRadius = () => {
103
+ return (
104
+ <div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
105
+ {sizes.map(size =>
106
+ radius.map(radius => (
107
+ <div key={`${radius}-${size}`} className="item-card">
108
+ <AvatarComponent
109
+ src="https://images.unsplash.com/photo-1492633423870-43d1cd2775eb?&w=128&h=128&dpr=2&q=80"
110
+ radius={radius !== "default" ? radius : undefined}
111
+ size={size !== "default" ? size : undefined}
112
+ />
113
+ </div>
114
+ ))
115
+ )}
116
+ </div>
117
+ );
118
+ };
@@ -0,0 +1,65 @@
1
+ import React, {FC, memo, ReactNode} from "react";
2
+ import classnames from "classnames";
3
+ import {AvatarFallbackProps, AvatarImageProps, Fallback, Image, Root} from "@radix-ui/react-avatar";
4
+
5
+ import {useComponentProps} from "../../providers";
6
+
7
+ import styles from "./avatar.module.scss";
8
+
9
+ export enum AvatarSize {
10
+ Small = "small",
11
+ Medium = "medium",
12
+ Large = "large",
13
+ }
14
+
15
+ export enum AvatarRadius {
16
+ Small = "small",
17
+ Medium = "medium",
18
+ Large = "large",
19
+ }
20
+
21
+ export interface AvatarProps extends AvatarImageProps, Pick<AvatarFallbackProps, "delayMs"> {
22
+ imageClassName?: string;
23
+ size?: AvatarSize;
24
+ radius?: AvatarRadius;
25
+ fallback?: ReactNode;
26
+ fallbackClassName?: string;
27
+ cursorPointer?: boolean;
28
+ }
29
+
30
+ const Avatar: FC<AvatarProps> = props => {
31
+ const {
32
+ size,
33
+ radius,
34
+ fallback,
35
+ fallbackClassName,
36
+ delayMs = 600,
37
+ cursorPointer,
38
+ imageClassName,
39
+ className,
40
+ ...other
41
+ } = {...useComponentProps("avatar"), ...props};
42
+
43
+ return (
44
+ <Root
45
+ className={classnames(
46
+ styles["avatar"],
47
+ {
48
+ [styles[`avatar--${size}-size`]]: size,
49
+ [styles[`avatar--${radius}-radius`]]: radius,
50
+ [styles[`avatar--cursor-pointer`]]: cursorPointer,
51
+ },
52
+ className
53
+ )}
54
+ >
55
+ <Image className={classnames(styles["avatar-image"], imageClassName)} {...other} />
56
+ {fallback && (
57
+ <Fallback className={classnames(styles["avatar-fallback"], fallbackClassName)} delayMs={delayMs}>
58
+ {fallback}
59
+ </Fallback>
60
+ )}
61
+ </Root>
62
+ );
63
+ };
64
+
65
+ export default memo(Avatar);
@@ -0,0 +1,77 @@
1
+ $root: avatar;
2
+
3
+ .#{$root} {
4
+ box-sizing: border-box;
5
+ display: inline-flex;
6
+ align-items: center;
7
+ justify-content: center;
8
+ vertical-align: middle;
9
+ overflow: hidden;
10
+ cursor: default;
11
+ width: var(--avatar-size, 45px);
12
+ height: var(--avatar-size, 45px);
13
+ background-color: var(--avatar-bg-color, transparent);
14
+ border-radius: var(--avatar-border-radius, 100%);
15
+ border-width: var(--avatar-border-width);
16
+ border-color: var(--avatar-border-color);
17
+ border-style: var(--avatar-border-style);
18
+ font-size: var(--avatar-font-size, 18px);
19
+ font-weight: var(--avatar-font-weight, 500);
20
+
21
+ &--cursor-pointer {
22
+ cursor: pointer;
23
+ }
24
+
25
+ // Size
26
+ &--small-size {
27
+ width: var(--avatar-size-sm, 35px);
28
+ height: var(--avatar-size-sm, 35px);
29
+ font-size: var(--avatar-font-size-sm, 14px);
30
+ }
31
+
32
+ &--medium-size {
33
+ width: var(--avatar-size-md, 55px);
34
+ height: var(--avatar-size-md, 55px);
35
+ font-size: var(--avatar-font-size-md, 22px);
36
+ }
37
+
38
+ &--large-size {
39
+ width: var(--avatar-size-lg, 65px);
40
+ height: var(--avatar-size-lg, 65px);
41
+ font-size: var(--avatar-font-size-lg, 26px);
42
+ }
43
+
44
+ // Radius
45
+ &--small-radius {
46
+ border-radius: var(--avatar-border-radius-sm, 20%);
47
+ }
48
+
49
+ &--medium-radius {
50
+ border-radius: var(--avatar-border-radius-md, 30%);
51
+ }
52
+
53
+ &--large-radius {
54
+ border-radius: var(--avatar-border-radius-lg, 40%);
55
+ }
56
+
57
+ &-image {
58
+ width: 100%;
59
+ height: 100%;
60
+ object-fit: cover;
61
+ border-radius: inherit;
62
+ }
63
+
64
+ &-fallback {
65
+ width: 100%;
66
+ height: 100%;
67
+ cursor: inherit;
68
+ display: flex;
69
+ align-items: center;
70
+ justify-content: center;
71
+ color: var(--avatar-fallback-color);
72
+ background-color: var(--avatar-fallback-bg-color, var(--avatar-bg-color));
73
+ border-width: var(--avatar-fallback-border-width, var(--avatar-border-width));
74
+ border-color: var(--avatar-fallback-border-color, var(--avatar-border-color));
75
+ border-style: var(--avatar-fallback-border-style, var(--avatar-border-style));
76
+ }
77
+ }
@@ -0,0 +1,2 @@
1
+ export {default as Avatar, AvatarSize, AvatarRadius} from "./Avatar";
2
+ export type {AvatarProps} from "./Avatar";