Skip to content

Commit bd616f8

Browse files
committed
fix(snackbar): add width prop for snackbar
1 parent 745a63d commit bd616f8

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

packages/core-components/src/components/snackbar/readme.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
## Properties
99

10-
| Property | Attribute | Description | Type | Default |
11-
| ------------- | -------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------- | ----------- |
12-
| `actionLabel` | `action-label` | Text for the Call-to-Action link. | `string` | `undefined` |
13-
| `description` | `description` | Text on the snackbar. | `string` | `undefined` |
14-
| `duration` | `duration` | How long is snackbar shown. Default value is 5000 ms. | `number` | `5000` |
15-
| `hasAction` | `has-action` | Whether the snackbar has a Call-to-Action. Per default, it is false. | `boolean` | `false` |
16-
| `opened` | `opened` | Whether the snackbar is currently visible. Set to true to display the snackbar. | `boolean` | `false` |
17-
| `timed` | `timed` | Whether snackbar is show for limited time. Default is true. Error snackbars cannot be timed. | `boolean` | `true` |
18-
| `type` | `type` | The type of snackbar. Default is info. | `"error" \| "info" \| "success" \| "warning"` | `'info'` |
19-
| `width` | `width` | Width of the snackbar in px, Default value is 270px. | `string` | `'270px'` |
10+
| Property | Attribute | Description | Type | Default |
11+
| ------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- | ----------- |
12+
| `actionLabel` | `action-label` | Text for the Call-to-Action link. | `string` | `undefined` |
13+
| `description` | `description` | Text on the snackbar. | `string` | `undefined` |
14+
| `duration` | `duration` | How long is snackbar shown. Default value is 5000 ms. | `number` | `5000` |
15+
| `hasAction` | `has-action` | Whether the snackbar has a Call-to-Action. Per default, it is false. | `boolean` | `false` |
16+
| `opened` | `opened` | Whether the snackbar is currently visible. Set to true to display the snackbar. | `boolean` | `false` |
17+
| `timed` | `timed` | Whether snackbar is show for limited time. Default is true. Error snackbars cannot be timed. | `boolean` | `true` |
18+
| `type` | `type` | The type of snackbar. Default is info. | `"error" \| "info" \| "success" \| "warning"` | `'info'` |
19+
| `width` | `width` | Width of the snackbar can be specified in px. If not provided, the default value is auto, which will adjust the width to fit the content. | `string` | `undefined` |
2020

2121

2222
## Events

packages/core-components/src/components/snackbar/snackbar.docs.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _Note_: when user hovers over the snackbar, timeout is paused and resumes once t
4040

4141
### Width
4242

43-
This property allow you to set the snackbar width. Minimum is 270px, maximum is 1000px. By default snackbar will have a width of 270px.
43+
This property allow you to set the snackbar width. Default value is auto, which will adjust the width to fit the content.
4444

4545
### Action
4646

packages/core-components/src/components/snackbar/snackbar.stories.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const meta: Meta = {
1818
duration: 5000,
1919
hasAction: true,
2020
actionLabel: 'Call to Action',
21-
width: '270px',
21+
width: 'auto',
2222
},
2323
argTypes: getArgTypes('b2b-snackbar'),
2424
render: ({ ...args }) => {
@@ -106,7 +106,6 @@ export const TimedSnackbar: Story = {
106106
timed: true,
107107
duration: 3000,
108108
description: 'This is timed snackbar',
109-
width: '270px',
110109
},
111110
play: async () => {
112111
await showSnackBar();

packages/core-components/src/components/snackbar/snackbar.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export class SnackbarComponent {
3535
/** Text for the Call-to-Action link. */
3636
@Prop() actionLabel: string;
3737

38-
/** Width of the snackbar in px, Default value is 270px. */
39-
@Prop() width: string = '270px';
38+
/** Width of the snackbar can be specified in px. If not provided, the default value is auto, which will adjust the width to fit the content. */
39+
@Prop() width: string;
4040

4141
/** Emits whenever the snackbar is closed. */
4242
@Event({ eventName: 'b2b-close' })
@@ -141,7 +141,7 @@ export class SnackbarComponent {
141141
[`b2b-snackbar--${this.type}`]: true,
142142
'b2b-snackbar--opened': this.opened,
143143
}}
144-
style={{ width: this.width }}>
144+
style={this.width ? { width: this.width } : { width: 'auto' }}>
145145
<div class="b2b-snackbar__content">
146146
<span class={{ [`b2b-snackbar--${this.type}__icon`]: true }}>
147147
{this.chooseIcon()}

0 commit comments

Comments
 (0)