Skip to content

Commit

Permalink
fix(Timeline): Forward className prop
Browse files Browse the repository at this point in the history
The `Timeline` had a `className` prop that wasn't used. This forwards it to the root child component so library users can override styles more easily.

The prop was also added to the docs.
  • Loading branch information
jpveooys committed Oct 9, 2020
1 parent 6aee881 commit ea752b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/docs-site/src/library/pages/timeline/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,25 @@ Here you will find comprehensive API documentation for the Timeline Components.
</div>
</div>

<div className="rn-fw-api">
<div className="rn-fw-api-header">
<h1 className="rn-fw-api-title">className</h1>
<Badge color="supa" colorVariant="faded" size="small">String</Badge>
</div>
<div className="rn-fw-api-body">
<div className="rn-fw-api-row">
<div className="rn-fw-api-item">Default Value</div>
<div className="rn-fw-api-value">
<code>-</code>
</div>
</div>
<div className="rn-fw-api-row">
<div className="rn-fw-api-item">Description</div>
<p className="rn-fw-api-value">Custom CSS class to add to the component.</p>
</div>
</div>
</div>

</div>
<div className="rn-fw-code rn-fw-md">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import classNames from 'classnames'
import styled from 'styled-components'
import { selectors } from '@royalnavy/design-tokens'

Expand Down Expand Up @@ -132,6 +133,7 @@ const StyledHeader = styled.div``

export const Timeline: React.FC<TimelineProps> = ({
children,
className,
dayWidth,
hasSide,
startDate,
Expand Down Expand Up @@ -182,7 +184,11 @@ export const Timeline: React.FC<TimelineProps> = ({
startDate={startDate}
today={today}
>
<StyledTimeline className="timeline" data-testid="timeline" role="grid">
<StyledTimeline
className={classNames('timeline', className)}
data-testid="timeline"
role="grid"
>
<StyledInner
className="timeline__inner"
hasSide={hasSide || hasTimelineSide}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ describe('Timeline', () => {
jest.clearAllMocks()
})

describe('when a custom className is provided', () => {
beforeEach(() => {
wrapper = render(
<Timeline
startDate={new Date(2020, 3, 1)}
today={new Date(2020, 3, 15)}
className="test-class-name"
>
<TimelineMonths />
<TimelineRows>{}</TimelineRows>
</Timeline>
)
})

it('adds the custom CSS class to the component', () => {
expect(wrapper.getByTestId('timeline')).toHaveClass('test-class-name')
})
})

describe('when no data is provided', () => {
beforeEach(() => {
wrapper = render(
Expand Down

0 comments on commit ea752b2

Please sign in to comment.