Skip to content

Commit

Permalink
feat: add min and max params to number field
Browse files Browse the repository at this point in the history
Closes #270
  • Loading branch information
jperasmus authored Dec 21, 2023
1 parent 4498467 commit 4932a6e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/demo/config/blocks/Columns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const Columns: ComponentConfig<ColumnsProps> = {
span: {
label: "Span (1-12)",
type: "number",
min: 0,
max: 12,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions apps/demo/config/blocks/Flex/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ export const Flex: ComponentConfig<FlexProps> = {
minItemWidth: {
label: "Minimum Item Width",
type: "number",
min: 0,
},
},
getItemSummary: (_, id) => `Item ${id + 1}`,
},
minItemWidth: {
label: "Minimum Item Width",
type: "number",
min: 0,
},
},
defaultProps: {
Expand Down
76 changes: 76 additions & 0 deletions apps/docs/pages/docs/api-reference/configuration/fields/number.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const config = {
| Param | Example | Type | Status |
| --------------- | ---------------- | -------- | -------- |
| [`type`](#type) | `type: "number"` | "number" | Required |
| [`min`](#min) | `min: 0` | number | - |
| [`max`](#max) | `max: 10` | number | - |

## Required params

Expand All @@ -62,3 +64,77 @@ const config = {
},
};
```

## Optional params

### `min`

Set the minimum numeric value to accept for the input field.

```tsx {7} copy
const config = {
components: {
Example: {
fields: {
items: {
type: "number",
min: 0,
},
},
// ...
},
},
};
```

<ConfigPreview
label="Example"
componentConfig={{
fields: {
myNumber: {
type: "number",
min: 0,
},
},
defaultProps: { myNumber: 5 },
render: ({ myNumber }) => {
return <div>{myNumber}</div>;
},
}}
/>

### `max`

Set the maximum numeric value to accept for the input field.

```tsx {7} copy
const config = {
components: {
Example: {
fields: {
items: {
type: "number",
max: 10,
},
},
// ...
},
},
};
```

<ConfigPreview
label="Example"
componentConfig={{
fields: {
myNumber: {
type: "number",
max: 10,
},
},
defaultProps: { myNumber: 5 },
render: ({ myNumber }) => {
return <div>{myNumber}</div>;
},
}}
/>
6 changes: 3 additions & 3 deletions apps/docs/pages/docs/integrating-puck/categories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const config = {
};
```

You can also change the label, collapse and hide categories:
You can also change the title, collapse and hide categories:

```tsx {5,6,10} copy showLineNumbers
const config = {
categories: {
typography: {
components: ["HeadingBlock", "ParagraphBlock"],
label: "Text",
title: "Text",
defaultExpanded: false, // Collapse this category by default
},
foundational: {
Expand All @@ -63,7 +63,7 @@ const config = {
components: ["HeadingBlock", "ParagraphBlock"],
},
other: {
label: "Other components",
title: "Other components",
},
},
// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const DefaultField = ({
}}
readOnly={readOnly}
id={id}
min={field.type === "number" ? field.min : undefined}
max={field.type === "number" ? field.max : undefined}
/>
</FieldLabelInternal>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/types/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type TextField = BaseField & {
};
export type NumberField = BaseField & {
type: "number";
min?: number;
max?: number;
};

export type TextareaField = BaseField & {
Expand Down

0 comments on commit 4932a6e

Please sign in to comment.