@superdispatch/ui-lab 0.21.8 → 0.21.12
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/.babelrc.js +5 -0
- package/.turbo/turbo-version.log +28 -0
- package/package.json +59 -34
- package/pkg/README.md +10 -0
- package/{dist-node → pkg/dist-node}/index.js +25 -23
- package/pkg/dist-node/index.js.map +1 -0
- package/{dist-src → pkg/dist-src}/alert/Alert.js +2 -4
- package/{dist-src → pkg/dist-src}/banner/Banner.js +0 -0
- package/{dist-src → pkg/dist-src}/box/Box.js +0 -0
- package/{dist-src → pkg/dist-src}/button/Button.js +0 -0
- package/{dist-src → pkg/dist-src}/button-area/ButtonArea.js +0 -0
- package/{dist-src → pkg/dist-src}/container/Container.js +0 -0
- package/{dist-src → pkg/dist-src}/description-item/DescriptionItem.js +0 -0
- package/{dist-src → pkg/dist-src}/file-drop-zone/FileDropZone.js +0 -0
- package/{dist-src → pkg/dist-src}/file-list-item/FileListItem.js +0 -0
- package/{dist-src → pkg/dist-src}/index.js +0 -0
- package/{dist-src → pkg/dist-src}/linked-text/LinkedText.js +0 -0
- package/{dist-src → pkg/dist-src}/multiline-text/MultilineText.js +0 -0
- package/{dist-src → pkg/dist-src}/navbar/Navbar.js +0 -0
- package/{dist-src → pkg/dist-src}/navbar/NavbarAccordion.js +5 -10
- package/{dist-src → pkg/dist-src}/navbar/NavbarAvatar.js +0 -0
- package/{dist-src → pkg/dist-src}/navbar/NavbarBottomBar.js +16 -6
- package/{dist-src → pkg/dist-src}/navbar/NavbarContext.js +0 -0
- package/{dist-src → pkg/dist-src}/navbar/NavbarItem.js +0 -0
- package/{dist-src → pkg/dist-src}/navbar/NavbarList.js +0 -0
- package/{dist-src → pkg/dist-src}/navbar/NavbarMenu.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/Sidebar.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarBackButton.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarContainer.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarContent.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarDivider.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarMenuItem.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarMenuItemAction.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarMenuItemAvatar.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarMenuItemContext.js +0 -0
- package/{dist-src → pkg/dist-src}/sidebar/SidebarSubheader.js +0 -0
- package/{dist-src → pkg/dist-src}/text-box/TextBox.js +0 -0
- package/{dist-src → pkg/dist-src}/utils/RuleNormalizer.js +0 -0
- package/{dist-src → pkg/dist-src}/utils/mergeStyles.js +0 -0
- package/{dist-types → pkg/dist-types}/index.d.ts +308 -308
- package/{dist-web → pkg/dist-web}/index.js +26 -24
- package/pkg/dist-web/index.js.map +1 -0
- package/pkg/package.json +34 -0
- package/playroom.ts +23 -0
- package/src/alert/Alert.stories.tsx +105 -0
- package/src/alert/Alert.tsx +108 -0
- package/src/banner/Banner.stories.tsx +64 -0
- package/src/banner/Banner.tsx +120 -0
- package/src/box/Box.stories.tsx +20 -0
- package/src/box/Box.tsx +252 -0
- package/src/button/Button.stories.tsx +717 -0
- package/src/button/Button.tsx +460 -0
- package/src/button-area/ButtonArea.stories.tsx +65 -0
- package/src/button-area/ButtonArea.tsx +88 -0
- package/src/container/Container.tsx +48 -0
- package/src/description-item/DescriptionItem.stories.tsx +163 -0
- package/src/description-item/DescriptionItem.tsx +104 -0
- package/src/file-drop-zone/FileDropZone.stories.tsx +44 -0
- package/src/file-drop-zone/FileDropZone.tsx +170 -0
- package/src/file-list-item/FileListItem.stories.tsx +37 -0
- package/src/file-list-item/FileListItem.tsx +145 -0
- package/src/file-list-item/__tests__/FileListItem.spec.tsx +339 -0
- package/src/index.spec.ts +43 -0
- package/src/index.ts +28 -0
- package/src/linked-text/LinkeText.stories.tsx +42 -0
- package/src/linked-text/LinkedText.tsx +47 -0
- package/src/multiline-text/MultilineText.stories.tsx +30 -0
- package/src/multiline-text/MultilineText.ts +16 -0
- package/src/navbar/Navbar.stories.tsx +135 -0
- package/src/navbar/Navbar.tsx +111 -0
- package/src/navbar/NavbarAccordion.tsx +171 -0
- package/src/navbar/NavbarAvatar.tsx +51 -0
- package/src/navbar/NavbarBottomBar.tsx +135 -0
- package/src/navbar/NavbarContext.tsx +23 -0
- package/src/navbar/NavbarItem.tsx +119 -0
- package/src/navbar/NavbarList.tsx +225 -0
- package/src/navbar/NavbarMenu.tsx +102 -0
- package/src/sidebar/Sidebar.stories.tsx +363 -0
- package/src/sidebar/Sidebar.tsx +73 -0
- package/src/sidebar/SidebarBackButton.tsx +33 -0
- package/src/sidebar/SidebarContainer.tsx +114 -0
- package/src/sidebar/SidebarContent.tsx +119 -0
- package/src/sidebar/SidebarDivider.tsx +15 -0
- package/src/sidebar/SidebarMenuItem.tsx +211 -0
- package/src/sidebar/SidebarMenuItemAction.tsx +27 -0
- package/src/sidebar/SidebarMenuItemAvatar.tsx +59 -0
- package/src/sidebar/SidebarMenuItemContext.tsx +33 -0
- package/src/sidebar/SidebarSubheader.tsx +38 -0
- package/src/styled.d.ts +12 -0
- package/src/text-box/TextBox.stories.tsx +108 -0
- package/src/text-box/TextBox.tsx +229 -0
- package/src/utils/RuleNormalizer.ts +24 -0
- package/src/utils/mergeStyles.ts +28 -0
- package/tsconfig.json +19 -0
- package/LICENSE +0 -21
- package/dist-node/index.js.map +0 -1
- package/dist-web/index.js.map +0 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { Column, Columns, Inline, Stack } from '@superdispatch/ui';
|
|
3
|
+
import { Button } from '../button/Button';
|
|
4
|
+
import { Alert } from './Alert';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Lab/Alert',
|
|
8
|
+
component: Alert,
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
export const basic = () => (
|
|
12
|
+
<Columns collapseBelow="tablet" space="xsmall">
|
|
13
|
+
<Column>
|
|
14
|
+
<Stack>
|
|
15
|
+
<Alert severity="positive">
|
|
16
|
+
<Inline verticalAlign="center">
|
|
17
|
+
<span>This is an error alert — check it out!</span>
|
|
18
|
+
<Button variant="neutral" size="small">
|
|
19
|
+
Button
|
|
20
|
+
</Button>
|
|
21
|
+
</Inline>
|
|
22
|
+
</Alert>
|
|
23
|
+
|
|
24
|
+
<Alert severity="info">
|
|
25
|
+
<Inline verticalAlign="center">
|
|
26
|
+
<span>This is an error alert — check it out!</span>
|
|
27
|
+
<Button variant="neutral" size="small">
|
|
28
|
+
Button
|
|
29
|
+
</Button>
|
|
30
|
+
</Inline>
|
|
31
|
+
</Alert>
|
|
32
|
+
|
|
33
|
+
<Alert severity="caution">
|
|
34
|
+
<Inline verticalAlign="center">
|
|
35
|
+
<span>This is an error alert — check it out!</span>
|
|
36
|
+
<Button variant="neutral" size="small">
|
|
37
|
+
Button
|
|
38
|
+
</Button>
|
|
39
|
+
</Inline>
|
|
40
|
+
</Alert>
|
|
41
|
+
|
|
42
|
+
<Alert severity="critical">
|
|
43
|
+
<Inline verticalAlign="center">
|
|
44
|
+
<span>This is an error alert — check it out!</span>
|
|
45
|
+
<Button variant="neutral" size="small">
|
|
46
|
+
Button
|
|
47
|
+
</Button>
|
|
48
|
+
</Inline>
|
|
49
|
+
</Alert>
|
|
50
|
+
</Stack>
|
|
51
|
+
</Column>
|
|
52
|
+
|
|
53
|
+
<Column>
|
|
54
|
+
<Stack>
|
|
55
|
+
<Alert severity="positive">
|
|
56
|
+
<Inline verticalAlign="center">
|
|
57
|
+
<span>
|
|
58
|
+
Uh-Oh! Your Super Carrier documents need review. please submit the
|
|
59
|
+
following documents. Don’t worry! Be happy!
|
|
60
|
+
</span>
|
|
61
|
+
<Button variant="neutral" size="small">
|
|
62
|
+
Button
|
|
63
|
+
</Button>
|
|
64
|
+
</Inline>
|
|
65
|
+
</Alert>
|
|
66
|
+
|
|
67
|
+
<Alert severity="info">
|
|
68
|
+
<Inline verticalAlign="center">
|
|
69
|
+
<span>
|
|
70
|
+
Uh-Oh! Your Super Carrier documents need review. please submit the
|
|
71
|
+
following documents. Don’t worry! Be happy!
|
|
72
|
+
</span>
|
|
73
|
+
<Button variant="neutral" size="small">
|
|
74
|
+
Button
|
|
75
|
+
</Button>
|
|
76
|
+
</Inline>
|
|
77
|
+
</Alert>
|
|
78
|
+
|
|
79
|
+
<Alert severity="caution">
|
|
80
|
+
<Inline verticalAlign="center">
|
|
81
|
+
<span>
|
|
82
|
+
Uh-Oh! Your Super Carrier documents need review. please submit the
|
|
83
|
+
following documents. Don’t worry! Be happy!
|
|
84
|
+
</span>
|
|
85
|
+
<Button variant="neutral" size="small">
|
|
86
|
+
Button
|
|
87
|
+
</Button>
|
|
88
|
+
</Inline>
|
|
89
|
+
</Alert>
|
|
90
|
+
|
|
91
|
+
<Alert severity="critical">
|
|
92
|
+
<Inline verticalAlign="center">
|
|
93
|
+
<span>
|
|
94
|
+
Uh-Oh! Your Super Carrier documents need review. please submit the
|
|
95
|
+
following documents. Don’t worry! Be happy!
|
|
96
|
+
</span>
|
|
97
|
+
<Button variant="neutral" size="small">
|
|
98
|
+
Button
|
|
99
|
+
</Button>
|
|
100
|
+
</Inline>
|
|
101
|
+
</Alert>
|
|
102
|
+
</Stack>
|
|
103
|
+
</Column>
|
|
104
|
+
</Columns>
|
|
105
|
+
);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { CheckCircle, Error, Info } from '@material-ui/icons';
|
|
2
|
+
import {
|
|
3
|
+
Alert as MaterialAlert,
|
|
4
|
+
AlertProps as MaterialAlertProps,
|
|
5
|
+
} from '@material-ui/lab';
|
|
6
|
+
import { Color } from '@superdispatch/ui';
|
|
7
|
+
import { forwardRef, ReactNode } from 'react';
|
|
8
|
+
import styled, { css, SimpleInterpolation } from 'styled-components';
|
|
9
|
+
|
|
10
|
+
function colorMixin(
|
|
11
|
+
textColor: Color,
|
|
12
|
+
backgroundColor: Color,
|
|
13
|
+
buttonHoverColor: Color,
|
|
14
|
+
): readonly SimpleInterpolation[] {
|
|
15
|
+
return css`
|
|
16
|
+
color: ${textColor};
|
|
17
|
+
background-color: ${backgroundColor};
|
|
18
|
+
|
|
19
|
+
& .MuiAlert-icon {
|
|
20
|
+
color: ${textColor};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
& .MuiAlert-action {
|
|
24
|
+
& .MuiIconButton-root {
|
|
25
|
+
&:hover,
|
|
26
|
+
&:active {
|
|
27
|
+
color: ${buttonHoverColor};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const StyledAlert = styled(MaterialAlert)`
|
|
35
|
+
&.MuiAlert-outlinedSuccess {
|
|
36
|
+
${colorMixin(Color.Green500, Color.Green50, Color.Green400)};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&.MuiAlert-outlinedInfo {
|
|
40
|
+
${colorMixin(Color.Blue500, Color.Blue50, Color.Blue400)};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&.MuiAlert-outlinedWarning {
|
|
44
|
+
${colorMixin(Color.Yellow500, Color.Yellow50, Color.Yellow400)};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.MuiAlert-outlinedError {
|
|
48
|
+
${colorMixin(Color.Red500, Color.Red50, Color.Red400)};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
& .MuiAlert-icon {
|
|
52
|
+
opacity: 1;
|
|
53
|
+
padding: 8px 0;
|
|
54
|
+
font-size: 24px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
& .MuiAlert-action {
|
|
58
|
+
display: block;
|
|
59
|
+
padding-top: 5px;
|
|
60
|
+
margin-right: -3px;
|
|
61
|
+
|
|
62
|
+
& .MuiIconButton-root {
|
|
63
|
+
& .MuiSvgIcon-root {
|
|
64
|
+
font-size: 24px;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
export type AlertSeverityProp = 'positive' | 'info' | 'caution' | 'critical';
|
|
71
|
+
|
|
72
|
+
export interface AlertProps {
|
|
73
|
+
onClose?: () => void;
|
|
74
|
+
children?: ReactNode;
|
|
75
|
+
severity?: AlertSeverityProp;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function toMaterialSeverity(
|
|
79
|
+
severity: AlertSeverityProp,
|
|
80
|
+
): MaterialAlertProps['severity'] {
|
|
81
|
+
return severity === 'info'
|
|
82
|
+
? 'info'
|
|
83
|
+
: severity === 'caution'
|
|
84
|
+
? 'warning'
|
|
85
|
+
: severity === 'critical'
|
|
86
|
+
? 'error'
|
|
87
|
+
: 'success';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const iconMapping: MaterialAlertProps['iconMapping'] = {
|
|
91
|
+
success: <CheckCircle />,
|
|
92
|
+
info: <Info />,
|
|
93
|
+
error: <Error />,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const Alert = forwardRef<HTMLDivElement, AlertProps>(
|
|
97
|
+
({ children, onClose, severity = 'positive' }, ref) => (
|
|
98
|
+
<StyledAlert
|
|
99
|
+
ref={ref}
|
|
100
|
+
variant="outlined"
|
|
101
|
+
iconMapping={iconMapping}
|
|
102
|
+
severity={toMaterialSeverity(severity)}
|
|
103
|
+
onClose={onClose}
|
|
104
|
+
>
|
|
105
|
+
{children}
|
|
106
|
+
</StyledAlert>
|
|
107
|
+
),
|
|
108
|
+
);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Link } from '@material-ui/core';
|
|
2
|
+
import { Meta } from '@storybook/react';
|
|
3
|
+
import { Inline, Stack } from '@superdispatch/ui';
|
|
4
|
+
import { UseState } from '@superdispatch/ui-docs';
|
|
5
|
+
import { Button } from '../button/Button';
|
|
6
|
+
import { TextBox } from '../text-box/TextBox';
|
|
7
|
+
import { Banner } from './Banner';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: 'Lab/Banner',
|
|
11
|
+
component: Banner,
|
|
12
|
+
} as Meta;
|
|
13
|
+
|
|
14
|
+
export const basic = () => (
|
|
15
|
+
<Stack>
|
|
16
|
+
<UseState initialState={true}>
|
|
17
|
+
{(open, setOpen) => (
|
|
18
|
+
<Stack space="none">
|
|
19
|
+
<Button
|
|
20
|
+
size="small"
|
|
21
|
+
variant="neutral"
|
|
22
|
+
aria-label="Rate Button"
|
|
23
|
+
onClick={() => {
|
|
24
|
+
setOpen(!open);
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
{open ? 'Close' : 'Open'}
|
|
28
|
+
</Button>
|
|
29
|
+
|
|
30
|
+
<Banner
|
|
31
|
+
in={open}
|
|
32
|
+
border="top"
|
|
33
|
+
mountOnEnter={true}
|
|
34
|
+
unmountOnExit={true}
|
|
35
|
+
>
|
|
36
|
+
<Inline
|
|
37
|
+
verticalAlign="center"
|
|
38
|
+
horizontalAlign="center"
|
|
39
|
+
space="small"
|
|
40
|
+
>
|
|
41
|
+
<Inline
|
|
42
|
+
space="xxsmall"
|
|
43
|
+
verticalAlign="center"
|
|
44
|
+
horizontalAlign="center"
|
|
45
|
+
>
|
|
46
|
+
<TextBox color="inherit">
|
|
47
|
+
Rate your recent experience with{' '}
|
|
48
|
+
</TextBox>
|
|
49
|
+
<Link
|
|
50
|
+
color="inherit"
|
|
51
|
+
target="_blank"
|
|
52
|
+
rel="noreferrer"
|
|
53
|
+
href="https://superdispatch.com/"
|
|
54
|
+
>
|
|
55
|
+
SuperDispatch
|
|
56
|
+
</Link>
|
|
57
|
+
</Inline>
|
|
58
|
+
</Inline>
|
|
59
|
+
</Banner>
|
|
60
|
+
</Stack>
|
|
61
|
+
)}
|
|
62
|
+
</UseState>
|
|
63
|
+
</Stack>
|
|
64
|
+
);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Color } from '@superdispatch/ui';
|
|
2
|
+
import { forwardRef, useEffect, useState } from 'react';
|
|
3
|
+
import { CSSTransition } from 'react-transition-group';
|
|
4
|
+
// eslint-disable-next-line import/no-internal-modules
|
|
5
|
+
import { CSSTransitionProps } from 'react-transition-group/CSSTransition';
|
|
6
|
+
import styled, {
|
|
7
|
+
css,
|
|
8
|
+
Keyframes,
|
|
9
|
+
keyframes,
|
|
10
|
+
SimpleInterpolation,
|
|
11
|
+
} from 'styled-components';
|
|
12
|
+
|
|
13
|
+
function enterMixin(border: BorderPlacement): readonly SimpleInterpolation[] {
|
|
14
|
+
return css`
|
|
15
|
+
min-height: 56px;
|
|
16
|
+
color: ${Color.Dark500};
|
|
17
|
+
background-color: ${Color.White};
|
|
18
|
+
|
|
19
|
+
border-${border}: 1px #dfe3e8 solid;
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function enterAnimation(border: BorderPlacement): Keyframes {
|
|
24
|
+
return keyframes`
|
|
25
|
+
0% {
|
|
26
|
+
min-height: 0;
|
|
27
|
+
color: ${Color.White};
|
|
28
|
+
background-color: ${Color.Dark500};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
50% {
|
|
32
|
+
min-height: 56px;
|
|
33
|
+
color: ${Color.White};
|
|
34
|
+
background-color: ${Color.Dark500};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
70% {
|
|
38
|
+
min-height: 56px;
|
|
39
|
+
color: ${Color.White};
|
|
40
|
+
background-color: ${Color.Dark500};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
100% {
|
|
44
|
+
${enterMixin(border)}
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type BorderPlacement = 'top' | 'bottom';
|
|
50
|
+
|
|
51
|
+
type CustomerTransitionProps = CSSTransitionProps<HTMLDivElement> & {
|
|
52
|
+
className?: string;
|
|
53
|
+
border?: BorderPlacement;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const CustomTransition = forwardRef<
|
|
57
|
+
CSSTransition<HTMLDivElement>,
|
|
58
|
+
CustomerTransitionProps
|
|
59
|
+
>(({ children, ...props }, ref) => (
|
|
60
|
+
<CSSTransition
|
|
61
|
+
{...props}
|
|
62
|
+
ref={ref}
|
|
63
|
+
timeout={3000}
|
|
64
|
+
classNames={props.className}
|
|
65
|
+
>
|
|
66
|
+
<div>{children}</div>
|
|
67
|
+
</CSSTransition>
|
|
68
|
+
));
|
|
69
|
+
|
|
70
|
+
const BannerContent = styled(CustomTransition)<CustomerTransitionProps>(
|
|
71
|
+
({ border = 'bottom' }) => {
|
|
72
|
+
return css`
|
|
73
|
+
height: 0;
|
|
74
|
+
width: 100%;
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
|
|
77
|
+
display: flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
|
|
81
|
+
color: ${Color.White};
|
|
82
|
+
background-color: ${Color.White};
|
|
83
|
+
|
|
84
|
+
&-enter-active {
|
|
85
|
+
animation: ${enterAnimation(border)} 2s 1s forwards;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&-enter-done {
|
|
89
|
+
${enterMixin(border)};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&-exit {
|
|
93
|
+
${enterMixin(border)};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
&-exit-active {
|
|
97
|
+
min-height: 0;
|
|
98
|
+
transition: min-height 2s 1s;
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
type BannerProps = Omit<
|
|
105
|
+
CustomerTransitionProps,
|
|
106
|
+
'timeout' | 'className' | 'classNames'
|
|
107
|
+
>;
|
|
108
|
+
|
|
109
|
+
export const Banner = forwardRef<CSSTransition<HTMLDivElement>, BannerProps>(
|
|
110
|
+
({ in: inProp, ...props }, ref) => {
|
|
111
|
+
const [isIn, setIn] = useState(false);
|
|
112
|
+
|
|
113
|
+
// transition is not triggered on initial render with `in: true`
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
setIn(!!inProp);
|
|
116
|
+
}, [inProp]);
|
|
117
|
+
|
|
118
|
+
return <BannerContent ref={ref} in={isIn} {...props} />;
|
|
119
|
+
},
|
|
120
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { Box } from './Box';
|
|
3
|
+
|
|
4
|
+
export default { title: 'Lab/Box', component: Box } as Meta;
|
|
5
|
+
|
|
6
|
+
export const basic = () => (
|
|
7
|
+
<Box
|
|
8
|
+
display="inline-block"
|
|
9
|
+
borderWidth="small"
|
|
10
|
+
borderTopRightRadius="small"
|
|
11
|
+
borderBottomRightRadius="small"
|
|
12
|
+
borderColor={['Blue200', 'Green200', 'Purple200']}
|
|
13
|
+
borderLeftWidth="large"
|
|
14
|
+
borderLeftColor={['Blue300', 'Green300', 'Purple300']}
|
|
15
|
+
padding={['large', 'medium', 'small']}
|
|
16
|
+
backgroundColor={['Blue50', 'Green50', 'Purple50']}
|
|
17
|
+
>
|
|
18
|
+
Hey
|
|
19
|
+
</Box>
|
|
20
|
+
);
|
package/src/box/Box.tsx
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Color,
|
|
3
|
+
ColorProp,
|
|
4
|
+
isColorProp,
|
|
5
|
+
NegativeSpaceProp,
|
|
6
|
+
parseResponsiveProp,
|
|
7
|
+
parseSpaceProp,
|
|
8
|
+
ResponsiveProp,
|
|
9
|
+
SpaceProp,
|
|
10
|
+
} from '@superdispatch/ui';
|
|
11
|
+
import { Property } from 'csstype';
|
|
12
|
+
import { ForwardRefExoticComponent, ReactNode, Ref } from 'react';
|
|
13
|
+
import styled, { CSSObject } from 'styled-components';
|
|
14
|
+
import { createRuleNormalizer, RuleNormalizer } from '../utils/RuleNormalizer';
|
|
15
|
+
|
|
16
|
+
//
|
|
17
|
+
// Colors
|
|
18
|
+
//
|
|
19
|
+
|
|
20
|
+
function normalizeColor(input: unknown): string | undefined {
|
|
21
|
+
return isColorProp(input) ? Color[input] : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//
|
|
25
|
+
// Space
|
|
26
|
+
//
|
|
27
|
+
|
|
28
|
+
function parseSpace(space: unknown): string {
|
|
29
|
+
return `${parseSpaceProp(space as SpaceProp)}px`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//
|
|
33
|
+
// Margins
|
|
34
|
+
//
|
|
35
|
+
|
|
36
|
+
export type MarginProp = 'auto' | SpaceProp | NegativeSpaceProp;
|
|
37
|
+
function parseMargin(input: unknown): string {
|
|
38
|
+
if (input === 'auto') return input;
|
|
39
|
+
|
|
40
|
+
let prefix = '';
|
|
41
|
+
|
|
42
|
+
if (typeof input == 'string' && input.startsWith('-')) {
|
|
43
|
+
prefix = '-';
|
|
44
|
+
input = input.slice(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return prefix + parseSpace(input);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//
|
|
51
|
+
// Borders
|
|
52
|
+
//
|
|
53
|
+
|
|
54
|
+
export type BorderRadiusProp = 'none' | 'small' | 'medium';
|
|
55
|
+
const normalizeBorderRadius = createRuleNormalizer<BorderRadiusProp>({
|
|
56
|
+
none: 0,
|
|
57
|
+
small: 4,
|
|
58
|
+
medium: 8,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export type BorderWidthProp = 'none' | 'small' | 'medium' | 'large';
|
|
62
|
+
const normalizeBorderWidth = createRuleNormalizer<BorderWidthProp>({
|
|
63
|
+
none: 0,
|
|
64
|
+
small: 1,
|
|
65
|
+
medium: 2,
|
|
66
|
+
large: 4,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
//
|
|
70
|
+
// Rules
|
|
71
|
+
//
|
|
72
|
+
|
|
73
|
+
interface BoxRules {
|
|
74
|
+
display?: ResponsiveProp<Property.Display>;
|
|
75
|
+
|
|
76
|
+
color?: ResponsiveProp<ColorProp>;
|
|
77
|
+
backgroundColor?: ResponsiveProp<ColorProp>;
|
|
78
|
+
|
|
79
|
+
borderColor?: ResponsiveProp<ColorProp>;
|
|
80
|
+
borderTopColor?: ResponsiveProp<ColorProp>;
|
|
81
|
+
borderLeftColor?: ResponsiveProp<ColorProp>;
|
|
82
|
+
borderRightColor?: ResponsiveProp<ColorProp>;
|
|
83
|
+
borderBottomColor?: ResponsiveProp<ColorProp>;
|
|
84
|
+
|
|
85
|
+
borderWidth?: ResponsiveProp<BorderWidthProp>;
|
|
86
|
+
borderTopWidth?: ResponsiveProp<BorderWidthProp>;
|
|
87
|
+
borderLeftWidth?: ResponsiveProp<BorderWidthProp>;
|
|
88
|
+
borderRightWidth?: ResponsiveProp<BorderWidthProp>;
|
|
89
|
+
borderBottomWidth?: ResponsiveProp<BorderWidthProp>;
|
|
90
|
+
|
|
91
|
+
padding?: ResponsiveProp<SpaceProp>;
|
|
92
|
+
paddingTop?: ResponsiveProp<SpaceProp>;
|
|
93
|
+
paddingLeft?: ResponsiveProp<SpaceProp>;
|
|
94
|
+
paddingRight?: ResponsiveProp<SpaceProp>;
|
|
95
|
+
paddingBottom?: ResponsiveProp<SpaceProp>;
|
|
96
|
+
|
|
97
|
+
margin?: ResponsiveProp<MarginProp>;
|
|
98
|
+
marginTop?: ResponsiveProp<MarginProp>;
|
|
99
|
+
marginLeft?: ResponsiveProp<MarginProp>;
|
|
100
|
+
marginRight?: ResponsiveProp<MarginProp>;
|
|
101
|
+
marginBottom?: ResponsiveProp<MarginProp>;
|
|
102
|
+
|
|
103
|
+
borderRadius?: ResponsiveProp<BorderRadiusProp>;
|
|
104
|
+
borderTopLeftRadius?: ResponsiveProp<BorderRadiusProp>;
|
|
105
|
+
borderTopRightRadius?: ResponsiveProp<BorderRadiusProp>;
|
|
106
|
+
borderBottomLeftRadius?: ResponsiveProp<BorderRadiusProp>;
|
|
107
|
+
borderBottomRightRadius?: ResponsiveProp<BorderRadiusProp>;
|
|
108
|
+
|
|
109
|
+
fontSize?: ResponsiveProp<Property.FontSize>;
|
|
110
|
+
|
|
111
|
+
width?: ResponsiveProp<Property.Width>;
|
|
112
|
+
maxWidth?: ResponsiveProp<Property.MaxWidth>;
|
|
113
|
+
minWidth?: ResponsiveProp<Property.MinWidth>;
|
|
114
|
+
|
|
115
|
+
height?: ResponsiveProp<Property.Height>;
|
|
116
|
+
maxHeight?: ResponsiveProp<Property.MaxHeight>;
|
|
117
|
+
minHeight?: ResponsiveProp<Property.MinHeight>;
|
|
118
|
+
|
|
119
|
+
overflow?: ResponsiveProp<Property.Overflow>;
|
|
120
|
+
overflowY?: ResponsiveProp<Property.OverflowY>;
|
|
121
|
+
overflowX?: ResponsiveProp<Property.OverflowX>;
|
|
122
|
+
|
|
123
|
+
top?: ResponsiveProp<Property.Top>;
|
|
124
|
+
left?: ResponsiveProp<Property.Left>;
|
|
125
|
+
right?: ResponsiveProp<Property.Right>;
|
|
126
|
+
bottom?: ResponsiveProp<Property.Bottom>;
|
|
127
|
+
position?: ResponsiveProp<Property.Position>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const normalizers: Record<keyof BoxRules, undefined | RuleNormalizer> = {
|
|
131
|
+
display: undefined,
|
|
132
|
+
|
|
133
|
+
color: normalizeColor,
|
|
134
|
+
backgroundColor: normalizeColor,
|
|
135
|
+
|
|
136
|
+
borderColor: normalizeColor,
|
|
137
|
+
borderTopColor: normalizeColor,
|
|
138
|
+
borderLeftColor: normalizeColor,
|
|
139
|
+
borderRightColor: normalizeColor,
|
|
140
|
+
borderBottomColor: normalizeColor,
|
|
141
|
+
|
|
142
|
+
borderWidth: normalizeBorderWidth,
|
|
143
|
+
borderTopWidth: normalizeBorderWidth,
|
|
144
|
+
borderLeftWidth: normalizeBorderWidth,
|
|
145
|
+
borderRightWidth: normalizeBorderWidth,
|
|
146
|
+
borderBottomWidth: normalizeBorderWidth,
|
|
147
|
+
|
|
148
|
+
margin: parseMargin,
|
|
149
|
+
marginTop: parseMargin,
|
|
150
|
+
marginLeft: parseMargin,
|
|
151
|
+
marginRight: parseMargin,
|
|
152
|
+
marginBottom: parseMargin,
|
|
153
|
+
|
|
154
|
+
padding: parseSpace,
|
|
155
|
+
paddingTop: parseSpace,
|
|
156
|
+
paddingLeft: parseSpace,
|
|
157
|
+
paddingRight: parseSpace,
|
|
158
|
+
paddingBottom: parseSpace,
|
|
159
|
+
|
|
160
|
+
borderRadius: normalizeBorderRadius,
|
|
161
|
+
borderTopLeftRadius: normalizeBorderRadius,
|
|
162
|
+
borderTopRightRadius: normalizeBorderRadius,
|
|
163
|
+
borderBottomLeftRadius: normalizeBorderRadius,
|
|
164
|
+
borderBottomRightRadius: normalizeBorderRadius,
|
|
165
|
+
|
|
166
|
+
fontSize: undefined,
|
|
167
|
+
|
|
168
|
+
width: undefined,
|
|
169
|
+
maxWidth: undefined,
|
|
170
|
+
minWidth: undefined,
|
|
171
|
+
|
|
172
|
+
height: undefined,
|
|
173
|
+
maxHeight: undefined,
|
|
174
|
+
minHeight: undefined,
|
|
175
|
+
|
|
176
|
+
overflow: undefined,
|
|
177
|
+
overflowY: undefined,
|
|
178
|
+
overflowX: undefined,
|
|
179
|
+
|
|
180
|
+
top: undefined,
|
|
181
|
+
left: undefined,
|
|
182
|
+
right: undefined,
|
|
183
|
+
bottom: undefined,
|
|
184
|
+
position: undefined,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
function injectRule(
|
|
188
|
+
styles: CSSObject,
|
|
189
|
+
key: string,
|
|
190
|
+
breakpoint: string,
|
|
191
|
+
value: unknown,
|
|
192
|
+
normalizer: undefined | RuleNormalizer,
|
|
193
|
+
): void {
|
|
194
|
+
if (normalizer != null) value = normalizer(value);
|
|
195
|
+
|
|
196
|
+
if (value != null) {
|
|
197
|
+
let rules = styles[breakpoint];
|
|
198
|
+
|
|
199
|
+
if (typeof rules != 'object') {
|
|
200
|
+
rules = {};
|
|
201
|
+
styles[breakpoint] = rules;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
rules[key] = String(value);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
//
|
|
209
|
+
// Box
|
|
210
|
+
//
|
|
211
|
+
|
|
212
|
+
export interface BoxProps extends BoxRules {
|
|
213
|
+
ref?: Ref<unknown>;
|
|
214
|
+
as?: keyof JSX.IntrinsicElements;
|
|
215
|
+
|
|
216
|
+
role?: string;
|
|
217
|
+
children?: ReactNode;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export const Box: ForwardRefExoticComponent<BoxProps> = styled.div<BoxProps>(
|
|
221
|
+
(props) => {
|
|
222
|
+
const { breakpoints } = props.theme;
|
|
223
|
+
const xs = breakpoints.up('xs');
|
|
224
|
+
const sm = breakpoints.up('sm');
|
|
225
|
+
const md = breakpoints.up('md');
|
|
226
|
+
|
|
227
|
+
const styles: CSSObject = {
|
|
228
|
+
margin: 0,
|
|
229
|
+
padding: 0,
|
|
230
|
+
borderWidth: 0,
|
|
231
|
+
borderStyle: 'solid',
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
for (const k in props) {
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(props, k) && k in normalizers) {
|
|
236
|
+
const key = k as keyof BoxRules;
|
|
237
|
+
const prop = props[key];
|
|
238
|
+
|
|
239
|
+
if (prop != null) {
|
|
240
|
+
const [mobile, tablet, desktop] = parseResponsiveProp(prop);
|
|
241
|
+
|
|
242
|
+
const normalizer = normalizers[key];
|
|
243
|
+
injectRule(styles, key, xs, mobile, normalizer);
|
|
244
|
+
injectRule(styles, key, sm, tablet, normalizer);
|
|
245
|
+
injectRule(styles, key, md, desktop, normalizer);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return styles;
|
|
251
|
+
},
|
|
252
|
+
);
|