Skip to content

Commit f278122

Browse files
committed
Add numeric text display
1 parent e16b3b9 commit f278122

File tree

7 files changed

+61
-4
lines changed

7 files changed

+61
-4
lines changed

src/components/CostDisplay/CostDisplay.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import styles from './CostDisplay.module.css';
4+
import NumericDisplay from '../NumericDisplay/NumericDisplay';
45

56
const CostDisplay = (
67
{ cost }, //cost display content
78
) => (
89
<div className={styles.CostDisplay} data-testid="CostDisplay">
910
{/*display cost display with specified styles*/}
10-
Cost: <span id="cost-value">{cost}</span>
11+
Cost:{" "}
12+
<span id="cost-value">
13+
<NumericDisplay value={cost} />
14+
</span>
1115
{/*bold the cost numeric value*/}
1216
</div>
1317
);
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
.CostDisplay {
22
text-align: center; /*center cost display text component*/
33
}
4-
#cost-value {
5-
font-weight: bold; /*bold numeric cost value*/
6-
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import styles from './NumericDisplay.module.css';
4+
5+
const NumericDisplay = ({ value }) => (
6+
<div className={styles.NumericDisplay} data-testid="NumericDisplay">
7+
{value}
8+
</div>
9+
);
10+
11+
NumericDisplay.propTypes = {};
12+
13+
NumericDisplay.defaultProps = {};
14+
15+
export default NumericDisplay;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React, { lazy, Suspense } from 'react';
2+
3+
const LazyNumericDisplay = lazy(() => import('./NumericDisplay'));
4+
5+
const NumericDisplay = props => (
6+
<Suspense fallback={null}>
7+
<LazyNumericDisplay {...props} />
8+
</Suspense>
9+
);
10+
11+
export default NumericDisplay;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.NumericDisplay {
2+
font-weight: bold; /*bold numeric cost value*/
3+
font-variant-numeric: tabular-nums; /*make all numeric values the same character width*/
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable */
2+
import NumericDisplay from './NumericDisplay';
3+
4+
export default {
5+
title: "NumericDisplay",
6+
};
7+
8+
export const Default = () => <NumericDisplay />;
9+
10+
Default.story = {
11+
name: 'default',
12+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import NumericDisplay from './NumericDisplay';
5+
6+
describe('<NumericDisplay />', () => {
7+
test('it should mount', () => {
8+
render(<NumericDisplay />);
9+
10+
const NumericDisplay = screen.getByTestId('NumericDisplay');
11+
12+
expect(NumericDisplay).toBeInTheDocument();
13+
});
14+
});

0 commit comments

Comments
 (0)