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

Select docs + preview #177

Merged
merged 3 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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"
}
}
22 changes: 22 additions & 0 deletions @stellar/design-system-website/docs/components/inputs/select.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
slug: /select
---

# Select

<ComponentDescription componentName="Select" />

## Example

```tsx live
<PreviewBlock componentName="Select">
<Select fieldSize="md" id="select">
<option>Option 1</option>
<option>Option 2</option>
</Select>
</PreviewBlock>
```

## Props

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

export const selectPreview: 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: "isLabelUppercase",
label: "Uppercase label",
},
{
type: "checkbox",
prop: "isPill",
label: "Pill",
},
{
type: "checkbox",
prop: "isError",
label: "Error",
},
{
type: "checkbox",
prop: "isExtraPadding",
label: "Extra padding",
},
{
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 @@ -19,6 +19,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 { selectPreview } from "@site/src/componentPreview/selectPreview";
import { titlePreview } from "@site/src/componentPreview/titlePreview";

// =============================================================================
Expand All @@ -38,6 +39,7 @@ const previews: { [key: string]: ComponentPreview } = {
Paragraph: paragraphPreview,
Profile: profilePreview,
ProjectLogo: projectLogoPreview,
Select: selectPreview,
Title: titlePreview,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

.PreviewBlock__selects__content .Select {
width: 8rem;
width: 9rem;
}

/* Checkboxes */
Expand Down Expand Up @@ -84,3 +84,7 @@
.PreviewBlock .Heading {
margin: 0 !important;
}

.PreviewBlock .Select {
max-width: 24rem;
}
28 changes: 25 additions & 3 deletions @stellar/design-system/src/components/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,44 @@ import { FieldNote } from "../utils/FieldNote";
import { Icon } from "../../icons";
import "./styles.scss";

interface SelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
/** Including all valid [select attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#attributes) */
export interface SelectProps {
/** ID of the select should be unique */
id: string;
// Note: cannot use "size" here because it's input's native property
/** Size of the select */
fieldSize: "md" | "sm" | "xs";
/** Select options or optgroup with options */
children: React.ReactNode;
/** Label of the select */
label?: string | React.ReactNode;
/** Note message of the select */
note?: string | React.ReactNode;
/** Error message of the select */
error?: string | string;
/** Make label uppercase */
isLabelUppercase?: boolean;
/** Pill shaped select */
isPill?: boolean;
/** Select error without a message */
isError?: boolean;
/** Select with extra padding */
isExtraPadding?: boolean;
/** Use a specific select rather than a generic HTML select (useful for Formik or otherwise controlled selects) */
customSelect?: React.ReactElement;
}

export const Select: React.FC<SelectProps> = ({
interface Props
extends SelectProps,
React.SelectHTMLAttributes<HTMLSelectElement> {
id: string;
children: React.ReactNode;
}

/**
* `Select` component is a form `select` element, which inherits all native HTML `select` element attributes.
*/
export const Select: React.FC<Props> = ({
id,
fieldSize,
children,
Expand All @@ -32,7 +54,7 @@ export const Select: React.FC<SelectProps> = ({
isExtraPadding,
customSelect,
...props
}: SelectProps) => {
}: Props) => {
const additionalClasses = [
`Select--${fieldSize}`,
...(props.disabled ? ["Select--disabled"] : []),
Expand Down
Loading