Skip to content

Commit e4df0aa

Browse files
chore: use data attribute util in new components (#64)
* chore: use data attribute util in new components * Create curvy-waves-burn.md Co-authored-by: Pietro Maximoff <74987028+pietro-maximoff@users.noreply.github.com>
1 parent 5321c95 commit e4df0aa

6 files changed

Lines changed: 17 additions & 9 deletions

File tree

.changeset/curvy-waves-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sovryn/ui": patch
3+
---
4+
5+
chore: use data attribute util in new components

packages/ui/src/1_atoms/Accordion/Accordion.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { ReactNode, FC, useCallback } from 'react';
22

33
import classNames from 'classnames';
44

5-
import { DATA_ATTRIBUTE } from '../../utils/constants';
5+
import { applyDataAttr } from '../../utils';
66
import { Heading } from '../Heading/Heading';
77
import { HeadingType } from '../Heading/Heading.types';
88
import { Icon } from '../Icon/Icon';
@@ -40,7 +40,7 @@ export const Accordion: FC<IAccordionProps> = ({
4040
[styles.disabled]: disabled,
4141
})}
4242
onClick={onClickCallback}
43-
{...{ [DATA_ATTRIBUTE]: dataLayoutId }}
43+
{...applyDataAttr(dataLayoutId)}
4444
>
4545
<>
4646
{typeof label === 'string' ? (
@@ -62,7 +62,7 @@ export const Accordion: FC<IAccordionProps> = ({
6262
{open && (
6363
<div
6464
className={styles.content}
65-
{...{ [DATA_ATTRIBUTE]: `${dataLayoutId}-content` }}
65+
{...applyDataAttr(`${dataLayoutId}-content`)}
6666
>
6767
{children}
6868
</div>

packages/ui/src/2_molecules/FormGroup/FormGroup.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { PropsWithChildren, ReactNode } from 'react';
33
import classNames from 'classnames';
44

55
import { Heading, HeadingType, Paragraph, ParagraphSize } from '../../1_atoms';
6+
import { applyDataAttr } from '../../utils';
67
import styles from './FormGroup.module.css';
78

89
type FormGroupProps = {
@@ -24,7 +25,7 @@ export const FormGroup: React.FC<PropsWithChildren<FormGroupProps>> = ({
2425
dataLayoutId,
2526
}) => (
2627
<div
27-
data-layout-id={dataLayoutId}
28+
{...applyDataAttr(dataLayoutId)}
2829
className={classNames(className, styles.formGroup)}
2930
>
3031
{(label || subtext) && (
@@ -44,7 +45,7 @@ export const FormGroup: React.FC<PropsWithChildren<FormGroupProps>> = ({
4445
{children}
4546
{errorLabel && (
4647
<span
47-
data-layout-id={`${dataLayoutId}__error-message`}
48+
{...applyDataAttr(`${dataLayoutId}__error-message`)}
4849
className={styles.errorLabel}
4950
>
5051
{errorLabel}

packages/ui/src/2_molecules/RadioButtonGroup/RadioButtonGroup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { FC } from 'react';
33
import classNames from 'classnames';
44

55
import { Heading, HeadingType } from '../../1_atoms';
6+
import { applyDataAttr } from '../../utils';
67
import { RadioButton } from '../RadioButton';
78
import styles from './RadioButtonGroup.module.css';
89
import {
@@ -20,7 +21,7 @@ export const RadioButtonGroup: FC<RadioButtonGroupProps> = ({
2021
}) => (
2122
<fieldset
2223
className={classNames(styles.radioButtonGroup, className)}
23-
data-layout-id={dataLayoutId}
24+
{...applyDataAttr(dataLayoutId)}
2425
>
2526
{label && (
2627
<Heading type={HeadingType.h3} className={styles.headingLabel}>

packages/ui/src/2_molecules/TableBase/TableBase.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { ReactNode } from 'react';
22

33
import classNames from 'classnames';
44

5+
import { applyDataAttr } from '../../utils';
56
import styles from './TableBase.module.css';
67
import { ColumnOptions, RowObject } from './TableBase.types';
78
import { TableRow } from './components/TableRow/TableRow';
@@ -32,7 +33,7 @@ export const TableBase = <RowType extends RowObject>({
3233
return (
3334
<table
3435
className={classNames(styles.table, className)}
35-
data-layout-id={dataAttribute}
36+
{...applyDataAttr(dataAttribute)}
3637
>
3738
<thead>
3839
<tr>

packages/ui/src/2_molecules/TableBase/components/TableRow/TableRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useState } from 'react';
22

33
import classNames from 'classnames';
44

5-
import { noop } from '../../../../utils';
5+
import { noop, applyDataAttr } from '../../../../utils';
66
import { RowObject, ColumnOptions } from '../../TableBase.types';
77
import styles from './TableRow.module.css';
88

@@ -38,7 +38,7 @@ export const TableRow = <RowType extends RowObject>({
3838
[styles.active]: isClickable && isSelected,
3939
})}
4040
onClick={onClick}
41-
data-layout-id={`${dataAttribute}-row-${index}`}
41+
{...applyDataAttr(`${dataAttribute}-row-${index}`)}
4242
>
4343
{columns.map(column => (
4444
<td

0 commit comments

Comments
 (0)