Skip to content

Commit

Permalink
Improve display for multiple action buttons in notices (#31799)
Browse files Browse the repository at this point in the history
  • Loading branch information
laras126 authored May 14, 2021
1 parent 818018d commit 69f3a97
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 54 deletions.
62 changes: 32 additions & 30 deletions packages/components/src/notice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,36 +88,38 @@ function Notice( {
<div className={ classes }>
<div className="components-notice__content">
{ children }
{ actions.map(
(
{
className: buttonCustomClasses,
label,
isPrimary,
noDefaultClasses = false,
onClick,
url,
},
index
) => {
return (
<Button
key={ index }
href={ url }
isPrimary={ isPrimary }
isSecondary={ ! noDefaultClasses && ! url }
isLink={ ! noDefaultClasses && !! url }
onClick={ url ? undefined : onClick }
className={ classnames(
'components-notice__action',
buttonCustomClasses
) }
>
{ label }
</Button>
);
}
) }
<div className="components-notice__actions">
{ actions.map(
(
{
className: buttonCustomClasses,
label,
isPrimary,
noDefaultClasses = false,
onClick,
url,
},
index
) => {
return (
<Button
key={ index }
href={ url }
isPrimary={ isPrimary }
isSecondary={ ! noDefaultClasses && ! url }
isLink={ ! noDefaultClasses && !! url }
onClick={ url ? undefined : onClick }
className={ classnames(
'components-notice__action',
buttonCustomClasses
) }
>
{ label }
</Button>
);
}
) }
</div>
</div>
{ isDismissible && (
<Button
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/notice/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
margin: $grid-unit-05 #{ $button-size-small + $border-width } $grid-unit-05 0;
}

.components-notice__actions {
display: flex;
flex-wrap: wrap;
}

.components-notice__action.components-button {
&,
&.is-link {
Expand All @@ -42,6 +47,10 @@
&.is-secondary {
vertical-align: initial;
}

// When it has better support, this can be replaced
// with column-gap since these are flex items.
margin-right: $grid-unit-10;
}

.components-notice__dismiss {
Expand Down
52 changes: 28 additions & 24 deletions packages/components/src/notice/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ exports[`Notice should match snapshot 1`] = `
className="components-notice__content"
>
Example
<ForwardRef(Button)
className="components-notice__action"
href="https://example.com"
isLink={true}
isSecondary={false}
<div
className="components-notice__actions"
>
More information
</ForwardRef(Button)>
<ForwardRef(Button)
className="components-notice__action"
isLink={false}
isSecondary={true}
onClick={[Function]}
>
Cancel
</ForwardRef(Button)>
<ForwardRef(Button)
className="components-notice__action"
isLink={false}
isPrimary={true}
isSecondary={true}
onClick={[Function]}
>
Submit
</ForwardRef(Button)>
<ForwardRef(Button)
className="components-notice__action"
href="https://example.com"
isLink={true}
isSecondary={false}
>
More information
</ForwardRef(Button)>
<ForwardRef(Button)
className="components-notice__action"
isLink={false}
isSecondary={true}
onClick={[Function]}
>
Cancel
</ForwardRef(Button)>
<ForwardRef(Button)
className="components-notice__action"
isLink={false}
isPrimary={true}
isSecondary={true}
onClick={[Function]}
>
Submit
</ForwardRef(Button)>
</div>
</div>
<ForwardRef(Button)
className="components-notice__dismiss"
Expand Down

0 comments on commit 69f3a97

Please sign in to comment.