Skip to content

Commit

Permalink
fix: issue with angular build
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerget committed Apr 12, 2024
1 parent 2071584 commit f69bd38
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/components/docs/Validation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Validation

- The form components `checkbox`, `radio`, `input`, `textarea` & `select` have some sort of "auto-validation"
- `checkbox` & `radio` do have a color change if you use the `required` attribute. If you use [required](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation) they will be highlighted directly
- `radio` do have a color change if you use the `required` attribute. If you use [required](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation) they will be highlighted directly
- If you use `required` on `input`, `textarea` or `select` you will see invalid/valid states only on submitting or `onchange`
- There are some other attributes for `input` (`type`,`minlength`,`maxlength`,`pattern`) and `textarea`(`minlength`,`maxlength`) which can be used for [validation](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation#using_built-in_form_validation).

Expand Down
16 changes: 12 additions & 4 deletions packages/components/src/components/checkbox/checkbox.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ export default function DBCheckbox(props: DBCheckboxProps) {
if (props.focus) {
props.focus(event);
}
},
getValidMessage: () => {
return props.validMessage || DEFAULT_VALID_MESSAGE;
},
getInvalidMessage: () => {
return (
props.invalidMessage ||
ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE
);
}
});

Expand Down Expand Up @@ -161,16 +171,14 @@ export default function DBCheckbox(props: DBCheckboxProps) {
id={state._validMessageId}
size="small"
semantic="successful">
{props.validMessage || DEFAULT_VALID_MESSAGE}
{state.getValidMessage()}
</DBInfotext>

<DBInfotext
id={state._invalidMessageId}
size="small"
semantic="critical">
{props.invalidMessage ||
ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE}
{state.getInvalidMessage()}
</DBInfotext>
</div>
);
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/components/checkbox/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
FormState,
FormCheckProps,
InitializedState,
FormMessageProps
FormMessageProps,
FormMessageState
} from '../../shared/model';

export interface DBCheckboxDefaultProps {
Expand Down Expand Up @@ -39,4 +40,5 @@ export type DBCheckboxState = DBCheckboxDefaultState &
ChangeEventState<HTMLInputElement> &
FocusEventState<HTMLInputElement> &
FormState &
InitializedState;
InitializedState &
FormMessageState;
16 changes: 12 additions & 4 deletions packages/components/src/components/input/input.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ export default function DBInput(props: DBInputProps) {
if (props.focus) {
props.focus(event);
}
},
getValidMessage: () => {
return props.validMessage || DEFAULT_VALID_MESSAGE;
},
getInvalidMessage: () => {
return (
props.invalidMessage ||
ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE
);
}
});

Expand Down Expand Up @@ -173,16 +183,14 @@ export default function DBInput(props: DBInputProps) {
id={state._validMessageId}
size="small"
semantic="successful">
{props.validMessage || DEFAULT_VALID_MESSAGE}
{state.getValidMessage()}
</DBInfotext>

<DBInfotext
id={state._invalidMessageId}
size="small"
semantic="critical">
{props.invalidMessage ||
ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE}
{state.getInvalidMessage()}
</DBInfotext>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/components/input/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
FocusEventProps,
FocusEventState,
FormMessageProps,
FormMessageState,
FormProps,
FormState,
FormTextProps,
Expand Down Expand Up @@ -72,4 +73,5 @@ export type DBInputState = DBInputDefaultState &
GlobalState &
ChangeEventState<HTMLInputElement> &
FocusEventState<HTMLInputElement> &
FormState;
FormState &
FormMessageState;
4 changes: 3 additions & 1 deletion packages/components/src/components/select/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FocusEventProps,
FocusEventState,
FormMessageProps,
FormMessageState,
FormProps,
FormState,
GlobalProps,
Expand Down Expand Up @@ -72,4 +73,5 @@ export type DBSelectState = DBSelectDefaultState &
ClickEventState<HTMLSelectElement> &
ChangeEventState<HTMLSelectElement> &
FocusEventState<HTMLSelectElement> &
FormState;
FormState &
FormMessageState;
16 changes: 12 additions & 4 deletions packages/components/src/components/select/select.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ export default function DBSelect(props: DBSelectProps) {
},
getOptionLabel: (option: DBSelectOptionType) => {
return option.label ?? option.value.toString();
},
getValidMessage: () => {
return props.validMessage || DEFAULT_VALID_MESSAGE;
},
getInvalidMessage: () => {
return (
props.invalidMessage ||
ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE
);
}
});

Expand Down Expand Up @@ -188,16 +198,14 @@ export default function DBSelect(props: DBSelectProps) {
id={state._validMessageId}
size="small"
semantic="successful">
{props.validMessage || DEFAULT_VALID_MESSAGE}
{state.getValidMessage()}
</DBInfotext>

<DBInfotext
id={state._invalidMessageId}
size="small"
semantic="critical">
{props.invalidMessage ||
ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE}
{state.getInvalidMessage()}
</DBInfotext>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/components/textarea/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
FocusEventProps,
FocusEventState,
FormMessageProps,
FormMessageState,
FormProps,
FormState,
FormTextProps,
Expand Down Expand Up @@ -49,4 +50,5 @@ export type DBTextareaState = DBTextareaDefaultState &
ChangeEventState<HTMLTextAreaElement> &
FocusEventState<HTMLTextAreaElement> &
FormState &
GlobalState;
GlobalState &
FormMessageState;
16 changes: 12 additions & 4 deletions packages/components/src/components/textarea/textarea.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export default function DBTextarea(props: DBTextareaProps) {
if (props.focus) {
props.focus(event);
}
},
getValidMessage: () => {
return props.validMessage || DEFAULT_VALID_MESSAGE;
},
getInvalidMessage: () => {
return (
props.invalidMessage ||
ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE
);
}
});

Expand Down Expand Up @@ -149,16 +159,14 @@ export default function DBTextarea(props: DBTextareaProps) {
id={state._validMessageId}
size="small"
semantic="successful">
{props.validMessage || DEFAULT_VALID_MESSAGE}
{state.getValidMessage()}
</DBInfotext>

<DBInfotext
id={state._invalidMessageId}
size="small"
semantic="critical">
{props.invalidMessage ||
ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE}
{state.getInvalidMessage()}
</DBInfotext>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/shared/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ export type FormCheckProps = {
variant?: 'hidden';
};

export type FormMessageState = {
getValidMessage: () => string;
getInvalidMessage: () => string;
};

export type FormMessageProps = {
/**
* Change the variant of the label to float or hidden
Expand Down

0 comments on commit f69bd38

Please sign in to comment.