Skip to content

Commit

Permalink
feat(components): RadioCard
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Jan 28, 2025
1 parent 74a5713 commit df94a19
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/components/src/components/RadioCard/RadioCard.stories.tsx
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;
inset: 0;
${({ isActive }) =>
isActive &&
css`
outline: ${borders.widths.large} solid ${({ theme }) => theme.borderSecondary};
outline-offset: -${borders.widths.large};
`}
border-radius: ${borders.radii.md};
`;

const IconWrapper = styled.div`
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';

0 comments on commit df94a19

Please sign in to comment.