@integrigo/integrigo-ui 1.6.17 → 1.6.18-a
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.
- package/jest.config.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.esm.js +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/src/components/atoms/Chip/Chip.d.ts +5 -4
- package/lib/src/components/atoms/Chip/Chip.stories.d.ts +3 -3
- package/lib/src/components/atoms/Dot/Dot.stories.d.ts +3 -3
- package/lib/src/components/atoms/Icon/Icon.d.ts +11 -1
- package/lib/src/components/atoms/Icon/Icon.stories.d.ts +2 -2
- package/lib/src/components/atoms/Icon/IconAddition.d.ts +5 -5
- package/lib/src/components/atoms/Icon/icons/Calendar.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/CloseSquare.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/CommentDots.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/DiceOne.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/Eye.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/Heart.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/HeartAlt.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/HourGlass.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/QuestionCircle.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/Rocket.d.ts +3 -0
- package/lib/src/components/atoms/Icon/icons/Search.d.ts +3 -0
- package/lib/src/components/atoms/Typography/Hero.d.ts +1 -1
- package/lib/src/components/atoms/index.d.ts +1 -0
- package/lib/src/components/molecules/Checkbox/Checkbox.stories.d.ts +4 -4
- package/lib/src/components/molecules/Input/Input.d.ts +8 -8
- package/lib/src/components/molecules/Input/Input.stories.d.ts +9 -9
- package/lib/src/components/molecules/Radio/Radio.stories.d.ts +4 -4
- package/lib/src/components/molecules/Switch/Switch.d.ts +13 -0
- package/lib/src/components/molecules/Switch/Switch.stories.d.ts +7 -0
- package/lib/src/components/molecules/Switch/index.d.ts +1 -0
- package/lib/src/components/molecules/index.d.ts +1 -0
- package/lib/src/components/organisms/Modal/Divider.d.ts +2 -0
- package/lib/src/components/organisms/Modal/Modal.d.ts +5 -1
- package/lib/src/components/organisms/Modal/Modal.stories.d.ts +2 -2
- package/lib/src/components/organisms/Table/Table.d.ts +12 -0
- package/lib/src/components/organisms/Table/Table.stories.d.ts +7 -0
- package/lib/src/components/organisms/Table/Table.test.d.ts +1 -0
- package/lib/src/components/organisms/Table/index.d.ts +1 -0
- package/lib/src/components/organisms/index.d.ts +1 -0
- package/lib/src/index.d.ts +4 -4
- package/package.json +7 -6
- package/src/components/atoms/Chip/Chip.stories.tsx +6 -8
- package/src/components/atoms/Chip/Chip.tsx +28 -17
- package/src/components/atoms/Icon/Icon.tsx +21 -1
- package/src/components/atoms/Icon/IconAddition.tsx +22 -20
- package/src/components/atoms/Icon/icons/Calendar.tsx +9 -0
- package/src/components/atoms/Icon/icons/CloseSquare.tsx +9 -0
- package/src/components/atoms/Icon/icons/CommentDots.tsx +9 -0
- package/src/components/atoms/Icon/icons/DiceOne.tsx +9 -0
- package/src/components/atoms/Icon/icons/Eye.tsx +9 -0
- package/src/components/atoms/Icon/icons/Heart.tsx +9 -0
- package/src/components/atoms/Icon/icons/HeartAlt.tsx +9 -0
- package/src/components/atoms/Icon/icons/HourGlass.tsx +9 -0
- package/src/components/atoms/Icon/icons/QuestionCircle.tsx +9 -0
- package/src/components/atoms/Icon/icons/Rocket.tsx +9 -0
- package/src/components/atoms/Icon/icons/Search.tsx +9 -0
- package/src/components/atoms/Typography/Hero.tsx +3 -2
- package/src/components/atoms/index.ts +1 -0
- package/src/components/molecules/Button/BasicButton.tsx +2 -1
- package/src/components/molecules/Button/Button.tsx +5 -4
- package/src/components/molecules/Input/Input.tsx +51 -47
- package/src/components/molecules/Profile/Profile.tsx +2 -2
- package/src/components/molecules/Switch/Switch.stories.tsx +39 -0
- package/src/components/molecules/Switch/Switch.tsx +94 -0
- package/src/components/molecules/Switch/index.ts +1 -0
- package/src/components/molecules/index.ts +1 -0
- package/src/components/organisms/Modal/Divider.tsx +13 -0
- package/src/components/organisms/Modal/Modal.stories.tsx +2 -0
- package/src/components/organisms/Modal/Modal.tsx +9 -6
- package/src/components/organisms/Table/Table.stories.tsx +180 -0
- package/src/components/organisms/Table/Table.test.tsx +82 -0
- package/src/components/organisms/Table/Table.tsx +162 -0
- package/src/components/organisms/Table/__snapshots__/Table.test.tsx.snap +101 -0
- package/src/components/organisms/Table/index.ts +1 -0
- package/src/components/organisms/index.ts +3 -2
- package/src/index.ts +6 -4
- package/src/styles/global.ts +8 -1
@@ -1,36 +1,36 @@
|
|
1
|
-
import React from
|
2
|
-
import styled, { css, FlattenSimpleInterpolation } from
|
3
|
-
import { FieldProps } from
|
1
|
+
import React from "react";
|
2
|
+
import styled, { css, FlattenSimpleInterpolation } from "styled-components";
|
3
|
+
import { FieldProps } from "formik";
|
4
4
|
|
5
|
-
import { getValidationTypeProps } from
|
6
|
-
import { ValidationType } from
|
7
|
-
import { IconAddition, IconType } from
|
8
|
-
import { Label } from
|
9
|
-
import { FieldLabel, fieldSizeVariants, FieldWrapper } from
|
5
|
+
import { getValidationTypeProps } from "../../../helpers/validation";
|
6
|
+
import { ValidationType } from "../../../types/validation";
|
7
|
+
import { IconAddition, IconType } from "../../atoms/Icon";
|
8
|
+
import { Label } from "../../atoms/Typography/Label";
|
9
|
+
import { FieldLabel, fieldSizeVariants, FieldWrapper } from "../../atoms/Field";
|
10
10
|
|
11
11
|
export type InputProps = Omit<
|
12
|
-
React.InputHTMLAttributes<HTMLInputElement>,
|
13
|
-
|
12
|
+
React.InputHTMLAttributes<HTMLInputElement>,
|
13
|
+
"size"
|
14
14
|
> &
|
15
|
-
FieldProps & {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
};
|
15
|
+
FieldProps & {
|
16
|
+
label?: string;
|
17
|
+
validationType?: ValidationType;
|
18
|
+
icon?: IconType;
|
19
|
+
size?: "xl" | "l" | "m" | "s";
|
20
|
+
direction?: "ltr" | "rtl";
|
21
|
+
onIconClick?: () => void;
|
22
|
+
};
|
23
23
|
|
24
24
|
const getDirectionPadding = (
|
25
|
-
direction: InputProps[
|
26
|
-
padding: string
|
25
|
+
direction: InputProps["direction"],
|
26
|
+
padding: string
|
27
27
|
): FlattenSimpleInterpolation => {
|
28
28
|
switch (direction) {
|
29
|
-
case
|
29
|
+
case "ltr":
|
30
30
|
return css`
|
31
31
|
padding-left: ${padding};
|
32
32
|
`;
|
33
|
-
case
|
33
|
+
case "rtl":
|
34
34
|
return css`
|
35
35
|
padding-right: ${padding};
|
36
36
|
`;
|
@@ -40,7 +40,7 @@ const getDirectionPadding = (
|
|
40
40
|
};
|
41
41
|
|
42
42
|
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
43
|
-
({ icon, label, size =
|
43
|
+
({ icon, label, size = "m", onIconClick, field, ...props }, ref) => (
|
44
44
|
<FieldWrapper withLabel={Boolean(label)} sizeVariant={size}>
|
45
45
|
{label && (
|
46
46
|
<FieldLabel sizeVariant={size}>
|
@@ -48,34 +48,36 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
48
48
|
</FieldLabel>
|
49
49
|
)}
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
<InputWrapper>
|
52
|
+
{props.direction !== "rtl" && (
|
53
|
+
<IconAddition
|
54
|
+
icon={icon}
|
55
|
+
disabled={props.disabled}
|
56
|
+
direction={props.direction}
|
57
|
+
onClick={onIconClick}
|
58
|
+
size={size}
|
59
|
+
/>
|
60
|
+
)}
|
60
61
|
|
61
|
-
|
62
|
+
<InputElement ref={ref} sizeVariant={size} {...field} {...props} />
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
64
|
+
{props.direction === "rtl" && (
|
65
|
+
<IconAddition
|
66
|
+
icon={icon}
|
67
|
+
disabled={props.disabled}
|
68
|
+
direction={props.direction}
|
69
|
+
onClick={onIconClick}
|
70
|
+
/>
|
71
|
+
)}
|
72
|
+
</InputWrapper>
|
71
73
|
</FieldWrapper>
|
72
|
-
)
|
74
|
+
)
|
73
75
|
);
|
74
76
|
|
75
77
|
const InputElement = styled.input<
|
76
|
-
Pick<InputProps,
|
77
|
-
|
78
|
-
}
|
78
|
+
Pick<InputProps, "validationType" | "direction"> & {
|
79
|
+
sizeVariant: "xl" | "l" | "m" | "s";
|
80
|
+
}
|
79
81
|
>`
|
80
82
|
background-color: var(--color-white);
|
81
83
|
border: 2px solid var(--shades-of-grey-80);
|
@@ -105,7 +107,7 @@ Pick<InputProps, 'validationType' | 'direction'> & {
|
|
105
107
|
${(p) =>
|
106
108
|
getDirectionPadding(
|
107
109
|
p.direction,
|
108
|
-
fieldSizeVariants[p.sizeVariant].iconPadding
|
110
|
+
fieldSizeVariants[p.sizeVariant].iconPadding
|
109
111
|
)};
|
110
112
|
|
111
113
|
&:disabled {
|
@@ -117,4 +119,6 @@ Pick<InputProps, 'validationType' | 'direction'> & {
|
|
117
119
|
}
|
118
120
|
`;
|
119
121
|
|
120
|
-
|
122
|
+
const InputWrapper = styled.div`
|
123
|
+
position: relative;
|
124
|
+
`;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { ComponentStory, ComponentMeta } from "@storybook/react";
|
2
|
+
|
3
|
+
import { Switch } from "./Switch";
|
4
|
+
|
5
|
+
export default {
|
6
|
+
title: "Molecules/Switch",
|
7
|
+
component: Switch,
|
8
|
+
} as ComponentMeta<typeof Switch>;
|
9
|
+
|
10
|
+
const Template: ComponentStory<typeof Switch> = (args) => <Switch {...args} />;
|
11
|
+
|
12
|
+
export const TwoOptions = Template.bind({});
|
13
|
+
TwoOptions.args = {
|
14
|
+
onClick: (id) => console.log(id),
|
15
|
+
options: [
|
16
|
+
{ id: "1", name: "One" },
|
17
|
+
{ id: "2", name: "Two" },
|
18
|
+
],
|
19
|
+
};
|
20
|
+
|
21
|
+
export const ThreeOptions = Template.bind({});
|
22
|
+
ThreeOptions.args = {
|
23
|
+
onClick: (id) => console.log(id),
|
24
|
+
options: [
|
25
|
+
{ id: "1", name: "One" },
|
26
|
+
{ id: "2", name: "Two" },
|
27
|
+
{ id: "3", name: "Three" },
|
28
|
+
],
|
29
|
+
};
|
30
|
+
|
31
|
+
export const ThreeWithDisabled = Template.bind({});
|
32
|
+
ThreeWithDisabled.args = {
|
33
|
+
onClick: (id) => console.log(id),
|
34
|
+
options: [
|
35
|
+
{ id: "1", name: "One" },
|
36
|
+
{ id: "2", name: "Two", disabled: true },
|
37
|
+
{ id: "3", name: "Three" },
|
38
|
+
],
|
39
|
+
};
|
@@ -0,0 +1,94 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import styled from "styled-components";
|
3
|
+
|
4
|
+
interface SwitchOption {
|
5
|
+
id: string;
|
6
|
+
name: string;
|
7
|
+
disabled?: boolean;
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface SwitchProps {
|
11
|
+
options:
|
12
|
+
| [SwitchOption, SwitchOption]
|
13
|
+
| [SwitchOption, SwitchOption, SwitchOption];
|
14
|
+
active?: SwitchOption["id"];
|
15
|
+
onClick: (id: SwitchOption["id"]) => void;
|
16
|
+
}
|
17
|
+
|
18
|
+
export const Switch: React.FC<SwitchProps> = ({
|
19
|
+
options,
|
20
|
+
active: defaultActive,
|
21
|
+
onClick,
|
22
|
+
}) => {
|
23
|
+
const [active, setActive] = useState(defaultActive);
|
24
|
+
|
25
|
+
const activeOption = options.find(({ id }) => id === active);
|
26
|
+
const offset = activeOption ? options.indexOf(activeOption) : 0;
|
27
|
+
|
28
|
+
const handleOptionClick = (id: string, disabled?: boolean) => {
|
29
|
+
if (disabled) {
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
|
33
|
+
setActive(id);
|
34
|
+
onClick(id);
|
35
|
+
};
|
36
|
+
|
37
|
+
return (
|
38
|
+
<Root count={options.length} offset={offset}>
|
39
|
+
{options.map((option) => (
|
40
|
+
<Option
|
41
|
+
onClick={() => handleOptionClick(option.id, option.disabled)}
|
42
|
+
key={option.id}
|
43
|
+
disabled={option.disabled}
|
44
|
+
>
|
45
|
+
{option.name}
|
46
|
+
</Option>
|
47
|
+
))}
|
48
|
+
</Root>
|
49
|
+
);
|
50
|
+
};
|
51
|
+
|
52
|
+
const Root = styled.div<{ count: number; offset: number }>`
|
53
|
+
border-radius: var(--padding-l);
|
54
|
+
background-color: var(--shades-of-grey-20);
|
55
|
+
gap: 0;
|
56
|
+
position: relative;
|
57
|
+
display: flex;
|
58
|
+
padding: var(--padding-s) 0;
|
59
|
+
|
60
|
+
& > div {
|
61
|
+
transition: color var(--transition-speed);
|
62
|
+
}
|
63
|
+
|
64
|
+
& > div:nth-child(${(p) => p.offset + 1}) {
|
65
|
+
color: white;
|
66
|
+
}
|
67
|
+
|
68
|
+
&::after {
|
69
|
+
content: "";
|
70
|
+
position: absolute;
|
71
|
+
background-color: var(--color-orange);
|
72
|
+
box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.2);
|
73
|
+
width: ${(p) => `calc(100% / ${p.count})`};
|
74
|
+
height: 100%;
|
75
|
+
transform: ${(p) => `translateX(calc(${p.offset} * 100%))`};
|
76
|
+
left: 0;
|
77
|
+
top: 0;
|
78
|
+
border-radius: var(--padding-xl);
|
79
|
+
z-index: 1;
|
80
|
+
transition: transform var(--transition-speed);
|
81
|
+
}
|
82
|
+
`;
|
83
|
+
|
84
|
+
const Option = styled.div<{ disabled?: boolean }>`
|
85
|
+
flex: 1;
|
86
|
+
font-weight: var(--font-medium);
|
87
|
+
display: flex;
|
88
|
+
${(p) => p.disabled && "color: var(--shades-of-grey-40)"};
|
89
|
+
cursor: ${(p) => (p.disabled ? "default" : "pointer")};
|
90
|
+
justify-content: center;
|
91
|
+
align-items: center;
|
92
|
+
position: relative;
|
93
|
+
z-index: ${(p) => (p.disabled ? 0 : 2)};
|
94
|
+
`;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { Switch } from './Switch'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import styled from "styled-components";
|
3
|
+
import { Divider as DividerComponent } from "../../atoms";
|
4
|
+
|
5
|
+
export const Divider: React.FC = () => {
|
6
|
+
return <ModalDivider />;
|
7
|
+
};
|
8
|
+
|
9
|
+
const ModalDivider = styled(DividerComponent)`
|
10
|
+
width: calc(100% + 2 * var(--padding-s));
|
11
|
+
margin: var(--padding-m) 0;
|
12
|
+
transform: translateX(calc(-1 * var(--padding-s)));
|
13
|
+
`;
|
@@ -1,18 +1,19 @@
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
2
2
|
import styled from "styled-components";
|
3
3
|
import { Card, Icon } from "../../atoms";
|
4
|
+
import { Divider } from "./Divider";
|
5
|
+
|
6
|
+
export interface ModalStaticProps {
|
7
|
+
Divider: typeof Divider;
|
8
|
+
}
|
4
9
|
|
5
10
|
export interface ModalProps {
|
6
11
|
show: boolean;
|
7
12
|
onClose: () => void;
|
8
13
|
}
|
9
14
|
|
10
|
-
export const Modal: React.FCS<PropsWithChildren<ModalProps>>
|
11
|
-
className,
|
12
|
-
children,
|
13
|
-
show,
|
14
|
-
onClose,
|
15
|
-
}) => {
|
15
|
+
export const Modal: React.FCS<PropsWithChildren<ModalProps>> &
|
16
|
+
ModalStaticProps = ({ className, children, show, onClose }) => {
|
16
17
|
if (!show) {
|
17
18
|
return null;
|
18
19
|
}
|
@@ -31,6 +32,8 @@ export const Modal: React.FCS<PropsWithChildren<ModalProps>> = ({
|
|
31
32
|
);
|
32
33
|
};
|
33
34
|
|
35
|
+
Modal.Divider = Divider;
|
36
|
+
|
34
37
|
const Root = styled.div`
|
35
38
|
position: fixed;
|
36
39
|
left: 0;
|
@@ -0,0 +1,180 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Table } from './Table';
|
3
|
+
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
4
|
+
|
5
|
+
import {
|
6
|
+
Column,
|
7
|
+
createColumnHelper,
|
8
|
+
} from '@tanstack/react-table';
|
9
|
+
import { Button, Profile } from '../../molecules';
|
10
|
+
|
11
|
+
export default {
|
12
|
+
title: 'Organisms/Table',
|
13
|
+
component: Table,
|
14
|
+
argTypes: {
|
15
|
+
variant: {
|
16
|
+
name: 'Color variant',
|
17
|
+
type: {
|
18
|
+
name: 'string',
|
19
|
+
required: false,
|
20
|
+
},
|
21
|
+
control: {
|
22
|
+
type: 'select',
|
23
|
+
},
|
24
|
+
options: ['primary', 'secondary'],
|
25
|
+
defaultValue: 'primary',
|
26
|
+
},
|
27
|
+
textAlign: {
|
28
|
+
name: 'Text alignment',
|
29
|
+
type: {
|
30
|
+
name: 'string',
|
31
|
+
required: false,
|
32
|
+
},
|
33
|
+
control: {
|
34
|
+
type: 'select',
|
35
|
+
},
|
36
|
+
options: ['left', 'right', 'center'],
|
37
|
+
defaultValue: 'center',
|
38
|
+
},
|
39
|
+
},
|
40
|
+
} as ComponentMeta<typeof Table>;
|
41
|
+
|
42
|
+
export const Primary: ComponentStory<typeof Table> = (args) => {
|
43
|
+
type Person = {
|
44
|
+
firstName: string
|
45
|
+
lastName: string
|
46
|
+
age: number
|
47
|
+
visits: number
|
48
|
+
status: string
|
49
|
+
progress: number
|
50
|
+
};
|
51
|
+
|
52
|
+
const personData: Person[] = [
|
53
|
+
{
|
54
|
+
firstName: 'tanner',
|
55
|
+
lastName: 'linsley',
|
56
|
+
age: 24,
|
57
|
+
visits: 100,
|
58
|
+
status: 'In Relationship',
|
59
|
+
progress: 50,
|
60
|
+
},
|
61
|
+
{
|
62
|
+
firstName: 'tandy',
|
63
|
+
lastName: 'miller',
|
64
|
+
age: 40,
|
65
|
+
visits: 40,
|
66
|
+
status: 'Single',
|
67
|
+
progress: 80,
|
68
|
+
},
|
69
|
+
{
|
70
|
+
firstName: 'joe',
|
71
|
+
lastName: 'dirte',
|
72
|
+
age: 45,
|
73
|
+
visits: 20,
|
74
|
+
status: 'Complicated',
|
75
|
+
progress: 10,
|
76
|
+
},
|
77
|
+
];
|
78
|
+
|
79
|
+
const personColumnHelper = createColumnHelper<Person>();
|
80
|
+
|
81
|
+
const personColumns = [
|
82
|
+
personColumnHelper.accessor('firstName', {
|
83
|
+
cell: info => info.getValue(),
|
84
|
+
footer: info => info.column.id,
|
85
|
+
}),
|
86
|
+
personColumnHelper.accessor(row => row.lastName, {
|
87
|
+
id: 'lastName',
|
88
|
+
cell: info => info.getValue(),
|
89
|
+
header: () => 'Last Name',
|
90
|
+
footer: info => info.column.id,
|
91
|
+
}),
|
92
|
+
personColumnHelper.accessor('age', {
|
93
|
+
header: () => 'Age',
|
94
|
+
cell: info => info.renderValue(),
|
95
|
+
footer: info => info.column.id,
|
96
|
+
}),
|
97
|
+
personColumnHelper.accessor('visits', {
|
98
|
+
header: () => 'Visits',
|
99
|
+
footer: info => info.column.id,
|
100
|
+
}),
|
101
|
+
personColumnHelper.accessor('status', {
|
102
|
+
header: 'Status',
|
103
|
+
footer: info => info.column.id,
|
104
|
+
}),
|
105
|
+
personColumnHelper.accessor('progress', {
|
106
|
+
header: 'Profile Progress',
|
107
|
+
footer: info => info.column.id,
|
108
|
+
}),
|
109
|
+
] as Column<Person>[];
|
110
|
+
|
111
|
+
return (
|
112
|
+
<Table columns={personColumns} data={personData} variant={args.variant} textAlign={args.textAlign}/>
|
113
|
+
);
|
114
|
+
};
|
115
|
+
|
116
|
+
export const WithProfile: ComponentStory<typeof Table> = (args) => {
|
117
|
+
type DataType = {
|
118
|
+
fullName: string;
|
119
|
+
points: number;
|
120
|
+
avatar: string;
|
121
|
+
email: string;
|
122
|
+
};
|
123
|
+
|
124
|
+
const data: DataType[] = [
|
125
|
+
{
|
126
|
+
fullName: 'Tanner Linsley',
|
127
|
+
points: 24,
|
128
|
+
avatar: 'https://img.freepik.com/darmowe-zdjecie/dosc-usmiechnieta-radosnie-kobieta-o-jasnych-wlosach-ubrana-swobodnie-wygladajaca-z-zadowoleniem_176420-15187.jpg?w=1380&t=st=1660198496~exp=1660199096~hmac=7401572065d2cd7bb67d9f43dbde5c116b90aad419b179fffac1196df24869f2',
|
129
|
+
email: 'abc@abc.pl',
|
130
|
+
},
|
131
|
+
{
|
132
|
+
fullName: 'Tandy Miller',
|
133
|
+
points: 80,
|
134
|
+
avatar: 'https://img.freepik.com/darmowe-zdjecie/dosc-usmiechnieta-radosnie-kobieta-o-jasnych-wlosach-ubrana-swobodnie-wygladajaca-z-zadowoleniem_176420-15187.jpg?w=1380&t=st=1660198496~exp=1660199096~hmac=7401572065d2cd7bb67d9f43dbde5c116b90aad419b179fffac1196df24869f2',
|
135
|
+
email: 'def@def.pl',
|
136
|
+
},
|
137
|
+
{
|
138
|
+
fullName: 'Joe Dirte',
|
139
|
+
points: 45,
|
140
|
+
avatar: 'https://img.freepik.com/darmowe-zdjecie/dosc-usmiechnieta-radosnie-kobieta-o-jasnych-wlosach-ubrana-swobodnie-wygladajaca-z-zadowoleniem_176420-15187.jpg?w=1380&t=st=1660198496~exp=1660199096~hmac=7401572065d2cd7bb67d9f43dbde5c116b90aad419b179fffac1196df24869f2',
|
141
|
+
email: 'ghi@ghi.pl',
|
142
|
+
},
|
143
|
+
];
|
144
|
+
|
145
|
+
const profileColumnHelper = createColumnHelper<DataType>();
|
146
|
+
|
147
|
+
const columns = [
|
148
|
+
profileColumnHelper.accessor('fullName', {
|
149
|
+
cell: info => {
|
150
|
+
return (
|
151
|
+
<div style={{ display: 'flex', alignItems: 'center' }}>
|
152
|
+
<div style={{ flexBasis: '20px' }}>{info.row.index + 1}.</div>
|
153
|
+
<Profile
|
154
|
+
name={info.getValue()}
|
155
|
+
src={info.row.original.avatar}
|
156
|
+
>
|
157
|
+
<span>{info.row.original.email}</span>
|
158
|
+
</Profile>
|
159
|
+
</div>
|
160
|
+
);
|
161
|
+
},
|
162
|
+
header: () => 'Team member',
|
163
|
+
footer: info => info.column.id,
|
164
|
+
}),
|
165
|
+
profileColumnHelper.accessor('points', {
|
166
|
+
header: () => 'Points',
|
167
|
+
cell: info => info.renderValue(),
|
168
|
+
footer: info => info.column.id,
|
169
|
+
}),
|
170
|
+
profileColumnHelper.display({
|
171
|
+
header: 'Actions',
|
172
|
+
id: 'Actions',
|
173
|
+
cell: () => <div style={{ width: '30px' }}><Button direction={'ltr'} icon={'edit'} ghost>Edit</Button></div>,
|
174
|
+
}),
|
175
|
+
] as Column<DataType>[];
|
176
|
+
|
177
|
+
return (
|
178
|
+
<Table columns={columns} data={data} variant={args.variant} width={'100%'} textAlign={"left"}/>
|
179
|
+
);
|
180
|
+
};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render } from '@testing-library/react';
|
3
|
+
import { Table } from './Table';
|
4
|
+
import { Column, createColumnHelper } from '@tanstack/react-table';
|
5
|
+
|
6
|
+
type Person = {
|
7
|
+
firstName: string
|
8
|
+
lastName: string
|
9
|
+
age: number
|
10
|
+
visits: number
|
11
|
+
status: string
|
12
|
+
progress: number
|
13
|
+
};
|
14
|
+
|
15
|
+
const data: Person[] = [
|
16
|
+
{
|
17
|
+
firstName: 'tanner',
|
18
|
+
lastName: 'linsley',
|
19
|
+
age: 24,
|
20
|
+
visits: 100,
|
21
|
+
status: 'In Relationship',
|
22
|
+
progress: 50,
|
23
|
+
},
|
24
|
+
{
|
25
|
+
firstName: 'tandy',
|
26
|
+
lastName: 'miller',
|
27
|
+
age: 40,
|
28
|
+
visits: 40,
|
29
|
+
status: 'Single',
|
30
|
+
progress: 80,
|
31
|
+
},
|
32
|
+
{
|
33
|
+
firstName: 'joe',
|
34
|
+
lastName: 'dirte',
|
35
|
+
age: 45,
|
36
|
+
visits: 20,
|
37
|
+
status: 'Complicated',
|
38
|
+
progress: 10,
|
39
|
+
},
|
40
|
+
];
|
41
|
+
|
42
|
+
const columnHelper = createColumnHelper<Person>();
|
43
|
+
|
44
|
+
const columns = [
|
45
|
+
columnHelper.accessor('firstName', {
|
46
|
+
cell: info => info.getValue(),
|
47
|
+
footer: info => info.column.id,
|
48
|
+
}),
|
49
|
+
columnHelper.accessor(row => row.lastName, {
|
50
|
+
id: 'lastName',
|
51
|
+
cell: info => info.getValue(),
|
52
|
+
header: () => 'Last Name',
|
53
|
+
footer: info => info.column.id,
|
54
|
+
}),
|
55
|
+
columnHelper.accessor('age', {
|
56
|
+
header: () => 'Age',
|
57
|
+
cell: info => info.renderValue(),
|
58
|
+
footer: info => info.column.id,
|
59
|
+
}),
|
60
|
+
columnHelper.accessor('visits', {
|
61
|
+
header: () => 'Visits',
|
62
|
+
footer: info => info.column.id,
|
63
|
+
}),
|
64
|
+
columnHelper.accessor('status', {
|
65
|
+
header: 'Status',
|
66
|
+
footer: info => info.column.id,
|
67
|
+
}),
|
68
|
+
columnHelper.accessor('progress', {
|
69
|
+
header: 'Profile Progress',
|
70
|
+
footer: info => info.column.id,
|
71
|
+
}),
|
72
|
+
] as Column<Person>[];
|
73
|
+
|
74
|
+
describe('<Table />', () => {
|
75
|
+
it('should render', () => {
|
76
|
+
render(<Table columns={columns} data={data}/>);
|
77
|
+
});
|
78
|
+
it('enabled - should match snapshot', () => {
|
79
|
+
const { container } = render(<Table columns={columns} data={data}/>);
|
80
|
+
expect(container).toMatchSnapshot();
|
81
|
+
});
|
82
|
+
});
|