Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ui/v2): Update icons and search bars on schema tab, glossary search, domain search #12740

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ButtonVariantValues } from '@components/components/Button/types';
import { MATERIAL_UI_ICONS, PHOSPHOR_ICONS } from '@components/components/Icon/constants';
import { SizeValues } from '@components/theme/config';
import React from 'react';

import type { Meta, StoryObj } from '@storybook/react';
Expand Down Expand Up @@ -33,7 +36,7 @@ const meta = {
},
variant: {
description: 'The variant of the Button.',
options: ['filled', 'outline', 'text'],
options: Object.values(ButtonVariantValues),
table: {
defaultValue: { summary: buttonDefaults.variant },
},
Expand All @@ -43,7 +46,7 @@ const meta = {
},
color: {
description: 'The color of the Button.',
options: ['violet', 'green', 'red', 'blue', 'gray'],
options: ['violet', 'green', 'red', 'gray'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request from Anna (no blue buttons)

table: {
defaultValue: { summary: buttonDefaults.color },
},
Expand All @@ -53,31 +56,22 @@ const meta = {
},
size: {
description: 'The size of the Button.',
options: ['sm', 'md', 'lg', 'xl'],
options: Object.values(SizeValues),
table: {
defaultValue: { summary: buttonDefaults.size },
},
control: {
type: 'select',
},
},
iconSize: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attached to icon now. Unfortunately, storybook doesn't have great support for nested fields: storybookjs/storybook#12078

description: 'The optional size of the Icon.',
options: ['xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl'],
table: {
defaultValue: {
summary: 'undefined',
detail: 'The size of the Button will be used as the size of the Icon',
},
},
control: {
type: 'select',
},
},
icon: {
description: 'The icon to display in the Button.',
type: 'string',
options: AVAILABLE_ICONS,
mapping: Object.fromEntries([
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maps options to props for Button component

...MATERIAL_UI_ICONS.map((icon) => [icon, { icon, source: 'material', size: '2xl' }]),
...PHOSPHOR_ICONS.map((icon) => [icon, { icon, source: 'phosphor', size: '2xl' }]),
]),
table: {
defaultValue: { summary: 'undefined' },
},
Expand Down Expand Up @@ -143,7 +137,7 @@ const meta = {

// Define defaults
args: {
children: 'Button Content',
children: 'Button',
variant: buttonDefaults.variant,
color: buttonDefaults.color,
size: buttonDefaults.size,
Expand All @@ -167,7 +161,7 @@ type Story = StoryObj<typeof meta>;
// Pass props to this so that it can be customized via the UI props panel
export const sandbox: Story = {
tags: ['dev'],
render: (props) => <Button {...props}>Button</Button>,
render: (props) => <Button {...props} />,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properly set children

};

export const states = () => (
Expand All @@ -191,26 +185,27 @@ export const colors = () => (

export const sizes = () => (
<GridList>
<Button size="sm">Small Button</Button>
<Button size="md">Regular Button</Button>
<Button size="lg">Large Button</Button>
<Button size="xl">XLarge Button</Button>
<Button size="xs">XSmall</Button>
<Button size="sm">Small</Button>
<Button size="md">Regular</Button>
<Button size="lg">Large</Button>
<Button size="xl">XLarge</Button>
</GridList>
);

export const withIcon = () => (
<GridList>
<Button icon="Add">Icon Left</Button>
<Button icon="Add" iconPosition="right">
<Button icon={{ icon: 'Add', source: 'material' }}>Icon Left</Button>
<Button icon={{ icon: 'Add', source: 'material' }} iconPosition="right">
Icon Right
</Button>
</GridList>
);

export const circleShape = () => (
<GridList>
<Button icon="Add" size="sm" isCircle />
<Button icon="Add" isCircle />
<Button icon="Add" size="lg" isCircle />
<Button icon={{ icon: 'Add', source: 'material' }} size="sm" isCircle />
<Button icon={{ icon: 'Add', source: 'material' }} isCircle />
<Button icon={{ icon: 'Add', source: 'material' }} size="lg" isCircle />
</GridList>
);
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const Button = ({
size = buttonDefaults.size,
icon, // default undefined
iconPosition = buttonDefaults.iconPosition,
iconSize,
isCircle = buttonDefaults.isCircle,
isLoading = buttonDefaults.isLoading,
isDisabled = buttonDefaults.isDisabled,
Expand All @@ -40,6 +39,7 @@ export const Button = ({
isLoading,
isActive,
isDisabled,
hasChildren: !!children,
};

if (isLoading) {
Expand All @@ -50,11 +50,12 @@ export const Button = ({
);
}

// Prefer `icon.size` over `size` for icon size
return (
<ButtonBase {...styleProps} {...props}>
{icon && iconPosition === 'left' && <Icon icon={icon} size={iconSize || size} />}
{icon && iconPosition === 'left' && <Icon size={size} {...icon} />}
{!isCircle && children}
{icon && iconPosition === 'right' && <Icon icon={icon} size={iconSize || size} />}
{icon && iconPosition === 'right' && <Icon size={size} {...icon} />}
</ButtonBase>
);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { IconProps } from '@components/components/Icon/types';
import { ButtonHTMLAttributes } from 'react';

import type { IconNames } from '@components';
import type { SizeOptions, ColorOptions, FontSizeOptions } from '@components/theme/config';
import type { SizeOptions, ColorOptions } from '@components/theme/config';

export type ButtonVariant = 'filled' | 'outline' | 'text';
export enum ButtonVariantValues {
filled = 'filled',
outline = 'outline',
text = 'text',
}
export type ButtonVariant = keyof typeof ButtonVariantValues;

export interface ButtonPropsDefaults {
variant: ButtonVariant;
Expand All @@ -19,8 +24,7 @@ export interface ButtonPropsDefaults {
export interface ButtonProps
extends Partial<ButtonPropsDefaults>,
Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'color'> {
icon?: IconNames;
iconSize?: FontSizeOptions;
icon?: IconProps;
}

export type ButtonStyleProps = Omit<ButtonPropsDefaults, 'iconPosition'>;
export type ButtonStyleProps = Omit<ButtonPropsDefaults, 'iconPosition'> & { hasChildren: boolean };
42 changes: 12 additions & 30 deletions datahub-web-react/src/alchemy-components/components/Button/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const getButtonColorStyles = (variant: ButtonVariant, color: ColorOptions): Colo

bgColor: colors.transparent,
borderColor: colors.transparent,
hoverBgColor: colors.transparent,
hoverBgColor: colors.gray[1500],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request from Anna: adds light gray on hover of "text" buttons

activeBgColor: colors.transparent,
disabledBgColor: colors.transparent,
disabledBorderColor: colors.transparent,
Expand Down Expand Up @@ -151,26 +151,7 @@ const getButtonFontStyles = (size: SizeOptions) => {
lineHeight: typography.lineHeights.none,
};

const sizeStyles = {
sm: {
...baseFontStyles,
fontSize: getFontSize(size), // 12px
},
md: {
...baseFontStyles,
fontSize: getFontSize(size), // 14px
},
lg: {
...baseFontStyles,
fontSize: getFontSize(size), // 16px
},
xl: {
...baseFontStyles,
fontSize: getFontSize(size), // 18px
},
};

return sizeStyles[size];
return { ...baseFontStyles, fontSize: getFontSize(size) };
};

// Generate radii styles for button
Expand All @@ -180,13 +161,14 @@ const getButtonRadiiStyles = (isCircle: boolean) => {
};

// Generate padding styles for button
const getButtonPadding = (size: SizeOptions, variant: ButtonVariant, isCircle: boolean) => {
const getButtonPadding = (size: SizeOptions, hasChildren: boolean, isCircle: boolean) => {
if (isCircle) return { padding: spacing.xsm };
if (!hasChildren) return { padding: spacing.xsm };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom padding for buttons that are just icons


const paddingStyles = {
xs: {
vertical: 0,
horizontal: 0,
vertical: 6,
horizontal: 6,
Comment on lines +170 to +171
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not actually used but this seems more appropriate

},
sm: {
vertical: 8,
Expand All @@ -208,7 +190,7 @@ const getButtonPadding = (size: SizeOptions, variant: ButtonVariant, isCircle: b

const selectedStyle = paddingStyles[size];
const verticalPadding = selectedStyle.vertical;
const horizontalPadding = variant === 'text' ? 0 : selectedStyle.horizontal;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding padding back to text buttons after talking to Anna

const horizontalPadding = selectedStyle.horizontal;
return { padding: `${verticalPadding}px ${horizontalPadding}px` };
};

Expand All @@ -221,16 +203,16 @@ const getButtonActiveStyles = (colorStyles: ColorStyles) => ({
});

// Generate loading styles for button
const getButtonLoadingStyles = () => ({
const getButtonLoadingStyles = (): CSSObject => ({
pointerEvents: 'none',
opacity: 0.75,
});

/*
* Main function to generate styles for button
*/
export const getButtonStyle = (props: ButtonStyleProps) => {
const { variant, color, size, isCircle, isActive, isLoading, isDisabled } = props;
export const getButtonStyle = (props: ButtonStyleProps): CSSObject => {
const { variant, color, size, isCircle, isActive, isLoading, isDisabled, hasChildren } = props;

// Get map of colors
const colorStyles = getButtonColorStyles(variant, color);
Expand All @@ -239,10 +221,10 @@ export const getButtonStyle = (props: ButtonStyleProps) => {
const variantStyles = getButtonVariantStyles(variant, colorStyles);
const fontStyles = getButtonFontStyles(size);
const radiiStyles = getButtonRadiiStyles(isCircle);
const paddingStyles = getButtonPadding(size, variant, isCircle);
const paddingStyles = getButtonPadding(size, hasChildren, isCircle);

// Base of all generated styles
let styles = {
let styles: CSSObject = {
...variantStyles,
...fontStyles,
...radiiStyles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{onBack && (
<Button
color="gray"
icon="ArrowBack"
icon={{ icon: 'ArrowBack', source: 'material' }}

Check warning on line 29 in datahub-web-react/src/alchemy-components/components/Drawer/Drawer.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/alchemy-components/components/Drawer/Drawer.tsx#L29

Added line #L29 was not covered by tests
iconPosition="left"
isCircle
onClick={() => onBack?.()}
Expand All @@ -41,7 +41,7 @@
{closable && (
<Button
color="gray"
icon="Close"
icon={{ icon: 'Close', source: 'material' }}

Check warning on line 44 in datahub-web-react/src/alchemy-components/components/Drawer/Drawer.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/alchemy-components/components/Drawer/Drawer.tsx#L44

Added line #L44 was not covered by tests
iconPosition="left"
isCircle
onClick={() => onClose?.()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const meta = {
subTitle: 'Description of the card',
renderControls: () => (
<>
<Button icon="Add" variant="outline" size="md">
<Button icon={{ icon: 'Add', source: 'material' }} variant="outline" size="md">
Assertion
</Button>
<SimpleSelect
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const MATERIAL_UI_ICONS = [
export const MATERIAL_UI_ICONS = [
'AccountCircle',
'AccountTree',
'AddCircle',
Expand Down Expand Up @@ -546,7 +546,7 @@ const MATERIAL_UI_ICONS = [
'ZoomOutMap',
];

const PHOSPHOR_ICONS = [
export const PHOSPHOR_ICONS = [
'Activity',
'AddressBook',
'Airplane',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MATERIAL_UI_ICONS, PHOSPHOR_ICONS } from '@components/components/Icon/constants';
import React from 'react';

import type { Meta, StoryObj } from '@storybook/react';
Expand Down Expand Up @@ -54,6 +55,10 @@ const meta = {
description: 'The icon to display in the Input.',
type: 'string',
options: AVAILABLE_ICONS,
mapping: Object.fromEntries([
...MATERIAL_UI_ICONS.map((icon) => [icon, { icon, source: 'material' }]),
...PHOSPHOR_ICONS.map((icon) => [icon, { icon, source: 'phosphor' }]),
]),
table: {
defaultValue: { summary: 'undefined' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</Label>
)}
<InputContainer {...inputBaseProps}>
{icon && <SearchIcon icon={icon.name} source={icon.source} variant={icon.variant} size="xl" />}
{icon && <SearchIcon size="xl" {...icon} />}

Check warning on line 79 in datahub-web-react/src/alchemy-components/components/Input/Input.tsx

View check run for this annotation

Codecov / codecov/patch

datahub-web-react/src/alchemy-components/components/Input/Input.tsx#L79

Added line #L79 was not covered by tests
<InputField
value={value}
onChange={(e) => setValue?.(e.target.value)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { IconSource } from '@components/components/Icon/types';
import { IconProps } from '@components/components/Icon/types';
import React, { InputHTMLAttributes } from 'react';

import { IconNames, MaterialIconVariant } from '../Icon';

export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
value?: string | number | readonly string[] | undefined;
setValue?: React.Dispatch<React.SetStateAction<string>>;
label: string;
placeholder?: string;
icon?: { name: IconNames; source: IconSource; variant?: MaterialIconVariant };
icon?: IconProps;
error?: string;
warning?: string;
isSuccess?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { SearchOutlined } from '@ant-design/icons';
import { Icon } from '@src/alchemy-components';
import { InputProps } from 'antd';
import React from 'react';
import { StyledSearchBar } from './components';
import { SearchBarProps } from './types';

export const searchBarDefaults: SearchBarProps = {
placeholder: 'Search...',
value: '',
width: '272px',
width: '100%',
allowClear: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default to 100% instead, I do make the corresponding change in StructuredProperties.tsx

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anywhere else this was used that was banking on that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just that and SchemaSearchInput which now passes in width=300px

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore me, I just added that too. Only place it was used is StructuredProperties

};

Expand All @@ -16,15 +17,17 @@ export const SearchBar = ({
width = searchBarDefaults.width,
allowClear = searchBarDefaults.allowClear,
onChange,
}: SearchBarProps) => {
...props
}: SearchBarProps & Omit<InputProps, 'onChange'>) => {
return (
<StyledSearchBar
placeholder={placeholder}
onChange={(e) => onChange?.(e.target.value)}
value={value}
prefix={<SearchOutlined />}
prefix={<Icon icon="MagnifyingGlass" source="phosphor" />}
allowClear={allowClear}
$width={width}
{...props}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface SearchBarProps {
width?: string;
onChange?: (value: string) => void;
allowClear?: boolean;
disabled?: boolean;
}
Loading
Loading