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

RadioCard component #16619

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,23 @@
import { Meta, StoryObj } from '@storybook/react';

import { RadioCard as RadioCardComponent, RadioCardProps } from './RadioCard';

const meta: Meta = {
title: 'RadioCard',
component: RadioCardComponent,
} as Meta;
export default meta;

export const RadioCard: StoryObj<RadioCardProps> = {
args: {
isActive: true,
children: 'Content',
},
argTypes: {
isActive: {
control: {
type: 'boolean',
},
},
},
};
51 changes: 51 additions & 0 deletions packages/components/src/components/RadioCard/RadioCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ReactNode } from 'react';

import styled, { css } from 'styled-components';

import { palette, borders, spacingsPx } from '@trezor/theme';

import { Card } from '../Card/Card';
import { Icon } from '../Icon/Icon';
import { Box } from '../Box/Box';
import { FrameProps } from '../../utils/frameProps';

export type RadioCardProps = {
isActive: boolean;
children: ReactNode;
onClick: () => void;
};

const BorderActive = styled.div<{ isActive: boolean }>`
pointer-events: none;
position: absolute;
enjojoy marked this conversation as resolved.
Show resolved Hide resolved
inset: 0;
${({ isActive }) =>
isActive &&
css`
outline: ${borders.widths.large} solid ${({ theme }) => theme.borderSecondary};
outline-offset: -${borders.widths.large};
Comment on lines +25 to +26
Copy link
Contributor

Choose a reason for hiding this comment

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

It is OK to use outline? IMHO yes.

@adamhavel What's your opinion here?

`}
border-radius: ${borders.radii.md};
`;

const IconWrapper = styled.div`
adamhavel marked this conversation as resolved.
Show resolved Hide resolved
border-radius: ${borders.radii.full};
background-color: ${({ theme }) => theme.borderSecondary};
padding: ${spacingsPx.xxxs};
`;

export const RadioCard = ({ isActive, children, ...frameProps }: RadioCardProps & FrameProps) => (
<Box position={{ type: 'relative' }} {...frameProps}>
{isActive && (
<Box position={{ type: 'absolute', top: '-1px', right: '-1px' }} zIndex={2}>
<IconWrapper>
<Icon name="check" size="extraSmall" color={palette.lightWhiteAlpha1000} />
</IconWrapper>
</Box>
)}
<Card paddingType="small" fillType="none">
{children}
</Card>
<BorderActive isActive={isActive} />
</Box>
);
2 changes: 2 additions & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ export { getSafeWindowSize } from './utils/getSafeWindowSize';

export { intermediaryTheme } from './config/colors';
export type { SuiteThemeColors } from './config/colors';

export { RadioCard } from './components/RadioCard/RadioCard';
Loading