Skip to content

Commit

Permalink
fix: support ContentList theme prop; pass theme prop from Content to …
Browse files Browse the repository at this point in the history
…ContentList (#1066)
  • Loading branch information
benax-se authored Nov 7, 2024
1 parent eb1813b commit 3de2d9e
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 14 deletions.
39 changes: 39 additions & 0 deletions src/components/ContentList/ContentList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ $iconSizeS: 20px;
$iconSizeXS: 18px;
$marginIconSizeS: 2px;
$marginIconSizeL: 1px;
$lightPrimary: var(--g-color-text-light-primary);
$darkPrimary: var(--g-color-text-dark-primary);
$darkSecondary: var(--g-color-text-dark-secondary);

@mixin content-link($baseColor: $primary, $hoverColor: $secondary) {
color: $baseColor;
text-decoration: underline;
&:hover {
color: $hoverColor;
}
}

#{$block} {
&_size_l {
Expand Down Expand Up @@ -84,6 +95,34 @@ $marginIconSizeL: 1px;
}
}

&_theme_light {
#{$block}__item {
*,
.yfm,
.yfm * {
color: $darkPrimary;
}

.yfm a {
@include content-link($darkPrimary, $darkSecondary);
}
}
}

&_theme_dark {
#{$block}__item {
*,
.yfm,
.yfm * {
color: $lightPrimary;
}

.yfm a {
@include content-link($lightPrimary, $lightSecondary);
}
}
}

&__icon {
display: block;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ContentList/ContentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ function getHeadingLevel(size: ContentSize) {
}
}

const ContentList = ({list, size = 'l', qa}: ContentListProps & QAProps) => {
const ContentList = ({list, size = 'l', qa, theme}: ContentListProps & QAProps) => {
const qaAttributes = getQaAttrubutes(qa, ['image', 'title', 'text']);

return (
<div className={b({size})} data-qa={qa}>
<div className={b({size, theme})} data-qa={qa}>
{list?.map((item) => {
const {icon, title, text} = item;
return (
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const transformedContentList = data.common.list.map((item) => {
};
}) as ContentItemProps[];

const transformedContentDarkList = data.common.darkList.map((item) => {
return {
...item,
text: item?.text && yfmTransform(item.text),
};
}) as ContentItemProps[];

const getPaddingBottomTitle = (padding: string) =>
data.paddings.title.replace('{{padding}}', padding);

Expand Down Expand Up @@ -78,7 +85,12 @@ const CardThemesTemplate: StoryFn<{items: BackgroundCardProps[]}> = (args) => (
<div style={{display: 'flex'}}>
{args.items.map((item, i) => (
<div style={{maxWidth: '400px', padding: '0 8px'}} key={i}>
<BackgroundCard {...item} />
<BackgroundCard
{...item}
list={
item.theme === 'dark' ? transformedContentDarkList : transformedContentList
}
/>
</div>
))}
</div>
Expand Down
15 changes: 15 additions & 0 deletions src/sub-blocks/BackgroundCard/__stories__/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
"title": "Lorem ipsum ipsum"
}
],
"darkList": [
{
"icon": "/story-assets/icon_1_dark.svg",
"title": "Lorem ipsum",
"text": "**Ut enim ad minim veniam** [quis nostrud](https://example.com) exercitation."
},
{
"icon": "/story-assets/icon_2_dark.svg",
"text": "**Ut enim ad minim veniam** [quis nostrud](https://example.com) exercitation."
},
{
"icon": "/story-assets/icon_3_dark.svg",
"title": "Lorem ipsum ipsum"
}
],
"buttons": [
{
"text": "Button\r",
Expand Down
12 changes: 2 additions & 10 deletions src/sub-blocks/Content/Content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ $darkSecondary: var(--g-color-text-dark-secondary);
#{$block}__title *,
#{$block}__text .yfm,
#{$block}__text .yfm *,
#{$block}__list *,
#{$block}__list .yfm,
#{$block}__list .yfm *,
#{$block}__links a {
color: $lightPrimary;
}
Expand All @@ -148,8 +145,7 @@ $darkSecondary: var(--g-color-text-dark-secondary);
}
}

#{$block}__text,
#{$block}__list {
#{$block}__text {
.yfm a {
@include content-link($lightPrimary, $lightSecondary);
}
Expand All @@ -167,9 +163,6 @@ $darkSecondary: var(--g-color-text-dark-secondary);
#{$block}__title *,
#{$block}__text .yfm,
#{$block}__text .yfm *,
#{$block}__list *,
#{$block}__list .yfm,
#{$block}__list .yfm *,
#{$block}__links a {
color: $darkPrimary;
}
Expand All @@ -185,8 +178,7 @@ $darkSecondary: var(--g-color-text-dark-secondary);
}
}

#{$block}__text,
#{$block}__list {
#{$block}__text {
.yfm a {
@include content-link($darkPrimary, $darkSecondary);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sub-blocks/Content/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Content = (props: ContentProps) => {
)}
{list?.length ? (
<div className={b('list')}>
<ContentList list={list} size={size} qa={qaAttributes.list} />
<ContentList list={list} size={size} qa={qaAttributes.list} theme={theme} />
</div>
) : null}
{additionalInfo && (
Expand Down

0 comments on commit 3de2d9e

Please sign in to comment.