Skip to content

Commit

Permalink
Refactor #3965 - For Fieldset
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed May 16, 2023
1 parent f80ed41 commit 987bf9c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 28 deletions.
48 changes: 20 additions & 28 deletions components/lib/fieldset/Fieldset.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<fieldset :class="['p-fieldset p-component', { 'p-fieldset-toggleable': toggleable }]" v-bind="ptm('root')">
<legend class="p-fieldset-legend" v-bind="ptm('legend')">
<fieldset :class="classes.root" v-bind="ptm('root')">
<legend :class="classes.legend" v-bind="ptm('legend')">
<slot v-if="!toggleable" name="legend">
<span :id="ariaId + '_header'" class="p-fieldset-legend-text" v-bind="ptm('legendtitle')">{{ legend }}</span>
<span :id="ariaId + '_header'" :class="classes.legendtitle" v-bind="ptm('legendtitle')">{{ legend }}</span>
</slot>
<a
v-if="toggleable"
Expand All @@ -18,16 +18,16 @@
v-bind="{ ...toggleButtonProps, ...ptm('toggler') }"
>
<slot name="togglericon" :collapsed="d_collapsed">
<component :is="d_collapsed ? 'PlusIcon' : 'MinusIcon'" class="p-fieldset-toggler" v-bind="ptm('togglericon')" />
<component :is="d_collapsed ? 'PlusIcon' : 'MinusIcon'" :class="classes.togglericon" v-bind="ptm('togglericon')" />
</slot>
<slot name="legend">
<span class="p-fieldset-legend-text" v-bind="ptm('legendtitle')">{{ legend }}</span>
<span :class="classes.legendtitle" v-bind="ptm('legendtitle')">{{ legend }}</span>
</slot>
</a>
</legend>
<transition name="p-toggleable-content">
<div v-show="!d_collapsed" :id="ariaId + '_content'" class="p-toggleable-content" role="region" :aria-labelledby="ariaId + '_header'" v-bind="ptm('toggleablecontent')">
<div class="p-fieldset-content" v-bind="ptm('content')">
<div v-show="!d_collapsed" :id="ariaId + '_content'" :class="classes.toggleablecontent" role="region" :aria-labelledby="ariaId + '_header'" v-bind="ptm('toggleablecontent')">
<div :class="classes.content" v-bind="ptm('content')">
<slot></slot>
</div>
</div>
Expand All @@ -40,7 +40,11 @@ import BaseComponent from 'primevue/basecomponent';
import MinusIcon from 'primevue/icons/minus';
import PlusIcon from 'primevue/icons/plus';
import Ripple from 'primevue/ripple';
import { useStyle } from 'primevue/usestyle';
import { UniqueComponentId } from 'primevue/utils';
import { getComputedClasses, styles } from './FieldsetStyle';
const styleInstance = useStyle(styles, { id: 'primevue_fieldset_style', manual: true });
export default {
name: 'Fieldset',
Expand All @@ -63,6 +67,12 @@ export default {
watch: {
collapsed(newValue) {
this.d_collapsed = newValue;
},
isUnstyled: {
immediate: true,
handler(newValue) {
!newValue && styleInstance.load();
}
}
},
methods: {
Expand All @@ -87,6 +97,9 @@ export default {
},
buttonAriaLabel() {
return this.toggleButtonProps && this.toggleButtonProps['aria-label'] ? this.toggleButtonProps['aria-label'] : this.legend;
},
classes() {
return this.isUnstyled ? {} : getComputedClasses(this.$props, this.$data);
}
},
directives: {
Expand All @@ -98,24 +111,3 @@ export default {
}
};
</script>

<style>
.p-fieldset-legend > a,
.p-fieldset-legend > span {
display: flex;
align-items: center;
justify-content: center;
}
.p-fieldset-toggleable .p-fieldset-legend a {
cursor: pointer;
user-select: none;
overflow: hidden;
position: relative;
text-decoration: none;
}
.p-fieldset-legend-text {
line-height: 1;
}
</style>
30 changes: 30 additions & 0 deletions components/lib/fieldset/FieldsetStyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const styles = `
.p-fieldset-legend > a,
.p-fieldset-legend > span {
display: flex;
align-items: center;
justify-content: center;
}
.p-fieldset-toggleable .p-fieldset-legend a {
cursor: pointer;
user-select: none;
overflow: hidden;
position: relative;
text-decoration: none;
}
.p-fieldset-legend-text {
line-height: 1;
}
`;

export const getComputedClasses = (props, states) => ({
root: ['p-fieldset p-component', { 'p-fieldset-toggleable': props.toggleable }],
legend: 'p-fieldset-legend',
legendtitle: 'p-fieldset-legend-text',
togglericon: 'p-fieldset-toggler',
legendtitle: 'p-fieldset-legend-text',
toggleablecontent: 'p-toggleable-content',
content: 'p-fieldset-content'
});

0 comments on commit 987bf9c

Please sign in to comment.