{ "name": "avatar", "file": "compositions/ui/avatar", "snippet": "import {\n Avatar as ChakraAvatar,\n AvatarGroup as ChakraAvatarGroup,\n} from \"@chakra-ui/react\"\nimport * as React from \"react\"\n\ntype ImageProps = React.ImgHTMLAttributes\n\nexport interface AvatarProps extends ChakraAvatar.RootProps {\n name?: string\n src?: string\n srcSet?: string\n loading?: ImageProps[\"loading\"]\n icon?: React.ReactElement\n fallback?: React.ReactNode\n}\n\nexport const Avatar = React.forwardRef(\n function Avatar(props, ref) {\n const { name, src, srcSet, loading, icon, fallback, children, ...rest } =\n props\n return (\n \n \n {icon || fallback}\n \n \n {children}\n \n )\n },\n)\n\nexport const AvatarGroup = ChakraAvatarGroup\n", "examples": [ { "name": "avatar-basic", "content": "export const AvatarBasic = () => {\n return (\n \n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-closed-component", "content": "type ImageProps = React.ImgHTMLAttributes\n\nexport interface AvatarProps extends ChakraAvatar.RootProps {\n name?: string\n src?: string\n srcSet?: string\n loading?: ImageProps[\"loading\"]\n icon?: React.ReactElement\n fallback?: React.ReactNode\n}\n\nexport const Avatar = React.forwardRef(\n function Avatar(props, ref) {\n const { name, src, srcSet, loading, icon, fallback, children, ...rest } =\n props\n return (\n \n \n {fallback || icon}\n \n \n {children}\n \n )\n },\n)\n\nexport const AvatarGroup = ChakraAvatarGroup\n", "hasSnippet": false, "importPaths": [ "import {\n Avatar as ChakraAvatar,\n AvatarGroup as ChakraAvatarGroup,\n} from \"@chakra-ui/react\"", "import * as React from \"react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-group-with-stacking", "content": "export const AvatarGroupWithStacking = () => {\n return (\n \n \n {items.map((item) => (\n \n \n \n \n ))}\n \n +3\n \n \n\n \n {items.map((item) => (\n \n \n \n \n ))}\n \n +3\n \n \n\n \n {items.map((item) => (\n \n \n \n \n ))}\n \n +3\n \n \n \n )\n}\n\nconst items = [\n {\n src: \"https://cdn.myanimelist.net/r/84x124/images/characters/9/131317.webp?s=d4b03c7291407bde303bc0758047f6bd\",\n name: \"Uchiha Sasuke\",\n },\n {\n src: \"https://cdn.myanimelist.net/r/84x124/images/characters/7/284129.webp?s=a8998bf668767de58b33740886ca571c\",\n name: \"Baki Ani\",\n },\n {\n src: \"https://cdn.myanimelist.net/r/84x124/images/characters/9/105421.webp?s=269ff1b2bb9abe3ac1bc443d3a76e863\",\n name: \"Uchiha Chan\",\n },\n]\n", "hasSnippet": false, "importPaths": [ "import { Avatar, AvatarGroup, Stack } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-persona", "content": "export const AvatarPersona = () => {\n return (\n \n {users.map((user) => (\n \n \n \n \n \n \n {user.name}\n \n {user.email}\n \n \n \n ))}\n \n )\n}\n\nconst users = [\n {\n id: \"1\",\n name: \"John Mason\",\n email: \"john.mason@example.com\",\n avatar: \"https://i.pravatar.cc/300?u=iu\",\n },\n {\n id: \"2\",\n name: \"Melissa Jones\",\n email: \"melissa.jones@example.com\",\n avatar: \"https://i.pravatar.cc/300?u=po\",\n },\n]\n", "hasSnippet": false, "importPaths": [ "import { Avatar, HStack, Stack, Text } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-badge", "content": "export const AvatarWithBadge = () => {\n return (\n \n \n \n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, Circle, Float } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-colors", "content": "export const AvatarWithColors = () => {\n return (\n \n {colorPalettes.map((colorPalette) => (\n \n {colorPalette}\n \n \n \n \n \n \n \n \n \n \n \n ))}\n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, Stack, Text } from \"@chakra-ui/react\"", "import { colorPalettes } from \"compositions/lib/color-palettes\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-fallback", "content": "export const AvatarWithFallback = () => {\n return (\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, HStack } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-group", "content": "export const AvatarWithGroup = () => {\n return (\n \n \n \n \n \n\n \n \n \n \n\n \n \n \n \n \n +3\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, AvatarGroup } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-overflow", "content": "const names = [\n \"Naruto Uzumaki\",\n \"Sakura Haruno\",\n \"Kakashi Hatake\",\n \"Hinata Hyuga\",\n \"Shikamaru Nara\",\n]\nconst maxAvatars = 3\n\nexport const AvatarWithOverflow = () => {\n const { items, overflow } = partition(names, maxAvatars)\n return (\n \n {items.map((item) => (\n \n \n \n ))}\n {overflow.length > 0 && (\n \n \n \n +{overflow.length}\n \n \n \n \n \n {overflow.map((item) => (\n \n \n \n \n {item}\n \n ))}\n \n \n \n \n )}\n \n )\n}\n\nconst colorPalette = [\"red\", \"blue\", \"green\", \"yellow\", \"purple\", \"orange\"]\n\nconst pickPalette = (name: string) => {\n const index = name.charCodeAt(0) % colorPalette.length\n return colorPalette[index]\n}\n\nconst partition = (arr: string[], max: number) => {\n const items = []\n const overflow = []\n for (const item of arr) {\n if (items.length < max) items.push(item)\n else overflow.push(item)\n }\n return { items, overflow }\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, Group, Menu, Portal } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-random-color", "content": "const colorPalette = [\"red\", \"blue\", \"green\", \"yellow\", \"purple\", \"orange\"]\n\nconst pickPalette = (name: string) => {\n const index = name.charCodeAt(0) % colorPalette.length\n return colorPalette[index]\n}\n\nexport const AvatarWithRandomColor = () => {\n return (\n \n \n \n \n \n \n \n \n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, HStack } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-ring", "content": "const ringCss = defineStyle({\n outlineWidth: \"2px\",\n outlineColor: \"colorPalette.500\",\n outlineOffset: \"2px\",\n outlineStyle: \"solid\",\n})\n\nexport const AvatarWithRing = () => {\n return (\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, HStack, defineStyle } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-shape", "content": "export const AvatarWithShape = () => {\n return (\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, HStack } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-sizes", "content": "export const AvatarWithSizes = () => {\n return (\n \n \n {(size) => (\n \n \n \n \n )}\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, For, HStack } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-store", "content": "\"use client\"\nexport const AvatarWithStore = () => {\n const avatar = useAvatar()\n return (\n \n \n \n \n \n {avatar.loaded ? \"loaded\" : \"not loaded\"}\n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, Code, Stack, useAvatar } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" }, { "name": "avatar-with-variants", "content": "export const AvatarWithVariants = () => {\n return (\n \n \n {(variant) => (\n \n \n \n )}\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Avatar, For, HStack } from \"@chakra-ui/react\"" ], "importPath": "import { Avatar } from \"@chakra-ui/react\"" } ] }