Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioButton docs + preview #180

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
slug: /radio-button
---

# Radio button

<ComponentDescription componentName="RadioButton" />

## Example

```tsx live
<PreviewBlock componentName="RadioButton">
<RadioButton fieldSize="md" id="radio" label="Label" />
</PreviewBlock>
```

## Props

<ComponentProps componentName="RadioButton" />
Original file line number Diff line number Diff line change
@@ -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",
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -43,6 +44,7 @@ const previews: { [key: string]: ComponentPreview } = {
Paragraph: paragraphPreview,
Profile: profilePreview,
ProjectLogo: projectLogoPreview,
RadioButton: radioButtonPreview,
Select: selectPreview,
Textarea: textareaPreview,
Title: titlePreview,
Expand Down
19 changes: 16 additions & 3 deletions @stellar/design-system/src/components/RadioButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import React from "react";
import "./styles.scss";

interface RadioButtonProps extends React.InputHTMLAttributes<HTMLInputElement> {
/** 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<RadioButtonProps> = ({
interface Props
extends RadioButtonProps,
React.InputHTMLAttributes<HTMLInputElement> {
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<Props> = ({
id,
label,
fieldSize,
...props
}: RadioButtonProps) => {
}: Props) => {
const additionalClasses = [
`RadioButton--${fieldSize}`,
...(props.disabled ? ["RadioButton--disabled"] : []),
Expand Down
Loading