Skip to content

Commit

Permalink
feat(objectInline): support inline boolean fields (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
hozblok authored Feb 16, 2024
1 parent 1f3f81c commit 043761c
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ test.describe('Checkbox', () => {

await expectScreenshot();
});

test('layout transparent', async ({mount, expectScreenshot}) => {
await mount(<DynamicForm spec={CHECKBOX.layoutTransparent} />);

await expectScreenshot();
});
});

test.describe('Checkbox view', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/kit/components/Inputs/Checkbox/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export const CHECKBOX: Record<string, BooleanSpec> = {
layoutTitle: 'File Input',
},
},
layoutTransparent: {
type: SpecTypes.Boolean,
viewSpec: {
type: 'base',
layout: 'transparent',
layoutTitle: 'Flag',
},
},
row_verbose: {
type: SpecTypes.Boolean,
viewSpec: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test.describe('Text Input', () => {
});

test('layout transperant', async ({mount, expectScreenshot}) => {
await mount(<DynamicForm spec={NUMBER_SPEC.layoutTransperant} />);
await mount(<DynamicForm spec={NUMBER_SPEC.layoutTransparent} />);

await expectScreenshot();
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/kit/components/Inputs/Text/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const NUMBER_SPEC: Record<string, NumberSpec> = {
placeholder: 'placeholder text',
},
},
layoutTransperant: {
layoutTransparent: {
type: SpecTypes.Number,
viewSpec: {
type: 'base',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.describe('Text Area', () => {
});

test('layout transperant', async ({mount, expectScreenshot}) => {
await mount(<DynamicForm spec={TEXT_AREA_SPEC.layoutTransperant} />);
await mount(<DynamicForm spec={TEXT_AREA_SPEC.layoutTransparent} />);

await expectScreenshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const TEXT_AREA_SPEC: Record<string, StringSpec> = {
layoutDescription: 'description',
},
},
layoutTransperant: {
layoutTransparent: {
type: SpecTypes.String,
viewSpec: {
type: 'textarea',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/kit/constants/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const dynamicConfig: DynamicFormConfig = {
row: Row,
row_verbose: RowVerbose,
table_item: TableCell,
transparent: Transparent,
},
validators: {
base: getBooleanValidator(),
Expand Down Expand Up @@ -214,6 +215,7 @@ export const dynamicViewConfig: DynamicViewConfig = {
row: ViewRow,
row_verbose: ViewRow,
table_item: ViewTableCell,
transparent: ViewTransparent,
},
},
number: {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/kit/utils/objectInline.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Spec, isNumberSpec, isStringSpec} from '../../core';
import {Spec, isBooleanSpec, isNumberSpec, isStringSpec} from '../../core';

export const filterPropertiesForObjectInline = (properties: Record<string, Spec>) => {
return Object.fromEntries(
Object.entries(properties).filter(
([, propSpec]) => isStringSpec(propSpec) || isNumberSpec(propSpec),
([, propSpec]) =>
isStringSpec(propSpec) || isNumberSpec(propSpec) || isBooleanSpec(propSpec),
),
);
};
7 changes: 7 additions & 0 deletions src/stories/ObjectInline.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const baseSpec: ObjectSpec = {
layoutTitle: 'Name',
},
},
license: {
type: SpecTypes.Boolean,
viewSpec: {
type: 'base',
layout: 'transparent',
},
},
},
viewSpec: {
type: 'inline',
Expand Down

0 comments on commit 043761c

Please sign in to comment.