Skip to content

Commit

Permalink
feat: add attribute to plugin root element (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marginy605 committed Apr 12, 2024
1 parent 2b74d55 commit d052702
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/plugins/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Button, Loader} from '@gravity-ui/uikit';
import {i18n} from '../../i18n';
import {Plugin, PluginWidgetProps} from '../../typings';
import {cn} from '../../utils/cn';
import {PLUGIN_ROOT_ATTR_NAME} from '../constants';

import './Text.scss';

Expand Down Expand Up @@ -107,7 +108,10 @@ export class PluginText extends React.PureComponent<PluginTextProps, PluginTextS

private renderText() {
return (
<div className={b({withMarkdown: this.withMarkdown})}>
<div
className={b({withMarkdown: this.withMarkdown})}
{...{[PLUGIN_ROOT_ATTR_NAME]: 'text'}}
>
{this.withMarkdown ? (
<div
className="yfm" // className из стилей для markdown
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/Title/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

import {Plugin, PluginWidgetProps} from '../../typings';
import {cn} from '../../utils/cn';
import {PLUGIN_ROOT_ATTR_NAME} from '../constants';

import './Title.scss';

Expand All @@ -22,7 +23,7 @@ export class PluginTitle extends React.Component<PluginTitleProps> {
const size = data.size ? data.size : false;
const id = data.showInTOC && text ? encodeURIComponent(text) : undefined;
return (
<div id={id} className={b({size})}>
<div id={id} className={b({size})} {...{[PLUGIN_ROOT_ATTR_NAME]: 'title'}}>
{text}
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PLUGIN_ROOT_ATTR_NAME = 'data-plugin-root-el';
1 change: 1 addition & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Text';
export * from './Title';
export * from './constants';

0 comments on commit d052702

Please sign in to comment.