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

feat(status): Add status behavior #880

Merged
merged 8 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion docs/src/components/DocsBehaviorRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DocsBehaviorRoot extends React.Component<any, any> {
<Header
as="h1"
content={pageTitle}
subheader={`Keyboard and Screenreader options for ${match.params.name}s.`}
subheader={`Keyboard and Screenreader options for ${match.params.name} component.`}
/>
</Grid.Column>
</Grid.Row>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { Status } from '@stardust-ui/react'

const StatusExampleShorthand = () => <Status />
const StatusExampleShorthand = () => <Status alt="default state" />

export default StatusExampleShorthand
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Status } from '@stardust-ui/react'

const StatusTypeExampleShorthand = () => (
<div>
<Status state="success" /> <code>state="success"</code>
<Status state="success" alt="success" /> <code>state="success"</code>
<br />
<Status state="info" /> <code>state="info"</code>
<Status state="info" alt="info" /> <code>state="info"</code>
<br />
<Status state="warning" /> <code>state="warning"</code>
<Status state="warning" alt="warning" /> <code>state="warning"</code>
<br />
<Status state="error" /> <code>state="error"</code>
<Status state="error" alt="error" /> <code>state="error"</code>
<br />
<Status state="unknown" /> <code>state="unknown"</code>
<Status state="unknown" alt="unknown" /> <code>state="unknown"</code>
</div>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { Status } from '@stardust-ui/react'

const StatusColorExampleShorthand = () => (
<div>
<Status color="red" />
<Status color="red" alt="red" />
&emsp;
<Status color="orange" />
<Status color="orange" alt="orange" />
&emsp;
<Status color="yellow" />
<Status color="yellow" alt="yellow" />
&emsp;
<Status color="green" />
<Status color="green" alt="green" />
&emsp;
<Status color="blue" />
<Status color="blue" alt="blue" />
&emsp;
<Status color="violet" />
<Status color="violet" alt="violet" />
</div>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Status } from '@stardust-ui/react'

const StatusCustomExampleShorthand = () => (
<div>
<Status color="orange" icon="clock" title="Be right back" />
<Status color="orange" icon="clock" title="Be right back" alt="be right back" />
&emsp;
<Status color="blue" icon="home" title="Working from home" />
<Status color="blue" icon="home" title="Working from home" alt="working from home" />
&emsp;
<Status color="red" icon="minus" title="Do not disturb" />
<Status color="red" icon="minus" title="Do not disturb" alt="do not disturb" />
</div>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Status } from '@stardust-ui/react'

const StatusIconExampleShorthand = () => (
<div>
<Status state="success" icon="check" />
<Status state="success" icon="check" alt="available" />
&emsp;
<Status state="error" icon="minus" />
<Status state="error" icon="minus" alt="busy" />
</div>
)

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Ref from '../Ref/Ref'
export interface DialogProps extends UIComponentProps, ContentComponentProps, ColorComponentProps {
/**
* Accessibility behavior if overridden by the user.
* @default defaultBehavior
* @default dialogBehavior
*/
accessibility?: Accessibility

Expand Down
16 changes: 14 additions & 2 deletions packages/react/src/components/Status/Status.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as PropTypes from 'prop-types'
import * as React from 'react'
import Icon from '../Icon/Icon'
import { statusBehavior } from '../../lib/accessibility'
import { Accessibility } from '../../lib/accessibility/types'

import {
customPropTypes,
Expand All @@ -13,6 +15,12 @@ import {
import { ReactProps, ShorthandValue } from '../../types'

export interface StatusProps extends UIComponentProps {
/**
* Accessibility behavior if overridden by the user.
* @default statusBehavior
*/
accessibility?: Accessibility

/** A custom color. */
color?: string

Expand All @@ -28,6 +36,8 @@ export interface StatusProps extends UIComponentProps {

/**
* A status graphically represents someone's or something's state.
* @accessibility
* Don't forget to put appropriate 'alt' attribute describing status. This is necessary for correct screen reader behavior.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If alt prop is so necessary, should be a component prop?

*/
class Status extends UIComponent<ReactProps<StatusProps>, any> {
static create: Function
Expand All @@ -41,22 +51,24 @@ class Status extends UIComponent<ReactProps<StatusProps>, any> {
children: false,
content: false,
}),
accessibility: PropTypes.func,
color: PropTypes.string,
icon: customPropTypes.itemShorthand,
size: customPropTypes.size,
state: PropTypes.oneOf(['success', 'info', 'warning', 'error', 'unknown']),
}

static defaultProps = {
accessibility: statusBehavior,
as: 'span',
size: 'medium',
state: 'unknown',
}

renderComponent({ ElementType, classes, unhandledProps, variables, styles }) {
renderComponent({ accessibility, ElementType, classes, unhandledProps, variables, styles }) {
const { icon } = this.props as StatusProps
return (
<ElementType {...unhandledProps} className={classes.root}>
<ElementType {...unhandledProps} className={classes.root} {...accessibility.attributes.root}>
{Icon.create(icon, {
defaultProps: {
size: 'smallest',
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export {
default as popupFocusTrapBehavior,
} from './lib/accessibility/Behaviors/Popup/popupFocusTrapBehavior'
export { default as dialogBehavior } from './lib/accessibility/Behaviors/Dialog/dialogBehavior'
export { default as statusBehavior } from './lib/accessibility/Behaviors/Status/statusBehavior'

//
// Utilities
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Accessibility } from '../../types'

/**
* @description
* The 'img' role is used to identify an element as image. Alt attribute have to be provided on status component.
*
* @specification
* Adds role='img'.
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be there an empty line? 🤔

const statusBehavior: Accessibility = (props: any) => ({
attributes: {
root: {
role: 'img',
},
},
})

export default statusBehavior
1 change: 1 addition & 0 deletions packages/react/src/lib/accessibility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export { default as chatMessageBehavior } from './Behaviors/Chat/chatMessageBeha
export { default as gridBehavior } from './Behaviors/Grid/gridBehavior'
export { default as treeTitleBehavior } from './Behaviors/Tree/treeTitleBehavior'
export { default as dialogBehavior } from './Behaviors/Dialog/dialogBehavior'
export { default as statusBehavior } from './Behaviors/Status/statusBehavior'
2 changes: 2 additions & 0 deletions packages/react/test/specs/behaviors/behavior-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
toolbarButtonBehavior,
treeTitleBehavior,
gridBehavior,
statusBehavior,
} from 'src/lib/accessibility'
import { TestHelper } from './testHelper'
import definitions from './testDefinitions'
Expand Down Expand Up @@ -66,5 +67,6 @@ testHelper.addBehavior('toolbarButtonBehavior', toolbarButtonBehavior)
testHelper.addBehavior('treeTitleBehavior', treeTitleBehavior)
testHelper.addBehavior('gridBehavior', gridBehavior)
testHelper.addBehavior('dialogBehavior', dialogBehavior)
testHelper.addBehavior('statusBehavior', statusBehavior)

testHelper.run(behaviorMenuItems)