Skip to content

Commit 21c773d

Browse files
authored
Merge pull request #6656 from nextcloud-libraries/chore/boolean-v11
feat: add boolean prop alternatives with false as default value
2 parents ceead85 + 875a256 commit 21c773d

File tree

4 files changed

+73
-11
lines changed

4 files changed

+73
-11
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
## UNRELEASED
99

1010
### 📝 Notes
11+
#### Boolean properties
12+
Some boolean props have been deprecated in favor of alternatives with default value `false`.
13+
This allows to use shorthand notation on the template, as a prop with a default value of `false`
14+
will be set to `true` if it is set (without any value) in the template,
15+
similar to native HTML boolean attributes.
16+
Following components have been adjusted:
17+
18+
| Component | Deprecated prop | New alternative |
19+
|---------------|-------------------------|-----------------|
20+
| `NcAvatar` | `showUserStatus` | `hideStatus` |
21+
| `NcAvatar` | `showUserStatusCompact` | `verboseStatus` |
22+
| `NcModal` | `canClose` | `noClose` |
23+
| `NcDialog` | `canClose` | `noClose` |
24+
1125
#### `NcButton` color variant and native type
1226
`NcButton` (and `NcDialogButton`) now provides a `variant` prop to set the color variant to use (e.g. `'primary'`) and allows to set the native button type using the `type` prop.
1327
The legacy behavior, `type` for the color variant and `nativeType` for the button type, still works but will be removed in the next major version.

src/components/NcAvatar/NcAvatar.vue

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,30 @@ export default {
318318
default: undefined,
319319
},
320320
/**
321-
* Whether or not to display the user-status
321+
* Do not show the user status on the avatar.
322+
*/
323+
hideStatus: {
324+
type: Boolean,
325+
default: false,
326+
},
327+
/**
328+
* Whether or not to display the user-status.
329+
* @deprecated - Use `hideStatus` instead. Will be removed with v9.
322330
*/
323331
showUserStatus: {
324332
type: Boolean,
325333
default: true,
326334
},
335+
/**
336+
* Show the verbose user status (e.g. "online" / "away") instead of just the status icon.
337+
*/
338+
verboseStatus: {
339+
type: Boolean,
340+
default: false,
341+
},
327342
/**
328343
* Whether or not to the status-icon should be used instead of online/away
344+
* @deprecated - Use `verboseStatus` instead. Will be removed with v9.
329345
*/
330346
showUserStatusCompact: {
331347
type: Boolean,
@@ -365,7 +381,15 @@ export default {
365381
default: 32,
366382
},
367383
/**
368-
* Placeholder avatars will be automatically generated when this is set to true
384+
* Do not automatically generate a placeholder avatars if there is no real avatar is available.
385+
*/
386+
noPlaceholder: {
387+
type: Boolean,
388+
default: false,
389+
},
390+
/**
391+
* Placeholder avatars will be automatically generated when this is set to true.
392+
* @deprecated - Use `noPlaceholder` instead. Will be removed in v9.
369393
*/
370394
allowPlaceholder: {
371395
type: Boolean,
@@ -439,12 +463,15 @@ export default {
439463
return t('Avatar of {displayName}', { displayName: this.displayName ?? this.user })
440464
},
441465
canDisplayUserStatus() {
442-
return this.showUserStatus
466+
return !this.hideStatus
467+
&& this.showUserStatus
443468
&& this.hasStatus
444469
&& ['online', 'away', 'busy', 'dnd'].includes(this.userStatus.status)
445470
},
446471
showUserStatusIconOnAvatar() {
447-
return this.showUserStatus
472+
return !this.hideStatus
473+
&& this.showUserStatus
474+
&& !this.verboseStatus
448475
&& this.showUserStatusCompact
449476
&& this.hasStatus
450477
&& this.userStatus.status !== 'dnd'
@@ -486,7 +513,7 @@ export default {
486513
* True if initials should be shown as the user icon fallback
487514
*/
488515
showInitials() {
489-
return this.allowPlaceholder && this.userDoesNotExist && !(this.iconClass || this.$slots.icon)
516+
return !this.noPlaceholder && this.allowPlaceholder && this.userDoesNotExist && !(this.iconClass || this.$slots.icon)
490517
},
491518
492519
avatarStyle() {

src/components/NcDialog/NcDialog.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,18 @@ export default defineComponent({
342342
validator: (value) => Array.isArray(value) && value.every((element) => typeof element === 'object'),
343343
},
344344
345+
/**
346+
* Do not show the close button for the dialog.
347+
* @default false
348+
*/
349+
noClose: {
350+
type: Boolean,
351+
default: false,
352+
},
353+
345354
/**
346355
* Set to false to no show a close button on the dialog
356+
* @deprecated - Use `noClose` instead. Will be removed in v9.
347357
* @default true
348358
*/
349359
canClose: {
@@ -578,7 +588,7 @@ export default defineComponent({
578588
* Properties to pass to the underlying NcModal
579589
*/
580590
const modalProps = computed(() => ({
581-
canClose: props.canClose,
591+
noClose: props.noClose || !props.canClose,
582592
container: props.container === undefined ? 'body' : props.container,
583593
// we do not pass the name as we already have the name as the headline
584594
// name: props.name,

src/components/NcModal/NcModal.vue

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export default {
258258
</NcActions>
259259

260260
<!-- Close modal -->
261-
<NcButton v-if="canClose && !closeButtonContained"
261+
<NcButton v-if="!noClose && canClose && !closeButtonContained"
262262
:aria-label="closeButtonAriaLabel"
263263
class="header-close"
264264
variant="tertiary"
@@ -300,7 +300,7 @@ export default {
300300
<slot />
301301
</div>
302302
<!-- Close modal -->
303-
<NcButton v-if="canClose && closeButtonContained"
303+
<NcButton v-if="!noClose && canClose && closeButtonContained"
304304
:aria-label="closeButtonAriaLabel"
305305
class="modal-container__close"
306306
variant="tertiary"
@@ -451,7 +451,18 @@ export default {
451451
},
452452
453453
/**
454-
* Declare if the modal can be closed
454+
* Do not show the close button for the dialog.
455+
* @default false
456+
*/
457+
noClose: {
458+
type: Boolean,
459+
default: false,
460+
},
461+
462+
/**
463+
* Set to false to no show a close button on the dialog
464+
* @deprecated - Use `noClose` instead. Will be removed in v9.
465+
* @default true
455466
*/
456467
canClose: {
457468
type: Boolean,
@@ -575,7 +586,7 @@ export default {
575586
* True if there are any buttons shown on the backdrop or a name (for accessibility)
576587
*/
577588
forceDarkBackdrop() {
578-
return (this.canClose && !this.closeButtonContained)
589+
return (!this.noClose && this.canClose && !this.closeButtonContained)
579590
|| this.hasNext
580591
|| this.hasPrevious
581592
|| this.modalName !== ''
@@ -703,7 +714,7 @@ export default {
703714
},
704715
close(data) {
705716
// do not fire event if forbidden
706-
if (this.canClose) {
717+
if (!this.noClose && this.canClose) {
707718
// We set internalShow here, so the out transitions properly run before the component is destroyed
708719
this.internalShow = false
709720
this.$emit('update:show', false)

0 commit comments

Comments
 (0)