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

deriv-com / deriv-com-v2 / 7041643579

30 Nov 2023 03:28AM CUT coverage: 85.023%. First build
7041643579

Pull #215

github

mohsen-deriv
Merge branch 'main' into michio/update-storybook-config-for-static-images
Pull Request #215: chore: updated storybook configs to fix images not showing up

193 of 259 branches covered (0.0%)

Branch coverage included in aggregate %.

6909 of 8094 relevant lines covered (85.36%)

3.36 hits per line

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

12.05
/libs/components/src/lib/breadcrumbs/base/index.tsx
1
import CustomLink from '../../link';
2✔
2
import { BreadcrumbsProps } from '../types';
2✔
3
import { useWindowWidth } from '@react-hook/window-size';
2✔
4
import { Fragment, ReactNode, useEffect, useState } from 'react';
2✔
5
import { qtMerge } from '@deriv/quill-design';
2✔
6
import { maxLinks } from './constants';
2✔
7

2✔
8
export function Base({ size = 'sm', links = [], className }: BreadcrumbsProps) {
2✔
9
  //todo: removed [LinkProps] from utils/generics and added here. we need to update this because we are using this on multiple places
×
10
  interface LinkProps {
×
11
    content: ReactNode;
×
12
    href: string;
×
13
  }
×
14

×
15
  const [renderLinks, setRenderLinks] = useState<LinkProps[]>([]);
×
16
  const [dropdownLinks, setDropdownLinks] = useState<LinkProps[]>([]);
×
17

×
18
  const isLastItem = (key: number) => renderLinks.length - 1 > key;
×
19
  const linksLen = links.length;
×
20
  const hasExtra = useWindowWidth() < 768 && maxLinks < linksLen;
×
21

×
22
  useEffect(() => {
×
23
    setRenderLinks(links);
×
24

×
25
    if (hasExtra) {
×
26
      const limitedLinks = [
×
27
        links[0],
×
28
        { content: '...', href: '' },
×
29
        links[linksLen - 2],
×
30
        links[linksLen - 1],
×
31
      ];
×
32

×
33
      setRenderLinks(limitedLinks);
×
34

×
35
      const remainingLinks: LinkProps[] = links.filter(
×
36
        (item) => !new Set(limitedLinks).has(item),
×
37
      );
×
38

×
39
      setDropdownLinks(remainingLinks);
×
40
    }
×
41
  }, [links]);
×
42

×
43
  return (
×
44
    <div className={qtMerge('flex', className)}>
×
45
      {renderLinks.map(({ content, href }, lk) => (
×
46
        <Fragment key={`breadcrumbs-${content}`}>
×
47
          {hasExtra && lk === 1 && (
×
48
            <select
×
49
              className="relative -right-600 -ml-1200 w-1300 opacity-50"
×
50
              onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
×
51
                if (typeof window !== 'undefined') {
×
52
                  window.location.href = e.target.value;
×
53
                }
×
54
              }}
×
55
            >
×
56
              {dropdownLinks.map(({ href, content }, dk) => {
×
57
                return (
×
58
                  <option key={`dropdown-${content}`} value={href}>
×
59
                    {content}
×
60
                  </option>
×
61
                );
×
62
              })}
×
63
            </select>
×
64
          )}
×
65

×
66
          <CustomLink
×
67
            size={size}
×
68
            href={href}
×
69
            hasHoverDecoration={isLastItem(lk)}
×
70
            hasIcon={isLastItem(lk)}
×
71
            iconColor="subtle"
×
72
            disabled={!isLastItem(lk)}
×
73
            className="items-center"
×
74
          >
×
75
            {content}
×
76
          </CustomLink>
×
77
        </Fragment>
×
78
      ))}
×
79
    </div>
×
80
  );
×
81
}
×
82

2✔
83
export default Base;
2✔
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