Skip to content

Commit

Permalink
[upd] Add text layout class constant; Add category to ts definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed Oct 8, 2020
1 parent 10fe652 commit 2ba8a3d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion css/s-forms.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions src/constants/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const LAYOUT = {
DATE: 'date',
TIME: 'time',
DATETIME: 'datetime',
TEXT: 'text',
TEXTAREA: 'textarea',
CHECKBOX: 'checkbox',
QUESTION_TYPEAHEAD: 'type-ahead',
Expand All @@ -35,13 +36,7 @@ export const LAYOUT = {
HIDDEN: 'hidden',
COLLAPSED: 'collapsed',
EMPHASISED: 'emphasised',
CATEGORY: [
'category-1',
'category-2',
'category-3',
'category-4',
'category-5'
]
CATEGORY: ['category-1', 'category-2', 'category-3', 'category-4', 'category-5']
};
export const VALUE_TYPE_CODE = 'code';
export const VALUE_TYPE_TEXT = 'text';
Expand Down
8 changes: 5 additions & 3 deletions src/util/FormUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default class FormUtils {
);
}

static isText(question) {
return JsonLdUtils.hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.TEXT);
}

static isCalendar(question) {
return FormUtils.isDate(question) || FormUtils.isTime(question) || FormUtils.isDateTime(question);
}
Expand Down Expand Up @@ -87,9 +91,7 @@ export default class FormUtils {
}

static getCategory(question) {
return Constants.LAYOUT.CATEGORY.find(
c => JsonLdUtils.hasValue(question, Constants.LAYOUT_CLASS, c)
);
return Constants.LAYOUT.CATEGORY.find((c) => JsonLdUtils.hasValue(question, Constants.LAYOUT_CLASS, c));
}

static resolveValue(answer) {
Expand Down
10 changes: 10 additions & 0 deletions types/s-forms.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export interface SFormsProps {
loader?: React.ElementType; // default <div>Loading SForms...</div>
}

type ArrayLengthMutationKeys = 'category-1' | 'category-2' | 'category-3' | 'category-4' | 'category-5';
type ArrayItems<T extends Array<any>> = T extends Array<infer TItems> ? TItems : never;
type FixedLengthArray<T extends any[]> = Pick<T, Exclude<keyof T, ArrayLengthMutationKeys>> & {
[Symbol.iterator]: () => IterableIterator<ArrayItems<T>>;
};

export module Constants {
const COLUMN_COUNT: unique symbol;
const INPUT_LENGTH_THRESHOLD: unique symbol;
Expand All @@ -67,6 +73,7 @@ export module Constants {
TIME: string;
DATETIME: string;
TEXTAREA: string;
TEXT: string;
CHECKBOX: string;
QUESTION_TYPEAHEAD: string;
MASKED_INPUT: string;
Expand All @@ -77,6 +84,7 @@ export module Constants {
DISABLED: string;
EMPHASISED: string;
HIDDEN: string;
CATEGORY: FixedLengthArray<[string, string, string, string, string]>;
};
const VALUE_TYPE_CODE: unique symbol;
const VALUE_TYPE_TEXT: unique symbol;
Expand Down Expand Up @@ -160,6 +168,7 @@ export class FormUtils {
static isDisabled(question): boolean;
static isHidden(question): boolean;
static isTextarea(question, answerValue): boolean;
static isText(question): boolean;
static isCalendar(question): boolean;
static isDate(question): boolean;
static isTime(question): boolean;
Expand All @@ -169,6 +178,7 @@ export class FormUtils {
static isSparqlInput(question): boolean;
static isTurtleInput(question): boolean;
static isCollapsed(question): boolean;
static getCategory(question): string;
static isEmphasised(question): boolean;
static resolveValue(answer): any;
static resolveValueObject(answer): any;
Expand Down

0 comments on commit 2ba8a3d

Please sign in to comment.