Skip to content

Commit

Permalink
feat(Timeline): date supports a list of dates (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
langz authored Jun 16, 2022
1 parent 91e69a8 commit a5c1dcd
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ showTabs: true

| Properties | Description |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | _(required)_ Name/title of the Timeline item. |
| `state` | _(required)_ The component state. Options: `completed` \| `current` \| `upcoming`. |
| `date` | _(optional)_ Date of the Timeline item, displayed below the `name`. |
| `name` | _(required)_ Name/title of the Timeline item. |
| `state` | _(required)_ The component state. Options: `completed` \| `current` \| `upcoming`. |
| `date` | _(optional)_ Date of the Timeline item, displayed below the `name`. Also supports passing an array of dates. |
| `infoMessage` | _(optional)_ Info message, displayed in a [FormStatus of state info](/uilib/components/form-status#formstatus-displaying-info-status), below the `date` if it exists. |
| `icon` | _(optional)_ Override icon displaying on the left side (Not recommended). Default: `check` for state `completed`, `pin` for state `current`, and `calendar` for state `upcoming` . |
| `iconAlt` | _(optional)_ Alt label describing the icon provided. |
Expand Down
33 changes: 24 additions & 9 deletions packages/dnb-eufemia/src/components/timeline/TimelineItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface TimelineItemProps {
/**
* Text displaying the date of the timeline item.
*/
date?: React.ReactNode
date?: React.ReactNode | React.ReactNode[]

/**
* Text displaying info message of the timeline item.
Expand Down Expand Up @@ -159,17 +159,32 @@ const TimelineItem = (localProps: TimelineItemProps) => {
)
}

const getDate = () => {
const TimelineItemDate = ({ date }: { date: React.ReactNode }) => (
<div
className="dnb-timeline__item__content__date"
data-testid="timeline-item-content-date"
>
{date}
</div>
)

if (!date) {
return null
}

if (Array.isArray(date)) {
return date.map((date, i) => (
<TimelineItemDate key={i} date={date} />
))
}
return <TimelineItemDate date={date} />
}

const TimelineItemContent = () => {
return (
<div className="dnb-timeline__item__content">
{date && (
<span
className="dnb-timeline__item__content__date"
data-testid="timeline-item-content-date"
>
{date}
</span>
)}
{getDate()}
{infoMessage && (
<FormStatus
text={infoMessage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,26 @@ describe('Timeline', () => {
).toBe(date)
})

it('renders dates', () => {
const dates = ['10. september 2021', '11. september 2021']
render(
<TimelineItem date={dates} name="Complete" state="completed" />
)

expect(
screen.queryAllByTestId('timeline-item-content-date')
).toHaveLength(2)

expect(
screen.queryAllByTestId('timeline-item-content-date')[0]
.textContent
).toBe(dates[0])
expect(
screen.queryAllByTestId('timeline-item-content-date')[1]
.textContent
).toBe(dates[1])
})

it('renders info message', () => {
const infoMessage = 'Info text'
render(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a5c1dcd

Please sign in to comment.