1- import React , { useMemo } from 'react' ;
1+ import React , { useMemo , useState } from 'react' ;
22import clsx from 'clsx' ;
33
44import { useDialog } from '../Dialog' ;
@@ -24,6 +24,7 @@ const stableOwnReactions: ReactionResponse[] = [];
2424
2525const UnMemoizedReactionSelector = ( props : ReactionSelectorProps ) => {
2626 const { handleReaction : propHandleReaction , own_reactions : propOwnReactions } = props ;
27+ const [ extendedListOpen , setExtendedListOpen ] = useState ( false ) ;
2728
2829 const { reactionOptions = defaultReactionOptions } =
2930 useComponentContext ( 'ReactionSelector' ) ;
@@ -49,40 +50,88 @@ const UnMemoizedReactionSelector = (props: ReactionSelectorProps) => {
4950 return map ;
5051 } , [ ownReactions ] ) ;
5152
53+ const adjustedQuickReactionOptions = useMemo ( ( ) => {
54+ if ( Array . isArray ( reactionOptions ) ) return reactionOptions ;
55+
56+ return Object . entries ( reactionOptions . quick ) . map (
57+ ( [ type , { Component, name, unicode } ] ) => ( {
58+ Component,
59+ name,
60+ type,
61+ unicode,
62+ } ) ,
63+ ) ;
64+ } , [ reactionOptions ] ) ;
65+
5266 return (
5367 < div className = 'str-chat__reaction-selector' data-testid = 'reaction-selector' >
54- < ul className = 'str-chat__reaction-selector-list' >
55- { reactionOptions . map ( ( { Component, name : reactionName , type : reactionType } ) => (
56- < li className = 'str-chat__reaction-list-selector__item' key = { reactionType } >
57- < button
58- aria-label = { `Select Reaction: ${ reactionName || reactionType } ` }
59- aria-pressed = { typeof ownReactionByType [ reactionType ] !== 'undefined' }
60- className = { clsx ( 'str-chat__reaction-selector-list__item-button' ) }
61- data-testid = 'select-reaction-button'
62- data-text = { reactionType }
63- onClick = { ( event ) => {
64- handleReaction ( reactionType , event ) ;
65- if ( closeReactionSelectorOnClick ) {
66- dialog . close ( ) ;
67- }
68- } }
69- >
70- < span className = 'str-chat__reaction-icon' >
71- < Component />
72- </ span >
73- </ button >
74- </ li >
75- ) ) }
76- </ ul >
77- < Button
78- appearance = 'outline'
79- circular
80- className = 'str-chat__reaction-selector__add-button'
81- size = 'sm'
82- variant = 'secondary'
83- >
84- < IconPlusLarge />
85- </ Button >
68+ { ! extendedListOpen && (
69+ < >
70+ < ul className = 'str-chat__reaction-selector-list' >
71+ { adjustedQuickReactionOptions . map (
72+ ( { Component, name : reactionName , type : reactionType } ) => (
73+ < li className = 'str-chat__reaction-list-selector__item' key = { reactionType } >
74+ < button
75+ aria-label = { `Select Reaction: ${ reactionName || reactionType } ` }
76+ aria-pressed = { typeof ownReactionByType [ reactionType ] !== 'undefined' }
77+ className = { clsx ( 'str-chat__reaction-selector-list__item-button' ) }
78+ data-testid = 'select-reaction-button'
79+ data-text = { reactionType }
80+ onClick = { ( event ) => {
81+ handleReaction ( reactionType , event ) ;
82+ if ( closeReactionSelectorOnClick ) {
83+ dialog . close ( ) ;
84+ }
85+ } }
86+ >
87+ < span className = 'str-chat__reaction-icon' >
88+ < Component />
89+ </ span >
90+ </ button >
91+ </ li >
92+ ) ,
93+ ) }
94+ </ ul >
95+ < Button
96+ appearance = 'outline'
97+ circular
98+ className = 'str-chat__reaction-selector__add-button'
99+ onClick = { ( ) => setExtendedListOpen ( true ) }
100+ size = 'sm'
101+ variant = 'secondary'
102+ >
103+ < IconPlusLarge />
104+ </ Button >
105+ </ >
106+ ) }
107+ { extendedListOpen &&
108+ ! Array . isArray ( reactionOptions ) &&
109+ reactionOptions . extended && (
110+ < div className = 'str-chat__reaction-selector-extended-list' >
111+ { Object . entries ( reactionOptions . extended ) . map (
112+ ( [ reactionType , { Component, name : reactionName } ] ) => (
113+ < button
114+ aria-label = { `Select Reaction: ${ reactionName || reactionType } ` }
115+ aria-pressed = { typeof ownReactionByType [ reactionType ] !== 'undefined' }
116+ className = 'str-chat__reaction-selector-extended-list__button str-chat__button str-chat__button--ghost str-chat__button--size-sm str-chat__button--circular'
117+ data-testid = 'select-reaction-button'
118+ data-text = { reactionType }
119+ key = { reactionType }
120+ onClick = { ( event ) => {
121+ handleReaction ( reactionType , event ) ;
122+ if ( closeReactionSelectorOnClick ) {
123+ dialog . close ( ) ;
124+ }
125+ } }
126+ >
127+ < span className = 'str-chat__reaction-icon' >
128+ < Component />
129+ </ span >
130+ </ button >
131+ ) ,
132+ ) }
133+ </ div >
134+ ) }
86135 </ div >
87136 ) ;
88137} ;
0 commit comments