Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cab3db6
-adjusting the header according to the styling guides
Sep 20, 2018
53c4c4f
-added chat action, bubble components
Sep 20, 2018
867e5d2
-fixing linting errors
Sep 20, 2018
fcc43fa
-fixed example
Sep 20, 2018
d4536b1
-fixed resizing of the bubble message
Sep 20, 2018
83e95ed
-added TODO for the wrapping
Sep 20, 2018
8d66d14
-added restrictions on the bubble, divider and action props
Sep 21, 2018
4bf7cde
-added examples for the different types of chat items
Sep 21, 2018
613abec
-small fixes in the description of the props
Sep 21, 2018
32ce04e
-changed the fontSize inside the chat action component to match the T…
Sep 21, 2018
705a379
-updated CHANGELOG
Sep 21, 2018
ecd7b4a
-adjust the styles for the icon inside the ChatAction component to ma…
Sep 21, 2018
84dc413
Merge branch 'master' into feat/chat-message-types
Sep 21, 2018
5607068
-removed ChatAction component
Sep 25, 2018
1bad1ce
Merge branch 'master' into feat/chat-message-types
Sep 25, 2018
57c8ba7
-updated CHANGELOG
Sep 25, 2018
30d7a23
-fixed chat example
Sep 25, 2018
c34c280
-changed description in props
Sep 26, 2018
2bbc3a3
-small fix
Sep 26, 2018
dc28481
-removed avatar and contentStyle from the ChatMessage component
Sep 27, 2018
f53003b
.
Sep 27, 2018
90b1e98
-reverting changes from merge
Sep 27, 2018
2c16fa1
-reverting changes from merge
Sep 27, 2018
d9214e6
-reverted changes to Button.tsx
Sep 27, 2018
5d5d635
-reverted changes to Button.tsx
Sep 27, 2018
218510b
-reverted changes to Button.tsx
Sep 27, 2018
4cc5fb5
-reverted auto sorted imports
Sep 27, 2018
c364df0
-fixed changelog
Sep 27, 2018
3def364
-fixing merging conflicts
Sep 27, 2018
c4971c7
-fixes after merging
Sep 27, 2018
4c5a19f
-fixes after merging
Sep 27, 2018
a7f5462
docs: cleanup chat example
levithomason Sep 27, 2018
b1ed360
-resolved comments on PR (added shorthand example, changed styles for…
Oct 1, 2018
e5b6e51
-providede the content API for the ChatItems in the shorthand example…
Oct 1, 2018
18b025a
Merge branch 'master' into feat/chat-message-types
Oct 1, 2018
e97beac
-merge conflicts and updating changelog
Oct 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### BREAKING CHANGES
- Change font ramp and Text size API @codepretty ([#214](https://github.com/stardust-ui/react/pull/214))
- Add `ChatItem` component that can be used inside the `Chat` via the Children API or the `items` prop, instead of the `Chat.Message` used directly in the previous `messages` prop @mnajdova ([#255](https://github.com/stardust-ui/react/pull/255))

### Features
- Add embed mode for `FocusZone` and use it in newly added Chat behaviors @tomasiser ([#233](https://github.com/stardust-ui/react/pull/233))
Expand Down
68 changes: 50 additions & 18 deletions docs/src/examples/components/Chat/Types/ChatExample.shorthand.tsx
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
52 changes: 52 additions & 0 deletions docs/src/examples/components/Chat/Types/ChatExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react'
Copy link
Contributor

@kuzhelov kuzhelov Oct 1, 2018

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:

image

Do we really want to dismiss shorthand case for Chat? This seems to be confusing, as by looking on Chat's implementation it is clearly visible that items prop 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 handling Chat component's accessibility concerns.

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.

15 changes: 0 additions & 15 deletions docs/src/examples/components/Chat/Variations/index.tsx

This file was deleted.

6 changes: 2 additions & 4 deletions docs/src/examples/components/Chat/index.tsx
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
20 changes: 11 additions & 9 deletions src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import * as PropTypes from 'prop-types'
import * as React from 'react'

import { childrenExist, customPropTypes, UIComponent } from '../../lib'
import ChatItem from './ChatItem'
import ChatMessage from './ChatMessage'
import { ComponentVariablesInput, ComponentPartStyle } from '../../../types/theme'
import { Extendable, ReactChildren, ItemShorthand } from '../../../types/utils'
import { ComponentPartStyle, ComponentVariablesInput } from '../../../types/theme'
import { Extendable, ItemShorthand, ReactChildren } from '../../../types/utils'
import { Accessibility, AccessibilityActionHandlers } from '../../lib/accessibility/interfaces'
import ChatBehavior from '../../lib/accessibility/Behaviors/Chat/ChatBehavior'

Expand All @@ -14,7 +15,7 @@ export interface IChatProps {
as?: any
className?: string
children?: ReactChildren
messages?: ItemShorthand[]
items?: ItemShorthand[]
styles?: ComponentPartStyle
variables?: ComponentVariablesInput
}
Expand All @@ -28,15 +29,17 @@ class Chat extends UIComponent<Extendable<IChatProps>, 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,

/** Additional CSS class name(s) to apply. */
className: PropTypes.string,

/** Child content. */
children: PropTypes.node,

/** Shorthand array of messages. */
messages: PropTypes.arrayOf(PropTypes.any),
/** Shorthand array of the items inside the chat. */
items: PropTypes.arrayOf(customPropTypes.itemShorthand),

/** Additional CSS styles to apply to the component instance. */
styles: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
Expand All @@ -47,14 +50,15 @@ class Chat extends UIComponent<Extendable<IChatProps>, any> {

static defaultProps = { accessibility: ChatBehavior as Accessibility, as: 'ul' }

static Item = ChatItem
static Message = ChatMessage

actionHandlers: AccessibilityActionHandlers = {
focus: event => this.focusZone && this.focusZone.focus(),
}

renderComponent({ ElementType, classes, accessibility, rest }) {
const { children, messages } = this.props
const { children, items } = this.props

return (
<ElementType
Expand All @@ -63,9 +67,7 @@ class Chat extends UIComponent<Extendable<IChatProps>, any> {
{...accessibility.keyHandlers.root}
{...rest}
>
{childrenExist(children)
? children
: _.map(messages, message => ChatMessage.create(message))}
{childrenExist(children) ? children : _.map(items, item => ChatItem.create(item))}
</ElementType>
)
}
Expand Down
64 changes: 64 additions & 0 deletions src/components/Chat/ChatItem.tsx
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,
Copy link
Contributor

@kuzhelov kuzhelov Oct 1, 2018

Choose a reason for hiding this comment

The 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 ChatMessage) - is it intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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}>
Copy link
Contributor

Choose a reason for hiding this comment

The 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
11 changes: 6 additions & 5 deletions src/components/Chat/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
childrenExist,
createShorthandFactory,
customPropTypes,
UIComponent,
IRenderResultConfig,
UIComponent,
} from '../../lib'
import {
ComponentVariablesInput,
ComponentPartStyle,
ComponentVariablesInput,
Copy link
Contributor

Choose a reason for hiding this comment

The 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'
Expand Down Expand Up @@ -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. */
Expand All @@ -78,7 +79,7 @@ class ChatMessage extends UIComponent<Extendable<IChatMessageProps>, any> {

static defaultProps = {
accessibility: ChatMessageBehavior as Accessibility,
as: 'li',
as: 'div',
}

actionHandlers: AccessibilityActionHandlers = {
Expand Down
1 change: 1 addition & 0 deletions src/components/Chat/index.ts
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'
Loading