@popsure/dirty-swan 0.59.1 → 0.60.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/cjs/index.js +14 -17
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/lib/components/badge/index.d.ts +4 -3
  4. package/dist/cjs/lib/components/badge/index.stories.d.ts +8 -2
  5. package/dist/cjs/lib/components/table/Table.d.ts +2 -1
  6. package/dist/cjs/lib/components/table/Table.stories.d.ts +2 -2
  7. package/dist/cjs/lib/components/table/utils/useTableNavigation/useTableNavigation.d.ts +1 -0
  8. package/dist/esm/components/badge/index.js +7 -16
  9. package/dist/esm/components/badge/index.js.map +1 -1
  10. package/dist/esm/components/badge/index.stories.js +25 -4
  11. package/dist/esm/components/badge/index.stories.js.map +1 -1
  12. package/dist/esm/components/table/Table.js +9 -4
  13. package/dist/esm/components/table/Table.js.map +1 -1
  14. package/dist/esm/components/table/Table.stories.js +3 -3
  15. package/dist/esm/components/table/Table.stories.js.map +1 -1
  16. package/dist/esm/components/table/Table.test.js +1 -1
  17. package/dist/esm/components/table/utils/useTableNavigation/useTableNavigation.test.js +1 -1
  18. package/dist/esm/index.js +1 -1
  19. package/dist/esm/lib/components/badge/index.d.ts +4 -3
  20. package/dist/esm/lib/components/badge/index.stories.d.ts +8 -2
  21. package/dist/esm/lib/components/table/Table.d.ts +2 -1
  22. package/dist/esm/lib/components/table/Table.stories.d.ts +2 -2
  23. package/dist/esm/lib/components/table/utils/useTableNavigation/useTableNavigation.d.ts +1 -0
  24. package/dist/esm/{useTableNavigation-f929fbc9.js → useTableNavigation-17d5cd3c.js} +2 -1
  25. package/dist/esm/useTableNavigation-17d5cd3c.js.map +1 -0
  26. package/package.json +1 -1
  27. package/src/lib/components/badge/index.stories.tsx +65 -0
  28. package/src/lib/components/badge/index.tsx +30 -26
  29. package/src/lib/components/badge/style.module.scss +118 -6
  30. package/src/lib/components/table/Table.stories.tsx +2 -0
  31. package/src/lib/components/table/Table.tsx +10 -2
  32. package/src/lib/components/table/utils/useTableNavigation/useTableNavigation.ts +2 -0
  33. package/dist/esm/useTableNavigation-f929fbc9.js.map +0 -1
@@ -18,12 +18,16 @@ const story = {
18
18
  variant: {
19
19
  description: 'Variant that defines the style of the Badge',
20
20
  },
21
+ showDot: {
22
+ description: 'Whether to show a dot indicator',
23
+ }
21
24
  },
22
25
  args: {
23
26
  children: 'Value',
24
27
  className: '',
25
28
  size: 'medium',
26
29
  variant: 'information',
30
+ showDot: false
27
31
  }
28
32
  };
29
33
 
@@ -32,11 +36,13 @@ export const BadgeStory = ({
32
36
  className,
33
37
  size,
34
38
  variant,
39
+ showDot,
35
40
  }: BadgeProps) => (
36
41
  <Badge
37
42
  className={className}
38
43
  size={size}
39
44
  variant={variant}
45
+ showDot={showDot}
40
46
  >
41
47
  {children}
42
48
  </Badge>
@@ -44,4 +50,63 @@ export const BadgeStory = ({
44
50
 
45
51
  BadgeStory.storyName = "Badge";
46
52
 
53
+ const variants: BadgeProps['variant'][] = [
54
+ 'white',
55
+ 'neutral',
56
+ 'neutralStrong',
57
+ 'information',
58
+ 'warning',
59
+ 'primary',
60
+ 'error',
61
+ 'success',
62
+ 'secondary',
63
+ 'secondaryStrong',
64
+ 'black',
65
+ ];
66
+
67
+ export const Variants = () => (
68
+ <div className='d-flex fd-column gap16'>
69
+ {variants.map((variant) => (
70
+ <div key={variant} className='d-flex'>
71
+ <div className='ws3'>
72
+ <Badge variant={variant}>
73
+ {variant}
74
+ </Badge>
75
+ </div>
76
+ <div className='ws3 ml32'>
77
+ <Badge
78
+ variant={variant}
79
+ showDot
80
+ >
81
+ {variant}
82
+ </Badge>
83
+ </div>
84
+ </div>
85
+ ))}
86
+ </div>
87
+ );
88
+
89
+ const sizes: BadgeProps['size'][] = ['xsmall', 'small', 'medium', 'large'];
90
+
91
+ export const Sizes = () => (
92
+ <div className='d-flex fd-column gap16'>
93
+ {sizes.map((size) => (
94
+ <div key={size} className='d-flex'>
95
+ <div className='ws3'>
96
+ <Badge size={size}>
97
+ {size}
98
+ </Badge>
99
+ </div>
100
+ <div className='ws3 ml32'>
101
+ <Badge size={size} showDot>
102
+ {size}
103
+ </Badge>
104
+ </div>
105
+ </div>
106
+ ))}
107
+ </div>
108
+ );
109
+
110
+ BadgeStory.storyName = "Badge";
111
+
47
112
  export default story;
@@ -3,51 +3,55 @@ import classNames from 'classnames';
3
3
  import styles from './style.module.scss';
4
4
 
5
5
  type Variant =
6
- | 'warning'
7
- | 'error'
8
- | 'success'
9
- | 'information'
10
- | 'neutral'
11
- | 'neutral200'
12
- | 'neutral300'
13
- | 'primary'
14
- | 'primary900';
6
+ | 'white'
7
+ | 'neutral'
8
+ | 'neutralStrong'
9
+ | 'information'
10
+ | 'warning'
11
+ | 'primary'
12
+ | 'error'
13
+ | 'success'
14
+ | 'black'
15
+ | 'secondary'
16
+ | 'secondaryStrong';
15
17
 
16
18
  export interface BadgeProps {
17
19
  className?: string;
18
20
  variant?: Variant;
19
- size?: 'small' | 'medium' | 'large';
21
+ size?: 'xsmall' | 'small' | 'medium' | 'large';
20
22
  children: ReactNode;
23
+ showDot?: boolean;
21
24
  }
22
25
 
23
- const getVariantClassNames = (variant: Variant) => ({
24
- information: 'bg-blue-100',
25
- neutral: 'bg-white',
26
- neutral200: 'bg-neutral-100',
27
- neutral300: 'bg-neutral-300',
28
- warning: 'bg-yellow-200',
29
- error: 'bg-red-100',
30
- success: 'bg-green-100',
31
- primary: 'bg-purple-300',
32
- primary900: 'bg-purple-900 tc-white',
33
- }[variant])
34
-
35
26
  const Badge = ({
36
27
  className = '',
37
28
  size = 'medium',
38
29
  variant = 'information',
39
30
  children,
31
+ showDot = false
40
32
  }: BadgeProps) => (
41
33
  <div
42
34
  role="status"
43
35
  className={classNames(
44
- className,
45
- 'px16 br8 d-inline-block ai-center fw-bold p-p',
46
- { 'p-p--small': size === 'small' },
36
+ className,
37
+ 'br8 d-inline-flex ai-center fw-bold p-p',
38
+ styles.badge,
47
39
  styles[`badge--${size}`],
48
- getVariantClassNames(variant)
40
+ styles[`badge--${variant}`],
41
+ {
42
+ 'p-p--small': size === 'small' || size === 'xsmall',
43
+ }
49
44
  )}
50
45
  >
46
+ {showDot && (
47
+ <span
48
+ className={classNames(
49
+ styles.badgeDot,
50
+ styles[`badgeDot--${variant}`]
51
+ )}
52
+ />
53
+ )}
54
+
51
55
  {children}
52
56
  </div>
53
57
  );
@@ -1,13 +1,125 @@
1
+ @use '../../scss/public/colors' as *;
1
2
 
2
3
  .badge {
3
- &--small,
4
+ border: 1px solid $ds-white;
5
+ position: relative;
6
+ gap: 6px;
7
+
8
+ &--xsmall {
9
+ padding: 4px 10px;
10
+ }
11
+
12
+ &--small {
13
+ padding: 6px 12px;
14
+ }
15
+
4
16
  &--medium {
5
- padding-bottom: 6px;
6
- padding-top: 6px;
17
+ padding: 6px 16px;
7
18
  }
8
19
 
9
20
  &--large {
10
- padding-bottom: 8px;
11
- padding-top: 8px;
21
+ gap: 8px;
22
+ padding: 8px 16px;
23
+ }
24
+
25
+ // Variants
26
+ &--white {
27
+ background-color: $ds-white;
28
+ border-color: $ds-neutral-100;
29
+ }
30
+
31
+ &--neutral {
32
+ background-color: $ds-neutral-100;
33
+ border-color: $ds-neutral-200;
34
+ }
35
+
36
+ &--neutralStrong {
37
+ background-color: $ds-neutral-300;
38
+ border-color: $ds-neutral-300;
39
+ }
40
+
41
+ &--information {
42
+ background-color: $ds-blue-100;
43
+ border-color: $ds-blue-200;
44
+ }
45
+
46
+ &--warning,
47
+ &--primary {
48
+ background-color: $ds-orange-300;
49
+ border-color: $ds-orange-400;
50
+ }
51
+
52
+ &--error {
53
+ background-color: $ds-red-100;
54
+ border-color: $ds-red-200;
55
+ }
56
+
57
+ &--success {
58
+ background-color: $ds-green-100;
59
+ border-color: $ds-green-200;
60
+ }
61
+
62
+ &--black {
63
+ background-color: $ds-neutral-900;
64
+ border-color: $ds-neutral-900;
65
+ color: $ds-white;
66
+ }
67
+
68
+ &--secondary {
69
+ background-color: $ds-purple-200;
70
+ border-color: $ds-purple-300;
71
+ }
72
+
73
+ &--secondaryStrong {
74
+ background-color: $ds-purple-600;
75
+ border-color: $ds-purple-600;
76
+ color: $ds-white;
77
+ }
78
+ }
79
+
80
+ .badgeDot {
81
+ display: inline-block;
82
+ width: 8px;
83
+ height: 8px;
84
+ border-radius: 50%;
85
+
86
+ &--primary,
87
+ &--warning {
88
+ background-color: $ds-orange-700;
89
+ }
90
+ &--white {
91
+ background-color: $ds-neutral-500;
92
+ }
93
+
94
+ &--neutral {
95
+ background-color: $ds-neutral-600;
96
+ }
97
+
98
+ &--neutralStrong {
99
+ background-color: $ds-neutral-700;
100
+ }
101
+
102
+ &--information {
103
+ background-color: $ds-blue-700;
104
+ }
105
+
106
+ &--error {
107
+ background-color: $ds-red-700;
108
+ }
109
+
110
+ &--success {
111
+ background-color: $ds-green-700;
112
+ }
113
+
114
+ &--black {
115
+ background-color: $ds-white;
116
+ }
117
+
118
+ &--secondary {
119
+ background-color: $ds-purple-700;
120
+ }
121
+
122
+ &--secondaryStrong {
123
+ background-color: $ds-white;
12
124
  }
13
- }
125
+ }
@@ -266,6 +266,7 @@ export const TableStory = ({
266
266
  stickyHeaderTopOffset,
267
267
  textOverrides,
268
268
  title,
269
+ activeSection,
269
270
  }: TableProps) => {
270
271
  const [price, setPrice] = useState(999);
271
272
  return (
@@ -305,6 +306,7 @@ export const TableStory = ({
305
306
  stickyHeaderTopOffset={stickyHeaderTopOffset}
306
307
  textOverrides={textOverrides}
307
308
  title={title}
309
+ activeSection={activeSection}
308
310
  />
309
311
  </div>
310
312
  );
@@ -1,6 +1,6 @@
1
1
  import { TableCell } from './components/TableCell/TableCell';
2
2
  import { BottomOrRegularModal } from '../modal';
3
- import { ReactNode, useCallback, useRef, useState } from 'react';
3
+ import { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
4
4
  import { ChevronDownIcon, ChevronUpIcon } from '../icon';
5
5
  import { Card } from '../cards/card';
6
6
 
@@ -41,6 +41,7 @@ export interface TableProps {
41
41
  tableData: TableData;
42
42
  textOverrides?: TextOverrides;
43
43
  title: string;
44
+ activeSection?: number;
44
45
  }
45
46
 
46
47
  const defaultTextOverrides = {
@@ -63,6 +64,7 @@ const Table = ({
63
64
  tableData,
64
65
  textOverrides: definedTextOverrides,
65
66
  title,
67
+ activeSection: externalActiveSection
66
68
  }: TableProps) => {
67
69
  const textOverrides = { ...defaultTextOverrides, ...definedTextOverrides };
68
70
  const isMobile = useMediaQuery('BELOW_MOBILE');
@@ -74,7 +76,7 @@ const Table = ({
74
76
 
75
77
  useScrollSync(headerRef, containerRef, !isMobile);
76
78
 
77
- const { activeSection, navigateTable } = useTableNavigation({
79
+ const { activeSection, navigateTable, setActiveSection } = useTableNavigation({
78
80
  enabled: isMobile,
79
81
  containerRef,
80
82
  onSelectionChanged,
@@ -100,6 +102,12 @@ const Table = ({
100
102
  setInfoModalData({ body, title });
101
103
  }, []);
102
104
 
105
+ useEffect(() => {
106
+ if (externalActiveSection && externalActiveSection !== activeSection) {
107
+ setActiveSection(externalActiveSection - 1);
108
+ }
109
+ }, [externalActiveSection]);
110
+
103
111
  return (
104
112
  <div className={classNames(styles.wrapper, 'bg-white')}>
105
113
  {isMobile ? (
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useState } from "react";
4
4
  interface UseTableNavigationReturn {
5
5
  activeSection: number;
6
6
  navigateTable: (increase?: boolean) => void;
7
+ setActiveSection: (section: number) => void;
7
8
  }
8
9
 
9
10
  interface UseTableNavigationProps {
@@ -75,5 +76,6 @@ export const useTableNavigation = ({
75
76
  return {
76
77
  activeSection: activeSection + 1,
77
78
  navigateTable: handleScrollToSection,
79
+ setActiveSection,
78
80
  }
79
81
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTableNavigation-f929fbc9.js","sources":["../../../src/lib/components/table/utils/useTableNavigation/useTableNavigation.ts"],"sourcesContent":["import debounce from \"lodash.debounce\";\nimport { useCallback, useEffect, useState } from \"react\";\n\ninterface UseTableNavigationReturn {\n activeSection: number;\n navigateTable: (increase?: boolean) => void;\n}\n\ninterface UseTableNavigationProps {\n containerRef: React.RefObject<HTMLElement>,\n enabled?: boolean,\n onSelectionChanged?: (index: number) => void\n}\n\nexport const useTableNavigation = ({\n enabled,\n containerRef,\n onSelectionChanged\n}: UseTableNavigationProps): UseTableNavigationReturn => {\n const [activeSection, setActiveSection] = useState(0);\n\n const handleScrollToSection = (increase?: boolean) => {\n if (!enabled) {\n return;\n }\n\n setActiveSection((prevSection) => \n prevSection + (increase ? 1 : -1)\n );\n };\n\n const handleTableScroll = useCallback(() => {\n if (!containerRef.current || !enabled) {\n return;\n }\n\n const containerWidth = containerRef.current.getBoundingClientRect().width;\n const scrollLeft = containerRef.current.scrollLeft * 1.1;\n const cellWidth = containerWidth / 2;\n\n setActiveSection(Math.floor(scrollLeft / cellWidth));\n }, [activeSection, containerRef, enabled]);\n\n const debouncedTableScroll = debounce(handleTableScroll, 150);\n\n useEffect(() => {\n const container = containerRef.current;\n\n container?.addEventListener('scroll', debouncedTableScroll, {\n passive: true,\n });\n\n return container?.removeEventListener('scroll', handleTableScroll);\n }, [enabled]);\n\n useEffect(() => {\n if (!enabled) {\n return\n }\n\n onSelectionChanged?.(activeSection + 1);\n\n if (containerRef.current) {\n const containerWidth = containerRef.current.getBoundingClientRect().width;\n const cellWidth = containerWidth / 2;\n\n containerRef.current.scroll({\n top: 0,\n left: cellWidth * activeSection,\n behavior: 'smooth',\n });\n }\n }, [enabled, activeSection]);\n\n return {\n activeSection: activeSection + 1,\n navigateTable: handleScrollToSection,\n }\n}"],"names":["debounce"],"mappings":";;;IAca,kBAAkB,GAAG,UAAC,EAIT;QAHxB,OAAO,aAAA,EACP,YAAY,kBAAA,EACZ,kBAAkB,wBAAA;IAEZ,IAAA,KAAoC,QAAQ,CAAC,CAAC,CAAC,EAA9C,aAAa,QAAA,EAAE,gBAAgB,QAAe,CAAC;IAEtD,IAAM,qB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