diff --git a/@stellar/design-system-website/docs/components/inputs/radio-button.mdx b/@stellar/design-system-website/docs/components/inputs/radio-button.mdx new file mode 100644 index 00000000..28337aba --- /dev/null +++ b/@stellar/design-system-website/docs/components/inputs/radio-button.mdx @@ -0,0 +1,19 @@ +--- +slug: /radio-button +--- + +# Radio button + + + +## Example + +```tsx live + + + +``` + +## Props + + diff --git a/@stellar/design-system-website/src/componentPreview/radioButtonPreview.tsx b/@stellar/design-system-website/src/componentPreview/radioButtonPreview.tsx new file mode 100644 index 00000000..95184a59 --- /dev/null +++ b/@stellar/design-system-website/src/componentPreview/radioButtonPreview.tsx @@ -0,0 +1,29 @@ +import { ComponentPreview } from "@site/src/components/PreviewBlock"; + +export const radioButtonPreview: ComponentPreview = { + options: [ + { + type: "select", + prop: "fieldSize", + options: [ + { + value: "md", + label: "MD", + }, + { + value: "sm", + label: "SM", + }, + { + value: "xs", + label: "XS", + }, + ], + }, + { + type: "checkbox", + prop: "disabled", + label: "Disabled", + }, + ], +}; diff --git a/@stellar/design-system-website/src/components/PreviewBlock/index.tsx b/@stellar/design-system-website/src/components/PreviewBlock/index.tsx index daf26e60..fdd72420 100644 --- a/@stellar/design-system-website/src/components/PreviewBlock/index.tsx +++ b/@stellar/design-system-website/src/components/PreviewBlock/index.tsx @@ -20,6 +20,7 @@ import { notificationPreview } from "@site/src/componentPreview/notificationPrev import { paragraphPreview } from "@site/src/componentPreview/paragraphPreview"; import { profilePreview } from "@site/src/componentPreview/profilePreview"; import { projectLogoPreview } from "@site/src/componentPreview/projectLogoPreview"; +import { radioButtonPreview } from "@site/src/componentPreview/radioButtonPreview"; import { selectPreview } from "@site/src/componentPreview/selectPreview"; import { textareaPreview } from "@site/src/componentPreview/textareaPreview"; import { titlePreview } from "@site/src/componentPreview/titlePreview"; @@ -43,6 +44,7 @@ const previews: { [key: string]: ComponentPreview } = { Paragraph: paragraphPreview, Profile: profilePreview, ProjectLogo: projectLogoPreview, + RadioButton: radioButtonPreview, Select: selectPreview, Textarea: textareaPreview, Title: titlePreview, diff --git a/@stellar/design-system/src/components/RadioButton/index.tsx b/@stellar/design-system/src/components/RadioButton/index.tsx index f21e6b6c..1a2f3c5c 100644 --- a/@stellar/design-system/src/components/RadioButton/index.tsx +++ b/@stellar/design-system/src/components/RadioButton/index.tsx @@ -1,19 +1,32 @@ import React from "react"; import "./styles.scss"; -interface RadioButtonProps extends React.InputHTMLAttributes { +/** Including all valid [input attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes) */ +export interface RadioButtonProps { + /** ID of the radio button should be unique */ id: string; + /** Label of the radio button */ label: string | React.ReactNode; // Note: cannot use "size" here because it's input's native property + /** Size of the radio button */ fieldSize: "md" | "sm" | "xs"; } -export const RadioButton: React.FC = ({ +interface Props + extends RadioButtonProps, + React.InputHTMLAttributes { + id: string; +} + +/** + * `RadioButton` component is a form input element, which allows you to select a single value from a group of options for submission. All native HTML `radio` input attributes apply. + */ +export const RadioButton: React.FC = ({ id, label, fieldSize, ...props -}: RadioButtonProps) => { +}: Props) => { const additionalClasses = [ `RadioButton--${fieldSize}`, ...(props.disabled ? ["RadioButton--disabled"] : []),