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

fix: add displayCloseButton prop, update storybook #1197

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions packages/components/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class Modal {
@Prop() closeButtonLabel?: string = 'Close Pop-up';
/** (optional) title for close button */
@Prop() closeButtonTitle?: string = 'Close';
/** (optional) display close button */
@Prop() displayCloseButton?: boolean = true;
acstll marked this conversation as resolved.
Show resolved Hide resolved
/** (optional) Alignment of action buttons */
@Prop() alignActions?: 'right' | 'left' = 'right';
/** (optional) Injected CSS styles */
Expand Down Expand Up @@ -274,18 +276,20 @@ export class Modal {
<h2 class="modal__heading" part="heading">
{this.heading}
</h2>
<button
ref={(el) => (this.closeButton = el)}
class="modal__close-button"
part="close-button"
onClick={() => this.emitBeforeClose('CLOSE_BUTTON')}
aria-label={this.closeButtonLabel}
title={this.closeButtonTitle}
>
<slot name="close-icon">
<scale-icon-action-circle-close decorative />
</slot>
</button>
{this.displayCloseButton && (
acstll marked this conversation as resolved.
Show resolved Hide resolved
<button
ref={(el) => (this.closeButton = el)}
class="modal__close-button"
part="close-button"
onClick={() => this.emitBeforeClose('CLOSE_BUTTON')}
aria-label={this.closeButtonLabel}
title={this.closeButtonTitle}
>
<slot name="close-icon">
<scale-icon-action-circle-close decorative />
</slot>
</button>
)}
</div>
<div
ref={(el) => (this.modalBody = el)}
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/components/modal/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| `allowInjectingStyleToBody` | `allow-injecting-style-to-body` | (optional) allow to inject css style {overflow: hidden} to body when modal is open | `boolean` | `false` |
| `closeButtonLabel` | `close-button-label` | (optional) Label for close button | `string` | `'Close Pop-up'` |
| `closeButtonTitle` | `close-button-title` | (optional) title for close button | `string` | `'Close'` |
| `displayCloseButton` | `display-close-button` | (optional) display close button | `boolean` | `true` |
| `duration` | `duration` | (optional) Transition duration | `number` | `200` |
| `heading` | `heading` | Modal heading | `string` | `undefined` |
| `opened` | `opened` | (optional) If `true`, the Modal is open. | `boolean` | `false` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ import ScaleModal from './ScaleModal.vue';
disable: true,
},
},
scaleBeforeClose: {
description: '@deprecated in v3 in favor of kebab-case event names.',
},
'scale-before-close': {
description:
'It fires on every close attempt. Calling `event.preventDefault()` will prevent the modal from closing.',
acstll marked this conversation as resolved.
Show resolved Hide resolved
},
}}
/>

Expand Down Expand Up @@ -74,6 +81,7 @@ export const Template = (args, context) => ({
:duration="duration"
:close-button-label="closeButtonLabel"
:close-button-title="closeButtonTitle"
:display-close-button="displayCloseButton"
:align-actions="alignActions"
:styles="styles"
:allow-injecting-style-to-body="allowInjectingStyleToBody"
Expand Down Expand Up @@ -140,10 +148,10 @@ export const Template = (args, context) => ({
```html
<scale-modal heading="Today is your lucky day" id="modal">
<p>Hello. Welcome. What a pleasure it is to have you.</p>
<scale-button variant="secondary" onclick="closeModal()">
<scale-button slot="action" variant="secondary" onclick="closeModal()">
Cancel
</scale-button>
<scale-button> Primary Action </scale-button>
<scale-button slot="action"> Primary Action </scale-button>
</scale-modal>

<script>
Expand Down Expand Up @@ -248,10 +256,10 @@ For Shadow Parts, please inspect the element's #shadow.
```html
<scale-modal heading="Today is your lucky day" size="small" id="modal">
<p>Hello. Welcome. What a pleasure it is to have you.</p>
<scale-button variant="secondary" onclick="closeModal()">
<scale-button slot="action" variant="secondary" onclick="closeModal()">
Cancel
</scale-button>
<scale-button> Primary Action </scale-button>
<scale-button slot="action"> Primary Action </scale-button>
</scale-modal>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:duration="duration"
:close-button-label="closeButtonLabel"
:close-button-title="closeButtonTitle"
:display-close-button="displayCloseButton"
:align-actions="alignActions"
:styles="styles"
:allow-injecting-style-to-body="allowInjectingStyleToBody"
Expand Down Expand Up @@ -34,6 +35,7 @@ export default {
duration: { type: Number, default: 200 },
closeButtonLabel: String,
closeButtonTitle: String,
displayCloseButton: { type: Boolean, default: true },
alignActions: { type: String, default: 'right' },
allowInjectingStyleToBody: Boolean,
styles: { type: String },
Expand Down