Skip to content

Commit

Permalink
Merge pull request #279 from lifeomic/pill-color
Browse files Browse the repository at this point in the history
feat: Add negative and positive colors to `<Pill`
  • Loading branch information
dexterca authored Jun 13, 2022
2 parents a4534bc + 9710edc commit 4bd7adb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/components/Pill/Pill.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,30 @@ test('it renders a Pill with a label', async () => {
expect(root).toBeInTheDocument();
});

test('it renders a Pill with the provided "color"', async () => {
test('it renders a Pill with primary "color"', async () => {
const { findByTestId } = renderWithTheme(
<Pill data-testid={testId} color="primary" />
);
const root = await findByTestId(testId);
expect(root).toHaveClass('ChromaPill-primaryColor');
});

test('it renders a Pill with negative "color"', async () => {
const { findByTestId } = renderWithTheme(
<Pill data-testid={testId} color="negative" />
);
const root = await findByTestId(testId);
expect(root).toHaveClass('ChromaPill-negative');
});

test('it renders a Pill with positive "color"', async () => {
const { findByTestId } = renderWithTheme(
<Pill data-testid={testId} color="positive" />
);
const root = await findByTestId(testId);
expect(root).toHaveClass('ChromaPill-positive');
});

test('it renders a Pill with the highlight variant', async () => {
const { findByTestId } = renderWithTheme(
<Pill data-testid={testId} variant="highlight" />
Expand Down
10 changes: 9 additions & 1 deletion src/components/Pill/Pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const useStyles = makeStyles(
primaryColor: {
background: theme.palette.primary.main,
},
negative: {
background: theme.palette.negative.main,
},
positive: {
background: theme.palette.positive.main,
},
highlight: {
background: `linear-gradient(135deg, ${theme.palette.primary.light} 0%, ${theme.palette.primary.main} 40%, rgb(166, 66, 254) 92%)`,
boxShadow: theme.boxShadows.table,
Expand Down Expand Up @@ -51,7 +57,7 @@ export interface PillOwnProps
'onAnimationStart' | 'onDrag' | 'onDragEnd' | 'onDragStart' | 'style'
>,
MotionProps {
color?: 'primary' | 'default';
color?: 'default' | 'primary' | 'negative' | 'positive';
children?: React.ReactNode;
label?: string;
variant?: 'default' | 'highlight';
Expand Down Expand Up @@ -79,6 +85,8 @@ export const Pill = React.forwardRef<HTMLSpanElement, PillProps>(
},
{
[classes.primaryColor]: color === 'primary',
[classes.negative]: color === 'negative',
[classes.positive]: color === 'positive',
},
className
)}
Expand Down
32 changes: 32 additions & 0 deletions stories/components/Pill/Pill.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const AllPillsStory: React.FC = () => (
<Pill label="123 Results" />
<Pill label="1 of 20" />
<Pill label="3" color="primary" />
<Pill label="4" color="negative" />
<Pill label="5" color="positive" />
<Pill label="Beta" variant="highlight" />
</Container>
</>
Expand Down Expand Up @@ -51,10 +53,40 @@ const HighlightPillStory: React.FC = () => (
</>
);

const NegativePillStory: React.FC = () => (
<>
<Container
containerStyles={{ display: 'flex', justifyContent: 'space-around' }}
>
<Pill label="123 Results" color="negative" />
<Pill label="1 of 20" color="negative" />
<Pill label="3" color="negative" />
</Container>
</>
);

const PositivePillStory: React.FC = () => (
<>
<Container
containerStyles={{ display: 'flex', justifyContent: 'space-around' }}
>
<Pill label="123 Results" color="positive" />
<Pill label="1 of 20" color="positive" />
<Pill label="3" color="positive" />
</Container>
</>
);

storiesOf('Components/Pill', module)
.add('Default', () => <AllPillsStory />, {
readme: { content: md },
})
.add('Highlight', () => <HighlightPillStory />, {
readme: { content: md },
})
.add('Negative', () => <NegativePillStory />, {
readme: { content: md },
})
.add('Positive', () => <PositivePillStory />, {
readme: { content: md },
});
2 changes: 2 additions & 0 deletions stories/components/Pill/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Pill allows for a `color` prop to be defined.

```jsx
<Pill label="My Pill" color="primary" />
<Pill label="My Pill" color="negative" />
<Pill label="My Pill" color="positive" />
```

### Class Name
Expand Down

0 comments on commit 4bd7adb

Please sign in to comment.