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

feat(chip): add chip component #1981

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Each layer does its bit to enforce and enhance accessibility. We consider this l
- [`ebay-carousel`](https://github.com/eBay/ebayui-core/tree/master/src/components/ebay-carousel)
- [`ebay-character-count`](https://github.com/eBay/ebayui-core/tree/master/src/components/ebay-character-count)
- [`ebay-checkbox`](https://github.com/eBay/ebayui-core/tree/master/src/components/ebay-checkbox)
- [`ebay-chip`](https://github.com/eBay/ebayui-core/tree/master/src/components/ebay-chip)
- [`ebay-combobox`](https://github.com/eBay/ebayui-core/tree/master/src/components/ebay-combobox)
- [`ebay-cta-button`](https://github.com/eBay/ebayui-core/tree/master/src/components/ebay-cta-button)
- [`ebay-date-textbox`](https://github.com/eBay/ebayui-core/tree/master/src/components/ebay-date-textbox)
Expand Down
16 changes: 16 additions & 0 deletions src/components/ebay-chip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h1 style='display: flex; justify-content: space-between; align-items: center;'>
<span>
ebay-chip
</span>
<span style='font-weight: normal; font-size: medium; margin-bottom: -15px;'>
DS v1.0.0
</span>
</h1>

A discrete highlighted value.

## Examples and Documentation

- [Storybook](https://ebay.github.io/ebayui-core/?path=/story/building-blocks-ebay-chip)
- [Storybook Docs](https://ebay.github.io/ebayui-core/?path=/docs/building-blocks-ebay-chip)
- [Code Examples](https://github.com/eBay/ebayui-core/tree/master/src/components/ebay-chip/examples)
9 changes: 9 additions & 0 deletions src/components/ebay-chip/browser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"requireRemap": [
{
"from": "./style.js",
"to": "../../common/empty.js",
"if-flag": "ebayui-no-skin"
}
]
}
67 changes: 67 additions & 0 deletions src/components/ebay-chip/chip.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { tagToString } from "../../../.storybook/storybook-code-source";
import { addRenderBodies } from "../../../.storybook/utils";
import Readme from "./README.md";
import Component from "./index.marko";

const Template = (args) => ({
input: addRenderBodies(args),
});

export default {
title: "building blocks/ebay-chip",
component: Component,
parameters: {
docs: {
description: {
component: Readme,
},
},
},

argTypes: {
renderBody: {
control: { type: "text" },
description: "Text to be displayed in the chip",
},
deleteButtonLabel: {
control: { type: "text" },
description:
"A11y text for the delete button, also determines if delete button is shown",
},
onDelete: {
action: "on-delete",
description: "Triggered when delete button is clicked",
table: {
category: "Events",
defaultValue: {
summary: "{ el, checked, originalEvent }",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To what is checked referring? Should it be deleted instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this was actually completely wrong, must've been a copy-paste error. I fixed it.

},
},
},
},
};

export const Standard = Template.bind({});
agliga marked this conversation as resolved.
Show resolved Hide resolved
Standard.args = {
renderBody: "chip text",
};
Standard.parameters = {
docs: {
source: {
code: tagToString("ebay-chip", Standard.args),
},
},
};

export const WithDelete = Template.bind({});
WithDelete.args = {
renderBody: "chip text",
deleteButtonLabel: "Delete",
};
WithDelete.parameters = {
docs: {
source: {
code: tagToString("ebay-chip", Standard.args),
},
},
};
19 changes: 19 additions & 0 deletions src/components/ebay-chip/index.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$ const textId = component.elId("text");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we don't allow the user to pass in a custom textid we should not do it this way but rather use :scoped
https://markojs.com/docs/class-components/#scoped

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nicer, thanks


<span class="chip">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should allow spread for probably the root element.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

<span class="chip__text" id=textId>
<${input.renderBody}/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have renderBody defined at the top (so it doesnt get added in spread), why not use it here? At least that way we don't have any unused variables

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! This is what I meant to do, thanks for catching it.

</span>
<if(input.deleteButtonLabel)>
<button
type="button"
class="chip__button"
type="button"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have two type=buttons.
You really want this to be a button! :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, good catch. I removed one of them.

aria-label=input.deleteButtonLabel
agliga marked this conversation as resolved.
Show resolved Hide resolved
aria-describedby=textId
on-click("emit", "delete")
>
<ebay-close-16-icon/>
</button>
</if>
</span>
9 changes: 9 additions & 0 deletions src/components/ebay-chip/marko-tag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"attribute-groups": ["html-attributes"],
"@*": {
"targetProperty": null,
"type": "expression"
},
"@html-attributes": "expression",
"@delete-button-label": "string"
}
1 change: 1 addition & 0 deletions src/components/ebay-chip/style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("@ebay/skin/chip");
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<DocumentFragment>
<span
class="chip"
>
<span
class="chip__text"
id="s0-text"
>
chip text
</span>
</span>
</DocumentFragment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<DocumentFragment>
<span
class="chip"
>
<span
class="chip__text"
id="s0-text"
>
chip text
</span>
<button
aria-describedby="s0-text"
aria-label="Delete"
class="chip__button"
type="button"
>
<svg
aria-hidden="true"
class="icon icon--close-16"
focusable="false"
>
<defs
data-marko-key="@defs s0-4-0"
>
<symbol
id="icon-close-16"
viewBox="0 0 16 16"
>
<path
d="M2.293 2.293a1 1 0 0 1 1.414 0L8 6.586l4.293-4.293a1 1 0 1 1 1.414 1.414L9.414 8l4.293 4.293a1 1 0 0 1-1.414 1.414L8 9.414l-4.293 4.293a1 1 0 0 1-1.414-1.414L6.586 8 2.293 3.707a1 1 0 0 1 0-1.414Z"
/>
</symbol>
</defs>
<use
xlink:href="#icon-close-16"
/>
</svg>
</button>
</span>
</DocumentFragment>
28 changes: 28 additions & 0 deletions src/components/ebay-chip/test/test.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect, use } from "chai";
import chaiDom from "chai-dom";
import { composeStories } from "@storybook/marko/dist/testing";
import { render, fireEvent, cleanup } from "@marko/testing-library";
import * as stories from "../chip.stories"; // import all stories from the stories file
const { WithDelete } = composeStories(stories);

use(chaiDom);
afterEach(cleanup);

/** @type import("@marko/testing-library").RenderResult */
let component;

describe("given delete button is present", () => {
beforeEach(async () => {
component = await render(WithDelete);
});

describe("when button is clicked", () => {
beforeEach(async () => {
await fireEvent.click(component.getByRole("button"));
});

it("then it emits the event with correct data", () => {
expect(component.emitted("delete")).has.length(1);
});
});
});
16 changes: 16 additions & 0 deletions src/components/ebay-chip/test/test.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { use } from "chai";
import { composeStories } from "@storybook/marko/dist/testing";
import { snapshotHTML } from "../../../common/test-utils/snapshots";
import * as stories from "../chip.stories"; // import all stories from the stories file
const { Standard, WithDelete } = composeStories(stories);
const htmlSnap = snapshotHTML(__dirname);

use(require("chai-dom"));

it("renders default chip component", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename these tests please?

  1. The default chip is also static, so something like, renders default static chip component
  2. The second one doesn't refer to chip; I think it should. Maybe something like, renders interactive chip with close button when close label is provided

Copy link
Contributor

@agliga agliga Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also on this same line, we should group up all these tests in a describe and say: ebay-chip or something like that. Then eep the descriptions for each test simple, like renders default and renders with close icon
https://github.com/eBay/ebayui-core/blob/master/src/components/ebay-icon/test/test.server.js#L11
(I know that its not everywhere but I think we should start to add it in all places)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I updated test names.

await htmlSnap(Standard);
});

it("renders with close icon when label is present", async () => {
await htmlSnap(WithDelete);
});
Loading