-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove toolbox.duration and symphony env from duration component
- Loading branch information
Showing
7 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { Duration } from './duration'; | ||
|
||
export const BasicDuration = () => { | ||
return <Duration time={2000} />; | ||
}; | ||
|
||
export const WithHours = () => { | ||
const hours = 240 * 60 * 60 * 1000; | ||
return <Duration time={hours} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
description: A component for rendering time durations. | ||
labels: ['time', 'duration', 'react', 'formatting'] | ||
--- | ||
|
||
import { Duration as TimeDuration } from '@teambit/toolbox.date.duration'; | ||
import { Duration } from './duration'; | ||
|
||
A component for rendering time durations. | ||
|
||
## Render duration from milliseconds. | ||
```tsx live=true | ||
() => { | ||
return <Duration time={3600} />; | ||
} | ||
``` | ||
|
||
## Render duration from minutes using the `Duration` module. | ||
```tsx live=true | ||
() => { | ||
const durationMs = 240 * 60 * 1000; | ||
return <Duration time={durationMs} />; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { BasicDuration, WithHours } from './duration.compositions'; | ||
|
||
describe('Duration', () => { | ||
it('should render the duration as text', async () => { | ||
const { findByText } = render(<BasicDuration />); | ||
const element = await findByText('00:00:02'); | ||
expect(element).toBeTruthy(); | ||
}); | ||
|
||
it('should render the duration with hours', async () => { | ||
const { findByText } = render(<WithHours />); | ||
const element = await findByText('240:00:00'); | ||
expect(element).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
// @ts-ignore | ||
import TimeDuration from 'duration'; | ||
|
||
export type DurationProps = { | ||
/** | ||
* time of duration in milliseconds. | ||
* can be either a number representing milliseconds or | ||
* a `Duration` instance of the `teambit.toolbox/date/duration` component. | ||
*/ | ||
time: number; | ||
}; | ||
|
||
export function Duration({ time }: DurationProps) { | ||
// @ts-ignore | ||
const duration = new TimeDuration(new Date(0), new Date(time)); | ||
|
||
const totalHours = pad(duration.hours); | ||
const minutes = pad(duration.minute); | ||
const seconds = pad(duration.second); | ||
const timeString = `${totalHours}:${minutes}:${seconds}`; | ||
|
||
return <span>{timeString}</span>; | ||
} | ||
|
||
function pad(num: number, count = 2) { | ||
return num.toString().padStart(count, '0'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { Duration } from './duration'; | ||
export type { DurationProps } from './duration'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters