From b565fb594b9adb8f07f5f1d665373cfbec656d74 Mon Sep 17 00:00:00 2001 From: khuctrang Date: Tue, 18 Jan 2022 17:11:38 +0700 Subject: [PATCH 1/7] fix: use bottom aligned avatar for bubble chat --- src/components/BubbleChat/index.js | 257 ++++++++++++++++------------- 1 file changed, 141 insertions(+), 116 deletions(-) diff --git a/src/components/BubbleChat/index.js b/src/components/BubbleChat/index.js index 503538c..a33dab4 100644 --- a/src/components/BubbleChat/index.js +++ b/src/components/BubbleChat/index.js @@ -94,7 +94,7 @@ const typeThemeClassNames = { const typeRadiusClassNames = { inbound: 'u-roundedExtraLarge u-roundedBottomRightNone', - outbound: 'u-roundedExtraLarge u-roundedBottomLeftNone', + outbound: 'u-roundedExtraLarge u-roundedBottomLeftNone', system: 'u-roundedExtraLarge', }; @@ -105,7 +105,63 @@ const BubbleChat = React.forwardRef(({ className, isTyping, text, type, variant, else if (type === 'outbound') variantOri = 'light'; else if (type === 'system') variantOri = 'primaryLight'; } + const context = useMemo(() => ({ type }), [type]); + + const renderTime = () => ( + <> + {type !== 'inbound' &&
} +
+ {time} +
+ {type === 'inbound' &&
} + + ); + + const renderTyping = () => ( +
+
+
+
+
+ ); + + const renderAvatar = (type = 'outbound') => ( +
+ {typeof (avatar) === 'function' + ? avatar() + : + } +
+ ); + return (
-
- {(avatar && type !== 'inbound') && ( -
- { - typeof (avatar) === 'function' ? avatar() : - } -
+
+ {(type !== 'inbound' && avatar) && renderAvatar('outbound')} + {(type !== 'inbound' && !avatar) &&
}
- {isTyping && ( -
-
-
-
-
- )} + {isTyping && renderTyping()} {!isTyping && ( - - {children || ( -
- {actionBar && ( -
- {actionBar} -
- )} -
-
+ {children || ( +
+ {actionBar && ( +
+ {actionBar} +
)} - onClick={onClickText} - > - {text} -
- {options && ( -
- {options.map((option, idx) => { - let cn; - let handleClick; +
+
+ {text} +
+ {options && ( +
+ {options.map((option, idx) => { + let cn; + let handleClick; - if (option.id === currentOption) { - cn = `u-backgroundPrimary ${textClassName || 'u-textWhite'} ${disabledOption ? 'u-cursorNotAllow' : ''}`; - handleClick = null; - } else if (disabledOption) { - cn = 'u-backgroundLighter u-textGray u-cursorNotAllow'; - handleClick = null; - } else { - cn = 'u-backgroundWhite hover:u-backgroundLightest u-textPrimary u-cursorPointer'; - handleClick = () => onSelectOption(option.id); - } + if (option.id === currentOption) { + cn = `u-backgroundPrimary ${textClassName || 'u-textWhite'} ${disabledOption ? 'u-cursorNotAllow' : ''}`; + handleClick = null; + } else if (disabledOption) { + cn = 'u-backgroundLighter u-textGray u-cursorNotAllow'; + handleClick = null; + } else { + cn = 'u-backgroundWhite hover:u-backgroundLightest u-textPrimary u-cursorPointer'; + handleClick = () => onSelectOption(option.id); + } - return ( - - ); - })} + return ( + + ); + })} +
+ )} +
- )} -
-
- )} - {time && ( -
- {time} -
- )} - + )} + )}
- {(avatar && (type !== 'outbound' && type !== 'system')) && ( -
- { - typeof (avatar) === 'function' ? avatar() : - } -
- )} + + {((type !== 'outbound' && type !== 'system') && avatar) && renderAvatar('inbound')} + {((type !== 'outbound' && type !== 'system') && !avatar) &&
} + + {time && renderTime()}
From ec7c0b93f96c0789ac73c355700631066e674ef4 Mon Sep 17 00:00:00 2001 From: khuctrang Date: Tue, 18 Jan 2022 17:12:01 +0700 Subject: [PATCH 2/7] fix: make bubble chat image style more predictable --- src/components/BubbleChat/Image.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/BubbleChat/Image.js b/src/components/BubbleChat/Image.js index c09381d..786421d 100644 --- a/src/components/BubbleChat/Image.js +++ b/src/components/BubbleChat/Image.js @@ -10,10 +10,12 @@ const BubbleChatImage = React.forwardRef(({ className, ...props }, ref) => { ref={ref} className={classNames( 'BubbleChat-image', - 'u-marginBottomTiny', (type === 'inbound') && 'u-textRight', className && className )} + style={{ + lineHeight: 0, + }} >
From ea23d0ab872f61f72fcd8ba43ad159c4d3f0df9d Mon Sep 17 00:00:00 2001 From: khuctrang Date: Tue, 18 Jan 2022 17:25:40 +0700 Subject: [PATCH 3/7] fix: add comments for hacky implementation --- src/components/BubbleChat/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/BubbleChat/index.js b/src/components/BubbleChat/index.js index a33dab4..7f9ebe5 100644 --- a/src/components/BubbleChat/index.js +++ b/src/components/BubbleChat/index.js @@ -110,6 +110,7 @@ const BubbleChat = React.forwardRef(({ className, isTyping, text, type, variant, const renderTime = () => ( <> + {/* Empty
to occupy the bottom left corner of grid template */} {type !== 'inbound' &&
}
{time}
+ {/* Empty
to occupy the bottom right corner of grid template */} {type === 'inbound' &&
} ); @@ -185,6 +187,7 @@ const BubbleChat = React.forwardRef(({ className, isTyping, text, type, variant, }} > {(type !== 'inbound' && avatar) && renderAvatar('outbound')} + {/* Empty
to occupy the top left corner of grid template */} {(type !== 'inbound' && !avatar) &&
}
{((type !== 'outbound' && type !== 'system') && avatar) && renderAvatar('inbound')} + {/* Empty
to occupy the top right corner of grid template */} {((type !== 'outbound' && type !== 'system') && !avatar) &&
} {time && renderTime()} From eb8aa2c9872ba439696a79ac9bf84f1feb55c5a2 Mon Sep 17 00:00:00 2001 From: khuctrang Date: Tue, 18 Jan 2022 17:26:03 +0700 Subject: [PATCH 4/7] docs: update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae56773..6440a7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Release 2.0.4 - Unreleased +### Fixed +* BubbleChat: Use bottom alignment for avatar +* BubbleChat.Image: Set `lineHeight` to `0` to make image in the same baseline with avatar ## Release 2.0.3 - January 18, 2022 ### Fixed * Code base: use absolute imports, rearrange hooks and utils From 1720f7303f016870d6071c7ba275fd2b99fad962 Mon Sep 17 00:00:00 2001 From: khuctrang Date: Tue, 18 Jan 2022 17:57:06 +0700 Subject: [PATCH 5/7] chore: update browserslist --- .browserslistrc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.browserslistrc b/.browserslistrc index 8289333..2e8bf2b 100644 --- a/.browserslistrc +++ b/.browserslistrc @@ -1,11 +1,12 @@ > 1% ie >= 8 -edge >= 15 +edge >= 16 ie_mob >= 10 -ff >= 45 -chrome >= 45 -safari >= 7 -opera >= 23 -ios >= 7 -android >= 4 +ff >= 52 +chrome >= 57 +safari >= 10.1 +opera >= 44 +ios >= 10.3 +and_uc >= 12.12 +and_chr >= 97 bb >= 10 From a685ec732e7ee7954cda3c0fed6edd8e7a008399 Mon Sep 17 00:00:00 2001 From: khuctrang Date: Tue, 18 Jan 2022 18:02:35 +0700 Subject: [PATCH 6/7] fix: prioritize classnames over inline style --- src/components/BubbleChat/Image.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/BubbleChat/Image.js b/src/components/BubbleChat/Image.js index 786421d..50bc8a2 100644 --- a/src/components/BubbleChat/Image.js +++ b/src/components/BubbleChat/Image.js @@ -10,12 +10,10 @@ const BubbleChatImage = React.forwardRef(({ className, ...props }, ref) => { ref={ref} className={classNames( 'BubbleChat-image', + 'u-lineHeightNone', (type === 'inbound') && 'u-textRight', className && className )} - style={{ - lineHeight: 0, - }} >
From dfc63630ba3833577aee89429e3cc2d0b0bb6f7e Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 19 Jan 2022 10:55:18 +0700 Subject: [PATCH 7/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6440a7c..38f34f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Fixed * BubbleChat: Use bottom alignment for avatar * BubbleChat.Image: Set `lineHeight` to `0` to make image in the same baseline with avatar + ## Release 2.0.3 - January 18, 2022 ### Fixed * Code base: use absolute imports, rearrange hooks and utils