You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/vc-pagination/Options.jsx

154 lines
3.8 KiB

import PropTypes from '../_util/vue-types';
import KEYCODE from './KeyCode';
import BaseMixin from '../_util/BaseMixin';
7 years ago
export default {
mixins: [BaseMixin],
7 years ago
props: {
disabled: PropTypes.bool,
changeSize: PropTypes.func,
quickGo: PropTypes.func,
selectComponentClass: PropTypes.any,
7 years ago
current: PropTypes.number,
pageSizeOptions: PropTypes.array.def(['10', '20', '30', '40']),
pageSize: PropTypes.number,
buildOptionText: PropTypes.func,
7 years ago
locale: PropTypes.object,
rootPrefixCls: PropTypes.string,
selectPrefixCls: PropTypes.string,
goButton: PropTypes.any,
7 years ago
},
data() {
7 years ago
return {
goInputText: '',
};
7 years ago
},
methods: {
getValidValue() {
const { goInputText, current } = this;
return isNaN(goInputText) ? current : Number(goInputText);
},
defaultBuildOptionText(opt) {
return `${opt.value} ${this.locale.items_per_page}`;
7 years ago
},
handleChange(e) {
this.setState({
goInputText: e.target.value,
});
7 years ago
},
handleBlur() {
const { goButton, quickGo } = this;
if (goButton) {
return;
}
quickGo(this.getValidValue());
},
go(e) {
const { goInputText } = this;
if (goInputText === '') {
return;
7 years ago
}
if (e.keyCode === KEYCODE.ENTER || e.type === 'click') {
// https://github.com/vueComponent/ant-design-vue/issues/1316
this.quickGo(this.getValidValue());
this.setState({
goInputText: '',
});
7 years ago
}
},
},
render() {
const {
rootPrefixCls,
locale,
changeSize,
quickGo,
goButton,
selectComponentClass: Select,
defaultBuildOptionText,
selectPrefixCls,
pageSize,
pageSizeOptions,
goInputText,
disabled,
} = this;
const prefixCls = `${rootPrefixCls}-options`;
let changeSelect = null;
let goInput = null;
let gotoButton = null;
7 years ago
if (!changeSize && !quickGo) {
return null;
7 years ago
}
if (changeSize && Select) {
const buildOptionText = this.buildOptionText || defaultBuildOptionText;
const options = pageSizeOptions.map((opt, i) => (
<Select.Option key={i} value={opt}>
{buildOptionText({ value: opt })}
</Select.Option>
));
7 years ago
changeSelect = (
<Select
disabled={disabled}
prefixCls={selectPrefixCls}
7 years ago
showSearch={false}
class={`${prefixCls}-size-changer`}
optionLabelProp="children"
7 years ago
dropdownMatchSelectWidth={false}
value={(pageSize || pageSizeOptions[0]).toString()}
onChange={value => this.changeSize(Number(value))}
7 years ago
getPopupContainer={triggerNode => triggerNode.parentNode}
>
{options}
</Select>
);
7 years ago
}
if (quickGo) {
if (goButton) {
gotoButton =
typeof goButton === 'boolean' ? (
<button type="button" onClick={this.go} onKeyup={this.go} disabled={disabled}>
7 years ago
{locale.jump_to_confirm}
</button>
) : (
<span onClick={this.go} onKeyup={this.go}>
{goButton}
</span>
);
7 years ago
}
goInput = (
<div class={`${prefixCls}-quick-jumper`}>
{locale.jump_to}
<input
disabled={disabled}
type="text"
value={goInputText}
onChange={this.handleChange}
7 years ago
onKeyup={this.go}
onBlur={this.handleBlur}
{...{
directives: [
{
name: 'ant-input',
},
],
}}
7 years ago
/>
{locale.page}
{gotoButton}
</div>
);
7 years ago
}
return (
<li class={`${prefixCls}`}>
{changeSelect}
{goInput}
</li>
);
7 years ago
},
};