-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add form-related types (#469)
Co-authored-by: Hein Jeong <heinje@amazon.com>
- Loading branch information
Showing
9 changed files
with
305 additions
and
0 deletions.
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,24 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
type FieldType = string | { model: string } | { nonModel: string } | { enum: string }; | ||
|
||
export type DataStoreModelField = { | ||
name: string; | ||
type: FieldType; | ||
isReadOnly: boolean; | ||
isRequired: boolean; | ||
isArray: boolean; | ||
}; |
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,46 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import { StudioFieldPosition } from './position'; | ||
import { StudioFieldInputConfig } from './input-config'; | ||
|
||
/** | ||
* Field configurations for StudioForm | ||
*/ | ||
type StudioFieldConfig = { | ||
label?: string; | ||
|
||
position?: StudioFieldPosition; | ||
}; | ||
|
||
/** | ||
* If a field is excluded, it should have no other properties. | ||
*/ | ||
type ExcludedStudioFieldConfig = { | ||
excluded: true; | ||
}; | ||
|
||
type StudioGenericFieldConfig = { | ||
/** | ||
* The configuration for what type of input is used. | ||
*/ | ||
inputType?: StudioFieldInputConfig; | ||
} & StudioFieldConfig; | ||
|
||
export type StudioFormFieldConfig = StudioGenericFieldConfig | ExcludedStudioFieldConfig; | ||
|
||
export type StudioFormFields = { | ||
[field: string]: StudioFormFieldConfig; | ||
}; |
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,39 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import { StudioFormStyle } from './style'; | ||
|
||
export type FormDefinitionElementProps = { | ||
isReadOnly?: boolean; | ||
isRequired?: boolean; | ||
label?: string; | ||
placeholder?: string; | ||
minValue?: number; | ||
maxValue?: number; | ||
step?: number; | ||
level?: number; | ||
text?: string; | ||
}; | ||
|
||
export type FormDefinition = { | ||
form: { | ||
props: { | ||
layoutStyle: StudioFormStyle; | ||
}; | ||
}; | ||
elements: { [element: string]: { componentType: string; dataType?: string; props: FormDefinitionElementProps } }; | ||
buttons: { [key: string]: string }; | ||
elementMatrix: string[][]; | ||
}; |
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,44 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { StudioFormStyle } from './style'; | ||
import { StudioFormFields, StudioFormFieldConfig } from './fields'; | ||
import { SectionalElement } from './sectional-element'; | ||
import { FormDefinition, FormDefinitionElementProps } from './form-definition'; | ||
|
||
/** | ||
* Data type definition for StudioForm | ||
*/ | ||
type StudioFormDataType = { | ||
dataSourceType: 'DataStore' | 'Custom'; | ||
|
||
dataTypeName: string; | ||
}; | ||
|
||
/** | ||
* This is the base type for all StudioForms | ||
*/ | ||
export type StudioForm = { | ||
dataType: StudioFormDataType; | ||
|
||
fields: StudioFormFields; | ||
|
||
sectionalElements: SectionalElement[]; | ||
|
||
style: StudioFormStyle; | ||
}; | ||
|
||
export type { StudioFormStyle, SectionalElement, StudioFormFieldConfig, FormDefinition, FormDefinitionElementProps }; |
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 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
type StudioFieldBaseConfig = { | ||
required?: boolean; | ||
|
||
readOnly?: boolean; | ||
}; | ||
|
||
type StudioFieldTextFieldConfig = { | ||
type: 'TextField'; | ||
|
||
placeholder?: string; | ||
}; | ||
|
||
type StudioFieldSelectListFieldConfig = { | ||
type: 'SelectField'; | ||
|
||
placeholder?: string; | ||
|
||
valueMappings: { value: string; displayValue: string }[]; | ||
}; | ||
|
||
type StudioFieldRadioListFieldConfig = { | ||
type: 'RadioGroupField'; | ||
|
||
valueMappings: { value: string; displayValue: string }[]; | ||
}; | ||
|
||
type StudioFieldSliderFieldConfig = { | ||
type: 'SliderField'; | ||
|
||
minValue: number; | ||
|
||
maxValue: number; | ||
|
||
step: number; | ||
}; | ||
|
||
export type StudioFieldInputConfig = ( | ||
| StudioFieldTextFieldConfig | ||
| StudioFieldSelectListFieldConfig | ||
| StudioFieldRadioListFieldConfig | ||
| StudioFieldSliderFieldConfig | ||
) & | ||
StudioFieldBaseConfig; |
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,16 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
export type StudioFieldPosition = { fixed: 'first' } | { rightOf: string } | { below: string }; |
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,42 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import { StudioFieldPosition } from './position'; | ||
/** | ||
* Sectional elements are visual helpers for the form. They don't have any data associated with them. | ||
*/ | ||
type HeadingSectionalElement = { | ||
type: 'Heading'; | ||
|
||
level: 1 | 2 | 3 | 4 | 5 | 6; | ||
|
||
text: string; | ||
}; | ||
|
||
type TextSectionalElement = { | ||
type: 'Text'; | ||
|
||
text: string; | ||
}; | ||
|
||
type DividerSectionalElement = { | ||
type: 'Divider'; | ||
}; | ||
|
||
export type SectionalElement = { position: StudioFieldPosition; name: string } & ( | ||
| HeadingSectionalElement | ||
| DividerSectionalElement | ||
| TextSectionalElement | ||
); |
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,33 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
type FormStyleConfigCommon = { | ||
tokenReference?: string; | ||
}; | ||
|
||
type FormStyleConfig = { | ||
value?: string; | ||
} & FormStyleConfigCommon; | ||
|
||
type FormAlignmentConfig = { | ||
value?: 'left' | 'center' | 'right'; | ||
} & FormStyleConfigCommon; | ||
|
||
export type StudioFormStyle = { | ||
horizontalGap?: FormStyleConfig; | ||
verticalGap?: FormStyleConfig; | ||
outerPadding?: FormStyleConfig; | ||
alignment?: FormAlignmentConfig; | ||
}; |
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