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

alkem-io / client-web / #5734

22 Sep 2023 11:16AM UTC coverage: 6.359%. First build
#5734

Pull #4782

travis-ci

Pull Request #4782: Remove character counters

173 of 8089 branches covered (0.0%)

Branch coverage included in aggregate %.

25 of 25 new or added lines in 5 files covered. (100.0%)

1290 of 14917 relevant lines covered (8.65%)

0.42 hits per line

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

0.0
/src/core/ui/forms/MarkdownInput/CharacterCountContext.tsx
1
import {
2
  createContext,
3
  Dispatch,
4
  PropsWithChildren,
5
  ReactElement,
6
  useContext,
7
  useLayoutEffect,
8
  useMemo,
9
  useState,
10
} from 'react';
11

12
type CharacterCountContextValue = {
13
  characterCount: number;
14
  setCharacterCount: Dispatch<number>;
15
};
16

17
const CharacterCountContext = createContext<CharacterCountContextValue | null>(null);
×
18

19
export const CharacterCountContextProvider = ({ children }: PropsWithChildren) => {
×
20
  const [characterCount, setCharacterCount] = useState(0);
×
21

22
  const contextValue = useMemo<CharacterCountContextValue>(
×
23
    () => ({ characterCount, setCharacterCount }),
×
24
    [characterCount, setCharacterCount]
25
  );
26

27
  return <CharacterCountContext value={contextValue}>{children}</CharacterCountContext>;
×
28
};
29

30
const useCharacterCountContext = () => {
×
31
  const context = useContext(CharacterCountContext);
×
32
  if (!context) {
×
33
    throw new Error('Must be wrapped in CharacterCountContextProvider');
×
34
  }
35
  return context;
×
36
};
37

38
export const useSetCharacterCount = () => {
×
39
  const { setCharacterCount } = useCharacterCountContext();
×
40
  return setCharacterCount;
×
41
};
42

43
interface CharacterCountContainerProps {
44
  onChange?: (characterCount: number) => void;
45
  children: ({ characterCount }) => ReactElement | null;
46
}
47

48
export const CharacterCountContainer = ({ onChange, children }: CharacterCountContainerProps) => {
×
49
  const { characterCount } = useCharacterCountContext();
×
50

×
51
  useLayoutEffect(() => {
×
52
    onChange?.(characterCount);
53
  }, [characterCount]);
54

×
55
  return children({ characterCount });
56
};
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

© 2026 Coveralls, Inc