Skip to content

Commit

Permalink
fix: review replies
Browse files Browse the repository at this point in the history
  • Loading branch information
niktverd committed Dec 20, 2024
1 parent d3b1c0b commit 2390740
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/blocks/ExtendedFeatures/ExtendedFeatures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ExtendedFeaturesBlock = ({
<div className={b('container')}>
{itemTitle && (
<YFMWrapper
variant={itemTitleHeadingTag}
tagName={itemTitleHeadingTag}
content={itemTitle}
className={b('item-title-container')}
contentClassName={b('item-title')}
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const HeaderBlock = (props: React.PropsWithChildren<HeaderBlockFullProps>
<Col sizes={titleSizes} className={b('content-inner')}>
{overtitle && (
<YFMWrapper
variant="div"
tagName="div"
className={b('overtitle')}
content={overtitle}
modifiers={{
Expand All @@ -151,7 +151,7 @@ export const HeaderBlock = (props: React.PropsWithChildren<HeaderBlockFullProps>
constructor: true,
constructorTheme: textTheme,
}}
variant="h1"
tagName="h1"
contentPosition="end"
>
{status}
Expand Down
14 changes: 7 additions & 7 deletions src/components/HTML/HTML.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, {PropsWithChildren, useMemo} from 'react';

import {ClassNameProps, QAProps} from '../../models/common';
import {selectVariant} from '../../utils';
import {ClassNameProps, QAProps, TagName} from '../../models/common';
import {selectTagName} from '../../utils';

export interface HTMLExtraProps {
variant?: 'span' | 'div' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'section' | 'p';
tagName?: TagName;
contentPosition?: 'start' | 'end';
contentClassName?: string;
onlyContent?: boolean;
Expand All @@ -24,28 +24,28 @@ const HTML = ({
contentClassName,
qa,
contentPosition = 'start',
variant = 'span',
tagName = 'span',
onlyContent = false,
...rest
}: HTMLProps) => {
const renderedContent = useMemo(() => {
return content
? React.createElement(selectVariant({content, block, variant, children}), {
? React.createElement(selectTagName({content, block, tagName, children}), {
dangerouslySetInnerHTML: {__html: content},
className: contentClassName,
'data-qa': qa,
...rest,
})
: null;
}, [block, children, content, contentClassName, qa, rest, variant]);
}, [block, children, content, contentClassName, qa, rest, tagName]);

if (onlyContent) {
return renderedContent;
}

if (children) {
return React.createElement(
variant,
tagName,
{
className,
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class Table extends React.Component<TableProps & ClassNameProps>
this.renderMarker(marker, cell)
) : (
<YFMWrapper
variant="span"
tagName="span"
content={cell}
modifiers={{
constructor: true,
Expand Down
2 changes: 2 additions & 0 deletions src/models/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ export type AnalyticsEventsProp = AnalyticsEvent | AnalyticsEvent[];
export interface AnalyticsEventsBase {
analyticsEvents?: AnalyticsEventsProp;
}

export type TagName = 'span' | 'div' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'section' | 'p';
2 changes: 1 addition & 1 deletion src/sub-blocks/BannerCard/BannerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const BannerCard = (props: BannerCardProps) => {
<div className={b('info')}>
<div className={b('text')}>
<YFMWrapper
variant="h2"
tagName="h2"
contentClassName={b('title')}
content={title}
modifiers={{
Expand Down
2 changes: 1 addition & 1 deletion src/sub-blocks/Quote/Quote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const Quote = (props: QuoteProps) => {
<div className={b('content', {'quote-type': quoteType})}>
{textLocal && (
<YFMWrapper
variant="span"
tagName="span"
contentClassName={b('text')}
content={textLocal}
modifiers={{constructor: true}}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ReactNode} from 'react';
import camelCase from 'lodash/camelCase';
import flatten from 'lodash/flatten';

import {ConstructorBlock, CustomConfig, PCShareSocialNetwork, TextSize} from '../models';
import {ConstructorBlock, CustomConfig, PCShareSocialNetwork, TagName, TextSize} from '../models';

const BLOCK_ELEMENTS = [
'div',
Expand Down Expand Up @@ -64,12 +64,12 @@ type SelectVariantArgs = {
block?: boolean;
content?: string;
children?: ReactNode;
variant?: string;
tagName?: TagName;
};

export function selectVariant({content, children, variant}: SelectVariantArgs): string {
if (!children && variant) {
return variant;
export function selectTagName({content, children, tagName}: SelectVariantArgs): string {
if (!children && tagName) {
return tagName;
}

if (!content) {
Expand Down

0 comments on commit 2390740

Please sign in to comment.