-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/components/src/components/RadioCard/RadioCard.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
packages/components/src/components/RadioCard/RadioCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters