Skip to content

Commit

Permalink
Merge pull request #363 from Panenco/feat/radiobutton-story
Browse files Browse the repository at this point in the history
Feat/radiobutton
  • Loading branch information
vlacher12 authored Jan 23, 2023
2 parents a1ba790 + 46fd8b7 commit aa531df
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 116 deletions.
9 changes: 0 additions & 9 deletions src/components/radiobutton/DOCS.md

This file was deleted.

40 changes: 0 additions & 40 deletions src/components/radiobutton/README.md

This file was deleted.

37 changes: 27 additions & 10 deletions src/components/radiobutton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import cx from 'classnames';

import { Text } from 'components';
import * as React from 'react';
import { idGenerator } from 'utils/helpers';
import { useTheme } from 'utils/hooks';

import { InputPropsType } from '../../utils/types';
Expand All @@ -14,18 +13,38 @@ interface WrapperProps extends React.LabelHTMLAttributes<HTMLLabelElement> {
}

export interface RadioButtonProps extends React.InputHTMLAttributes<HTMLInputElement> {
/**
* Is checked;
* @default false
* */
checked?: boolean;
/**
* Error text;
*/
error?: string;
/**
* Child html input component props. Will be removed in next version;
*/
inputProps?: InputPropsType;
/**
* RadioButton label;
*/
label?: string;
pointColor?: string; // will be removed in next version
/**
* Point color;
*/
pointColor?: string;
// will be removed in next version
/**
* Wrapper props;
*/
wrapperProps?: WrapperProps;
}

export const Radio = React.forwardRef<HTMLLabelElement, RadioButtonProps>(
(
{
label,
id,
className,
checked,
value,
Expand All @@ -39,20 +58,18 @@ export const Radio = React.forwardRef<HTMLLabelElement, RadioButtonProps>(
ref,
): JSX.Element => {
const theme = useTheme();
const uniqueID = idGenerator();
const defaultId = id || uniqueID;
const { className: inputClassName, ...otherInputProps } = inputProps;
const { className: inputClassName, id, ...otherInputProps } = inputProps;

return (
<StyledRadio theme={theme} ref={ref} error={error} pointColor={pointColor} {...wrapperProps}>
<label className={cx('label', disabled && 'labelDisabled', className)} htmlFor={id || defaultId}>
<label className={cx('label', disabled && 'labelDisabled', className)} htmlFor={id}>
<input
type='radio'
className={cx('radiobox', inputClassName)}
id={id || defaultId}
id={id}
disabled={disabled}
checked={checked || value === id}
value={id || value || defaultId}
checked={checked}
value={value}
{...otherInputProps}
{...props}
/>
Expand Down
36 changes: 36 additions & 0 deletions stories/radiobutton/Radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { Radio } from 'components/radiobutton';

export default {
title: 'Example/Radio',
component: Radio,
argTypes: {
pointColor: { control: 'color' },
},
args: {
label: 'Radio button label',
checked: true,
inputProps: {
id: 'radio-button',
},
},
} as ComponentMeta<typeof Radio>;

const Template: ComponentStory<typeof Radio> = (args) => <Radio {...args} />;

export const Default = Template.bind({});

export const Error = Template.bind({});

Error.args = {
error: 'Validation error',
checked: false,
};

export const Disabled = Template.bind({});

Disabled.args = {
disabled: true,
checked: false,
};
57 changes: 0 additions & 57 deletions stories/radiobutton/index.jsx

This file was deleted.

0 comments on commit aa531df

Please sign in to comment.