-
Notifications
You must be signed in to change notification settings - Fork 51
feat(Chat): add different chat item types #255
Changes from all commits
cab3db6
53c4c4f
867e5d2
fcc43fa
d4536b1
83e95ed
8d66d14
4bf7cde
613abec
32ce04e
705a379
ecd7b4a
84dc413
5607068
1bad1ce
57c8ba7
30d7a23
c34c280
2bbc3a3
dc28481
f53003b
90b1e98
2c16fa1
d9214e6
5d5d635
218510b
4cc5fb5
c364df0
3def364
c4971c7
4c5a19f
a7f5462
b1ed360
e5b6e51
18b025a
e97beac
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 |
|---|---|---|
| @@ -1,30 +1,62 @@ | ||
| import React from 'react' | ||
| import { Chat, Divider } from '@stardust-ui/react' | ||
|
|
||
| import { Chat } from '@stardust-ui/react' | ||
| const janeAvatar = { | ||
| image: 'public/images/avatar/small/ade.jpg', | ||
| status: { color: 'green', icon: 'check' }, | ||
| } | ||
|
|
||
| const messages = [ | ||
| { key: 1, content: 'Hello', author: 'John Doe', timestamp: 'Yesterday, 10:15 PM', mine: true }, | ||
| { key: 2, content: 'Hi', author: 'Jane Doe', timestamp: 'Yesterday, 10:15 PM' }, | ||
| const items = [ | ||
| { | ||
| key: 3, | ||
| content: ( | ||
| <> | ||
| Let's go get some lunch! I suggest the new <a>Downtown Burgers</a> or <a>Chef's Finest</a>. | ||
| </> | ||
| <Chat.Message content="Hello" author="John Doe" timestamp="Yesterday, 10:15 PM" mine /> | ||
| ), | ||
| author: 'John Doe', | ||
| timestamp: 'Yesterday, 10:15 PM', | ||
| mine: true, | ||
| }, | ||
| { | ||
| key: 4, | ||
| content: | ||
| 'Sure thing. I was thinking we should try the new place downtown. The name of its chief promises a delicious food being offered.', | ||
| author: 'Jane Doe', | ||
| timestamp: 'Yesterday, 10:15 PM', | ||
| content: ( | ||
| <Chat.Message | ||
| content="Hi" | ||
| author="Jane Doe" | ||
| timestamp="Yesterday, 10:15 PM" | ||
| avatar={janeAvatar} | ||
| /> | ||
| ), | ||
| }, | ||
| { | ||
| content: ( | ||
| <Chat.Message | ||
| content="Would you like to grab a lunch?" | ||
| author="John Doe" | ||
| timestamp="Yesterday, 10:16 PM" | ||
| mine | ||
| /> | ||
| ), | ||
| }, | ||
| { | ||
| content: ( | ||
| <Chat.Message | ||
| content="Sure! Let's try the new place downtown" | ||
| author="Jane Doe" | ||
| timestamp="Yesterday, 10:15 PM" | ||
| avatar={janeAvatar} | ||
| /> | ||
| ), | ||
| }, | ||
| { | ||
| content: <Divider content="Today" type="primary" important />, | ||
| }, | ||
| { | ||
| content: ( | ||
| <Chat.Message | ||
| content="Let's have a call" | ||
| author="John Doe" | ||
| timestamp="Today, 11:15 PM" | ||
| mine | ||
| /> | ||
| ), | ||
| }, | ||
| ] | ||
|
|
||
| const ChatExampleShorthand = () => <Chat messages={messages} /> | ||
| const ChatExample = () => <Chat items={items} /> | ||
|
|
||
| export default ChatExampleShorthand | ||
| export default ChatExample |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import React from 'react' | ||
| import { Chat, Divider } from '@stardust-ui/react' | ||
|
|
||
| const janeAvatar = { | ||
| image: 'public/images/avatar/small/ade.jpg', | ||
| status: { color: 'green', icon: 'check' }, | ||
| } | ||
|
|
||
| const ChatExample = () => ( | ||
| <Chat> | ||
| <Chat.Item> | ||
| <Chat.Message content="Hello" author="John Doe" timestamp="Yesterday, 10:15 PM" mine /> | ||
| </Chat.Item> | ||
| <Chat.Item> | ||
| <Chat.Message | ||
| content="Hi" | ||
| author="Jane Doe" | ||
| timestamp="Yesterday, 10:15 PM" | ||
| avatar={janeAvatar} | ||
| /> | ||
| </Chat.Item> | ||
| <Chat.Item> | ||
| <Chat.Message | ||
| content="Would you like to grab a lunch?" | ||
| author="John Doe" | ||
| timestamp="Yesterday, 10:16 PM" | ||
| mine | ||
| /> | ||
| </Chat.Item> | ||
| <Chat.Item> | ||
| <Chat.Message | ||
| content="Sure! Let's try the new place downtown" | ||
| author="Jane Doe" | ||
| timestamp="Yesterday, 10:15 PM" | ||
| avatar={janeAvatar} | ||
| /> | ||
| </Chat.Item> | ||
| <Chat.Item> | ||
| <Divider content="Today" type="primary" important /> | ||
| </Chat.Item> | ||
| <Chat.Item> | ||
| <Chat.Message | ||
| content="Let's have a call" | ||
| author="John Doe" | ||
| timestamp="Today, 11:15 PM" | ||
| mine | ||
| /> | ||
| </Chat.Item> | ||
| </Chat> | ||
| ) | ||
|
|
||
| export default ChatExample | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,10 @@ | ||
| import React from 'react' | ||
| import Types from './Types' | ||
| import Variations from './Variations' | ||
|
|
||
| const MessageExamples = () => ( | ||
| const ChatExamples = () => ( | ||
| <div> | ||
| <Types /> | ||
| <Variations /> | ||
| </div> | ||
| ) | ||
|
|
||
| export default MessageExamples | ||
| export default ChatExamples |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import * as React from 'react' | ||
| import * as PropTypes from 'prop-types' | ||
|
|
||
| import { | ||
| createShorthandFactory, | ||
| customPropTypes, | ||
| IRenderResultConfig, | ||
| UIComponent, | ||
| } from '../../lib' | ||
| import { ComponentPartStyle, ComponentVariablesInput } from '../../../types/theme' | ||
| import { Extendable, ReactChildren } from '../../../types/utils' | ||
| import childrenExist from '../../lib/childrenExist' | ||
|
|
||
| export interface IChatItemProps { | ||
| as?: any | ||
| content?: React.ReactNode | ||
| children?: ReactChildren | ||
| className?: string | ||
| styles?: ComponentPartStyle | ||
| variables?: ComponentVariablesInput | ||
| } | ||
|
|
||
| class ChatItem extends UIComponent<Extendable<IChatItemProps>, any> { | ||
| static className = 'ui-chat__item' | ||
|
|
||
| static create: Function | ||
|
|
||
| static displayName = 'ChatItem' | ||
|
|
||
| static propTypes = { | ||
| /** An element type to render as (string or function). */ | ||
| as: customPropTypes.as, | ||
|
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. nit: description for this prop is missing (as well s for a few other components of this PR, like
Contributor
Author
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. It's not intentional, will provide description for all prop types in the components added/changed in this PR. |
||
|
|
||
| /** Child content. */ | ||
| children: PropTypes.node, | ||
|
|
||
| /** Additional CSS class name(s) to apply. */ | ||
| className: PropTypes.string, | ||
|
|
||
| /** Custom styles to be applied for component. */ | ||
| styles: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
|
|
||
| /** Custom variables to be applied for component. */ | ||
| variables: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
| } | ||
|
|
||
| static defaultProps = { | ||
| as: 'li', | ||
| } | ||
|
|
||
| renderComponent({ ElementType, classes, rest }: IRenderResultConfig<IChatItemProps>) { | ||
| const { children, content } = this.props | ||
|
|
||
| return ( | ||
| <ElementType {...rest} className={classes.root}> | ||
|
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. 👍 |
||
| {childrenExist(children) ? children : content} | ||
| </ElementType> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| ChatItem.create = createShorthandFactory(ChatItem, content => ({ content })) | ||
|
|
||
| export default ChatItem | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,15 +6,15 @@ import { | |
| childrenExist, | ||
| createShorthandFactory, | ||
| customPropTypes, | ||
| UIComponent, | ||
| IRenderResultConfig, | ||
| UIComponent, | ||
| } from '../../lib' | ||
| import { | ||
| ComponentVariablesInput, | ||
| ComponentPartStyle, | ||
| ComponentVariablesInput, | ||
|
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. I like the ordered dependencies :) |
||
| IComponentPartStylesInput, | ||
| } from '../../../types/theme' | ||
| import { Extendable, ReactChildren, ItemShorthand } from '../../../types/utils' | ||
| import { Extendable, ItemShorthand, ReactChildren } from '../../../types/utils' | ||
| import Avatar from '../Avatar' | ||
| import ChatMessageBehavior from '../../lib/accessibility/Behaviors/Chat/ChatMessageBehavior' | ||
| import { Accessibility, AccessibilityActionHandlers } from '../../lib/accessibility/interfaces' | ||
|
|
@@ -46,12 +46,13 @@ class ChatMessage extends UIComponent<Extendable<IChatMessageProps>, any> { | |
| /** Accessibility behavior if overridden by the user. */ | ||
| accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), | ||
|
|
||
| /** An element type to render as (string or function). */ | ||
| as: customPropTypes.as, | ||
|
|
||
| /** Author of the message. */ | ||
| author: customPropTypes.itemShorthand, | ||
|
|
||
| /** Chat messages can have an avatar */ | ||
| /** Chat messages can have an avatar. */ | ||
| avatar: customPropTypes.itemShorthand, | ||
|
|
||
| /** Child content. */ | ||
|
|
@@ -78,7 +79,7 @@ class ChatMessage extends UIComponent<Extendable<IChatMessageProps>, any> { | |
|
|
||
| static defaultProps = { | ||
| accessibility: ChatMessageBehavior as Accessibility, | ||
| as: 'li', | ||
| as: 'div', | ||
| } | ||
|
|
||
| actionHandlers: AccessibilityActionHandlers = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export { default } from './Chat' | ||
| export { default as ChatItem } from './ChatItem' | ||
| export { default as ChatMessage } from './ChatMessage' |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shorthand API currently is not working correctly in docs examples - the problem is apparent if one would try to click on 'Shorthand API' button:
Do we really want to dismiss shorthand case for
Chat? This seems to be confusing, as by looking onChat's implementation it is clearly visible thatitemsprop is exposed - thus, it is possible to utilize shorthand advantages for this component. More than that, it seems that we won't be able to get rid of Shorthand API support, due to in this case there won't be clear mechanisms for handlingChatcomponent's accessibility concerns.