Skip to content

Commit

Permalink
Refactor #5553 - For Inplace
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Apr 9, 2024
1 parent 014dc68 commit 6b605f6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 106 deletions.
12 changes: 1 addition & 11 deletions api-generator/components/inplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ const InplaceProps = [
description: 'Whether the content is displayed or not.'
},
{
name: 'closable',
type: 'boolean',
default: 'false',
description: 'Displays a button to switch back to display mode.'
},
{
name: 'diabled',
name: 'disabled',
type: 'boolean',
default: 'false',
description: 'When present, it specifies that the element should be disabled.'
Expand Down Expand Up @@ -64,10 +58,6 @@ const InplaceSlots = [
{
name: 'content',
description: 'Custom content template.'
},
{
name: 'closeicon',
description: 'Custom close icon template.'
}
];

Expand Down
12 changes: 0 additions & 12 deletions components/lib/inplace/BaseInplace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ export default {
name: 'BaseInplace',
extends: BaseComponent,
props: {
closable: {
type: Boolean,
default: false
},
active: {
type: Boolean,
default: false
Expand All @@ -18,17 +14,9 @@ export default {
type: Boolean,
default: false
},
closeIcon: {
type: String,
default: undefined
},
displayProps: {
type: null,
default: null
},
closeButtonProps: {
type: null,
default: null
}
},
style: InplaceStyle,
Expand Down
31 changes: 9 additions & 22 deletions components/lib/inplace/Inplace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
*
*/

import { ButtonHTMLAttributes, HTMLAttributes, VNode } from 'vue';
import { HTMLAttributes, VNode } from 'vue';
import { ComponentHooks } from '../basecomponent';
import { ButtonPassThroughOptions } from '../button';
import { PassThroughOptions } from '../passthrough';
import { ClassComponent, DesignToken, GlobalComponentConstructor, PassThrough } from '../ts-helpers';

Expand Down Expand Up @@ -77,11 +76,6 @@ export interface InplacePassThroughOptions {
* Used to pass attributes to the content's DOM element.
*/
content?: InplacePassThroughOptionType;
/**
* Used to pass attributes to the Button component.
* @see {@link ButtonPassThroughOptions}
*/
closeButton?: ButtonPassThroughOptions<InplaceSharedPassThroughMethodOptions>;
/**
* Used to manage all lifecycle hooks.
* @see {@link BaseComponent.ComponentHooks}
Expand Down Expand Up @@ -111,11 +105,6 @@ export interface InplaceState {
* Defines valid properties in Inplace component.
*/
export interface InplaceProps {
/**
* Displays a button to switch back to display mode.
* @defaultValue false
*/
closable?: boolean | undefined;
/**
* Whether the content is displayed or not.
* @defaultValue false
Expand All @@ -135,10 +124,6 @@ export interface InplaceProps {
* Used to pass all properties of the HTMLDivElement to display container.
*/
displayProps?: HTMLAttributes | undefined;
/**
* Used to pass all properties of the HTMLButtonElement to the close button.
*/
closeButtonProps?: ButtonHTMLAttributes | undefined;
/**
* It generates scoped CSS variables using design tokens for the component.
*/
Expand Down Expand Up @@ -170,12 +155,14 @@ export interface InplaceSlots {
display(): VNode[];
/**
* Custom content template.
*/
content(): VNode[];
/**
* Custom close icon template.
*/
closeicon(): VNode[];
* @param {Object} scope - container slot's params.
*/
content(scope: {
/**
* Close message function.
*/
closeCallback: () => void;
}): VNode[];
}

/**
Expand Down
33 changes: 7 additions & 26 deletions components/lib/inplace/Inplace.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
<template>
<div v-focustrap :class="cx('root')" aria-live="polite" v-bind="ptmi('root')">
<div :class="cx('root')" aria-live="polite" v-bind="ptmi('root')">
<div v-if="!d_active" ref="display" :class="cx('display')" :tabindex="$attrs.tabindex || '0'" role="button" @click="open" @keydown.enter="open" v-bind="{ ...displayProps, ...ptm('display') }">
<slot name="display"></slot>
</div>
<div v-else :class="cx('content')" v-bind="ptm('content')">
<slot name="content"></slot>
<IPButton v-if="closable" :aria-label="closeAriaLabel" @click="close" :unstyled="unstyled" :pt="ptm('closeButton')" v-bind="closeButtonProps">
<template #icon>
<slot name="closeicon">
<component :is="closeIcon ? 'span' : 'TimesIcon'" :class="closeIcon" v-bind="ptm('closeButton')['icon']" data-pc-section="closebuttonicon"></component>
</slot>
</template>
</IPButton>
<slot name="content" :closeCallback="close" />
</div>
</div>
</template>

<script>
import Button from 'primevue/button';
import FocusTrap from 'primevue/focustrap';
import TimesIcon from 'primevue/icons/times';
import BaseInplace from './BaseInplace.vue';
export default {
Expand All @@ -43,30 +33,21 @@ export default {
return;
}
this.$emit('open', event);
this.d_active = true;
this.$emit('open', event);
this.$emit('update:active', true);
},
close(event) {
this.$emit('close', event);
this.d_active = false;
this.$emit('close', event);
this.$emit('update:active', false);
setTimeout(() => {
this.$refs.display.focus();
}, 0);
}
},
computed: {
closeAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.close : undefined;
}
},
components: {
IPButton: Button,
TimesIcon
},
directives: {
focustrap: FocusTrap
}
};
</script>
2 changes: 1 addition & 1 deletion components/lib/inplace/style/InplaceStyle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BaseStyle from 'primevue/base/style';

const classes = {
root: ({ props }) => 'p-inplace p-component',
root: 'p-inplace p-component',
display: ({ props }) => ['p-inplace-display', { 'p-disabled': props.disabled }],
content: 'p-inplace-content'
};
Expand Down
34 changes: 0 additions & 34 deletions doc/inplace/AccessibilityDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
<DocSectionText id="accessibility" label="Accessibility" v-bind="$attrs">
<h3>Screen Reader</h3>
<p>Inplace component defines <i>aria-live</i> as "polite" by default, since any valid attribute is passed to the main container aria roles and attributes of the root element can be customized easily.</p>
<p>
Display element uses <i>button</i> role in view mode by default, <i>displayProps</i> can be used for customizations like adding <i>aria-label</i> or <i>aria-labelledby</i> attributes to describe the content of the view mode or even
overriding the default role.
</p>
<p>
Closable inplace components displays a button with an <i>aria-label</i> that refers to the <i>aria.close</i> property of the <NuxtLink to="/configuration/#locale">locale</NuxtLink> API by default, you may use <i>closeButtonProps</i> to
customize the element and override the default <i>aria-label</i>.
</p>

<h3>View Mode Keyboard Support</h3>
<div class="doc-tablewrapper">
Expand All @@ -30,31 +22,5 @@
</tbody>
</table>
</div>

<h3>Close Button Keyboard Support</h3>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Key</th>
<th>Function</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<i>enter</i>
</td>
<td>Switches to display.</td>
</tr>
<tr>
<td>
<i>space</i>
</td>
<td>Switches to display.</td>
</tr>
</tbody>
</table>
</div>
</DocSectionText>
</template>

0 comments on commit 6b605f6

Please sign in to comment.