Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
feat: (breaking change) re-implemented table component
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianKienle committed Jul 14, 2019
1 parent 23a266a commit 48cd6e0
Show file tree
Hide file tree
Showing 45 changed files with 1,317 additions and 1,295 deletions.
6 changes: 3 additions & 3 deletions src/components/Form/Controls/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<input
:class="inputClasses"
:disabled="disabled ? '' : null"
:checked="checked ? true : false"
:checked="checked"
@change="updateInput"
v-on="$listeners"
:value="value"
Expand Down Expand Up @@ -45,14 +45,14 @@ export default {
},
computed: {
checked() {
const { modelValue, value } = this;
const { modelValue, value, trueValue } = this;
if (Array.isArray(modelValue)) {
if (value == null) {
throw Error("value cannot be null");
}
return modelValue.indexOf(value) >= 0;
}
return modelValue === this.trueValue;
return modelValue === trueValue;
}
},
methods: {
Expand Down
9 changes: 4 additions & 5 deletions src/components/Form/FormLabel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<label class="fd-form__label" :aria-required="String(required)">
<slot name="control" />
<label class="fd-form__label" :for="itemId" :aria-required="String(required)">
<slot />
<template v-if="required"
>*</template
Expand All @@ -11,6 +10,9 @@
<script>
export default {
name: "FdFormLabel",
inject: {
itemId: { default: null }
},
props: {
inline: {
type: Boolean,
Expand All @@ -20,9 +22,6 @@ export default {
default: false,
type: Boolean
}
},
inject: {
itemId: { default: null }
}
};
</script>
65 changes: 0 additions & 65 deletions src/components/Table/Components/RowSelectionIndicator.vue

This file was deleted.

58 changes: 48 additions & 10 deletions src/components/Table/Components/TableCell.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,66 @@
<template>
<td :class="classes" :style="style">
<slot />
</td>
</template>

<script>
// Renders a single table cell.
export default {
name: "FdTableCell",
props: {
// Override the scope for this specific cell – used for a11y-related things.
// The scope is automatically set for you – use this prop only if you have special needs.
scope: {
// `col` / `row` / `null`
type: String,
validator: value => value === "col" || value === "row",
// `null`
default: null
},
// Whether or not this cell is rendered inside in a fixed column.
// `fixed` is automatically set for you – use this prop only if you have special needs.
fixed: {
type: Boolean,
default: null
default: false
}
},
inject: {
fdTableFixedProvider: {
default: {
fixed: null
}
}
},
render(h) {
const { fixed_, style, classes, $slots } = this;
const tag = fixed_ ? "th" : "td";
const attrs = fixed_ ? { scope: this.scope_ } : {};
return h(tag, { attrs, style, class: classes }, $slots.default);
},
computed: {
scope_() {
const { scope, fixed_ } = this;
if (scope != null) {
return scope;
}
return fixed_ ? "row" : null;
},
fixed_() {
const { fixed, fdTableFixedProvider } = this;
return fdTableFixedProvider.fixed != null
? fdTableFixedProvider.fixed
: fixed;
},
style() {
return this.fixed ? { left: "0", width: "200px" } : {};
return this.fixed_
? {
left: "0",
width: "200px"
}
: {};
},
classes() {
if (!this.fixed) {
const { fixed_ } = this;
if (!fixed_) {
return null;
}
return {
"fd-table__fixed-col": this.fixed
"fd-table__fixed-col": fixed_
};
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/Table/Components/TableHeaderCell.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<template>
<th v-on="$listeners" :class="classes" :style="styles">
<th scope="col" v-on="$listeners" :class="classes" :style="styles">
{{ label }}
<slot />
</th>
</template>

<script>
import { isTextAlignment, TextAlignment, SortOrder } from "./../Util";
import { SortOrder } from "./../utils/sort-order";
import { TextAlignment, isTextAlignment } from "./../utils/text-alignment";
export default {
name: "FdTableHeaderCell",
Expand Down
76 changes: 34 additions & 42 deletions src/components/Table/Components/TableRow.vue
Original file line number Diff line number Diff line change
@@ -1,59 +1,51 @@
<template>
<tr :aria-selected="String(selected_)" v-on="$listeners">
<template v-for="header in normalizedHeaders">
<fd-table-cell-fixed-provider
:fixed="header.columnFixed"
:key="header.id"
>
<slot :name="header.slotName" />
</fd-table-cell-fixed-provider>
</template>
</tr>
</template>

<script>
import FdTableCellFixedProvider from "./fixed-provider.vue";
export default {
name: "FdTableRow",
components: { FdTableCellFixedProvider },
inject: {
fdTableItemProvider: {
default: {
item: {},
selected: null
}
},
table: { default: null }
},
props: {
itemId: {
type: String,
default: null
item: {
type: Object,
default: () => {}
},
isSelected: {
selected: {
type: Boolean,
default: false
}
},
computed: {
firstColumnFixed() {
const table = this.table;
return (table || false) && table.firstColumnFixed;
}
},
methods: {
handleClick() {
const table = this.table;
const { itemId } = this;
if (itemId == null || table == null) {
return false;
}
table.toggleSelectionForItem(itemId);
selected_() {
const { selected, fdTableItemProvider } = this;
return fdTableItemProvider.selected != null
? fdTableItemProvider.selected
: selected;
},
normalizedHeaders() {
return this.table.normalizedHeaders;
}
},
render(h) {
const cells = this.$slots.default || [];
cells.forEach((cell, index) => {
const options = cell.componentOptions;
if (options == null) {
return;
}
const fixed = index === 0 && this.firstColumnFixed;
const { propsData = {} } = options;
options.propsData = { ...propsData, fixed };
});
return h(
"tr",
{
on: {
...this.$listeners,
"&click": this.handleClick // & = passive modifier
},
attrs: {
"aria-selected": this.isSelected
}
},
cells
);
}
};
</script>
34 changes: 34 additions & 0 deletions src/components/Table/Components/fixed-provider.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script>
export default {
props: {
fixed: {
type: Boolean,
required: true
}
},
provide() {
return {
fdTableFixedProvider: this.fdTableFixedProvider
};
},
render() {
const defaultSlot = this.$scopedSlots.default;
if (defaultSlot == null) {
return null;
}
return defaultSlot();
},
watch: {
fixed(fixed) {
this.fdTableFixedProvider.fixed = fixed;
}
},
data() {
return {
fdTableFixedProvider: {
fixed: this.fixed
}
};
}
};
</script>
6 changes: 0 additions & 6 deletions src/components/Table/Components/index.js

This file was deleted.

38 changes: 38 additions & 0 deletions src/components/Table/Components/item-provider.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script>
export default {
props: {
item: {
type: Object,
required: true
},
selected: {
type: Boolean,
require: true
}
},
provide() {
return {
fdTableItemProvider: this.fdTableItemProvider
};
},
render() {
return this.$scopedSlots.default();
},
watch: {
selected(selected) {
this.fdTableItemProvider.selected = selected;
},
item(item) {
this.fdTableItemProvider.item = item;
}
},
data() {
return {
fdTableItemProvider: {
item: this.item,
selected: this.selected
}
};
}
};
</script>
Loading

0 comments on commit 48cd6e0

Please sign in to comment.