Skip to content

Commit

Permalink
add RadioButton
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyanB committed Jun 2, 2023
1 parent 040d545 commit 2490be5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/RadioButton/RadioButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RadioButton } from './RadioButton';

export default {
title: 'Components/Radio Button',
component: RadioButton,
};

export const _RadioButton = {
render: () => <RadioButton />,
};
13 changes: 13 additions & 0 deletions src/components/RadioButton/RadioButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { RadioButton } from './RadioButton';

describe('Components | Buttons | Account Selector', () => {
test('it should render', () => {
render(<RadioButton />);

let radioButton = screen.getByTestId('radio-button');

expect(radioButton).toBeInTheDocument();
});
});
32 changes: 32 additions & 0 deletions src/components/RadioButton/RadioButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import React from 'react';
import { ComponentPropsWithoutRef } from 'react';

export type RadioButtonProps = ComponentPropsWithoutRef<'div'>;

export function RadioButton(props: RadioButtonProps) {
let { ...rest } = props;

return (
<div data-testid="radio-button">
<div className="inline-flex items-center">
<label className="relative flex cursor-pointer items-center rounded-full p-3">
<input
type="radio"
className={`peer relative h-5 w-5
cursor-pointer appearance-none rounded-full
border-2 border-gray-400 checked:border-green-500`}
{...rest}
/>
<div
className={`pointer-events-none absolute top-2/4 left-2/4
-translate-y-2/4 -translate-x-2/4 bg-green-500
w-2.5 h-2.5 rounded-full opacity-0
transition-opacity peer-checked:opacity-100`}
></div>
</label>
</div>
</div>
);
}
1 change: 1 addition & 0 deletions src/components/RadioButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './RadioButton';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './Icons';
export * from './Toggle';
export * from './Balance';
export * from './ThemeMode';
export * from './RadioButton';

0 comments on commit 2490be5

Please sign in to comment.