-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat(SubBlocks): add possibility to position controls within cards at footer #823
Changes from all commits
e6ed9c3
cec49fa
ff0e912
af1e814
09dad73
71ca3d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import '../../../styles/variables.scss'; | ||
|
||
$block: '.#{$ns}buttons'; | ||
|
||
#{$block} { | ||
display: flex; | ||
flex-wrap: wrap; | ||
column-gap: $indentXXS; | ||
|
||
&_size { | ||
&_s { | ||
row-gap: $indentXXXS; | ||
} | ||
|
||
&_l { | ||
row-gap: $indentXXS; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
|
||
import {ButtonProps, ContentSize} from '../../models'; | ||
import {block} from '../../utils'; | ||
import Button from '../Button/Button'; | ||
|
||
import './Buttons.scss'; | ||
|
||
const b = block('buttons'); | ||
|
||
type ButtonsProps = { | ||
className?: string; | ||
buttons?: ButtonProps[]; | ||
size?: ContentSize; | ||
titleId?: string; | ||
qa?: string; | ||
buttonQa?: string; | ||
}; | ||
|
||
function getButtonSize(size: ContentSize) { | ||
switch (size) { | ||
case 's': | ||
return 'm'; | ||
case 'l': | ||
default: | ||
return 'xl'; | ||
} | ||
} | ||
|
||
const Buttons: React.FC<ButtonsProps> = ({className, titleId, buttons, size = 's', qa, buttonQa}) => | ||
buttons ? ( | ||
<div className={b({size}, className)} data-qa={qa}> | ||
{buttons.map((item) => ( | ||
<Button | ||
className={b('button')} | ||
{...item} | ||
key={item.url} | ||
size={getButtonSize(size)} | ||
qa={buttonQa} | ||
extraProps={{ | ||
'aria-describedby': item.urlTitle ? undefined : titleId, | ||
...item.extraProps, | ||
}} | ||
/> | ||
))} | ||
</div> | ||
) : null; | ||
|
||
export default Buttons; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@import '../../../styles/variables.scss'; | ||
|
||
$block: '.#{$ns}links'; | ||
|
||
#{$block} { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: baseline; | ||
|
||
&__link { | ||
margin-top: 0px; | ||
} | ||
|
||
&_size { | ||
&_s { | ||
gap: $indentXXXS; | ||
} | ||
|
||
&_l { | ||
gap: $indentXXS; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
|
||
import {ContentSize, LinkProps} from '../../models'; | ||
import {block} from '../../utils'; | ||
import Link from '../Link/Link'; | ||
|
||
import './Links.scss'; | ||
|
||
const b = block('links'); | ||
|
||
function getLinkSize(size: ContentSize) { | ||
switch (size) { | ||
case 's': | ||
return 'm'; | ||
case 'l': | ||
default: | ||
return 'l'; | ||
} | ||
} | ||
|
||
type LinksProps = { | ||
className?: string; | ||
titleId?: string; | ||
links?: LinkProps[]; | ||
size?: ContentSize; | ||
qa?: string; | ||
linkQa?: string; | ||
}; | ||
|
||
const Links: React.FC<LinksProps> = ({className, titleId, links, size = 's', qa, linkQa}) => | ||
links ? ( | ||
<div className={b({size}, className)} data-qa={qa}> | ||
{links?.map((link) => ( | ||
<Link | ||
className={b('link')} | ||
{...link} | ||
textSize={getLinkSize(size)} | ||
key={link.url} | ||
qa={linkQa} | ||
extraProps={{ | ||
'aria-describedby': link.urlTitle ? undefined : titleId, | ||
...link.extraProps, | ||
}} | ||
/> | ||
))} | ||
</div> | ||
) : null; | ||
|
||
export default Links; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { | |
ButtonPixel, | ||
ButtonProps, | ||
CardBaseProps, | ||
CardLayoutProps, | ||
ContentTheme, | ||
DividerSize, | ||
ImageCardMargins, | ||
|
@@ -134,6 +135,7 @@ export interface QuoteProps extends Themable, CardBaseProps { | |
export interface BackgroundCardProps | ||
extends CardBaseProps, | ||
AnalyticsEventsBase, | ||
CardLayoutProps, | ||
Omit<ContentBlockProps, 'colSizes' | 'centered'> { | ||
url?: string; | ||
urlTitle?: string; | ||
|
@@ -145,6 +147,7 @@ export interface BackgroundCardProps | |
export interface BasicCardProps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. `interface CardLayoutProps = { ... export interface BannerCardProps extends CardLayoutProps |
||
extends CardBaseProps, | ||
AnalyticsEventsBase, | ||
CardLayoutProps, | ||
Omit<ContentBlockProps, 'colSizes' | 'centered' | 'size' | 'theme'> { | ||
url: string; | ||
urlTitle?: string; | ||
|
@@ -178,7 +181,7 @@ export interface PriceCardProps extends CardBaseProps, Pick<ContentBlockProps, ' | |
list?: string[]; | ||
} | ||
|
||
export interface LayoutItemProps extends ClassNameProps, AnalyticsEventsBase { | ||
export interface LayoutItemProps extends ClassNameProps, CardLayoutProps, AnalyticsEventsBase { | ||
content: Omit<ContentBlockProps, 'colSizes' | 'centered' | 'size'>; | ||
media?: MediaProps; | ||
metaInfo?: string[]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import React from 'react'; | ||
import React, {useMemo} from 'react'; | ||
|
||
import {useUniqId} from '@gravity-ui/uikit'; | ||
|
||
import {BackgroundImage, CardBase} from '../../components/'; | ||
import {useTheme} from '../../context/theme'; | ||
import {BackgroundCardProps} from '../../models'; | ||
import {block, getThemedValue} from '../../utils'; | ||
import renderContentControls from '../../utils/renderContentControls/renderContentControls'; | ||
import Content from '../Content/Content'; | ||
import renderCardFooterControlsContainer from '../renderCardFooterControlsContainer/renderCardFooterControlsContainer'; | ||
|
||
import './BackgroundCard.scss'; | ||
|
||
|
@@ -25,11 +29,29 @@ const BackgroundCard = (props: BackgroundCardProps) => { | |
buttons, | ||
analyticsEvents, | ||
urlTitle, | ||
controlPosition = 'content', | ||
} = props; | ||
|
||
const titleId = useUniqId(); | ||
|
||
const theme = useTheme(); | ||
const hasBackgroundColor = backgroundColor || cardTheme !== 'default'; | ||
const borderType = hasBackgroundColor ? 'none' : border; | ||
const areControlsInFooter = !paddingBottom && controlPosition === 'footer'; | ||
|
||
const footerControls = useMemo( | ||
() => | ||
renderContentControls( | ||
{ | ||
links: areControlsInFooter ? links : undefined, | ||
buttons: areControlsInFooter ? buttons : undefined, | ||
size: 's', | ||
titleId, | ||
}, | ||
renderCardFooterControlsContainer, | ||
), | ||
[areControlsInFooter, links, buttons, titleId], | ||
); | ||
|
||
return ( | ||
<CardBase | ||
|
@@ -46,16 +68,18 @@ const BackgroundCard = (props: BackgroundCardProps) => { | |
style={{backgroundColor}} | ||
/> | ||
<Content | ||
titleId={titleId} | ||
title={title} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
text={text} | ||
additionalInfo={additionalInfo} | ||
size="s" | ||
theme={cardTheme} | ||
links={links} | ||
buttons={buttons} | ||
links={areControlsInFooter ? undefined : links} | ||
buttons={areControlsInFooter ? undefined : buttons} | ||
colSizes={{all: 12, md: 12}} | ||
/> | ||
</CardBase.Content> | ||
{footerControls} | ||
</CardBase> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, this won't work within CardBase. |
||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of
isValidElement
? didn't find any usage examples in prThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at line 96. It used to handle children elements correctly.