refactor: update itemRender & dropdownRender
parent
06c8623db0
commit
f34a5d962f
|
@ -1 +1 @@
|
||||||
Subproject commit a71e2eac4c9b38092fc8edd2282bdd91170fa04b
|
Subproject commit fce7a2bab42ec55d7cc8b7414336249c3dbf91c5
|
|
@ -32,7 +32,7 @@ export const PaginationProps = () => ({
|
||||||
locale: PropTypes.object,
|
locale: PropTypes.object,
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
selectPrefixCls: PropTypes.string,
|
selectPrefixCls: PropTypes.string,
|
||||||
itemRender: PropTypes.any,
|
itemRender: PropTypes.func,
|
||||||
role: PropTypes.string,
|
role: PropTypes.string,
|
||||||
showLessItems: PropTypes.bool,
|
showLessItems: PropTypes.bool,
|
||||||
});
|
});
|
||||||
|
@ -116,6 +116,7 @@ export default {
|
||||||
buildOptionText: buildOptionText || this.$slots.buildOptionText,
|
buildOptionText: buildOptionText || this.$slots.buildOptionText,
|
||||||
...this.$attrs,
|
...this.$attrs,
|
||||||
class: classNames({ mini: isSmall }, this.$attrs.class),
|
class: classNames({ mini: isSmall }, this.$attrs.class),
|
||||||
|
itemRender: this.itemRender || this.$slots.itemRender,
|
||||||
};
|
};
|
||||||
|
|
||||||
return <VcPagination {...paginationProps} />;
|
return <VcPagination {...paginationProps} />;
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default {
|
||||||
class={cls}
|
class={cls}
|
||||||
style={style}
|
style={style}
|
||||||
>
|
>
|
||||||
{this.itemRender(this.page, 'page', <a>{this.page}</a>)}
|
{this.itemRender({ page: this.page, type: 'page', originalElement: <a>{this.page}</a> })}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,8 +14,8 @@ function isInteger(value) {
|
||||||
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
|
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultItemRender(page, type, element) {
|
function defaultItemRender({ originalElement }) {
|
||||||
return element;
|
return originalElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculatePage(p, state, props) {
|
function calculatePage(p, state, props) {
|
||||||
|
@ -52,7 +52,7 @@ export default {
|
||||||
showTotal: PropTypes.func,
|
showTotal: PropTypes.func,
|
||||||
simple: PropTypes.bool,
|
simple: PropTypes.bool,
|
||||||
locale: PropTypes.object.def(LOCALE),
|
locale: PropTypes.object.def(LOCALE),
|
||||||
itemRender: PropTypes.func.def(defaultItemRender),
|
itemRender: PropTypes.func,
|
||||||
prevIcon: PropTypes.any,
|
prevIcon: PropTypes.any,
|
||||||
nextIcon: PropTypes.any,
|
nextIcon: PropTypes.any,
|
||||||
jumpPrevIcon: PropTypes.any,
|
jumpPrevIcon: PropTypes.any,
|
||||||
|
@ -315,6 +315,7 @@ export default {
|
||||||
if (this.hideOnSinglePage === true && this.total <= this.statePageSize) {
|
if (this.hideOnSinglePage === true && this.total <= this.statePageSize) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const itemRender = this.itemRender || defaultItemRender;
|
||||||
const props = this.$props;
|
const props = this.$props;
|
||||||
const locale = this.locale;
|
const locale = this.locale;
|
||||||
|
|
||||||
|
@ -368,7 +369,11 @@ export default {
|
||||||
class={`${hasPrev ? '' : `${prefixCls}-disabled`} ${prefixCls}-prev`}
|
class={`${hasPrev ? '' : `${prefixCls}-disabled`} ${prefixCls}-prev`}
|
||||||
aria-disabled={!this.hasPrev()}
|
aria-disabled={!this.hasPrev()}
|
||||||
>
|
>
|
||||||
{this.itemRender(prevPage, 'prev', this.getItemIcon('prevIcon'))}
|
{itemRender({
|
||||||
|
page: prevPage,
|
||||||
|
type: 'prev',
|
||||||
|
originalElement: this.getItemIcon('prevIcon'),
|
||||||
|
})}
|
||||||
</li>
|
</li>
|
||||||
<li
|
<li
|
||||||
title={this.showTitle ? `${stateCurrent}/${allPages}` : null}
|
title={this.showTitle ? `${stateCurrent}/${allPages}` : null}
|
||||||
|
@ -394,7 +399,11 @@ export default {
|
||||||
class={`${hasNext ? '' : `${prefixCls}-disabled`} ${prefixCls}-next`}
|
class={`${hasNext ? '' : `${prefixCls}-disabled`} ${prefixCls}-next`}
|
||||||
aria-disabled={!this.hasNext()}
|
aria-disabled={!this.hasNext()}
|
||||||
>
|
>
|
||||||
{this.itemRender(nextPage, 'next', this.getItemIcon('nextIcon'))}
|
{itemRender({
|
||||||
|
page: nextPage,
|
||||||
|
type: 'next',
|
||||||
|
originalElement: this.getItemIcon('nextIcon'),
|
||||||
|
})}
|
||||||
</li>
|
</li>
|
||||||
{gotoButton}
|
{gotoButton}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -405,7 +414,7 @@ export default {
|
||||||
locale,
|
locale,
|
||||||
rootPrefixCls: prefixCls,
|
rootPrefixCls: prefixCls,
|
||||||
showTitle: props.showTitle,
|
showTitle: props.showTitle,
|
||||||
itemRender: props.itemRender,
|
itemRender,
|
||||||
onClick: this.handleChange,
|
onClick: this.handleChange,
|
||||||
onKeypress: this.runIfEnter,
|
onKeypress: this.runIfEnter,
|
||||||
};
|
};
|
||||||
|
@ -435,7 +444,11 @@ export default {
|
||||||
onKeypress={this.runIfEnterJumpPrev}
|
onKeypress={this.runIfEnterJumpPrev}
|
||||||
class={jumpPrevClassString}
|
class={jumpPrevClassString}
|
||||||
>
|
>
|
||||||
{this.itemRender(this.getJumpPrevPage(), 'jump-prev', this.getItemIcon('jumpPrevIcon'))}
|
{itemRender({
|
||||||
|
page: this.getJumpPrevPage(),
|
||||||
|
type: 'jump-prev',
|
||||||
|
originalElement: this.getItemIcon('jumpPrevIcon'),
|
||||||
|
})}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
let jumpNextClassString = `${prefixCls}-jump-next`;
|
let jumpNextClassString = `${prefixCls}-jump-next`;
|
||||||
|
@ -451,7 +464,11 @@ export default {
|
||||||
onKeypress={this.runIfEnterJumpNext}
|
onKeypress={this.runIfEnterJumpNext}
|
||||||
class={jumpNextClassString}
|
class={jumpNextClassString}
|
||||||
>
|
>
|
||||||
{this.itemRender(this.getJumpNextPage(), 'jump-next', this.getItemIcon('jumpNextIcon'))}
|
{itemRender({
|
||||||
|
page: this.getJumpNextPage(),
|
||||||
|
type: 'jump-next',
|
||||||
|
originalElement: this.getItemIcon('jumpNextIcon'),
|
||||||
|
})}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -467,7 +484,7 @@ export default {
|
||||||
page={allPages}
|
page={allPages}
|
||||||
active={false}
|
active={false}
|
||||||
showTitle={this.showTitle}
|
showTitle={this.showTitle}
|
||||||
itemRender={this.itemRender}
|
itemRender={itemRender}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
firstPager = (
|
firstPager = (
|
||||||
|
@ -480,7 +497,7 @@ export default {
|
||||||
page={1}
|
page={1}
|
||||||
active={false}
|
active={false}
|
||||||
showTitle={this.showTitle}
|
showTitle={this.showTitle}
|
||||||
itemRender={this.itemRender}
|
itemRender={itemRender}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -507,7 +524,7 @@ export default {
|
||||||
page={i}
|
page={i}
|
||||||
active={active}
|
active={active}
|
||||||
showTitle={this.showTitle}
|
showTitle={this.showTitle}
|
||||||
itemRender={this.itemRender}
|
itemRender={itemRender}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -524,7 +541,7 @@ export default {
|
||||||
class={`${prefixCls}-item-after-jump-prev`}
|
class={`${prefixCls}-item-after-jump-prev`}
|
||||||
active={false}
|
active={false}
|
||||||
showTitle={this.showTitle}
|
showTitle={this.showTitle}
|
||||||
itemRender={this.itemRender}
|
itemRender={itemRender}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
pagerList.unshift(jumpPrev);
|
pagerList.unshift(jumpPrev);
|
||||||
|
@ -541,7 +558,7 @@ export default {
|
||||||
class={`${prefixCls}-item-before-jump-next`}
|
class={`${prefixCls}-item-before-jump-next`}
|
||||||
active={false}
|
active={false}
|
||||||
showTitle={this.showTitle}
|
showTitle={this.showTitle}
|
||||||
itemRender={this.itemRender}
|
itemRender={itemRender}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
pagerList.push(jumpNext);
|
pagerList.push(jumpNext);
|
||||||
|
@ -589,7 +606,11 @@ export default {
|
||||||
class={`${!prevDisabled ? '' : `${prefixCls}-disabled`} ${prefixCls}-prev`}
|
class={`${!prevDisabled ? '' : `${prefixCls}-disabled`} ${prefixCls}-prev`}
|
||||||
aria-disabled={prevDisabled}
|
aria-disabled={prevDisabled}
|
||||||
>
|
>
|
||||||
{this.itemRender(prevPage, 'prev', this.getItemIcon('prevIcon'))}
|
{itemRender({
|
||||||
|
page: prevPage,
|
||||||
|
type: 'prev',
|
||||||
|
originalElement: this.getItemIcon('prevIcon'),
|
||||||
|
})}
|
||||||
</li>
|
</li>
|
||||||
{pagerList}
|
{pagerList}
|
||||||
<li
|
<li
|
||||||
|
@ -600,7 +621,11 @@ export default {
|
||||||
class={`${!nextDisabled ? '' : `${prefixCls}-disabled`} ${prefixCls}-next`}
|
class={`${!nextDisabled ? '' : `${prefixCls}-disabled`} ${prefixCls}-next`}
|
||||||
aria-disabled={nextDisabled}
|
aria-disabled={nextDisabled}
|
||||||
>
|
>
|
||||||
{this.itemRender(nextPage, 'next', this.getItemIcon('nextIcon'))}
|
{itemRender({
|
||||||
|
page: nextPage,
|
||||||
|
type: 'next',
|
||||||
|
originalElement: this.getItemIcon('nextIcon'),
|
||||||
|
})}
|
||||||
</li>
|
</li>
|
||||||
<Options
|
<Options
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|
|
@ -98,7 +98,7 @@ const Select = {
|
||||||
tokenSeparators: PropTypes.arrayOf(PropTypes.string).def([]),
|
tokenSeparators: PropTypes.arrayOf(PropTypes.string).def([]),
|
||||||
autoClearSearchValue: PropTypes.bool.def(true),
|
autoClearSearchValue: PropTypes.bool.def(true),
|
||||||
tabindex: PropTypes.any.def(0),
|
tabindex: PropTypes.any.def(0),
|
||||||
dropdownRender: PropTypes.func.def(menu => menu),
|
dropdownRender: PropTypes.func.def(({ menuNode }) => menuNode),
|
||||||
// onChange: noop,
|
// onChange: noop,
|
||||||
// onFocus: noop,
|
// onFocus: noop,
|
||||||
// onBlur: noop,
|
// onBlur: noop,
|
||||||
|
|
|
@ -131,7 +131,7 @@ export default {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (dropdownRender) {
|
if (dropdownRender) {
|
||||||
return dropdownRender(menuNode, props);
|
return dropdownRender({ menuNode, props });
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import demo from '../antdv-demo/docs/mentions/demo/form';
|
import demo from '../antdv-demo/docs/select/demo/custom-dropdown-menu';
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
demo,
|
demo,
|
||||||
|
|
Loading…
Reference in New Issue