From 49045a24959a121210c5fb4b31dec5f61692390f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Mon, 11 Dec 2017 21:28:04 -0300 Subject: [PATCH 01/29] Create ClayTable --- packages/clay-table/LICENSE.md | 29 ++ packages/clay-table/README.md | 26 ++ packages/clay-table/demos/index.html | 353 ++++++++++++++++ packages/clay-table/package.json | 59 +++ packages/clay-table/src/ClayTable.js | 76 ++++ packages/clay-table/src/ClayTable.soy | 89 ++++ packages/clay-table/src/ClayTableItem.js | 115 ++++++ packages/clay-table/src/ClayTableItem.soy | 243 +++++++++++ .../clay-table/src/__tests__/ClayTable.js | 133 ++++++ .../clay-table/src/__tests__/ClayTableItem.js | 384 ++++++++++++++++++ .../__tests__/__snapshots__/ClayTable.js.snap | 65 +++ .../__snapshots__/ClayTableItem.js.snap | 252 ++++++++++++ packages/clay-table/src/items_validator.js | 59 +++ packages/clay-table/webpack.config.js | 31 ++ 14 files changed, 1914 insertions(+) create mode 100644 packages/clay-table/LICENSE.md create mode 100644 packages/clay-table/README.md create mode 100644 packages/clay-table/demos/index.html create mode 100644 packages/clay-table/package.json create mode 100644 packages/clay-table/src/ClayTable.js create mode 100644 packages/clay-table/src/ClayTable.soy create mode 100644 packages/clay-table/src/ClayTableItem.js create mode 100644 packages/clay-table/src/ClayTableItem.soy create mode 100644 packages/clay-table/src/__tests__/ClayTable.js create mode 100644 packages/clay-table/src/__tests__/ClayTableItem.js create mode 100644 packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap create mode 100644 packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap create mode 100644 packages/clay-table/src/items_validator.js create mode 100644 packages/clay-table/webpack.config.js diff --git a/packages/clay-table/LICENSE.md b/packages/clay-table/LICENSE.md new file mode 100644 index 000000000..70f93e946 --- /dev/null +++ b/packages/clay-table/LICENSE.md @@ -0,0 +1,29 @@ +# Software License Agreement (BSD License) + +Copyright (c) 2014, Liferay Inc. +All rights reserved. + +Redistribution and use of this software in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* The name of Liferay Inc. may not be used to endorse or promote products + derived from this software without specific prior + written permission of Liferay Inc. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/clay-table/README.md b/packages/clay-table/README.md new file mode 100644 index 000000000..5138b1083 --- /dev/null +++ b/packages/clay-table/README.md @@ -0,0 +1,26 @@ +# clay-table + +Metal Clay Table component + +## Setup + +1. Install NodeJS >= v0.12.0 and NPM >= v3.0.0, if you don't have it yet. You +can find it [here](https://nodejs.org). + +2. Install local dependencies: + + ``` + npm install + ``` + +3. Build the code: + + ``` + npm run build + ``` + +4. Open the demo at demos/index.html on your browser. + +## Contribute + +We'd love to get contributions from you! Please, check our [Contributing Guidelines](CONTRIBUTING.md) to see how you can help us improve. diff --git a/packages/clay-table/demos/index.html b/packages/clay-table/demos/index.html new file mode 100644 index 000000000..3b9daf091 --- /dev/null +++ b/packages/clay-table/demos/index.html @@ -0,0 +1,353 @@ + + + + + + Demo: ClayTable + + + + + + + + +

+ ClayTable +

+ +
+
+ + + + diff --git a/packages/clay-table/package.json b/packages/clay-table/package.json new file mode 100644 index 000000000..c48389d2f --- /dev/null +++ b/packages/clay-table/package.json @@ -0,0 +1,59 @@ +{ + "name": "clay-table", + "version": "1.0.0-alpha.5", + "description": "Metal ClayTable component", + "license": "BSD", + "repository": "https://github.com/metal/metal-clay-components/tree/master/packages/clay-table", + "engines": { + "node": ">=0.12.0", + "npm": ">=3.0.0" + }, + "main": "lib/ClayTable.js", + "esnext:main": "src/ClayTable.js", + "jsnext:main": "src/ClayTable.js", + "files": [ + "lib", + "src", + "test" + ], + "scripts": { + "build": "npm run soy && webpack", + "compile": "babel -d lib/ src/ -s --ignore src/__tests__", + "prepublish": "npm run soy && npm run compile", + "soy": "metalsoy --soyDeps '../../node_modules/clay-+(dropdown|label|sticker|progress-bar|button|checkbox|icon|link|radio)/src/**/*.soy'" + }, + "keywords": [ + "clay", + "metal" + ], + "dependencies": { + "clay-checkbox": "^1.0.0-alpha.5", + "clay-dropdown": "^1.0.0-alpha.5", + "clay-icon": "^1.0.0-alpha.5", + "clay-label": "^1.0.0-alpha.5", + "clay-link": "^1.0.0-alpha.5", + "clay-progress-bar": "^1.0.0-alpha.5", + "clay-radio": "^1.0.0-alpha.5", + "clay-sticker": "^1.0.0-alpha.5", + "metal": "^2.14.0", + "metal-component": "^2.14.0", + "metal-soy": "^2.14.0", + "metal-state": "^2.14.0", + "metal-web-component": "^2.14.0" + }, + "devDependencies": { + "babel-cli": "^6.24.1", + "babel-core": "^6.25.0", + "babel-loader": "^7.0.0", + "babel-plugin-transform-node-env-inline": "^0.1.1", + "babel-preset-env": "^1.6.0", + "browserslist-config-clay-components": "^1.0.0-alpha.2", + "clay": "^2.0.0-beta.4", + "metal-dom": "^2.13.2", + "metal-tools-soy": "^4.2.1", + "webpack": "^3.0.0" + }, + "browserslist": [ + "extends browserslist-config-clay-components" + ] +} diff --git a/packages/clay-table/src/ClayTable.js b/packages/clay-table/src/ClayTable.js new file mode 100644 index 000000000..9b150c121 --- /dev/null +++ b/packages/clay-table/src/ClayTable.js @@ -0,0 +1,76 @@ +import './ClayTableItem'; +import {Config} from 'metal-state'; +import Component from 'metal-component'; +import defineWebComponent from 'metal-web-component'; +import itemsValidator from './items_validator'; +import Soy from 'metal-soy'; + +import templates from './ClayTable.soy.js'; + +/** + * Metal ClayTable component. + */ +class ClayTable extends Component {} + +/** + * State definition. + * @static + * @type {!Object} + */ +ClayTable.STATE = { + /** + * CSS classes to be applied to the element. + * @instance + * @memberof ClayTable + * @type {?string|undefined} + * @default undefined + */ + elementClasses: Config.string(), + + /** + * Used to render the header of a column. + * @instance + * @memberof ClayTable + * @type {?array|undefined} + * @default undefined + */ + header: Config.arrayOf( + Config.shapeOf({ + label: Config.string(), + }) + ), + + /** + * Id to be applied to the element. + * @instance + * @memberof ClayTable + * @type {?string|undefined} + * @default undefined + */ + id: Config.string(), + + /** + * List the items of the table. + * @instance + * @memberof ClayTable + * @type {?array|undefined} + * @default undefined + */ + items: itemsValidator, + + /** + * The path to the SVG spritemap file containing the icons. + * @instance + * @memberof ClayTable + * @type {!string} + * @default undefined + */ + spritemap: Config.string().required(), +}; + +defineWebComponent('clay-table', ClayTable); + +Soy.register(ClayTable, templates); + +export {ClayTable}; +export default ClayTable; diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy new file mode 100644 index 000000000..6629118cd --- /dev/null +++ b/packages/clay-table/src/ClayTable.soy @@ -0,0 +1,89 @@ +{namespace ClayTable} + +/** + * This renders the component's whole content. + */ +{template .render} + {@param spritemap: string} + {@param? elementClasses: string} + {@param? header: list<[ + label: string + ]>} + {@param? id: string} + {@param? items: list<[ + actionItems: list<[ + disabled: bool, + icon: string, + label: string, + quickAction: bool, + separator: bool, + url: string + ]>, + columns: list<[ + label: string, + labelStyle: string, + progressBar: [ + maxValue: int, + minValue: int, + status: string, + value: int + ], + stickerLabel: string, + stickerStyle: string, + text: string, + url: string, + useEllipse: bool + ]>, + disabled: bool, + inputName: string, + inputValue: string, + selectable: bool, + selected: bool, + group: string + ]>} + + {let $attributes kind="attributes"} + class="table table-autofit table-heading-nowrap table-hover table-list show-quick-actions-on-hover + {if $elementClasses} + {sp}{$elementClasses} + {/if} + " + + {if $id} + id="{$id}" + {/if} + {/let} + +
+ + {if $header} + + {foreach $item in $header} + + {/foreach} + + {/if} + {if $items} + + {foreach $item in $items} + {call ClayTableItem.render} + {param actionItems: $item.actionItems /} + {param columns: $item.columns /} + {param disabled: $item.disabled /} + {param group: $item.group /} + {param inputName: $item.inputName /} + {param inputValue: $item.inputValue /} + {param selectable: $item.selectable /} + {param selected: $item.selected /} + {param spritemap: $spritemap /} + {/call} + {/foreach} + + {/if} +
+ {if $item.label} + {$item.label} + {/if} +
+
+{/template} diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js new file mode 100644 index 000000000..799292558 --- /dev/null +++ b/packages/clay-table/src/ClayTableItem.js @@ -0,0 +1,115 @@ +import 'clay-checkbox'; +import 'clay-dropdown'; +import 'clay-icon'; +import 'clay-label'; +import 'clay-link'; +import 'clay-progress-bar'; +import 'clay-radio'; +import 'clay-sticker'; +import {actionsItemsValidator, columnsValidator} from './items_validator'; +import {Config} from 'metal-state'; +import Component from 'metal-component'; +import defineWebComponent from 'metal-web-component'; +import Soy from 'metal-soy'; + +import templates from './ClayTableItem.soy.js'; + +/** + * Metal ClayTableItem component. + */ +class ClayTableItem extends Component {} + +/** + * State definition. + * @static + * @type {!Object} + */ +ClayTableItem.STATE = { + /** + * List of items to display in the actions menu. + * @instance + * @memberof ClayTableItem + * @type {?array|undefined} + * @default undefined + */ + actionItems: actionsItemsValidator, + + /** + * List of the columns in the row. + * @instance + * @memberof ClayTableItem + * @type {?array|undefined} + * @default undefined + */ + columns: columnsValidator, + + /** + * Flag to indicate if the item is disabled or not. + * @instance + * @memberof ClayTableItem + * @type {?bool} + * @default false + */ + disabled: Config.bool().value(false), + + /** + * Table group separator. + * @instance + * @memberof ClayTableItem + * @type {?string|undefined} + * @default undefined + */ + group: Config.string(), + + /** + * Name to be applied to the input element. + * @instance + * @memberof ClayTableItem + * @type {?string|undefined} + * @default undefined + */ + inputName: Config.string(), + + /** + * Value to be applied to the input element. + * @instance + * @memberof ClayTableItem + * @type {?string|undefined} + * @default undefined + */ + inputValue: Config.string(), + + /** + * Flag to indicate if the item is selectable. + * @instance + * @memberof ClayTableItem + * @type {?bool} + * @default false + */ + selectable: Config.bool().value(false), + + /** + * Flag to indicate if the item is selected or not. + * @instance + * @memberof ClayTableItem + * @type {?bool} + * @default false + */ + selected: Config.bool().value(false), + + /** + * The path to the SVG spritemap file containing the icons. + * @instance + * @memberof ClayTableItem + * @type {!string} + * @default undefined + */ + spritemap: Config.string().required(), +}; + +defineWebComponent('clay-table-item', ClayTableItem); + +Soy.register(ClayTableItem, templates); + +export {ClayTableItem}; +export default ClayTableItem; diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy new file mode 100644 index 000000000..1c3bbd5ba --- /dev/null +++ b/packages/clay-table/src/ClayTableItem.soy @@ -0,0 +1,243 @@ +{namespace ClayTableItem} + +/** + * This renders the component's whole content. + */ +{template .render} + {@param spritemap: string} + {@param? actionItems: list<[ + disabled: bool, + icon: string, + label: string, + quickAction: bool, + separator: bool, + url: string + ]>} + {@param? columns: list<[ + label: string, + labelStyle: string, + progressBar: [ + maxValue: int, + minValue: int, + status: string, + value: int + ], + stickerLabel: string, + stickerStyle: string, + text: string, + url: string, + useEllipse: bool + ]>} + {@param? disabled: bool} + {@param? group: string} + {@param? inputName: string} + {@param? inputValue: string} + {@param? selectable: bool} + {@param? selected: bool} + + {let $attributes kind="attributes"} + class=" + {if $selectable and $selected} + table-active + {/if} + + {if $group} + table-divider + {/if} + " + {/let} + + + {if $group} + {$group} + {else} + {call .content} + {param actionItems: $actionItems /} + {param columns: $columns /} + {param disabled: $disabled /} + {param inputName: $inputName /} + {param inputValue: $inputValue /} + {param selectable: $selectable /} + {param selected: $selected /} + {param spritemap: $spritemap /} + {/call} + {/if} + +{/template} + +/** + * This renders the content of the row. + */ +{template .content} + {@param spritemap: string} + {@param? actionItems: list<[ + disabled: bool, + icon: string, + label: string, + quickAction: bool, + separator: bool, + url: string + ]>} + {@param? columns: list<[ + label: string, + labelStyle: string, + progressBar: [ + maxValue: int, + minValue: int, + status: string, + value: int + ], + stickerLabel: string, + stickerStyle: string, + text: string, + url: string, + useEllipse: bool + ]>} + {@param? disabled: bool} + {@param? inputName: string} + {@param? inputValue: string} + {@param? selectable: bool} + {@param? selected: bool} + + {if $selectable} + + {call ClayCheckbox.render} + {param checked: $selected /} + {param disabled: $disabled /} + {param hideLabel: true /} + {param name: $inputName /} + {param value: $inputValue /} + {/call} + + {/if} + + {if $columns} + {foreach $column in $columns} + {let $isColumnFirst: index($column) == '0' and not $selectable or index($column) == '1' and $selectable /} + + {call .column} + {param isColumnFirst: $isColumnFirst /} + {param label: $column.label /} + {param labelStyle: $column.labelStyle /} + {param progressBar: $column.progressBar /} + {param stickerLabel: $column.stickerLabel /} + {param stickerStyle: $column.stickerStyle /} + {param text: $column.text /} + {param url: $column.url /} + {param useEllipse: $column.useEllipse /} + {/call} + {/foreach} + {/if} + + {if $actionItems} + + {call .quickMenu} + {param actionItems: $actionItems /} + {param spritemap: $spritemap /} + {/call} + + {call ClayActionsDropdown.render} + {param items: $actionItems /} + {param spritemap: $spritemap /} + {/call} + + {/if} +{/template} + +/** + * This renders a multiples columns of the row. + */ +{template .column} + {@param? isColumnFirst: bool} + {@param? label: string} + {@param? labelStyle: string} + {@param? progressBar: [ + maxValue: int, + minValue: int, + status: string, + value: int + ]} + {@param? stickerLabel: string} + {@param? stickerStyle: string} + {@param? text: string} + {@param? url: string} + {@param? useEllipse: bool} + + {let $textContent kind="html"} + {if $stickerLabel and $isColumnFirst} + {call ClaySticker.render} + {param label: $stickerLabel /} + {param shape: 'circle' /} + {param style: $stickerStyle /} + {/call} + {/if} + {$text} + {/let} + + {let $content kind="html"} + {if $label} + {call ClayLabel.render} + {param label: $label /} + {param style: $labelStyle /} + {/call} + {elseif $progressBar} + {call ClayProgressBar.render} + {param minValue: $progressBar.minValue /} + {param maxValue: $progressBar.maxValue /} + {param status: $progressBar.status /} + {param value: $progressBar.value /} + {/call} + {elseif $useEllipse} + {$textContent} + {elseif $text and not $url} + {$textContent} + {elseif $text and $url} + {call ClayLink.render} + {param href: $url /} + {param label: $text /} + {/call} + {/if} + {/let} + + {let $attributes kind="attributes"} + {if $useEllipse} + class="table-cell-content" + {/if} + {/let} + + + {$content} + +{/template} + +/** + * This renders the quick actions menu. + */ +{template .quickMenu} + {@param actionItems: list<[ + disabled: bool, + icon: string, + label: string, + quickAction: bool, + separator: bool, + url: string + ]>} + {@param spritemap: string} + +
+ {foreach $item in $actionItems} + {if $item.quickAction and $item.icon} + {call ClayLink.render} + {param elementClasses: 'quick-action-item' /} + {param href: $item.url /} + {param label kind="html"} + {call ClayIcon.render} + {param spritemap: $spritemap /} + {param symbol: $item.icon /} + {/call} + {/param} + {/call} + {/if} + {/foreach} +
+{/template} diff --git a/packages/clay-table/src/__tests__/ClayTable.js b/packages/clay-table/src/__tests__/ClayTable.js new file mode 100644 index 000000000..e78790928 --- /dev/null +++ b/packages/clay-table/src/__tests__/ClayTable.js @@ -0,0 +1,133 @@ +import ClayTable from '../ClayTable'; + +let component; +let spritemap = 'icons.svg'; +let items = [ + { + columns: [ + { + text: 'suffing-photo.png', + cellContent: true, + }, + { + text: 'Juan Anton', + }, + { + text: '264KB', + }, + { + labels: [ + { + label: 'Approved', + style: 'success', + }, + ], + }, + { + text: '15 Minutes Ago', + }, + { + text: '15 Minutes Ago', + }, + ], + }, + { + columns: [ + { + text: 'suffing-photo.png', + cellContent: true, + }, + { + text: 'Juan Anton', + }, + { + text: '264KB', + }, + { + labels: [ + { + label: 'Approved', + style: 'success', + }, + ], + }, + { + text: '15 Minutes Ago', + }, + { + text: '15 Minutes Ago', + }, + ], + }, +]; + +describe('ClayTable', function() { + afterEach(() => { + if (component) { + component.dispose(); + } + }); + + it('should render the default markup', () => { + component = new ClayTable({ + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render a ClayTable with classes', () => { + component = new ClayTable({ + elementClasses: 'my-custom-class', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render a ClayTable with id', () => { + component = new ClayTable({ + id: 'myId', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render a ClayTable with multiples items', () => { + component = new ClayTable({ + items: items, + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render a ClayTable with multiples columns in header', () => { + component = new ClayTable({ + header: [ + { + label: 'Title', + }, + { + label: 'Author', + }, + { + label: 'Size', + }, + { + label: 'Status', + }, + ], + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should fail when no spritemap is passed', () => { + expect(() => { + component = new ClayTable(); + }).toThrow(); + }); +}); diff --git a/packages/clay-table/src/__tests__/ClayTableItem.js b/packages/clay-table/src/__tests__/ClayTableItem.js new file mode 100644 index 000000000..3ca3db1e5 --- /dev/null +++ b/packages/clay-table/src/__tests__/ClayTableItem.js @@ -0,0 +1,384 @@ +import ClayTableItem from '../ClayTableItem'; + +let component; +let spritemap = 'icons.svg'; + +describe('ClayTableItem', function() { + afterEach(() => { + if (component) { + component.dispose(); + } + }); + + it('should render the default markup', () => { + component = new ClayTableItem({ + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with id', () => { + component = new ClayTableItem({ + id: 'myId', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with custom element class', () => { + component = new ClayTableItem({ + elementClasses: 'my-custom-class', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with columns', () => { + component = new ClayTableItem({ + columns: [ + { + text: 'Foo', + cellContent: true, + }, + { + text: 'Bar', + url: '#1', + }, + { + text: 'Foo', + }, + { + text: 'Bar', + }, + ], + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with multiples stickers in the column', () => { + component = new ClayTableItem({ + columns: [ + { + stickers: [ + { + label: 'AA', + style: 'danger', + }, + { + label: 'BB', + style: 'dark', + }, + { + label: 'CC', + style: 'info', + }, + { + label: 'CC', + style: 'light', + }, + { + label: 'CC', + style: 'primary', + }, + { + label: 'CC', + style: 'secondary', + }, + { + label: 'CC', + style: 'success', + }, + { + label: 'CC', + style: 'warning', + }, + ], + }, + ], + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with multiples badges in the column', () => { + component = new ClayTableItem({ + columns: [ + { + badges: [ + { + label: '01', + style: 'danger', + }, + { + label: '01', + style: 'dark', + }, + { + label: '01', + style: 'info', + }, + { + label: '01', + style: 'light', + }, + { + label: '01', + style: 'primary', + }, + { + label: '01', + style: 'secondary', + }, + { + label: '01', + style: 'success', + }, + { + label: '01', + style: 'warning', + }, + ], + }, + ], + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with multiples labels in the column', () => { + component = new ClayTableItem({ + columns: [ + { + labels: [ + { + label: 'Approved', + style: 'success', + }, + { + label: 'Rejected', + style: 'danger', + }, + { + label: 'Status', + style: 'info', + }, + { + label: 'Label text', + style: 'secondary', + }, + { + label: 'Pending', + style: 'warning', + }, + ], + }, + ], + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with actionItems', () => { + component = new ClayTableItem({ + actionItems: [ + { + label: 'Option 1', + url: '#1', + }, + { + label: 'Option 2', + separator: true, + url: '#2', + }, + { + label: 'Option 3', + url: '#3', + }, + ], + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with actionItems and quick menu', () => { + component = new ClayTableItem({ + actionItems: [ + { + icon: 'trash', + label: 'Option 1', + quickAction: true, + url: '#1', + }, + { + icon: 'download', + label: 'Option 2', + quickAction: true, + separator: true, + url: '#2', + }, + { + icon: 'info-circle-open', + label: 'Option 3', + quickAction: true, + url: '#3', + }, + ], + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem selectable', () => { + component = new ClayTableItem({ + columns: [ + { + text: 'Foo', + cellContent: true, + }, + { + text: 'Bar', + url: '#1', + }, + { + text: 'Foo', + }, + { + text: 'Bar', + }, + ], + selectable: true, + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem selected', () => { + component = new ClayTableItem({ + columns: [ + { + text: 'Foo', + cellContent: true, + }, + { + text: 'Bar', + url: '#1', + }, + { + text: 'Foo', + }, + { + text: 'Bar', + }, + ], + selectable: true, + selected: true, + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem disabled', () => { + component = new ClayTableItem({ + columns: [ + { + text: 'Foo', + cellContent: true, + }, + { + text: 'Bar', + url: '#1', + }, + { + text: 'Foo', + }, + { + text: 'Bar', + }, + ], + selectable: true, + disabled: true, + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with input name', () => { + component = new ClayTableItem({ + columns: [ + { + text: 'Foo', + cellContent: true, + }, + { + text: 'Bar', + url: '#1', + }, + { + text: 'Foo', + }, + { + text: 'Bar', + }, + ], + inputName: 'name', + selectable: true, + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with input value', () => { + component = new ClayTableItem({ + columns: [ + { + text: 'Foo', + cellContent: true, + }, + { + text: 'Bar', + url: '#1', + }, + { + text: 'Foo', + }, + { + text: 'Bar', + }, + ], + inputValue: 'value', + selectable: true, + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render the ClayTableItem with group', () => { + component = new ClayTableItem({ + group: 'Group 1', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should fail when no spritemap is passed', () => { + expect(() => { + component = new ClayTableItem(); + }).toThrow(); + }); +}); diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap new file mode 100644 index 000000000..0b6b09ae1 --- /dev/null +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap @@ -0,0 +1,65 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ClayTable should render a ClayTable with classes 1`] = ` +
+
+
+`; + +exports[`ClayTable should render a ClayTable with id 1`] = ` +
+
+
+`; + +exports[`ClayTable should render a ClayTable with multiples columns in header 1`] = ` +
+ + + + + + + +
TitleAuthorSizeStatus
+
+`; + +exports[`ClayTable should render a ClayTable with multiples items 1`] = ` +
+ + + + + + + + + + + + + + + + + + + +
+ suffing-photo.png + Juan Anton264KB + Approved + 15 Minutes Ago15 Minutes Ago
+ suffing-photo.png + Juan Anton264KB + Approved + 15 Minutes Ago15 Minutes Ago
+
+`; + +exports[`ClayTable should render the default markup 1`] = ` +
+
+
+`; diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap new file mode 100644 index 000000000..743d257e6 --- /dev/null +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap @@ -0,0 +1,252 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ClayTableItem should render the ClayTableItem disabled 1`] = ` + + +
+ +
+ + + Foo + + + Bar + + Foo + Bar + +`; + +exports[`ClayTableItem should render the ClayTableItem selectable 1`] = ` + + +
+ +
+ + + Foo + + + Bar + + Foo + Bar + +`; + +exports[`ClayTableItem should render the ClayTableItem selected 1`] = ` + + +
+ +
+ + + Foo + + + Bar + + Foo + Bar + +`; + +exports[`ClayTableItem should render the ClayTableItem with actionItems 1`] = ` + + +
+ + + +`; + +exports[`ClayTableItem should render the ClayTableItem with actionItems and quick menu 1`] = ` + + +
+ + + + + + + + + +
+ + + +`; + +exports[`ClayTableItem should render the ClayTableItem with columns 1`] = ` + + + Foo + + + Bar + + Foo + Bar + +`; + +exports[`ClayTableItem should render the ClayTableItem with custom element class 1`] = ``; + +exports[`ClayTableItem should render the ClayTableItem with group 1`] = ` + + Group 1 + +`; + +exports[`ClayTableItem should render the ClayTableItem with id 1`] = ``; + +exports[`ClayTableItem should render the ClayTableItem with input name 1`] = ` + + +
+ +
+ + + Foo + + + Bar + + Foo + Bar + +`; + +exports[`ClayTableItem should render the ClayTableItem with input value 1`] = ` + + +
+ +
+ + + Foo + + + Bar + + Foo + Bar + +`; + +exports[`ClayTableItem should render the ClayTableItem with multiples badges in the column 1`] = ` + + + 01 + 01 + 01 + 01 + 01 + 01 + 01 + 01 + + +`; + +exports[`ClayTableItem should render the ClayTableItem with multiples labels in the column 1`] = ` + + + Approved + Rejected + Status + Label text + Pending + + +`; + +exports[`ClayTableItem should render the ClayTableItem with multiples stickers in the column 1`] = ` + + + AA + BB + CC + CC + CC + CC + CC + CC + + +`; + +exports[`ClayTableItem should render the default markup 1`] = ``; diff --git a/packages/clay-table/src/items_validator.js b/packages/clay-table/src/items_validator.js new file mode 100644 index 000000000..cd9e5dfcd --- /dev/null +++ b/packages/clay-table/src/items_validator.js @@ -0,0 +1,59 @@ +import {Config} from 'metal-state'; + +let actionItems = { + disabled: Config.bool().value(false), + icon: Config.string(), + label: Config.string(), + quickAction: Config.bool().value(false), + separator: Config.bool().value(false), + url: Config.string().required(), +}; + +let columns = { + label: Config.string(), + labelStyle: Config.oneOf([ + 'danger', + 'info', + 'secondary', + 'success', + 'warning', + ]).value('secondary'), + progressBar: Config.shapeOf({ + maxValue: Config.number(), + minValue: Config.number(), + status: Config.oneOf(['complete', 'warning']), + value: Config.number(), + }), + stickerLabel: Config.any(), + stickerStyle: Config.oneOf([ + 'danger', + 'dark', + 'info', + 'light', + 'primary', + 'secondary', + 'success', + 'warning', + ]).value('primary'), + text: Config.string(), + url: Config.string(), + useEllipse: Config.bool().value(false), +}; + +let items = { + actionItems: Config.arrayOf(Config.shapeOf(actionItems)), + columns: Config.arrayOf(Config.shapeOf(columns)), + disabled: Config.bool().value(false), + group: Config.string(), + inputName: Config.string(), + inputValue: Config.string(), + selectable: Config.bool().value(false), + selected: Config.bool().value(false), +}; + +const actionsItemsValidator = Config.arrayOf(Config.shapeOf(actionItems)); +const columnsValidator = Config.arrayOf(Config.shapeOf(columns)); +const itemsValidator = Config.arrayOf(Config.shapeOf(items)); + +export {actionsItemsValidator, columnsValidator, itemsValidator}; +export default itemsValidator; diff --git a/packages/clay-table/webpack.config.js b/packages/clay-table/webpack.config.js new file mode 100644 index 000000000..63267c1da --- /dev/null +++ b/packages/clay-table/webpack.config.js @@ -0,0 +1,31 @@ +const path = require('path'); +const webpack = require('webpack'); + +module.exports = { + entry: './src/ClayTable.js', + module: { + rules: [ + { + test: /\.js$/, + exclude: /(node_modules|bower_components)/, + use: { + loader: 'babel-loader', + options: { + compact: false, + presets: ['babel-preset-env'], + plugins: ['babel-plugin-transform-node-env-inline'], + }, + }, + }, + ], + }, + output: { + library: 'metal', + libraryTarget: 'this', + filename: './build/globals/clay-table.js', + }, + plugins: [new webpack.optimize.ModuleConcatenationPlugin()], + resolve: { + mainFields: ['esnext:main', 'main'], + }, +}; From ad96e545bf313bdd92f43a6ca435e13941286779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 10:58:32 -0300 Subject: [PATCH 02/29] Separate column for flexible use with deltemplate --- packages/clay-table/src/ClayTableItem.js | 9 +++ packages/clay-table/src/ClayTableItem.soy | 72 ++++++++++++++++------- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js index 799292558..13f4d00e7 100644 --- a/packages/clay-table/src/ClayTableItem.js +++ b/packages/clay-table/src/ClayTableItem.js @@ -43,6 +43,15 @@ ClayTableItem.STATE = { */ columns: columnsValidator, + /** + * Name of the content renderer to use template variants. + * @instance + * @memberof ClayTableItem + * @type {?string|undefined} + * @default undefined + */ + contentRenderer: Config.string(), + /** * Flag to indicate if the item is disabled or not. * @instance diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index 1c3bbd5ba..7706cfbc4 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -28,6 +28,7 @@ url: string, useEllipse: bool ]>} + {@param? contentRenderer: string} {@param? disabled: bool} {@param? group: string} {@param? inputName: string} @@ -54,6 +55,7 @@ {call .content} {param actionItems: $actionItems /} {param columns: $columns /} + {param contentRenderer: $contentRenderer /} {param disabled: $disabled /} {param inputName: $inputName /} {param inputValue: $inputValue /} @@ -93,6 +95,7 @@ url: string, useEllipse: bool ]>} + {@param? contentRenderer: string} {@param? disabled: bool} {@param? inputName: string} {@param? inputValue: string} @@ -115,7 +118,7 @@ {foreach $column in $columns} {let $isColumnFirst: index($column) == '0' and not $selectable or index($column) == '1' and $selectable /} - {call .column} + {delcall ClayTableItem.Column variant="$contentRenderer"} {param isColumnFirst: $isColumnFirst /} {param label: $column.label /} {param labelStyle: $column.labelStyle /} @@ -125,7 +128,7 @@ {param text: $column.text /} {param url: $column.url /} {param useEllipse: $column.useEllipse /} - {/call} + {/delcall} {/foreach} {/if} @@ -147,9 +150,9 @@ /** * This renders a multiples columns of the row. */ -{template .column} +{deltemplate ClayTableItem.Column} {@param? isColumnFirst: bool} - {@param? label: string} + {@param? label: string} {@param? labelStyle: string} {@param? progressBar: [ maxValue: int, @@ -164,14 +167,13 @@ {@param? useEllipse: bool} {let $textContent kind="html"} - {if $stickerLabel and $isColumnFirst} - {call ClaySticker.render} - {param label: $stickerLabel /} - {param shape: 'circle' /} - {param style: $stickerStyle /} - {/call} - {/if} - {$text} + {call .text} + {param isColumnFirst: $isColumnFirst /} + {param stickerLabel: $stickerLabel /} + {param stickerStyle: $stickerStyle /} + {param text: $text /} + {param url: $url /} + {/call} {/let} {let $content kind="html"} @@ -187,15 +189,12 @@ {param status: $progressBar.status /} {param value: $progressBar.value /} {/call} - {elseif $useEllipse} - {$textContent} - {elseif $text and not $url} - {$textContent} - {elseif $text and $url} - {call ClayLink.render} - {param href: $url /} - {param label: $text /} - {/call} + {elseif $text} + {if $useEllipse} + {$textContent} + {else} + {$textContent} + {/if} {/if} {/let} @@ -208,6 +207,37 @@ {$content} +{/deltemplate} + +/** + * This renders a text of the column. + */ +{template .text} + {@param? isColumnFirst: bool} + {@param? stickerLabel: string} + {@param? stickerStyle: string} + {@param? text: string} + {@param? url: string} + + {let $textContent kind="html"} + {if $stickerLabel and $isColumnFirst} + {call ClaySticker.render} + {param label: $stickerLabel /} + {param shape: 'circle' /} + {param style: $stickerStyle /} + {/call} + {/if} + {$text} + {/let} + + {if $text and not $url} + {$textContent} + {elseif $text and $url} + {call ClayLink.render} + {param href: $url /} + {param label: $text /} + {/call} + {/if} {/template} /** From ed4c70a6c2321c3b3a02da2dcb2536e06f2eeb07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 11:20:15 -0300 Subject: [PATCH 03/29] Update ClayTable tests --- .../clay-table/src/__tests__/ClayTable.js | 20 +-- .../clay-table/src/__tests__/ClayTableItem.js | 117 +++--------------- 2 files changed, 24 insertions(+), 113 deletions(-) diff --git a/packages/clay-table/src/__tests__/ClayTable.js b/packages/clay-table/src/__tests__/ClayTable.js index e78790928..8ce735dec 100644 --- a/packages/clay-table/src/__tests__/ClayTable.js +++ b/packages/clay-table/src/__tests__/ClayTable.js @@ -7,7 +7,7 @@ let items = [ columns: [ { text: 'suffing-photo.png', - cellContent: true, + useEllipse: true, }, { text: 'Juan Anton', @@ -16,12 +16,8 @@ let items = [ text: '264KB', }, { - labels: [ - { - label: 'Approved', - style: 'success', - }, - ], + label: 'Approved', + labelStyle: 'success', }, { text: '15 Minutes Ago', @@ -35,7 +31,7 @@ let items = [ columns: [ { text: 'suffing-photo.png', - cellContent: true, + useEllipse: true, }, { text: 'Juan Anton', @@ -44,12 +40,8 @@ let items = [ text: '264KB', }, { - labels: [ - { - label: 'Approved', - style: 'success', - }, - ], + label: 'Approved', + labelStyle: 'success', }, { text: '15 Minutes Ago', diff --git a/packages/clay-table/src/__tests__/ClayTableItem.js b/packages/clay-table/src/__tests__/ClayTableItem.js index 3ca3db1e5..3a405c629 100644 --- a/packages/clay-table/src/__tests__/ClayTableItem.js +++ b/packages/clay-table/src/__tests__/ClayTableItem.js @@ -41,7 +41,7 @@ describe('ClayTableItem', function() { columns: [ { text: 'Foo', - cellContent: true, + useEllipse: true, }, { text: 'Bar', @@ -60,44 +60,14 @@ describe('ClayTableItem', function() { expect(component).toMatchSnapshot(); }); - it('should render the ClayTableItem with multiples stickers in the column', () => { + it('should render the ClayTableItem with user sticker in the column', () => { component = new ClayTableItem({ columns: [ { - stickers: [ - { - label: 'AA', - style: 'danger', - }, - { - label: 'BB', - style: 'dark', - }, - { - label: 'CC', - style: 'info', - }, - { - label: 'CC', - style: 'light', - }, - { - label: 'CC', - style: 'primary', - }, - { - label: 'CC', - style: 'secondary', - }, - { - label: 'CC', - style: 'success', - }, - { - label: 'CC', - style: 'warning', - }, - ], + stickerLabel: 'AA', + stickerStyle: 'primary', + text: 'Name', + useEllipse: true, }, ], spritemap: spritemap, @@ -106,44 +76,13 @@ describe('ClayTableItem', function() { expect(component).toMatchSnapshot(); }); - it('should render the ClayTableItem with multiples badges in the column', () => { + it('should render the ClayTableItem with ClayProgressBar in the column', () => { component = new ClayTableItem({ columns: [ { - badges: [ - { - label: '01', - style: 'danger', - }, - { - label: '01', - style: 'dark', - }, - { - label: '01', - style: 'info', - }, - { - label: '01', - style: 'light', - }, - { - label: '01', - style: 'primary', - }, - { - label: '01', - style: 'secondary', - }, - { - label: '01', - style: 'success', - }, - { - label: '01', - style: 'warning', - }, - ], + progressBar: { + value: 40, + }, }, ], spritemap: spritemap, @@ -152,32 +91,12 @@ describe('ClayTableItem', function() { expect(component).toMatchSnapshot(); }); - it('should render the ClayTableItem with multiples labels in the column', () => { + it('should render the ClayTableItem with label in the column', () => { component = new ClayTableItem({ columns: [ { - labels: [ - { - label: 'Approved', - style: 'success', - }, - { - label: 'Rejected', - style: 'danger', - }, - { - label: 'Status', - style: 'info', - }, - { - label: 'Label text', - style: 'secondary', - }, - { - label: 'Pending', - style: 'warning', - }, - ], + label: 'Approved', + labelStyle: 'success', }, ], spritemap: spritemap, @@ -243,7 +162,7 @@ describe('ClayTableItem', function() { columns: [ { text: 'Foo', - cellContent: true, + useEllipse: true, }, { text: 'Bar', @@ -268,7 +187,7 @@ describe('ClayTableItem', function() { columns: [ { text: 'Foo', - cellContent: true, + useEllipse: true, }, { text: 'Bar', @@ -294,7 +213,7 @@ describe('ClayTableItem', function() { columns: [ { text: 'Foo', - cellContent: true, + useEllipse: true, }, { text: 'Bar', @@ -320,7 +239,7 @@ describe('ClayTableItem', function() { columns: [ { text: 'Foo', - cellContent: true, + useEllipse: true, }, { text: 'Bar', @@ -346,7 +265,7 @@ describe('ClayTableItem', function() { columns: [ { text: 'Foo', - cellContent: true, + useEllipse: true, }, { text: 'Bar', From 3f77126295a2f587720f7a1cb60fbd4f0ad3d939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 11:20:39 -0300 Subject: [PATCH 04/29] Update ClayTable snapshots --- .../__snapshots__/ClayTableItem.js.snap | 48 +++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap index 743d257e6..27c33a569 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap @@ -66,6 +66,19 @@ exports[`ClayTableItem should render the ClayTableItem selected 1`] = ` `; +exports[`ClayTableItem should render the ClayTableItem with ClayProgressBar in the column 1`] = ` + + +
+
+
+
+
40%
+
+ + +`; + exports[`ClayTableItem should render the ClayTableItem with actionItems 1`] = ` @@ -207,44 +220,19 @@ exports[`ClayTableItem should render the ClayTableItem with input value 1`] = ` `; -exports[`ClayTableItem should render the ClayTableItem with multiples badges in the column 1`] = ` - - - 01 - 01 - 01 - 01 - 01 - 01 - 01 - 01 - - -`; - -exports[`ClayTableItem should render the ClayTableItem with multiples labels in the column 1`] = ` +exports[`ClayTableItem should render the ClayTableItem with label in the column 1`] = ` Approved - Rejected - Status - Label text - Pending `; -exports[`ClayTableItem should render the ClayTableItem with multiples stickers in the column 1`] = ` +exports[`ClayTableItem should render the ClayTableItem with user sticker in the column 1`] = ` - - AA - BB - CC - CC - CC - CC - CC - CC + + + AAName `; From 25047fed8adce3f085628ef967c532ee66bb8534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 11:23:30 -0300 Subject: [PATCH 05/29] SF --- packages/clay-table/package.json | 1 - packages/clay-table/src/ClayTableItem.js | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/clay-table/package.json b/packages/clay-table/package.json index c48389d2f..ce9d4b432 100644 --- a/packages/clay-table/package.json +++ b/packages/clay-table/package.json @@ -33,7 +33,6 @@ "clay-label": "^1.0.0-alpha.5", "clay-link": "^1.0.0-alpha.5", "clay-progress-bar": "^1.0.0-alpha.5", - "clay-radio": "^1.0.0-alpha.5", "clay-sticker": "^1.0.0-alpha.5", "metal": "^2.14.0", "metal-component": "^2.14.0", diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js index 13f4d00e7..ec01cf100 100644 --- a/packages/clay-table/src/ClayTableItem.js +++ b/packages/clay-table/src/ClayTableItem.js @@ -4,7 +4,6 @@ import 'clay-icon'; import 'clay-label'; import 'clay-link'; import 'clay-progress-bar'; -import 'clay-radio'; import 'clay-sticker'; import {actionsItemsValidator, columnsValidator} from './items_validator'; import {Config} from 'metal-state'; From 00a73487922107118f560b549772a7ea8afeb618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 15:13:48 -0300 Subject: [PATCH 06/29] Restrict the use of the sticker on the columns --- packages/clay-table/src/ClayTable.js | 2 + packages/clay-table/src/ClayTable.soy | 42 ++++++++++++++------ packages/clay-table/src/ClayTableItem.js | 36 +++++++++++++++++ packages/clay-table/src/ClayTableItem.soy | 46 ++++++++++------------ packages/clay-table/src/items_validator.js | 23 +++++------ 5 files changed, 101 insertions(+), 48 deletions(-) diff --git a/packages/clay-table/src/ClayTable.js b/packages/clay-table/src/ClayTable.js index 9b150c121..ba9f272a9 100644 --- a/packages/clay-table/src/ClayTable.js +++ b/packages/clay-table/src/ClayTable.js @@ -36,7 +36,9 @@ ClayTable.STATE = { */ header: Config.arrayOf( Config.shapeOf({ + colSpan: Config.number(), label: Config.string(), + sort: Config.bool().value(false), }) ), diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index 6629118cd..b69ee2e53 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -7,7 +7,9 @@ {@param spritemap: string} {@param? elementClasses: string} {@param? header: list<[ - label: string + colSpan: int, + label: string, + sort: bool ]>} {@param? id: string} {@param? items: list<[ @@ -28,18 +30,19 @@ status: string, value: int ], - stickerLabel: string, - stickerStyle: string, text: string, url: string, useEllipse: bool ]>, disabled: bool, + group: string, inputName: string, inputValue: string, selectable: bool, selected: bool, - group: string + stickerLabel: string, + stickerStyle: string, + stickerShape: string ]>} {let $attributes kind="attributes"} @@ -58,13 +61,27 @@ {if $header} - {foreach $item in $header} - - {/foreach} + + {foreach $item in $header} + {let $thAttributes kind="attributes"} + {if $item.colSpan} + colspan="{$item.colSpan}" + {/if} + {/let} + + + {/foreach} + {/if} {if $items} @@ -80,6 +97,9 @@ {param selectable: $item.selectable /} {param selected: $item.selected /} {param spritemap: $spritemap /} + {param stickerLabel: $item.stickerLabel /} + {param stickerStyle: $item.stickerStyle /} + {param stickerShape: $item.stickerShape /} {/call} {/foreach} diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js index ec01cf100..c63dbed46 100644 --- a/packages/clay-table/src/ClayTableItem.js +++ b/packages/clay-table/src/ClayTableItem.js @@ -113,6 +113,42 @@ ClayTableItem.STATE = { * @default undefined */ spritemap: Config.string().required(), + + /** + * The path to the SVG spritemap file containing the icons. + * @instance + * @memberof ClayTableItem + * @type {?string|undefined} + * @default undefined + */ + stickerLabel: Config.string(), + + /** + * The path to the SVG spritemap file containing the icons. + * @instance + * @memberof ClayTableItem + * @type {?string} + * @default primary + */ + stickerStyle: Config.oneOf([ + 'danger', + 'dark', + 'info', + 'light', + 'primary', + 'secondary', + 'success', + 'warning', + ]).value('primary'), + + /** + * The path to the SVG spritemap file containing the icons. + * @instance + * @memberof ClayTableItem + * @type {?string} + * @default circle + */ + stickerShape: Config.string().value('circle'), }; defineWebComponent('clay-table-item', ClayTableItem); diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index 7706cfbc4..f33597ece 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -22,8 +22,6 @@ status: string, value: int ], - stickerLabel: string, - stickerStyle: string, text: string, url: string, useEllipse: bool @@ -35,6 +33,9 @@ {@param? inputValue: string} {@param? selectable: bool} {@param? selected: bool} + {@param? stickerLabel: string} + {@param? stickerStyle: string} + {@param? stickerShape: string} {let $attributes kind="attributes"} class=" @@ -62,6 +63,9 @@ {param selectable: $selectable /} {param selected: $selected /} {param spritemap: $spritemap /} + {param stickerLabel: $stickerLabel /} + {param stickerStyle: $stickerStyle /} + {param stickerShape: $stickerShape /} {/call} {/if} @@ -89,8 +93,6 @@ status: string, value: int ], - stickerLabel: string, - stickerStyle: string, text: string, url: string, useEllipse: bool @@ -101,6 +103,9 @@ {@param? inputValue: string} {@param? selectable: bool} {@param? selected: bool} + {@param? stickerLabel: string} + {@param? stickerStyle: string} + {@param? stickerShape: string} {if $selectable} {/if} + {if $stickerLabel} + + {/if} + {if $columns} {foreach $column in $columns} {let $isColumnFirst: index($column) == '0' and not $selectable or index($column) == '1' and $selectable /} @@ -123,8 +138,6 @@ {param label: $column.label /} {param labelStyle: $column.labelStyle /} {param progressBar: $column.progressBar /} - {param stickerLabel: $column.stickerLabel /} - {param stickerStyle: $column.stickerStyle /} {param text: $column.text /} {param url: $column.url /} {param useEllipse: $column.useEllipse /} @@ -160,17 +173,12 @@ status: string, value: int ]} - {@param? stickerLabel: string} - {@param? stickerStyle: string} {@param? text: string} {@param? url: string} {@param? useEllipse: bool} {let $textContent kind="html"} {call .text} - {param isColumnFirst: $isColumnFirst /} - {param stickerLabel: $stickerLabel /} - {param stickerStyle: $stickerStyle /} {param text: $text /} {param url: $url /} {/call} @@ -213,25 +221,11 @@ * This renders a text of the column. */ {template .text} - {@param? isColumnFirst: bool} - {@param? stickerLabel: string} - {@param? stickerStyle: string} {@param? text: string} {@param? url: string} - {let $textContent kind="html"} - {if $stickerLabel and $isColumnFirst} - {call ClaySticker.render} - {param label: $stickerLabel /} - {param shape: 'circle' /} - {param style: $stickerStyle /} - {/call} - {/if} - {$text} - {/let} - {if $text and not $url} - {$textContent} + {$text} {elseif $text and $url} {call ClayLink.render} {param href: $url /} diff --git a/packages/clay-table/src/items_validator.js b/packages/clay-table/src/items_validator.js index cd9e5dfcd..4f3668394 100644 --- a/packages/clay-table/src/items_validator.js +++ b/packages/clay-table/src/items_validator.js @@ -24,17 +24,6 @@ let columns = { status: Config.oneOf(['complete', 'warning']), value: Config.number(), }), - stickerLabel: Config.any(), - stickerStyle: Config.oneOf([ - 'danger', - 'dark', - 'info', - 'light', - 'primary', - 'secondary', - 'success', - 'warning', - ]).value('primary'), text: Config.string(), url: Config.string(), useEllipse: Config.bool().value(false), @@ -49,6 +38,18 @@ let items = { inputValue: Config.string(), selectable: Config.bool().value(false), selected: Config.bool().value(false), + stickerLabel: Config.string(), + stickerStyle: Config.oneOf([ + 'danger', + 'dark', + 'info', + 'light', + 'primary', + 'secondary', + 'success', + 'warning', + ]).value('primary'), + stickerShape: Config.string().value('circle'), }; const actionsItemsValidator = Config.arrayOf(Config.shapeOf(actionItems)); From d8cf140d342fb20f16ec9599d2f1da2e513aa1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 15:19:04 -0300 Subject: [PATCH 07/29] Update ClayTableItem tests with use the sticker --- packages/clay-table/src/__tests__/ClayTableItem.js | 4 ++-- .../src/__tests__/__snapshots__/ClayTable.js.snap | 10 ++++++---- .../src/__tests__/__snapshots__/ClayTableItem.js.snap | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/clay-table/src/__tests__/ClayTableItem.js b/packages/clay-table/src/__tests__/ClayTableItem.js index 3a405c629..871e7e735 100644 --- a/packages/clay-table/src/__tests__/ClayTableItem.js +++ b/packages/clay-table/src/__tests__/ClayTableItem.js @@ -64,13 +64,13 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - stickerLabel: 'AA', - stickerStyle: 'primary', text: 'Name', useEllipse: true, }, ], spritemap: spritemap, + stickerLabel: 'AA', + stickerStyle: 'primary', }); expect(component).toMatchSnapshot(); diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap index 0b6b09ae1..ab4f5970a 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap @@ -16,10 +16,12 @@ exports[`ClayTable should render a ClayTable with multiples columns in header 1`
- {if $item.label} - {$item.label} - {/if} -
+ {if $item.label} + {$item.label} + {/if} + {if $item.sort} + {call ClayIcon.render} + {param spritemap: $spritemap /} + {param symbol: 'order-arrow-down' /} + {/call} + {/if} +
@@ -114,6 +119,16 @@ + {call ClaySticker.render} + {param label: $stickerLabel /} + {param shape: $stickerShape ?: 'circle' /} + {param style: $stickerStyle /} + {/call} +
- - - - + + + + + +
TitleAuthorSizeStatus
TitleAuthorSizeStatus
diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap index 27c33a569..03c3244f5 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap @@ -230,9 +230,11 @@ exports[`ClayTableItem should render the ClayTableItem with label in the column exports[`ClayTableItem should render the ClayTableItem with user sticker in the column 1`] = ` + + AA + - - AAName + Name `; From 97f012f8dfea4dfe2f3a3e28c144e6603e250689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 19:47:15 -0300 Subject: [PATCH 08/29] Fix JSDOC on ClayTableItem --- packages/clay-table/src/ClayTableItem.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js index c63dbed46..dee23c8e0 100644 --- a/packages/clay-table/src/ClayTableItem.js +++ b/packages/clay-table/src/ClayTableItem.js @@ -115,7 +115,7 @@ ClayTableItem.STATE = { spritemap: Config.string().required(), /** - * The path to the SVG spritemap file containing the icons. + * Sets the text to be rendered inside sticker. * @instance * @memberof ClayTableItem * @type {?string|undefined} @@ -124,7 +124,17 @@ ClayTableItem.STATE = { stickerLabel: Config.string(), /** - * The path to the SVG spritemap file containing the icons. + * Shape of sticker. Available shapes are `circle`, `rounded`. + * @instance + * @memberof ClayTableItem + * @type {?string} + * @default circle + */ + stickerShape: Config.string().value('circle'), + + /** + * Sticker style. Available sizes are: `danger`, `dark`, `info`, `light`, + * `primary`, `secondary`, `success`, `warning`. * @instance * @memberof ClayTableItem * @type {?string} @@ -140,15 +150,6 @@ ClayTableItem.STATE = { 'success', 'warning', ]).value('primary'), - - /** - * The path to the SVG spritemap file containing the icons. - * @instance - * @memberof ClayTableItem - * @type {?string} - * @default circle - */ - stickerShape: Config.string().value('circle'), }; defineWebComponent('clay-table-item', ClayTableItem); From f8a639872f104efa381853b732ad4f68b4f7991b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 21:07:19 -0300 Subject: [PATCH 09/29] Add handleSortColumn with icon direction in ClayTable --- packages/clay-table/src/ClayTable.js | 11 ++++++++++- packages/clay-table/src/ClayTable.soy | 18 +++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/clay-table/src/ClayTable.js b/packages/clay-table/src/ClayTable.js index ba9f272a9..3bede4616 100644 --- a/packages/clay-table/src/ClayTable.js +++ b/packages/clay-table/src/ClayTable.js @@ -10,7 +10,14 @@ import templates from './ClayTable.soy.js'; /** * Metal ClayTable component. */ -class ClayTable extends Component {} +class ClayTable extends Component { + /** + * Handle button sort in header. + */ + handleSortColum_(event) { + this.emit('buttonSortClicked', event); + } +} /** * State definition. @@ -37,8 +44,10 @@ ClayTable.STATE = { header: Config.arrayOf( Config.shapeOf({ colSpan: Config.number(), + elementClasses: Config.string(), label: Config.string(), sort: Config.bool().value(false), + sortDirection_: Config.oneOf(['down', 'up']).value('down'), }) ), diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index b69ee2e53..b1e108f33 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -9,8 +9,10 @@ {@param? header: list<[ colSpan: int, label: string, - sort: bool + sort: bool, + sortDirection_: string ]>} + {@param? handleSortColum_: any} {@param? id: string} {@param? items: list<[ actionItems: list<[ @@ -70,13 +72,15 @@ {/let} - {if $item.label} + {if $item.label and not $item.sort} {$item.label} - {/if} - {if $item.sort} - {call ClayIcon.render} + {elseif $item.sort and $item.label} + {call ClayLink.render} + {param events: ['click': $handleSortColum_] /} + {param href: '#sort' /} + {param icon: 'order-arrow-' + $item.sortDirection_ ?: 'down' /} + {param iconAlignment: 'right' /} {param spritemap: $spritemap /} - {param symbol: 'order-arrow-down' /} {/call} {/if} @@ -98,8 +102,8 @@ {param selected: $item.selected /} {param spritemap: $spritemap /} {param stickerLabel: $item.stickerLabel /} - {param stickerStyle: $item.stickerStyle /} {param stickerShape: $item.stickerShape /} + {param stickerStyle: $item.stickerStyle /} {/call} {/foreach} From e4839e38e116dfbf1d4efd0d5e7a804346b91c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 21:00:55 -0300 Subject: [PATCH 10/29] Add elementClasses for th and td columns in ClayTable and ClayTableItem --- packages/clay-table/src/ClayTable.soy | 8 ++++++++ packages/clay-table/src/ClayTableItem.soy | 22 ++++++++++++++++------ packages/clay-table/src/items_validator.js | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index b1e108f33..596c4eb55 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -8,6 +8,7 @@ {@param? elementClasses: string} {@param? header: list<[ colSpan: int, + elementClasses: string, label: string, sort: bool, sortDirection_: string @@ -24,6 +25,7 @@ url: string ]>, columns: list<[ + elementClasses: string, label: string, labelStyle: string, progressBar: [ @@ -66,6 +68,12 @@ {foreach $item in $header} {let $thAttributes kind="attributes"} + class=" + {if $item.elementClasses} + {$item.elementClasses} + {/if} + " + {if $item.colSpan} colspan="{$item.colSpan}" {/if} diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index f33597ece..0a8f6f990 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -14,6 +14,7 @@ url: string ]>} {@param? columns: list<[ + elementClasses: string, label: string, labelStyle: string, progressBar: [ @@ -34,8 +35,8 @@ {@param? selectable: bool} {@param? selected: bool} {@param? stickerLabel: string} - {@param? stickerStyle: string} {@param? stickerShape: string} + {@param? stickerStyle: string} {let $attributes kind="attributes"} class=" @@ -64,8 +65,8 @@ {param selected: $selected /} {param spritemap: $spritemap /} {param stickerLabel: $stickerLabel /} - {param stickerStyle: $stickerStyle /} {param stickerShape: $stickerShape /} + {param stickerStyle: $stickerStyle /} {/call} {/if} @@ -85,6 +86,7 @@ url: string ]>} {@param? columns: list<[ + elementClasses: string, label: string, labelStyle: string, progressBar: [ @@ -104,8 +106,8 @@ {@param? selectable: bool} {@param? selected: bool} {@param? stickerLabel: string} - {@param? stickerStyle: string} {@param? stickerShape: string} + {@param? stickerStyle: string} {if $selectable} @@ -134,6 +136,7 @@ {let $isColumnFirst: index($column) == '0' and not $selectable or index($column) == '1' and $selectable /} {delcall ClayTableItem.Column variant="$contentRenderer"} + {param elementClasses: $column.elementClasses /} {param isColumnFirst: $isColumnFirst /} {param label: $column.label /} {param labelStyle: $column.labelStyle /} @@ -164,6 +167,7 @@ * This renders a multiples columns of the row. */ {deltemplate ClayTableItem.Column} + {@param? elementClasses: string} {@param? isColumnFirst: bool} {@param? label: string} {@param? labelStyle: string} @@ -207,9 +211,15 @@ {/let} {let $attributes kind="attributes"} - {if $useEllipse} - class="table-cell-content" - {/if} + class=" + {if $elementClasses} + {$elementClasses} + {/if} + + {if $useEllipse} + {sp}table-cell-content + {/if} + " {/let} diff --git a/packages/clay-table/src/items_validator.js b/packages/clay-table/src/items_validator.js index 4f3668394..0f2f41dd3 100644 --- a/packages/clay-table/src/items_validator.js +++ b/packages/clay-table/src/items_validator.js @@ -10,6 +10,7 @@ let actionItems = { }; let columns = { + elementClasses: Config.string(), label: Config.string(), labelStyle: Config.oneOf([ 'danger', From 62d8493947fb511f80a97c7831088a3478cce46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 21:01:41 -0300 Subject: [PATCH 11/29] Update demo --- packages/clay-table/demos/index.html | 126 +++++++++++++++------------ 1 file changed, 68 insertions(+), 58 deletions(-) diff --git a/packages/clay-table/demos/index.html b/packages/clay-table/demos/index.html index 3b9daf091..c30976298 100644 --- a/packages/clay-table/demos/index.html +++ b/packages/clay-table/demos/index.html @@ -70,11 +70,10 @@

new metal.ClayTable({ header: [ + {}, { - label: '' - }, - { - label: 'Title' + label: 'Title', + sort: true }, { label: 'Author' @@ -91,9 +90,7 @@

{ label: 'Modified Date' }, - { - label: '' - } + {} ], items: [ { @@ -216,134 +213,147 @@

new metal.ClayTable({ header: [ + {}, { - label: 'Title' - }, - { - label: 'Author' - }, - { - label: 'Size' + label: 'Title', + colSpan: 2 }, { label: 'Status' }, { - label: 'Creation Date' + label: 'Items' }, { - label: 'Modified Date' + label: 'Start Date' }, { - - } + label: 'Duration' + }, + {}, + {} ], items: [ { - group: 'Group 1' + group: 'In progress' }, { actionItems: actionItems, columns: [ { - stickerLabel: 'AA', - stickerStyle: 'primary', - text: 'Name', + text: 'Publication Ttitle', useEllipse: true }, { - text: 'Juan Anton' + label: 'In progress', + labelStyle: 'warning' }, { - text: '264KB' + text: '100.000' }, - {}, { - text: '15 Minutes Ago' + text: '2017.11.24 - 17:15' }, { - text: '15 Minutes Ago' + text: '4 Minutes' + }, + { + progressBar: { + value: 30 + } } - ] + ], + selectable: true, + stickerLabel: 'MT', + stickerStyle: 'danger', }, { actionItems: actionItems, columns: [ { - text: 'suffing-photo-ReallySuperInsanelyJustIncrediblyLongAndTotallyNotPossibleWordButWeAreReallyTryingToCoverAllOurBasesHereJustInCaseSomeoneIsNutsAsPerUsual.jpg', + text: 'Publication Ttitle', useEllipse: true }, { - text: 'Juan Anton' + label: 'In progress', + labelStyle: 'warning' }, { - text: '264KB' + text: '10' }, { - progressBar: { - value: 40 - } + text: '2017.11.24 - 17:15' }, { - text: '15 Minutes Ago' + text: '45 hours' }, { - text: '15 Minutes Ago' + progressBar: { + value: 30 + } } - ] + ], + selectable: true, + stickerLabel: 'BB', + stickerStyle: 'danger', + }, + { + group: 'Sdheduled' }, { actionItems: actionItems, columns: [ { - text: 'suffing-photo-ReallySuperInsanelyJustIncrediblyLongAndTotallyNotPossibleWordButWeAreReallyTryingToCoverAllOurBasesHereJustInCaseSomeoneIsNutsAsPerUsual.jpg', + text: 'Publication Ttitle', useEllipse: true }, { - text: 'Juan Anton' + label: 'Sdheduled', + labelStyle: 'info' }, { - text: '264KB' + text: '20' }, { - label: 'Rejected', - labelStyle: 'danger' + text: '2017.11.24 - 17:15' }, { - text: '15 Minutes Ago' + text: '1 hour' }, - { - text: '15 Minutes Ago' - } - ] + {} + ], + selectable: true, + stickerLabel: 'CC', + stickerStyle: 'danger', }, { - group: 'Group 2' + group: 'Completed' }, { actionItems: actionItems, columns: [ { - text: 'suffing-photo-ReallySuperInsanelyJustIncrediblyLongAndTotallyNotPossibleWordButWeAreReallyTryingToCoverAllOurBasesHereJustInCaseSomeoneIsNutsAsPerUsual.jpg', + text: 'Publication Ttitle', useEllipse: true }, { - text: 'Juan Anton' + label: 'Successful', + labelStyle: 'success' }, { - text: '264KB' + text: '29.999' }, { - label: 'In progress', - labelStyle: 'warning' + text: '2017.11.24 - 17:15' }, { - text: '15 Minutes Ago' + text: '4 Minutes' }, - { - text: '15 Minutes Ago' - } - ] + {} + ], + selectable: true, + stickerLabel: 'AA', + stickerStyle: 'danger', } ], spritemap: spritemap From f60349d3ad556737b5fc25eb883825d0afd631d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 21:17:33 -0300 Subject: [PATCH 12/29] SF --- packages/clay-table/src/ClayTable.js | 1 + packages/clay-table/src/ClayTable.soy | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/clay-table/src/ClayTable.js b/packages/clay-table/src/ClayTable.js index 3bede4616..aff7c2f2d 100644 --- a/packages/clay-table/src/ClayTable.js +++ b/packages/clay-table/src/ClayTable.js @@ -1,4 +1,5 @@ import './ClayTableItem'; +import 'clay-link'; import {Config} from 'metal-state'; import Component from 'metal-component'; import defineWebComponent from 'metal-web-component'; diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index 596c4eb55..2ea116d31 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -83,10 +83,12 @@ {if $item.label and not $item.sort} {$item.label} {elseif $item.sort and $item.label} + {let $icon: $item.sortDirection_ ?: 'down' /} + {call ClayLink.render} {param events: ['click': $handleSortColum_] /} {param href: '#sort' /} - {param icon: 'order-arrow-' + $item.sortDirection_ ?: 'down' /} + {param icon: 'order-arrow-{$icon}' /} {param iconAlignment: 'right' /} {param spritemap: $spritemap /} {/call} From ac75751a599f5f5b799fc6b7310e7bd64cce23c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Tue, 12 Dec 2017 21:26:47 -0300 Subject: [PATCH 13/29] Add support for images when using sticker on ClayTable --- packages/clay-table/src/ClayTable.soy | 4 ++++ packages/clay-table/src/ClayTableItem.js | 18 +++++++++++++++ packages/clay-table/src/ClayTableItem.soy | 26 +++++++++++++++++----- packages/clay-table/src/items_validator.js | 4 +++- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index 2ea116d31..6c7951b33 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -44,6 +44,8 @@ inputValue: string, selectable: bool, selected: bool, + stickerImageAlt: string, + stickerImageSrc: string, stickerLabel: string, stickerStyle: string, stickerShape: string @@ -111,6 +113,8 @@ {param selectable: $item.selectable /} {param selected: $item.selected /} {param spritemap: $spritemap /} + {param stickerImageAlt: $item.stickerImageAlt /} + {param stickerImageSrc: $item.stickerImageSrc /} {param stickerLabel: $item.stickerLabel /} {param stickerShape: $item.stickerShape /} {param stickerStyle: $item.stickerStyle /} diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js index dee23c8e0..506264fb3 100644 --- a/packages/clay-table/src/ClayTableItem.js +++ b/packages/clay-table/src/ClayTableItem.js @@ -114,6 +114,24 @@ ClayTableItem.STATE = { */ spritemap: Config.string().required(), + /** + * Alternate text of the image sticker. + * @instance + * @memberof ClayTableItem + * @type {?string|undefined} + * @default undefined + */ + stickerImageAlt: Config.string(), + + /** + * Source of the image to be rendered inside the sticker. + * @instance + * @memberof ClayTableItem + * @type {?string|undefined} + * @default undefined + */ + stickerImageSrc: Config.string(), + /** * Sets the text to be rendered inside sticker. * @instance diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index 0a8f6f990..b44e40b72 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -34,6 +34,8 @@ {@param? inputValue: string} {@param? selectable: bool} {@param? selected: bool} + {@param? stickerImageAlt: string} + {@param? stickerImageSrc: string} {@param? stickerLabel: string} {@param? stickerShape: string} {@param? stickerStyle: string} @@ -64,6 +66,8 @@ {param selectable: $selectable /} {param selected: $selected /} {param spritemap: $spritemap /} + {param stickerImageAlt: $stickerImageAlt /} + {param stickerImageSrc: $stickerImageSrc /} {param stickerLabel: $stickerLabel /} {param stickerShape: $stickerShape /} {param stickerStyle: $stickerStyle /} @@ -105,6 +109,8 @@ {@param? inputValue: string} {@param? selectable: bool} {@param? selected: bool} + {@param? stickerImageAlt: string} + {@param? stickerImageSrc: string} {@param? stickerLabel: string} {@param? stickerShape: string} {@param? stickerStyle: string} @@ -121,13 +127,21 @@ {/if} - {if $stickerLabel} + {if $stickerLabel or $stickerImageSrc} - {call ClaySticker.render} - {param label: $stickerLabel /} - {param shape: $stickerShape ?: 'circle' /} - {param style: $stickerStyle /} - {/call} + {if $stickerImageSrc} + {call ClaySticker.render} + {param imageAlt: $stickerImageAlt /} + {param imageSrc: $stickerImageSrc /} + {param shape: $stickerShape ?: 'circle' /} + {/call} + {else} + {call ClaySticker.render} + {param label: $stickerLabel /} + {param shape: $stickerShape ?: 'circle' /} + {param style: $stickerStyle /} + {/call} + {/if} {/if} diff --git a/packages/clay-table/src/items_validator.js b/packages/clay-table/src/items_validator.js index 0f2f41dd3..ab4106646 100644 --- a/packages/clay-table/src/items_validator.js +++ b/packages/clay-table/src/items_validator.js @@ -39,7 +39,10 @@ let items = { inputValue: Config.string(), selectable: Config.bool().value(false), selected: Config.bool().value(false), + stickerImageAlt: Config.string(), + stickerImageSrc: Config.string(), stickerLabel: Config.string(), + stickerShape: Config.string().value('circle'), stickerStyle: Config.oneOf([ 'danger', 'dark', @@ -50,7 +53,6 @@ let items = { 'success', 'warning', ]).value('primary'), - stickerShape: Config.string().value('circle'), }; const actionsItemsValidator = Config.arrayOf(Config.shapeOf(actionItems)); From fab40d33d2c235b75d658cf3d653d73267be8cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Wed, 13 Dec 2017 12:03:48 -0300 Subject: [PATCH 14/29] Rename ClayTableItem url params to href --- packages/clay-table/demos/index.html | 3 +- packages/clay-table/src/ClayTable.soy | 6 +- packages/clay-table/src/ClayTableItem.soy | 49 ++++++++------- .../clay-table/src/__tests__/ClayTableItem.js | 22 +++---- .../__tests__/__snapshots__/ClayTable.js.snap | 32 +++++----- .../__snapshots__/ClayTableItem.js.snap | 61 ++++++++++--------- packages/clay-table/src/items_validator.js | 4 +- 7 files changed, 90 insertions(+), 87 deletions(-) diff --git a/packages/clay-table/demos/index.html b/packages/clay-table/demos/index.html index c30976298..804dd9266 100644 --- a/packages/clay-table/demos/index.html +++ b/packages/clay-table/demos/index.html @@ -106,7 +106,8 @@

useEllipse: true }, { - text: 'Juan Anton' + text: 'Juan Anton', + href: '#1' }, { text: '264KB' diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index 6c7951b33..e7f587937 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -18,14 +18,15 @@ {@param? items: list<[ actionItems: list<[ disabled: bool, + href: string, icon: string, label: string, quickAction: bool, - separator: bool, - url: string + separator: bool ]>, columns: list<[ elementClasses: string, + href: string, label: string, labelStyle: string, progressBar: [ @@ -35,7 +36,6 @@ value: int ], text: string, - url: string, useEllipse: bool ]>, disabled: bool, diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index b44e40b72..716ae8bb9 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -7,14 +7,15 @@ {@param spritemap: string} {@param? actionItems: list<[ disabled: bool, + href: string, icon: string, label: string, quickAction: bool, - separator: bool, - url: string + separator: bool ]>} {@param? columns: list<[ elementClasses: string, + href: string, label: string, labelStyle: string, progressBar: [ @@ -24,7 +25,6 @@ value: int ], text: string, - url: string, useEllipse: bool ]>} {@param? contentRenderer: string} @@ -83,14 +83,15 @@ {@param spritemap: string} {@param? actionItems: list<[ disabled: bool, + href: string, icon: string, label: string, quickAction: bool, - separator: bool, - url: string + separator: bool ]>} {@param? columns: list<[ elementClasses: string, + href: string, label: string, labelStyle: string, progressBar: [ @@ -100,7 +101,6 @@ value: int ], text: string, - url: string, useEllipse: bool ]>} {@param? contentRenderer: string} @@ -151,12 +151,12 @@ {delcall ClayTableItem.Column variant="$contentRenderer"} {param elementClasses: $column.elementClasses /} + {param href: $column.href /} {param isColumnFirst: $isColumnFirst /} {param label: $column.label /} {param labelStyle: $column.labelStyle /} {param progressBar: $column.progressBar /} {param text: $column.text /} - {param url: $column.url /} {param useEllipse: $column.useEllipse /} {/delcall} {/foreach} @@ -182,6 +182,7 @@ */ {deltemplate ClayTableItem.Column} {@param? elementClasses: string} + {@param? href: string} {@param? isColumnFirst: bool} {@param? label: string} {@param? labelStyle: string} @@ -192,13 +193,12 @@ value: int ]} {@param? text: string} - {@param? url: string} {@param? useEllipse: bool} {let $textContent kind="html"} {call .text} + {param href: $href /} {param text: $text /} - {param url: $url /} {/call} {/let} @@ -224,19 +224,17 @@ {/if} {/let} - {let $attributes kind="attributes"} - class=" - {if $elementClasses} - {$elementClasses} - {/if} + {let $classes kind="text"} + {if $elementClasses} + {$elementClasses} + {/if} - {if $useEllipse} - {sp}table-cell-content - {/if} - " + {if $useEllipse} + {sp}table-cell-content + {/if} {/let} - + {$content} {/deltemplate} @@ -245,14 +243,15 @@ * This renders a text of the column. */ {template .text} + {@param? href: string} {@param? text: string} - {@param? url: string} - {if $text and not $url} + {if $text and not $href} {$text} - {elseif $text and $url} + {elseif $text and $href} + {log}{$href}{/log} {call ClayLink.render} - {param href: $url /} + {param href: $href /} {param label: $text /} {/call} {/if} @@ -268,7 +267,7 @@ label: string, quickAction: bool, separator: bool, - url: string + href: string ]>} {@param spritemap: string} @@ -277,7 +276,7 @@ {if $item.quickAction and $item.icon} {call ClayLink.render} {param elementClasses: 'quick-action-item' /} - {param href: $item.url /} + {param href: $item.href /} {param label kind="html"} {call ClayIcon.render} {param spritemap: $spritemap /} diff --git a/packages/clay-table/src/__tests__/ClayTableItem.js b/packages/clay-table/src/__tests__/ClayTableItem.js index 871e7e735..95ccd15d8 100644 --- a/packages/clay-table/src/__tests__/ClayTableItem.js +++ b/packages/clay-table/src/__tests__/ClayTableItem.js @@ -110,16 +110,16 @@ describe('ClayTableItem', function() { actionItems: [ { label: 'Option 1', - url: '#1', + href: '#1', }, { label: 'Option 2', separator: true, - url: '#2', + href: '#2', }, { label: 'Option 3', - url: '#3', + href: '#3', }, ], spritemap: spritemap, @@ -135,20 +135,20 @@ describe('ClayTableItem', function() { icon: 'trash', label: 'Option 1', quickAction: true, - url: '#1', + href: '#1', }, { icon: 'download', label: 'Option 2', quickAction: true, separator: true, - url: '#2', + href: '#2', }, { icon: 'info-circle-open', label: 'Option 3', quickAction: true, - url: '#3', + href: '#3', }, ], spritemap: spritemap, @@ -166,7 +166,7 @@ describe('ClayTableItem', function() { }, { text: 'Bar', - url: '#1', + href: '#1', }, { text: 'Foo', @@ -191,7 +191,7 @@ describe('ClayTableItem', function() { }, { text: 'Bar', - url: '#1', + href: '#1', }, { text: 'Foo', @@ -217,7 +217,7 @@ describe('ClayTableItem', function() { }, { text: 'Bar', - url: '#1', + href: '#1', }, { text: 'Foo', @@ -243,7 +243,7 @@ describe('ClayTableItem', function() { }, { text: 'Bar', - url: '#1', + href: '#1', }, { text: 'Foo', @@ -269,7 +269,7 @@ describe('ClayTableItem', function() { }, { text: 'Bar', - url: '#1', + href: '#1', }, { text: 'Foo', diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap index ab4f5970a..4b7cd1011 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap @@ -17,10 +17,10 @@ exports[`ClayTable should render a ClayTable with multiples columns in header 1` - - - - + + + +
TitleAuthorSizeStatusTitleAuthorSizeStatus
@@ -32,28 +32,28 @@ exports[`ClayTable should render a ClayTable with multiples items 1`] = ` - - - - + + - - + + - - - - + + - - + +
+ suffing-photo.png Juan Anton264KB + Juan Anton264KB Approved 15 Minutes Ago15 Minutes Ago15 Minutes Ago15 Minutes Ago
+ suffing-photo.png Juan Anton264KB + Juan Anton264KB Approved 15 Minutes Ago15 Minutes Ago15 Minutes Ago15 Minutes Ago
diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap index 03c3244f5..a3b90d505 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap @@ -11,14 +11,14 @@ exports[`ClayTableItem should render the ClayTableItem disabled 1`] = ` - + Foo - + Bar - Foo - Bar + Foo + Bar `; @@ -33,14 +33,14 @@ exports[`ClayTableItem should render the ClayTableItem selectable 1`] = ` - + Foo - + Bar - Foo - Bar + Foo + Bar `; @@ -55,20 +55,20 @@ exports[`ClayTableItem should render the ClayTableItem selected 1`] = ` - + Foo - + Bar - Foo - Bar + Foo + Bar `; exports[`ClayTableItem should render the ClayTableItem with ClayProgressBar in the column 1`] = ` - +
@@ -86,6 +86,7 @@ exports[`ClayTableItem should render the ClayTableItem with actionItems 1`] = ` `; +exports[`ClayTable should render a ClayTable with colspan in columns header 1`] = ` +
+ + + + + + + +
FooBar
+
+`; + +exports[`ClayTable should render a ClayTable with elementClasses in the columns 1`] = ` +
+ + + + + + + + + + + + + +
FooBar
FooBar
+
+`; + exports[`ClayTable should render a ClayTable with id 1`] = `
@@ -33,7 +65,9 @@ exports[`ClayTable should render a ClayTable with multiples items 1`] = ` - suffing-photo.png + + suffing-photo.png + Juan Anton 264KB @@ -45,7 +79,9 @@ exports[`ClayTable should render a ClayTable with multiples items 1`] = ` - suffing-photo.png + + suffing-photo.png + Juan Anton 264KB diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap index dd5859d83..d7971e69d 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap @@ -1,5 +1,18 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`ClayTableItem should render ClayTableItem with sticker shape \`rounded\` 1`] = ` + + + + Image + + + + Name + + +`; + exports[`ClayTableItem should render ClayTableItem with sticker with image in column 1`] = ` @@ -79,20 +92,7 @@ exports[`ClayTableItem should render the ClayTableItem selected 1`] = ` `; -exports[`ClayTableItem should render the ClayTableItem with ClayProgressBar in the column 1`] = ` - - -
-
-
-
-
40%
-
- - -`; - -exports[`ClayTableItem should render the ClayTableItem with actionItems 1`] = ` +exports[`ClayTableItem should render the ClayTableItem with action menu 1`] = `
@@ -122,29 +122,21 @@ exports[`ClayTableItem should render the ClayTableItem with actionItems 1`] = ` `; -exports[`ClayTableItem should render the ClayTableItem with actionItems and quick menu 1`] = ` +exports[`ClayTableItem should render the ClayTableItem with columns 1`] = ` - - + + Foo + + Bar + Foo + Bar + +`; + +exports[`ClayTableItem should render the ClayTableItem with custom classes in column of \`action menu\` 1`] = ` + + +
+ + +`; + exports[`ClayTableItem should render the ClayTableItem with user sticker in the column 1`] = ` From 9011c4f46537b5d8c54e5aceee2b177a6901e7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Thu, 14 Dec 2017 00:14:22 -0300 Subject: [PATCH 20/29] SF --- packages/clay-table/demos/index.html | 6 +++--- packages/clay-table/package.json | 8 ++++---- packages/clay-table/src/ClayTable.soy | 6 +++--- packages/clay-table/src/ClayTableItem.js | 12 ++++++------ packages/clay-table/src/ClayTableItem.soy | 8 ++++---- packages/clay-table/src/items_validator.js | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/clay-table/demos/index.html b/packages/clay-table/demos/index.html index 8019fdbe1..e5901f72f 100644 --- a/packages/clay-table/demos/index.html +++ b/packages/clay-table/demos/index.html @@ -580,7 +580,7 @@

Selectable Table with Selected Items

}, '#quick-action-menu-block'); /** - * Selectable Table with Action Menu + * Selectable Table with group separator */ new metal.ClayTable({ header: [ @@ -656,7 +656,7 @@

Selectable Table with Selected Items

}, '#group-block'); /** - * Selectable Table with Action Menu + * Selectable Table with Selected Items */ new metal.ClayTable({ header: [ @@ -726,7 +726,7 @@

Selectable Table with Selected Items

selectable: true, selectableElementClasses: 'custom-column', selected: true, - stickerElementClasses: 'custom-column' + stickerElementClasses: 'custom-column', stickerImageSrc: './image.jpg', } ], diff --git a/packages/clay-table/package.json b/packages/clay-table/package.json index ce9d4b432..566291055 100644 --- a/packages/clay-table/package.json +++ b/packages/clay-table/package.json @@ -1,6 +1,6 @@ { "name": "clay-table", - "version": "1.0.0-alpha.5", + "version": "1.0.0-alpha.8", "description": "Metal ClayTable component", "license": "BSD", "repository": "https://github.com/metal/metal-clay-components/tree/master/packages/clay-table", @@ -28,10 +28,10 @@ ], "dependencies": { "clay-checkbox": "^1.0.0-alpha.5", - "clay-dropdown": "^1.0.0-alpha.5", + "clay-dropdown": "^1.0.0-alpha.8", "clay-icon": "^1.0.0-alpha.5", - "clay-label": "^1.0.0-alpha.5", - "clay-link": "^1.0.0-alpha.5", + "clay-label": "^1.0.0-alpha.8", + "clay-link": "^1.0.0-alpha.8", "clay-progress-bar": "^1.0.0-alpha.5", "clay-sticker": "^1.0.0-alpha.5", "metal": "^2.14.0", diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index 5d65a2fd1..6ae791635 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -6,6 +6,7 @@ {template .render} {@param spritemap: string} {@param? elementClasses: string} + {@param? handleButtonSortColumn_: any} {@param? header: list<[ colSpan: int, elementClasses: string, @@ -13,9 +14,9 @@ sort: bool, sortDirection_: string ]>} - {@param? handleButtonSortColumn_: any} {@param? id: string} {@param? items: list<[ + actionColumnElementClasses: string, actionItems: list<[ disabled: bool, href: string, @@ -24,7 +25,6 @@ quickAction: bool, separator: bool ]>, - actionColumnElementClasses: string, columns: list<[ elementClasses: string, href: string, @@ -108,8 +108,8 @@ {foreach $item in $items} {call ClayTableItem.render} - {param actionItems: $item.actionItems /} {param actionColumnElementClasses: $item.actionColumnElementClasses /} + {param actionItems: $item.actionItems /} {param columns: $item.columns /} {param disabled: $item.disabled /} {param group: $item.group /} diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js index 7c6684c00..26c446277 100644 --- a/packages/clay-table/src/ClayTableItem.js +++ b/packages/clay-table/src/ClayTableItem.js @@ -25,22 +25,22 @@ class ClayTableItem extends Component {} */ ClayTableItem.STATE = { /** - * List of items to display in the actions menu. + * CSS classes to be applied to the td of the actions menu. * @instance * @memberof ClayTableItem - * @type {?array|undefined} + * @type {?string|undefined} * @default undefined */ - actionItems: actionsItemsValidator, + actionColumnElementClasses: Config.string(), /** - * CSS classes to be applied to the td of the dropdown. + * List of items to display in the actions menu. * @instance * @memberof ClayTableItem - * @type {?string|undefined} + * @type {?array|undefined} * @default undefined */ - actionColumnElementClasses: Config.string(), + actionItems: actionsItemsValidator, /** * List of the columns in the row. diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index 29ac516c9..7808d31a0 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -5,6 +5,7 @@ */ {template .render} {@param spritemap: string} + {@param? actionColumnElementClasses: string} {@param? actionItems: list<[ disabled: bool, href: string, @@ -13,7 +14,6 @@ quickAction: bool, separator: bool ]>} - {@param? actionColumnElementClasses: string} {@param? columns: list<[ elementClasses: string, href: string, @@ -60,8 +60,8 @@ {$group} {else} {call .content} - {param actionItems: $actionItems /} {param actionColumnElementClasses: $actionColumnElementClasses /} + {param actionItems: $actionItems /} {param columns: $columns /} {param contentRenderer: $contentRenderer /} {param disabled: $disabled /} @@ -87,6 +87,7 @@ */ {template .content} {@param spritemap: string} + {@param? actionColumnElementClasses: string} {@param? actionItems: list<[ disabled: bool, href: string, @@ -95,7 +96,6 @@ quickAction: bool, separator: bool ]>} - {@param? actionColumnElementClasses: string} {@param? columns: list<[ elementClasses: string, href: string, @@ -219,8 +219,8 @@ {/call} {elseif $progressBar} {call ClayProgressBar.render} - {param minValue: $progressBar.minValue /} {param maxValue: $progressBar.maxValue /} + {param minValue: $progressBar.minValue /} {param status: $progressBar.status /} {param value: $progressBar.value /} {/call} diff --git a/packages/clay-table/src/items_validator.js b/packages/clay-table/src/items_validator.js index 2e94df4bf..a42d99df3 100644 --- a/packages/clay-table/src/items_validator.js +++ b/packages/clay-table/src/items_validator.js @@ -31,8 +31,8 @@ let columns = { }; let items = { - actionItems: Config.arrayOf(Config.shapeOf(actionItems)), actionColumnElementClasses: Config.string(), + actionItems: Config.arrayOf(Config.shapeOf(actionItems)), columns: Config.arrayOf(Config.shapeOf(columns)), disabled: Config.bool().value(false), group: Config.string(), From 92523a817a476b570fd58de6ac6bc031b20fbabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Thu, 14 Dec 2017 01:02:14 -0300 Subject: [PATCH 21/29] Add support for sizes to ClayTable --- packages/clay-table/src/ClayTable.js | 9 +++++ packages/clay-table/src/ClayTable.soy | 12 +++++- .../clay-table/src/__tests__/ClayTable.js | 36 ++++++++++++++++++ .../__tests__/__snapshots__/ClayTable.js.snap | 38 +++++++++++++++---- 4 files changed, 86 insertions(+), 9 deletions(-) diff --git a/packages/clay-table/src/ClayTable.js b/packages/clay-table/src/ClayTable.js index a975f4a67..068b296bb 100644 --- a/packages/clay-table/src/ClayTable.js +++ b/packages/clay-table/src/ClayTable.js @@ -70,6 +70,15 @@ ClayTable.STATE = { */ items: itemsValidator, + /** + * Table responsive sizes. Available `lg`, `md`, `sm` and `xl`. + * @instance + * @memberof ClayTable + * @type {?string|undefined} + * @default undefined + */ + size: Config.oneOf(['lg', 'md', 'sm', 'xl']), + /** * The path to the SVG spritemap file containing the icons. * @instance diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index 6ae791635..2aa418873 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -53,9 +53,10 @@ stickerStyle: string, stickerShape: string ]>} + {@param? size: string} {let $attributes kind="attributes"} - class="table table-autofit table-heading-nowrap table-hover table-list show-quick-actions-on-hover + class="table table-autofit table-hover table-list show-quick-actions-on-hover {if $elementClasses} {sp}{$elementClasses} {/if} @@ -66,7 +67,14 @@ {/if} {/let} -
+ {let $classes kind="text"} + table-responsive + {if $size} + -{$size} + {/if} + {/let} + +
{if $header} diff --git a/packages/clay-table/src/__tests__/ClayTable.js b/packages/clay-table/src/__tests__/ClayTable.js index 266f9a794..47db71314 100644 --- a/packages/clay-table/src/__tests__/ClayTable.js +++ b/packages/clay-table/src/__tests__/ClayTable.js @@ -79,6 +79,42 @@ describe('ClayTable', function() { expect(component).toMatchSnapshot(); }); + it('should render a ClayTable with size `lg`', () => { + component = new ClayTable({ + size: 'lg', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render a ClayTable with size `md`', () => { + component = new ClayTable({ + size: 'md', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render a ClayTable with size `sm`', () => { + component = new ClayTable({ + size: 'sm', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render a ClayTable with size `xl`', () => { + component = new ClayTable({ + size: 'xl', + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + it('should render a ClayTable with id', () => { component = new ClayTable({ id: 'myId', diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap index 6424cad6b..c06f70c72 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap @@ -2,13 +2,13 @@ exports[`ClayTable should render a ClayTable with classes 1`] = `
-
+
`; exports[`ClayTable should render a ClayTable with colspan in columns header 1`] = `
- +
@@ -21,7 +21,7 @@ exports[`ClayTable should render a ClayTable with colspan in columns header 1`] exports[`ClayTable should render a ClayTable with elementClasses in the columns 1`] = `
-
Foo
+
@@ -40,13 +40,13 @@ exports[`ClayTable should render a ClayTable with elementClasses in the columns exports[`ClayTable should render a ClayTable with id 1`] = `
-
Foo
+
`; exports[`ClayTable should render a ClayTable with multiples columns in header 1`] = `
- +
@@ -61,7 +61,7 @@ exports[`ClayTable should render a ClayTable with multiples columns in header 1` exports[`ClayTable should render a ClayTable with multiples items 1`] = `
-
Title
+
- {foreach $item in $header} - {let $thAttributes kind="attributes"} - class=" - {if $item.elementClasses} - {$item.elementClasses} - {/if} - " - - {if $item.colSpan} - colspan="{$item.colSpan}" - {/if} - {/let} - - - {/foreach} + {call .header} + {param handleSortColumn_: $handleSortColumn_ /} + {param header: $header /} + {param spritemap: $spritemap /} + {/call} {/if} {if $items} - {foreach $item in $items} - {call ClayTableItem.render} - {param actionColumnElementClasses: $item.actionColumnElementClasses /} - {param actionItems: $item.actionItems /} - {param columns: $item.columns /} - {param disabled: $item.disabled /} - {param group: $item.group /} - {param inputName: $item.inputName /} - {param inputValue: $item.inputValue /} - {param selectable: $item.selectable /} - {param selectableElementClasses: $item.selectableElementClasses /} - {param selected: $item.selected /} - {param spritemap: $spritemap /} - {param stickerElementClasses: $item.stickerElementClasses /} - {param stickerImageAlt: $item.stickerImageAlt /} - {param stickerImageSrc: $item.stickerImageSrc /} - {param stickerLabel: $item.stickerLabel /} - {param stickerShape: $item.stickerShape /} - {param stickerStyle: $item.stickerStyle /} - {/call} - {/foreach} + {call .body} + {param handleClickCheckbox_: $handleClickCheckbox_ /} + {param items: $items /} + {param spritemap: $spritemap /} + {/call} {/if}
@@ -96,8 +96,32 @@ exports[`ClayTable should render a ClayTable with multiples items 1`] = ` `; +exports[`ClayTable should render a ClayTable with size \`lg\` 1`] = ` +
+
+
+`; + +exports[`ClayTable should render a ClayTable with size \`md\` 1`] = ` +
+
+
+`; + +exports[`ClayTable should render a ClayTable with size \`sm\` 1`] = ` +
+
+
+`; + +exports[`ClayTable should render a ClayTable with size \`xl\` 1`] = ` +
+
+
+`; + exports[`ClayTable should render the default markup 1`] = `
-
+
`; From 7154d958a7d0c652e7372833383131d9c0b866dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Fri, 15 Dec 2017 16:43:59 -0300 Subject: [PATCH 22/29] Add supported to focus the quick actions menus in ClayTable --- packages/clay-table/package.json | 6 ++- packages/clay-table/src/ClayTable.js | 57 +++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/packages/clay-table/package.json b/packages/clay-table/package.json index 566291055..b9d1daf37 100644 --- a/packages/clay-table/package.json +++ b/packages/clay-table/package.json @@ -34,11 +34,13 @@ "clay-link": "^1.0.0-alpha.8", "clay-progress-bar": "^1.0.0-alpha.5", "clay-sticker": "^1.0.0-alpha.5", - "metal": "^2.14.0", "metal-component": "^2.14.0", + "metal-dom": "^2.14.0", + "metal-events": "^2.14.0", "metal-soy": "^2.14.0", "metal-state": "^2.14.0", - "metal-web-component": "^2.14.0" + "metal-web-component": "^2.14.0", + "metal": "^2.14.0" }, "devDependencies": { "babel-cli": "^6.24.1", diff --git a/packages/clay-table/src/ClayTable.js b/packages/clay-table/src/ClayTable.js index 068b296bb..1d73785ee 100644 --- a/packages/clay-table/src/ClayTable.js +++ b/packages/clay-table/src/ClayTable.js @@ -1,8 +1,10 @@ import './ClayTableItem'; import 'clay-link'; import {Config} from 'metal-state'; +import {EventHandler} from 'metal-events'; import Component from 'metal-component'; import defineWebComponent from 'metal-web-component'; +import dom from 'metal-dom'; import itemsValidator from './items_validator'; import Soy from 'metal-soy'; @@ -12,11 +14,62 @@ import templates from './ClayTable.soy.js'; * Metal ClayTable component. */ class ClayTable extends Component { + /** + * @inheritDoc + */ + attached() { + this.eventHandler_.add( + dom.delegate( + document, + 'click', + 'body', + this.handleClickDocument_.bind(this) + ), + dom.delegate(this.element, 'focus', 'tr', this.handleFocus_) + ); + } + + /** + * @inheritDoc + */ + created() { + this.eventHandler_ = new EventHandler(); + } + + /** + * @inheritDoc + */ + detached() { + super.detached(); + this.eventHandler_.removeAllListeners(); + } + + /** + * Handle click in document for remove the class `table-focus` of tr. + * @private + */ + handleClickDocument_() { + dom.removeClasses(this.element.querySelectorAll('tr'), 'table-focus'); + } + + /** + * Handle focus the tr for add class `table-focus`. + * @private + */ + handleFocus_(event) { + const getFirstTable = dom.closest(event.target, 'table'); + const getFirstTr = dom.closest(event.target, 'tr'); + + dom.removeClasses(getFirstTable.querySelectorAll('tr'), 'table-focus'); + dom.addClasses(getFirstTr, 'table-focus'); + } + /** * Handle button sort in header. + * @private */ - handleButtonSortColumn_(event) { - this.emit('buttonSortClicked', event); + handleSortColumn_(event) { + this.emit('sortClick', event); } } From 11f29ed77917f0fe797ccda99aa997f08d25f260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Fri, 15 Dec 2017 17:38:59 -0300 Subject: [PATCH 23/29] Add table-active when change checkbox and improve the using of groups in ClayTable --- packages/clay-table/src/ClayTable.js | 12 +- packages/clay-table/src/ClayTable.soy | 166 +++++++++++++++------- packages/clay-table/src/ClayTableItem.js | 23 +-- packages/clay-table/src/ClayTableItem.soy | 88 ++++-------- 4 files changed, 164 insertions(+), 125 deletions(-) diff --git a/packages/clay-table/src/ClayTable.js b/packages/clay-table/src/ClayTable.js index 1d73785ee..d54a59a80 100644 --- a/packages/clay-table/src/ClayTable.js +++ b/packages/clay-table/src/ClayTable.js @@ -44,6 +44,15 @@ class ClayTable extends Component { this.eventHandler_.removeAllListeners(); } + /** + * Propagate the change of the checkbox event. + * @param {!Event} event + * @private + */ + handleClickCheckbox_(event) { + this.emit('itemToggled', event); + } + /** * Handle click in document for remove the class `table-focus` of tr. * @private @@ -54,6 +63,7 @@ class ClayTable extends Component { /** * Handle focus the tr for add class `table-focus`. + * @param {!Event} event * @private */ handleFocus_(event) { @@ -69,7 +79,7 @@ class ClayTable extends Component { * @private */ handleSortColumn_(event) { - this.emit('sortClick', event); + this.emit('sortColumn', event); } } diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index 2aa418873..52df2e860 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -6,7 +6,8 @@ {template .render} {@param spritemap: string} {@param? elementClasses: string} - {@param? handleButtonSortColumn_: any} + {@param? handleClickCheckbox_: any} + {@param? handleSortColumn_: any} {@param? header: list<[ colSpan: int, elementClasses: string, @@ -43,6 +44,7 @@ group: string, inputName: string, inputValue: string, + items: list, selectable: bool, selectableElementClasses: string, selected: bool, @@ -79,64 +81,124 @@ {if $header}
- {if $item.label and not $item.sort} - {$item.label} - {elseif $item.sort and $item.label} - {let $icon: $item.sortDirection_ ?: 'down' /} - - {call ClayLink.render} - {param events: ['click': $handleButtonSortColumn_] /} - {param href: '#sort' /} - {param icon: 'order-arrow-' + $icon /} - {param iconAlignment: 'right' /} - {param label: $item.label /} - {param spritemap: $spritemap /} - {/call} - {/if} -
{/template} + +/** + * This renders a rows of the table. + */ +{template .body} + {@param items: list} + {@param spritemap: string} + {@param? handleClickCheckbox_: any} + + {foreach $item in $items} + {if $item.group} + + {$item.group} + + {if $item.items} + {foreach $itemToGroup in $item.items} + {call ClayTableItem.render} + {param actionColumnElementClasses: $itemToGroup.actionColumnElementClasses /} + {param actionItems: $itemToGroup.actionItems /} + {param columns: $itemToGroup.columns /} + {param disabled: $itemToGroup.disabled /} + {param events: ['itemToggled': $handleClickCheckbox_] /} + {param inputName: $itemToGroup.inputName /} + {param inputValue: $itemToGroup.inputValue /} + {param selectable: $itemToGroup.selectable /} + {param selectableElementClasses: $itemToGroup.selectableElementClasses /} + {param selected: $itemToGroup.selected /} + {param spritemap: $spritemap /} + {param stickerElementClasses: $itemToGroup.stickerElementClasses /} + {param stickerImageAlt: $itemToGroup.stickerImageAlt /} + {param stickerImageSrc: $itemToGroup.stickerImageSrc /} + {param stickerLabel: $itemToGroup.stickerLabel /} + {param stickerShape: $itemToGroup.stickerShape /} + {param stickerStyle: $itemToGroup.stickerStyle /} + {/call} + {/foreach} + {/if} + {else} + {call ClayTableItem.render} + {param actionColumnElementClasses: $item.actionColumnElementClasses /} + {param actionItems: $item.actionItems /} + {param columns: $item.columns /} + {param disabled: $item.disabled /} + {param events: ['itemToggled': $handleClickCheckbox_] /} + {param inputName: $item.inputName /} + {param inputValue: $item.inputValue /} + {param selectable: $item.selectable /} + {param selectableElementClasses: $item.selectableElementClasses /} + {param selected: $item.selected /} + {param spritemap: $spritemap /} + {param stickerElementClasses: $item.stickerElementClasses /} + {param stickerImageAlt: $item.stickerImageAlt /} + {param stickerImageSrc: $item.stickerImageSrc /} + {param stickerLabel: $item.stickerLabel /} + {param stickerShape: $item.stickerShape /} + {param stickerStyle: $item.stickerStyle /} + {/call} + {/if} + {/foreach} +{/template} + +/** + * This renders columns to the header of the table. + */ +{template .header} + {@param header: list} + {@param spritemap: string} + {@param? handleSortColumn_: any} + + {foreach $item in $header} + {let $thAttributes kind="attributes"} + class=" + {if $item.elementClasses} + {$item.elementClasses} + {/if} + " + + {if $item.colSpan} + colspan="{$item.colSpan}" + {/if} + {/let} + + + {if $item.label and not $item.sort} + {$item.label} + {elseif $item.sort and $item.label} + {let $icon: $item.sortDirection_ ?: 'down' /} + + {call ClayLink.render} + {param events: ['click': $handleSortColumn_] /} + {param href: '#sort' /} + {param icon: 'order-arrow-' + $icon /} + {param iconAlignment: 'right' /} + {param id: '' + index($item) /} + {param label: $item.label /} + {param spritemap: $spritemap /} + {/call} + {/if} + + {/foreach} +{/template} diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js index 26c446277..ec6798329 100644 --- a/packages/clay-table/src/ClayTableItem.js +++ b/packages/clay-table/src/ClayTableItem.js @@ -9,6 +9,7 @@ import {actionsItemsValidator, columnsValidator} from './items_validator'; import {Config} from 'metal-state'; import Component from 'metal-component'; import defineWebComponent from 'metal-web-component'; +import dom from 'metal-dom'; import Soy from 'metal-soy'; import templates from './ClayTableItem.soy.js'; @@ -16,7 +17,18 @@ import templates from './ClayTableItem.soy.js'; /** * Metal ClayTableItem component. */ -class ClayTableItem extends Component {} +class ClayTableItem extends Component { + /** + * Handle input of type `checkbox` for add class `table-active` in tr. + * @param {!Event} event + * @private + */ + handleItemToggled_(event) { + dom.toggleClasses(this.element, 'table-active'); + + this.emit('itemToggled', event); + } +} /** * State definition. @@ -69,15 +81,6 @@ ClayTableItem.STATE = { */ disabled: Config.bool().value(false), - /** - * Table group separator. - * @instance - * @memberof ClayTableItem - * @type {?string|undefined} - * @default undefined - */ - group: Config.string(), - /** * Name to be applied to the input element. * @instance diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index 7808d31a0..aeec73323 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -30,7 +30,7 @@ ]>} {@param? contentRenderer: string} {@param? disabled: bool} - {@param? group: string} + {@param? handleItemToggled_: any} {@param? inputName: string} {@param? inputValue: string} {@param? selectable: bool} @@ -48,37 +48,30 @@ {if $selectable and $selected} table-active {/if} - - {if $group} - table-divider - {/if} " {/let} - {if $group} - {$group} - {else} - {call .content} - {param actionColumnElementClasses: $actionColumnElementClasses /} - {param actionItems: $actionItems /} - {param columns: $columns /} - {param contentRenderer: $contentRenderer /} - {param disabled: $disabled /} - {param inputName: $inputName /} - {param inputValue: $inputValue /} - {param selectable: $selectable /} - {param selectableElementClasses: $selectableElementClasses /} - {param selected: $selected /} - {param spritemap: $spritemap /} - {param stickerElementClasses: $stickerElementClasses /} - {param stickerImageAlt: $stickerImageAlt /} - {param stickerImageSrc: $stickerImageSrc /} - {param stickerLabel: $stickerLabel /} - {param stickerShape: $stickerShape /} - {param stickerStyle: $stickerStyle /} - {/call} - {/if} + {call .content} + {param actionColumnElementClasses: $actionColumnElementClasses /} + {param actionItems: $actionItems /} + {param columns: $columns /} + {param contentRenderer: $contentRenderer /} + {param disabled: $disabled /} + {param handleItemToggled_: $handleItemToggled_ /} + {param inputName: $inputName /} + {param inputValue: $inputValue /} + {param selectable: $selectable /} + {param selectableElementClasses: $selectableElementClasses /} + {param selected: $selected /} + {param spritemap: $spritemap /} + {param stickerElementClasses: $stickerElementClasses /} + {param stickerImageAlt: $stickerImageAlt /} + {param stickerImageSrc: $stickerImageSrc /} + {param stickerLabel: $stickerLabel /} + {param stickerShape: $stickerShape /} + {param stickerStyle: $stickerStyle /} + {/call} {/template} @@ -88,30 +81,11 @@ {template .content} {@param spritemap: string} {@param? actionColumnElementClasses: string} - {@param? actionItems: list<[ - disabled: bool, - href: string, - icon: string, - label: string, - quickAction: bool, - separator: bool - ]>} - {@param? columns: list<[ - elementClasses: string, - href: string, - label: string, - labelStyle: string, - progressBar: [ - maxValue: int, - minValue: int, - status: string, - value: int - ], - text: string, - useEllipse: bool - ]>} + {@param? actionItems: list} + {@param? columns: list} {@param? contentRenderer: string} {@param? disabled: bool} + {@param? handleItemToggled_: any} {@param? inputName: string} {@param? inputValue: string} {@param? selectable: bool} @@ -129,6 +103,7 @@ {call ClayCheckbox.render} {param checked: $selected /} {param disabled: $disabled /} + {param events: ['change': $handleItemToggled_] /} {param hideLabel: true /} {param name: $inputName /} {param value: $inputValue /} @@ -156,12 +131,9 @@ {if $columns} {foreach $column in $columns} - {let $isColumnFirst: index($column) == '0' and not $selectable or index($column) == '1' and $selectable /} - {delcall ClayTableItem.Column variant="$contentRenderer"} {param elementClasses: $column.elementClasses /} {param href: $column.href /} - {param isColumnFirst: $isColumnFirst /} {param label: $column.label /} {param labelStyle: $column.labelStyle /} {param progressBar: $column.progressBar /} @@ -192,7 +164,6 @@ {deltemplate ClayTableItem.Column} {@param? elementClasses: string} {@param? href: string} - {@param? isColumnFirst: bool} {@param? label: string} {@param? labelStyle: string} {@param? progressBar: [ @@ -269,14 +240,7 @@ * This renders the quick actions menu. */ {template .quickMenu} - {@param actionItems: list<[ - disabled: bool, - icon: string, - label: string, - quickAction: bool, - separator: bool, - href: string - ]>} + {@param actionItems: list} {@param spritemap: string}
From 8a90db1949b9dd80a78ca1c13e7f1639887f30fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Fri, 15 Dec 2017 17:44:24 -0300 Subject: [PATCH 24/29] Update the ClayTable demo using groups --- packages/clay-table/demos/index.html | 147 +++++++++++++++++++-------- 1 file changed, 102 insertions(+), 45 deletions(-) diff --git a/packages/clay-table/demos/index.html b/packages/clay-table/demos/index.html index e5901f72f..3ebd58777 100644 --- a/packages/clay-table/demos/index.html +++ b/packages/clay-table/demos/index.html @@ -122,20 +122,20 @@

Selectable Table with Selected Items

icon: 'trash', label: 'Option 1', quickAction: true, - url: '#1', + href: '#1', }, { icon: 'download', label: 'Option 2', quickAction: true, separator: true, - url: '#2', + href: '#2', }, { icon: 'info-circle-open', label: 'Option 3', quickAction: true, - url: '#3', + href: '#3', }, ]; @@ -601,55 +601,112 @@

Selectable Table with Selected Items

], items: [ { - actionItems: actionItemsWithQuickItems, - actionColumnElementClasses: 'custom-column', - columns: [ - { - text: 'Foo' - }, - { - label: 'Approved', - labelStyle: 'success' - }, - { - progressBar: { - maxValue: 100, - minValue: 0, - value: 80 - } + items: [ + { + actionItems: actionItemsWithQuickItems, + actionColumnElementClasses: 'custom-column', + columns: [ + { + text: 'Foo' + }, + { + label: 'Approved', + labelStyle: 'success' + }, + { + progressBar: { + maxValue: 100, + minValue: 0, + value: 80 + } + } + ], + selectable: true, + selectableElementClasses: 'custom-column', + stickerLabel: 'MT', + stickerStyle: 'danger', + stickerElementClasses: 'custom-column' + }, + { + actionItems: actionItemsWithQuickItems, + actionColumnElementClasses: 'custom-column', + columns: [ + { + text: 'Bar' + }, + { + label: 'Approved', + labelStyle: 'success' + }, + { + progressBar: { + maxValue: 100, + minValue: 0, + value: 80 + } + } + ], + selectable: true, + selectableElementClasses: 'custom-column', + stickerLabel: 'MT', + stickerStyle: 'danger', + stickerElementClasses: 'custom-column' } ], - selectable: true, - selectableElementClasses: 'custom-column', - stickerLabel: 'MT', - stickerStyle: 'danger', - stickerElementClasses: 'custom-column' - }, - { group: 'Group 1' }, { - actionItems: actionItemsWithQuickItems, - actionColumnElementClasses: 'custom-column', - columns: [ - { - text: 'Foo' - }, - { - label: 'In progress', - labelStyle: 'warning' - }, - { - progressBar: { - status: 'warning', - value: 20 - } + items: [ + { + actionItems: actionItemsWithQuickItems, + actionColumnElementClasses: 'custom-column', + columns: [ + { + text: 'Foo' + }, + { + label: 'In progress', + labelStyle: 'warning' + }, + { + progressBar: { + status: 'warning', + value: 20 + } + } + ], + selectable: true, + selectableElementClasses: 'custom-column', + stickerImageSrc: './image.jpg', + stickerElementClasses: 'custom-column' + }, + { + actionItems: actionItemsWithQuickItems, + actionColumnElementClasses: 'custom-column', + columns: [ + { + text: 'Bar' + }, + { + label: 'Approved', + labelStyle: 'success' + }, + { + progressBar: { + maxValue: 100, + minValue: 0, + value: 80 + } + } + ], + selectable: true, + selectableElementClasses: 'custom-column', + stickerLabel: 'MT', + stickerStyle: 'danger', + stickerElementClasses: 'custom-column' } ], - selectable: true, - selectableElementClasses: 'custom-column', - stickerImageSrc: './image.jpg', - stickerElementClasses: 'custom-column' + group: 'Group 2' } ], spritemap: spritemap From 89a22463ad8f9e957a4cd7c6b91346439cd3271e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Fri, 15 Dec 2017 18:02:04 -0300 Subject: [PATCH 25/29] Update the ClayTable and ClayTableItem test --- .../clay-table/src/__tests__/ClayTable.js | 34 +++++++++++++++++++ .../clay-table/src/__tests__/ClayTableItem.js | 26 ++++++++++++-- .../__tests__/__snapshots__/ClayTable.js.snap | 21 ++++++++++++ .../__snapshots__/ClayTableItem.js.snap | 6 ---- 4 files changed, 78 insertions(+), 9 deletions(-) diff --git a/packages/clay-table/src/__tests__/ClayTable.js b/packages/clay-table/src/__tests__/ClayTable.js index 47db71314..c3433aa7a 100644 --- a/packages/clay-table/src/__tests__/ClayTable.js +++ b/packages/clay-table/src/__tests__/ClayTable.js @@ -204,6 +204,40 @@ describe('ClayTable', function() { expect(component).toMatchSnapshot(); }); + it('should render the ClayTable with group', () => { + component = new ClayTable({ + items: [ + { + items: [ + { + columns: [ + { + text: 'Foo', + }, + ], + }, + ], + group: 'Group 1', + }, + { + items: [ + { + columns: [ + { + text: 'Foo', + }, + ], + }, + ], + group: 'Group 2', + }, + ], + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + it('should fail when no spritemap is passed', () => { expect(() => { component = new ClayTable(); diff --git a/packages/clay-table/src/__tests__/ClayTableItem.js b/packages/clay-table/src/__tests__/ClayTableItem.js index b1ec58a1d..439029851 100644 --- a/packages/clay-table/src/__tests__/ClayTableItem.js +++ b/packages/clay-table/src/__tests__/ClayTableItem.js @@ -386,13 +386,33 @@ describe('ClayTableItem', function() { expect(component).toMatchSnapshot(); }); - it('should render the ClayTableItem with group', () => { + it('should render a selectable ClayTableItem and emit an event on itemToggle', () => { component = new ClayTableItem({ - group: 'Group 1', + columns: [ + { + text: 'Foo', + }, + { + text: 'Bar', + href: '#1', + }, + { + text: 'Foo', + }, + { + text: 'Bar', + }, + ], + selectable: true, spritemap: spritemap, }); - expect(component).toMatchSnapshot(); + const spy = jest.spyOn(component, 'emit'); + + component.element.querySelector('input[type="checkbox"]').click(); + + expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith('itemToggled', expect.any(Object)); }); it('should fail when no spritemap is passed', () => { diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap index c06f70c72..89369437f 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap @@ -120,6 +120,27 @@ exports[`ClayTable should render a ClayTable with size \`xl\` 1`] = `
`; +exports[`ClayTable should render the ClayTable with group 1`] = ` +
+ + + + + + + + + + + + + + + +
Group 1
Foo
Group 2
Foo
+
+`; + exports[`ClayTable should render the default markup 1`] = `
diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap index d7971e69d..9203ecdf0 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap @@ -198,12 +198,6 @@ exports[`ClayTableItem should render the ClayTableItem with custom classes in co exports[`ClayTableItem should render the ClayTableItem with custom element class 1`] = ``; -exports[`ClayTableItem should render the ClayTableItem with group 1`] = ` - - Group 1 - -`; - exports[`ClayTableItem should render the ClayTableItem with id 1`] = ``; exports[`ClayTableItem should render the ClayTableItem with input name 1`] = ` From 473894103ceaa43321f7ab2079a2b9d56a2f8c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Fri, 15 Dec 2017 18:03:55 -0300 Subject: [PATCH 26/29] Ignore ClayTable in mcritic --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 70597f2d8..2a88a95f5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "jest": "jest", "lerna": "lerna bootstrap -- --no-optional --no-package-lock", "lint": "eslint packages/clay-*/src/*.js packages/clay-*/src/**/*.js && npm run mcritic", - "mcritic": "mcritic packages/ --ignore '**/{browserslist-config-clay-components,generator-metal-clay,clay-dropdown,clay-alert,clay-list,clay-management-toolbar,clay-card,node_modules}/**'", + "mcritic": "mcritic packages/ --ignore '**/{browserslist-config-clay-components,generator-metal-clay,clay-dropdown,clay-alert,clay-list,clay-management-toolbar,clay-card,clay-table,node_modules}/**'", "precommit": "lint-staged", "prettier": "prettier-eslint packages/clay-*/src/*.js packages/clay-*/src/**/*.js", "start": "http-server . -p 4000", From 9730ca69e04862a638a0046bf7f3610f7be21f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Fri, 15 Dec 2017 18:14:03 -0300 Subject: [PATCH 27/29] Update table-cell-content to table-cell-expand in ClayTableItem --- packages/clay-table/src/ClayTableItem.soy | 2 +- .../__tests__/__snapshots__/ClayTable.js.snap | 4 ++-- .../__snapshots__/ClayTableItem.js.snap | 22 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index aeec73323..cfdda1be9 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -210,7 +210,7 @@ {/if} {if $useEllipse} - {sp}table-cell-content + {sp}table-cell-expand {/if} {/let} diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap index 89369437f..72c30f3d8 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTable.js.snap @@ -64,7 +64,7 @@ exports[`ClayTable should render a ClayTable with multiples items 1`] = ` - - - @@ -20,7 +20,7 @@ exports[`ClayTableItem should render ClayTableItem with sticker with image in co Image - @@ -37,7 +37,7 @@ exports[`ClayTableItem should render the ClayTableItem disabled 1`] = ` - - - - @@ -168,7 +168,7 @@ exports[`ClayTableItem should render the ClayTableItem with custom classes in co - @@ -185,7 +185,7 @@ exports[`ClayTableItem should render the ClayTableItem with custom classes in co - - - - From 8a0b1a9c8bc1d810da23e53cab66ac76164be33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Fri, 15 Dec 2017 19:07:39 -0300 Subject: [PATCH 28/29] Improve the ClayTable API and add button support --- packages/clay-table/demos/index.html | 112 ++++++++++-------- packages/clay-table/package.json | 1 + packages/clay-table/src/ClayTable.soy | 3 +- packages/clay-table/src/ClayTableItem.js | 1 + packages/clay-table/src/ClayTableItem.soy | 41 ++++--- .../clay-table/src/__tests__/ClayTable.js | 30 ++--- .../clay-table/src/__tests__/ClayTableItem.js | 101 ++++++++++------ .../__snapshots__/ClayTableItem.js.snap | 24 ++++ packages/clay-table/src/items_validator.js | 5 +- 9 files changed, 203 insertions(+), 115 deletions(-) diff --git a/packages/clay-table/demos/index.html b/packages/clay-table/demos/index.html index 3ebd58777..5fcbf15c7 100644 --- a/packages/clay-table/demos/index.html +++ b/packages/clay-table/demos/index.html @@ -104,16 +104,16 @@

Selectable Table with Selected Items

let actionItems = [ { label: 'Option 1', - url: '#1', + href: '#1', }, { label: 'Option 2', separator: true, - url: '#2', + href: '#2', }, { label: 'Option 3', - url: '#3', + href: '#3', }, ]; @@ -155,20 +155,20 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo' + label: 'Foo' }, { - text: 'Bar' + label: 'Bar' } ] }, { columns: [ { - text: 'Foo' + label: 'Foo' }, { - text: 'Bar' + label: 'Bar' } ] } @@ -192,22 +192,22 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo', + label: 'Foo', href: '#foo' }, { - text: 'Bar' + label: 'Bar' } ] }, { columns: [ { - text: 'Foo', + label: 'Foo', href: '#foo' }, { - text: 'Bar' + label: 'Bar' } ] } @@ -231,22 +231,24 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' } ] }, { columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'In progress', - labelStyle: 'warning' + labelStyle: 'warning', + type: 'label' } ] } @@ -271,11 +273,12 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -289,11 +292,12 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'In progress', - labelStyle: 'warning' + labelStyle: 'warning', + type: 'label' }, { progressBar: { @@ -327,11 +331,12 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -347,11 +352,12 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'In progress', - labelStyle: 'warning' + labelStyle: 'warning', + type: 'label' }, { progressBar: { @@ -388,11 +394,12 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -411,11 +418,12 @@

Selectable Table with Selected Items

{ columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'In progress', - labelStyle: 'warning' + labelStyle: 'warning', + type: 'label' }, { progressBar: { @@ -459,11 +467,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -484,11 +493,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'In progress', - labelStyle: 'warning' + labelStyle: 'warning', + type: 'label' }, { progressBar: { @@ -532,11 +542,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -557,11 +568,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'In progress', - labelStyle: 'warning' + labelStyle: 'warning', + type: 'label' }, { progressBar: { @@ -607,11 +619,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -632,11 +645,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Bar' + label: 'Bar' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -662,11 +676,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'In progress', - labelStyle: 'warning' + labelStyle: 'warning', + type: 'label' }, { progressBar: { @@ -685,11 +700,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Bar' + label: 'Bar' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -738,11 +754,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'Approved', - labelStyle: 'success' + labelStyle: 'success', + type: 'label' }, { progressBar: { @@ -767,11 +784,12 @@

Selectable Table with Selected Items

actionColumnElementClasses: 'custom-column', columns: [ { - text: 'Foo' + label: 'Foo' }, { label: 'In progress', - labelStyle: 'warning' + labelStyle: 'warning', + type: 'label' }, { progressBar: { diff --git a/packages/clay-table/package.json b/packages/clay-table/package.json index b9d1daf37..1868c66aa 100644 --- a/packages/clay-table/package.json +++ b/packages/clay-table/package.json @@ -27,6 +27,7 @@ "metal" ], "dependencies": { + "clay-button": "^1.0.0-alpha.8", "clay-checkbox": "^1.0.0-alpha.5", "clay-dropdown": "^1.0.0-alpha.8", "clay-icon": "^1.0.0-alpha.5", diff --git a/packages/clay-table/src/ClayTable.soy b/packages/clay-table/src/ClayTable.soy index 52df2e860..d3defa41a 100644 --- a/packages/clay-table/src/ClayTable.soy +++ b/packages/clay-table/src/ClayTable.soy @@ -27,6 +27,7 @@ separator: bool ]>, columns: list<[ + buttonStyle: string, elementClasses: string, href: string, label: string, @@ -37,7 +38,7 @@ status: string, value: int ], - text: string, + type: string, useEllipse: bool ]>, disabled: bool, diff --git a/packages/clay-table/src/ClayTableItem.js b/packages/clay-table/src/ClayTableItem.js index ec6798329..511461cfa 100644 --- a/packages/clay-table/src/ClayTableItem.js +++ b/packages/clay-table/src/ClayTableItem.js @@ -1,3 +1,4 @@ +import 'clay-button'; import 'clay-checkbox'; import 'clay-dropdown'; import 'clay-icon'; diff --git a/packages/clay-table/src/ClayTableItem.soy b/packages/clay-table/src/ClayTableItem.soy index cfdda1be9..e636c8313 100644 --- a/packages/clay-table/src/ClayTableItem.soy +++ b/packages/clay-table/src/ClayTableItem.soy @@ -15,6 +15,7 @@ separator: bool ]>} {@param? columns: list<[ + buttonStyle: string, elementClasses: string, href: string, label: string, @@ -25,7 +26,7 @@ status: string, value: int ], - text: string, + type: string, useEllipse: bool ]>} {@param? contentRenderer: string} @@ -132,12 +133,13 @@ {if $columns} {foreach $column in $columns} {delcall ClayTableItem.Column variant="$contentRenderer"} + {param buttonStyle: $column.buttonStyle /} {param elementClasses: $column.elementClasses /} {param href: $column.href /} {param label: $column.label /} {param labelStyle: $column.labelStyle /} {param progressBar: $column.progressBar /} - {param text: $column.text /} + {param type: $column.type ?: 'text' /} {param useEllipse: $column.useEllipse /} {/delcall} {/foreach} @@ -162,6 +164,7 @@ * This renders a multiples columns of the row. */ {deltemplate ClayTableItem.Column} + {@param? buttonStyle: string} {@param? elementClasses: string} {@param? href: string} {@param? label: string} @@ -172,18 +175,18 @@ status: string, value: int ]} - {@param? text: string} + {@param? type: string} {@param? useEllipse: bool} - {let $textContent kind="html"} - {call .text} + {let $labelContent kind="html"} + {call .label} {param href: $href /} - {param text: $text /} + {param label: $label /} {/call} {/let} {let $content kind="html"} - {if $label} + {if $type == 'label'} {call ClayLabel.render} {param label: $label /} {param style: $labelStyle /} @@ -195,11 +198,17 @@ {param status: $progressBar.status /} {param value: $progressBar.value /} {/call} - {elseif $text} + {elseif $type == 'button'} + {call ClayButton.render} + {param label: $label /} + {param size: 'sm' /} + {param style: $labelStyle /} + {/call} + {elseif $type == 'text'} {if $useEllipse} - {$textContent} + {$labelContent} {else} - {$textContent} + {$labelContent} {/if} {/if} {/let} @@ -222,17 +231,17 @@ /** * This renders a text of the column. */ -{template .text} +{template .label} {@param? href: string} - {@param? text: string} + {@param? label: string} - {if $text and not $href} - {$text} - {elseif $text and $href} + {if $label and $href} {call ClayLink.render} {param href: $href /} - {param label: $text /} + {param label: $label /} {/call} + {else} + {$label} {/if} {/template} diff --git a/packages/clay-table/src/__tests__/ClayTable.js b/packages/clay-table/src/__tests__/ClayTable.js index c3433aa7a..528cf83a3 100644 --- a/packages/clay-table/src/__tests__/ClayTable.js +++ b/packages/clay-table/src/__tests__/ClayTable.js @@ -7,24 +7,25 @@ let items = [ columns: [ { href: '#1', - text: 'suffing-photo.png', + label: 'suffing-photo.png', useEllipse: true, }, { - text: 'Juan Anton', + label: 'Juan Anton', }, { - text: '264KB', + label: '264KB', }, { label: 'Approved', labelStyle: 'success', + type: 'label', }, { - text: '15 Minutes Ago', + label: '15 Minutes Ago', }, { - text: '15 Minutes Ago', + label: '15 Minutes Ago', }, ], }, @@ -32,24 +33,25 @@ let items = [ columns: [ { href: '#1', - text: 'suffing-photo.png', + label: 'suffing-photo.png', useEllipse: true, }, { - text: 'Juan Anton', + label: 'Juan Anton', }, { - text: '264KB', + label: '264KB', }, { label: 'Approved', labelStyle: 'success', + type: 'label', }, { - text: '15 Minutes Ago', + label: '15 Minutes Ago', }, { - text: '15 Minutes Ago', + label: '15 Minutes Ago', }, ], }, @@ -189,11 +191,11 @@ describe('ClayTable', function() { columns: [ { elementClasses: 'custom1-column', - text: 'Foo', + label: 'Foo', }, { elementClasses: 'custom2-column', - text: 'Bar', + label: 'Bar', }, ], }, @@ -212,7 +214,7 @@ describe('ClayTable', function() { { columns: [ { - text: 'Foo', + label: 'Foo', }, ], }, @@ -224,7 +226,7 @@ describe('ClayTable', function() { { columns: [ { - text: 'Foo', + label: 'Foo', }, ], }, diff --git a/packages/clay-table/src/__tests__/ClayTableItem.js b/packages/clay-table/src/__tests__/ClayTableItem.js index 439029851..6318a3c4c 100644 --- a/packages/clay-table/src/__tests__/ClayTableItem.js +++ b/packages/clay-table/src/__tests__/ClayTableItem.js @@ -40,18 +40,18 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Foo', + label: 'Foo', useEllipse: true, }, { - text: 'Bar', + label: 'Bar', url: '#1', }, { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', }, ], spritemap: spritemap, @@ -64,7 +64,7 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Name', + label: 'Name', useEllipse: true, }, ], @@ -80,7 +80,7 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Name', + label: 'Name', useEllipse: true, }, ], @@ -97,7 +97,7 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Name', + label: 'Name', useEllipse: true, }, ], @@ -113,7 +113,7 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Name', + label: 'Name', useEllipse: true, }, ], @@ -147,6 +147,7 @@ describe('ClayTableItem', function() { { label: 'Approved', labelStyle: 'success', + type: 'label', }, ], spritemap: spritemap, @@ -235,18 +236,18 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Foo', + label: 'Foo', useEllipse: true, }, { - text: 'Bar', + label: 'Bar', href: '#1', }, { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', }, ], selectable: true, @@ -260,18 +261,18 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Foo', + label: 'Foo', useEllipse: true, }, { - text: 'Bar', + label: 'Bar', href: '#1', }, { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', }, ], selectable: true, @@ -286,18 +287,18 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Foo', + label: 'Foo', useEllipse: true, }, { - text: 'Bar', + label: 'Bar', href: '#1', }, { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', }, ], selectable: true, @@ -312,18 +313,18 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Foo', + label: 'Foo', useEllipse: true, }, { - text: 'Bar', + label: 'Bar', href: '#1', }, { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', }, ], selectable: true, @@ -338,18 +339,18 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Foo', + label: 'Foo', useEllipse: true, }, { - text: 'Bar', + label: 'Bar', href: '#1', }, { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', }, ], inputName: 'name', @@ -364,18 +365,18 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Foo', + label: 'Foo', useEllipse: true, }, { - text: 'Bar', + label: 'Bar', href: '#1', }, { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', }, ], inputValue: 'value', @@ -390,17 +391,17 @@ describe('ClayTableItem', function() { component = new ClayTableItem({ columns: [ { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', href: '#1', }, { - text: 'Foo', + label: 'Foo', }, { - text: 'Bar', + label: 'Bar', }, ], selectable: true, @@ -415,6 +416,34 @@ describe('ClayTableItem', function() { expect(spy).toHaveBeenCalledWith('itemToggled', expect.any(Object)); }); + it('should render the ClayTableItem with button', () => { + component = new ClayTableItem({ + columns: [ + { + label: 'Foo', + useEllipse: true, + }, + { + label: 'Bar', + href: '#1', + }, + { + label: 'Foo', + }, + { + label: 'Bar', + buttonStyle: 'primary', + type: 'button', + }, + ], + inputValue: 'value', + selectable: true, + spritemap: spritemap, + }); + + expect(component).toMatchSnapshot(); + }); + it('should fail when no spritemap is passed', () => { expect(() => { component = new ClayTableItem(); diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap index 128347069..3fe6c52e8 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap @@ -122,6 +122,30 @@ exports[`ClayTableItem should render the ClayTableItem with action menu 1`] = ` `; +exports[`ClayTableItem should render the ClayTableItem with button 1`] = ` +
+ + + + + + +`; + exports[`ClayTableItem should render the ClayTableItem with columns 1`] = `
+ suffing-photo.png @@ -78,7 +78,7 @@ exports[`ClayTable should render a ClayTable with multiples items 1`] = ` 15 Minutes Ago
+ suffing-photo.png diff --git a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap index 9203ecdf0..128347069 100644 --- a/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap +++ b/packages/clay-table/src/__tests__/__snapshots__/ClayTableItem.js.snap @@ -7,7 +7,7 @@ exports[`ClayTableItem should render ClayTableItem with sticker shape \`rounded\ Image + Name
+ Name
+ Foo @@ -59,7 +59,7 @@ exports[`ClayTableItem should render the ClayTableItem selectable 1`] = ` + Foo @@ -81,7 +81,7 @@ exports[`ClayTableItem should render the ClayTableItem selected 1`] = ` + Foo @@ -124,7 +124,7 @@ exports[`ClayTableItem should render the ClayTableItem with action menu 1`] = ` exports[`ClayTableItem should render the ClayTableItem with columns 1`] = `
+ Foo Bar AA + Name
+ Foo @@ -211,7 +211,7 @@ exports[`ClayTableItem should render the ClayTableItem with input name 1`] = ` + Foo @@ -233,7 +233,7 @@ exports[`ClayTableItem should render the ClayTableItem with input value 1`] = ` + Foo @@ -319,7 +319,7 @@ exports[`ClayTableItem should render the ClayTableItem with user sticker in the AA + Name
+
+ +
+
+ Foo + + Bar + Foo + +
diff --git a/packages/clay-table/src/items_validator.js b/packages/clay-table/src/items_validator.js index a42d99df3..1478b49b8 100644 --- a/packages/clay-table/src/items_validator.js +++ b/packages/clay-table/src/items_validator.js @@ -10,6 +10,9 @@ let actionItems = { }; let columns = { + buttonStyle: Config.oneOf(['link', 'primary', 'secondary']).value( + 'primary' + ), elementClasses: Config.string(), href: Config.string(), label: Config.string(), @@ -26,7 +29,7 @@ let columns = { status: Config.oneOf(['complete', 'warning']), value: Config.number(), }), - text: Config.string(), + type: Config.oneOf(['text', 'button', 'label']).value('text'), useEllipse: Config.bool().value(false), }; From c34ee52e56b43260307efc09e54a05c83698481c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matuzale=CC=81m=20S=2E=20Teles?= Date: Fri, 15 Dec 2017 20:21:18 -0300 Subject: [PATCH 29/29] SF --- packages/clay-table/src/ClayTable.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/clay-table/src/ClayTable.js b/packages/clay-table/src/ClayTable.js index d54a59a80..7a9185789 100644 --- a/packages/clay-table/src/ClayTable.js +++ b/packages/clay-table/src/ClayTable.js @@ -76,6 +76,7 @@ class ClayTable extends Component { /** * Handle button sort in header. + * @param {!Event} event * @private */ handleSortColumn_(event) {