@agility/plenum-ui 2.0.0-rc47 → 2.0.0-rc49
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.
- package/.eslintrc.json +6 -6
- package/.prettierrc +13 -13
- package/.storybook/Layout.jsx +12 -12
- package/.storybook/head.tsx +4 -4
- package/.storybook/main.ts +18 -18
- package/.storybook/manager-head.html +1 -1
- package/.storybook/manager.ts +25 -25
- package/.storybook/plenumTheme.ts +8 -8
- package/.storybook/preview-head.html +3 -3
- package/.storybook/preview.tsx +28 -28
- package/.vscode/settings.json +3 -3
- package/README.md +271 -271
- package/app/globals.css +99 -99
- package/app/head.tsx +59 -59
- package/app/layout.tsx +28 -28
- package/app/page.tsx +7 -7
- package/build.js +45 -45
- package/dist/index.d.ts +232 -230
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/types/stories/molecules/inputs/select/Select.d.ts +2 -0
- package/local.sh +100 -100
- package/next.config.js +8 -8
- package/package.json +82 -82
- package/pages/api/hello.ts +13 -13
- package/postcss.config.js +6 -6
- package/rollup.config.mjs +41 -41
- package/scripts/create-component.js +97 -97
- package/stories/Introduction.mdx +314 -314
- package/stories/assets/stackalt.svg +1 -1
- package/stories/atoms/Avatar/Avatar.stories.tsx +96 -96
- package/stories/atoms/Avatar/Avatar.tsx +123 -123
- package/stories/atoms/Avatar/index.ts +3 -3
- package/stories/atoms/badges/Badge.tsx +127 -127
- package/stories/atoms/badges/Pill/Pill.stories.tsx +75 -75
- package/stories/atoms/badges/Rounded/Rounded.stories.tsx +75 -75
- package/stories/atoms/badges/index.ts +3 -3
- package/stories/atoms/buttons/Button/Alternative/Alternative.stories.ts +86 -86
- package/stories/atoms/buttons/Button/Button.tsx +232 -232
- package/stories/atoms/buttons/Button/Danger/Danger.stories.ts +90 -90
- package/stories/atoms/buttons/Button/Primary/Primary.stories.ts +97 -97
- package/stories/atoms/buttons/Button/Secondary/Secondary.stories.ts +93 -93
- package/stories/atoms/buttons/Button/defaultArgs.ts +9 -9
- package/stories/atoms/buttons/Button/index.ts +3 -3
- package/stories/atoms/buttons/Capsule/Alternative/Alternative.stories.ts +27 -27
- package/stories/atoms/buttons/Capsule/Capsule.tsx +88 -88
- package/stories/atoms/buttons/Capsule/Danger/Danger.stories.ts +27 -27
- package/stories/atoms/buttons/Capsule/Primary/Primary.stories.ts +27 -27
- package/stories/atoms/buttons/Capsule/Secondary/Secondary.stories.ts +27 -27
- package/stories/atoms/buttons/Capsule/index.ts +3 -3
- package/stories/atoms/buttons/FloatingActionButton/FloatingActionButton.stories.tsx +15 -15
- package/stories/atoms/buttons/FloatingActionButton/FloatingActionButton.tsx +22 -22
- package/stories/atoms/buttons/FloatingActionButton/index.tsx +3 -3
- package/stories/atoms/buttons/index.ts +4 -4
- package/stories/atoms/crumb/Crumb.stories.tsx +18 -18
- package/stories/atoms/crumb/Crumb.tsx +22 -22
- package/stories/atoms/crumb/index.tsx +3 -3
- package/stories/atoms/icons/DynamicIcon.stories.ts +43 -43
- package/stories/atoms/icons/DynamicIcon.tsx +90 -90
- package/stories/atoms/icons/IconWithShadow.stories.ts +43 -43
- package/stories/atoms/icons/IconWithShadow.tsx +16 -16
- package/stories/atoms/icons/TablerIcon.tsx +22 -22
- package/stories/atoms/icons/index.tsx +14 -14
- package/stories/atoms/icons/tablerIconNames.ts +4336 -4336
- package/stories/atoms/index.ts +46 -46
- package/stories/atoms/loaders/Loader.stories.ts +15 -15
- package/stories/atoms/loaders/Loader.tsx +21 -21
- package/stories/atoms/loaders/NProgress/RadialProgress.stories.tsx +19 -19
- package/stories/atoms/loaders/NProgress/RadialProgress.tsx +74 -74
- package/stories/atoms/loaders/NProgress/index.ts +3 -3
- package/stories/atoms/loaders/index.ts +4 -4
- package/stories/index.ts +136 -136
- package/stories/molecules/index.ts +51 -51
- package/stories/molecules/inputs/InputCounter/InputCounter.stories.tsx +18 -18
- package/stories/molecules/inputs/InputCounter/InputCounter.tsx +24 -24
- package/stories/molecules/inputs/InputCounter/index.tsx +3 -3
- package/stories/molecules/inputs/InputField/InputField.stories.tsx +29 -29
- package/stories/molecules/inputs/InputField/InputField.tsx +96 -96
- package/stories/molecules/inputs/InputField/index.tsx +3 -3
- package/stories/molecules/inputs/InputLabel/InputLabel.stories.tsx +19 -19
- package/stories/molecules/inputs/InputLabel/InputLabel.tsx +45 -45
- package/stories/molecules/inputs/InputLabel/index.tsx +3 -3
- package/stories/molecules/inputs/NestedInputButton/NestedInputButton.stories.tsx +52 -52
- package/stories/molecules/inputs/NestedInputButton/NestedInputButton.tsx +64 -64
- package/stories/molecules/inputs/NestedInputButton/index.tsx +3 -3
- package/stories/molecules/inputs/TextInput/TextInput.stories.tsx +32 -32
- package/stories/molecules/inputs/TextInput/TextInput.tsx +165 -165
- package/stories/molecules/inputs/TextInput/index.tsx +5 -5
- package/stories/molecules/inputs/checkbox/Checkbox.stories.ts +23 -23
- package/stories/molecules/inputs/checkbox/Checkbox.tsx +98 -98
- package/stories/molecules/inputs/checkbox/index.ts +3 -3
- package/stories/molecules/inputs/combobox/ComboBox.stories.ts +41 -41
- package/stories/molecules/inputs/combobox/ComboBox.tsx +185 -185
- package/stories/molecules/inputs/combobox/index.ts +3 -3
- package/stories/molecules/inputs/index.ts +38 -38
- package/stories/molecules/inputs/radio/Radio.stories.ts +27 -27
- package/stories/molecules/inputs/radio/Radio.tsx +92 -92
- package/stories/molecules/inputs/radio/index.ts +3 -3
- package/stories/molecules/inputs/select/Select.stories.ts +23 -23
- package/stories/molecules/inputs/select/Select.tsx +108 -100
- package/stories/molecules/inputs/select/index.ts +3 -3
- package/stories/molecules/inputs/textArea/TextArea.stories.ts +22 -22
- package/stories/molecules/inputs/textArea/TextArea.tsx +158 -158
- package/stories/molecules/inputs/textArea/index.ts +3 -3
- package/stories/molecules/inputs/toggleSwitch/ToggleSwitch.stories.tsx +118 -118
- package/stories/molecules/inputs/toggleSwitch/ToggleSwitch.tsx +81 -81
- package/stories/molecules/inputs/toggleSwitch/index.ts +3 -3
- package/stories/molecules/tabs/Tabs.stories.tsx +18 -18
- package/stories/molecules/tabs/Tabs.tsx +22 -22
- package/stories/molecules/tabs/index.tsx +2 -2
- package/stories/organisms/AnimatedLabelInput/AnimatedLabelInput.stories.tsx +30 -30
- package/stories/organisms/AnimatedLabelInput/AnimatedLabelInput.tsx +66 -66
- package/stories/organisms/AnimatedLabelInput/index.tsx +3 -3
- package/stories/organisms/AnimatedLabelTextArea/AnimatedLabelTextArea.stories.tsx +26 -26
- package/stories/organisms/AnimatedLabelTextArea/AnimatedLabelTextArea.tsx +61 -61
- package/stories/organisms/AnimatedLabelTextArea/index.tsx +3 -3
- package/stories/organisms/ButtonDropdown/ButtonDropdown.stories.tsx +125 -125
- package/stories/organisms/ButtonDropdown/ButtonDropdown.tsx +86 -86
- package/stories/organisms/ButtonDropdown/index.tsx +3 -3
- package/stories/organisms/DropdownComponent/Dropdown.stories.tsx +73 -73
- package/stories/organisms/DropdownComponent/DropdownComponent.tsx +346 -346
- package/stories/organisms/DropdownComponent/dropdownItems.ts +122 -122
- package/stories/organisms/DropdownComponent/index.ts +4 -4
- package/stories/organisms/EmptySectionPlaceholder/EmptySectionPlaceholder.stories.tsx +76 -76
- package/stories/organisms/EmptySectionPlaceholder/EmptySectionPlaceholder.tsx +52 -52
- package/stories/organisms/EmptySectionPlaceholder/index.tsx +4 -4
- package/stories/organisms/FormInputWithAddons/FormInputWithAddons.stories.tsx +29 -29
- package/stories/organisms/FormInputWithAddons/FormInputWithAddons.tsx +145 -145
- package/stories/organisms/FormInputWithAddons/index.tsx +3 -3
- package/stories/organisms/TextInputSelect/InputSelect.tsx +59 -59
- package/stories/organisms/TextInputSelect/TextInputSelect.stories.tsx +33 -33
- package/stories/organisms/TextInputSelect/TextInputSelect.tsx +186 -186
- package/stories/organisms/TextInputSelect/index.tsx +3 -3
- package/stories/organisms/index.ts +27 -27
- package/tailwind.config.js +192 -192
- package/tsconfig.json +29 -29
- package/tsconfig.lib.json +25 -25
- package/utils/types.d.ts +2 -2
- package/utils/types.ts +3 -3
- package/utils/useId.d.ts +1 -1
- package/utils/useId.tsx +16 -16
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react"
|
|
2
|
-
import Avatar from "./Avatar"
|
|
3
|
-
|
|
4
|
-
const meta: Meta<typeof Avatar> = {
|
|
5
|
-
title: "Design System/atoms/Avatar",
|
|
6
|
-
component: Avatar,
|
|
7
|
-
tags: ["autodocs"],
|
|
8
|
-
parameters: {
|
|
9
|
-
design: {
|
|
10
|
-
type: "figma",
|
|
11
|
-
url: "https://www.figma.com/file/Rb5fJ8hD3pwvLnidgCaGgB/Agility-UI?type=design&node-id=19-1017&mode=design&t=9hpwa8YStpwXksff-4"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type Story = StoryObj<typeof Avatar>
|
|
17
|
-
|
|
18
|
-
// get random number between 0 and 45
|
|
19
|
-
const getRandomNumber = () => Math.floor(Math.random() * 45)
|
|
20
|
-
// function to return random string either "women" or "men"
|
|
21
|
-
const getRandomGender = (): "men" | "women" => (Math.random() < 0.5 ? "men" : "women")
|
|
22
|
-
|
|
23
|
-
export const DefaultAvatar: Story = {
|
|
24
|
-
args: {
|
|
25
|
-
// get image from randomuser.me/api
|
|
26
|
-
src: `https://randomuser.me/api/portraits/thumb/${getRandomGender()}/${getRandomNumber()}.jpg`
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export const AvatarWithStatus: Story = {
|
|
30
|
-
args: {
|
|
31
|
-
...DefaultAvatar.args,
|
|
32
|
-
status: "online"
|
|
33
|
-
},
|
|
34
|
-
parameters: {
|
|
35
|
-
design: {
|
|
36
|
-
type: "figma",
|
|
37
|
-
url: "https://www.figma.com/file/Rb5fJ8hD3pwvLnidgCaGgB/Agility-UI?type=design&node-id=19-1030&mode=design&t=9hpwa8YStpwXksff-4"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export const AvatarWithInitials: Story = {
|
|
42
|
-
args: {
|
|
43
|
-
src: undefined,
|
|
44
|
-
initials: "JD"
|
|
45
|
-
},
|
|
46
|
-
parameters: {
|
|
47
|
-
design: {
|
|
48
|
-
type: "figma",
|
|
49
|
-
url: "https://www.figma.com/file/Rb5fJ8hD3pwvLnidgCaGgB/Agility-UI?type=design&node-id=19-1254&mode=design&t=9hpwa8YStpwXksff-4"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export const AvatarWithStatusAndInitials: Story = {
|
|
54
|
-
args: {
|
|
55
|
-
status: "online",
|
|
56
|
-
initials: "JD"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export const XXSmallAvatar: Story = {
|
|
60
|
-
args: {
|
|
61
|
-
...DefaultAvatar.args,
|
|
62
|
-
size: "xxs"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export const XSmallAvatar: Story = {
|
|
66
|
-
args: {
|
|
67
|
-
...DefaultAvatar.args,
|
|
68
|
-
size: "xs"
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export const SmallAvatar: Story = {
|
|
72
|
-
args: {
|
|
73
|
-
...DefaultAvatar.args,
|
|
74
|
-
size: "sm"
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export const MediumAvatar: Story = {
|
|
78
|
-
args: {
|
|
79
|
-
...DefaultAvatar.args,
|
|
80
|
-
size: "md"
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export const LargeAvatar: Story = {
|
|
84
|
-
args: {
|
|
85
|
-
...DefaultAvatar.args,
|
|
86
|
-
size: "lg"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export const XLargeAvatar: Story = {
|
|
90
|
-
args: {
|
|
91
|
-
...DefaultAvatar.args,
|
|
92
|
-
size: "lg"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export default meta
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react"
|
|
2
|
+
import Avatar from "./Avatar"
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Avatar> = {
|
|
5
|
+
title: "Design System/atoms/Avatar",
|
|
6
|
+
component: Avatar,
|
|
7
|
+
tags: ["autodocs"],
|
|
8
|
+
parameters: {
|
|
9
|
+
design: {
|
|
10
|
+
type: "figma",
|
|
11
|
+
url: "https://www.figma.com/file/Rb5fJ8hD3pwvLnidgCaGgB/Agility-UI?type=design&node-id=19-1017&mode=design&t=9hpwa8YStpwXksff-4"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type Story = StoryObj<typeof Avatar>
|
|
17
|
+
|
|
18
|
+
// get random number between 0 and 45
|
|
19
|
+
const getRandomNumber = () => Math.floor(Math.random() * 45)
|
|
20
|
+
// function to return random string either "women" or "men"
|
|
21
|
+
const getRandomGender = (): "men" | "women" => (Math.random() < 0.5 ? "men" : "women")
|
|
22
|
+
|
|
23
|
+
export const DefaultAvatar: Story = {
|
|
24
|
+
args: {
|
|
25
|
+
// get image from randomuser.me/api
|
|
26
|
+
src: `https://randomuser.me/api/portraits/thumb/${getRandomGender()}/${getRandomNumber()}.jpg`
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const AvatarWithStatus: Story = {
|
|
30
|
+
args: {
|
|
31
|
+
...DefaultAvatar.args,
|
|
32
|
+
status: "online"
|
|
33
|
+
},
|
|
34
|
+
parameters: {
|
|
35
|
+
design: {
|
|
36
|
+
type: "figma",
|
|
37
|
+
url: "https://www.figma.com/file/Rb5fJ8hD3pwvLnidgCaGgB/Agility-UI?type=design&node-id=19-1030&mode=design&t=9hpwa8YStpwXksff-4"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export const AvatarWithInitials: Story = {
|
|
42
|
+
args: {
|
|
43
|
+
src: undefined,
|
|
44
|
+
initials: "JD"
|
|
45
|
+
},
|
|
46
|
+
parameters: {
|
|
47
|
+
design: {
|
|
48
|
+
type: "figma",
|
|
49
|
+
url: "https://www.figma.com/file/Rb5fJ8hD3pwvLnidgCaGgB/Agility-UI?type=design&node-id=19-1254&mode=design&t=9hpwa8YStpwXksff-4"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export const AvatarWithStatusAndInitials: Story = {
|
|
54
|
+
args: {
|
|
55
|
+
status: "online",
|
|
56
|
+
initials: "JD"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export const XXSmallAvatar: Story = {
|
|
60
|
+
args: {
|
|
61
|
+
...DefaultAvatar.args,
|
|
62
|
+
size: "xxs"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export const XSmallAvatar: Story = {
|
|
66
|
+
args: {
|
|
67
|
+
...DefaultAvatar.args,
|
|
68
|
+
size: "xs"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export const SmallAvatar: Story = {
|
|
72
|
+
args: {
|
|
73
|
+
...DefaultAvatar.args,
|
|
74
|
+
size: "sm"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export const MediumAvatar: Story = {
|
|
78
|
+
args: {
|
|
79
|
+
...DefaultAvatar.args,
|
|
80
|
+
size: "md"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export const LargeAvatar: Story = {
|
|
84
|
+
args: {
|
|
85
|
+
...DefaultAvatar.args,
|
|
86
|
+
size: "lg"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export const XLargeAvatar: Story = {
|
|
90
|
+
args: {
|
|
91
|
+
...DefaultAvatar.args,
|
|
92
|
+
size: "lg"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default meta
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import React, { FC, useMemo } from "react"
|
|
2
|
-
import { default as cn } from "classnames"
|
|
3
|
-
// import Image from "next/image"
|
|
4
|
-
export interface IAvatarProps {
|
|
5
|
-
/**
|
|
6
|
-
* source url for the avatar
|
|
7
|
-
*/
|
|
8
|
-
src?: string
|
|
9
|
-
/**
|
|
10
|
-
* Initials we use as fallback if no src is passed
|
|
11
|
-
*/
|
|
12
|
-
initials?: string
|
|
13
|
-
/**
|
|
14
|
-
* optional status
|
|
15
|
-
*/
|
|
16
|
-
status?: "offline" | "online" | "busy"
|
|
17
|
-
/**
|
|
18
|
-
* avatar picture size (also affects status indicator)
|
|
19
|
-
*/
|
|
20
|
-
size?: "xxs" | "xs" | "sm" | "md" | "lg" | "xl"
|
|
21
|
-
/**
|
|
22
|
-
* avatar img alt
|
|
23
|
-
*/
|
|
24
|
-
alt?: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Avatar component that shows profile image or name initials of the user
|
|
29
|
-
*/
|
|
30
|
-
const Avatar: FC<IAvatarProps> = ({ src, status, size = "md", alt = "Avatar image", initials }: IAvatarProps) => {
|
|
31
|
-
const imageStyles = cn("rounded-full", {
|
|
32
|
-
"h-6 w-6": size === "xxs",
|
|
33
|
-
"h-8 w-8": size === "xs",
|
|
34
|
-
"h-10 w-10": size === "sm",
|
|
35
|
-
"h-12 w-12": size === "md",
|
|
36
|
-
"h-14 w-14": size === "lg",
|
|
37
|
-
"h-16 w-16": size === "xl"
|
|
38
|
-
})
|
|
39
|
-
const initialsStyles = cn("inline-flex items-center justify-center rounded-full bg-gray-500", {
|
|
40
|
-
"h-6 w-6": size === "xxs",
|
|
41
|
-
"h-8 w-8": size === "xs",
|
|
42
|
-
"h-10 w-10": size === "sm",
|
|
43
|
-
"h-12 w-12": size === "md",
|
|
44
|
-
"h-14 w-14": size === "lg",
|
|
45
|
-
"h-16 w-16": size === "xl"
|
|
46
|
-
})
|
|
47
|
-
const fontStyles = cn("font-medium leading-none text-white uppercase", {
|
|
48
|
-
"text-xs": size === "xxs" || size === "xs",
|
|
49
|
-
"text-sm": size === "sm",
|
|
50
|
-
"text-base": size === "md",
|
|
51
|
-
"text-lg": size === "lg",
|
|
52
|
-
"text-xl": size === "xl"
|
|
53
|
-
})
|
|
54
|
-
const defaultAvatarStyles = cn("inline-block rounded-full overflow-hidden bg-gray-100", {
|
|
55
|
-
"h-6 w-6": size === "xxs",
|
|
56
|
-
"h-8 w-8": size === "xs",
|
|
57
|
-
"h-10 w-10": size === "sm",
|
|
58
|
-
"h-12 w-12": size === "md",
|
|
59
|
-
"h-14 w-14": size === "lg",
|
|
60
|
-
"h-16 w-16": size === "xl"
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const statusStyles = cn("absolute top-0 right-0 block rounded-full ring-2 ring-white", {
|
|
64
|
-
"h-1.5 w-1.5": size === "xxs",
|
|
65
|
-
"h-2 w-2": size === "xs",
|
|
66
|
-
"h-2.5 w-2.5": size === "sm",
|
|
67
|
-
"h-3 w-3": size === "md",
|
|
68
|
-
"h-3.5 w-3.5": size === "lg",
|
|
69
|
-
"h-4 w-4": size === "xl",
|
|
70
|
-
"bg-gray-300": status === "offline",
|
|
71
|
-
"bg-red-400": status === "busy",
|
|
72
|
-
"bg-green-400": status === "online"
|
|
73
|
-
})
|
|
74
|
-
const imageSize: number = useMemo(() => {
|
|
75
|
-
let imageSize: number = 0
|
|
76
|
-
switch (size) {
|
|
77
|
-
case "xxs":
|
|
78
|
-
imageSize = 24
|
|
79
|
-
break
|
|
80
|
-
case "xs":
|
|
81
|
-
imageSize = 32
|
|
82
|
-
break
|
|
83
|
-
case "sm":
|
|
84
|
-
imageSize = 40
|
|
85
|
-
break
|
|
86
|
-
case "md":
|
|
87
|
-
imageSize = 48
|
|
88
|
-
break
|
|
89
|
-
case "lg":
|
|
90
|
-
imageSize = 56
|
|
91
|
-
break
|
|
92
|
-
case "xl":
|
|
93
|
-
imageSize = 64
|
|
94
|
-
break
|
|
95
|
-
default:
|
|
96
|
-
imageSize = 48
|
|
97
|
-
break
|
|
98
|
-
}
|
|
99
|
-
return imageSize
|
|
100
|
-
}, [size])
|
|
101
|
-
|
|
102
|
-
return (
|
|
103
|
-
<span className="inline-block relative">
|
|
104
|
-
{src ? (
|
|
105
|
-
// eslint-disable-next-line @next/next/no-img-element
|
|
106
|
-
<img className={imageStyles} width={imageSize} height={imageSize} src={src} alt={alt} loading="eager" />
|
|
107
|
-
) : initials ? (
|
|
108
|
-
<span className={initialsStyles}>
|
|
109
|
-
<span className={fontStyles}>{initials}</span>
|
|
110
|
-
</span>
|
|
111
|
-
) : (
|
|
112
|
-
<span className={defaultAvatarStyles}>
|
|
113
|
-
<svg className="h-full w-full text-gray-300" fill="currentColor" viewBox="0 0 24 24">
|
|
114
|
-
<path d="M24 20.993V24H0v-2.996A14.977 14.977 0 0112.004 15c4.904 0 9.26 2.354 11.996 5.993zM16.002 8.999a4 4 0 11-8 0 4 4 0 018 0z" />
|
|
115
|
-
</svg>
|
|
116
|
-
</span>
|
|
117
|
-
)}
|
|
118
|
-
{status && <span className={statusStyles}></span>}
|
|
119
|
-
</span>
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export default Avatar
|
|
1
|
+
import React, { FC, useMemo } from "react"
|
|
2
|
+
import { default as cn } from "classnames"
|
|
3
|
+
// import Image from "next/image"
|
|
4
|
+
export interface IAvatarProps {
|
|
5
|
+
/**
|
|
6
|
+
* source url for the avatar
|
|
7
|
+
*/
|
|
8
|
+
src?: string
|
|
9
|
+
/**
|
|
10
|
+
* Initials we use as fallback if no src is passed
|
|
11
|
+
*/
|
|
12
|
+
initials?: string
|
|
13
|
+
/**
|
|
14
|
+
* optional status
|
|
15
|
+
*/
|
|
16
|
+
status?: "offline" | "online" | "busy"
|
|
17
|
+
/**
|
|
18
|
+
* avatar picture size (also affects status indicator)
|
|
19
|
+
*/
|
|
20
|
+
size?: "xxs" | "xs" | "sm" | "md" | "lg" | "xl"
|
|
21
|
+
/**
|
|
22
|
+
* avatar img alt
|
|
23
|
+
*/
|
|
24
|
+
alt?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Avatar component that shows profile image or name initials of the user
|
|
29
|
+
*/
|
|
30
|
+
const Avatar: FC<IAvatarProps> = ({ src, status, size = "md", alt = "Avatar image", initials }: IAvatarProps) => {
|
|
31
|
+
const imageStyles = cn("rounded-full", {
|
|
32
|
+
"h-6 w-6": size === "xxs",
|
|
33
|
+
"h-8 w-8": size === "xs",
|
|
34
|
+
"h-10 w-10": size === "sm",
|
|
35
|
+
"h-12 w-12": size === "md",
|
|
36
|
+
"h-14 w-14": size === "lg",
|
|
37
|
+
"h-16 w-16": size === "xl"
|
|
38
|
+
})
|
|
39
|
+
const initialsStyles = cn("inline-flex items-center justify-center rounded-full bg-gray-500", {
|
|
40
|
+
"h-6 w-6": size === "xxs",
|
|
41
|
+
"h-8 w-8": size === "xs",
|
|
42
|
+
"h-10 w-10": size === "sm",
|
|
43
|
+
"h-12 w-12": size === "md",
|
|
44
|
+
"h-14 w-14": size === "lg",
|
|
45
|
+
"h-16 w-16": size === "xl"
|
|
46
|
+
})
|
|
47
|
+
const fontStyles = cn("font-medium leading-none text-white uppercase", {
|
|
48
|
+
"text-xs": size === "xxs" || size === "xs",
|
|
49
|
+
"text-sm": size === "sm",
|
|
50
|
+
"text-base": size === "md",
|
|
51
|
+
"text-lg": size === "lg",
|
|
52
|
+
"text-xl": size === "xl"
|
|
53
|
+
})
|
|
54
|
+
const defaultAvatarStyles = cn("inline-block rounded-full overflow-hidden bg-gray-100", {
|
|
55
|
+
"h-6 w-6": size === "xxs",
|
|
56
|
+
"h-8 w-8": size === "xs",
|
|
57
|
+
"h-10 w-10": size === "sm",
|
|
58
|
+
"h-12 w-12": size === "md",
|
|
59
|
+
"h-14 w-14": size === "lg",
|
|
60
|
+
"h-16 w-16": size === "xl"
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const statusStyles = cn("absolute top-0 right-0 block rounded-full ring-2 ring-white", {
|
|
64
|
+
"h-1.5 w-1.5": size === "xxs",
|
|
65
|
+
"h-2 w-2": size === "xs",
|
|
66
|
+
"h-2.5 w-2.5": size === "sm",
|
|
67
|
+
"h-3 w-3": size === "md",
|
|
68
|
+
"h-3.5 w-3.5": size === "lg",
|
|
69
|
+
"h-4 w-4": size === "xl",
|
|
70
|
+
"bg-gray-300": status === "offline",
|
|
71
|
+
"bg-red-400": status === "busy",
|
|
72
|
+
"bg-green-400": status === "online"
|
|
73
|
+
})
|
|
74
|
+
const imageSize: number = useMemo(() => {
|
|
75
|
+
let imageSize: number = 0
|
|
76
|
+
switch (size) {
|
|
77
|
+
case "xxs":
|
|
78
|
+
imageSize = 24
|
|
79
|
+
break
|
|
80
|
+
case "xs":
|
|
81
|
+
imageSize = 32
|
|
82
|
+
break
|
|
83
|
+
case "sm":
|
|
84
|
+
imageSize = 40
|
|
85
|
+
break
|
|
86
|
+
case "md":
|
|
87
|
+
imageSize = 48
|
|
88
|
+
break
|
|
89
|
+
case "lg":
|
|
90
|
+
imageSize = 56
|
|
91
|
+
break
|
|
92
|
+
case "xl":
|
|
93
|
+
imageSize = 64
|
|
94
|
+
break
|
|
95
|
+
default:
|
|
96
|
+
imageSize = 48
|
|
97
|
+
break
|
|
98
|
+
}
|
|
99
|
+
return imageSize
|
|
100
|
+
}, [size])
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<span className="inline-block relative">
|
|
104
|
+
{src ? (
|
|
105
|
+
// eslint-disable-next-line @next/next/no-img-element
|
|
106
|
+
<img className={imageStyles} width={imageSize} height={imageSize} src={src} alt={alt} loading="eager" />
|
|
107
|
+
) : initials ? (
|
|
108
|
+
<span className={initialsStyles}>
|
|
109
|
+
<span className={fontStyles}>{initials}</span>
|
|
110
|
+
</span>
|
|
111
|
+
) : (
|
|
112
|
+
<span className={defaultAvatarStyles}>
|
|
113
|
+
<svg className="h-full w-full text-gray-300" fill="currentColor" viewBox="0 0 24 24">
|
|
114
|
+
<path d="M24 20.993V24H0v-2.996A14.977 14.977 0 0112.004 15c4.904 0 9.26 2.354 11.996 5.993zM16.002 8.999a4 4 0 11-8 0 4 4 0 018 0z" />
|
|
115
|
+
</svg>
|
|
116
|
+
</span>
|
|
117
|
+
)}
|
|
118
|
+
{status && <span className={statusStyles}></span>}
|
|
119
|
+
</span>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default Avatar
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import Avatar, { IAvatarProps } from "./Avatar"
|
|
2
|
-
export default Avatar
|
|
3
|
-
export type { IAvatarProps }
|
|
1
|
+
import Avatar, { IAvatarProps } from "./Avatar"
|
|
2
|
+
export default Avatar
|
|
3
|
+
export type { IAvatarProps }
|