• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atomicpages / pretty-checkbox-react / 8690206103

15 Apr 2024 01:41PM CUT coverage: 100.0%. Remained the same
8690206103

Pull #1092

github

web-flow
build(deps-dev): bump @commitlint/config-conventional

Bumps [@commitlint/config-conventional](https://github.com/conventional-changelog/commitlint/tree/HEAD/@commitlint/config-conventional) from 17.0.2 to 19.2.2.
- [Release notes](https://github.com/conventional-changelog/commitlint/releases)
- [Changelog](https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/CHANGELOG.md)
- [Commits](https://github.com/conventional-changelog/commitlint/commits/v19.2.2/@commitlint/config-conventional)

---
updated-dependencies:
- dependency-name: "@commitlint/config-conventional"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #1092: build(deps-dev): bump @commitlint/config-conventional from 17.0.2 to 19.2.2

67 of 67 branches covered (100.0%)

Branch coverage included in aggregate %.

172 of 172 relevant lines covered (100.0%)

9.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/components/checkbox/useCheckboxState.ts
1
import * as React from 'react';
3✔
2

3
export type UseCheckboxState = {
4
  /**
5
   * The state object of the checkbox. This can be a boolean or
6
   * an array of items.
7
   * @default false
8
   */
9
  state?: boolean | string | any[];
10

11
  /**
12
   * Your change handlers to run _after_ the default dispatch
13
   * has occurred.
14
   */
15
  onChange?: React.InputHTMLAttributes<HTMLInputElement>['onChange'];
16
};
17

18
const INDETERMINATE_STATE = 'indeterminate';
3✔
19

20
const dispatch = (value: string) => (state: UseCheckboxState['state']) => {
10✔
21
  if (Array.isArray(state)) {
10✔
22
    const index = state.indexOf(value);
6✔
23

24
    if (index === -1) {
6✔
25
      state.push(value);
4✔
26
    } else {
27
      state.splice(index, 1);
2✔
28
    }
29

30
    return [...state];
6✔
31
  } else if (value !== '') {
4✔
32
    return [value];
1✔
33
  }
34

35
  return !state;
3✔
36
};
37

38
export const useCheckboxState = ({
3✔
39
  state: initialState = false,
9✔
40
  onChange,
41
}: UseCheckboxState = {}) => {
42
  const [state, setState] = React.useState(() => {
18✔
43
    if (
8✔
44
      typeof initialState === 'string' &&
10✔
45
      initialState !== INDETERMINATE_STATE
46
    ) {
47
      return [initialState];
1✔
48
    }
49

50
    return initialState;
7✔
51
  });
52

53
  return {
18✔
54
    state,
55
    setState,
56
    onChange: React.useCallback(
57
      (e: React.ChangeEvent<HTMLInputElement>) => {
58
        const { value } = e.currentTarget;
10✔
59

60
        setState(dispatch(value));
10✔
61

62
        if (typeof onChange === 'function') {
10✔
63
          onChange(e);
3✔
64
        }
65
      },
66
      [onChange]
67
    ),
68
  };
69
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc