Skip to content

Commit

Permalink
feat: add extra content class name prop for radio and checkbox compon…
Browse files Browse the repository at this point in the history
…ents (#1048)

* feat(radio): add content class name prop

* feat(checkbox): add content class name prop
  • Loading branch information
NooNoo1337 authored Mar 29, 2022
1 parent 5d7a9d5 commit 3c076b9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/checkbox/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ describe('Checkbox', () => {
expect(container.firstElementChild).toHaveClass(className);
});

it('should set contentClassName', () => {
const className = 'custom-class';
const { container } = render(<Checkbox label='label' contentClassName={className} />);

expect(container.querySelector('.content')).toHaveClass(className);
});

it('should set boxClassName', () => {
const className = 'custom-class';
const { container } = render(<Checkbox boxClassName={className} />);

expect(container.querySelector('.box')).toHaveClass(className);
});

it('should set `checked` class', () => {
const { container } = render(<Checkbox checked={true} />);

Expand Down
10 changes: 9 additions & 1 deletion packages/checkbox/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export type CheckboxProps = Omit<NativeProps, 'size' | 'onChange'> & {
*/
boxClassName?: string;

/**
* Доп. класс контента
*/
contentClassName?: string;

/**
* Выравнивание
*/
Expand Down Expand Up @@ -96,6 +101,7 @@ export const Checkbox = forwardRef<HTMLLabelElement, CheckboxProps>(
hint,
size = 's',
boxClassName,
contentClassName,
align = 'start',
addons,
block,
Expand Down Expand Up @@ -151,9 +157,11 @@ export const Checkbox = forwardRef<HTMLLabelElement, CheckboxProps>(
</span>

{(label || hint || errorMessage) && (
<span className={styles.content}>
<span className={cn(styles.content, contentClassName)}>
{label && <span className={styles.label}>{label}</span>}

{hint && !errorMessage && <span className={styles.hint}>{hint}</span>}

{errorMessage && (
<span className={styles.errorMessage} role='alert'>
{errorMessage}
Expand Down
16 changes: 15 additions & 1 deletion packages/radio/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ describe('Radio', () => {
expect(container.firstElementChild).toHaveClass(className);
});

it('should set contentClassName', () => {
const className = 'custom-class';
const { container } = render(<Radio label='label' contentClassName={className} />);

expect(container.querySelector('.content')).toHaveClass(className);
});

it('should set circleClassName', () => {
const className = 'custom-class';
const { container } = render(<Radio circleClassName={className} />);

expect(container.querySelector('.circle')).toHaveClass(className);
});

it('should set `checked` class', () => {
const { container } = render(<Radio checked={true} />);

Expand All @@ -52,7 +66,7 @@ describe('Radio', () => {
});

describe('Attributes tests', () => {
it('should set `data-test-id` atribute', () => {
it('should set `data-test-id` attribute', () => {
const dataTestId = 'test-id';
const { getByTestId } = render(<Radio dataTestId={dataTestId} />);

Expand Down
8 changes: 7 additions & 1 deletion packages/radio/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export type RadioProps = Omit<
*/
circleClassName?: string;

/**
* Доп. класс контента
*/
contentClassName?: string;

/**
* Выравнивание
*/
Expand Down Expand Up @@ -95,6 +100,7 @@ export const Radio = forwardRef<HTMLLabelElement, RadioProps>(
onChange,
className,
circleClassName,
contentClassName,
name,
disabled,
inactive,
Expand Down Expand Up @@ -143,7 +149,7 @@ export const Radio = forwardRef<HTMLLabelElement, RadioProps>(
/>
<span className={cn(styles.circle, circleClassName)} />
{(label || hint) && (
<span className={styles.content}>
<span className={cn(styles.content, contentClassName)}>
{label && <span className={styles.label}>{label}</span>}
{hint && <span className={styles.hint}>{hint}</span>}
</span>
Expand Down

0 comments on commit 3c076b9

Please sign in to comment.