Fixed #992 - breakpoints for Dialog and ConfirmDialog

pull/1021/head
Cagatay Civici 2021-02-19 20:24:08 +03:00
parent 19fe8b219b
commit a8fdc2858d
7 changed files with 142 additions and 5 deletions

View File

@ -1,5 +1,6 @@
interface ConfirmDialogProps { interface ConfirmDialogProps {
group?: string; group?: string;
breakpoints?: {[key: string]: string};
} }
declare class ConfirmDialog { declare class ConfirmDialog {

View File

@ -1,5 +1,6 @@
<template> <template>
<CDialog v-model:visible="visible" :modal="true" :header="header" :blockScroll="blockScroll" :position="position" class="p-confirm-dialog"> <CDialog v-model:visible="visible" :modal="true" :header="header" :blockScroll="blockScroll" :position="position" class="p-confirm-dialog"
:breakpoints="breakpoints">
<i :class="iconClass" /> <i :class="iconClass" />
<span class="p-confirm-dialog-message">{{message}}</span> <span class="p-confirm-dialog-message">{{message}}</span>
<template #footer> <template #footer>
@ -16,7 +17,11 @@ import Button from 'primevue/button';
export default { export default {
props: { props: {
group: String group: String,
breakpoints: {
type: Object,
default: null
}
}, },
data() { data() {
return { return {

View File

@ -16,6 +16,7 @@ interface DialogProps {
ariaCloseLabel?: string; ariaCloseLabel?: string;
position?: string; position?: string;
maximizable?: boolean; maximizable?: boolean;
breakpoints?: {[key: string]: string};
} }
declare class Dialog { declare class Dialog {

View File

@ -68,6 +68,10 @@ export default {
position: { position: {
type: String, type: String,
default: 'center' default: 'center'
},
breakpoints: {
type: Object,
default: null
} }
}, },
data() { data() {
@ -79,6 +83,7 @@ export default {
documentKeydownListener: null, documentKeydownListener: null,
container: null, container: null,
mask: null, mask: null,
styleElement: null,
updated() { updated() {
if (this.visible) { if (this.visible) {
this.containerVisible = this.visible; this.containerVisible = this.visible;
@ -86,9 +91,15 @@ export default {
}, },
beforeUnmount() { beforeUnmount() {
this.unbindDocumentState(); this.unbindDocumentState();
this.destroyStyle();
this.container = null; this.container = null;
this.mask = null; this.mask = null;
}, },
mounted() {
if (this.breakpoints) {
this.createStyle();
}
},
methods: { methods: {
close() { close() {
this.$emit('update:visible', false); this.$emit('update:visible', false);
@ -97,6 +108,8 @@ export default {
if (this.autoZIndex) { if (this.autoZIndex) {
el.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex()); el.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
} }
el.setAttribute(this.attributeSelector, '');
}, },
onEnter() { onEnter() {
this.mask.style.zIndex = String(parseInt(this.container.style.zIndex, 10) - 1); this.mask.style.zIndex = String(parseInt(this.container.style.zIndex, 10) - 1);
@ -205,6 +218,32 @@ export default {
}, },
maskRef(el) { maskRef(el) {
this.mask = el; this.mask = el;
},
createStyle() {
if (!this.styleElement) {
this.styleElement = document.createElement('style');
this.styleElement.type = 'text/css';
document.body.appendChild(this.styleElement);
let innerHTML = '';
for (let breakpoint in this.breakpoints) {
innerHTML += `
@media screen and (max-width: ${breakpoint}) {
.p-dialog[${this.attributeSelector}] {
width: ${this.breakpoints[breakpoint]} !important;
}
}
`
}
this.styleElement.innerHTML = innerHTML;
}
},
destroyStyle() {
if (this.styleElement) {
document.body.removeChild(this.styleElement);
this.styleElement = null;
}
} }
}, },
computed: { computed: {
@ -228,6 +267,9 @@ export default {
}, },
ariaLabelledById() { ariaLabelledById() {
return this.header != null ? this.ariaId + '_header' : null; return this.header != null ? this.ariaId + '_header' : null;
},
attributeSelector() {
return UniqueComponentId();
} }
}, },
directives: { directives: {

View File

@ -93,6 +93,14 @@ export default {
} }
} }
</code></pre>
<h5>Responsive</h5>
<p>ConfirmDialog width can be adjusted per screen size with the <i>breakpoints</i> option. In example below, default width is set to 50vw and below 961px, width would be 75vw and finally below 641px width becomes
100%. The value of <i>breakpoints</i> should be an object literal whose keys are the maximum screen sizes and values are the widths per screen.</p>
<pre v-code><code>
&lt;ConfirmDialog :breakpoints="{'960px': '75vw', '640px': '100vw'}" :style="{width: '50vw'}"&gt;&lt;/ConfirmDialog&gt;
</code></pre> </code></pre>
<h5>Confirmation Options</h5> <h5>Confirmation Options</h5>
@ -208,6 +216,12 @@ export default {
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Optional key to match the key of the confirmation, useful to target a specific confirm dialog instance.</td> <td>Optional key to match the key of the confirmation, useful to target a specific confirm dialog instance.</td>
</tr>
<tr>
<td>breakpoints</td>
<td>object</td>
<td>null</td>
<td>Object literal to define widths per screen size.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -56,6 +56,19 @@
</template> </template>
</Dialog> </Dialog>
<h5>Responsive</h5>
<Button label="Show" icon="pi pi-external-link" @click="openResponsive" />
<Dialog header="Header" v-model:visible="displayResponsive" :breakpoints="{'960px': '75vw'}" :style="{width: '50vw'}">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<template #footer>
<Button label="No" icon="pi pi-times" @click="closeResponsive" class="p-button-text"/>
<Button label="Yes" icon="pi pi-check" @click="closeResponsive" autofocus />
</template>
</Dialog>
<h5>Confirmation</h5> <h5>Confirmation</h5>
<Button label="Confirm" icon="pi pi-external-link" @click="openConfirmation" /> <Button label="Confirm" icon="pi pi-external-link" @click="openConfirmation" />
<Dialog header="Confirmation" v-model:visible="displayConfirmation" :style="{width: '350px'}" :modal="true"> <Dialog header="Confirmation" v-model:visible="displayConfirmation" :style="{width: '350px'}" :modal="true">
@ -124,6 +137,7 @@ export default {
displayBasic: false, displayBasic: false,
displayBasic2: false, displayBasic2: false,
displayModal: false, displayModal: false,
displayResponsive: false,
displayConfirmation: false, displayConfirmation: false,
displayMaximizable: false, displayMaximizable: false,
displayPosition: false, displayPosition: false,
@ -143,6 +157,12 @@ export default {
closeBasic2() { closeBasic2() {
this.displayBasic2 = false; this.displayBasic2 = false;
}, },
openResponsive() {
this.displayResponsive = true;
},
closeResponsive() {
this.displayResponsive = false;
},
openModal() { openModal() {
this.displayModal = true; this.displayModal = true;
}, },

View File

@ -62,10 +62,18 @@ export default {
</code></pre> </code></pre>
<h5>Popup Content inside the Dialog</h5> <h5>Responsive</h5>
<p>If the dialog contains components with popup elements such as Dropdown or Calendar, set <i>contentStyle</i> to overflow:visible so that overlays can be displayed outside of the content area.</p> <p>Dialog width can be adjusted per screen size with the <i>breakpoints</i> option. In example below, default width is set to 50vw and below 961px, width would be 75vw and finally below 641px width becomes
100%. The value of <i>breakpoints</i> should be an object literal whose keys are the maximum screen sizes and values are the widths per screen.</p>
<pre v-code><code> <pre v-code><code>
&lt;Dialog v-model:visible="display" :contentStyle="{overflow: 'visible'}"&gt; &lt;Dialog position="top" v-model:visible="display"&gt;
Content
&lt;/Dialog&gt;
</code></pre>
<pre v-code><code>
&lt;Dialog v-model:visible="display" :breakpoints="{'960px': '75vw', '640px': '100vw'}" :style="{width: '50vw'}"&gt;
Content Content
&lt;/Dialog&gt; &lt;/Dialog&gt;
@ -185,6 +193,12 @@ export default {
<td>boolean</td> <td>boolean</td>
<td>false</td> <td>false</td>
<td>Whether the dialog can be displayed full screen.</td> <td>Whether the dialog can be displayed full screen.</td>
</tr>
<tr>
<td>breakpoints</td>
<td>object</td>
<td>null</td>
<td>Object literal to define widths per screen size.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -313,6 +327,19 @@ export default {
&lt;/template&gt; &lt;/template&gt;
&lt;/Dialog&gt; &lt;/Dialog&gt;
&lt;h5&gt;Responsive&lt;/h5&gt;
&lt;Button label="Show" icon="pi pi-external-link" @click="openResponsive" /&gt;
&lt;Dialog header="Header" v-model:visible="displayResponsive" :breakpoints="{'960px': '75vw'}" :style="{width: '50vw'}"&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&lt;/p&gt;
&lt;template #footer&gt;
&lt;Button label="No" icon="pi pi-times" @click="closeResponsive" class="p-button-text"/&gt;
&lt;Button label="Yes" icon="pi pi-check" @click="closeResponsive" autofocus /&gt;
&lt;/template&gt;
&lt;/Dialog&gt;
&lt;h5&gt;Confirmation&lt;/h5&gt; &lt;h5&gt;Confirmation&lt;/h5&gt;
&lt;Button label="Confirm" icon="pi pi-external-link" @click="openConfirmation" /&gt; &lt;Button label="Confirm" icon="pi pi-external-link" @click="openConfirmation" /&gt;
&lt;Dialog header="Confirmation" v-model:visible="displayConfirmation" :style="{width: '350px'}" :modal="true"&gt; &lt;Dialog header="Confirmation" v-model:visible="displayConfirmation" :style="{width: '350px'}" :modal="true"&gt;
@ -375,6 +402,7 @@ export default {
displayBasic: false, displayBasic: false,
displayBasic2: false, displayBasic2: false,
displayModal: false, displayModal: false,
displayResponsive: false,
displayConfirmation: false, displayConfirmation: false,
displayMaximizable: false, displayMaximizable: false,
displayPosition: false, displayPosition: false,
@ -394,6 +422,12 @@ export default {
closeBasic2() { closeBasic2() {
this.displayBasic2 = false; this.displayBasic2 = false;
}, },
openResponsive() {
this.displayResponsive = true;
},
closeResponsive() {
this.displayResponsive = false;
},
openModal() { openModal() {
this.displayModal = true; this.displayModal = true;
}, },
@ -511,6 +545,19 @@ export default {
</template> </template>
</Dialog> </Dialog>
<h5>Responsive</h5>
<Button label="Show" icon="pi pi-external-link" @click="openResponsive" />
<Dialog header="Header" v-model:visible="displayResponsive" :breakpoints="{'960px': '75vw'}" :style="{width: '50vw'}">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<template #footer>
<Button label="No" icon="pi pi-times" @click="closeResponsive" class="p-button-text"/>
<Button label="Yes" icon="pi pi-check" @click="closeResponsive" autofocus />
</template>
</Dialog>
<h5>Confirmation</h5> <h5>Confirmation</h5>
<Button label="Confirm" icon="pi pi-external-link" @click="openConfirmation" /> <Button label="Confirm" icon="pi pi-external-link" @click="openConfirmation" />
<Dialog header="Confirmation" v-model:visible="displayConfirmation" :style="{width: '350px'}" :modal="true"> <Dialog header="Confirmation" v-model:visible="displayConfirmation" :style="{width: '350px'}" :modal="true">
@ -575,6 +622,7 @@ export default {
displayBasic: false, displayBasic: false,
displayBasic2: false, displayBasic2: false,
displayModal: false, displayModal: false,
displayResponsive: false,
displayConfirmation: false, displayConfirmation: false,
displayMaximizable: false, displayMaximizable: false,
displayPosition: false, displayPosition: false,
@ -594,6 +642,12 @@ export default {
closeBasic2() { closeBasic2() {
this.displayBasic2 = false; this.displayBasic2 = false;
}, },
openResponsive() {
this.displayResponsive = true;
},
closeResponsive() {
this.displayResponsive = false;
},
openModal() { openModal() {
this.displayModal = true; this.displayModal = true;
}, },