# react-visibility-toggles

> Visibility toggles

Latest version **1.2.0** (published 2017-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-visibility-toggles
pnpm add react-visibility-toggles
yarn add react-visibility-toggles
bun add react-visibility-toggles
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2017-10-02 |
| First published | 2016-11-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Juho Vepsalainen |
| Maintainers | bebraw |
| Keywords | react, reactjs, reactabular |

## Links

- npm: https://www.npmjs.com/package/react-visibility-toggles
- Repository: https://github.com/reactabular/react-visibility-toggles
- Homepage: https://reactabular.github.io/react-visibility-toggles/
- Issues: https://github.com/reactabular/react-visibility-toggles/issues
- npm.io page: https://npm.io/package/react-visibility-toggles

## Dependencies (1)

- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2017-10-02
- 1.1.1 — 2016-12-20
- 1.1.0 — 2016-12-08
- 1.0.1 — 2016-11-27
- 1.0.0 — 2016-11-27

## README

[![build status](https://secure.travis-ci.org/reactabular/react-visibility-toggles.svg)](http://travis-ci.org/reactabular/react-visibility-toggles) [![bitHound Score](https://www.bithound.io/github/reactabular/react-visibility-toggles/badges/score.svg)](https://www.bithound.io/github/reactabular/react-visibility-toggles) [![codecov](https://codecov.io/gh/reactabular/react-visibility-toggles/branch/master/graph/badge.svg)](https://codecov.io/gh/reactabular/react-visibility-toggles)

# react-visibility-toggles - Visibility toggles for React

`react-visibility-toggles` provides a React component for rendering visibility toggles for table columns. It works well with Reactabular.

## Example

```
/*
import VisibilityToggles from 'react-visibility-toggles';
*/

const columns = [
  {
    header: {
      label: 'Name'
    },
    visible: true
  },
  {
    header: {
      label: 'Age'
    },
    visible: false
  }
];

<VisibilityToggles
  columns={columns}
  onToggleColumn={({ column, columnIndex }) => console.log(column, columnIndex)}
  isVisible={({ column }) => column.visible}
  props={{}}
/>
```

## Integrating with Reactabular

The following example shows how to integrate `react-visibility-toggles` with Reactabular:

```jsx
/*
import React from 'react';
import * as Table from 'reactabular-table';
import { cloneDeep } from 'lodash';
import VisibilityToggles from 'react-visibility-toggles';
*/

class ToggleColumnsTable extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      columns: [
        {
          property: 'name',
          header: {
            label: 'Name'
          },
          visible: true
        },
        {
          property: 'age',
          header: {
            label: 'Age'
          },
          visible: false
        },
        {
          property: 'color',
          header: {
            label: 'Color'
          },
          cell: {
            transforms: [color => ({ style: { color } })]
          },
          visible: true
        }
      ],
      rows: [
        {
          id: 100,
          name: 'Adam',
          age: 12,
          color: 'red'
        },
        {
          id: 101,
          name: 'Brian',
          age: 44,
          color: 'green'
        },
        {
          id: 102,
          name: 'Mike',
          age: 25,
          color: 'blue'
        }
      ]
    };

    this.onToggleColumn = this.onToggleColumn.bind(this);
  }
  render() {
    const { columns, rows } = this.state;

    return (
      <div>
        <VisibilityToggles
          columns={columns}
          onToggleColumn={this.onToggleColumn}
        />

        <Table.Provider
          columns={columns.filter(column => column.visible)}
        >
          <Table.Header />

          <Table.Body rows={rows} rowKey="id" />
        </Table.Provider>
      </div>
    );
  }
  onToggleColumn({ columnIndex }) {
    const columns = cloneDeep(this.state.columns);

    columns[columnIndex].visible = !columns[columnIndex].visible;

    this.setState({ columns });
  }
}

<ToggleColumnsTable />
```

## License

MIT. See LICENSE for details.

---
_Source: https://npm.io/package/react-visibility-toggles · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
