@apify/ui-library 0.67.5-featoutputschemacomponent-327312.64 → 0.68.1-feattabs-4feb6d.72
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/CHANGELOG.md +11 -0
- package/dist/src/components/badge.d.ts +2 -2
- package/dist/src/components/badge.d.ts.map +1 -1
- package/dist/src/components/badge.js +12 -1
- package/dist/src/components/badge.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/tabs/index.d.ts +3 -0
- package/dist/src/components/tabs/index.d.ts.map +1 -0
- package/dist/src/components/tabs/index.js +3 -0
- package/dist/src/components/tabs/index.js.map +1 -0
- package/dist/src/components/tabs/tab.d.ts +25 -0
- package/dist/src/components/tabs/tab.d.ts.map +1 -0
- package/dist/src/components/tabs/tab.js +142 -0
- package/dist/src/components/tabs/tab.js.map +1 -0
- package/dist/src/components/tabs/tabs.d.ts +16 -0
- package/dist/src/components/tabs/tabs.d.ts.map +1 -0
- package/dist/src/components/tabs/tabs.js +121 -0
- package/dist/src/components/tabs/tabs.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/components/badge.tsx +14 -2
- package/src/components/index.ts +1 -0
- package/src/components/tabs/index.ts +2 -0
- package/src/components/tabs/tab.tsx +194 -0
- package/src/components/tabs/tabs.tsx +160 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/ui-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.68.1-feattabs-4feb6d.72+6c2024f5a97",
|
|
4
4
|
"description": "React UI library used by apify.com",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@apify/ui-icons": "^0.10.0",
|
|
30
30
|
"@floating-ui/react": "^0.26.2",
|
|
31
|
+
"@react-hook/resize-observer": "^2.0.2",
|
|
31
32
|
"clsx": "^2.0.0",
|
|
32
33
|
"dayjs": "1.11.9",
|
|
33
34
|
"fast-average-color": "^9.4.0",
|
|
@@ -65,5 +66,5 @@
|
|
|
65
66
|
"typescript": "^5.1.6",
|
|
66
67
|
"typescript-eslint": "^8.24.0"
|
|
67
68
|
},
|
|
68
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "6c2024f5a97b2f1844976716cc92199dd6ede982"
|
|
69
70
|
}
|
package/src/components/badge.tsx
CHANGED
|
@@ -9,14 +9,21 @@ import { Box, type MarginSpacingProps, type RegularBoxProps } from './box.js';
|
|
|
9
9
|
import { Text } from './text/index.js';
|
|
10
10
|
import type { SharedTextSize, SharedTextType } from './text/text_shared.js';
|
|
11
11
|
|
|
12
|
-
type BadgeSize =
|
|
12
|
+
export type BadgeSize = 'regular' | 'small' | 'extra_small';
|
|
13
13
|
export const BADGE_SIZES: BadgeSize[] = ['regular', 'small'];
|
|
14
14
|
|
|
15
15
|
const BADGE_ICON_SIZES = {
|
|
16
16
|
regular: '16',
|
|
17
17
|
small: '12',
|
|
18
|
+
extra_small: '12',
|
|
18
19
|
} satisfies Record<BadgeSize, IconSize>;
|
|
19
20
|
|
|
21
|
+
const BADGE_TEXT_SIZES = {
|
|
22
|
+
regular: 'regular',
|
|
23
|
+
small: 'small',
|
|
24
|
+
extra_small: 'small',
|
|
25
|
+
} satisfies Record<BadgeSize, SharedTextSize>;
|
|
26
|
+
|
|
20
27
|
export const BADGE_VARIANTS = ['neutral', 'neutral_muted', 'neutral_subtle', 'primary_black', 'primary_blue', 'success', 'warning', 'danger'] as const;
|
|
21
28
|
type BadgeVariant = typeof BADGE_VARIANTS[number];
|
|
22
29
|
|
|
@@ -39,6 +46,11 @@ const badgeSizeStyle = {
|
|
|
39
46
|
padding: ${theme.space.space2} ${theme.space.space6};
|
|
40
47
|
border-radius: ${theme.radius.radius4};
|
|
41
48
|
`,
|
|
49
|
+
extra_small: css`
|
|
50
|
+
height: 1.6rem;
|
|
51
|
+
padding: ${theme.space.space2} ${theme.space.space4};
|
|
52
|
+
border-radius: ${theme.radius.radius4};
|
|
53
|
+
`,
|
|
42
54
|
} satisfies Record<BadgeSize, FlattenSimpleInterpolation>;
|
|
43
55
|
|
|
44
56
|
const badgeVariantStyle = {
|
|
@@ -127,7 +139,7 @@ export const Badge = forwardRef(
|
|
|
127
139
|
{...props}
|
|
128
140
|
>
|
|
129
141
|
{LeadingIcon && <LeadingIcon size={BADGE_ICON_SIZES[size]} />}
|
|
130
|
-
{children && (<Text size={size} type={type} weight="medium">{children}</Text>)}
|
|
142
|
+
{children && (<Text size={BADGE_TEXT_SIZES[size]} type={type} weight="medium">{children}</Text>)}
|
|
131
143
|
</StyledBadge>
|
|
132
144
|
);
|
|
133
145
|
},
|
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import { createPath } from 'history';
|
|
3
|
+
import type { FlattenSimpleInterpolation } from 'styled-components';
|
|
4
|
+
import styled, { css } from 'styled-components';
|
|
5
|
+
|
|
6
|
+
import type { IconComponent } from '@apify/ui-icons';
|
|
7
|
+
|
|
8
|
+
import { theme } from '../../design_system/theme.js';
|
|
9
|
+
import type { WithTransientProps } from '../../type_utils.js';
|
|
10
|
+
import type { BadgeSize } from '../badge.js';
|
|
11
|
+
import { Badge } from '../badge.js';
|
|
12
|
+
import type { MarginSpacingProps, RegularBoxProps } from '../box.js';
|
|
13
|
+
import type { RegularLinkProps } from '../link.js';
|
|
14
|
+
import { Link } from '../link.js';
|
|
15
|
+
import { Text } from '../text/index.js';
|
|
16
|
+
import type { SharedTextSize } from '../text/text_shared.js';
|
|
17
|
+
|
|
18
|
+
type SharedTabProps = Omit<RegularBoxProps, 'as' | 'onClick'> & MarginSpacingProps & Omit<RegularLinkProps, 'hideExternalIcon' | 'showExternalIcon'>;
|
|
19
|
+
|
|
20
|
+
export type TabVariant = 'default' | 'boxed' | 'buttoned';
|
|
21
|
+
|
|
22
|
+
export type TabData = SharedTabProps & {
|
|
23
|
+
id: string;
|
|
24
|
+
title: string;
|
|
25
|
+
Icon?: IconComponent;
|
|
26
|
+
chip?: number | string;
|
|
27
|
+
rollout?: 'alpha' | 'beta';
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type TabProps = TabData & {
|
|
32
|
+
variant?: TabVariant;
|
|
33
|
+
active?: boolean;
|
|
34
|
+
onSelect?: (data: { id: string, href: string, event: React.MouseEvent }) => void;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const tabVariantTextSize = {
|
|
38
|
+
default: 'regular',
|
|
39
|
+
boxed: 'regular',
|
|
40
|
+
buttoned: 'small',
|
|
41
|
+
} satisfies Record<TabVariant, SharedTextSize>;
|
|
42
|
+
|
|
43
|
+
const tabVariantBadgeSize = {
|
|
44
|
+
default: 'small',
|
|
45
|
+
boxed: 'small',
|
|
46
|
+
buttoned: 'extra_small',
|
|
47
|
+
} satisfies Record<TabVariant, BadgeSize>;
|
|
48
|
+
|
|
49
|
+
const tabVariantStyle = {
|
|
50
|
+
default: css`
|
|
51
|
+
height: 3.6rem;
|
|
52
|
+
padding: 0 ${theme.space.space8};
|
|
53
|
+
color: ${theme.color.neutral.textSubtle};
|
|
54
|
+
|
|
55
|
+
&:hover {
|
|
56
|
+
color: ${theme.color.primaryBlack.actionHover}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&.active {
|
|
60
|
+
color: ${theme.color.neutral.text};
|
|
61
|
+
|
|
62
|
+
&::after {
|
|
63
|
+
bottom: -${theme.space.space4};
|
|
64
|
+
right: 0;
|
|
65
|
+
left: 0;
|
|
66
|
+
height: 2px;
|
|
67
|
+
background-color: ${theme.color.primaryBlack.action};
|
|
68
|
+
border-radius: ${theme.radius.radiusFull};
|
|
69
|
+
content: '';
|
|
70
|
+
display: block;
|
|
71
|
+
pointer-events: none;
|
|
72
|
+
position: absolute;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&.disabled::after {
|
|
76
|
+
background-color: ${theme.color.neutral.textDisabled};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
`,
|
|
80
|
+
boxed: css`
|
|
81
|
+
height: 3.6rem;
|
|
82
|
+
border: 1px solid transparent;
|
|
83
|
+
border-top-right-radius: ${theme.radius.radius6};
|
|
84
|
+
border-top-left-radius: ${theme.radius.radius6};
|
|
85
|
+
padding: 0 ${theme.space.space12};
|
|
86
|
+
color: ${theme.color.neutral.textMuted};
|
|
87
|
+
|
|
88
|
+
&::after {
|
|
89
|
+
inset: ${theme.space.space4};
|
|
90
|
+
background-color: transparent;
|
|
91
|
+
border-radius: ${theme.radius.radius6};
|
|
92
|
+
content: '';
|
|
93
|
+
display: block;
|
|
94
|
+
pointer-events: none;
|
|
95
|
+
position: absolute;
|
|
96
|
+
transition: background-color ${theme.transition.fastEaseOut};
|
|
97
|
+
z-index: -1;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
&:hover {
|
|
101
|
+
color: ${theme.color.neutral.text};
|
|
102
|
+
|
|
103
|
+
&::after {
|
|
104
|
+
background-color: ${theme.color.neutral.hover};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&.active {
|
|
109
|
+
color: ${theme.color.neutral.text};
|
|
110
|
+
border-color: ${theme.color.neutral.border};
|
|
111
|
+
border-bottom-color: ${theme.color.neutral.background};
|
|
112
|
+
|
|
113
|
+
&::after {
|
|
114
|
+
background-color: transparent;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`,
|
|
118
|
+
buttoned: css`
|
|
119
|
+
height: 3.2rem;
|
|
120
|
+
margin: 0 ${theme.space.space4};
|
|
121
|
+
padding: 0 ${theme.space.space8};
|
|
122
|
+
background-color: transparent;
|
|
123
|
+
border: 1px solid transparent;
|
|
124
|
+
border-radius: ${theme.radius.radius8};
|
|
125
|
+
color: ${theme.color.neutral.textMuted};
|
|
126
|
+
|
|
127
|
+
&:hover {
|
|
128
|
+
background-color: ${theme.color.neutral.hover};
|
|
129
|
+
color: ${theme.color.neutral.text};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
&.active {
|
|
133
|
+
background-color: transparent;
|
|
134
|
+
border-color: ${theme.color.neutral.border};
|
|
135
|
+
color: ${theme.color.neutral.text};
|
|
136
|
+
}
|
|
137
|
+
`,
|
|
138
|
+
} satisfies Record<TabVariant, FlattenSimpleInterpolation>;
|
|
139
|
+
|
|
140
|
+
type TabWrapperProps = WithTransientProps<Required<Pick<TabProps, 'variant'>>> & {
|
|
141
|
+
role?: React.AriaRole;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const TabWrapper = styled(Link)<TabWrapperProps>`
|
|
145
|
+
display: inline-flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
justify-content: center;
|
|
148
|
+
gap: ${theme.space.space4};
|
|
149
|
+
cursor: pointer;
|
|
150
|
+
position: relative;
|
|
151
|
+
transition: background-color ${theme.transition.fastEaseOut}, border-color ${theme.transition.fastEaseOut}, color ${theme.transition.fastEaseOut};
|
|
152
|
+
z-index: 1;
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
${({ $variant }) => tabVariantStyle[$variant]};
|
|
156
|
+
|
|
157
|
+
&.disabled {
|
|
158
|
+
color: ${theme.color.neutral.textDisabled};
|
|
159
|
+
pointer-events: none;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.Tab-icon {
|
|
163
|
+
color: inherit;
|
|
164
|
+
flex-shrink: 0;
|
|
165
|
+
transition: color ${theme.transition.fastEaseOut};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.Tab-badge {
|
|
169
|
+
flex-shrink: 0;
|
|
170
|
+
text-transform: uppercase;
|
|
171
|
+
}
|
|
172
|
+
`;
|
|
173
|
+
|
|
174
|
+
export const Tab = ({ variant = 'default', id, to, Icon, title, chip, rollout, className, onSelect, active = false, disabled = false, ...props }: TabProps) => {
|
|
175
|
+
const href = typeof (to) === 'string' ? to : createPath(to);
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<TabWrapper
|
|
179
|
+
{...props}
|
|
180
|
+
id={id}
|
|
181
|
+
to={to}
|
|
182
|
+
role="tab"
|
|
183
|
+
data-test="tab"
|
|
184
|
+
className={clsx(className, { active, disabled })}
|
|
185
|
+
onClick={onSelect ? (event) => onSelect({ id, href, event }) : undefined}
|
|
186
|
+
$variant={variant}
|
|
187
|
+
>
|
|
188
|
+
{Icon && <Icon size="16" className="Tab-icon" />}
|
|
189
|
+
<Text size={tabVariantTextSize[variant]} weight="bold" as="div">{title}</Text>
|
|
190
|
+
{chip && <Badge size={tabVariantBadgeSize[variant]} variant={active ? 'primary_black' : 'neutral_subtle'} className="Tab-badge">{chip}</Badge>}
|
|
191
|
+
{rollout && <Badge size={tabVariantBadgeSize[variant]} variant="primary_blue" className="Tab-badge">{rollout}</Badge>}
|
|
192
|
+
</TabWrapper>
|
|
193
|
+
);
|
|
194
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import useResizeObserver from '@react-hook/resize-observer';
|
|
2
|
+
import { type AriaRole, useCallback, useRef, useState } from 'react';
|
|
3
|
+
import type { FlattenSimpleInterpolation } from 'styled-components';
|
|
4
|
+
import styled, { css } from 'styled-components';
|
|
5
|
+
|
|
6
|
+
import { theme } from '../../design_system/theme.js';
|
|
7
|
+
import type { WithTransientProps } from '../../type_utils.js';
|
|
8
|
+
import type { MarginSpacingProps, RegularBoxProps } from '../box.js';
|
|
9
|
+
import { Box } from '../box.js';
|
|
10
|
+
import { Tab, type TabData, type TabVariant } from './tab.js';
|
|
11
|
+
|
|
12
|
+
type SharedTabsProps = Omit<RegularBoxProps, 'as' | 'onClick'> & MarginSpacingProps;
|
|
13
|
+
type TabsProps = SharedTabsProps & {
|
|
14
|
+
variant?: TabVariant;
|
|
15
|
+
tabs: TabData[];
|
|
16
|
+
activeTab?: string;
|
|
17
|
+
onSelect?: (data: { id: string, href: string, event: React.MouseEvent }) => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const tabsVariantStyle = {
|
|
21
|
+
default: css`
|
|
22
|
+
align-items: flex-start;
|
|
23
|
+
gap: ${theme.space.space8};
|
|
24
|
+
|
|
25
|
+
&::after {
|
|
26
|
+
bottom: 0;
|
|
27
|
+
right: 0;
|
|
28
|
+
left: 0;
|
|
29
|
+
height: 1px;
|
|
30
|
+
background-color: ${theme.color.neutral.separatorSubtle};
|
|
31
|
+
border-radius: ${theme.radius.radiusFull};
|
|
32
|
+
content: '';
|
|
33
|
+
display: block;
|
|
34
|
+
pointer-events: none;
|
|
35
|
+
position: absolute;
|
|
36
|
+
}
|
|
37
|
+
`,
|
|
38
|
+
boxed: css`
|
|
39
|
+
align-items: flex-end;
|
|
40
|
+
|
|
41
|
+
&::after {
|
|
42
|
+
bottom: 0;
|
|
43
|
+
right: 0;
|
|
44
|
+
left: 0;
|
|
45
|
+
height: 1px;
|
|
46
|
+
background-color: ${theme.color.neutral.border};
|
|
47
|
+
content: '';
|
|
48
|
+
display: block;
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
position: absolute;
|
|
51
|
+
}
|
|
52
|
+
`,
|
|
53
|
+
buttoned: css`
|
|
54
|
+
align-items: center;
|
|
55
|
+
`,
|
|
56
|
+
} satisfies Record<TabVariant, FlattenSimpleInterpolation>;
|
|
57
|
+
|
|
58
|
+
type TabsWrapperProps = WithTransientProps<Required<Pick<TabsProps, 'variant'>>> & {
|
|
59
|
+
role?: AriaRole;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const TabsWrapper = styled(Box)<TabsWrapperProps>`
|
|
63
|
+
height: 4rem;
|
|
64
|
+
display: flex;
|
|
65
|
+
position: relative;
|
|
66
|
+
|
|
67
|
+
[role='tabpanel'] {
|
|
68
|
+
min-width: 0;
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-grow: 1;
|
|
71
|
+
overflow-x: auto;
|
|
72
|
+
${({ $variant }) => tabsVariantStyle[$variant]};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
& > [role="cell"] {
|
|
76
|
+
position: sticky;
|
|
77
|
+
top: 0;
|
|
78
|
+
height: 100%;
|
|
79
|
+
width: 0;
|
|
80
|
+
margin-left: auto;
|
|
81
|
+
opacity: 0;
|
|
82
|
+
transition: opacity ${theme.transition.fastEaseOut};
|
|
83
|
+
z-index: 2;
|
|
84
|
+
|
|
85
|
+
&[aria-hidden="false"] {
|
|
86
|
+
opacity: 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&::after {
|
|
90
|
+
height: 100%;
|
|
91
|
+
width: ${theme.space.space32};
|
|
92
|
+
content: ' ';
|
|
93
|
+
pointer-events: none;
|
|
94
|
+
position: absolute;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&:first-of-type {
|
|
98
|
+
left: 0;
|
|
99
|
+
|
|
100
|
+
&::after {
|
|
101
|
+
left: 0;
|
|
102
|
+
background: linear-gradient(90deg, ${theme.color.neutral.background} 0%, rgba(255, 255, 255, 0) 100%);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
&:last-of-type {
|
|
107
|
+
right: 0;
|
|
108
|
+
|
|
109
|
+
&::after {
|
|
110
|
+
right: 0;
|
|
111
|
+
background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, ${theme.color.neutral.background} 100%);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
116
|
+
|
|
117
|
+
type TabOverflowState = {
|
|
118
|
+
right: boolean;
|
|
119
|
+
left: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const isTabsOverflowing = (node: HTMLDivElement): TabOverflowState => {
|
|
123
|
+
if (node.scrollWidth > node.clientWidth) {
|
|
124
|
+
return {
|
|
125
|
+
right: node.clientWidth + node.scrollLeft < node.scrollWidth,
|
|
126
|
+
left: node.scrollLeft > 0,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
right: false,
|
|
132
|
+
left: false,
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const Tabs = ({ variant = 'default', tabs, activeTab, onSelect, ...props }: TabsProps) => {
|
|
137
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
138
|
+
const [overflowState, setOveflowState] = useState<TabOverflowState>();
|
|
139
|
+
|
|
140
|
+
useResizeObserver(ref, (entry) => setOveflowState(isTabsOverflowing(entry.target as HTMLDivElement)));
|
|
141
|
+
const scrollHandler = useCallback((event: React.SyntheticEvent<HTMLDivElement>) => {
|
|
142
|
+
setOveflowState(isTabsOverflowing(event.currentTarget as HTMLDivElement));
|
|
143
|
+
}, []);
|
|
144
|
+
|
|
145
|
+
return <TabsWrapper {...props} role="tablist" data-test="tabs-wrapper" $variant={variant}>
|
|
146
|
+
<div role="cell" aria-hidden={!overflowState?.left} />
|
|
147
|
+
<div ref={ref} role="tabpanel" onScroll={scrollHandler}>
|
|
148
|
+
{tabs.map((tab) => (
|
|
149
|
+
<Tab
|
|
150
|
+
{...tab}
|
|
151
|
+
key={tab.id}
|
|
152
|
+
variant={variant}
|
|
153
|
+
active={tab.id === activeTab}
|
|
154
|
+
onSelect={onSelect}
|
|
155
|
+
/>
|
|
156
|
+
))}
|
|
157
|
+
</div>
|
|
158
|
+
<div role="cell" aria-hidden={!overflowState?.right} />
|
|
159
|
+
</TabsWrapper>;
|
|
160
|
+
};
|