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-1645: Allow custom option item elements #2139

Merged
merged 10 commits into from
Dec 14, 2023
Merged

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented Dec 13, 2023

Summary:

  1. Allow custom OptionItem components by using DetailCell internally.
  • Removed ClickableBehavior from OptionItem and replaced it with
    DetailCell (which internally uses Clickable).
  • Added stories and included docs for OptionItem.
  1. Modified Cell to support a new prop required for the Optionitem changes:
  • aria-selected is used to allow the OptionItem to be selectable (via aria attributes).

Issue: WB-1645

Test plan:

SingleSelect:

  1. Navigate to http://localhost:6061/?path=/docs/dropdown-singleselect--docs#custom-option-items
  2. Verify that the custom option items are rendered as expected.
  3. Verify that the custom option items are clickable and that clicking on them
    selects them.
Screen.Recording.2023-12-13.at.11.41.07.AM.mov

MultiSelect:

  1. Navigate to http://localhost:6061/?path=/docs/dropdown-multiselect--docs#custom-option-items
  2. Verify that the custom option items are rendered as expected.
  3. Verify that the custom option items are clickable and that clicking on them
    selects them.
Screen.Recording.2023-12-13.at.12.03.08.PM.mov

OptionItem docs:

  1. Navigate to http://localhost:6061/?path=/docs/dropdown-optionitem--docs
  2. Verify that the documentation for OptionItem is correct and up to date.
Screenshot 2023-12-13 at 12 07 11 PM

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

changeset-bot bot commented Dec 13, 2023

🦋 Changeset detected

Latest commit: f67aa59

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-cell Minor
@khanacademy/wonder-blocks-dropdown Major
@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 13, 2023 17:05
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Dec 13, 2023

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/fuzzy-roses-crash.md, .changeset/smooth-icons-whisper.md, __docs__/wonder-blocks-cell/compact-cell.argtypes.tsx, __docs__/wonder-blocks-dropdown/multi-select.stories.tsx, __docs__/wonder-blocks-dropdown/option-item-examples.tsx, __docs__/wonder-blocks-dropdown/option-item.argtypes.tsx, __docs__/wonder-blocks-dropdown/option-item.stories.tsx, __docs__/wonder-blocks-dropdown/single-select.stories.tsx, consistency-tests/__tests__/clickables.test.tsx, packages/wonder-blocks-cell/src/util/types.ts, packages/wonder-blocks-dropdown/src/components/check.tsx, packages/wonder-blocks-dropdown/src/components/checkbox.tsx, packages/wonder-blocks-dropdown/src/components/dropdown-core.tsx, packages/wonder-blocks-dropdown/src/components/dropdown-opener.tsx, packages/wonder-blocks-dropdown/src/components/multi-select.tsx, packages/wonder-blocks-dropdown/src/components/option-item.tsx, packages/wonder-blocks-dropdown/src/components/select-opener.tsx, packages/wonder-blocks-dropdown/src/components/single-select.tsx, packages/wonder-blocks-dropdown/src/util/constants.ts, packages/wonder-blocks-dropdown/src/util/helpers.ts, packages/wonder-blocks-dropdown/src/util/types.ts, packages/wonder-blocks-cell/src/components/internal/cell-core.tsx, packages/wonder-blocks-dropdown/src/components/__tests__/multi-select.test.tsx, packages/wonder-blocks-dropdown/src/components/__tests__/option-item.test.tsx, packages/wonder-blocks-dropdown/src/components/__tests__/single-select.test.tsx, packages/wonder-blocks-dropdown/src/util/__tests__/helpers.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 13, 2023

Size Change: +172 B (0%)

Total Size: 91.4 kB

Filename Size Change
packages/wonder-blocks-cell/dist/es/index.js 2.24 kB +22 B (+1%)
packages/wonder-blocks-dropdown/dist/es/index.js 12.3 kB +150 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.7 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.38 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 13, 2023

npm Snapshot: Published

🎉 Good news!! We've packaged up the latest commit from this PR (3db1f69) 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="PR2139"

Packages can also be installed manually by running:

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

Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Merging #2139 (f67aa59) into main (6df21f7) will increase coverage by 0.00%.
The diff coverage is 99.25%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main    #2139    +/-   ##
========================================
  Coverage   97.05%   97.06%            
========================================
  Files         242      242            
  Lines       28058    28191   +133     
  Branches     2457     2419    -38     
========================================
+ Hits        27232    27363   +131     
- Misses        826      828     +2     
Files Coverage Δ
...-blocks-cell/src/components/internal/cell-core.tsx 100.00% <100.00%> (ø)
...es/wonder-blocks-dropdown/src/components/check.tsx 100.00% <100.00%> (ø)
...wonder-blocks-dropdown/src/components/checkbox.tsx 100.00% <100.00%> (ø)
...blocks-dropdown/src/components/dropdown-opener.tsx 100.00% <100.00%> (ø)
...er-blocks-dropdown/src/components/multi-select.tsx 99.83% <100.00%> (+<0.01%) ⬆️
...der-blocks-dropdown/src/components/option-item.tsx 100.00% <100.00%> (ø)
...r-blocks-dropdown/src/components/select-opener.tsx 99.33% <100.00%> (+<0.01%) ⬆️
...r-blocks-dropdown/src/components/single-select.tsx 100.00% <100.00%> (ø)
...kages/wonder-blocks-dropdown/src/util/constants.ts 100.00% <100.00%> (ø)
...ackages/wonder-blocks-dropdown/src/util/helpers.ts 100.00% <100.00%> (ø)
... and 1 more

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 6df21f7...f67aa59. Read the comment docs.

Copy link
Contributor

github-actions bot commented Dec 13, 2023

A new build was pushed to Chromatic! 🚀

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

Chromatic results:

Metric Total
Captured snapshots 47
Tests with visual changes 18
Total stories 402
Inherited (not captured) snapshots [TurboSnap] 280
Tests on the build 327

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: Noticed that we didn't have docs for this, and now that this component is more complex, we should have docs included!

@@ -172,6 +172,7 @@ const CellCore = (props: CellCoreProps): React.ReactElement => {
href,
onClick,
"aria-label": ariaLabel,
"aria-selected": ariaSelected,
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 needed by OptionItem so we can know when a given option is selected.

Comment on lines -36 to -42
color={
disabled
? offBlack32
: pressed || hovered || focused
? white
: offBlack
}
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 this as we no longer depend on Clickable/getClickableBehavior and instead we assign this with CSS (defined in OptionItem).

? activeBlue
: blue
: white;
const {disabled, selected} = props;

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: Similar to check.tsx, these states are now handled directly in OptionItem with css objects.

Comment on lines 210 to 212
subtitle1={
<LabelSmall className="subtitle">{subtitle1}</LabelSmall>
}
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: Adding this custom "LabelSmall.subtitle" wrapper to be able to style the hover state correctly.

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.

Very nice - looks great to me!

Base automatically changed from option-item-as-cell-2 to main December 14, 2023 15:33
@jandrade jandrade merged commit 56a896c into main Dec 14, 2023
13 checks passed
@jandrade jandrade deleted the option-item-as-cell-3 branch December 14, 2023 17:57
jandrade added a commit that referenced this pull request Dec 15, 2023
🖍 _This is an audit!_ 🖍

## Summary:

Fixes a regression in `SingleSelect` where the opener is not able to use an
empty string as a label.

In #2139, I changed the logic to use `1 item` for those cases, but turns out
that this "empty" value feature is required by Perseus.

Issue: WB-1645

## Test plan:

Verify that the "Two with Text" example in the `SingleSelect` storybook page
shows empty string as the label for both openers:

http://localhost:6061/?path=/story/dropdown-singleselect--two-with-text

<img width="1584" alt="Screenshot 2023-12-15 at 1 52 16 PM" src="https://github.com/Khan/wonder-blocks/assets/843075/5a65edeb-334b-43db-9a72-ce2fe2058139">

Author: jandrade

Auditors: jeresig, jeremywiebe, nedredmond

Required Reviewers:

Approved By: jeresig, jeremywiebe

Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 16.x), ✅ Lint (ubuntu-latest, 16.x), ✅ Check build sizes (ubuntu-latest, 16.x), ✅ Test (ubuntu-latest, 16.x, 2/2), ✅ Test (ubuntu-latest, 16.x, 1/2), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 16.x), ✅ Publish npm snapshot (ubuntu-latest, 16.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 16.x), ⏭  Chromatic - Skip on Release PR (changesets), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 16.x), ✅ gerald, ✅ codecov/project, ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 16.x), ✅ Lint (ubuntu-latest, 16.x), ✅ Test (ubuntu-latest, 16.x, 2/2), ✅ Check build sizes (ubuntu-latest, 16.x), ✅ Test (ubuntu-latest, 16.x, 1/2), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 16.x), ✅ Publish npm snapshot (ubuntu-latest, 16.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 16.x), ⏭  Chromatic - Skip on Release PR (changesets), ✅ gerald, ✅ Check for .changeset entries for all changed files (ubuntu-latest, 16.x), ⏭  dependabot

Pull Request URL: #2146
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