-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9023b7f
commit 6edca39
Showing
11 changed files
with
153 additions
and
3 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
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,4 @@ | ||
The `Pill` component is a very simple variation of the `Chip` component. | ||
|
||
### Usages | ||
The `Pill` component must be used in a dropdownMenu to add information (eg: Add the code language in a language switcher) |
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 @@ | ||
// empty | ||
.moonstone-pill { | ||
padding: 0 var(--spacing-nano); | ||
|
||
border-radius: 2px; | ||
background-color: var(--color-gray_light40); | ||
|
||
&.moonstone-pill_reversed { | ||
color: var(--color-light); | ||
} | ||
} |
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,21 @@ | ||
import React from 'react'; | ||
import {render, screen} from '@testing-library/react'; | ||
import {Pill} from './index'; | ||
|
||
describe('Pill', () => { | ||
it('should display label', () => { | ||
render(<Pill label="Say my name"/>); | ||
expect(screen.getByText('Say my name')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should add additional class names', () => { | ||
const testClassName = 'hello'; | ||
render(<Pill data-testid="moonstone-listItemChip" className={testClassName} label="Say my name"/>); | ||
expect(screen.getByTestId('moonstone-listItemChip')).toHaveClass(testClassName); | ||
}); | ||
|
||
it('should add additional attribute', () => { | ||
render(<Pill data-testid="moonstone-listItemChip" label="Say my name"/>); | ||
expect(screen.getByTestId('moonstone-listItemChip')).toBeInTheDocument(); | ||
}); | ||
}); |
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,23 @@ | ||
import React from 'react'; | ||
import {Story} from '@storybook/react'; | ||
import markdownNotes from './Pill.md'; | ||
|
||
import {Pill} from './index'; | ||
import type {PillProps} from './Pill.types'; | ||
|
||
export default { | ||
title: 'Components/Pill', | ||
component: Pill, | ||
|
||
parameters: { | ||
layout: 'centered', | ||
notes: {markdown: markdownNotes} | ||
} | ||
}; | ||
|
||
export const Default: Story<PillProps> = args => ( | ||
<Pill {...args}/> | ||
); | ||
Default.args = { | ||
label: 'ListItem label' | ||
}; |
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'; | ||
import clsx from 'clsx'; | ||
|
||
import type {PillProps} from './Pill.types'; | ||
|
||
import {Typography} from '~/components/Typography'; | ||
import './Pill.scss'; | ||
|
||
export const Pill: React.FC<PillProps> = ({ | ||
label, | ||
className, | ||
isReversed, | ||
...props | ||
}) => { | ||
return ( | ||
<Typography | ||
component="span" | ||
variant="caption" | ||
weight="semiBold" | ||
className={clsx('moonstone-pill', {'moonstone-pill_reversed': isReversed}, className)} | ||
{...props} | ||
> | ||
{label} | ||
</Typography> | ||
); | ||
}; | ||
|
||
Pill.displayName = 'Pill'; |
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,16 @@ | ||
export type PillProps = { | ||
/** | ||
* ListItem label | ||
*/ | ||
label: string; | ||
|
||
/** | ||
* Reversed style for dark background with light text | ||
*/ | ||
isReversed?: boolean; | ||
|
||
/** | ||
* Additional classname | ||
*/ | ||
className?: string; | ||
} |
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 @@ | ||
export * from './Pill'; |
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