@toptal/picasso-tabs 1.0.1-alpha-fx-4861-find-missing-deep-imports-in-staff-portal-ca4ef823d.4082 → 1.0.1-alpha-fx-4861-find-missing-deep-imports-in-staff-portal-c6a9da7e9.4084

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.
@@ -0,0 +1,77 @@
1
+ import React from 'react'
2
+ import { render } from '@toptal/picasso-test-utils'
3
+ import type { OmitInternalProps } from '@toptal/picasso-shared'
4
+ import * as titleCaseModule from 'ap-style-title-case'
5
+ import type { PicassoConfig } from '@toptal/picasso-test-utils'
6
+
7
+ import type { Props } from './Tab'
8
+ import { Tab } from './Tab'
9
+
10
+ jest.mock('ap-style-title-case')
11
+
12
+ const renderTab = (
13
+ props: OmitInternalProps<Props>,
14
+ picassoConfig?: PicassoConfig
15
+ ) => {
16
+ const { label, disabled, icon, titleCase } = props
17
+
18
+ return render(
19
+ <Tab label={label} disabled={disabled} icon={icon} titleCase={titleCase} />,
20
+ undefined,
21
+ picassoConfig
22
+ )
23
+ }
24
+
25
+ let spiedOnTitleCase: jest.SpyInstance
26
+
27
+ describe('Tab', () => {
28
+ beforeEach(() => {
29
+ spiedOnTitleCase = jest.spyOn(titleCaseModule, 'default')
30
+ })
31
+ afterEach(() => {
32
+ spiedOnTitleCase.mockReset()
33
+ })
34
+
35
+ describe('Tab', () => {
36
+ it('renders', () => {
37
+ const { container } = renderTab({
38
+ label: 'Tab Label',
39
+ })
40
+
41
+ expect(container).toMatchSnapshot()
42
+ })
43
+
44
+ it('disabled tab', () => {
45
+ const { container } = renderTab({
46
+ label: 'Tab Label',
47
+ disabled: true,
48
+ })
49
+
50
+ expect(container).toMatchSnapshot()
51
+ })
52
+
53
+ it('tab with icon', () => {
54
+ const Icon = () => <div id='Icon' />
55
+ const { container } = renderTab({
56
+ label: 'Tab Label',
57
+ icon: <Icon />,
58
+ })
59
+
60
+ expect(container).toMatchSnapshot()
61
+ })
62
+
63
+ it('should transform text to title case when Picasso titleCase property is true', () => {
64
+ const LABEL_TEXT = 'Test vh2'
65
+
66
+ renderTab({ label: LABEL_TEXT }, { titleCase: true })
67
+
68
+ expect(spiedOnTitleCase).toHaveBeenCalledWith(LABEL_TEXT)
69
+ })
70
+
71
+ it('should not transform text to title case when Picasso titleCase property is true but the component property overrides it', () => {
72
+ renderTab({ label: 'abc sp3', titleCase: false }, { titleCase: true })
73
+
74
+ expect(spiedOnTitleCase).toHaveBeenCalledTimes(0)
75
+ })
76
+ })
77
+ })
@@ -0,0 +1,31 @@
1
+ import React from 'react'
2
+ import type { Theme } from '@material-ui/core/styles'
3
+ import { makeStyles } from '@material-ui/core/styles'
4
+ import { TypographyOverflow } from '@toptal/picasso-typography-overflow'
5
+
6
+ import styles from './styles'
7
+
8
+ interface Props {
9
+ children: string
10
+ disabled?: boolean
11
+ }
12
+
13
+ const useStyles = makeStyles<Theme>(styles, { name: 'PicassoTabDescription' })
14
+
15
+ const TabDescription = ({ children, disabled }: Props) => {
16
+ const classes = useStyles()
17
+ const color = disabled ? 'inherit' : undefined
18
+
19
+ return (
20
+ <TypographyOverflow
21
+ className={classes.root}
22
+ size='xxsmall'
23
+ inline
24
+ color={color}
25
+ >
26
+ {children}
27
+ </TypographyOverflow>
28
+ )
29
+ }
30
+
31
+ export default TabDescription
@@ -0,0 +1 @@
1
+ export { default as TabDescription } from './TabDescription'
@@ -0,0 +1,7 @@
1
+ import { rem } from '@toptal/picasso-shared'
2
+
3
+ export default {
4
+ root: {
5
+ marginTop: rem('2px'),
6
+ },
7
+ }
@@ -0,0 +1,35 @@
1
+ import React from 'react'
2
+ import { TypographyOverflow } from '@toptal/picasso-typography-overflow'
3
+ import { Typography } from '@toptal/picasso-typography'
4
+ import { toTitleCase } from '@toptal/picasso-utils'
5
+
6
+ interface Props {
7
+ label?: React.ReactNode
8
+ orientation: 'horizontal' | 'vertical'
9
+ titleCase?: boolean
10
+ }
11
+
12
+ const TabLabel = ({ label, orientation, titleCase }: Props) => {
13
+ if (orientation === 'horizontal') {
14
+ return (
15
+ <Typography as='div' size='small' weight='semibold' color='inherit'>
16
+ {titleCase ? toTitleCase(label) : label}
17
+ </Typography>
18
+ )
19
+ }
20
+
21
+ return (
22
+ <TypographyOverflow
23
+ as='div'
24
+ color='inherit'
25
+ inline
26
+ size='medium'
27
+ variant='body'
28
+ weight='semibold'
29
+ >
30
+ {titleCase ? toTitleCase(label) : label}
31
+ </TypographyOverflow>
32
+ )
33
+ }
34
+
35
+ export default TabLabel
@@ -0,0 +1 @@
1
+ export { default as TabLabel } from './TabLabel'
@@ -0,0 +1,64 @@
1
+ import cx from 'classnames'
2
+ import React, { forwardRef } from 'react'
3
+ import { ButtonBase } from '@material-ui/core'
4
+ import { makeStyles } from '@material-ui/core/styles'
5
+ import type { BaseProps } from '@toptal/picasso-shared'
6
+ import { BackMinor16, ChevronMinor16 } from '@toptal/picasso-icons'
7
+ import { Container } from '@toptal/picasso-container'
8
+
9
+ import styles from './styles'
10
+
11
+ type DirectionType = 'left' | 'right'
12
+
13
+ export interface Props extends BaseProps {
14
+ /** The direction the button should indicate. */
15
+ direction: DirectionType
16
+ /** If `true`, the component is disabled. */
17
+ disabled?: boolean
18
+ }
19
+
20
+ const useStyles = makeStyles(styles, {
21
+ name: 'PicassoTabScrollButton',
22
+ })
23
+
24
+ export const TabScrollButton = forwardRef<HTMLDivElement, Props>(
25
+ function TabScrollButton(props, ref) {
26
+ const { className, style, direction, disabled, ...rest } = props
27
+ const classes = useStyles()
28
+
29
+ if (disabled) {
30
+ return null
31
+ }
32
+
33
+ return (
34
+ <Container
35
+ {...rest}
36
+ ref={ref}
37
+ className={cx(classes.root, className)}
38
+ style={style}
39
+ >
40
+ <Container
41
+ className={cx(classes.gradient, {
42
+ [classes.left]: direction === 'left',
43
+ [classes.right]: direction === 'right',
44
+ })}
45
+ >
46
+ <ButtonBase
47
+ className={cx(classes.button, {
48
+ [classes.left]: direction === 'left',
49
+ [classes.right]: direction === 'right',
50
+ })}
51
+ aria-label={`${direction} button`}
52
+ data-testid={`tab-scroll-button-${direction}`}
53
+ >
54
+ {direction === 'left' ? <BackMinor16 /> : <ChevronMinor16 />}
55
+ </ButtonBase>
56
+ </Container>
57
+ </Container>
58
+ )
59
+ }
60
+ )
61
+
62
+ TabScrollButton.displayName = 'TabScrollButton'
63
+
64
+ export default TabScrollButton
@@ -0,0 +1,6 @@
1
+ import type { OmitInternalProps } from '@toptal/picasso-shared'
2
+
3
+ import type { Props } from './TabScrollButton'
4
+
5
+ export { default as TabScrollButton } from './TabScrollButton'
6
+ export type TabScrollButtonProps = OmitInternalProps<Props>
@@ -0,0 +1,37 @@
1
+ import { createStyles } from '@material-ui/core'
2
+ import type { Theme } from '@material-ui/core/styles'
3
+ import { alpha } from '@toptal/picasso-shared'
4
+
5
+ export default ({ palette }: Theme) => {
6
+ const color = palette.common.white
7
+ const colorStops = `${color} 0%, ${color} 50%, ${alpha(color, 0)} 100%`
8
+
9
+ return createStyles({
10
+ root: {
11
+ position: 'relative',
12
+ },
13
+ gradient: {
14
+ position: 'absolute',
15
+ width: '2.5rem',
16
+ height: '100%',
17
+ zIndex: 2,
18
+ '&$left': {
19
+ background: `linear-gradient(90deg, ${colorStops})`,
20
+ },
21
+ '&$right': {
22
+ background: `linear-gradient(270deg, ${colorStops})`,
23
+ },
24
+ },
25
+ button: {
26
+ position: 'absolute',
27
+ width: '1rem',
28
+ height: '100%',
29
+ },
30
+ left: {
31
+ left: 0,
32
+ },
33
+ right: {
34
+ right: 0,
35
+ },
36
+ })
37
+ }
@@ -0,0 +1,81 @@
1
+ import type { ReactNode } from 'react'
2
+ import React, { forwardRef } from 'react'
3
+ import type { Theme } from '@material-ui/core/styles'
4
+ import { makeStyles } from '@material-ui/core/styles'
5
+ import type { TabsProps } from '@material-ui/core'
6
+ import { Tabs as MUITabs } from '@material-ui/core'
7
+ import type { ButtonOrAnchorProps, BaseProps } from '@toptal/picasso-shared'
8
+
9
+ import { TabScrollButton } from '../TabScrollButton'
10
+ import styles from './styles'
11
+ import useTabAction from './use-tab-action'
12
+
13
+ export interface Props
14
+ extends BaseProps,
15
+ Omit<ButtonOrAnchorProps, 'onChange'> {
16
+ /** Tabs content containing Tab components */
17
+ children: ReactNode
18
+
19
+ /** Callback fired when the value changes. */
20
+ onChange?: (event: React.ChangeEvent<{}>, value: TabsProps['value']) => void
21
+
22
+ /** The value of the currently selected Tab. If you don't want any selected Tab, you can set this property to false. */
23
+ value: TabsProps['value']
24
+
25
+ /** The tabs orientation (layout flow direction). */
26
+ orientation?: 'horizontal' | 'vertical'
27
+
28
+ /** Determines additional display behavior of the tabs */
29
+ variant?: Extract<TabsProps['variant'], 'scrollable' | 'fullWidth'>
30
+ }
31
+
32
+ const useStyles = makeStyles<Theme>(styles, {
33
+ name: 'Tabs',
34
+ })
35
+
36
+ export const TabsOrientationContext = React.createContext<
37
+ 'horizontal' | 'vertical'
38
+ >('horizontal')
39
+
40
+ // eslint-disable-next-line react/display-name
41
+ export const Tabs = forwardRef<HTMLButtonElement, Props>(function Tabs(
42
+ props,
43
+ ref
44
+ ) {
45
+ const {
46
+ children,
47
+ orientation,
48
+ onChange,
49
+ value,
50
+ variant = 'scrollable',
51
+ ...rest
52
+ } = props
53
+ const classes = useStyles(props)
54
+ const action = useTabAction()
55
+
56
+ return (
57
+ <TabsOrientationContext.Provider value={orientation!}>
58
+ <MUITabs
59
+ {...rest}
60
+ classes={{ root: classes[orientation!] }}
61
+ ref={ref}
62
+ onChange={onChange}
63
+ value={value}
64
+ action={action}
65
+ scrollButtons='auto'
66
+ ScrollButtonComponent={TabScrollButton}
67
+ orientation={orientation}
68
+ variant={variant}
69
+ >
70
+ {children}
71
+ </MUITabs>
72
+ </TabsOrientationContext.Provider>
73
+ )
74
+ })
75
+
76
+ Tabs.displayName = 'Tabs'
77
+ Tabs.defaultProps = {
78
+ orientation: 'horizontal',
79
+ }
80
+
81
+ export default Tabs
@@ -0,0 +1,346 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Tabs renders 1`] = `
4
+ <div>
5
+ <div
6
+ class="Picasso-root"
7
+ >
8
+ <div
9
+ class="MuiTabs-root Tabs-horizontal"
10
+ >
11
+ <div
12
+ class="MuiTabs-scrollable"
13
+ style="width: 99px; height: 99px; position: absolute; top: -9999px; overflow: scroll;"
14
+ />
15
+ <div
16
+ class="MuiTabs-scroller MuiTabs-scrollable"
17
+ style="margin-bottom: 0px;"
18
+ >
19
+ <div
20
+ class="MuiTabs-flexContainer"
21
+ role="tablist"
22
+ >
23
+ <button
24
+ aria-selected="false"
25
+ class="MuiButtonBase-root MuiTab-root PicassoTab-horizontal MuiTab-textColorInherit"
26
+ data-testid="tab-1"
27
+ role="tab"
28
+ tabindex="0"
29
+ type="button"
30
+ >
31
+ <span
32
+ class="MuiTab-wrapper PicassoTab-wrapper"
33
+ >
34
+ <div
35
+ class="MuiTypography-root PicassoTypography-bodySmall PicassoTypography-inherit PicassoTypography-semibold MuiTypography-body1"
36
+ >
37
+ Tab 1
38
+ </div>
39
+ </span>
40
+ </button>
41
+ <button
42
+ aria-selected="false"
43
+ class="MuiButtonBase-root MuiTab-root PicassoTab-horizontal MuiTab-textColorInherit"
44
+ data-testid="tab-2"
45
+ role="tab"
46
+ tabindex="0"
47
+ type="button"
48
+ >
49
+ <span
50
+ class="MuiTab-wrapper PicassoTab-wrapper"
51
+ >
52
+ <div
53
+ class="MuiTypography-root PicassoTypography-bodySmall PicassoTypography-inherit PicassoTypography-semibold MuiTypography-body1"
54
+ >
55
+ Tab 2
56
+ </div>
57
+ </span>
58
+ </button>
59
+ </div>
60
+ <span
61
+ class="PrivateTabIndicator-root PrivateTabIndicator-colorSecondary MuiTabs-indicator"
62
+ style="left: 0px; width: 0px;"
63
+ />
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ `;
69
+
70
+ exports[`Tabs renders in full width 1`] = `
71
+ <div>
72
+ <div
73
+ class="Picasso-root"
74
+ >
75
+ <div
76
+ class="MuiTabs-root Tabs-horizontal"
77
+ >
78
+ <div
79
+ class="MuiTabs-scroller MuiTabs-fixed"
80
+ style="overflow: hidden;"
81
+ >
82
+ <div
83
+ class="MuiTabs-flexContainer"
84
+ role="tablist"
85
+ >
86
+ <button
87
+ aria-selected="false"
88
+ class="MuiButtonBase-root MuiTab-root PicassoTab-horizontal MuiTab-textColorInherit MuiTab-fullWidth"
89
+ data-testid="tab-1"
90
+ role="tab"
91
+ tabindex="0"
92
+ type="button"
93
+ >
94
+ <span
95
+ class="MuiTab-wrapper PicassoTab-wrapper"
96
+ >
97
+ <div
98
+ class="MuiTypography-root PicassoTypography-bodySmall PicassoTypography-inherit PicassoTypography-semibold MuiTypography-body1"
99
+ >
100
+ Tab 1
101
+ </div>
102
+ </span>
103
+ </button>
104
+ <button
105
+ aria-selected="false"
106
+ class="MuiButtonBase-root MuiTab-root PicassoTab-horizontal MuiTab-textColorInherit MuiTab-fullWidth"
107
+ data-testid="tab-2"
108
+ role="tab"
109
+ tabindex="0"
110
+ type="button"
111
+ >
112
+ <span
113
+ class="MuiTab-wrapper PicassoTab-wrapper"
114
+ >
115
+ <div
116
+ class="MuiTypography-root PicassoTypography-bodySmall PicassoTypography-inherit PicassoTypography-semibold MuiTypography-body1"
117
+ >
118
+ Tab 2
119
+ </div>
120
+ </span>
121
+ </button>
122
+ </div>
123
+ <span
124
+ class="PrivateTabIndicator-root PrivateTabIndicator-colorSecondary MuiTabs-indicator"
125
+ style="left: 0px; width: 0px;"
126
+ />
127
+ </div>
128
+ </div>
129
+ </div>
130
+ </div>
131
+ `;
132
+
133
+ exports[`Tabs renders in vertical orientation 1`] = `
134
+ <div>
135
+ <div
136
+ class="Picasso-root"
137
+ >
138
+ <div
139
+ class="MuiTabs-root Tabs-vertical MuiTabs-vertical"
140
+ >
141
+ <div
142
+ class="MuiTabs-scrollable"
143
+ style="width: 99px; height: 99px; position: absolute; top: -9999px; overflow: scroll;"
144
+ />
145
+ <div
146
+ class="MuiTabs-scroller MuiTabs-scrollable"
147
+ style="margin-bottom: 0px;"
148
+ >
149
+ <div
150
+ class="MuiTabs-flexContainer MuiTabs-flexContainerVertical"
151
+ role="tablist"
152
+ >
153
+ <button
154
+ aria-selected="false"
155
+ class="MuiButtonBase-root MuiTab-root PicassoTab-vertical MuiTab-textColorInherit"
156
+ data-testid="tab-1"
157
+ role="tab"
158
+ tabindex="0"
159
+ type="button"
160
+ >
161
+ <span
162
+ class="MuiTab-wrapper PicassoTab-wrapper"
163
+ >
164
+ <div
165
+ class="MuiTypography-root PicassoTypography-bodyMedium PicassoTypography-inherit PicassoTypography-semibold TypographyOverflow-wrapper TypographyOverflow-singleLine MuiTypography-body1 MuiTypography-noWrap MuiTypography-displayInline"
166
+ >
167
+ Tab 1
168
+ </div>
169
+ </span>
170
+ </button>
171
+ <button
172
+ aria-selected="false"
173
+ class="MuiButtonBase-root MuiTab-root PicassoTab-vertical MuiTab-textColorInherit"
174
+ data-testid="tab-2"
175
+ role="tab"
176
+ tabindex="0"
177
+ type="button"
178
+ >
179
+ <span
180
+ class="MuiTab-wrapper PicassoTab-wrapper"
181
+ >
182
+ <div
183
+ class="MuiTypography-root PicassoTypography-bodyMedium PicassoTypography-inherit PicassoTypography-semibold TypographyOverflow-wrapper TypographyOverflow-singleLine MuiTypography-body1 MuiTypography-noWrap MuiTypography-displayInline"
184
+ >
185
+ Tab 2
186
+ </div>
187
+ </span>
188
+ </button>
189
+ </div>
190
+ <span
191
+ class="PrivateTabIndicator-root PrivateTabIndicator-colorSecondary MuiTabs-indicator PrivateTabIndicator-vertical"
192
+ style="top: 0px; height: 0px;"
193
+ />
194
+ </div>
195
+ </div>
196
+ </div>
197
+ </div>
198
+ `;
199
+
200
+ exports[`Tabs renders with a pre-selected option 1`] = `
201
+ <div>
202
+ <div
203
+ class="Picasso-root"
204
+ >
205
+ <div
206
+ class="MuiTabs-root Tabs-horizontal"
207
+ >
208
+ <div
209
+ class="MuiTabs-scrollable"
210
+ style="width: 99px; height: 99px; position: absolute; top: -9999px; overflow: scroll;"
211
+ />
212
+ <div
213
+ class="MuiTabs-scroller MuiTabs-scrollable"
214
+ style="margin-bottom: 0px;"
215
+ >
216
+ <div
217
+ class="MuiTabs-flexContainer"
218
+ role="tablist"
219
+ >
220
+ <button
221
+ aria-selected="false"
222
+ class="MuiButtonBase-root MuiTab-root PicassoTab-horizontal MuiTab-textColorInherit"
223
+ data-testid="tab-1"
224
+ role="tab"
225
+ tabindex="0"
226
+ type="button"
227
+ >
228
+ <span
229
+ class="MuiTab-wrapper PicassoTab-wrapper"
230
+ >
231
+ <div
232
+ class="MuiTypography-root PicassoTypography-bodySmall PicassoTypography-inherit PicassoTypography-semibold MuiTypography-body1"
233
+ >
234
+ Tab 1
235
+ </div>
236
+ </span>
237
+ </button>
238
+ <button
239
+ aria-selected="true"
240
+ class="MuiButtonBase-root MuiTab-root PicassoTab-horizontal MuiTab-textColorInherit Mui-selected PicassoTab-selected"
241
+ data-testid="tab-2"
242
+ role="tab"
243
+ tabindex="0"
244
+ type="button"
245
+ >
246
+ <span
247
+ class="MuiTab-wrapper PicassoTab-wrapper"
248
+ >
249
+ <div
250
+ class="MuiTypography-root PicassoTypography-bodySmall PicassoTypography-inherit PicassoTypography-semibold MuiTypography-body1"
251
+ >
252
+ Tab 2
253
+ </div>
254
+ </span>
255
+ </button>
256
+ </div>
257
+ <span
258
+ class="PrivateTabIndicator-root PrivateTabIndicator-colorSecondary MuiTabs-indicator"
259
+ style="left: 0px; width: 0px;"
260
+ />
261
+ </div>
262
+ </div>
263
+ <div
264
+ data-testid="tab-1-content"
265
+ >
266
+ Tab #
267
+ 1
268
+ content
269
+ </div>
270
+ </div>
271
+ </div>
272
+ `;
273
+
274
+ exports[`Tabs renders with a pre-selected option using custom value 1`] = `
275
+ <div>
276
+ <div
277
+ class="Picasso-root"
278
+ >
279
+ <div
280
+ class="MuiTabs-root Tabs-horizontal"
281
+ >
282
+ <div
283
+ class="MuiTabs-scrollable"
284
+ style="width: 99px; height: 99px; position: absolute; top: -9999px; overflow: scroll;"
285
+ />
286
+ <div
287
+ class="MuiTabs-scroller MuiTabs-scrollable"
288
+ style="margin-bottom: 0px;"
289
+ >
290
+ <div
291
+ class="MuiTabs-flexContainer"
292
+ role="tablist"
293
+ >
294
+ <button
295
+ aria-selected="true"
296
+ class="MuiButtonBase-root MuiTab-root PicassoTab-horizontal MuiTab-textColorInherit Mui-selected PicassoTab-selected"
297
+ data-testid="tab-1"
298
+ role="tab"
299
+ tabindex="0"
300
+ type="button"
301
+ >
302
+ <span
303
+ class="MuiTab-wrapper PicassoTab-wrapper"
304
+ >
305
+ <div
306
+ class="MuiTypography-root PicassoTypography-bodySmall PicassoTypography-inherit PicassoTypography-semibold MuiTypography-body1"
307
+ >
308
+ Tab 1
309
+ </div>
310
+ </span>
311
+ </button>
312
+ <button
313
+ aria-selected="false"
314
+ class="MuiButtonBase-root MuiTab-root PicassoTab-horizontal MuiTab-textColorInherit"
315
+ data-testid="tab-2"
316
+ role="tab"
317
+ tabindex="0"
318
+ type="button"
319
+ >
320
+ <span
321
+ class="MuiTab-wrapper PicassoTab-wrapper"
322
+ >
323
+ <div
324
+ class="MuiTypography-root PicassoTypography-bodySmall PicassoTypography-inherit PicassoTypography-semibold MuiTypography-body1"
325
+ >
326
+ Tab 2
327
+ </div>
328
+ </span>
329
+ </button>
330
+ </div>
331
+ <span
332
+ class="PrivateTabIndicator-root PrivateTabIndicator-colorSecondary MuiTabs-indicator"
333
+ style="left: 0px; width: 0px;"
334
+ />
335
+ </div>
336
+ </div>
337
+ <div
338
+ data-testid="tab-1-content"
339
+ >
340
+ Tab #
341
+ 1
342
+ content
343
+ </div>
344
+ </div>
345
+ </div>
346
+ `;