From 2395b1e2d8a879c13efa3fea319d1c028cd9e5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSalar?= <“salar.sali97@gmail.com”> Date: Thu, 28 Jul 2022 14:19:08 +0300 Subject: [PATCH 1/2] Radio Component v1.0 --- src/components/Radio.tsx | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/components/Radio.tsx diff --git a/src/components/Radio.tsx b/src/components/Radio.tsx new file mode 100644 index 0000000..0157cd3 --- /dev/null +++ b/src/components/Radio.tsx @@ -0,0 +1,46 @@ +import React from "react"; +/** + * [*]This is a Radio component. + * + * [*]when you click on the label the radio will be selected + * + * [*] when you call this component pass the following: + * [1]. label + * [2]. id + * [3]. name + * + * [*] A good example will be: + * + */ +type RadioProps = { + /** + * the text that will be shown besie the radio + */ + label: string; + /** + * please provide a unique id + */ + id: string; + /** + * The name of radio element + */ + name: string; +} & Omit, "type">; + +const Radio = ({ label, id, name, ...props }: RadioProps) => { + return ( +
+ + +
+ ); +}; + +export default Radio; From f008d80b60f1f73b67480e65d2b9bfb50d23be6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSalar?= <“salar.sali97@gmail.com”> Date: Fri, 5 Aug 2022 14:06:21 +0300 Subject: [PATCH 2/2] Radio component with its stories --- src/components/Radio.tsx | 69 ++++++++++++++++------------------- src/stories/Radio.stories.tsx | 46 +++++++++++++++++++++++ 2 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 src/stories/Radio.stories.tsx diff --git a/src/components/Radio.tsx b/src/components/Radio.tsx index 0157cd3..3c2e198 100644 --- a/src/components/Radio.tsx +++ b/src/components/Radio.tsx @@ -1,46 +1,41 @@ +import classNames from "classnames"; import React from "react"; -/** - * [*]This is a Radio component. - * - * [*]when you click on the label the radio will be selected - * - * [*] when you call this component pass the following: - * [1]. label - * [2]. id - * [3]. name - * - * [*] A good example will be: - * - */ -type RadioProps = { +import { ReactComponent as Checkmark } from "assets/svg/check.svg"; + +export type Props = { /** - * the text that will be shown besie the radio + * An Element next to the Radio */ - label: string; - /** - * please provide a unique id - */ - id: string; - /** - * The name of radio element - */ - name: string; + children?: React.ReactNode; } & Omit, "type">; -const Radio = ({ label, id, name, ...props }: RadioProps) => { +const Radio = ({ children, className, ...props }: Props) => { return ( -
- - -
+ ); }; - export default Radio; diff --git a/src/stories/Radio.stories.tsx b/src/stories/Radio.stories.tsx new file mode 100644 index 0000000..bc1dc72 --- /dev/null +++ b/src/stories/Radio.stories.tsx @@ -0,0 +1,46 @@ +import Radio from "../components/Radio"; +import { Meta, Story, ComponentStory, ComponentMeta } from "@storybook/react"; +import React, { useState } from "react"; +import { ReactComponent as Checkmark } from "assets/svg/check.svg"; +import { boolean } from "yup/lib/locale"; + +export default { + title: "Radio", + component: Radio, + // More on argTypes: https://storybook.js.org/docs/react/api/argtypes + argTypes: { + checked: { + type: "boolean", + }, + children: { + type: "string", + defaultValue: "Use light theme", + }, + className: { + type: "string", + defaultValue: "mt-4 ml-4", + }, + disabled: { + type: "boolean", + defaultValue: "false", + }, + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => ; + +export const Checked = Template.bind({}); +Checked.args = { + checked: true, + children: "This is a custom Radio", +}; + +export const Unchecked = Template.bind({}); +Unchecked.args = { + checked: false, +}; + +export const Disabled = Template.bind({}); +Disabled.args = { + disabled: true, +};