Skip to content

Commit 5885ac1

Browse files
authored
fix(Banner): styles (#1022)
1 parent 8646bde commit 5885ac1

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Fixed Banner component description text styling by correcting the style selector from `Label` to `Description`. Improved display style system to respect user-provided `whiteSpace` prop, allowing it to override default white-space values set by `textOverflow`.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
---
2-
description: When user asked to add a changeset
3-
alwaysApply: false
4-
---
1+
# add-changeset
52

6-
Add changeset manually. Place the changeset in the `/.changeset` folder.
3+
Add changeset manually (direct edit / without cli commands). Place the changeset in the `/.changeset` folder.
74

85
## Version Selection
96
- Use `patch` for bug fixes and small changes (even with minor breaking changes)
@@ -14,6 +11,8 @@ Add changeset manually. Place the changeset in the `/.changeset` folder.
1411
1. Diff introduced in the current chat session
1512
2. Diff of the working tree (if chat diff is empty)
1613
3. Diff with the `main` branch (if working tree is empty)
14+
- Check other changesets in case they can be edited instead of creating a new one
15+
- Add several changesets instead of one if it makes sense
1716
- Keep the changeset concise and user-focused
1817
- Only document changes that affect end users or the public API
1918
- Exclude fixes for issues that were introduced and resolved within the same PR (internal corrections during development)

src/components/actions/Banner/Banner.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,19 @@ CustomIcon.args = {
121121
icon: <IconBell />,
122122
isDismissible: true,
123123
};
124+
125+
/**
126+
* Shows the `description` prop with a long description that overflows.
127+
* Narrow width triggers text truncation with ellipsis after two lines.
128+
*/
129+
export const WithDescription: StoryFn<BannerProps> = () => {
130+
return (
131+
<Banner
132+
theme="note"
133+
width="300px"
134+
description="This is an extended description that spans multiple lines to demonstrate text overflow behavior. When the banner container has limited width, the description should show ellipsis after two lines."
135+
>
136+
Payment method expiring soon
137+
</Banner>
138+
);
139+
};

src/components/actions/Banner/Banner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ const BannerElement = tasty(Item, {
4848
styles: {
4949
width: '100%',
5050

51-
Label: {
51+
Description: {
5252
textOverflow: 'ellipsis / 2',
53-
textWrap: 'initial',
53+
whiteSpace: 'normal',
5454
},
5555

5656
Actions: {

src/tasty/styles/display.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('displayStyle', () => {
7474
expect(result).toEqual({
7575
overflow: 'hidden',
7676
'text-overflow': 'ellipsis',
77+
'white-space': 'initial',
7778
display: '-webkit-box',
7879
'-webkit-box-orient': 'vertical',
7980
'-webkit-line-clamp': 2,
@@ -86,6 +87,7 @@ describe('displayStyle', () => {
8687
expect(result).toEqual({
8788
overflow: 'hidden',
8889
'text-overflow': 'ellipsis',
90+
'white-space': 'initial',
8991
display: '-webkit-box',
9092
'-webkit-box-orient': 'vertical',
9193
'-webkit-line-clamp': 3,
@@ -98,6 +100,7 @@ describe('displayStyle', () => {
98100
expect(result).toEqual({
99101
overflow: 'hidden',
100102
'text-overflow': 'clip',
103+
'white-space': 'initial',
101104
display: '-webkit-box',
102105
'-webkit-box-orient': 'vertical',
103106
'-webkit-line-clamp': 2,
@@ -132,12 +135,12 @@ describe('displayStyle', () => {
132135
expect(result!['overflow']).toBe('hidden');
133136
});
134137

135-
it('textOverflow white-space takes precedence over user whiteSpace', () => {
138+
it('user whiteSpace overrides textOverflow default white-space', () => {
136139
const result = displayStyle({
137140
textOverflow: 'ellipsis',
138141
whiteSpace: 'pre-wrap',
139142
});
140-
expect(result!['white-space']).toBe('nowrap');
143+
expect(result!['white-space']).toBe('pre-wrap');
141144
});
142145

143146
it('multi-line textOverflow display takes precedence over user display', () => {
@@ -166,6 +169,14 @@ describe('displayStyle', () => {
166169
expect(result!['display']).toBe('flex');
167170
});
168171

172+
it('user whiteSpace overrides multi-line textOverflow default white-space', () => {
173+
const result = displayStyle({
174+
textOverflow: 'ellipsis / 2',
175+
whiteSpace: 'pre-wrap',
176+
});
177+
expect(result!['white-space']).toBe('pre-wrap');
178+
});
179+
169180
it('preserves user overflow when textOverflow is reset', () => {
170181
const result = displayStyle({
171182
textOverflow: true,

src/tasty/styles/display.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ interface DisplayStyleProps {
2121
* Priority:
2222
* 1. `hide` takes precedence (display: none)
2323
* 2. Multi-line `textOverflow` forces display: -webkit-box
24-
* 3. Single-line `textOverflow` forces white-space: nowrap and overflow: hidden
24+
* 3. Single-line `textOverflow` defaults white-space to nowrap, multi-line defaults to initial
25+
* 4. Explicit `whiteSpace` overrides the default white-space from `textOverflow`
2526
*/
2627
export function displayStyle({
2728
display,
@@ -63,12 +64,13 @@ export function displayStyle({
6364
result['text-overflow'] = hasEllipsis ? 'ellipsis' : 'clip';
6465

6566
if (clamp === 1) {
66-
result['white-space'] = 'nowrap';
67+
result['white-space'] = whiteSpace || 'nowrap';
6768
} else {
6869
result['display'] = '-webkit-box';
6970
result['-webkit-box-orient'] = 'vertical';
7071
result['-webkit-line-clamp'] = clamp;
7172
result['line-clamp'] = clamp;
73+
result['white-space'] = whiteSpace || 'initial';
7274
}
7375
}
7476
}

0 commit comments

Comments
 (0)