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-1635: Button - Allow styling the inner label element #2112

Merged
merged 2 commits into from
Nov 15, 2023
Merged

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented Nov 14, 2023

Summary:

The current button doesn’t allow to display the text contents in multiple lines.

This is required so we can remove the truncate functionality for certain cases
like the ActionBubble component in webapp. This is needed so we can wrap the
text instead and allow the button’s content to be displayed in two (or more)
lines when needed.

This PR adds a new prop labelStyle to the Button component that allows to
style the inner label element.

Also changed the border property to outline to be consistent with the
overall strategy for visual indicatorss in all the WB components. This will also
help us to avoid some layout issues in case folks override the button styles.

Issue: https://khanacademy.atlassian.net/browse/WB-1635

Test plan:

Verify that the following story works as expected:

/?path=/story/button--custom-styles

Screenshot 2023-11-14 at 5 00 45 PM

By working as expected, it means that the custom button should be displayed
in multiple lines and the text should be wrapped instead of being truncated.

Also verify that the other stories work as expected.

@jandrade jandrade self-assigned this Nov 14, 2023
Copy link

changeset-bot bot commented Nov 14, 2023

🦋 Changeset detected

Latest commit: 14eba89

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-button Minor
@khanacademy/wonder-blocks-banner Patch
@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 November 14, 2023 22:00
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/fluffy-beers-reply.md, __docs__/wonder-blocks-button/button.argtypes.ts, __docs__/wonder-blocks-button/button.stories.tsx, packages/wonder-blocks-button/src/components/button-core.tsx, packages/wonder-blocks-button/src/components/button.tsx, packages/wonder-blocks-button/src/__tests__/__snapshots__/custom-snapshot.test.tsx.snap

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

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

Merging #2112 (14eba89) into main (7b24db9) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2112      +/-   ##
==========================================
- Coverage   97.06%   97.06%   -0.01%     
==========================================
  Files         243      243              
  Lines       28203    28186      -17     
  Branches     2462     2416      -46     
==========================================
- Hits        27376    27359      -17     
  Misses        827      827              
Files Coverage Δ
...onder-blocks-button/src/components/button-core.tsx 99.80% <100.00%> (-0.01%) ⬇️
...ges/wonder-blocks-button/src/components/button.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 7b24db9...14eba89. Read the comment docs.

Copy link
Contributor

github-actions bot commented Nov 14, 2023

Size Change: -63 B (0%)

Total Size: 92.6 kB

Filename Size Change
packages/wonder-blocks-button/dist/es/index.js 4.26 kB -63 B (-1%)
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.53 kB
packages/wonder-blocks-banner/dist/es/index.js 1.53 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.69 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 1.13 kB
packages/wonder-blocks-cell/dist/es/index.js 2.19 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.23 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-dropdown/dist/es/index.js 12 kB
packages/wonder-blocks-form/dist/es/index.js 5.42 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.06 kB
packages/wonder-blocks-icon/dist/es/index.js 3.04 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.53 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 Nov 14, 2023

npm Snapshot: Published

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

Packages can also be installed manually by running:

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

Copy link
Contributor

@nishasy nishasy left a comment

Choose a reason for hiding this comment

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

Looks AWESOME! Very excited about the border -> outline update.

Don't forget to update the chromatic interaction test before landing 🙂

whiteSpace: "normal",
},
},
render: (args: any) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Praise: Great time to use args!

@@ -488,25 +482,12 @@ export const _generateStyles = (
},
},
focus: {
":after": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Praise: I love that we can remove this!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the test on line 124 is failing here because of the border/outline update. (It won't let me comment that line directly)

await expect(computedStyleButton.borderWidth).toBe("2px");

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I'll fix that.

Copy link
Contributor

A new build was pushed to Chromatic! 🚀

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

Chromatic results:

Metric Total
Captured snapshots 9
Tests with visual changes 13
Total stories 393
Inherited (not captured) snapshots [TurboSnap] 312
Tests on the build 321

@jandrade jandrade merged commit a70a929 into main Nov 15, 2023
13 checks passed
@jandrade jandrade deleted the button-styles branch November 15, 2023 15:43
jandrade added a commit that referenced this pull request Nov 17, 2023
## Summary:

In #2112, I introduced a new `labelStyle` prop and refactored the styles for the
secondary button. However, I missed a case where the border was not being
applied correctly, causing the button from being cut off in certain scenarios.
This PR fixes that issue by including the `border` in the resting/default state,
so the button is always rendered with a border (including that as part of
the box model).

NOTE: The issue was noticed while trying to integrate the changes in webapp.

<img width="621" alt="Screenshot 2023-11-15 at 6 00 42 PM" src="https://github.com/Khan/wonder-blocks/assets/843075/32f76420-1aff-47c9-ad34-cb4aa8976bff">

Issue: WB-1635

## Test plan:

Verify that the secondary button is rendered correctly in all scenarios. This
means that now secondary buttons will always have a border in the resting state.

Author: jandrade

Reviewers: jeresig

Required Reviewers:

Approved By: jeresig

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

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