Skip to content

Commit

Permalink
Merge pull request #270 from lifeomic/feature/negative-positive-text
Browse files Browse the repository at this point in the history
feat: Add positive and negative `color` values to `<Text`
  • Loading branch information
dexterca authored May 20, 2022
2 parents 50103e5 + 8cead69 commit 742cd2f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/components/Text/Text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ test('it applies the inverse class when `color="inverse"`', async () => {
expect(root).toHaveClass('ChromaText-inverseColor');
});

test('it applies the negative class when `color="negative"`', async () => {
const { findByTestId } = renderWithTheme(
<Text data-testid={testId} color="negative">
test
</Text>
);
const root = await findByTestId(testId);
expect(root).toHaveClass('ChromaText-negativeColor');
});

test('it applies the positive class when `color="positive"`', async () => {
const { findByTestId } = renderWithTheme(
<Text data-testid={testId} color="positive">
test
</Text>
);
const root = await findByTestId(testId);
expect(root).toHaveClass('ChromaText-positiveColor');
});

test('it applies the marginBottom class when "marginBottom"', async () => {
const { findByTestId } = renderWithTheme(
<Text data-testid={testId} marginBottom>
Expand Down
10 changes: 9 additions & 1 deletion src/components/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export const useStyles = makeStyles(
inverseColor: {
color: theme.palette.common.white,
},
negativeColor: {
color: theme.palette.negative.main,
},
positiveColor: {
color: theme.palette.positive.main,
},
headline: {
fontSize: theme.pxToRem(20),
letterSpacing: theme.pxToRem(0.5),
Expand Down Expand Up @@ -99,7 +105,7 @@ export interface TextOwnProps extends React.HTMLAttributes<HTMLElement> {
weight?: 'light' | 'regular' | 'bold';
marginBottom?: boolean;
useH1?: boolean;
color?: 'default' | 'inverse';
color?: 'default' | 'inverse' | 'negative' | 'positive';
}

export type TextClasses = GetClasses<typeof useStyles>;
Expand Down Expand Up @@ -150,6 +156,8 @@ export const Text = React.forwardRef<HTMLParagraphElement, TextProps>(
},
{
[classes.inverseColor]: color === 'inverse',
[classes.negativeColor]: color === 'negative',
[classes.positiveColor]: color === 'positive',
},
marginBottom && classes.marginBottom,
{
Expand Down
37 changes: 37 additions & 0 deletions stories/components/Text/Text.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,31 @@ import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { Text } from '../../../src/components/Text';
import { Container } from '../../storyComponents/Container';
import { spacing } from '../../storyStyles';
import md from './default.md';

interface WrappedContainerProps {
additionalStyles?: React.CSSProperties;
children: React.ReactNode;
}

const WrappedContainer: React.FC<WrappedContainerProps> = ({
additionalStyles,
children,
}) => (
<Container
containerStyles={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
...additionalStyles,
}}
>
{children}
</Container>
);

const TextStory: React.FunctionComponent = () => {
return (
<Container
Expand Down Expand Up @@ -54,6 +77,20 @@ const TextStory: React.FunctionComponent = () => {
<Text align="left">align left</Text>
<Text align="right">align right</Text>
<Text align="justify">align justify</Text>
<WrappedContainer additionalStyles={{ gap: spacing[4] }}>
<Text
color="inverse"
style={{
background: '#384049',
paddingLeft: spacing[2],
paddingRight: spacing[2],
}}
>
Inverse
</Text>
<Text color="negative">Negative</Text>
<Text color="positive">Positive</Text>
</WrappedContainer>
</Container>
);
};
Expand Down
2 changes: 2 additions & 0 deletions stories/components/Text/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The sizing options are listed above in the story.

```jsx
<Text color="inverse">body text</Text>
<Text color="negative">body text</Text>
<Text color="positive">body text</Text>
```

### Align
Expand Down

0 comments on commit 742cd2f

Please sign in to comment.