-
Notifications
You must be signed in to change notification settings - Fork 2.9k
BREAKING-CHANGE: new ChatMessageContent for style caching #24691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e784d98
b4e735d
8e19434
48433a9
3ffd532
15a65d8
cf04b0e
a33934e
a4df770
13ebe54
5cdd745
adb1c67
3a0752e
4a9d7f3
6db6cfb
d17de44
226a1b1
f30934e
6ed1c3e
e37308c
4b3e3f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { compose } from '@fluentui/react-bindings'; | ||
| import * as PropTypes from 'prop-types'; | ||
|
|
||
| import { commonPropTypes } from '../../utils'; | ||
| import { Box, BoxProps, BoxStylesProps } from '../Box/Box'; | ||
| import { ChatDensity } from './chatDensity'; | ||
| import { ChatMessageLayout, ChatMessageProps } from './ChatMessage'; | ||
|
|
||
| export interface ChatMessageContentOwnProps | ||
| extends Pick<ChatMessageProps, 'badgePosition' | 'density' | 'failed' | 'mine' | 'unstable_layout'> { | ||
| /** Indicates whether parent ChatMessage has badge. */ | ||
| hasBadge?: boolean; | ||
| } | ||
| export interface ChatMessageContentProps extends ChatMessageContentOwnProps, BoxProps {} | ||
|
|
||
| export type ChatMessageContentStylesProps = Required< | ||
| Pick<ChatMessageContentOwnProps, 'badgePosition' | 'density' | 'failed' | 'hasBadge' | 'mine'> | ||
| > & { | ||
| layout: ChatMessageLayout; | ||
| }; | ||
| export const chatMessageContentClassName = 'ui-chat__messagecontent'; | ||
|
|
||
| /** | ||
| * A ChatMessageContent provides a slot for content in the ChatMessage. | ||
| */ | ||
| export const ChatMessageContent = compose< | ||
| 'div', | ||
| ChatMessageContentOwnProps, | ||
| ChatMessageContentStylesProps, | ||
| BoxProps, | ||
| BoxStylesProps | ||
| >(Box, { | ||
| className: chatMessageContentClassName, | ||
| displayName: 'ChatMessageContent', | ||
| handledProps: ['badgePosition', 'density', 'failed', 'hasBadge', 'mine', 'unstable_layout'], | ||
| mapPropsToStylesProps: ({ badgePosition, density, failed, hasBadge, mine, unstable_layout }) => ({ | ||
| badgePosition, | ||
| density, | ||
| failed, | ||
| hasBadge, | ||
| layout: unstable_layout, | ||
| mine, | ||
| }), | ||
| overrideStyles: true, | ||
| shorthandConfig: { mappedProp: 'content' }, | ||
| }); | ||
|
|
||
| ChatMessageContent.propTypes = { | ||
| ...commonPropTypes.createCommon(), | ||
| badgePosition: PropTypes.oneOf(['start', 'end']), | ||
| density: PropTypes.oneOf<ChatDensity>(['comfy', 'compact']), | ||
| failed: PropTypes.bool, | ||
| hasBadge: PropTypes.bool, | ||
| mine: PropTypes.bool, | ||
| unstable_layout: PropTypes.oneOf(['default', 'refresh']), | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { ComponentSlotStylesPrepared, ICSSInJSStyle } from '@fluentui/styles'; | ||
|
|
||
| import { ChatMessageContentStylesProps } from '../../../../components/Chat/ChatMessageContent'; | ||
| import { ChatMessageVariables } from './chatMessageVariables'; | ||
| import { pxToRem } from '../../../../utils'; | ||
|
|
||
| export const chatMessageContentStyles: ComponentSlotStylesPrepared< | ||
| ChatMessageContentStylesProps, | ||
| ChatMessageVariables | ||
| > = { | ||
| root: (componentStyleFunctionParam): ICSSInJSStyle => { | ||
| const { props: p, variables: v, theme } = componentStyleFunctionParam; | ||
| return { | ||
| color: v.contentColor, | ||
| display: 'block', | ||
| '& a': { | ||
| outline: 'none', | ||
| color: p.mine ? v.linkColorMine : v.linkColor, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davezuko Is this how we're styling links in TMP?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In TMP it looks like links are colored the same for both my/their messages, so this doesn't seem necessary. |
||
| ':focus': { | ||
| textDecoration: 'underline', | ||
| }, | ||
| }, | ||
|
|
||
| ...(p.layout === 'refresh' && | ||
| p.density === 'comfy' && { | ||
| wordBreak: 'break-word', | ||
| wordWrap: 'break-word', | ||
| '& a': { | ||
| color: 'inherit', | ||
| textDecoration: 'underline', | ||
| wordBreak: 'break-all', | ||
| '&:hover': { textDecorationStyle: 'double' }, | ||
| '&:focus': { textDecorationStyle: 'double' }, | ||
| }, | ||
| ...(p.failed && { | ||
| color: theme.siteVariables.colorScheme.default.foreground, | ||
| }), | ||
| }), | ||
|
|
||
| ...(p.density === 'comfy' && { | ||
| ...(p.hasBadge && p.badgePosition === 'end' && { marginRight: pxToRem(4) }), | ||
| }), | ||
| }; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { chatMessageVariables as chatMessageContentVariables } from './chatMessageVariables'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { ChatMessageContent } from 'src/components/Chat/ChatMessageContent'; | ||
| import { isConformant } from 'test/specs/commonTests'; | ||
|
|
||
| describe('ChatMessageContent', () => { | ||
| isConformant(ChatMessageContent, { | ||
| testPath: __filename, | ||
| constructorName: 'ChatMessageContent', | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.