Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
chore(types): make Props param in ShorthandValue and ShorthandCollect…
Browse files Browse the repository at this point in the history
…ion required (#1605)

* chore(types): make Props param in ShorthandValue and ShorthandCollection required

* fix issues

* fix types

* fix types

* fix imports

* replace ShorthandValue[]

* fix type

* fix usage of `ShorthandValue[]`

* fix type

* type `reactions` in examples

* fix `message` type

* update to use ShorthandCollection<ListItemProps>

* fix types in DropdownItem

* remove cruft content

* add a comment

* fix type

* fix last review comment

* add changelog entry

* fix types in `ChatMessage`

* fix CH entry
  • Loading branch information
layershifter authored Jul 15, 2019
1 parent 308fa1d commit 2a33a21
Show file tree
Hide file tree
Showing 73 changed files with 363 additions and 296 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `trapFocus` and `autoFocus` props to `Popup` and remove `popupFocusTrapBehavior` and `popupAutoFocusBehavior` @sophieH29 ([#1565](https://github.com/stardust-ui/react/pull/1565))
- `defaultBehavior` was removed @layershifter ([#1600](https://github.com/stardust-ui/react/pull/1600))
- `ReactElement`s are now handled in the same way as string in all shorthands @layershifter ([#1600](https://github.com/stardust-ui/react/pull/1600))
- `Props` param is required in `ShorthandValue` and `ShorthandCollection` @layershifter ([#1605](https://github.com/stardust-ui/react/pull/1605))

### Features
- Split action handlers with "OR" condition in accessibility behaviors @sophieH29 ([#1622](https://github.com/stardust-ui/react/pull/1622))
Expand Down
5 changes: 3 additions & 2 deletions docs/src/components/ColorSchemes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import {
ComponentSlotStylesInput,
ThemePrepared,
Grid,
ShorthandValue,
Header,
HeaderProps,
ShorthandCollection,
} from '@stardust-ui/react'

import ColorBox from './ColorBox'

type ColorVariantsProps = {
name?: string
themes?: ThemePrepared[]
headers?: ShorthandValue[]
headers?: ShorthandCollection<HeaderProps>
}

export const colorVariantsStyles: ComponentSlotStylesInput<ColorVariantsProps> = {
Expand Down
21 changes: 15 additions & 6 deletions docs/src/components/ComponentBestPractices.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import * as React from 'react'
import _ from 'lodash'
import { Box, Flex, Header, Icon, List, Segment, ShorthandValue } from '@stardust-ui/react'
import * as _ from 'lodash'
import {
Box,
Flex,
Header,
Icon,
List,
ListItemProps,
Segment,
ShorthandCollection,
} from '@stardust-ui/react'
import { Extendable } from 'src/types'

export type ComponentBestPracticesProps = Extendable<{
doList?: ShorthandValue<{}>[]
dontList?: ShorthandValue<{}>[]
doList?: ShorthandCollection<ListItemProps>
dontList?: ShorthandCollection<ListItemProps>
}>

const ComponentBestPractices: React.FC<ComponentBestPracticesProps> = ({ doList, dontList }) => {
const updatedDoList: ShorthandValue<{}>[] = []
const updatedDontList: ShorthandValue<{}>[] = []
const updatedDoList: ShorthandCollection<ListItemProps> = []
const updatedDontList: ShorthandCollection<ListItemProps> = []

if (_.size(doList) > 0) {
_.map(doList, element => {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Sidebar extends React.Component<any, any> {
}
}

getTreeItems(): ShorthandValue[] {
getTreeItems(): TreeProps['items'] {
return [
{
key: 'concepts',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Avatar, Chat } from '@stardust-ui/react'
import { Avatar, Chat, ChatItemProps, ShorthandCollection } from '@stardust-ui/react'
import * as React from 'react'

const actionMenu = {
Expand All @@ -9,7 +9,7 @@ const actionMenu = {
],
}

const items = [
const items: ShorthandCollection<ChatItemProps> = [
{
attached: 'top',
contentPosition: 'end',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Avatar, Chat } from '@stardust-ui/react'
import { Avatar, Chat, ChatItemProps, ReactionProps, ShorthandCollection } from '@stardust-ui/react'
import * as React from 'react'

const reactions = [
const reactions: ShorthandCollection<ReactionProps> = [
{ key: 'up', icon: 'thumbs up', content: '1K' },
{ key: 'down', icon: 'thumbs down', content: 5 },
]

const items = [
const items: ShorthandCollection<ChatItemProps> = [
{
attached: 'top',
contentPosition: 'end',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react'
import { Avatar, Chat } from '@stardust-ui/react'
import { Avatar, Chat, ChatItemProps, ReactionProps, ShorthandCollection } from '@stardust-ui/react'

const reactions = [
const reactions: ShorthandCollection<ReactionProps> = [
{ icon: 'thumbs up', content: '1K', key: 'likes', variables: { meReacting: true }, as: 'button' },
{ icon: 'thumbs down', content: 2, key: 'dislikes', as: 'button' },
]

const items = [
const items: ShorthandCollection<ChatItemProps> = [
{
attached: 'top',
contentPosition: 'end',
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/components/Chat/Rtl/ChatExample.rtl.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { Avatar, Chat } from '@stardust-ui/react'
import { Avatar, Chat, ChatItemProps, ShorthandCollection } from '@stardust-ui/react'

const items = [
const items: ShorthandCollection<ChatItemProps> = [
{
message: (
<Chat.Message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react'
import { Avatar, Chat, Divider } from '@stardust-ui/react'
import { Avatar, Chat, ChatItemProps, Divider, ShorthandCollection } from '@stardust-ui/react'

const janeAvatar = {
image: 'public/images/avatar/small/ade.jpg',
status: { color: 'green', icon: 'check' },
}

const items = [
const items: ShorthandCollection<ChatItemProps> = [
{
message: (
<Chat.Message content="Hello" author="John Doe" timestamp="Yesterday, 10:15 PM" mine />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { Avatar, Chat } from '@stardust-ui/react'
import { Avatar, Chat, ChatItemProps, ShorthandCollection } from '@stardust-ui/react'

const [janeAvatar, johnAvatar] = [
'public/images/avatar/small/ade.jpg',
Expand All @@ -9,7 +9,7 @@ const [janeAvatar, johnAvatar] = [
status: { color: 'green', icon: 'check' },
}))

const items = [
const items: ShorthandCollection<ChatItemProps> = [
{
contentPosition: 'start',
gutter: <Avatar {...johnAvatar} />,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react'
import { Avatar, Chat } from '@stardust-ui/react'
import { Avatar, Chat, ChatItemProps, ShorthandCollection } from '@stardust-ui/react'

const janeAvatar = {
image: 'public/images/avatar/small/ade.jpg',
status: { color: 'green', icon: 'check' },
}

const items = [
const items: ShorthandCollection<ChatItemProps> = [
{
message: (
<Chat.Message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import * as React from 'react'
import { Avatar, Chat, Provider } from '@stardust-ui/react'
import {
Avatar,
AvatarProps,
Chat,
Provider,
ReactionProps,
ShorthandCollection,
} from '@stardust-ui/react'

const reactions = [
const reactions: ShorthandCollection<ReactionProps> = [
{ key: 'up', icon: 'thumbs up', content: '1K' },
{ key: 'down', icon: 'thumbs down', content: 5 },
]

const janeAvatar = {
const janeAvatar: AvatarProps = {
image: 'public/images/avatar/small/ade.jpg',
status: { color: 'green', icon: 'check' },
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { Menu, menuAsToolbarBehavior } from '@stardust-ui/react'
import { Menu, menuAsToolbarBehavior, MenuItemProps, ShorthandCollection } from '@stardust-ui/react'

const items = [
const items: ShorthandCollection<MenuItemProps> = [
{
key: 'format',
icon: {
Expand Down Expand Up @@ -115,18 +115,14 @@ const items = [
},
]

class MenuExampleToolbarShorthand extends React.Component {
render() {
return (
<Menu
defaultActiveIndex={0}
items={items}
iconOnly
accessibility={menuAsToolbarBehavior}
aria-label="Compose Editor"
/>
)
}
}
const MenuExampleToolbarShorthand = () => (
<Menu
defaultActiveIndex={0}
items={items}
iconOnly
accessibility={menuAsToolbarBehavior}
aria-label="Compose Editor"
/>
)

export default MenuExampleToolbarShorthand
2 changes: 1 addition & 1 deletion docs/src/prototypes/MenuButton/MenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class MenuButton extends React.Component<MenuButtonProps, MenuButtonState> {
}

handleMenuItemOverrides = (menuItemAccessibilityAttributes: AccessibilityAttributes) =>
_.map(_.get(this.props.menu, 'items'), (item: ShorthandValue) =>
_.map(_.get(this.props.menu, 'items'), (item: ShorthandValue<MenuItemProps>) =>
typeof item === 'object'
? {
...item,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Chat, Provider, Avatar, ChatMessageProps } from '@stardust-ui/react'
import {
Chat,
Provider,
Avatar,
ChatMessageProps,
ShorthandCollection,
ReactionProps,
} from '@stardust-ui/react'
import * as React from 'react'
import Popover from './Popover'
import ReactionPopup from './ReactionPopup'
import { Ref } from '@stardust-ui/react-component-ref'

const reactions = [
const reactions: ShorthandCollection<ReactionProps> = [
{
icon: 'thumbs up',
content: '1K',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react'
import { Avatar, Chat } from '@stardust-ui/react'
import { Avatar, Chat, ChatItemProps, ShorthandCollection } from '@stardust-ui/react'

const janeAvatar = {
image: 'public/images/avatar/small/ade.jpg',
status: { color: 'green', icon: 'check' },
}

const items = [
const items: ShorthandCollection<ChatItemProps> = [
{
message: (
<Chat.Message
Expand Down
8 changes: 5 additions & 3 deletions docs/src/prototypes/chatPane/composeMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
Provider,
menuAsToolbarBehavior,
MenuItemProps,
ShorthandCollection,
IconXSpacing,
} from '@stardust-ui/react'

import { Props } from 'src/types'
Expand Down Expand Up @@ -72,8 +74,8 @@ const getInputWrapperStyles = ({ attached }: ComposeMessageProps): React.CSSProp
}
}

const getMenuItems = (): MenuItemProps[] => {
const items: MenuItemProps[] = [
const getMenuItems = (): ShorthandCollection<MenuItemProps> => {
const items: ShorthandCollection<MenuItemProps> = [
'compose',
'attach',
'smile',
Expand All @@ -86,7 +88,7 @@ const getMenuItems = (): MenuItemProps[] => {
key: `${index}-${name}`,
icon: {
name,
xSpacing: 'both',
xSpacing: 'both' as IconXSpacing,
variables: siteVars => ({ color: siteVars.colors.grey[500] }),
},
'aria-label': `${name} tool`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function generateChatMsgProps(message: MessageData, fromUser: UserData): ChatIte
}
}

function createMessageContent(message: MessageData): ShorthandValue {
function createMessageContent(message: MessageData): ShorthandValue<ChatMessageProps> {
const messageId = `content-${message.id}`
return {
id: message.withAttachment ? undefined : messageId,
Expand Down
Loading

0 comments on commit 2a33a21

Please sign in to comment.