UNPKG

wix-style-react

Version:
205 lines (190 loc) • 7.46 kB
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } import React from 'react'; import { Table, ToolbarContextPropTypes } from 'wix-style-react/Table'; import { TableToolbar, ItemGroup, Item, Title, SelectedCount } from 'wix-style-react/TableToolbar'; import TableActionCell from 'wix-style-react/TableActionCell'; import Card from 'wix-style-react/Card'; import { Star, Download, Duplicate, Print } from 'wix-style-react/new-icons'; var baseData = [{ name: 'Apple Towels', SKU: '111222', price: '$2.00', inventory: 'In stock' }, { name: 'Cyan Towels', SKU: '222333', price: '$2.00', inventory: 'In stock' }, { name: 'Marble Slippers', SKU: '333444', price: '$14.00', inventory: 'In stock' }, { name: 'Red Slippers', SKU: '444555', price: '$14.00', inventory: 'Out of stock' }]; var primaryAction = function primaryAction(rowData) { return window.alert('Editing ' + rowData.name); }; export var ActionCellPrimarySecondaryExample = function (_React$Component) { _inherits(ActionCellPrimarySecondaryExample, _React$Component); function ActionCellPrimarySecondaryExample() { _classCallCheck(this, ActionCellPrimarySecondaryExample); return _possibleConstructorReturn(this, (ActionCellPrimarySecondaryExample.__proto__ || Object.getPrototypeOf(ActionCellPrimarySecondaryExample)).apply(this, arguments)); } _createClass(ActionCellPrimarySecondaryExample, [{ key: 'render', value: function render() { return React.createElement( Card, null, React.createElement( Table, { dataHook: 'story-action-cell-primary-secondary-example', data: baseData, itemsPerPage: 20, showSelection: true, onRowClick: primaryAction, columns: [{ title: 'Name', render: function render(row) { return React.createElement( 'span', null, row.name ); }, width: '20%', minWidth: '150px' }, { title: 'SKU', render: function render(row) { return React.createElement( 'span', null, row.SKU ); }, width: '10%', minWidth: '100px' }, { title: 'Price', render: function render(row) { return React.createElement( 'span', null, row.price ); }, width: '10%', minWidth: '100px' }, { title: 'Inventory', render: function render(row) { return React.createElement( 'span', null, row.inventory ); }, width: '20%', minWidth: '100px' }, { title: '', width: '40%', render: function render(rowData) { return React.createElement(TableActionCell, { dataHook: 'action-cell-component-secondary', primaryAction: { text: 'Edit', theme: 'fullblue', onActionTrigger: function onActionTrigger() { return primaryAction(rowData); } }, secondaryActions: [{ text: 'Star', icon: React.createElement(Star, null), onClick: function onClick() { return window.alert('Starring ' + rowData.name); } }, { text: 'Download', icon: React.createElement(Download, null), onClick: function onClick() { return window.alert('Downloading ' + rowData.name); } }, { text: 'Duplicate', icon: React.createElement(Duplicate, null), onClick: function onClick() { return window.alert('Duplicating ' + rowData.name); } }, { text: 'Print', icon: React.createElement(Print, null), onClick: function onClick() { return window.alert('Printing ' + rowData.name); } }], numOfVisibleSecondaryActions: 2, alwaysShowSecondaryActions: false }); } }] }, React.createElement( Table.ToolbarContainer, null, function (selectionContext) { return selectionContext.selectedCount === 0 ? React.createElement(MainToolbar, null) : React.createElement(BulkActionsToolbar, selectionContext); } ), React.createElement(Table.Content, null) ) ); } }]); return ActionCellPrimarySecondaryExample; }(React.Component); var MainToolbar = function MainToolbar() { return React.createElement( TableToolbar, null, React.createElement( ItemGroup, { position: 'start' }, React.createElement( Item, null, React.createElement( Title, null, 'My Table' ) ) ) ); }; var BulkActionsToolbar = function BulkActionsToolbar(props) { return React.createElement( TableToolbar, null, React.createElement( ItemGroup, { position: 'start' }, React.createElement( Item, null, React.createElement( SelectedCount, null, props.selectedCount + ' Selected' ) ) ) ); }; BulkActionsToolbar.propTypes = ToolbarContextPropTypes;