Skip to content

Commit d36860e

Browse files
authored
[WB-2123] ActivityIconButton: Update styling to avoid truncating labels by default (#2885)
## Summary: Changes `ActivityIconButton` styling to allow longer labels in the same line. This will allow us to display the label correctly for non-EN locales. Slack thread: https://khanacademy.slack.com/archives/C07CA2YR0BZ/p1759503438340869 Also took the opportunity to apply some default styles in the chonky box. Issue: WB-2123 ## Test plan: Verify that the ActivityIconButton snapshots look as expected. This means that short labels won't truncate, and longer labels will become multi-line when it exceeds 200px. Author: jandrade Reviewers: beaesguerra Required Reviewers: Approved By: beaesguerra Checks: ✅ 12 checks were successful, ⏭️ 3 checks have been skipped Pull Request URL: #2885
1 parent 0fd41cc commit d36860e

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

.changeset/tough-scissors-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/wonder-blocks-icon-button": patch
3+
---
4+
5+
Changes `ActivityIconButton` styling to allow longer labels in the same line.

__docs__/wonder-blocks-icon-button/activity-icon-button-testing-snapshots.stories.tsx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {View} from "@khanacademy/wonder-blocks-core";
1212
import {semanticColor, sizing} from "@khanacademy/wonder-blocks-tokens";
1313
import {Icon} from "@khanacademy/wonder-blocks-icon";
1414
import khanmigoIcon from "./images/mini-khanmigo.svg";
15+
import {StatusBadge} from "@khanacademy/wonder-blocks-badge";
1516

1617
/**
1718
* The following stories are used to generate the pseudo states for the
@@ -136,7 +137,7 @@ export const Scenarios: Story = {
136137
},
137138
},
138139
{
139-
name: "Long label with single word in two lines",
140+
name: "Long label with single word in same line",
140141
props: {
141142
children: (
142143
<ActivityIconButton
@@ -187,6 +188,47 @@ export const Scenarios: Story = {
187188
),
188189
},
189190
},
191+
{
192+
name: "With custom size + badge",
193+
props: {
194+
children: (
195+
<ActivityIconButton
196+
icon={
197+
<>
198+
<StatusBadge
199+
label="new"
200+
kind="info"
201+
styles={{
202+
root: {
203+
top: sizing.size_0,
204+
right: sizing.size_0,
205+
position: "absolute",
206+
transform:
207+
"translate(-50%, -50%)",
208+
},
209+
}}
210+
/>
211+
<Icon size="large">
212+
<img alt="" src={khanmigoIcon} />
213+
</Icon>
214+
</>
215+
}
216+
label="Cool badge"
217+
actionType="neutral"
218+
kind="secondary"
219+
styles={{
220+
root: {
221+
marginBlock: sizing.size_160,
222+
},
223+
box: {
224+
inlineSize: sizing.size_960,
225+
blockSize: sizing.size_960,
226+
},
227+
}}
228+
/>
229+
),
230+
},
231+
},
190232
];
191233
return (
192234
<ScenariosLayout scenarios={scenarios}>

packages/wonder-blocks-icon-button/src/components/activity-icon-button.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const theme = {
196196
disabled: semanticColor.core.foreground.disabled.default,
197197
},
198198
layout: {
199-
width: sizing.size_640,
199+
inlineSize: sizing.size_640,
200200
},
201201
},
202202
};
@@ -249,8 +249,9 @@ const _generateStyles = (
249249
// layout
250250
flexDirection: "column",
251251
gap: sizing.size_020,
252-
// Prevent the button from stretching to fill the parent
253-
maxWidth: theme.label.layout.width,
252+
// Putting an arbitrary max inline size to prevent the button from
253+
// stretching to fill the parent.
254+
maxInlineSize: 200,
254255
alignSelf: "flex-start",
255256
justifySelf: "center",
256257
/**
@@ -302,6 +303,9 @@ const _generateStyles = (
302303
marginBlockEnd: theme.root.shadow.y.rest,
303304
paddingBlock: theme.root.layout.padding.block,
304305
paddingInline: theme.root.layout.padding.inline,
306+
inlineSize: theme.label.layout.inlineSize,
307+
justifyContent: "center",
308+
alignItems: "center",
305309
// theming
306310
background: themeVariant.background[kind].rest,
307311
border: `${borderWidthKind.rest} solid ${themeVariant.border[kind].rest}`,

0 commit comments

Comments
 (0)