Skip to content

Commit 53c4c51

Browse files
laske185Copilot
andauthored
refactor: extract validation functions
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Peter Laske <37439758+laske185@users.noreply.github.com>
1 parent 02dbdd2 commit 53c4c51

File tree

8 files changed

+42
-10
lines changed

8 files changed

+42
-10
lines changed

packages/components/src/schema/props/alert-type.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export type PropAlertType = {
1414
type: AlertTypePropType;
1515
};
1616

17+
const isAlertTypePropType = (value: unknown): value is AlertTypePropType => {
18+
return typeof value === 'string' && alertTypeOptions.includes(value as AlertTypePropType);
19+
};
20+
1721
export const validateAlertType = (component: Generic.Element.Component, value?: AlertTypePropType): void => {
18-
watchValidator(component, '_type', (value) => typeof value === 'string' && alertTypeOptions.includes(value), new Set(alertTypeOptions), value);
22+
watchValidator(component, '_type', isAlertTypePropType, new Set(alertTypeOptions), value);
1923
};

packages/components/src/schema/props/resize-textarea.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ export type PropResizeTextarea = {
1212
resize: TextareaResizePropType;
1313
};
1414

15+
const isTextareaResizePropType = (value: unknown): value is TextareaResizePropType => {
16+
return typeof value === 'string' && textareaResizeOptions.includes(value as TextareaResizePropType);
17+
};
18+
1519
export const validateResizeTextarea = (component: Generic.Element.Component, value?: TextareaResizePropType): void => {
16-
watchValidator(component, '_resize', (value) => typeof value === 'string' && textareaResizeOptions.includes(value), new Set(textareaResizeOptions), value, {
17-
defaultValue: 'vertical',
18-
});
20+
watchValidator(component, '_resize', isTextareaResizePropType, new Set(textareaResizeOptions), value, {
21+
defaultValue: 'vertical',
22+
});
1923
};

packages/components/src/schema/props/type-input-date.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export type PropTypeInputDate = {
1212
type: InputDateTypePropType;
1313
};
1414

15+
const isInputDateTypePropType = (value: unknown): value is InputDateTypePropType => {
16+
return typeof value === 'string' && inputDateTypeOptions.includes(value as InputDateTypePropType);
17+
};
18+
1519
export const validateTypeInputDate = (component: Generic.Element.Component, value?: InputDateTypePropType): void => {
16-
watchValidator(component, '_type', (value) => typeof value === 'string' && inputDateTypeOptions.includes(value), new Set(inputDateTypeOptions), value);
20+
watchValidator(component, '_type', isInputDateTypePropType, new Set(inputDateTypeOptions), value);
1721
};

packages/components/src/schema/props/type-input-text.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export type PropTypeInputText = {
1212
type: InputTextTypePropType;
1313
};
1414

15+
const isInputTextTypePropType = (value: unknown): value is InputTextTypePropType => {
16+
return typeof value === 'string' && inputTextTypeOptions.includes(value as InputTextTypePropType);
17+
};
18+
1519
export const validateTypeInputText = (component: Generic.Element.Component, value?: InputTextTypePropType): void => {
16-
watchValidator(component, '_type', (value) => typeof value === 'string' && inputTextTypeOptions.includes(value), new Set(inputTextTypeOptions), value);
20+
watchValidator(component, '_type', isInputTextTypePropType, new Set(inputTextTypeOptions), value);
1721
};

packages/components/src/schema/props/variant-alert.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export type PropAlertVariant = {
1212
variant: AlertVariantPropType;
1313
};
1414

15+
const isAlertVariantPropType = (value: unknown): value is AlertVariantPropType => {
16+
return typeof value === 'string' && alertVariantOptions.includes(value as AlertVariantPropType);
17+
};
18+
1519
export const validateAlertVariant = (component: Generic.Element.Component, value?: AlertVariantPropType): void => {
16-
watchValidator(component, '_variant', (value) => typeof value === 'string' && alertVariantOptions.includes(value), new Set(alertVariantOptions), value);
20+
watchValidator(component, '_variant', isAlertVariantPropType, new Set(alertVariantOptions), value);
1721
};

packages/components/src/schema/props/variant-input-checkbox.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ export type PropVariantInputCheckbox = {
1212
variant: InputCheckboxVariantPropType;
1313
};
1414

15+
const isInputCheckboxVariantPropType = (value: unknown): value is InputCheckboxVariantPropType => {
16+
return typeof value === 'string' && inputCheckboxVariantOptions.includes(value as InputCheckboxVariantPropType);
17+
};
18+
1519
export const validateVariantInputCheckbox = (component: Generic.Element.Component, value?: InputCheckboxVariantPropType): void => {
1620
watchValidator(
1721
component,
1822
'_variant',
19-
(value) => typeof value === 'string' && inputCheckboxVariantOptions.includes(value),
23+
isInputCheckboxVariantPropType,
2024
new Set(inputCheckboxVariantOptions),
2125
value,
2226
);

packages/components/src/schema/props/variant-progress.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export type PropVariantProgress = {
1212
variant: ProgressVariantPropType;
1313
};
1414

15+
const isProgressVariantPropType = (value: unknown): value is ProgressVariantPropType => {
16+
return typeof value === 'string' && progressVariantOptions.includes(value as ProgressVariantPropType);
17+
};
18+
1519
export const validateVariantProgress = (component: Generic.Element.Component, value?: ProgressVariantPropType): void => {
16-
watchValidator(component, '_variant', (value) => typeof value === 'string' && progressVariantOptions.includes(value), new Set(progressVariantOptions), value);
20+
watchValidator(component, '_variant', isProgressVariantPropType, new Set(progressVariantOptions), value);
1721
};

packages/components/src/schema/props/variant-quote.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export type PropVariantQuote = {
1212
variant: QuoteVariantPropType;
1313
};
1414

15+
const isQuoteVariantPropType = (value: unknown): value is QuoteVariantPropType => {
16+
return typeof value === 'string' && quoteVariantOptions.includes(value as QuoteVariantPropType);
17+
};
18+
1519
export const validateVariantQuote = (component: Generic.Element.Component, value?: QuoteVariantPropType): void => {
16-
watchValidator(component, '_variant', (value) => typeof value === 'string' && quoteVariantOptions.includes(value), new Set(quoteVariantOptions), value);
20+
watchValidator(component, '_variant', isQuoteVariantPropType, new Set(quoteVariantOptions), value);
1721
};

0 commit comments

Comments
 (0)