Skip to content

Commit

Permalink
feat: use textProps to control style
Browse files Browse the repository at this point in the history
  • Loading branch information
Arucard89 committed Jul 4, 2024
1 parent d11a24b commit 7f29f29
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@gravity-ui/icons": "^2.8.1",
"@gravity-ui/navigation": "^2.15.0",
"@gravity-ui/page-constructor": "^5.2.0",
"@gravity-ui/uikit": "^6.17.0",
"@gravity-ui/uikit": "^6.20.1",
"@mdx-js/mdx": "^2.3.0",
"@mdx-js/react": "^2.3.0",
"@octokit/rest": "^20.1.1",
Expand Down
28 changes: 7 additions & 21 deletions src/components/SelectableCard/SelectableCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,17 @@ export type SelecableCardProps = {
* Props for inner Text component
*/
textProps?: TextProps;
/**
* Style object to customize decorated text. Has an impact when pureText has falsie values
*/
contentStyle?: React.CSSProperties;
} & Pick<CardProps, 'selected' | 'onClick'> &
Pick<DOMProps, 'className'>;

const CardContent = ({
text,
pureText,
textProps,
contentStyle,
}: Pick<SelecableCardProps, 'text' | 'pureText' | 'textProps' | 'contentStyle'>) => {
}: Pick<SelecableCardProps, 'text' | 'pureText' | 'textProps'>) => {
const props: Record<string, unknown> = pureText
? {variant: 'body-2'}
: {color: 'inverted-primary', className: b('fake-button')};
props.style = contentStyle;
return (
<Text {...props} {...textProps}>
{text}
Expand All @@ -52,17 +46,9 @@ export const SelectableCard = ({
onClick,
className,
textProps,
contentStyle,
}: SelecableCardProps) => {
return (
<Card className={b(null, className)} type="selection" selected={selected} onClick={onClick}>
<CardContent
text={text}
pureText={pureText}
textProps={textProps}
contentStyle={contentStyle}
/>
{selected && <CircleCheckFill className={b('icon')} />}
</Card>
);
};
}: SelecableCardProps) => (
<Card className={b(null, className)} type="selection" selected={selected} onClick={onClick}>
<CardContent text={text} pureText={pureText} textProps={textProps} />
{selected && <CircleCheckFill className={b('icon')} />}
</Card>
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ export const BorderCard = ({selected, preset, onClick}: BorderCardProps) => {
}, [preset]);

const displayName = t(preset);
const borderRadiusStyle = {borderRadius: RADIUS_PRESETS[preset]?.m + 'px'};

return (
<SelectableCard
text={displayName}
onClick={handleClick}
selected={selected}
pureText={preset === RadiusPresetName.Custom}
contentStyle={{borderRadius: RADIUS_PRESETS[preset]?.m + 'px'}}
textProps={{style: borderRadiusStyle}}
/>
);
};

0 comments on commit 7f29f29

Please sign in to comment.