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

feat: placeholder param for text, textarea, number fields #881

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion apps/demo/config/blocks/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ButtonProps = {
export const Button: ComponentConfig<ButtonProps> = {
label: "Button",
fields: {
label: { type: "text" },
label: { type: "text", placeholder: "Lorem ipsum..." },
href: { type: "text" },
variant: {
type: "radio",
Expand Down
46 changes: 41 additions & 5 deletions apps/docs/pages/docs/api-reference/fields/number.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ const config = {

## Params

| Param | Example | Type | Status |
| --------------- | ---------------- | -------- | -------- |
| [`type`](#type) | `type: "number"` | "number" | Required |
| [`max`](#max) | `max: 10` | number | - |
| [`min`](#min) | `min: 0` | number | - |
| Param | Example | Type | Status |
| ----------------------------- | ------------------------------- | -------- | -------- |
| [`type`](#type) | `type: "number"` | "number" | Required |
| [`max`](#max) | `max: 10` | number | - |
| [`min`](#min) | `min: 0` | number | - |
| [`placeholder`](#placeholder) | `placeholder: "Lorem ipsum..."` | String | - |

## Required params

Expand Down Expand Up @@ -138,3 +139,38 @@ const config = {
},
}}
/>

### Placeholder

The placeholder text to display when the field is empty.

```tsx {7} copy
const config = {
components: {
Example: {
fields: {
myNumber: {
type: "number",
placeholder: "Lorem ipsum...",
},
},
// ...
},
},
};
```

<ConfigPreview
label="Example"
componentConfig={{
fields: {
myNumber: {
type: "number",
placeholder: "Lorem ipsum...",
},
},
render: ({ myNumber }) => {
return <div>{myNumber}</div>;
},
}}
/>
44 changes: 41 additions & 3 deletions apps/docs/pages/docs/api-reference/fields/text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const config = {

## Params

| Param | Example | Type | Status |
| --------------- | -------------- | ------ | -------- |
| [`type`](#type) | `type: "text"` | "text" | Required |
| Param | Example | Type | Status |
| ----------------------------- | ------------------------------- | ------ | -------- |
| [`type`](#type) | `type: "text"` | "text" | Required |
| [`placeholder`](#placeholder) | `placeholder: "Lorem ipsum..."` | String | - |

## Required params

Expand All @@ -62,3 +63,40 @@ const config = {
},
};
```

## Optional params

### Placeholder

The placeholder text to display when the field is empty.

```tsx {7} copy
const config = {
components: {
Example: {
fields: {
title: {
type: "text",
placeholder: "Lorem ipsum...",
},
},
// ...
},
},
};
```

<ConfigPreview
label="Example"
componentConfig={{
fields: {
title: {
type: "text",
placeholder: "Lorem ipsum...",
},
},
render: ({ title }) => {
return <div>{title}</div>;
},
}}
/>
44 changes: 41 additions & 3 deletions apps/docs/pages/docs/api-reference/fields/textarea.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const config = {

## Params

| Param | Example | Type | Status |
| --------------- | ------------------ | ---------- | -------- |
| [`type`](#type) | `type: "textarea"` | "textarea" | Required |
| Param | Example | Type | Status |
| ----------------------------- | ------------------------------- | ---------- | -------- |
| [`type`](#type) | `type: "textarea"` | "textarea" | Required |
| [`placeholder`](#placeholder) | `placeholder: "Lorem ipsum..."` | String | - |

## Required params

Expand All @@ -62,3 +63,40 @@ const config = {
},
};
```

## Optional params

### Placeholder

The placeholder text to display when the field is empty.

```tsx {7} copy
const config = {
components: {
Example: {
fields: {
description: {
type: "textarea",
placeholder: "Lorem ipsum...",
},
},
// ...
},
},
};
```

<ConfigPreview
label="Example"
componentConfig={{
fields: {
description: {
type: "textarea",
placeholder: "Lorem ipsum...",
},
},
render: ({ description }) => {
return <div>{description}</div>;
},
}}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export const DefaultField = ({
id={id}
min={field.type === "number" ? field.min : undefined}
max={field.type === "number" ? field.max : undefined}
placeholder={
field.type === "text" || field.type === "number"
? field.placeholder
: undefined
}
/>
</Label>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FieldPropsInternal } from "../..";
const getClassName = getClassNameFactory("Input", styles);

export const TextareaField = ({
field,
onChange,
readOnly,
value,
Expand All @@ -26,6 +27,7 @@ export const TextareaField = ({
readOnly={readOnly}
tabIndex={readOnly ? -1 : undefined}
rows={5}
placeholder={field.type === "textarea" ? field.placeholder : undefined}
chrisvxd marked this conversation as resolved.
Show resolved Hide resolved
/>
</Label>
);
Expand Down
3 changes: 3 additions & 0 deletions packages/core/types/Fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ export type BaseField = {

export type TextField = BaseField & {
type: "text";
placeholder?: string;
};
export type NumberField = BaseField & {
type: "number";
placeholder?: string;
min?: number;
max?: number;
};

export type TextareaField = BaseField & {
type: "textarea";
placeholder?: string;
};

export type SelectField = BaseField & {
Expand Down
Loading