Skip to content

Commit b51327e

Browse files
authored
feat(versioning): Add V2 UI; make backend more synchronous; add to component library (#12542)
1 parent e1ce780 commit b51327e

File tree

90 files changed

+3899
-725
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3899
-725
lines changed

datahub-web-react/src/alchemy-components/components/Badge/Badge.stories.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ export const sizes = () => (
8585
export const colors = () => (
8686
<GridList>
8787
<Badge count={100} />
88-
<Badge count={100} colorScheme="violet" />
89-
<Badge count={100} colorScheme="green" />
90-
<Badge count={100} colorScheme="red" />
91-
<Badge count={100} colorScheme="blue" />
92-
<Badge count={100} colorScheme="gray" />
88+
<Badge count={100} color="violet" />
89+
<Badge count={100} color="green" />
90+
<Badge count={100} color="red" />
91+
<Badge count={100} color="blue" />
92+
<Badge count={100} color="gray" />
9393
</GridList>
9494
);
9595

datahub-web-react/src/alchemy-components/components/Badge/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HTMLAttributes } from 'react';
22
import { PillProps } from '../Pills/types';
33

4-
export interface BadgeProps extends HTMLAttributes<HTMLElement>, Omit<PillProps, 'label'> {
4+
export interface BadgeProps extends Omit<PillProps, 'label'>, Omit<HTMLAttributes<HTMLElement>, 'color'> {
55
count: number;
66
overflowCount?: number;
77
showZero?: boolean;

datahub-web-react/src/alchemy-components/components/Badge/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const formatBadgeValue = (value: number, overflowCount?: number): string
44
return `${overflowCount}+`;
55
};
66

7-
export function omitKeys<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {
7+
export function omitKeys<T extends object, K extends keyof T>(obj: T | undefined, keys: K[]): Omit<T, K> {
88
const { ...rest } = obj;
99

1010
keys.forEach((key) => {

datahub-web-react/src/alchemy-components/components/Button/Button.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { LoadingOutlined } from '@ant-design/icons';
55
import { Icon } from '@components';
66

77
import { ButtonBase } from './components';
8-
import { ButtonProps } from './types';
8+
import { ButtonProps, ButtonPropsDefaults } from './types';
99

10-
export const buttonDefaults: ButtonProps = {
10+
export const buttonDefaults: ButtonPropsDefaults = {
1111
variant: 'filled',
1212
color: 'violet',
1313
size: 'md',
@@ -32,27 +32,26 @@ export const Button = ({
3232
children,
3333
...props
3434
}: ButtonProps) => {
35-
const sharedProps = {
35+
const styleProps = {
3636
variant,
3737
color,
3838
size,
3939
isCircle,
4040
isLoading,
4141
isActive,
4242
isDisabled,
43-
disabled: isDisabled,
4443
};
4544

4645
if (isLoading) {
4746
return (
48-
<ButtonBase {...sharedProps} {...props}>
47+
<ButtonBase {...styleProps} {...props}>
4948
<LoadingOutlined rotate={10} /> {!isCircle && children}
5049
</ButtonBase>
5150
);
5251
}
5352

5453
return (
55-
<ButtonBase {...sharedProps} {...props}>
54+
<ButtonBase {...styleProps} {...props}>
5655
{icon && iconPosition === 'left' && <Icon icon={icon} size={iconSize || size} />}
5756
{!isCircle && children}
5857
{icon && iconPosition === 'right' && <Icon icon={icon} size={iconSize || size} />}

datahub-web-react/src/alchemy-components/components/Button/components.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import styled from 'styled-components';
22

33
import { spacing } from '@components/theme';
4-
import { ButtonProps } from './types';
4+
import { ButtonStyleProps } from './types';
55
import { getButtonStyle } from './utils';
66

77
export const ButtonBase = styled.button(
88
// Dynamic styles
9-
(props: ButtonProps) => ({ ...getButtonStyle(props as ButtonProps) }),
9+
(props: ButtonStyleProps) => ({ ...getButtonStyle(props) }),
1010
{
1111
// Base root styles
1212
display: 'flex',

datahub-web-react/src/alchemy-components/components/Button/types.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ import { ButtonHTMLAttributes } from 'react';
33
import type { IconNames } from '@components';
44
import type { SizeOptions, ColorOptions, FontSizeOptions } from '@components/theme/config';
55

6-
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
7-
variant?: 'filled' | 'outline' | 'text';
8-
color?: ColorOptions;
9-
size?: SizeOptions;
6+
export type ButtonVariant = 'filled' | 'outline' | 'text';
7+
8+
export interface ButtonPropsDefaults {
9+
variant: ButtonVariant;
10+
color: ColorOptions;
11+
size: SizeOptions;
12+
iconPosition: 'left' | 'right';
13+
isCircle: boolean;
14+
isLoading: boolean;
15+
isDisabled: boolean;
16+
isActive: boolean;
17+
}
18+
19+
export interface ButtonProps
20+
extends Partial<ButtonPropsDefaults>,
21+
Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'color'> {
1022
icon?: IconNames;
11-
iconPosition?: 'left' | 'right';
1223
iconSize?: FontSizeOptions;
13-
isCircle?: boolean;
14-
isLoading?: boolean;
15-
isDisabled?: boolean;
16-
isActive?: boolean;
1724
}
25+
26+
export type ButtonStyleProps = Omit<ButtonPropsDefaults, 'iconPosition'>;

datahub-web-react/src/alchemy-components/components/Button/utils.ts

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@
33
*/
44

55
import { typography, colors, shadows, radius, spacing } from '@components/theme';
6+
import { ColorOptions, SizeOptions } from '@components/theme/config';
67
import { getColor, getFontSize } from '@components/theme/utils';
7-
import { ButtonProps } from './types';
8+
import { CSSObject } from 'styled-components';
9+
import { ButtonStyleProps, ButtonVariant } from './types';
10+
11+
interface ColorStyles {
12+
bgColor: string;
13+
hoverBgColor: string;
14+
activeBgColor: string;
15+
disabledBgColor: string;
16+
borderColor: string;
17+
activeBorderColor: string;
18+
disabledBorderColor: string;
19+
textColor: string;
20+
disabledTextColor: string;
21+
}
822

923
// Utility function to get color styles for button - does not generate CSS
10-
const getButtonColorStyles = (variant, color) => {
24+
const getButtonColorStyles = (variant: ButtonVariant, color: ColorOptions): ColorStyles => {
1125
const color500 = getColor(color, 500); // value of 500 shade
1226
const isViolet = color === 'violet';
1327

@@ -79,49 +93,49 @@ const getButtonColorStyles = (variant, color) => {
7993
};
8094

8195
// Generate color styles for button
82-
const getButtonVariantStyles = (variant, color) => {
96+
const getButtonVariantStyles = (variant: ButtonVariant, colorStyles: ColorStyles): CSSObject => {
8397
const variantStyles = {
8498
filled: {
85-
backgroundColor: color.bgColor,
86-
border: `1px solid ${color.borderColor}`,
87-
color: color.textColor,
99+
backgroundColor: colorStyles.bgColor,
100+
border: `1px solid ${colorStyles.borderColor}`,
101+
color: colorStyles.textColor,
88102
'&:hover': {
89-
backgroundColor: color.hoverBgColor,
90-
border: `1px solid ${color.hoverBgColor}`,
103+
backgroundColor: colorStyles.hoverBgColor,
104+
border: `1px solid ${colorStyles.hoverBgColor}`,
91105
boxShadow: shadows.sm,
92106
},
93107
'&:disabled': {
94-
backgroundColor: color.disabledBgColor,
95-
border: `1px solid ${color.disabledBorderColor}`,
96-
color: color.disabledTextColor,
108+
backgroundColor: colorStyles.disabledBgColor,
109+
border: `1px solid ${colorStyles.disabledBorderColor}`,
110+
color: colorStyles.disabledTextColor,
97111
boxShadow: shadows.xs,
98112
},
99113
},
100114
outline: {
101115
backgroundColor: 'transparent',
102-
border: `1px solid ${color.borderColor}`,
103-
color: color.textColor,
116+
border: `1px solid ${colorStyles.borderColor}`,
117+
color: colorStyles.textColor,
104118
'&:hover': {
105-
backgroundColor: color.hoverBgColor,
119+
backgroundColor: colorStyles.hoverBgColor,
106120
boxShadow: 'none',
107121
},
108122
'&:disabled': {
109-
backgroundColor: color.disabledBgColor,
110-
border: `1px solid ${color.disabledBorderColor}`,
111-
color: color.disabledTextColor,
123+
backgroundColor: colorStyles.disabledBgColor,
124+
border: `1px solid ${colorStyles.disabledBorderColor}`,
125+
color: colorStyles.disabledTextColor,
112126
boxShadow: shadows.xs,
113127
},
114128
},
115129
text: {
116130
backgroundColor: 'transparent',
117131
border: 'none',
118-
color: color.textColor,
132+
color: colorStyles.textColor,
119133
'&:hover': {
120-
backgroundColor: color.hoverBgColor,
134+
backgroundColor: colorStyles.hoverBgColor,
121135
},
122136
'&:disabled': {
123-
backgroundColor: color.disabledBgColor,
124-
color: color.disabledTextColor,
137+
backgroundColor: colorStyles.disabledBgColor,
138+
color: colorStyles.disabledTextColor,
125139
},
126140
},
127141
};
@@ -130,7 +144,7 @@ const getButtonVariantStyles = (variant, color) => {
130144
};
131145

132146
// Generate font styles for button
133-
const getButtonFontStyles = (size) => {
147+
const getButtonFontStyles = (size: SizeOptions) => {
134148
const baseFontStyles = {
135149
fontFamily: typography.fonts.body,
136150
fontWeight: typography.fontWeights.normal,
@@ -160,39 +174,46 @@ const getButtonFontStyles = (size) => {
160174
};
161175

162176
// Generate radii styles for button
163-
const getButtonRadiiStyles = (isCircle) => {
177+
const getButtonRadiiStyles = (isCircle: boolean) => {
164178
if (isCircle) return { borderRadius: radius.full };
165179
return { borderRadius: radius.sm }; // radius is the same for all button sizes
166180
};
167181

168182
// Generate padding styles for button
169-
const getButtonPadding = (size, isCircle) => {
183+
const getButtonPadding = (size: SizeOptions, variant: ButtonVariant, isCircle: boolean) => {
170184
if (isCircle) return { padding: spacing.xsm };
171185

172186
const paddingStyles = {
173187
sm: {
174-
padding: '8px 12px',
188+
vertical: 8,
189+
horizontal: 12,
175190
},
176191
md: {
177-
padding: '10px 12px',
192+
vertical: 10,
193+
horizontal: 12,
178194
},
179195
lg: {
180-
padding: '10px 16px',
196+
vertical: 10,
197+
horizontal: 16,
181198
},
182199
xl: {
183-
padding: '12px 20px',
200+
vertical: 12,
201+
horizontal: 20,
184202
},
185203
};
186204

187-
return paddingStyles[size];
205+
const selectedStyle = paddingStyles[size];
206+
const verticalPadding = selectedStyle.vertical;
207+
const horizontalPadding = variant === 'text' ? 0 : selectedStyle.horizontal;
208+
return { padding: `${verticalPadding}px ${horizontalPadding}px` };
188209
};
189210

190211
// Generate active styles for button
191-
const getButtonActiveStyles = (styleColors) => ({
212+
const getButtonActiveStyles = (colorStyles: ColorStyles) => ({
192213
borderColor: 'transparent',
193-
backgroundColor: styleColors.activeBgColor,
214+
backgroundColor: colorStyles.activeBgColor,
194215
// TODO: Figure out how to make the #fff interior border transparent
195-
boxShadow: `0 0 0 2px #fff, 0 0 0 4px ${styleColors.activeBgColor}`,
216+
boxShadow: `0 0 0 2px #fff, 0 0 0 4px ${colorStyles.activeBgColor}`,
196217
});
197218

198219
// Generate loading styles for button
@@ -204,17 +225,17 @@ const getButtonLoadingStyles = () => ({
204225
/*
205226
* Main function to generate styles for button
206227
*/
207-
export const getButtonStyle = (props: ButtonProps) => {
208-
const { variant, color, size, isCircle, isActive, isLoading } = props;
228+
export const getButtonStyle = (props: ButtonStyleProps) => {
229+
const { variant, color, size, isCircle, isActive, isLoading, isDisabled } = props;
209230

210231
// Get map of colors
211-
const colorStyles = getButtonColorStyles(variant, color) || ({} as any);
232+
const colorStyles = getButtonColorStyles(variant, color);
212233

213234
// Define styles for button
214235
const variantStyles = getButtonVariantStyles(variant, colorStyles);
215236
const fontStyles = getButtonFontStyles(size);
216237
const radiiStyles = getButtonRadiiStyles(isCircle);
217-
const paddingStyles = getButtonPadding(size, isCircle);
238+
const paddingStyles = getButtonPadding(size, variant, isCircle);
218239

219240
// Base of all generated styles
220241
let styles = {
@@ -226,9 +247,11 @@ export const getButtonStyle = (props: ButtonProps) => {
226247

227248
// Focus & Active styles are the same, but active styles are applied conditionally & override prevs styles
228249
const activeStyles = { ...getButtonActiveStyles(colorStyles) };
229-
styles['&:focus'] = activeStyles;
230-
styles['&:active'] = activeStyles;
231-
if (isActive) styles = { ...styles, ...activeStyles };
250+
if (!isDisabled && isActive) {
251+
styles['&:focus'] = activeStyles;
252+
styles['&:active'] = activeStyles;
253+
styles = { ...styles, ...activeStyles };
254+
}
232255

233256
// Loading styles
234257
if (isLoading) styles = { ...styles, ...getButtonLoadingStyles() };

datahub-web-react/src/alchemy-components/components/Card/Card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const Card = ({
4343
<Pill
4444
label={`${Math.abs(percent)}%`}
4545
size="sm"
46-
colorScheme={percent < 0 ? 'red' : 'green'}
46+
color={percent < 0 ? 'red' : 'green'}
4747
leftIcon={percent < 0 ? 'TrendingDown' : 'TrendingUp'}
4848
clickable={false}
4949
/>

datahub-web-react/src/alchemy-components/components/Heading/Heading.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22

3-
import { HeadingProps } from './types';
3+
import { HeadingProps, HeadingPropsDefaults } from './types';
44
import { H1, H2, H3, H4, H5, H6 } from './components';
55

6-
export const headingDefaults: HeadingProps = {
6+
export const headingDefaults: HeadingPropsDefaults = {
77
type: 'h1',
88
color: 'inherit',
99
size: '2xl',
@@ -15,9 +15,10 @@ export const Heading = ({
1515
size = headingDefaults.size,
1616
color = headingDefaults.color,
1717
weight = headingDefaults.weight,
18+
colorLevel,
1819
children,
1920
}: HeadingProps) => {
20-
const sharedProps = { size, color, weight };
21+
const sharedProps = { size, color, colorLevel, weight };
2122

2223
switch (type) {
2324
case 'h1':

datahub-web-react/src/alchemy-components/components/Heading/components.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import styled from 'styled-components';
22

33
import { typography, colors } from '@components/theme';
44
import { getColor, getFontSize } from '@components/theme/utils';
5-
import { HeadingProps } from './types';
5+
import { HeadingStyleProps } from './types';
66

77
const headingStyles = {
88
H1: {
@@ -48,10 +48,10 @@ const baseStyles = {
4848
};
4949

5050
// Prop Driven Styles
51-
const propStyles = (props, isText = false) => {
51+
const propStyles = (props: HeadingStyleProps, isText = false) => {
5252
const styles = {} as any;
5353
if (props.size) styles.fontSize = getFontSize(props.size);
54-
if (props.color) styles.color = getColor(props.color);
54+
if (props.color) styles.color = getColor(props.color, props.colorLevel);
5555
if (props.weight) styles.fontWeight = typography.fontWeights[props.weight];
5656
if (isText) styles.lineHeight = typography.lineHeights[props.size];
5757
return styles;
@@ -62,8 +62,8 @@ const headings = {} as any;
6262

6363
['H1', 'H2', 'H3', 'H4', 'H5', 'H6'].forEach((heading) => {
6464
const component = styled[heading.toLowerCase()];
65-
headings[heading] = component({ ...baseStyles, ...headingStyles[heading] }, (props: HeadingProps) => ({
66-
...propStyles(props as HeadingProps),
65+
headings[heading] = component({ ...baseStyles, ...headingStyles[heading] }, (props: HeadingStyleProps) => ({
66+
...propStyles(props),
6767
}));
6868
});
6969

0 commit comments

Comments
 (0)