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

Checkbox docs + preview #179

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,6 @@
{
"label": "Inputs",
"link": {
"type": "generated-index"
}
}
19 changes: 19 additions & 0 deletions @stellar/design-system-website/docs/components/inputs/checkbox.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
slug: /checkbox
---

# Checkbox

<ComponentDescription componentName="Checkbox" />

## Example

```tsx live
<PreviewBlock componentName="Checkbox">
<Checkbox fieldSize="md" id="checkbox" />
</PreviewBlock>
```

## Props

<ComponentProps componentName="Checkbox" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { ComponentPreview } from "@site/src/components/PreviewBlock";

export const checkboxPreview: ComponentPreview = {
options: [
{
type: "select",
prop: "label",
customValue: "Label",
options: [
{
value: "",
label: "No label",
},
{
value: "label",
label: "Label",
},
],
},
{
type: "select",
prop: "fieldSize",
options: [
{
value: "md",
label: "MD",
},
{
value: "sm",
label: "SM",
},
{
value: "xs",
label: "XS",
},
],
},
{
type: "checkbox",
prop: "disabled",
label: "Disabled",
},
{
type: "checkbox",
prop: "isError",
label: "Error",
},
{
type: "select",
prop: "note",
customValue: "Note message",
options: [
{
value: "",
label: "No note",
},
{
value: "note",
label: "Note",
},
],
},
{
type: "select",
prop: "error",
customValue: "Error message",
options: [
{
value: "",
label: "No error",
},
{
value: "error",
label: "Error",
},
],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { badgePreview } from "@site/src/componentPreview/badgePreview";
import { bannerPreview } from "@site/src/componentPreview/bannerPreview";
import { buttonPreview } from "@site/src/componentPreview/buttonPreview";
import { captionPreview } from "@site/src/componentPreview/captionPreview";
import { checkboxPreview } from "@site/src/componentPreview/checkboxPreview";
import { headingPreview } from "@site/src/componentPreview/headingPreview";
import { linkPreview } from "@site/src/componentPreview/linkPreview";
import { loaderPreview } from "@site/src/componentPreview/loaderPreview";
Expand All @@ -31,6 +32,7 @@ const previews: { [key: string]: ComponentPreview } = {
Banner: bannerPreview,
Button: buttonPreview,
Caption: captionPreview,
Checkbox: checkboxPreview,
Heading: headingPreview,
Link: linkPreview,
Loader: loaderPreview,
Expand Down
24 changes: 20 additions & 4 deletions @stellar/design-system/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
import React from "react";
import "./styles.scss";
import { FieldNote } from "../utils/FieldNote";
import { Icon } from "../../icons";
import "./styles.scss";

interface CheckboxProps extends React.InputHTMLAttributes<HTMLInputElement> {
/** Including all valid [input attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes) */
export interface CheckboxProps {
/** ID of the checkbox should be unique */
id: string;
// Note: cannot use "size" here because it's input's native property
/** Size of the checkbox */
fieldSize: "md" | "sm" | "xs";
/** Label of the checkbox */
label?: string | React.ReactNode;
/** Note message of the checkbox */
note?: string | React.ReactNode;
/** Error message of the checkbox */
error?: string | React.ReactNode;
/** Checkbox error without a message */
isError?: boolean;
}

export const Checkbox: React.FC<CheckboxProps> = ({
interface Props
extends CheckboxProps,
React.InputHTMLAttributes<HTMLInputElement> {
id: string;
}

/**
* `Checkbox` component is a form input element, which allows you to select single values for submission. All native HTML `checkbox` input attributes apply.
*/
export const Checkbox: React.FC<Props> = ({
id,
fieldSize,
label,
note,
error,
isError,
...props
}: CheckboxProps) => {
}: Props) => {
const additionalClasses = [
`Checkbox--${fieldSize}`,
...(props.disabled ? ["Checkbox--disabled"] : []),
Expand Down
Loading