diff --git a/.github/CONTRIBUTION.md b/CONTRIBUTION.md similarity index 100% rename from .github/CONTRIBUTION.md rename to CONTRIBUTION.md diff --git a/src/components/Radio/index.stories.tsx b/src/components/Radio/index.stories.tsx index 136c62a99..19ff82bd8 100644 --- a/src/components/Radio/index.stories.tsx +++ b/src/components/Radio/index.stories.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import Radio from '.'; import '../../styles/stories.scss'; @@ -13,65 +13,116 @@ const FormContainer = ({ children }) => { return
{children}
; }; -export const BasicUsage = () => ( -
- - - -
-); - -export const RadioDisabled = () => ( -
- - - -
-); - -export const LabelDisabled = () => ( -
- - - -
-); - -export const RadioColor = () => ( -
- - - -
-); - -export const OnChange = () => ( -
- - alert(v)} /> - -
-); -export const OnClick = () => ( -
- - alert('clicked')} /> - -
-); - -export const RadioCell = () => ( - <> -
- +export const BasicUsage = () => { + const [checked, setChecked] = useState(false); + return ( +
+ + setChecked(!checked)} /> +
- -); + ); +}; + +export const RadioDisabled = () => { + const [checked, setChecked] = useState(false); + + return ( +
+ + setChecked(!checked)} + /> + +
+ ); +}; + +export const LabelDisabled = () => { + const [checked, setChecked] = useState(false); -export const RadioCellRTL = () => ( - <> -
- + return ( +
+ + setChecked(!checked)} + /> +
- -); + ); +}; + +export const RadioColor = () => { + const [checked, setChecked] = useState(false); + + return ( +
+ + setChecked(!checked)} + /> + +
+ ); +}; + +export const OnClick = () => { + const [checked, setChecked] = useState(false); + + return ( +
+ + { + setChecked(!checked); + alert(checked); + }} + /> + +
+ ); +}; + +export const RadioCell = () => { + const [checked, setChecked] = useState(false); + + return ( + <> +
+ setChecked(!checked) + }} + /> +
+ + ); +}; + +export const RadioCellRTL = () => { + const [checked, setChecked] = useState(false); + + return ( + <> +
+ setChecked(!checked) + }} + /> +
+ + ); +}; diff --git a/src/components/Radio/index.tsx b/src/components/Radio/index.tsx index b1c3247ad..b8606b2c1 100644 --- a/src/components/Radio/index.tsx +++ b/src/components/Radio/index.tsx @@ -1,4 +1,4 @@ -import React, { MouseEvent, useEffect, useState } from 'react'; +import React, { MouseEvent } from 'react'; import classnames from '../../utils/classNames'; import Icon from '../Icons'; @@ -15,31 +15,23 @@ const Radio = ({ labelDisabled, checkedColor, onClick, - onChange, rtl, label = 'radio button' }: IProps) => { - const [isChecked, setChecked] = useState(checked); const handleClick = (event: MouseEvent): void => { if (!labelDisabled) { - setChecked(!isChecked); onClick && onClick(event); } }; const handleRadioClick = (event: MouseEvent): void => { if (labelDisabled) { - setChecked(!isChecked); onClick && onClick(event); } }; - useEffect(() => { - onChange && onChange(isChecked); - }, [isChecked]); - - const iconName = isChecked ? 'checked' : 'circle'; - const iconColor = disabled ? '#c8c9cc' : isChecked ? checkedColor : '#000'; + const iconName = checked ? 'checked' : 'circle'; + const iconColor = disabled ? '#c8c9cc' : checked ? checkedColor : '#000'; // TODO: Add form related inputs here when working on form element return ( diff --git a/src/components/Radio/types.ts b/src/components/Radio/types.ts index a5946377e..6606805f5 100644 --- a/src/components/Radio/types.ts +++ b/src/components/Radio/types.ts @@ -1,12 +1,11 @@ export interface IProps { name?: string; disabled?: boolean; - checked?: boolean; + checked: boolean; labelDisabled?: boolean; rtl?: boolean; iconSize?: string; checkedColor?: string; - onClick?: Function; - onChange?: Function; + onClick: Function; label?: string; }