Skip to content

Commit

Permalink
feat(suite): quick-action refactotring, simplification of the UI and …
Browse files Browse the repository at this point in the history
…adding a update icon

chore(components): add frameProps for ComponentWithSubIcon
  • Loading branch information
peter-sanderson committed Sep 4, 2024
1 parent 29dab70 commit f296deb
Show file tree
Hide file tree
Showing 28 changed files with 592 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Meta, StoryObj } from '@storybook/react';
import { Icon, iconVariants } from '../Icon/Icon';
import {
allowedComponentWithSubIconFrameProps,
ComponentWithSubIcon as ComponentWithSubIconComponent,
ComponentWithSubIconProps,
} from './ComponentWithSubIcon';
import { getFramePropsStory } from '../../utils/frameProps';

const meta: Meta = {
title: 'ComponentWithSubIcon',
component: ComponentWithSubIconComponent,
} as Meta;
export default meta;

export const ComponentWithSubIcon: StoryObj<ComponentWithSubIconProps> = {
args: {
subIconProps: {
name: 'check',
},
variant: 'destructive',
children: <Icon name="tor" />,
...getFramePropsStory(allowedComponentWithSubIconFrameProps).args,
},
argTypes: {
variant: {
options: iconVariants,
control: {
type: 'select',
},
},
...getFramePropsStory(allowedComponentWithSubIconFrameProps).argTypes,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import styled, { useTheme } from 'styled-components';
import {
ExclusiveColorOrVariant,
getColorForIconVariant,
getIconSize,
Icon,
IconProps,
} from '../Icon/Icon';
import { borders, spacingsPx } from '@trezor/theme';
import { TransientProps } from '../../utils/transientProps';
import { ReactNode } from 'react';
import { FramePropsKeys, FrameProps, withFrameProps } from '../../utils/frameProps';

export const allowedComponentWithSubIconFrameProps: FramePropsKeys[] = ['margin'];
type AllowedFrameProps = Pick<FrameProps, (typeof allowedComponentWithSubIconFrameProps)[number]>;

const Container = styled.div<TransientProps<AllowedFrameProps>>`
position: relative;
${withFrameProps}
`;

type SubIconWrapperProps = TransientProps<ExclusiveColorOrVariant> & {
$subIconColor: string;
$subIconSize: number;
};

const SubIconWrapper = styled.div<SubIconWrapperProps>`
position: absolute;
right: -${({ $subIconSize }) => $subIconSize / 2 + 3}px;
top: -${({ $subIconSize }) => $subIconSize / 2 + 3}px;
background-color: ${({ theme, $variant, $color }) =>
getColorForIconVariant({ theme, variant: $variant, color: $color })};
border-radius: ${borders.radii.full};
border: 1px solid ${({ theme }) => theme['borderElevationNegative']};
padding: ${spacingsPx.xxxs};
`;

export type ComponentWithSubIconProps = AllowedFrameProps &
ExclusiveColorOrVariant & {
subIconProps?: IconProps;
children: ReactNode;
};

export const ComponentWithSubIcon = ({
variant,
color,
children,
subIconProps,
margin,
}: ComponentWithSubIconProps) => {
const theme = useTheme();

if (subIconProps === undefined) {
return <Container $margin={margin}>{children}</Container>;
}

const backgroundIconColor = getColorForIconVariant({
theme,
color,
variant,
});

const iconColor = getColorForIconVariant({
theme,
color: subIconProps.color,
variant: subIconProps.variant,
});

const subIconSize = getIconSize(subIconProps.size ?? 12);

return (
<Container $margin={margin}>
{children}
<SubIconWrapper
$color={backgroundIconColor}
$subIconColor={iconColor}
$subIconSize={subIconSize}
>
<Icon {...subIconProps} size={subIconSize} />
</SubIconWrapper>
</Container>
);
};
13 changes: 10 additions & 3 deletions packages/components/src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Meta, StoryObj } from '@storybook/react';
import { allowedIconFrameProps, Icon as IconComponent, IconProps, iconVariants } from './Icon';
import { IconName, icons } from '@suite-common/icons/src/icons';
import {
allowedIconFrameProps,
Icon as IconComponent,
IconName,
IconProps,
icons,
iconSizes,
iconVariants,
} from './Icon';
import { getFramePropsStory } from '../../utils/frameProps';
import { iconSizes } from '@suite-common/icons/src/webComponents';

const meta: Meta = {
title: 'Icons',
component: IconComponent,
Expand Down
27 changes: 21 additions & 6 deletions packages/components/src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ import { CSSColor, Color } from '@trezor/theme';
import { makePropsTransient, TransientProps } from '../../utils/transientProps';
import { FrameProps, FramePropsKeys, withFrameProps } from '../../utils/frameProps';

export const iconVariants = ['primary', 'tertiary', 'info', 'warning', 'destructive'] as const;
export type IconVariant = Extract<UIVariant, (typeof iconVariants)[number]>;

type ExclusiveColorOrVariant =
export const iconVariants = [
'primary',
'tertiary',
'info',
'warning',
'destructive',
'purple',
] as const;

export type IconVariant = Extract<UIVariant, (typeof iconVariants)[number]> | 'purple';

export type ExclusiveColorOrVariant =
| { variant?: IconVariant; color?: undefined }
| {
variant?: undefined;
Expand All @@ -34,9 +42,10 @@ const variantColorMap: Record<IconVariant, Color> = {
info: 'iconAlertBlue',
warning: 'iconAlertYellow',
destructive: 'iconAlertRed',
purple: 'iconAlertPurple',
};

const getColorForIconVariant = ({
export const getColorForIconVariant = ({
variant,
theme,
color,
Expand Down Expand Up @@ -190,4 +199,10 @@ export const Icon = forwardRef(
},
);

export { type IconName, icons, type IconSize } from '@suite-common/icons/src/webComponents';
export {
type IconName,
icons,
type IconSize,
iconSizes,
getIconSize,
} from '@suite-common/icons/src/webComponents';
11 changes: 9 additions & 2 deletions packages/components/src/components/Icon/icons.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import React, { useState } from 'react';
import styled, { useTheme } from 'styled-components';
import { Meta, StoryObj } from '@storybook/react';
import { IconName, icons, Icon, IconProps, allowedIconFrameProps, iconVariants } from './Icon';
import {
IconName,
icons,
Icon,
IconProps,
allowedIconFrameProps,
iconVariants,
iconSizes,
} from './Icon';
import { getFramePropsStory } from '../../utils/frameProps';
import { Input } from '../form/Input/Input';
import { typography } from '@trezor/theme';
import { iconSizes } from '@suite-common/icons/src/webComponents';

const CopiedText = styled.div`
display: flex;
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/components/buttons/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ButtonContainerProps = TransientProps<AllowedFrameProps> & {
$hasIcon?: boolean;
$isFullWidth?: boolean;
$isSubtle: boolean;
$borderRadius?: typeof borders.radii.sm | typeof borders.radii.full; // Do not allow all, we want consistency
};

export const ButtonContainer = styled.button<ButtonContainerProps>`
Expand All @@ -36,7 +37,7 @@ export const ButtonContainer = styled.button<ButtonContainerProps>`
gap: ${({ $hasIcon }) => $hasIcon && spacingsPx.xs};
padding: ${({ $size }) => getPadding($size, true)};
width: ${({ $isFullWidth }) => $isFullWidth && '100%'};
border-radius: ${borders.radii.full};
border-radius: ${({ $borderRadius }) => $borderRadius ?? borders.radii.full};
transition:
${focusStyleTransition},
background 0.1s ease-out;
Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/components/typography/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ type TextWrap = 'balance' | 'break-word';
export const allowedTextFrameProps: FramePropsKeys[] = ['margin'];
type AllowedFrameProps = Pick<FrameProps, (typeof allowedTextFrameProps)[number]>;

export type TextVariant = Extract<
UIVariant,
'primary' | 'secondary' | 'tertiary' | 'info' | 'warning' | 'destructive'
>;
export type TextVariant =
| Extract<UIVariant, 'primary' | 'secondary' | 'tertiary' | 'info' | 'warning' | 'destructive'>
| 'purple';

type ExclusiveColorOrVariant =
| { variant?: TextVariant; color?: undefined }
Expand All @@ -30,6 +29,7 @@ const variantColorMap: Record<TextVariant, Color> = {
info: 'textAlertBlue',
warning: 'textAlertYellow',
destructive: 'textAlertRed',
purple: 'textAlertPurple',
};

type ColorProps = {
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from './components/buttons/Button/Button';
export * from './components/buttons/ButtonGroup/ButtonGroup';
export * from './components/buttons/IconButton/IconButton';
export * from './components/Icon/Icon';
export { ComponentWithSubIcon } from './components/ComponentWithSubIcon/ComponentWithSubIcon';
export * from './components/buttons/PinButton/PinButton';
export * from './components/buttons/TextButton/TextButton';
export { Card, type CardProps } from './components/Card/Card';
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit f296deb

Please sign in to comment.