0.8.0 • Published 2 years ago

@netology-group/wc-user-list v0.8.0

Weekly downloads
190
License
MIT
Repository
-
Last release
2 years ago

<user-list>

downloads

user-list is an element for displaying a list of users with their avatars and online statuses that provides useful filtering, sorting and grouping options.

Installation

npm install --save netology-group/wc-user-list

Example

HTML:

<user-list
  id="list1"
  me="3"
  melead
  canblock
  withfilter
  sortby="online:desc,name:asc,blocked:desc"
  groupby="role"
></user-list>

You need to pass array of users for list:

var userList1 = document.getElementById('list1')

userList1.users = [
  {
    id: 1,
    name: 'Calhoun Beer',
    avatar: 'https://robohash.org/nihilveritatisfugit.png?size=64x64&set=set1',
    online: false,
    role: 'user',
    blocked: false
  },
  {
    id: 2,
    name: 'Oneida Ivimey',
    avatar: 'https://robohash.org/quisetofficia.png?size=64x64&set=set1',
    online: false,
    role: 'user',
    blocked: true
  },
  {
    id: 3,
    name: 'Sheila MacCombe',
    avatar: 'https://robohash.org/consequaturnihildolores.png?size=64x64&set=set1',
    online: false,
    role: 'user',
    blocked: true
  }
]

Using in project

To start using user-list you need to add next line in your project root.

import '@netology-group/wc-user-list/dist/user-list'

Also you need to add webcomponents-bundle polyfill and custom-elements-es5-adapter (see webcomponentsjs).

<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.0.2/webcomponents-bundle.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.0.2/custom-elements-es5-adapter.js"></script>

Build

You may want to build your own custom user-list-like element. Here's how:

import {
  UserList,
  withStyles,
  withFilter,
  withSort,
  withGroup
} from '@netology-group/wc-user-list'

// custom styles
const css = `...`
// custom map of strings for grouping
const withGroupConfig = {
  mapping: {
    admin: 'Admins',
    moderator: 'Moderators',
    presenter: 'Presenters',
    user: 'Users'
  }
}

window.customElements.define('custom-user-list', withGroup(withSort(withFilter(withStyles(UserList, css))), withGroupConfig))

Demo

npm start

User object

Example:

{
  id: 1,
  name: 'Calhoun Beer',
  avatar: 'https://robohash.org/nihilveritatisfugit.png?size=64x64&set=set1',
  online: false,
  role: 'user',
  blocked: false
}
PropertyTypeRequired
idNumberyes
nameStringyes
avatarStringyes
onlineBooleanno
blockedBooleanyes

API

Attributes and properties:

NameKindTypeDescription
userspropertyArrayArray of users
meattributeNumberHighlight user with specified id
meleadattributeBooleanShow highlighted user on top of list
canblockattributeBooleanWhen set, "lock" action is available
withfilterattributeBooleanShow input field for filtering users by name
sortbyattributeStringAllows to sort users in list by one or many properties with ordering
groupbyattributeStringAllows to group users by value of specified key in user object

sortby format:

  • attribute not set - without sorting
  • sortby="online,name,blocked" - sort by key online, then by key name and finally by key blocked (default order is desc)
  • sortby="online,name:asc,blocked" - sort by key online, then by key name with order asc and finally by key blocked

Events:

NameExampleDescription
toggle-user-lock{detail: {id: 2}}Dispatched when user click on "lock" icon. id - id of user to witch the "lock" action was applied
0.8.0-dev.0

2 years ago

0.8.0

2 years ago

0.7.4-dev.1

2 years ago

0.7.4-dev.0

2 years ago

0.7.4

2 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.5.1-dev.0

3 years ago

0.5.0

3 years ago

0.4.3

3 years ago

0.4.3-dev.0

3 years ago

0.4.2

3 years ago

0.4.1

5 years ago

0.4.1-alpha.0

5 years ago

0.4.0-alpha.0

5 years ago

0.4.0

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago