Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: table #4641

Merged
merged 29 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c9db475
refactor: table
tangjinzhou Sep 2, 2021
60ea53c
refactor: table
tangjinzhou Sep 3, 2021
a948e66
refactor: table
tangjinzhou Sep 4, 2021
0d06e32
refactor: table
tangjinzhou Sep 4, 2021
de233c9
refactor: table
tangjinzhou Sep 4, 2021
456e3ae
refactor: table
tangjinzhou Sep 5, 2021
a64ed0d
refactor: table
tangjinzhou Sep 6, 2021
915100e
refactor: table
tangjinzhou Sep 6, 2021
844700e
refactor: table
tangjinzhou Sep 6, 2021
61e8bfd
fix: column not pass to cell
tangjinzhou Sep 6, 2021
562d86f
doc: uppate table
tangjinzhou Sep 6, 2021
c45b93b
fix: update bodyCell headerCell
tangjinzhou Sep 6, 2021
8d60808
doc: remove examples
tangjinzhou Sep 7, 2021
10cb279
refactor: table
tangjinzhou Sep 7, 2021
a8b2318
fix: table title not work
tangjinzhou Sep 7, 2021
5f640f1
fix: table selection
tangjinzhou Sep 7, 2021
fdf772a
fix: table checkStrictly
tangjinzhou Sep 8, 2021
6e3e52b
refactor: table
tangjinzhou Sep 9, 2021
9693d89
fix: table template error
tangjinzhou Sep 9, 2021
16e8012
feat: table support summary
tangjinzhou Sep 9, 2021
d3acab2
test: update snap
tangjinzhou Sep 9, 2021
6e85fd9
perf: table
tangjinzhou Sep 10, 2021
ba743b2
docs(table): fix ajax demo (#4639)
John60676 Sep 10, 2021
223abb1
test: update table
tangjinzhou Sep 10, 2021
d84ebc4
refactor: remove old table
tangjinzhou Sep 10, 2021
56ed985
doc: update table doc
tangjinzhou Sep 11, 2021
1a77a98
doc: update doc
tangjinzhou Sep 11, 2021
29e76b2
doc: update select
tangjinzhou Sep 11, 2021
48c5165
doc: update summary
tangjinzhou Sep 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
let cached;
/* eslint-disable no-param-reassign */

let cached: number;

export default function getScrollBarSize(fresh?: boolean) {
if (typeof document === 'undefined') {
return 0;
}

export default function getScrollBarSize(fresh) {
if (fresh || cached === undefined) {
const inner = document.createElement('div');
inner.style.width = '100%';
Expand All @@ -10,8 +16,8 @@ export default function getScrollBarSize(fresh) {
const outerStyle = outer.style;

outerStyle.position = 'absolute';
outerStyle.top = 0;
outerStyle.left = 0;
outerStyle.top = '0';
outerStyle.left = '0';
outerStyle.pointerEvents = 'none';
outerStyle.visibility = 'hidden';
outerStyle.width = '200px';
Expand All @@ -36,3 +42,21 @@ export default function getScrollBarSize(fresh) {
}
return cached;
}

function ensureSize(str: string) {
const match = str.match(/^(.*)px$/);
const value = Number(match?.[1]);
return Number.isNaN(value) ? getScrollBarSize() : value;
}

export function getTargetScrollBarSize(target: HTMLElement) {
if (typeof document === 'undefined' || !target || !(target instanceof Element)) {
return { width: 0, height: 0 };
}

const { width, height } = getComputedStyle(target, '::-webkit-scrollbar');
return {
width: ensureSize(width),
height: ensureSize(height),
};
}
1 change: 1 addition & 0 deletions components/_util/props-util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const parseStyleText = (cssText = '', camel) => {
const res = {};
const listDelimiter = /;(?![^(]*\))/g;
const propertyDelimiter = /:(.+)/;
if (typeof cssText === 'object') return cssText;
cssText.split(listDelimiter).forEach(function (item) {
if (item) {
const tmp = item.split(propertyDelimiter);
Expand Down
14 changes: 14 additions & 0 deletions components/_util/reactivePick.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { UnwrapRef } from 'vue';
import { reactive, toRef } from 'vue';

/**
* Reactively pick fields from a reactive object
*
* @see https://vueuse.js.org/reactivePick
*/
export function reactivePick<T extends object, K extends keyof T>(
obj: T,
...keys: K[]
): { [S in K]: UnwrapRef<T[S]> } {
return reactive(Object.fromEntries(keys.map(k => [k, toRef(obj, k)]))) as any;
}
42 changes: 42 additions & 0 deletions components/_util/toReactive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { isRef, reactive } from 'vue';
import type { Ref } from 'vue';
type MaybeRef<T> = T | Ref<T>;
/**
* Converts ref to reactive.
*
* @see https://vueuse.org/toReactive
* @param objectRef A ref of object
*/
export function toReactive<T extends object>(objectRef: MaybeRef<T>): T {
if (!isRef(objectRef)) return reactive(objectRef) as T;

const proxy = new Proxy(
{},
{
get(_, p, receiver) {
return Reflect.get(objectRef.value, p, receiver);
},
set(_, p, value) {
(objectRef.value as any)[p] = value;
return true;
},
deleteProperty(_, p) {
return Reflect.deleteProperty(objectRef.value, p);
},
has(_, p) {
return Reflect.has(objectRef.value, p);
},
ownKeys() {
return Object.keys(objectRef.value);
},
getOwnPropertyDescriptor() {
return {
enumerable: true,
configurable: true,
};
},
},
);

return reactive(proxy) as T;
}
5 changes: 5 additions & 0 deletions components/_util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ export function getDataAndAriaProps(props) {
}, {});
}

export function toPx(val) {
if (typeof val === 'number') return `${val}px`;
return val;
}

export { isOn, cacheStringFunction, camelize, hyphenate, capitalize, resolvePropValue };
27 changes: 19 additions & 8 deletions components/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ExtractPropTypes } from 'vue';
import { defineComponent, inject, nextTick } from 'vue';
import PropTypes from '../_util/vue-types';
import classNames from '../_util/classNames';
Expand All @@ -9,11 +10,8 @@ import type { RadioChangeEvent } from '../radio/interface';
import type { EventHandler } from '../_util/EventInterface';
function noop() {}

export default defineComponent({
name: 'ACheckbox',
inheritAttrs: false,
__ANT_CHECKBOX: true,
props: {
export const checkboxProps = () => {
return {
prefixCls: PropTypes.string,
defaultChecked: PropTypes.looseBool,
checked: PropTypes.looseBool,
Expand All @@ -27,7 +25,17 @@ export default defineComponent({
autofocus: PropTypes.looseBool,
onChange: PropTypes.func,
'onUpdate:checked': PropTypes.func,
},
skipGroup: PropTypes.looseBool,
};
};

export type CheckboxProps = Partial<ExtractPropTypes<ReturnType<typeof checkboxProps>>>;

export default defineComponent({
name: 'ACheckbox',
inheritAttrs: false,
__ANT_CHECKBOX: true,
props: checkboxProps(),
emits: ['change', 'update:checked'],
setup() {
return {
Expand All @@ -38,6 +46,9 @@ export default defineComponent({

watch: {
value(value, prevValue) {
if (this.skipGroup) {
return;
}
nextTick(() => {
const { checkboxGroupContext: checkboxGroup = {} } = this;
if (checkboxGroup.registerValue && checkboxGroup.cancelValue) {
Expand Down Expand Up @@ -85,7 +96,7 @@ export default defineComponent({
const props = getOptionProps(this);
const { checkboxGroupContext: checkboxGroup, $attrs } = this;
const children = getSlot(this);
const { indeterminate, prefixCls: customizePrefixCls, ...restProps } = props;
const { indeterminate, prefixCls: customizePrefixCls, skipGroup, ...restProps } = props;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('checkbox', customizePrefixCls);
const {
Expand All @@ -101,7 +112,7 @@ export default defineComponent({
prefixCls,
...restAttrs,
};
if (checkboxGroup) {
if (checkboxGroup && !skipGroup) {
checkboxProps.onChange = (...args) => {
this.$emit('change', ...args);
checkboxGroup.toggleOption({ label: children, value: props.value });
Expand Down
5 changes: 3 additions & 2 deletions components/checkbox/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { App, Plugin } from 'vue';
import Checkbox from './Checkbox';
import Checkbox, { checkboxProps } from './Checkbox';
import CheckboxGroup from './Group';
export type { CheckboxProps } from './Checkbox';

Checkbox.Group = CheckboxGroup;

Expand All @@ -10,7 +11,7 @@ Checkbox.install = function (app: App) {
app.component(CheckboxGroup.name, CheckboxGroup);
return app;
};
export { CheckboxGroup };
export { CheckboxGroup, checkboxProps };
export default Checkbox as typeof Checkbox &
Plugin & {
readonly Group: typeof CheckboxGroup;
Expand Down
17 changes: 16 additions & 1 deletion components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,22 @@ export { default as Steps, Step } from './steps';
export type { SwitchProps } from './switch';
export { default as Switch } from './switch';

export { default as Table, TableColumn, TableColumnGroup } from './table';
export type {
TableProps,
TablePaginationConfig,
ColumnGroupType as TableColumnGroupType,
ColumnType as TableColumnType,
ColumnProps as TableColumnProps,
ColumnsType as TableColumnsType,
} from './table';
export {
default as Table,
TableColumn,
TableColumnGroup,
TableSummary,
TableSummaryRow,
TableSummaryCell,
} from './table';

export type { TransferProps } from './transfer';
export { default as Transfer } from './transfer';
Expand Down
87 changes: 37 additions & 50 deletions components/empty/__tests__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,47 @@ exports[`renders ./components/empty/demo/config-provider.vue correctly 1`] = `
<div class="ant-spin-nested-loading">
<!---->
<div class="ant-spin-container">
<div class="ant-table ant-table-default ant-table-empty ant-table-scroll-position-left">
<div class="ant-table ant-table-empty" style="margin-top: 8px;">
<!---->
<div class="ant-table-content">
<!---->
<div class="ant-table-body">
<table class="">
<colgroup>
<col data-key="0">
<col data-key="1">
</colgroup>
<div class="ant-table-container">
<div class="ant-table-content">
<table style="table-layout: auto;">
<colgroup></colgroup>
<thead class="ant-table-thead">
<tr>
<th colstart="0" colspan="1" colend="0" rowspan="1" class=""><span class="ant-table-header-column"><div><span class="ant-table-column-title">Name</span><span class="ant-table-column-sorter"><!----></span>
</div></span>
<!---->
</th>
<th colstart="1" colspan="1" colend="1" rowspan="1" class=""><span class="ant-table-header-column"><div><span class="ant-table-column-title">Age</span><span class="ant-table-column-sorter"><!----></span>
</div></span>
<th class="ant-table-cell" colstart="0" colend="0">
<!---->Name
</th>
<th class="ant-table-cell" colstart="1" colend="1">
<!---->Age
</th>
</tr>
</thead>
<tbody class="ant-table-tbody">
<!---->
<tr class="ant-table-placeholder">
<td colspan="2" class="ant-table-cell">
<!---->No data
</td>
</tr>
</tbody>
<!---->
</table>
</div>
</div>
<!---->
</th>
</tr>
</thead>
<tbody class="ant-table-tbody"></tbody>
</table>
</div>
<div class="ant-table-placeholder">
</div>
</div>
</div>
<h3>List</h3>
<div class="ant-list ant-list-split">
<!---->
<!---->
<div class="ant-spin-nested-loading">
<!---->
<div class="ant-spin-container">
<div class="ant-list-empty-text">
<div class="ant-empty ant-empty-normal">
<div class="ant-empty-image"><svg class="ant-empty-img-simple" width="64" height="41" viewBox="0 0 64 41">
<g transform="translate(0 1)" fill="none" fill-rule="evenodd">
Expand All @@ -153,39 +168,11 @@ exports[`renders ./components/empty/demo/config-provider.vue correctly 1`] = `
<!---->
</div>
</div>
<!---->
</div>
</div>
</div>
</div>
</div>
<h3>List</h3>
<div class="ant-list ant-list-split">
<!---->
<!---->
<div class="ant-spin-nested-loading">
<!---->
<div class="ant-spin-container">
<div class="ant-list-empty-text">
<div class="ant-empty ant-empty-normal">
<div class="ant-empty-image"><svg class="ant-empty-img-simple" width="64" height="41" viewBox="0 0 64 41">
<g transform="translate(0 1)" fill="none" fill-rule="evenodd">
<ellipse class="ant-empty-img-simple-ellipse" fill="#F5F5F5" cx="32" cy="33" rx="32" ry="7"></ellipse>
<g class="ant-empty-img-simple-g" fill-rule="nonzero" stroke="#D9D9D9">
<path d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path>
<path d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z" fill="#FAFAFA" class="ant-empty-img-simple-path"></path>
</g>
</g>
</svg></div>
<p class="ant-empty-description">No Data</p>
<!---->
</div>
</div>
</div>
<!---->
</div>
<!---->
<!---->
</div>
</div>
`;

Expand Down
Loading