11<template >
2- <div
3- v-if =" $slots.default"
2+ <pf-label-group
43 v-bind =" ouiaProps"
5- :id =" id"
6- :class =" [styles.chipGroup, {
7- [styles.modifiers.category]: category,
8- }]"
4+ :num-labels =" numChips"
5+ :close-btn-aria-label =" closeBtnAriaLabel"
6+ :aria-label =" ariaLabel"
7+ :expanded-text =" expandedText"
8+ :collapsed-text =" collapsedText"
99 >
10- <div :class =" styles.chipGroupMain" >
11- <pf-tooltip v-if =" category" >
12- <template v-if =" labelOverflowing " #content >
13- {{ category }}
14- </template >
15-
16- <span ref =" labelRef" :class =" styles.chipGroupLabel" >
17- {{ category }}
18- </span >
19- </pf-tooltip >
20-
21- <ul
22- :class =" styles.chipGroupList"
23- :aria-labelledby =" id"
24- :aria-label =" ariaLabel"
25- role =" list"
26- >
27- <render />
28- </ul >
29-
30- <div v-if =" closable" :class =" styles.chipGroupClose" >
31- <pf-button variant =" plain" :aria-label =" closeBtnAriaLabel" @click =" emit('click', $event)" >
32- <circle-xmark-icon aria-hidden />
33- </pf-button >
34- </div >
35- </div >
36- </div >
10+ <slot />
11+ </pf-label-group >
3712</template >
3813
3914<script lang="ts" setup>
40- import { h , ref , type Ref , type HTMLAttributes } from ' vue' ;
41- // import styles from '@patternfly/react-styles/css/components/Chip/chip-group';
42- import CircleXmarkIcon from ' @vue-patternfly/icons/circle-xmark-icon' ;
43- import PfChip from ' ./Chip.vue' ;
44- import PfButton from ' ../Button.vue' ;
45- import PfTooltip from ' ../Tooltip/Tooltip.vue' ;
46- import { findChildrenVNodes , fillTemplate } from ' ../../util' ;
47- import { useElementOverflow } from ' ../../use' ;
15+ import PfLabelGroup , { type Props as LabelGroupProps } from ' ../Label/LabelGroup.vue' ;
4816import { useOUIAProps , type OUIAProps } from ' ../../helpers/ouia' ;
49- import type { Placement } from ' ../../helpers/FloatingUi.vue' ;
5017
5118defineOptions ({
5219 name: ' PfChipGroup' ,
5320});
5421
55- export interface Props extends OUIAProps , /* @vue-ignore */ Omit <HTMLAttributes , ' onClick ' > {
22+ export interface Props extends OUIAProps , /* @vue-ignore */ Omit <LabelGroupProps , ' numLabels ' > {
5623 id? : string ;
57- defaultOpen? : boolean ;
58- closable? : boolean ;
59- category? : string ;
6024 numChips? : number ;
61- tooltipPosition? : Placement ;
6225 closeBtnAriaLabel? : string ;
6326 ariaLabel? : string ;
6427 expandedText? : string ;
@@ -67,58 +30,14 @@ export interface Props extends OUIAProps, /* @vue-ignore */ Omit<HTMLAttributes,
6730
6831const props = withDefaults (defineProps <Props >(), {
6932 numChips: 3 ,
70- tooltipPosition: ' top' ,
7133 closeBtnAriaLabel: ' Close chip group' ,
7234 ariaLabel: ' Chip group category' ,
7335 expandedText: ' Show Less' ,
7436 collapsedText: ' ${remaining} more' ,
7537});
7638const ouiaProps = useOUIAProps ({id: props .ouiaId , safe: props .ouiaSafe });
7739
78- const emit = defineEmits <{
79- (name : ' click' , e : PointerEvent ): void ;
80- (name : ' overflow-chip-click' , e : PointerEvent ): void ;
81- }>();
82-
8340const slots = defineSlots <{
8441 default? : (props ? : Record <never , never >) => any ;
8542}>();
86-
87- const labelRef: Ref <HTMLSpanElement | undefined > = ref ();
88- const labelOverflowing = useElementOverflow (labelRef );
89- const open = ref (props .defaultOpen );
90-
91- function overflowChipClick(e : PointerEvent ) {
92- toggleCollapse ();
93- emit (' overflow-chip-click' , e );
94- }
95-
96- function toggleCollapse() {
97- open .value = ! open .value ;
98- }
99-
100- function render() {
101- const children = slots .default ? findChildrenVNodes (slots .default ({})) : [];
102-
103- const chipArray = open .value ? children : children .slice (0 , props .numChips );
104-
105- const lis = chipArray .map ((child , i ) => h (' li' , { key: i , class: styles .chipGroupListItem }, child ));
106-
107- if (children .length > props .numChips ) {
108- const collapsedTextResult = fillTemplate (props .collapsedText , {
109- remaining: children .length - chipArray .length ,
110- });
111- lis .push (h (' li' , { class: styles .chipGroupListItem }, [
112- h (PfChip , {
113- component: ' button' ,
114- overflow: true ,
115- onClick: overflowChipClick as (e : MouseEvent ) => void ,
116- },
117- () => open .value ? props .expandedText : collapsedTextResult ,
118- ),
119- ]));
120- }
121-
122- return lis ;
123- }
12443 </script >
0 commit comments