-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request is intended to add the AvatarGroup component.
- Loading branch information
Selemondev
authored and
Selemondev
committed
Jul 28, 2023
1 parent
97843b2
commit c5986b0
Showing
23 changed files
with
263 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Slot, VNode } from 'vue' | ||
|
||
export function getSlotsFromChildren(slot: Slot | any): VNode[] { | ||
let children = slot?.default?.() | ||
if (children.length) { | ||
children = children.flatMap((c: { type: { name: string }; children: any; ctx: { slots: { default: () => any } } }) => { | ||
if (typeof c.type === 'symbol') { | ||
if (typeof c.children === 'string') | ||
return false | ||
|
||
return c.children | ||
} | ||
else if (c.type.name === 'ContentSlot') { | ||
return c.ctx.slots.default?.() | ||
} | ||
return c | ||
}).filter(Boolean) | ||
} | ||
return children | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script lang="ts"> | ||
import { cloneVNode, computed, defineComponent, h } from 'vue' | ||
import type { PropType, VNode } from 'vue' | ||
import classNames from 'classnames' | ||
import windiTheme from '../../theme/windiTheme' | ||
import { getSlotsFromChildren } from './Types' | ||
import WAvatar from './WAvatar.vue' | ||
import { getVariantPropsWithClassesList } from '@/utils/getVariantProps' | ||
import type { WAvatarGroup } from '@/Types/componentsTypes/components' | ||
import { Components } from '@/Types/enums/Components' | ||
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | ||
export default defineComponent({ | ||
name: Components.WAvatarGroup, | ||
...getVariantPropsWithClassesList<WAvatarGroup>(), | ||
props: { | ||
size: { | ||
type: String as PropType<AvatarSize>, | ||
default: 'md', | ||
}, | ||
max: { | ||
type: Number, | ||
default: null, | ||
}, | ||
}, | ||
setup(props, { slots }) { | ||
const children = computed(() => getSlotsFromChildren(slots)) | ||
// if max is passed as a string, we go ahead and convert it into an integer | ||
const max = computed(() => typeof props.max === 'string' ? Number.parseInt(props.max) : props.max) | ||
const clones = computed(() => children.value.map((node: VNode<unknown, unknown, { [key: string]: any }>, index: number) => { | ||
const vProps: Record<string, string> = {} | ||
if (!props.max || (max.value && index < max.value)) { | ||
if (props.size) | ||
vProps.size = props.size | ||
vProps.class = node.props?.class || '' | ||
vProps.class += `${classNames( | ||
windiTheme.WAvatarGroup.base.margin, | ||
)}` | ||
return cloneVNode(node, vProps) | ||
} | ||
if (max.value !== undefined && index === max.value) { | ||
return h(WAvatar, { | ||
size: props.size, | ||
text: `${children.value.length - max.value}`, | ||
name: `${children.value.length - max.value}`, | ||
}) | ||
} | ||
return null | ||
}).filter(Boolean).reverse()) | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
return () => h('div', { class: windiTheme.WAvatarGroup.base.root }, clones.value) | ||
}, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import Avatar from './WAvatar.vue' | ||
import AvatarGroup from './WAvatarGroup.vue' | ||
|
||
export default { | ||
Avatar, | ||
AvatarGroup, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@windi-ui/tailwind-config/postcss.config') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<script setup lang='ts'> | ||
</script> | ||
|
||
<template> | ||
<div> | ||
|
||
hello there | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.