Skip to content

Commit

Permalink
Refactor #4103 - unstyled option updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Jul 7, 2023
1 parent 6c9b61a commit 0f0c9b9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
18 changes: 9 additions & 9 deletions components/lib/badgedirective/BadgeDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@ const BadgeDirective = BaseBadgeDirective.extend('badge', {
mounted(el, binding) {
const id = UniqueComponentId() + '_badge';

el.$_pbadgeUnstyled = binding.instance.$primevue.config.unstyled || binding.value?.unstyled || false;
el.unstyled = binding.instance.$primevue?.config?.unstyled || binding.value?.unstyled || false;

const badge = DomHandler.createElement('span', {
id,
class: !el.$_pbadgeUnstyled && this.cx('root'),
class: !el.unstyled && this.cx('root'),
'p-bind': this.ptm('root')
});

el.$_pbadgeId = badge.getAttribute('id');

for (let modifier in binding.modifiers) {
!el.$_pbadgeUnstyled && DomHandler.addClass(badge, 'p-badge-' + modifier);
!el.unstyled && DomHandler.addClass(badge, 'p-badge-' + modifier);
}

if (binding.value != null) {
if (typeof binding.value === 'object') el.$_badgeValue = binding.value.value;
else el.$_badgeValue = binding.value;
badge.appendChild(document.createTextNode(el.$_badgeValue));

if (String(el.$_badgeValue).length === 1 && !el.$_pbadgeUnstyled) {
!el.$_pbadgeUnstyled && DomHandler.addClass(badge, 'p-badge-no-gutter');
if (String(el.$_badgeValue).length === 1 && !el.unstyled) {
!el.unstyled && DomHandler.addClass(badge, 'p-badge-no-gutter');
}
} else {
!el.$_pbadgeUnstyled && DomHandler.addClass(badge, 'p-badge-dot');
!el.unstyled && DomHandler.addClass(badge, 'p-badge-dot');
}

!el.$_pbadgeUnstyled && DomHandler.addClass(el, 'p-overlay-badge');
!el.unstyled && DomHandler.addClass(el, 'p-overlay-badge');
el.setAttribute('data-p-overlay-badge', 'true');
el.appendChild(badge);

this.$el = badge;
},
updated(el, binding) {
!el.$_pbadgeUnstyled && DomHandler.addClass(el, 'p-overlay-badge');
!el.unstyled && DomHandler.addClass(el, 'p-overlay-badge');
el.setAttribute('data-p-overlay-badge', 'true');

if (binding.oldValue !== binding.value) {
Expand All @@ -47,7 +47,7 @@ const BadgeDirective = BaseBadgeDirective.extend('badge', {
if (typeof binding.value === 'object') el.$_badgeValue = binding.value.value;
else el.$_badgeValue = binding.value;

if (!el.$_pbadgeUnstyled) {
if (!el.unstyled) {
if (el.$_badgeValue) {
if (DomHandler.hasClass(badge, 'p-badge-dot')) DomHandler.removeClass(badge, 'p-badge-dot');

Expand Down
2 changes: 1 addition & 1 deletion components/lib/basedirective/BaseDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const BaseDirective = {
$css: { classes: undefined, inlineStyles: undefined, loadStyle: () => {}, ...options?.css },
/* computed instance variables */
defaultPT: config?.pt?.directives?.[name],
isUnstyled: config?.unstyled,
isUnstyled: el.unstyled !== undefined ? el.unstyled : config?.unstyled,
/* instance's methods */
ptm: (key = '', params = {}) => BaseDirective._getPTValue(el.$instance, el.$instance?.$binding?.value?.pt, key, { ...params }),
ptmo: (obj = {}, key = '', params = {}) => BaseDirective._getPTValue(el.$instance, obj, key, params, false),
Expand Down
12 changes: 6 additions & 6 deletions components/lib/ripple/Ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Ripple = BaseRipple.extend('ripple', {
const primevue = binding.instance.$primevue;

if (primevue && primevue.config && primevue.config.ripple) {
el.$_prippleUnstyled = primevue.config.unstyled || binding.value?.unstyled || false;
el.unstyled = primevue.config.unstyled || binding.value?.unstyled || false;

this.create(el);
this.bindEvents(el);
Expand All @@ -29,7 +29,7 @@ const Ripple = BaseRipple.extend('ripple', {
'aria-hidden': true,
'data-p-ink': true,
'data-p-ink-active': false,
class: !el.$_prippleUnstyled && this.cx('root'),
class: !el.unstyled && this.cx('root'),
onAnimationEnd: this.onAnimationEnd,
'p-bind': this.ptm('root')
});
Expand All @@ -55,7 +55,7 @@ const Ripple = BaseRipple.extend('ripple', {
return;
}

!target.$_prippleUnstyled && DomHandler.removeClass(ink, 'p-ink-active');
!target.unstyled && DomHandler.removeClass(ink, 'p-ink-active');
ink.setAttribute('data-p-ink-active', 'false');

if (!DomHandler.getHeight(ink) && !DomHandler.getWidth(ink)) {
Expand All @@ -72,12 +72,12 @@ const Ripple = BaseRipple.extend('ripple', {
ink.style.top = y + 'px';
ink.style.left = x + 'px';

!target.$_prippleUnstyled && DomHandler.addClass(ink, 'p-ink-active');
!target.unstyled && DomHandler.addClass(ink, 'p-ink-active');
ink.setAttribute('data-p-ink-active', 'true');

this.timeout = setTimeout(() => {
if (ink) {
!target.$_prippleUnstyled && DomHandler.removeClass(ink, 'p-ink-active');
!target.unstyled && DomHandler.removeClass(ink, 'p-ink-active');
ink.setAttribute('data-p-ink-active', 'false');
}
}, 401);
Expand All @@ -87,7 +87,7 @@ const Ripple = BaseRipple.extend('ripple', {
clearTimeout(this.timeout);
}

!event.currentTarget.$_prippleUnstyled && DomHandler.removeClass(event.currentTarget, 'p-ink-active');
!event.currentTarget.unstyled && DomHandler.removeClass(event.currentTarget, 'p-ink-active');
event.currentTarget.setAttribute('data-p-ink-active', 'false');
},
getInk(el) {
Expand Down
14 changes: 7 additions & 7 deletions components/lib/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const Tooltip = BaseTooltip.extend('tooltip', {
}
}

target.$_ptooltipZIndex = options.instance.$primevue.config?.zIndex?.tooltip;
target.$_ptooltipUnstyled = options.instance.$primevue.config?.unstyled || options.value?.unstyled || false;
target.$_ptooltipZIndex = options.instance.$primevue?.config?.zIndex?.tooltip;
target.unstyled = options.instance.$primevue?.config?.unstyled || options.value?.unstyled || false;

this.bindEvents(target, options);
},
Expand Down Expand Up @@ -75,7 +75,7 @@ const Tooltip = BaseTooltip.extend('tooltip', {
}
}

target.$_ptooltipUnstyled = options.instance.$primevue.config?.unstyled || options.value?.unstyled || false;
target.unstyled = options.instance.$primevue?.config?.unstyled || options.value?.unstyled || false;
},
unmounted(el, options) {
let target = this.getTarget(el);
Expand Down Expand Up @@ -184,7 +184,7 @@ const Tooltip = BaseTooltip.extend('tooltip', {
let tooltipElement = this.create(el, options);

this.align(el);
!el.$_ptooltipUnstyled && DomHandler.fadeIn(tooltipElement, 250);
!el.unstyled && DomHandler.fadeIn(tooltipElement, 250);

const $this = this;

Expand Down Expand Up @@ -224,12 +224,12 @@ const Tooltip = BaseTooltip.extend('tooltip', {
},
create(el, options) {
const tooltipArrow = DomHandler.createElement('div', {
class: !el.$_ptooltipUnstyled && this.cx('arrow'),
class: !el.unstyled && this.cx('arrow'),
'p-bind': this.ptm('arrow')
});

const tooltipText = DomHandler.createElement('div', {
class: !el.$_ptooltipUnstyled && this.cx('text'),
class: !el.unstyled && this.cx('text'),
'p-bind': this.ptm('text')
});

Expand All @@ -249,7 +249,7 @@ const Tooltip = BaseTooltip.extend('tooltip', {
display: 'inline-block',
width: el.$_ptooltipFitContent ? 'fit-content' : undefined
},
class: [!el.$_ptooltipUnstyled && this.cx('root'), el.$_ptooltipClass],
class: [!el.unstyled && this.cx('root'), el.$_ptooltipClass],
'p-bind': this.ptm('root')
},
tooltipArrow,
Expand Down

0 comments on commit 0f0c9b9

Please sign in to comment.