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(hidden): added a new hidden option #110

Merged
merged 1 commit into from
Sep 8, 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
10 changes: 5 additions & 5 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
| viewSpec.link | `any` | | A field containing information for forming a [link](#link) for a value |
| viewSpec.placeholder | `string` | | A short hint displayed in the field before the user enters the value |
| viewSpec.addButtonPosition | `"down"/"right"` | | The location of the button adding a new element to the array. Default value "down". |
| viewSpec.hideInput | `boolean` | | Hide input |
| viewSpec.hidden | `boolean` | | Hide field and view |
| viewSpec.selectParams | `object` | | [Parameters](#selectparams) additional options for the selector |

### BooleanSpec
Expand All @@ -49,7 +49,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
| viewSpec.layoutDescription | `string` | | Additional description/hint for [Layout](./config.md#layouts) |
| viewSpec.layoutOpen | `boolean` | | Expand [Layout](./config.md#layouts) at the first rendering |
| viewSpec.link | `any` | | A field containing information for forming a [link](#link) for a value |
| viewSpec.hideInput | `boolean` | | Hide input |
| viewSpec.hidden | `boolean` | | Hide field and view |

### NumberSpec

Expand All @@ -71,7 +71,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
| viewSpec.link | `any` | | A field containing information for forming a [link](#link) for a value |
| viewSpec.placeholder | `string` | | A short hint displayed in the field before the user enters the value |
| viewSpec.copy | `boolean` | | For `true`, will add a copy value button |
| viewSpec.hideInput | `boolean` | | Hide input |
| viewSpec.hidden | `boolean` | | Hide field and view |

### ObjectSpec

Expand All @@ -93,7 +93,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
| viewSpec.link | `any` | | A field containing information for forming a [link](#link) for a value |
| viewSpec.oneOfParams | `object` | | [Parameters](#oneofparams) that must be passed to oneof input |
| viewSpec.placeholder | `string` | | A short hint displayed in the field before the user enters the value |
| viewSpec.hideInput | `boolean` | | Hide input |
| viewSpec.hidden | `boolean` | | Hide field and view |

### StringSpec

Expand Down Expand Up @@ -122,7 +122,7 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
| viewSpec.placeholder | `string` | | A short hint displayed in the field before the user enters the value |
| viewSpec.fileInput | `object` | | [Parameters](#FileInput) that must be passed to file input |
| viewSpec.copy | `boolean` | | For `true`, will add a copy value button |
| viewSpec.hideInput | `boolean` | | Hide input |
| viewSpec.hidden | `boolean` | | Hide field and view |
| viewSpec.textContentParams | `object` | | [Parameters](#textcontentparams) that must be passed to text content |
| viewSpec.selectParams | `object` | | [Parameters](#selectparams) additional options for the selector |

Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/components/Form/Controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const Controller = <Value extends FieldValue, SpecType extends Spec>({
__mirror,
);

if (_.isString(name) && isCorrectSpec(spec) && !spec.viewSpec.hideInput) {
if (_.isString(name) && isCorrectSpec(spec) && !spec.viewSpec.hidden) {
return withSearch(render(renderProps));
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/core/components/View/ViewController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ export const ViewController = <SpecType extends Spec>({
const {viewEntity, Layout} = useComponents(spec, config);
const render = useRender({name, value, spec, viewEntity, Layout, Link});

return <>{render}</>;
if (!spec.viewSpec.hidden) {
return <React.Fragment>{render}</React.Fragment>;
}

return null;
};
10 changes: 5 additions & 5 deletions src/lib/core/types/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ArraySpec<LinkType = any> {
link?: LinkType;
placeholder?: string;
addButtonPosition?: 'down' | 'right';
hideInput?: boolean;
hidden?: boolean;
selectParams?: {
filterPlaceholder?: string;
meta?: Record<string, string>;
Expand All @@ -52,7 +52,7 @@ export interface BooleanSpec<LinkType = any> {
layoutDescription?: string;
layoutOpen?: boolean;
link?: LinkType;
hideInput?: boolean;
hidden?: boolean;
};
}

Expand All @@ -74,7 +74,7 @@ export interface NumberSpec<LinkType = any> {
link?: LinkType;
placeholder?: string;
copy?: boolean;
hideInput?: boolean;
hidden?: boolean;
};
}

Expand All @@ -98,7 +98,7 @@ export interface ObjectSpec<LinkType = any> {
toggler?: 'select' | 'radio' | 'card';
};
placeholder?: string;
hideInput?: boolean;
hidden?: boolean;
};
}

Expand Down Expand Up @@ -132,7 +132,7 @@ export interface StringSpec<LinkType = any> {
};
hideValues?: string[];
placeholder?: string;
hideInput?: boolean;
hidden?: boolean;
textContentParams?: {
themeLabel?: LabelProps['theme'];
text: string;
Expand Down
24 changes: 12 additions & 12 deletions src/stories/components/InputPreview/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ const table: ArraySpec = {
},
};

const hideInput: BooleanSpec = {
const hidden: BooleanSpec = {
type: SpecTypes.Boolean,
viewSpec: {type: 'base', layout: 'row', layoutTitle: 'Hide input'},
viewSpec: {type: 'base', layout: 'row', layoutTitle: 'Hidden'},
};

const textContentParams: ObjectSpec = {
Expand Down Expand Up @@ -443,7 +443,7 @@ export const getArrayOptions = (): ObjectSpec => ({
table,
placeholder,
addButtonPosition,
hideInput,
hidden,
selectParams,
},
[
Expand All @@ -458,7 +458,7 @@ export const getArrayOptions = (): ObjectSpec => ({
'table',
'placeholder',
'addButtonPosition',
'hideInput',
'hidden',
'selectParams',
],
),
Expand Down Expand Up @@ -493,7 +493,7 @@ export const getBooleanOptions = (): ObjectSpec => ({
layoutTitle,
layoutDescription,
layoutOpen,
hideInput,
hidden,
},
[
'disabled',
Expand All @@ -502,7 +502,7 @@ export const getBooleanOptions = (): ObjectSpec => ({
'layoutTitle',
'layoutDescription',
'layoutOpen',
'hideInput',
'hidden',
],
),
},
Expand Down Expand Up @@ -532,7 +532,7 @@ export const getNumberOptions = (): ObjectSpec => ({
layoutOpen,
placeholder,
copy,
hideInput,
hidden,
},
[
'disabled',
Expand All @@ -543,7 +543,7 @@ export const getNumberOptions = (): ObjectSpec => ({
'layoutOpen',
'placeholder',
'copy',
'hideInput',
'hidden',
],
),
},
Expand Down Expand Up @@ -573,7 +573,7 @@ export const getObjectOptions = (): ObjectSpec => ({
order,
oneOfParams,
placeholder,
hideInput,
hidden,
},
[
'disabled',
Expand All @@ -585,7 +585,7 @@ export const getObjectOptions = (): ObjectSpec => ({
'order',
'oneOfParams',
'placeholder',
'hideInput',
'hidden',
],
),
},
Expand Down Expand Up @@ -625,7 +625,7 @@ export const getStringOptions = (): ObjectSpec => ({
placeholder,
fileInput,
copy,
hideInput,
hidden,
selectParams,
},
[
Expand All @@ -641,7 +641,7 @@ export const getStringOptions = (): ObjectSpec => ({
'placeholder',
'fileInput',
'copy',
'hideInput',
'hidden',
'selectParams',
],
),
Expand Down