Skip to content

Commit

Permalink
feat: add size config to FidgetEditConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
hiporox committed May 7, 2024
1 parent 2889de1 commit 513acdd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/common/fidgets/makeFidget.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NumericRange } from "@/constants/numericRange";
import React from "react";

export interface FidgetSettings {
Expand All @@ -21,6 +22,12 @@ export type FidgetFieldConfig = {

export type FidgetEditConfig = {
fields: FidgetFieldConfig[];
size: {
minHeight: NumericRange<1,36>;
maxHeight: NumericRange<1,36>;
minWidth: NumericRange<1,36>;
maxWidth: NumericRange<1,36>;
}
};

export interface Fidget<P> extends React.FC<P> {
Expand Down
8 changes: 8 additions & 0 deletions src/constants/numericRange.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type NumericRange<
start extends number,
end extends number,
arr extends unknown[] = [],
acc extends number = never,
> = arr['length'] extends end
? acc | start | end
: NumericRange<start, end, [...arr, 1], arr[start] extends undefined ? acc : acc | arr['length']>;
6 changes: 6 additions & 0 deletions src/fidgets/example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const exampleConfig: FidgetEditConfig = {
inputSelector: TextInput,
}
],
size: {
minHeight: 1,
maxHeight: 36,
minWidth: 1,
maxWidth: 36,
}
};

const Example: React.FC<ExampleFidgetSettings> = ({ text }: ExampleFidgetSettings) => {
Expand Down

0 comments on commit 513acdd

Please sign in to comment.