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

WB-1588: Allow custom ActionItem elements #2135

Merged
merged 6 commits into from
Dec 5, 2023
Merged

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented Dec 5, 2023

Summary:

  1. Allow custom ActionItem components by using Cell internally.
  • Removed ClickableBehavior from ActionItem and replaced it with
    CompactCell (which internally uses Clickable).
  • Removed skipClientNav from ActionItem as it is no longer used/needed.
  • Added stories and better documentation for ActionMenu and ActionItem.
  1. Modified Cell to support two new props required for the ActionItem changes:
  • role is used to set the role attribute on the cell's root element.
  • rootStyle is used to override the style attribute on the cell's root
    element.

Issue: WB-1588

Test plan:

ActionMenu:

  1. Navigate to http://localhost:6061/?path=/story/dropdown-actionmenu--custom-action-items
  2. Verify that the custom action items are rendered as expected.
  3. Verify that the custom action items are clickable and that the click handler
    is called as expected.
Screen.Recording.2023-12-05.at.12.51.05.PM.mov

ActionItem docs:

  1. Navigate to http://localhost:6061/?path=/docs/dropdown-actionitem--docs
  2. Verify that the documentation for ActionItem is correct and up to date.
Screenshot 2023-12-05 at 12 52 01 PM

@jandrade jandrade self-assigned this Dec 5, 2023
Copy link

changeset-bot bot commented Dec 5, 2023

🦋 Changeset detected

Latest commit: 4533719

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@khanacademy/wonder-blocks-dropdown Major
@khanacademy/wonder-blocks-cell Minor
@khanacademy/wonder-blocks-birthday-picker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@khan-actions-bot khan-actions-bot requested a review from a team December 5, 2023 17:50
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/empty-kids-breathe.md, .changeset/new-lamps-doubt.md, __docs__/wonder-blocks-cell/compact-cell.argtypes.tsx, __docs__/wonder-blocks-dropdown/action-item.argtypes.tsx, __docs__/wonder-blocks-dropdown/action-item.stories.tsx, __docs__/wonder-blocks-dropdown/action-menu.stories.tsx, __docs__/wonder-blocks-icon/phosphor-icon.argtypes.ts, consistency-tests/__tests__/clickables.test.tsx, packages/wonder-blocks-dropdown/package.json, packages/wonder-blocks-dropdown/tsconfig-build.json, packages/wonder-blocks-cell/src/util/types.ts, packages/wonder-blocks-dropdown/src/components/action-item.tsx, packages/wonder-blocks-cell/src/components/internal/cell-core.tsx, packages/wonder-blocks-dropdown/src/components/__tests__/action-item.test.tsx, packages/wonder-blocks-cell/src/components/internal/__tests__/cell-core.test.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Contributor

github-actions bot commented Dec 5, 2023

Size Change: -40 B (0%)

Total Size: 90.9 kB

Filename Size Change
packages/wonder-blocks-cell/dist/es/index.js 2.22 kB +25 B (+1%)
packages/wonder-blocks-dropdown/dist/es/index.js 11.9 kB -65 B (-1%)
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.69 kB
packages/wonder-blocks-banner/dist/es/index.js 1.53 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.72 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 1.13 kB
packages/wonder-blocks-button/dist/es/index.js 4.27 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.24 kB
packages/wonder-blocks-color/dist/es/index.js 1.15 kB
packages/wonder-blocks-core/dist/es/index.js 3.67 kB
packages/wonder-blocks-data/dist/es/index.js 6.33 kB
packages/wonder-blocks-form/dist/es/index.js 5.34 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-i18n/dist/es/index.js 4.54 kB
packages/wonder-blocks-icon-button/dist/es/index.js 3.21 kB
packages/wonder-blocks-icon/dist/es/index.js 1.06 kB
packages/wonder-blocks-labeled-field/dist/es/index.js 72 B
packages/wonder-blocks-layout/dist/es/index.js 1.88 kB
packages/wonder-blocks-link/dist/es/index.js 2.54 kB
packages/wonder-blocks-modal/dist/es/index.js 5.04 kB
packages/wonder-blocks-pill/dist/es/index.js 1.03 kB
packages/wonder-blocks-popover/dist/es/index.js 4.33 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.51 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.55 kB
packages/wonder-blocks-spacing/dist/es/index.js 158 B
packages/wonder-blocks-switch/dist/es/index.js 2.06 kB
packages/wonder-blocks-testing/dist/es/index.js 3.94 kB
packages/wonder-blocks-theming/dist/es/index.js 1.21 kB
packages/wonder-blocks-timing/dist/es/index.js 1.78 kB
packages/wonder-blocks-toolbar/dist/es/index.js 862 B
packages/wonder-blocks-tooltip/dist/es/index.js 5.05 kB
packages/wonder-blocks-typography/dist/es/index.js 1.49 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Dec 5, 2023

npm Snapshot: Published

🎉 Good news!! We've packaged up the latest commit from this PR (002aeb6) and published all packages with changesets to npm.

You can install the packages in webapp by running:

./services/static/dev/tools/deploy_wonder_blocks.js --tag="PR2135"

Packages can also be installed manually by running:

yarn add @khanacademy/wonder-blocks-<package-name>@PR2135

Copy link

codecov bot commented Dec 5, 2023

Codecov Report

Merging #2135 (4533719) into main (9092363) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2135      +/-   ##
==========================================
- Coverage   97.05%   97.05%   -0.01%     
==========================================
  Files         241      241              
  Lines       28038    28006      -32     
  Branches     2464     2405      -59     
==========================================
- Hits        27212    27180      -32     
  Misses        826      826              
Files Coverage Δ
...-blocks-cell/src/components/internal/cell-core.tsx 100.00% <100.00%> (ø)
...der-blocks-dropdown/src/components/action-item.tsx 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9092363...4533719. Read the comment docs.

Copy link
Contributor

github-actions bot commented Dec 5, 2023

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-rypjmjkakz.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 4
Tests with visual changes 7
Total stories 394
Inherited (not captured) snapshots [TurboSnap] 317
Tests on the build 321

Copy link
Member

@jeresig jeresig left a comment

Choose a reason for hiding this comment

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

This looks really sharp - thank you for working on this!

wrapper: {
// This removes the 300ms click delay on mobile browsers by indicating
// that "double-tap to zoom" shouldn't be used on this element.
touchAction: "manipulation",
Copy link
Member

Choose a reason for hiding this comment

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

Ooh - neat!

Copy link
Member Author

Choose a reason for hiding this comment

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

note: Added separate docs for ActionItem to help understanding better how this component works.

@@ -431,3 +442,91 @@ const locales = [
{id: "fr", locale: "fr", localName: "français"},
{id: "it", locale: "it", localName: "italiano"},
];

Copy link
Member Author

Choose a reason for hiding this comment

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

note: This story shows how we can use an ActionMenu with custom ActionItem elements.

@@ -10,7 +10,7 @@ import {render, screen} from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import plus from "@phosphor-icons/core/regular/plus.svg";
import {ActionItem, OptionItem} from "@khanacademy/wonder-blocks-dropdown";
import {OptionItem} from "@khanacademy/wonder-blocks-dropdown";
Copy link
Member Author

Choose a reason for hiding this comment

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

note: Removed ActionItem from here as we now delegate the ActionItem's clickable behavior/rendering to CompactCell.

@@ -18,7 +18,10 @@ describe("ActionItem", () => {
render(<ActionItem href="/foo" label="Example" disabled={true} />);

// Assert
expect(screen.getByRole("menuitem")).toBeDisabled();
expect(screen.getByRole("menuitem")).toHaveAttribute(
Copy link
Member Author

Choose a reason for hiding this comment

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

note: Cell handles the disabled state with the aria-disabled attr.

* https://khanacademy.org/math/algebra/eval-exprs will trigger a full
* page reload.
*/
skipClientNav?: boolean;
Copy link
Member Author

Choose a reason for hiding this comment

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

note: This is no longer used, so I got rid of it.

@jandrade jandrade merged commit 860d9ef into main Dec 5, 2023
13 checks passed
@jandrade jandrade deleted the action-item-as-cell branch December 5, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants