-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [#2] Implement columns component schema type
- Loading branch information
1 parent
c90192c
commit dad9370
Showing
4 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {AnyComponentSchema, LayoutComponentSchema} from '..'; | ||
|
||
/** | ||
* Configuration of a single column. | ||
* | ||
* Note that this deviates from Formio.js' own schema, as they are tightly coupled with | ||
* Bootstrap properties/class names, which we deliberately avoid. | ||
*/ | ||
export interface Column { | ||
/** | ||
* Size on non-mobile viewports. | ||
* | ||
* The size specifies the number of columns spanned in a 12-column grid. If no mobile | ||
* size is specified, a 100% width is assumed. | ||
*/ | ||
size: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; | ||
/** | ||
* Size on mobile viewports. | ||
* | ||
* The mobile size specifies the numbers of columns spanned in a 4-column grid. | ||
* | ||
* @todo Add backend migration to ensure this attribute is set everywhere. | ||
*/ | ||
sizeMobile: 1 | 2 | 3 | 4; | ||
/** | ||
* Nested components inside a single column. | ||
*/ | ||
components: AnyComponentSchema[]; | ||
} | ||
|
||
/** | ||
* The columns component schema. | ||
* | ||
* Columns are used to manage layout on desktop and mobile viewports by grouping nested | ||
* components inside into columns. | ||
* | ||
* @group Form.io components | ||
* @category Concrete types | ||
*/ | ||
export interface ColumnsComponentSchema | ||
extends Omit< | ||
LayoutComponentSchema<never>, | ||
| 'label' | ||
| 'placeholder' | ||
| 'multiple' | ||
| 'defaultValue' | ||
| 'conditional' | ||
| 'errors' | ||
| 'description' | ||
| 'tooltip' | ||
| 'hideLabel' | ||
| 'disabled' | ||
| 'validateOn' | ||
> { | ||
id: string; | ||
key: string; | ||
type: 'columns'; | ||
columns: Column[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ export * from './radio'; | |
|
||
// Layout components | ||
export * from './content'; | ||
export * from './columns'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {expectAssignable, expectNotAssignable} from 'tsd'; | ||
|
||
import {Column, ColumnsComponentSchema} from '../../../lib'; | ||
|
||
// Minimal schema | ||
expectAssignable<ColumnsComponentSchema>({ | ||
id: 'eqegfc', | ||
type: 'columns', | ||
key: 'columns', | ||
columns: [], | ||
}); | ||
|
||
// Full schema | ||
expectAssignable<ColumnsComponentSchema>({ | ||
id: 'eqegfc', | ||
type: 'columns', | ||
key: 'columns', | ||
columns: [ | ||
{ | ||
size: 6, | ||
sizeMobile: 4, | ||
components: [ | ||
{ | ||
id: 'wien53il', | ||
type: 'textfield', | ||
key: 'nestedTextField', | ||
label: 'Nested text field', | ||
}, | ||
], | ||
}, | ||
{ | ||
size: 3, | ||
sizeMobile: 4, | ||
components: [ | ||
{ | ||
id: 'abcdefgh', | ||
type: 'textfield', | ||
key: 'nested2', | ||
label: 'Second text field', | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
expectNotAssignable<Column>({ | ||
size: 0 as const, | ||
sizeMobile: 4 as const, | ||
components: [], | ||
}); | ||
|
||
expectNotAssignable<Column>({ | ||
size: 13 as const, | ||
sizeMobile: 4 as const, | ||
components: [], | ||
}); | ||
|
||
expectNotAssignable<Column>({ | ||
size: 3.14 as number, | ||
sizeMobile: 4 as const, | ||
components: [], | ||
}); |