Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow icons to be changed by the user #74

Merged
merged 15 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'babel-polyfill'
import { configure } from '@storybook/react';
import '../src/main.sass'
import '../node_modules/@fortawesome/fontawesome-free/css/all.css'

const appStories = require.context('../src/', true, /stories\.js$/)

Expand Down
5 changes: 4 additions & 1 deletion .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ module.exports = {
},{
loader: 'sass-loader?sourceMap' // compiles Sass to CSS
}],
include: path.resolve(__dirname, '../src')
include: [
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../node_modules/@fortawesome'),
tabby-or-not marked this conversation as resolved.
Show resolved Hide resolved
],
}, {
test: /\.(woff2?|eot|ttf|svg|otf)(\?.+)?$/i,
use: [
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,44 @@ yarn add react-object-list
```
Ensure you have all peer dependencies installed
```
yarn add classnames font-awesome moment prop-types react-day-picker react-month-picker react-select
yarn add classnames moment prop-types react-day-picker react-month-picker react-select
```


Include icons from FontAwesome 4:

```javascript
import React from 'react'
import ReactDOM from 'react-dom'

import ObjectList from 'react-object-list'
import {FontAwesome} from 'react-object-list/icons'

var mount = document.querySelectorAll('div.browser-mount');
ReactDOM.render(
<ObjectList
icons={icons.FontAwesome(4)}
/>,
mount[0]
);
```

or your own icons by specifying as so:
```javascript
<ObjectList
icons={{
OptionalFields: <i className="list" />,
Favourites: <i className="heart" />,
RemoveFavourite: <i className="minus-circle" />,
RemoveFilter: <i className="trash-o" />,
DropdownOpen: <i className="caret-down" />,
DropdownClose: <i className="caret-up" />,
SortAsc: <i className="caret-up" />,
SortDesc: <i className="caret-down" />,
Unsorted: <i className="sort" />,
Loading: <i className="circle-notch spin" />,
}}
/>
```

Unspecified icons will not show.
1 change: 1 addition & 0 deletions demo-site/demos.sass
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import 'node_modules/uptick-demo-site/dist/uptick-demo-site'
@import 'node_modules/react-object-list/styles/main'
@import 'node_modules/font-awesome/css/font-awesome.min'
2 changes: 2 additions & 0 deletions demo-site/table-demo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDom from 'react-dom'

import ObjectList from 'react-object-list'
import {TextContainsFilter} from 'react-object-list/filters'
import {FontAwesome} from 'react-object-list/icons'

const mockData = require('./demo.data.json')
const columns = [
Expand Down Expand Up @@ -145,6 +146,7 @@ class TableDemo extends React.Component {
addFilter={this.addFilter}
removeFilter={this.removeFilter}
updateFilter={this.updateFilter}
icons={FontAwesome(4)}
tabby-or-not marked this conversation as resolved.
Show resolved Hide resolved
/>
}
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"author": "Uptick Pty Ltd (http://uptickhq.com)",
"license": "MIT",
"devDependencies": {
"@fortawesome/fontawesome-free": "^5.4.1",
"@storybook/addon-actions": "^4.0.0-alpha.8",
"@storybook/addon-info": "^4.0.0-alpha.8",
"@storybook/addon-knobs": "^4.0.0-alpha.8",
Expand Down Expand Up @@ -58,7 +59,6 @@
"eslint-plugin-standard": "^4.0.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^1.1.11",
"font-awesome": "^4.7.0",
"jest": "^22.4.2",
"moment": "^2.21.0",
"node-sass": "^4.7.2",
Expand All @@ -80,7 +80,6 @@
},
"peerDependencies": {
"classnames": "^2.2.5",
"font-awesome": "^4.7.0",
"moment": "^2.21.0",
"prop-types": "^15.6.1",
"react": "15.x - 16.x",
Expand Down
2 changes: 2 additions & 0 deletions src/ObjectList.demo.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import { withInfo } from '@storybook/addon-info'
import {TextContainsFilter, SearchFilter} from './filters'
import {FontAwesome} from './icons'

import ObjectList from '.'
import Table from './data-renderers/Table'
Expand Down Expand Up @@ -181,6 +182,7 @@ class InteractiveObjectList extends React.Component {
updateFilter={this.updateFilter}
searchKey="first_name"
itemOnClick={action('clicked on')}
icons={FontAwesome(5)}
/>
}
}
Expand Down
25 changes: 19 additions & 6 deletions src/ObjectList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
SELECTION_TYPE,
ALL_SELECTED,
} from './utils/proptypes'
import {
loadingSpinner,
ErrorMessage as DefaultErrorMessage,
} from './utils'
import {ErrorMessage as DefaultErrorMessage} from './utils'

class ObjectList extends Component {
static propTypes = {
Expand Down Expand Up @@ -85,6 +82,19 @@ class ObjectList extends Component {
selectItems: PropTypes.func,
/** Array of custom actions to be rendered */
customActions: PropTypes.arrayOf(PropTypes.func),
/** Icons to be rendered across the component */
icons: PropTypes.shape({
OptionalFields: PropTypes.element,
Favourites: PropTypes.element,
RemoveFavourite: PropTypes.element,
RemoveFilter: PropTypes.element,
DropdownOpen: PropTypes.element,
DropdownClose: PropTypes.element,
SortAsc: PropTypes.element,
SortDesc: PropTypes.element,
Unsorted: PropTypes.element,
Loading: PropTypes.element,
}),
}

static defaultProps = {
Expand All @@ -93,6 +103,7 @@ class ObjectList extends Component {
Pagination: DefaultPagination,
ErrorMessage: DefaultErrorMessage,
data: [],
icons: {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the css file that we publish with the js already has FA included, I do think we should have some defaults set up to work out of the box.

Copy link
Contributor Author

@tabby-or-not tabby-or-not Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not any more 😈
https://github.com/uptick/react-object-list/pull/74/files#diff-5fea21b08a353ec25a50a2178f880439L1

Default is currently no icons so that there is no dependency, but we could revert that, thoughts @scaredcat @jarekwg ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I like it. As long as there are still icons in the demo, we're good.
Maybes also adjust the main README to explain how this package treats icons now (import your own, feed them into the props)

columns: [],
customActions: [],
error: null,
Expand Down Expand Up @@ -121,7 +132,7 @@ class ObjectList extends Component {
const {
DataRenderer, Pagination, ErrorMessage,
filters, addFilter, updateFilter, meta, status, searchKey,
data, columns, updateColumns, itemOnClick,
data, columns, updateColumns, itemOnClick, icons,
favourites, handleDeleteFavourite, handleAddFavourite, favouritesEnabled,
selectedFavouriteName, loadFavourite, maxPages, removeFilter,
updatePage, updateSorting, selection, selectItems, customActions, error,
Expand All @@ -134,6 +145,7 @@ class ObjectList extends Component {
<div>
<ActionsFiltersContainer
filters={filters}
icons={icons}
addFilter={addFilter}
updateFilter={updateFilter}
removeFilter={removeFilter}
Expand Down Expand Up @@ -164,6 +176,7 @@ class ObjectList extends Component {
<DataRenderer
data={data}
summaryData={summaryData}
icons={icons}
meta={meta}
columns={columns}
updateSorting={updateSorting}
Expand All @@ -181,7 +194,7 @@ class ObjectList extends Component {
count={totalCount}
goToPage={updatePage}
loading={status === STATUS_CHOICES.loading}
LoadingIcon={loadingSpinner}
LoadingIcon={icons.Loading}
itemPluralName={itemPluralName}
/>
}
Expand Down
2 changes: 2 additions & 0 deletions src/ObjectList.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { storiesOf } from '@storybook/react'
import { withInfo } from '@storybook/addon-info'
import { action } from '@storybook/addon-actions'
import * as importedFilters from './filters'
import FontAwesomeIcons from './icons/FontAwesome'

import ObjectList from '.'

Expand All @@ -11,6 +12,7 @@ const baseProps = {
updateColumns: action('Update columns'),
updateFilter: action('Update filters'),
addFilter: action('Add filter'),
icons: FontAwesomeIcons(5),
}

const filters = Object.entries(importedFilters).map(([name, filter]) => {
Expand Down
19 changes: 11 additions & 8 deletions src/__snapshots__/ObjectList.demo.stories.storyshot
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ exports[`Storyshots object-list/demo interactive list 1`] = `
className="objectlist-button objectlist-button--dropdown objectlist-button--borderless"
>
<i
className="fa fa-list"
className="fas fa-list"
/>
Change columns
<i
className="fas fa-caret-down"
/>
</button>
<div
className="objectlist-dropdown__menu objectlist-dropdown__menu--borderless"
Expand Down Expand Up @@ -804,9 +807,12 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
className="objectlist-button objectlist-button--dropdown objectlist-button--borderless"
>
<i
className="fa fa-list"
className="fas fa-list"
/>
Change columns
<i
className="fas fa-caret-down"
/>
</button>
<div
className="objectlist-dropdown__menu objectlist-dropdown__menu--borderless"
Expand Down Expand Up @@ -866,8 +872,7 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
>

<i
aria-hidden="true"
className="fa fa-sort"
className="fas fa-sort"
/>
</span>
</div>
Expand All @@ -889,8 +894,7 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
>

<i
aria-hidden="true"
className="fa fa-sort"
className="fas fa-sort"
/>
</span>
</div>
Expand All @@ -912,8 +916,7 @@ exports[`Storyshots object-list/demo interactive table 1`] = `
>

<i
aria-hidden="true"
className="fa fa-sort"
className="fas fa-sort"
/>
</span>
</div>
Expand Down
Loading