Skip to content

Commit

Permalink
feat: use state instead of status on #form-status (but status w…
Browse files Browse the repository at this point in the history
…ill still work in future)
  • Loading branch information
tujoworker committed Jul 24, 2019
1 parent 524ea39 commit e0c9da5
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Example extends PureComponent {
<FormStatus
title="Hover title"
text="Long info nisl tempus hendrerit tortor dapibus nascetur taciti porta risus cursus fusce platea enim curabitur proin nibh ut luctus magnis metus"
status="info"
state="info"
/>
`}
</ComponentBox>
Expand Down Expand Up @@ -76,7 +76,7 @@ const myHTML = \`
\`
const CustomStatus = () => <span dangerouslySetInnerHTML={{ __html: myHTML }} />
render(
<FormStatus status="info">
<FormStatus state="info">
<CustomStatus />
</FormStatus>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ draft: true
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `text|children` | _(optional)_ the `text` appears as the status message. Beside plain text, You can send in a React component as well. |
| `title` | _(optional)_ the `title` attribute in the status. |
| `status` | _(optional)_ defines the visual appearance of the status. There are two main statuses `error` and `info`. The default status is `error`. |
| `state` | _(optional)_ defines the visual appearance of the status. There are two main statuses `error` and `info`. The default status is `error`. |
| `icon` | _(optional)_ the `icon` show before the status text. Defaults to `exclamation`. |
| `icon_size` | _(optional)_ the icon size of the icon shows. Defaults to `medium`. |
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ exports[`DatePicker component have to match snapshot 1`] = `
icon="exclamation"
icon_size="medium"
render_content={null}
state="error"
status="error"
text="status"
text_id="date-picker-id-status"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ exports[`Dropdown component have to match snapshot 1`] = `
icon="exclamation"
icon_size="medium"
render_content={null}
state="error"
status="error"
text="status"
text_id="dropdown-id-status"
Expand Down
25 changes: 14 additions & 11 deletions packages/dnb-ui-lib/src/components/form-status/FormStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const propTypes = {
PropTypes.node
]),
icon_size: PropTypes.string,
status: PropTypes.oneOf(['error', 'info']),
state: PropTypes.oneOf(['error', 'info']),
status: PropTypes.oneOf(['error', 'info']), // Deprecated
hidden: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
text_id: PropTypes.string,
class: PropTypes.string,
Expand All @@ -56,7 +57,8 @@ export const defaultProps = {
text: null,
icon: 'exclamation',
icon_size: 'medium',
status: 'error',
state: 'error',
status: null, // Deprecated
hidden: false,
text_id: null,
class: null,
Expand Down Expand Up @@ -87,11 +89,11 @@ export default class FormStatus extends PureComponent {
return processChildren(props)
}

static getIcon({ status, icon, icon_size }) {
static getIcon({ state, icon, icon_size }) {
if (typeof icon === 'string') {
let iconToLoad = icon

switch (status) {
switch (state) {
case 'info':
case 'information':
iconToLoad = 'information'
Expand All @@ -107,13 +109,13 @@ export default class FormStatus extends PureComponent {
return icon
}

correctStatus(status) {
switch (status) {
correctStatus(state) {
switch (state) {
case 'information':
status = 'info'
state = 'info'
break
}
return status
return state
}

render() {
Expand All @@ -126,6 +128,7 @@ export default class FormStatus extends PureComponent {
const {
title,
status: rawStatus,
state: rawState,
hidden,
className,
animation,
Expand All @@ -138,9 +141,9 @@ export default class FormStatus extends PureComponent {
...attributes
} = props

const status = this.correctStatus(rawStatus)
const state = this.correctStatus(rawStatus || rawState)
const iconToRender = FormStatus.getIcon({
status,
state,
icon,
icon_size
})
Expand All @@ -152,7 +155,7 @@ export default class FormStatus extends PureComponent {
hidden,
className: classnames(
'dnb-form-status',
`dnb-form-status--${status}`,
`dnb-form-status--${state}`,
animation ? `dnb-form-status--${animation}` : null,
hasStringContent ? 'dnb-form-status--has-content' : null,
createSpacingClasses(props),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import dnb_form_status_theme_ui from '../style/themes/dnb-form-status-theme-ui.s
const props = fakeProps(require.resolve('../FormStatus'), {
optional: true
})
props.status = 'error'
props.state = 'error'
props.status = null
props.hidden = false
props.icon = 'exclamation'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ exports[`FormStatus component have to match snapshot 1`] = `
icon="exclamation"
icon_size="icon_size"
render_content={[Function]}
status="error"
state="error"
status={null}
text="text"
text_id="text_id"
title="title"
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-ui-lib/stories/components/FormStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default [
<FormStatus>Status</FormStatus>
</Box>
<Box>
<FormStatus status="info">
<FormStatus state="info">
Long info text Ipsum habitant enim ullamcorper elit sit elementum
platea rutrum eu condimentum erat risus lacinia viverra magnis
lobortis nibh mollis suspendisse
Expand Down

0 comments on commit e0c9da5

Please sign in to comment.