Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tag component housekeeping #16355

Merged
merged 2 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ui/components/component-library/tag/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ The `Tag` accepts all props below as well as all [Box](/docs/ui-components-ui-bo
### Label

The text content of the `Tag` component

<Canvas>
<Story id="ui-components-component-library-tag-tag-stories-js--label" />
</Canvas>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tag should render the label inside the tag and match snapshot 1`] = `
<div>
<div
class="box mm-tag box--padding-right-1 box--padding-left-1 box--display-inline-block box--flex-direction-row box--justify-content-center box--align-items-center box--background-color-background-default box--rounded-pill box--border-color-border-default box--border-width-1 box--border-style-solid"
data-testid="tag"
>
<p
class="box text text--body-sm text--color-text-default box--flex-direction-row"
>
Imported
</p>
</div>
</div>
`;
6 changes: 5 additions & 1 deletion ui/components/component-library/tag/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
export const Tag = ({ label, className, labelProps, ...props }) => {
return (
<Box
className={classnames('tag', className)}
className={classnames('mm-tag', className)}
backgroundColor={COLORS.BACKGROUND_DEFAULT}
borderColor={COLORS.BORDER_DEFAULT}
borderWidth={1}
Expand Down Expand Up @@ -47,4 +47,8 @@ Tag.propTypes = {
* Additional classNames to be added to the Tag component
*/
className: PropTypes.string,
/**
* Tag also accepts all props from Box
*/
...Box.propTypes,
};
2 changes: 1 addition & 1 deletion ui/components/component-library/tag/tag.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.tag {
.mm-tag {
height: auto;
width: max-content;
padding-top: 1px;
Expand Down
6 changes: 6 additions & 0 deletions ui/components/component-library/tag/tag.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ export default {
export const DefaultStory = (args) => <Tag {...args} />;

DefaultStory.storyName = 'Default';

export const Label = (args) => <Tag {...args}>Anchor Element</Tag>;

Label.args = {
label: 'Label Story',
};
7 changes: 5 additions & 2 deletions ui/components/component-library/tag/tag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import React from 'react';
import { Tag } from './tag';

describe('Tag', () => {
it('should render the label inside the tag', () => {
const { getByTestId } = render(<Tag data-testid="tag" label="Imported" />);
it('should render the label inside the tag and match snapshot', () => {
const { getByTestId, container } = render(
<Tag data-testid="tag" label="Imported" />,
);
expect(getByTestId('tag')).toBeDefined();
expect(getByTestId('tag')).toHaveTextContent('Imported');
expect(container).toMatchSnapshot();
});
});